(closes issue #12846)
[asterisk-bristuff.git] / apps / app_setcdruserfield.c
blobccfbcedd2d2bde78265a66af354a508e7aef69bc
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Justin Huff <jjhuff@mspin.net>
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.
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.
19 /*! \file
21 * \brief Applictions connected with CDR engine
23 * \author Justin Huff <jjhuff@mspin.net>
25 * \ingroup applications
28 #include "asterisk.h"
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32 #include <sys/types.h>
33 #include <stdlib.h>
34 #include <string.h>
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"
46 static char *setcdruserfield_descrip =
47 "[Synopsis]\n"
48 "SetCDRUserField(value)\n\n"
49 "[Description]\n"
50 "SetCDRUserField(value): Set the CDR 'user field' to value\n"
51 " The Call Data Record (CDR) user field is an extra field you\n"
52 " can use for data not stored anywhere else in the record.\n"
53 " CDR records can be used for billing or storing other arbitrary data\n"
54 " (I.E. telephone survey responses)\n"
55 " Also see AppendCDRUserField().\n"
56 "\nThis application is deprecated in favor of Set(CDR(userfield)=...)\n";
59 static char *setcdruserfield_app = "SetCDRUserField";
60 static char *setcdruserfield_synopsis = "Set the CDR user field";
62 static char *appendcdruserfield_descrip =
63 "[Synopsis]\n"
64 "AppendCDRUserField(value)\n\n"
65 "[Description]\n"
66 "AppendCDRUserField(value): Append value to the CDR user field\n"
67 " The Call Data Record (CDR) user field is an extra field you\n"
68 " can use for data not stored anywhere else in the record.\n"
69 " CDR records can be used for billing or storing other arbitrary data\n"
70 " (I.E. telephone survey responses)\n"
71 " Also see SetCDRUserField().\n"
72 "\nThis application is deprecated in favor of Set(CDR(userfield)=...)\n";
74 static char *appendcdruserfield_app = "AppendCDRUserField";
75 static char *appendcdruserfield_synopsis = "Append to the CDR user field";
78 static int action_setcdruserfield(struct mansession *s, const struct message *m)
80 struct ast_channel *c = NULL;
81 const char *userfield = astman_get_header(m, "UserField");
82 const char *channel = astman_get_header(m, "Channel");
83 const char *append = astman_get_header(m, "Append");
85 if (ast_strlen_zero(channel)) {
86 astman_send_error(s, m, "No Channel specified");
87 return 0;
89 if (ast_strlen_zero(userfield)) {
90 astman_send_error(s, m, "No UserField specified");
91 return 0;
93 c = ast_get_channel_by_name_locked(channel);
94 if (!c) {
95 astman_send_error(s, m, "No such channel");
96 return 0;
98 if (ast_true(append))
99 ast_cdr_appenduserfield(c, userfield);
100 else
101 ast_cdr_setuserfield(c, userfield);
102 ast_mutex_unlock(&c->lock);
103 astman_send_ack(s, m, "CDR Userfield Set");
104 return 0;
107 static int setcdruserfield_exec(struct ast_channel *chan, void *data)
109 struct ast_module_user *u;
110 int res = 0;
111 static int dep_warning = 0;
113 u = ast_module_user_add(chan);
115 if (chan->cdr && data) {
116 ast_cdr_setuserfield(chan, (char*)data);
119 if (!dep_warning) {
120 dep_warning = 1;
121 ast_log(LOG_WARNING, "SetCDRUserField is deprecated. Please use CDR(userfield) instead.\n");
124 ast_module_user_remove(u);
126 return res;
129 static int appendcdruserfield_exec(struct ast_channel *chan, void *data)
131 struct ast_module_user *u;
132 int res = 0;
133 static int dep_warning = 0;
135 u = ast_module_user_add(chan);
137 if (chan->cdr && data) {
138 ast_cdr_appenduserfield(chan, (char*)data);
141 if (!dep_warning) {
142 dep_warning = 1;
143 ast_log(LOG_WARNING, "AppendCDRUserField is deprecated. Please use CDR(userfield) instead.\n");
146 ast_module_user_remove(u);
148 return res;
151 static int unload_module(void)
153 int res;
155 res = ast_unregister_application(setcdruserfield_app);
156 res |= ast_unregister_application(appendcdruserfield_app);
157 res |= ast_manager_unregister("SetCDRUserField");
159 ast_module_user_hangup_all();
161 return res;
164 static int load_module(void)
166 int res;
168 res = ast_register_application(setcdruserfield_app, setcdruserfield_exec, setcdruserfield_synopsis, setcdruserfield_descrip);
169 res |= ast_register_application(appendcdruserfield_app, appendcdruserfield_exec, appendcdruserfield_synopsis, appendcdruserfield_descrip);
170 res |= ast_manager_register("SetCDRUserField", EVENT_FLAG_CALL, action_setcdruserfield, "Set the CDR UserField");
172 return res;
175 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "CDR user field apps");