#include "asterisk.h"
#include <time.h>
#include "asterisk/channel.h"
#include "asterisk/cdr.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "asterisk/manager.h"
#include "asterisk/config.h"
#include "asterisk/pbx.h"
Go to the source code of this file.
Defines | |
#define | CONF_FILE "cdr_manager.conf" |
#define | CUSTOM_FIELDS_BUF_SIZE 1024 |
#define | DATE_FORMAT "%Y-%m-%d %T" |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | load_config (int reload) |
static int | load_module (void) |
static int | manager_log (struct ast_cdr *cdr) |
static int | reload (void) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Asterisk Manager Interface CDR Backend" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, .reload = reload, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
ast_str * | customfields |
static int | enablecdr = 0 |
static char * | name = "cdr_manager" |
See also
Definition in file cdr_manager.c.
#define CONF_FILE "cdr_manager.conf" |
#define CUSTOM_FIELDS_BUF_SIZE 1024 |
#define DATE_FORMAT "%Y-%m-%d %T" |
Definition at line 42 of file cdr_manager.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 204 of file cdr_manager.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 204 of file cdr_manager.c.
static int load_config | ( | int | reload | ) | [static] |
Definition at line 53 of file cdr_manager.c.
References ast_category_browse(), ast_cdr_register(), ast_cdr_unregister(), ast_config_destroy(), ast_config_load, ast_free, ast_log(), ast_str_append(), ast_str_create(), ast_strlen_zero(), ast_true(), ast_variable_browse(), CONF_FILE, CONFIG_FLAG_FILEUNCHANGED, config_flags, CONFIG_STATUS_FILEUNCHANGED, CUSTOM_FIELDS_BUF_SIZE, customfields, ast_str::len, LOG_NOTICE, LOG_WARNING, manager_log(), ast_variable::name, ast_variable::next, ast_str::used, and ast_variable::value.
00054 { 00055 char *cat = NULL; 00056 struct ast_config *cfg; 00057 struct ast_variable *v; 00058 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; 00059 int newenablecdr = 0; 00060 00061 cfg = ast_config_load(CONF_FILE, config_flags); 00062 if (cfg == CONFIG_STATUS_FILEUNCHANGED) 00063 return 0; 00064 00065 if (reload && customfields) { 00066 ast_free(customfields); 00067 } 00068 customfields = NULL; 00069 00070 if (!cfg) { 00071 /* Standard configuration */ 00072 ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n"); 00073 if (enablecdr) 00074 ast_cdr_unregister(name); 00075 enablecdr = 0; 00076 return 0; 00077 } 00078 00079 while ( (cat = ast_category_browse(cfg, cat)) ) { 00080 if (!strcasecmp(cat, "general")) { 00081 v = ast_variable_browse(cfg, cat); 00082 while (v) { 00083 if (!strcasecmp(v->name, "enabled")) 00084 newenablecdr = ast_true(v->value); 00085 00086 v = v->next; 00087 } 00088 } else if (!strcasecmp(cat, "mappings")) { 00089 customfields = ast_str_create(CUSTOM_FIELDS_BUF_SIZE); 00090 v = ast_variable_browse(cfg, cat); 00091 while (v) { 00092 if (customfields && !ast_strlen_zero(v->name) && !ast_strlen_zero(v->value)) { 00093 if( (customfields->used + strlen(v->value) + strlen(v->name) + 14) < customfields->len) { 00094 ast_str_append(&customfields, -1, "%s: ${CDR(%s)}\r\n", v->value, v->name); 00095 ast_log(LOG_NOTICE, "Added mapping %s: ${CDR(%s)}\n", v->value, v->name); 00096 } else { 00097 ast_log(LOG_WARNING, "No more buffer space to add other custom fields\n"); 00098 break; 00099 } 00100 00101 } 00102 v = v->next; 00103 } 00104 } 00105 } 00106 00107 ast_config_destroy(cfg); 00108 00109 if (enablecdr && !newenablecdr) 00110 ast_cdr_unregister(name); 00111 else if (!enablecdr && newenablecdr) 00112 ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log); 00113 enablecdr = newenablecdr; 00114 00115 return 1; 00116 }
static int load_module | ( | void | ) | [static] |
Definition at line 186 of file cdr_manager.c.
References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and load_config().
00187 { 00188 /* Configuration file */ 00189 if (!load_config(0)) 00190 return AST_MODULE_LOAD_DECLINE; 00191 00192 return AST_MODULE_LOAD_SUCCESS; 00193 }
static int manager_log | ( | struct ast_cdr * | cdr | ) | [static] |
Definition at line 118 of file cdr_manager.c.
References ast_cdr::accountcode, ast_cdr::amaflags, ast_cdr::answer, ast_cdr_disp2str(), ast_cdr_flags2str(), ast_localtime(), ast_strftime(), ast_cdr::billsec, buf, ast_channel::cdr, ast_cdr::channel, ast_cdr::clid, CUSTOM_FIELDS_BUF_SIZE, customfields, DATE_FORMAT, ast_cdr::dcontext, ast_cdr::disposition, ast_cdr::dst, ast_cdr::dstchannel, dummy(), ast_cdr::duration, ast_cdr::end, EVENT_FLAG_CDR, ast_cdr::lastapp, ast_cdr::lastdata, manager_event, pbx_substitute_variables_helper(), ast_cdr::src, ast_cdr::start, ast_str::str, ast_cdr::uniqueid, ast_str::used, and ast_cdr::userfield.
Referenced by load_config().
00119 { 00120 struct ast_tm timeresult; 00121 char strStartTime[80] = ""; 00122 char strAnswerTime[80] = ""; 00123 char strEndTime[80] = ""; 00124 char buf[CUSTOM_FIELDS_BUF_SIZE]; 00125 struct ast_channel dummy; 00126 00127 if (!enablecdr) 00128 return 0; 00129 00130 ast_localtime(&cdr->start, &timeresult, NULL); 00131 ast_strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult); 00132 00133 if (cdr->answer.tv_sec) { 00134 ast_localtime(&cdr->answer, &timeresult, NULL); 00135 ast_strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult); 00136 } 00137 00138 ast_localtime(&cdr->end, &timeresult, NULL); 00139 ast_strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult); 00140 00141 buf[0] = 0; 00142 /* Custom fields handling */ 00143 if (customfields != NULL && customfields->used > 0) { 00144 memset(&dummy, 0, sizeof(dummy)); 00145 dummy.cdr = cdr; 00146 pbx_substitute_variables_helper(&dummy, customfields->str, buf, sizeof(buf) - 1); 00147 } 00148 00149 manager_event(EVENT_FLAG_CDR, "Cdr", 00150 "AccountCode: %s\r\n" 00151 "Source: %s\r\n" 00152 "Destination: %s\r\n" 00153 "DestinationContext: %s\r\n" 00154 "CallerID: %s\r\n" 00155 "Channel: %s\r\n" 00156 "DestinationChannel: %s\r\n" 00157 "LastApplication: %s\r\n" 00158 "LastData: %s\r\n" 00159 "StartTime: %s\r\n" 00160 "AnswerTime: %s\r\n" 00161 "EndTime: %s\r\n" 00162 "Duration: %ld\r\n" 00163 "BillableSeconds: %ld\r\n" 00164 "Disposition: %s\r\n" 00165 "AMAFlags: %s\r\n" 00166 "UniqueID: %s\r\n" 00167 "UserField: %s\r\n" 00168 "%s", 00169 cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel, 00170 cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime, 00171 cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), 00172 ast_cdr_flags2str(cdr->amaflags), cdr->uniqueid, cdr->userfield,buf); 00173 00174 return 0; 00175 }
static int reload | ( | void | ) | [static] |
Definition at line 195 of file cdr_manager.c.
References load_config().
00196 { 00197 return load_config(1); 00198 }
static int unload_module | ( | void | ) | [static] |
Definition at line 177 of file cdr_manager.c.
References ast_cdr_unregister(), ast_free, and customfields.
00178 { 00179 ast_cdr_unregister(name); 00180 if (customfields) 00181 ast_free(customfields); 00182 00183 return 0; 00184 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Asterisk Manager Interface CDR Backend" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, .reload = reload, } [static] |
Definition at line 204 of file cdr_manager.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 204 of file cdr_manager.c.
struct ast_str* customfields |
Definition at line 49 of file cdr_manager.c.
Referenced by load_config(), manager_log(), and unload_module().
int enablecdr = 0 [static] |
Definition at line 48 of file cdr_manager.c.
char* name = "cdr_manager" [static] |
Definition at line 46 of file cdr_manager.c.