From 2974f32e4f200726ffdcf7f2a5d9f22a47f6014e Mon Sep 17 00:00:00 2001 From: markster Date: Sun, 25 Jul 2004 14:56:34 +0000 Subject: Add Manager CDR (off by default) (bug #2127) courtesy cybershield git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3509 f38db490-d61c-443f-a65b-d21fe96a405b --- cdr/cdr_manager.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100755 cdr/cdr_manager.c (limited to 'cdr/cdr_manager.c') diff --git a/cdr/cdr_manager.c b/cdr/cdr_manager.c new file mode 100755 index 000000000..1ebc58e73 --- /dev/null +++ b/cdr/cdr_manager.c @@ -0,0 +1,158 @@ +/* + * Asterisk -- A telephony toolkit for Linux. + * + * Asterisk Call Manager CDR records. + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "../asterisk.h" +#include "../astconf.h" +#include +#include +#include + +#define DATE_FORMAT "%Y-%m-%d %T" +#define CONF_FILE "cdr_manager.conf" + +static char *desc = "Asterisk Call Manager CDR Backend"; +static char *name = "cdr_as"; + +static int enablecdr = 0; + +static void loadconfigurationfile(void) +{ + char *cat; + struct ast_config *cfg; + struct ast_variable *v; + + cfg = ast_load(CONF_FILE); + if (!cfg) { + /* Standard configuration */ + enablecdr = 0; + return; + } + + cat = ast_category_browse(cfg, NULL); + while (cat) { + if (!strcasecmp(cat, "general")) { + v = ast_variable_browse(cfg, cat); + while (v) { + if (!strcasecmp(v->name, "enabled")) { + enablecdr = ast_true(v->value); + } + + v = v->next; + } + } + + /* Next category */ + cat = ast_category_browse(cfg, cat); + } + + ast_destroy(cfg); +} + +static int manager_log(struct ast_cdr *cdr) +{ + time_t t; + struct tm timeresult; + char strStartTime[80] = ""; + char strAnswerTime[80] = ""; + char strEndTime[80] = ""; + + if (!enablecdr) + return 0; + + t = cdr->start.tv_sec; + localtime_r(&t, &timeresult); + strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult); + + if (cdr->answer.tv_sec) { + t = cdr->answer.tv_sec; + localtime_r(&t, &timeresult); + strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult); + } + + t = cdr->end.tv_sec; + localtime_r(&t, &timeresult); + strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult); + + manager_event(EVENT_FLAG_CALL, "Cdr", + "AccountCode: %s\r\n" + "Source: %s\r\n" + "Destination: %s\r\n" + "DestinationContext: %s\r\n" + "CallerID: %s\r\n" + "Channel: %s\r\n" + "DestinationChannel: %s\r\n" + "LastApplication: %s\r\n" + "LastData: %s\r\n" + "StartTime: %s\r\n" + "AnswerTime: %s\r\n" + "EndTime: %s\r\n" + "Duration: %d\r\n" + "BillableSeconds: %d\r\n" + "Disposition: %s\r\n" + "AMAFlags: %s\r\n" + "UniqueID: %s\r\n" + "UserField: %s\r\n", + cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel, + cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime, + cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), + ast_cdr_flags2str(cdr->amaflags), cdr->uniqueid, cdr->userfield); + + return 0; +} + +char *description(void) +{ + return desc; +} + +int unload_module(void) +{ + ast_cdr_unregister(name); + return 0; +} + +int load_module(void) +{ + int res; + + /* Configuration file */ + loadconfigurationfile(); + + res = ast_cdr_register(name, desc, manager_log); + if (res) { + ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CDR handling\n"); + } + + return res; +} + +int reload(void) +{ + loadconfigurationfile(); + return 0; +} + +int usecount(void) +{ + return 0; +} + +char *key() +{ + return ASTERISK_GPL_KEY; +} -- cgit v1.2.3