- mark some applications deprecated that already have replacements
[asterisk/asterisk.git] / apps / app_setcdruserfield.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Justin Huff <jjhuff@mspin.net>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief Applictions connected with CDR engine
22  *
23  * \author Justin Huff <jjhuff@mspin.net>
24  *  
25  * \ingroup applications
26  */
27
28 #include <sys/types.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include "asterisk.h"
33
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
35
36 #include "asterisk/channel.h"
37 #include "asterisk/cdr.h"
38 #include "asterisk/module.h"
39 #include "asterisk/pbx.h"
40 #include "asterisk/logger.h"
41 #include "asterisk/config.h"
42 #include "asterisk/manager.h"
43 #include "asterisk/utils.h"
44
45
46 static char *tdesc = "CDR user field apps";
47
48 static char *setcdruserfield_descrip = 
49                "[Synopsis]\n"
50                "SetCDRUserField(value)\n\n"
51                "[Description]\n"
52                "SetCDRUserField(value): Set the CDR 'user field' to value\n"
53                "       The Call Data Record (CDR) user field is an extra field you\n"
54                "       can use for data not stored anywhere else in the record.\n"
55                "       CDR records can be used for billing or storing other arbitrary data\n"
56                "       (I.E. telephone survey responses)\n"
57                "       Also see AppendCDRUserField().\n";
58
59                 
60 static char *setcdruserfield_app = "SetCDRUserField";
61 static char *setcdruserfield_synopsis = "Set the CDR user field";
62
63 static char *appendcdruserfield_descrip = 
64                "[Synopsis]\n"
65                "AppendCDRUserField(value)\n\n"
66                "[Description]\n"
67                "AppendCDRUserField(value): Append value to the CDR user field\n"
68                "       The Call Data Record (CDR) user field is an extra field you\n"
69                "       can use for data not stored anywhere else in the record.\n"
70                "       CDR records can be used for billing or storing other arbitrary data\n"
71                "       (I.E. telephone survey responses)\n"
72                "       Also see SetCDRUserField().\n";
73                 
74 static char *appendcdruserfield_app = "AppendCDRUserField";
75 static char *appendcdruserfield_synopsis = "Append to the CDR user field";
76
77 LOCAL_USER_DECL;
78
79 static int action_setcdruserfield(struct mansession *s, struct message *m)
80 {
81         struct ast_channel *c = NULL;
82         char *userfield = astman_get_header(m, "UserField");
83         char *channel = astman_get_header(m, "Channel");
84         char *append = astman_get_header(m, "Append");
85
86         if (ast_strlen_zero(channel)) {
87                 astman_send_error(s, m, "No Channel specified");
88                 return 0;
89         }
90         if (ast_strlen_zero(userfield)) {
91                 astman_send_error(s, m, "No UserField specified");
92                 return 0;
93         }
94         c = ast_get_channel_by_name_locked(channel);
95         if (!c) {
96                 astman_send_error(s, m, "No such channel");
97                 return 0;
98         }
99         if (ast_true(append))
100                 ast_cdr_appenduserfield(c, userfield);
101         else
102                 ast_cdr_setuserfield(c, userfield);
103         ast_mutex_unlock(&c->lock);
104         astman_send_ack(s, m, "CDR Userfield Set");
105         return 0;
106 }
107
108 static int setcdruserfield_exec(struct ast_channel *chan, void *data)
109 {
110         struct localuser *u;
111         int res = 0;
112         static int dep_warning = 0;
113         
114         LOCAL_USER_ADD(u);
115
116         if (chan->cdr && data) {
117                 ast_cdr_setuserfield(chan, (char*)data);
118         }
119
120         if (!dep_warning) {
121                 dep_warning = 1;
122                 ast_log(LOG_WARNING, "SetCDRUserField is deprecated.  Please use CDR(userfield) instead.\n");
123         }
124
125         LOCAL_USER_REMOVE(u);
126         
127         return res;
128 }
129
130 static int appendcdruserfield_exec(struct ast_channel *chan, void *data)
131 {
132         struct localuser *u;
133         int res = 0;
134         static int dep_warning = 0;
135         
136         LOCAL_USER_ADD(u);
137
138         if (chan->cdr && data) {
139                 ast_cdr_appenduserfield(chan, (char*)data);
140         }
141
142         if (!dep_warning) {
143                 dep_warning = 1;
144                 ast_log(LOG_WARNING, "AppendCDRUserField is deprecated.  Please use CDR(userfield) instead.\n");
145         }
146
147         LOCAL_USER_REMOVE(u);
148         
149         return res;
150 }
151
152 static int unload_module(void *mod)
153 {
154         int res;
155         
156         res = ast_unregister_application(setcdruserfield_app);
157         res |= ast_unregister_application(appendcdruserfield_app);
158         res |= ast_manager_unregister("SetCDRUserField");
159
160         STANDARD_HANGUP_LOCALUSERS;
161
162         return res;
163 }
164
165 static int load_module(void *mod)
166 {
167         int res;
168
169         res = ast_register_application(setcdruserfield_app, setcdruserfield_exec, setcdruserfield_synopsis, setcdruserfield_descrip);
170         res |= ast_register_application(appendcdruserfield_app, appendcdruserfield_exec, appendcdruserfield_synopsis, appendcdruserfield_descrip);
171         res |= ast_manager_register("SetCDRUserField", EVENT_FLAG_CALL, action_setcdruserfield, "Set the CDR UserField");
172         
173         return res;
174 }
175
176 static const char *description(void)
177 {
178         return tdesc;
179 }
180
181 static const char *key(void)
182 {
183         return ASTERISK_GPL_KEY;
184 }
185
186 STD_MOD1;