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