Asterisk Call Manager CDR records. More...
#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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, .reload = reload, } |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static struct ast_str * | customfields |
| static ast_rwlock_t | customfields_lock = PTHREAD_RWLOCK_INITIALIZER |
| static int | enablecdr = 0 |
| static char * | name = "cdr_manager" |
Asterisk Call Manager CDR records.
See also
Definition in file cdr_manager.c.
| #define CONF_FILE "cdr_manager.conf" |
Definition at line 43 of file cdr_manager.c.
Referenced by load_config().
| #define CUSTOM_FIELDS_BUF_SIZE 1024 |
Definition at line 44 of file cdr_manager.c.
Referenced by load_config(), and manager_log().
| #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 221 of file cdr_manager.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 221 of file cdr_manager.c.
| static int load_config | ( | int | reload | ) | [static] |
Definition at line 55 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_rwlock_unlock(), ast_rwlock_wrlock(), ast_str_append(), ast_str_create(), ast_str_size(), ast_str_strlen(), ast_strlen_zero(), ast_true(), ast_variable_browse(), CONF_FILE, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, CUSTOM_FIELDS_BUF_SIZE, customfields_lock, LOG_ERROR, LOG_NOTICE, LOG_WARNING, manager_log(), ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by load_module(), and reload().
00056 { 00057 char *cat = NULL; 00058 struct ast_config *cfg; 00059 struct ast_variable *v; 00060 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; 00061 int newenablecdr = 0; 00062 00063 cfg = ast_config_load(CONF_FILE, config_flags); 00064 if (cfg == CONFIG_STATUS_FILEUNCHANGED) { 00065 return 0; 00066 } 00067 00068 if (cfg == CONFIG_STATUS_FILEINVALID) { 00069 ast_log(LOG_ERROR, "Config file '%s' could not be parsed\n", CONF_FILE); 00070 return -1; 00071 } 00072 00073 if (!cfg) { 00074 /* Standard configuration */ 00075 ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n"); 00076 if (enablecdr) 00077 ast_cdr_unregister(name); 00078 enablecdr = 0; 00079 return -1; 00080 } 00081 00082 if (reload) { 00083 ast_rwlock_wrlock(&customfields_lock); 00084 } 00085 00086 if (reload && customfields) { 00087 ast_free(customfields); 00088 customfields = NULL; 00089 } 00090 00091 while ( (cat = ast_category_browse(cfg, cat)) ) { 00092 if (!strcasecmp(cat, "general")) { 00093 v = ast_variable_browse(cfg, cat); 00094 while (v) { 00095 if (!strcasecmp(v->name, "enabled")) 00096 newenablecdr = ast_true(v->value); 00097 00098 v = v->next; 00099 } 00100 } else if (!strcasecmp(cat, "mappings")) { 00101 customfields = ast_str_create(CUSTOM_FIELDS_BUF_SIZE); 00102 v = ast_variable_browse(cfg, cat); 00103 while (v) { 00104 if (customfields && !ast_strlen_zero(v->name) && !ast_strlen_zero(v->value)) { 00105 if ((ast_str_strlen(customfields) + strlen(v->value) + strlen(v->name) + 14) < ast_str_size(customfields)) { 00106 ast_str_append(&customfields, -1, "%s: ${CDR(%s)}\r\n", v->value, v->name); 00107 ast_log(LOG_NOTICE, "Added mapping %s: ${CDR(%s)}\n", v->value, v->name); 00108 } else { 00109 ast_log(LOG_WARNING, "No more buffer space to add other custom fields\n"); 00110 break; 00111 } 00112 00113 } 00114 v = v->next; 00115 } 00116 } 00117 } 00118 00119 if (reload) { 00120 ast_rwlock_unlock(&customfields_lock); 00121 } 00122 00123 ast_config_destroy(cfg); 00124 00125 if (enablecdr && !newenablecdr) 00126 ast_cdr_unregister(name); 00127 else if (!enablecdr && newenablecdr) 00128 ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log); 00129 enablecdr = newenablecdr; 00130 00131 return 0; 00132 }
| static int load_module | ( | void | ) | [static] |
Definition at line 203 of file cdr_manager.c.
References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and load_config().
00204 { 00205 if (load_config(0)) { 00206 return AST_MODULE_LOAD_DECLINE; 00207 } 00208 00209 return AST_MODULE_LOAD_SUCCESS; 00210 }
| static int manager_log | ( | struct ast_cdr * | cdr | ) | [static] |
Definition at line 134 of file cdr_manager.c.
References ast_cdr::accountcode, ast_cdr::amaflags, ast_cdr::answer, ast_cdr_disp2str(), ast_cdr_flags2str(), ast_localtime(), ast_rwlock_rdlock(), ast_rwlock_unlock(), ast_str_buffer(), ast_str_strlen(), ast_strftime(), ast_cdr::billsec, buf, ast_channel::cdr, ast_cdr::channel, ast_cdr::clid, CUSTOM_FIELDS_BUF_SIZE, customfields_lock, DATE_FORMAT, ast_cdr::dcontext, ast_cdr::disposition, ast_cdr::dst, ast_cdr::dstchannel, 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_cdr::uniqueid, and ast_cdr::userfield.
Referenced by load_config().
00135 { 00136 struct ast_tm timeresult; 00137 char strStartTime[80] = ""; 00138 char strAnswerTime[80] = ""; 00139 char strEndTime[80] = ""; 00140 char buf[CUSTOM_FIELDS_BUF_SIZE]; 00141 struct ast_channel dummy; 00142 00143 if (!enablecdr) 00144 return 0; 00145 00146 ast_localtime(&cdr->start, &timeresult, NULL); 00147 ast_strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult); 00148 00149 if (cdr->answer.tv_sec) { 00150 ast_localtime(&cdr->answer, &timeresult, NULL); 00151 ast_strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult); 00152 } 00153 00154 ast_localtime(&cdr->end, &timeresult, NULL); 00155 ast_strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult); 00156 00157 buf[0] = '\0'; 00158 ast_rwlock_rdlock(&customfields_lock); 00159 if (customfields && ast_str_strlen(customfields)) { 00160 memset(&dummy, 0, sizeof(dummy)); 00161 dummy.cdr = cdr; 00162 pbx_substitute_variables_helper(&dummy, ast_str_buffer(customfields), buf, sizeof(buf) - 1); 00163 } 00164 ast_rwlock_unlock(&customfields_lock); 00165 00166 manager_event(EVENT_FLAG_CDR, "Cdr", 00167 "AccountCode: %s\r\n" 00168 "Source: %s\r\n" 00169 "Destination: %s\r\n" 00170 "DestinationContext: %s\r\n" 00171 "CallerID: %s\r\n" 00172 "Channel: %s\r\n" 00173 "DestinationChannel: %s\r\n" 00174 "LastApplication: %s\r\n" 00175 "LastData: %s\r\n" 00176 "StartTime: %s\r\n" 00177 "AnswerTime: %s\r\n" 00178 "EndTime: %s\r\n" 00179 "Duration: %ld\r\n" 00180 "BillableSeconds: %ld\r\n" 00181 "Disposition: %s\r\n" 00182 "AMAFlags: %s\r\n" 00183 "UniqueID: %s\r\n" 00184 "UserField: %s\r\n" 00185 "%s", 00186 cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel, 00187 cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime, 00188 cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), 00189 ast_cdr_flags2str(cdr->amaflags), cdr->uniqueid, cdr->userfield,buf); 00190 00191 return 0; 00192 }
| static int reload | ( | void | ) | [static] |
Definition at line 212 of file cdr_manager.c.
References load_config().
00213 { 00214 return load_config(1); 00215 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 194 of file cdr_manager.c.
References ast_cdr_unregister(), and ast_free.
00195 { 00196 ast_cdr_unregister(name); 00197 if (customfields) 00198 ast_free(customfields); 00199 00200 return 0; 00201 }
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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, .reload = reload, } [static] |
Definition at line 221 of file cdr_manager.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 221 of file cdr_manager.c.
struct ast_str* customfields [static] |
Definition at line 50 of file cdr_manager.c.
ast_rwlock_t customfields_lock = PTHREAD_RWLOCK_INITIALIZER [static] |
Definition at line 51 of file cdr_manager.c.
Referenced by load_config(), and manager_log().
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.
1.6.2