add more descriptive usage information
[asterisk/asterisk.git] / apps / app_setcdruserfield.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Applictions connected with CDR engine
5  * 
6  * Copyright (C) 2003, Digium
7  *
8  * Justin Huff <jjhuff@mspin.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #include <sys/types.h>
15 #include <asterisk/channel.h>
16 #include <asterisk/cdr.h>
17 #include <asterisk/module.h>
18 #include <asterisk/pbx.h>
19 #include <asterisk/logger.h>
20
21 #include <stdlib.h>
22 #include <string.h>
23
24
25 static char *tdesc = "CDR user field apps";
26
27 static char *setcdruserfield_descrip = 
28                "[Synopsis]\n"
29                "SetCDRUserField(value)\n\n"
30                "[Description]\n"
31                "SetCDRUserField(value): Set the CDR 'user field' to value\n"
32                "       The Call Data Record (CDR) user field is an extra field you\n"
33                "       can use for data not stored anywhere else in the record.\n"
34                "       CDR records can be used for billing or storing other arbitrary data\n"
35                "       (I.E. telephone survey responses)\n"
36                "       Also see AppendCDRUserField().\n"
37                "       Always returns 0\n";
38
39                 
40 static char *setcdruserfield_app = "SetCDRUserField";
41 static char *setcdruserfield_synopsis = "Set the CDR user field";
42
43 static char *appendcdruserfield_descrip = 
44                "[Synopsis]\n"
45                "AppendCDRUserField(value)\n\n"
46                "[Description]\n"
47                "AppendCDRUserField(value): Append value to the CDR user field\n"
48                "       The Call Data Record (CDR) user field is an extra field you\n"
49                "       can use for data not stored anywhere else in the record.\n"
50                "       CDR records can be used for billing or storing other arbitrary data\n"
51                "       (I.E. telephone survey responses)\n"
52                "       Also see SetCDRUserField().\n"
53                "       Always returns 0\n";
54                 
55 static char *appendcdruserfield_app = "AppendCDRUserField";
56 static char *appendcdruserfield_synopsis = "Append to the CDR user field";
57
58 STANDARD_LOCAL_USER;
59
60 LOCAL_USER_DECL;
61
62 static int setcdruserfield_exec(struct ast_channel *chan, void *data)
63 {
64         struct localuser *u;
65         int res = 0;
66         
67         LOCAL_USER_ADD(u)
68         if (chan->cdr && data) 
69         {
70                 ast_cdr_setuserfield(chan, (char*)data);
71         }
72
73         LOCAL_USER_REMOVE(u);
74         
75         return res;
76 }
77
78 static int appendcdruserfield_exec(struct ast_channel *chan, void *data)
79 {
80         struct localuser *u;
81         int res = 0;
82         
83         LOCAL_USER_ADD(u)
84         if (chan->cdr && data) 
85         {
86                 ast_cdr_appenduserfield(chan, (char*)data);
87         }
88
89         LOCAL_USER_REMOVE(u);
90         
91         return res;
92 }
93
94 int unload_module(void)
95 {
96         int res;
97         STANDARD_HANGUP_LOCALUSERS;
98         res = ast_unregister_application(setcdruserfield_app);
99         res |= ast_unregister_application(appendcdruserfield_app);
100         return res;
101 }
102
103 int load_module(void)
104 {
105         int res;
106         res = ast_register_application(setcdruserfield_app, setcdruserfield_exec, setcdruserfield_synopsis, setcdruserfield_descrip);
107         res |= ast_register_application(appendcdruserfield_app, appendcdruserfield_exec, appendcdruserfield_synopsis, appendcdruserfield_descrip);
108
109         return res;
110 }
111
112 char *description(void)
113 {
114         return tdesc;
115 }
116
117 int usecount(void)
118 {
119         int res;
120         STANDARD_USECOUNT(res);
121         return res;
122 }
123
124 char *key()
125 {
126         return ASTERISK_GPL_KEY;
127 }