#include "asterisk.h"
#include <sys/types.h>
#include <strings.h>
#include <unistd.h>
#include <time.h>
#include "asterisk/channel.h"
#include "asterisk/cdr.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/manager.h"
#include "asterisk/config.h"
Go to the source code of this file.
Defines | |
#define | CONF_FILE "cdr_manager.conf" |
#define | DATE_FORMAT "%Y-%m-%d %T" |
Functions | |
AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,"Asterisk Manager Interface CDR Backend",.load=load_module,.unload=unload_module,.reload=reload,) | |
static int | load_module (void) |
static int | loadconfigurationfile (void) |
static int | manager_log (struct ast_cdr *cdr) |
static int | reload (void) |
static int | unload_module (void) |
Variables | |
static int | enablecdr = 0 |
static char * | name = "cdr_manager" |
See also
Definition in file cdr_manager.c.
#define CONF_FILE "cdr_manager.conf" |
#define DATE_FORMAT "%Y-%m-%d %T" |
Definition at line 45 of file cdr_manager.c.
AST_MODULE_INFO | ( | ASTERISK_GPL_KEY | , | |
AST_MODFLAG_DEFAULT | , | |||
"Asterisk Manager Interface CDR Backend" | , | |||
. | load = load_module , |
|||
. | unload = unload_module , |
|||
. | reload = reload | |||
) |
static int load_module | ( | void | ) | [static] |
Definition at line 144 of file cdr_manager.c.
References ast_cdr_register(), ast_log(), AST_MODULE_LOAD_DECLINE, loadconfigurationfile(), LOG_ERROR, and manager_log().
00145 { 00146 int res; 00147 00148 /* Configuration file */ 00149 if (!loadconfigurationfile()) 00150 return AST_MODULE_LOAD_DECLINE; 00151 00152 res = ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log); 00153 if (res) { 00154 ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CDR handling\n"); 00155 } 00156 00157 return res; 00158 }
static int loadconfigurationfile | ( | void | ) | [static] |
Definition at line 52 of file cdr_manager.c.
References ast_category_browse(), ast_config_destroy(), ast_config_load(), ast_true(), ast_variable_browse(), CONF_FILE, ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by load_module(), and reload().
00053 { 00054 char *cat; 00055 struct ast_config *cfg; 00056 struct ast_variable *v; 00057 00058 cfg = ast_config_load(CONF_FILE); 00059 if (!cfg) { 00060 /* Standard configuration */ 00061 enablecdr = 0; 00062 return 0; 00063 } 00064 00065 cat = ast_category_browse(cfg, NULL); 00066 while (cat) { 00067 if (!strcasecmp(cat, "general")) { 00068 v = ast_variable_browse(cfg, cat); 00069 while (v) { 00070 if (!strcasecmp(v->name, "enabled")) { 00071 enablecdr = ast_true(v->value); 00072 } 00073 00074 v = v->next; 00075 } 00076 } 00077 00078 /* Next category */ 00079 cat = ast_category_browse(cfg, cat); 00080 } 00081 00082 ast_config_destroy(cfg); 00083 return 1; 00084 }
static int manager_log | ( | struct ast_cdr * | cdr | ) | [static] |
Definition at line 86 of file cdr_manager.c.
References ast_cdr::accountcode, ast_cdr::amaflags, ast_cdr::answer, ast_cdr_disp2str(), ast_cdr_flags2str(), ast_localtime(), ast_cdr::billsec, ast_cdr::channel, ast_cdr::clid, DATE_FORMAT, ast_cdr::dcontext, ast_cdr::disposition, ast_cdr::dst, ast_cdr::dstchannel, ast_cdr::duration, ast_cdr::end, EVENT_FLAG_CALL, ast_cdr::lastapp, ast_cdr::lastdata, manager_event(), ast_cdr::src, ast_cdr::start, t, ast_cdr::uniqueid, and ast_cdr::userfield.
Referenced by load_module().
00087 { 00088 time_t t; 00089 struct tm timeresult; 00090 char strStartTime[80] = ""; 00091 char strAnswerTime[80] = ""; 00092 char strEndTime[80] = ""; 00093 00094 if (!enablecdr) 00095 return 0; 00096 00097 t = cdr->start.tv_sec; 00098 ast_localtime(&t, &timeresult, NULL); 00099 strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult); 00100 00101 if (cdr->answer.tv_sec) { 00102 t = cdr->answer.tv_sec; 00103 ast_localtime(&t, &timeresult, NULL); 00104 strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult); 00105 } 00106 00107 t = cdr->end.tv_sec; 00108 ast_localtime(&t, &timeresult, NULL); 00109 strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult); 00110 00111 manager_event(EVENT_FLAG_CALL, "Cdr", 00112 "AccountCode: %s\r\n" 00113 "Source: %s\r\n" 00114 "Destination: %s\r\n" 00115 "DestinationContext: %s\r\n" 00116 "CallerID: %s\r\n" 00117 "Channel: %s\r\n" 00118 "DestinationChannel: %s\r\n" 00119 "LastApplication: %s\r\n" 00120 "LastData: %s\r\n" 00121 "StartTime: %s\r\n" 00122 "AnswerTime: %s\r\n" 00123 "EndTime: %s\r\n" 00124 "Duration: %ld\r\n" 00125 "BillableSeconds: %ld\r\n" 00126 "Disposition: %s\r\n" 00127 "AMAFlags: %s\r\n" 00128 "UniqueID: %s\r\n" 00129 "UserField: %s\r\n", 00130 cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel, 00131 cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime, 00132 cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition), 00133 ast_cdr_flags2str(cdr->amaflags), cdr->uniqueid, cdr->userfield); 00134 00135 return 0; 00136 }
static int reload | ( | void | ) | [static] |
Definition at line 160 of file cdr_manager.c.
References loadconfigurationfile().
00161 { 00162 loadconfigurationfile(); 00163 return 0; 00164 }
static int unload_module | ( | void | ) | [static] |
Definition at line 138 of file cdr_manager.c.
References ast_cdr_unregister().
00139 { 00140 ast_cdr_unregister(name); 00141 return 0; 00142 }
int enablecdr = 0 [static] |
Definition at line 50 of file cdr_manager.c.
char* name = "cdr_manager" [static] |
Definition at line 48 of file cdr_manager.c.