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.
21 * \brief Applictions connected with CDR engine
23 * \author Justin Huff <jjhuff@mspin.net>
25 * \ingroup applications
30 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
32 #include <sys/types.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
=
48 "SetCDRUserField(value)\n\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
=
64 "AppendCDRUserField(value)\n\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");
89 if (ast_strlen_zero(userfield
)) {
90 astman_send_error(s
, m
, "No UserField specified");
93 c
= ast_get_channel_by_name_locked(channel
);
95 astman_send_error(s
, m
, "No such channel");
99 ast_cdr_appenduserfield(c
, userfield
);
101 ast_cdr_setuserfield(c
, userfield
);
102 ast_mutex_unlock(&c
->lock
);
103 astman_send_ack(s
, m
, "CDR Userfield Set");
107 static int setcdruserfield_exec(struct ast_channel
*chan
, void *data
)
109 struct ast_module_user
*u
;
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
);
121 ast_log(LOG_WARNING
, "SetCDRUserField is deprecated. Please use CDR(userfield) instead.\n");
124 ast_module_user_remove(u
);
129 static int appendcdruserfield_exec(struct ast_channel
*chan
, void *data
)
131 struct ast_module_user
*u
;
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
);
143 ast_log(LOG_WARNING
, "AppendCDRUserField is deprecated. Please use CDR(userfield) instead.\n");
146 ast_module_user_remove(u
);
151 static int unload_module(void)
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();
164 static int load_module(void)
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");
175 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "CDR user field apps");