Add userfield logging
[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                 "SetCDRUserField(value): Set the CDR user field to value\n";
29                 
30 static char *setcdruserfield_app = "SetCDRUserField";
31 static char *setcdruserfield_synopsis = "Set the CDR user field";
32
33 static char *appendcdruserfield_descrip = 
34                 "AppendCDRUserField(value): Append value to the CDR user field\n";
35                 
36 static char *appendcdruserfield_app = "AppendCDRUserField";
37 static char *appendcdruserfield_synopsis = "Append to the CDR user field";
38
39 STANDARD_LOCAL_USER;
40
41 LOCAL_USER_DECL;
42
43 static int setcdruserfield_exec(struct ast_channel *chan, void *data)
44 {
45         struct localuser *u;
46         int res = 0;
47         
48         LOCAL_USER_ADD(u)
49         if (chan->cdr && data) 
50         {
51                 ast_cdr_setuserfield(chan, (char*)data);
52         }
53
54         LOCAL_USER_REMOVE(u);
55         
56         return res;
57 }
58
59 static int appendcdruserfield_exec(struct ast_channel *chan, void *data)
60 {
61         struct localuser *u;
62         int res = 0;
63         
64         LOCAL_USER_ADD(u)
65         if (chan->cdr && data) 
66         {
67                 ast_cdr_appenduserfield(chan, (char*)data);
68         }
69
70         LOCAL_USER_REMOVE(u);
71         
72         return res;
73 }
74
75 int unload_module(void)
76 {
77         int res;
78         STANDARD_HANGUP_LOCALUSERS;
79         res = ast_unregister_application(setcdruserfield_app);
80         res |= ast_unregister_application(appendcdruserfield_app);
81         return res;
82 }
83
84 int load_module(void)
85 {
86         int res;
87         res = ast_register_application(setcdruserfield_app, setcdruserfield_exec, setcdruserfield_synopsis, setcdruserfield_descrip);
88         res |= ast_register_application(appendcdruserfield_app, appendcdruserfield_exec, appendcdruserfield_synopsis, appendcdruserfield_descrip);
89
90         return res;
91 }
92
93 char *description(void)
94 {
95         return tdesc;
96 }
97
98 int usecount(void)
99 {
100         int res;
101         STANDARD_USECOUNT(res);
102         return res;
103 }
104
105 char *key()
106 {
107         return ASTERISK_GPL_KEY;
108 }