2 * Asterisk -- A telephony toolkit for Linux.
4 * Asterisk Call Manager CDR records.
6 * This program is free software, distributed under the terms of
7 * the GNU General Public License.
11 #include <sys/types.h>
18 ASTERISK_FILE_VERSION("$Revision$")
20 #include "asterisk/channel.h"
21 #include "asterisk/cdr.h"
22 #include "asterisk/module.h"
23 #include "asterisk/logger.h"
24 #include "asterisk/utils.h"
25 #include "asterisk/manager.h"
26 #include "asterisk/config.h"
28 #define DATE_FORMAT "%Y-%m-%d %T"
29 #define CONF_FILE "cdr_manager.conf"
31 static char *desc = "Asterisk Call Manager CDR Backend";
32 static char *name = "cdr_manager";
34 static int enablecdr = 0;
36 static void loadconfigurationfile(void)
39 struct ast_config *cfg;
40 struct ast_variable *v;
42 cfg = ast_config_load(CONF_FILE);
44 /* Standard configuration */
49 cat = ast_category_browse(cfg, NULL);
51 if (!strcasecmp(cat, "general")) {
52 v = ast_variable_browse(cfg, cat);
54 if (!strcasecmp(v->name, "enabled")) {
55 enablecdr = ast_true(v->value);
63 cat = ast_category_browse(cfg, cat);
66 ast_config_destroy(cfg);
69 static int manager_log(struct ast_cdr *cdr)
73 char strStartTime[80] = "";
74 char strAnswerTime[80] = "";
75 char strEndTime[80] = "";
80 t = cdr->start.tv_sec;
81 localtime_r(&t, &timeresult);
82 strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
84 if (cdr->answer.tv_sec) {
85 t = cdr->answer.tv_sec;
86 localtime_r(&t, &timeresult);
87 strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
91 localtime_r(&t, &timeresult);
92 strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
94 manager_event(EVENT_FLAG_CALL, "Cdr",
98 "DestinationContext: %s\r\n"
101 "DestinationChannel: %s\r\n"
102 "LastApplication: %s\r\n"
108 "BillableSeconds: %d\r\n"
109 "Disposition: %s\r\n"
113 cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel,
114 cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime,
115 cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition),
116 ast_cdr_flags2str(cdr->amaflags), cdr->uniqueid, cdr->userfield);
121 char *description(void)
126 int unload_module(void)
128 ast_cdr_unregister(name);
132 int load_module(void)
136 /* Configuration file */
137 loadconfigurationfile();
139 res = ast_cdr_register(name, desc, manager_log);
141 ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CDR handling\n");
149 loadconfigurationfile();
160 return ASTERISK_GPL_KEY;