app_setcdruserfield.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 58939 $")
00031
00032 #include <sys/types.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035
00036 #include "asterisk/channel.h"
00037 #include "asterisk/cdr.h"
00038 #include "asterisk/module.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/logger.h"
00041 #include "asterisk/config.h"
00042 #include "asterisk/manager.h"
00043 #include "asterisk/utils.h"
00044
00045
00046 static char *setcdruserfield_descrip =
00047 "[Synopsis]\n"
00048 "SetCDRUserField(value)\n\n"
00049 "[Description]\n"
00050 "SetCDRUserField(value): Set the CDR 'user field' to value\n"
00051 " The Call Data Record (CDR) user field is an extra field you\n"
00052 " can use for data not stored anywhere else in the record.\n"
00053 " CDR records can be used for billing or storing other arbitrary data\n"
00054 " (I.E. telephone survey responses)\n"
00055 " Also see AppendCDRUserField().\n"
00056 "\nThis application is deprecated in favor of Set(CDR(userfield)=...)\n";
00057
00058
00059 static char *setcdruserfield_app = "SetCDRUserField";
00060 static char *setcdruserfield_synopsis = "Set the CDR user field";
00061
00062 static char *appendcdruserfield_descrip =
00063 "[Synopsis]\n"
00064 "AppendCDRUserField(value)\n\n"
00065 "[Description]\n"
00066 "AppendCDRUserField(value): Append value to the CDR user field\n"
00067 " The Call Data Record (CDR) user field is an extra field you\n"
00068 " can use for data not stored anywhere else in the record.\n"
00069 " CDR records can be used for billing or storing other arbitrary data\n"
00070 " (I.E. telephone survey responses)\n"
00071 " Also see SetCDRUserField().\n"
00072 "\nThis application is deprecated in favor of Set(CDR(userfield)=...)\n";
00073
00074 static char *appendcdruserfield_app = "AppendCDRUserField";
00075 static char *appendcdruserfield_synopsis = "Append to the CDR user field";
00076
00077
00078 static int action_setcdruserfield(struct mansession *s, const struct message *m)
00079 {
00080 struct ast_channel *c = NULL;
00081 const char *userfield = astman_get_header(m, "UserField");
00082 const char *channel = astman_get_header(m, "Channel");
00083 const char *append = astman_get_header(m, "Append");
00084
00085 if (ast_strlen_zero(channel)) {
00086 astman_send_error(s, m, "No Channel specified");
00087 return 0;
00088 }
00089 if (ast_strlen_zero(userfield)) {
00090 astman_send_error(s, m, "No UserField specified");
00091 return 0;
00092 }
00093 c = ast_get_channel_by_name_locked(channel);
00094 if (!c) {
00095 astman_send_error(s, m, "No such channel");
00096 return 0;
00097 }
00098 if (ast_true(append))
00099 ast_cdr_appenduserfield(c, userfield);
00100 else
00101 ast_cdr_setuserfield(c, userfield);
00102 ast_mutex_unlock(&c->lock);
00103 astman_send_ack(s, m, "CDR Userfield Set");
00104 return 0;
00105 }
00106
00107 static int setcdruserfield_exec(struct ast_channel *chan, void *data)
00108 {
00109 struct ast_module_user *u;
00110 int res = 0;
00111 static int dep_warning = 0;
00112
00113 u = ast_module_user_add(chan);
00114
00115 if (chan->cdr && data) {
00116 ast_cdr_setuserfield(chan, (char*)data);
00117 }
00118
00119 if (!dep_warning) {
00120 dep_warning = 1;
00121 ast_log(LOG_WARNING, "SetCDRUserField is deprecated. Please use CDR(userfield) instead.\n");
00122 }
00123
00124 ast_module_user_remove(u);
00125
00126 return res;
00127 }
00128
00129 static int appendcdruserfield_exec(struct ast_channel *chan, void *data)
00130 {
00131 struct ast_module_user *u;
00132 int res = 0;
00133 static int dep_warning = 0;
00134
00135 u = ast_module_user_add(chan);
00136
00137 if (chan->cdr && data) {
00138 ast_cdr_appenduserfield(chan, (char*)data);
00139 }
00140
00141 if (!dep_warning) {
00142 dep_warning = 1;
00143 ast_log(LOG_WARNING, "AppendCDRUserField is deprecated. Please use CDR(userfield) instead.\n");
00144 }
00145
00146 ast_module_user_remove(u);
00147
00148 return res;
00149 }
00150
00151 static int unload_module(void)
00152 {
00153 int res;
00154
00155 res = ast_unregister_application(setcdruserfield_app);
00156 res |= ast_unregister_application(appendcdruserfield_app);
00157 res |= ast_manager_unregister("SetCDRUserField");
00158
00159 ast_module_user_hangup_all();
00160
00161 return res;
00162 }
00163
00164 static int load_module(void)
00165 {
00166 int res;
00167
00168 res = ast_register_application(setcdruserfield_app, setcdruserfield_exec, setcdruserfield_synopsis, setcdruserfield_descrip);
00169 res |= ast_register_application(appendcdruserfield_app, appendcdruserfield_exec, appendcdruserfield_synopsis, appendcdruserfield_descrip);
00170 res |= ast_manager_register("SetCDRUserField", EVENT_FLAG_CALL, action_setcdruserfield, "Set the CDR UserField");
00171
00172 return res;
00173 }
00174
00175 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "CDR user field apps");