create the IAX2 processing threads as background threads so they will use smaller...
[asterisk-bristuff.git] / apps / app_setcdruserfield.c
blobf6c83f48bc82b5a932fe9fb89c55e6f7a1c771d6
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";
58 static char *setcdruserfield_app = "SetCDRUserField";
59 static char *setcdruserfield_synopsis = "Set the CDR user field";
61 static char *appendcdruserfield_descrip =
62 "[Synopsis]\n"
63 "AppendCDRUserField(value)\n\n"
64 "[Description]\n"
65 "AppendCDRUserField(value): Append value to the CDR user field\n"
66 " The Call Data Record (CDR) user field is an extra field you\n"
67 " can use for data not stored anywhere else in the record.\n"
68 " CDR records can be used for billing or storing other arbitrary data\n"
69 " (I.E. telephone survey responses)\n"
70 " Also see SetCDRUserField().\n";
72 static char *appendcdruserfield_app = "AppendCDRUserField";
73 static char *appendcdruserfield_synopsis = "Append to the CDR user field";
76 static int action_setcdruserfield(struct mansession *s, struct message *m)
78 struct ast_channel *c = NULL;
79 char *userfield = astman_get_header(m, "UserField");
80 char *channel = astman_get_header(m, "Channel");
81 char *append = astman_get_header(m, "Append");
83 if (ast_strlen_zero(channel)) {
84 astman_send_error(s, m, "No Channel specified");
85 return 0;
87 if (ast_strlen_zero(userfield)) {
88 astman_send_error(s, m, "No UserField specified");
89 return 0;
91 c = ast_get_channel_by_name_locked(channel);
92 if (!c) {
93 astman_send_error(s, m, "No such channel");
94 return 0;
96 if (ast_true(append))
97 ast_cdr_appenduserfield(c, userfield);
98 else
99 ast_cdr_setuserfield(c, userfield);
100 ast_mutex_unlock(&c->lock);
101 astman_send_ack(s, m, "CDR Userfield Set");
102 return 0;
105 static int setcdruserfield_exec(struct ast_channel *chan, void *data)
107 struct ast_module_user *u;
108 int res = 0;
109 static int dep_warning = 0;
111 u = ast_module_user_add(chan);
113 if (chan->cdr && data) {
114 ast_cdr_setuserfield(chan, (char*)data);
117 if (!dep_warning) {
118 dep_warning = 1;
119 ast_log(LOG_WARNING, "SetCDRUserField is deprecated. Please use CDR(userfield) instead.\n");
122 ast_module_user_remove(u);
124 return res;
127 static int appendcdruserfield_exec(struct ast_channel *chan, void *data)
129 struct ast_module_user *u;
130 int res = 0;
131 static int dep_warning = 0;
133 u = ast_module_user_add(chan);
135 if (chan->cdr && data) {
136 ast_cdr_appenduserfield(chan, (char*)data);
139 if (!dep_warning) {
140 dep_warning = 1;
141 ast_log(LOG_WARNING, "AppendCDRUserField is deprecated. Please use CDR(userfield) instead.\n");
144 ast_module_user_remove(u);
146 return res;
149 static int unload_module(void)
151 int res;
153 res = ast_unregister_application(setcdruserfield_app);
154 res |= ast_unregister_application(appendcdruserfield_app);
155 res |= ast_manager_unregister("SetCDRUserField");
157 ast_module_user_hangup_all();
159 return res;
162 static int load_module(void)
164 int res;
166 res = ast_register_application(setcdruserfield_app, setcdruserfield_exec, setcdruserfield_synopsis, setcdruserfield_descrip);
167 res |= ast_register_application(appendcdruserfield_app, appendcdruserfield_exec, appendcdruserfield_synopsis, appendcdruserfield_descrip);
168 res |= ast_manager_register("SetCDRUserField", EVENT_FLAG_CALL, action_setcdruserfield, "Set the CDR UserField");
170 return res;
173 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "CDR user field apps");