2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2004 - 2005
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
19 * \brief Asterisk Call Manager CDR records.
24 * \arg \ref Config_ami
27 #include <sys/types.h>
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
36 #include "asterisk/channel.h"
37 #include "asterisk/cdr.h"
38 #include "asterisk/module.h"
39 #include "asterisk/logger.h"
40 #include "asterisk/utils.h"
41 #include "asterisk/manager.h"
42 #include "asterisk/config.h"
44 #define DATE_FORMAT "%Y-%m-%d %T"
45 #define CONF_FILE "cdr_manager.conf"
47 static char *desc = "Asterisk Call Manager CDR Backend";
48 static char *name = "cdr_manager";
50 static int enablecdr = 0;
52 static void loadconfigurationfile(void)
55 struct ast_config *cfg;
56 struct ast_variable *v;
58 cfg = ast_config_load(CONF_FILE);
60 /* Standard configuration */
65 cat = ast_category_browse(cfg, NULL);
67 if (!strcasecmp(cat, "general")) {
68 v = ast_variable_browse(cfg, cat);
70 if (!strcasecmp(v->name, "enabled")) {
71 enablecdr = ast_true(v->value);
79 cat = ast_category_browse(cfg, cat);
82 ast_config_destroy(cfg);
85 static int manager_log(struct ast_cdr *cdr)
89 char strStartTime[80] = "";
90 char strAnswerTime[80] = "";
91 char strEndTime[80] = "";
96 t = cdr->start.tv_sec;
97 localtime_r(&t, &timeresult);
98 strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
100 if (cdr->answer.tv_sec) {
101 t = cdr->answer.tv_sec;
102 localtime_r(&t, &timeresult);
103 strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
107 localtime_r(&t, &timeresult);
108 strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
110 manager_event(EVENT_FLAG_CALL, "Cdr",
111 "AccountCode: %s\r\n"
113 "Destination: %s\r\n"
114 "DestinationContext: %s\r\n"
117 "DestinationChannel: %s\r\n"
118 "LastApplication: %s\r\n"
124 "BillableSeconds: %d\r\n"
125 "Disposition: %s\r\n"
129 cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel,
130 cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime,
131 cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition),
132 ast_cdr_flags2str(cdr->amaflags), cdr->uniqueid, cdr->userfield);
137 char *description(void)
142 int unload_module(void)
144 ast_cdr_unregister(name);
148 int load_module(void)
152 /* Configuration file */
153 loadconfigurationfile();
155 res = ast_cdr_register(name, desc, manager_log);
157 ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CDR handling\n");
165 loadconfigurationfile();
176 return ASTERISK_GPL_KEY;