2004-01-11 03:23:05 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2004-01-11 03:23:05 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
2004-01-11 03:23:05 +00:00
|
|
|
*
|
|
|
|
* Justin Huff <jjhuff@mspin.net>
|
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2004-01-11 03:23:05 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Applictions connected with CDR engine
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
|
|
|
* \author Justin Huff <jjhuff@mspin.net>
|
|
|
|
*
|
2005-11-06 15:09:47 +00:00
|
|
|
* \ingroup applications
|
2004-01-11 03:23:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#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"
|
2004-01-11 03:23:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
static char *tdesc = "CDR user field apps";
|
|
|
|
|
|
|
|
static char *setcdruserfield_descrip =
|
2004-01-11 18:37:59 +00:00
|
|
|
"[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"
|
2005-11-07 22:01:22 +00:00
|
|
|
" Also see AppendCDRUserField().\n";
|
2004-01-11 18:37:59 +00:00
|
|
|
|
2004-01-11 03:23:05 +00:00
|
|
|
|
|
|
|
static char *setcdruserfield_app = "SetCDRUserField";
|
|
|
|
static char *setcdruserfield_synopsis = "Set the CDR user field";
|
|
|
|
|
|
|
|
static char *appendcdruserfield_descrip =
|
2004-01-11 18:37:59 +00:00
|
|
|
"[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"
|
2005-11-07 22:01:22 +00:00
|
|
|
" Also see SetCDRUserField().\n";
|
2004-01-11 03:23:05 +00:00
|
|
|
|
|
|
|
static char *appendcdruserfield_app = "AppendCDRUserField";
|
|
|
|
static char *appendcdruserfield_synopsis = "Append to the CDR user field";
|
|
|
|
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
2004-03-26 06:28:56 +00:00
|
|
|
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");
|
|
|
|
|
2004-05-09 07:51:44 +00:00
|
|
|
if (ast_strlen_zero(channel)) {
|
2004-03-26 06:28:56 +00:00
|
|
|
astman_send_error(s, m, "No Channel specified");
|
|
|
|
return 0;
|
|
|
|
}
|
2004-05-09 07:51:44 +00:00
|
|
|
if (ast_strlen_zero(userfield)) {
|
2004-03-26 06:28:56 +00:00
|
|
|
astman_send_error(s, m, "No UserField specified");
|
|
|
|
return 0;
|
|
|
|
}
|
2005-06-06 02:29:18 +00:00
|
|
|
c = ast_get_channel_by_name_locked(channel);
|
2004-03-26 06:28:56 +00:00
|
|
|
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);
|
2004-05-20 16:30:10 +00:00
|
|
|
ast_mutex_unlock(&c->lock);
|
2004-03-26 06:28:56 +00:00
|
|
|
astman_send_ack(s, m, "CDR Userfield Set");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-11 03:23:05 +00:00
|
|
|
static int setcdruserfield_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
|
|
|
struct localuser *u;
|
|
|
|
int res = 0;
|
|
|
|
|
2005-10-19 18:19:02 +00:00
|
|
|
LOCAL_USER_ADD(u);
|
|
|
|
|
|
|
|
if (chan->cdr && data) {
|
2004-01-11 03:23:05 +00:00
|
|
|
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;
|
|
|
|
|
2005-10-19 18:19:02 +00:00
|
|
|
LOCAL_USER_ADD(u);
|
|
|
|
|
|
|
|
if (chan->cdr && data) {
|
2004-01-11 03:23:05 +00:00
|
|
|
ast_cdr_appenduserfield(chan, (char*)data);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static int unload_module(void *mod)
|
2004-01-11 03:23:05 +00:00
|
|
|
{
|
|
|
|
int res;
|
2005-10-18 22:52:21 +00:00
|
|
|
|
2004-01-11 03:23:05 +00:00
|
|
|
res = ast_unregister_application(setcdruserfield_app);
|
|
|
|
res |= ast_unregister_application(appendcdruserfield_app);
|
2005-10-18 22:52:21 +00:00
|
|
|
res |= ast_manager_unregister("SetCDRUserField");
|
|
|
|
|
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
|
|
|
|
2004-01-11 03:23:05 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static int load_module(void *mod)
|
2004-01-11 03:23:05 +00:00
|
|
|
{
|
|
|
|
int res;
|
2005-10-18 22:52:21 +00:00
|
|
|
|
2004-01-11 03:23:05 +00:00
|
|
|
res = ast_register_application(setcdruserfield_app, setcdruserfield_exec, setcdruserfield_synopsis, setcdruserfield_descrip);
|
|
|
|
res |= ast_register_application(appendcdruserfield_app, appendcdruserfield_exec, appendcdruserfield_synopsis, appendcdruserfield_descrip);
|
2005-10-18 22:52:21 +00:00
|
|
|
res |= ast_manager_register("SetCDRUserField", EVENT_FLAG_CALL, action_setcdruserfield, "Set the CDR UserField");
|
|
|
|
|
2004-01-11 03:23:05 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static const char *description(void)
|
2004-01-11 03:23:05 +00:00
|
|
|
{
|
|
|
|
return tdesc;
|
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static const char *key(void)
|
2004-01-11 03:23:05 +00:00
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|
2006-04-14 14:08:19 +00:00
|
|
|
|
|
|
|
STD_MOD1;
|