Wed Oct 28 11:45:51 2009

Asterisk developer's documentation


cdr_manager.c File Reference

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"

Include dependency graph for cdr_manager.c:

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 void fini_customfields_lock (void)
static void init_customfields_lock (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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, }
static const struct
ast_module_info
ast_module_info = &__mod_info
static struct ast_strcustomfields
static ast_rwlock_t customfields_lock
static int enablecdr = 0
static char * name = "cdr_manager"


Detailed Description

Asterisk Call Manager CDR records.

See also

Definition in file cdr_manager.c.


Define Documentation

#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.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 216 of file cdr_manager.c.

static void __unreg_module ( void   )  [static]

Definition at line 216 of file cdr_manager.c.

static void fini_customfields_lock ( void   )  [static]

Definition at line 51 of file cdr_manager.c.

00056 {

static void init_customfields_lock ( void   )  [static]

Definition at line 51 of file cdr_manager.c.

00056 {

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_strlen_zero(), ast_true(), ast_variable_browse(), CONF_FILE, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEUNCHANGED, CUSTOM_FIELDS_BUF_SIZE, customfields_lock, ast_str::len, LOG_NOTICE, LOG_WARNING, manager_log(), ast_variable::name, ast_variable::next, ast_str::used, and ast_variable::value.

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) {
00069       /* Standard configuration */
00070       ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
00071       if (enablecdr)
00072          ast_cdr_unregister(name);
00073       enablecdr = 0;
00074       return -1;
00075    }
00076    
00077    if (reload) {
00078       ast_rwlock_wrlock(&customfields_lock);
00079    }
00080 
00081    if (reload && customfields) {
00082       ast_free(customfields);
00083       customfields = NULL;
00084    }
00085 
00086    while ( (cat = ast_category_browse(cfg, cat)) ) {
00087       if (!strcasecmp(cat, "general")) {
00088          v = ast_variable_browse(cfg, cat);
00089          while (v) {
00090             if (!strcasecmp(v->name, "enabled"))
00091                newenablecdr = ast_true(v->value);
00092             
00093             v = v->next;
00094          }
00095       } else if (!strcasecmp(cat, "mappings")) {
00096          customfields = ast_str_create(CUSTOM_FIELDS_BUF_SIZE);
00097          v = ast_variable_browse(cfg, cat);
00098          while (v) {
00099             if (customfields && !ast_strlen_zero(v->name) && !ast_strlen_zero(v->value)) {
00100                if( (customfields->used + strlen(v->value) + strlen(v->name) + 14) < customfields->len) {
00101                   ast_str_append(&customfields, -1, "%s: ${CDR(%s)}\r\n", v->value, v->name);
00102                   ast_log(LOG_NOTICE, "Added mapping %s: ${CDR(%s)}\n", v->value, v->name);
00103                } else {
00104                   ast_log(LOG_WARNING, "No more buffer space to add other custom fields\n");
00105                   break;
00106                }
00107                
00108             }
00109             v = v->next;
00110          }
00111       }
00112    }
00113    
00114    if (reload) {
00115       ast_rwlock_unlock(&customfields_lock);
00116    }
00117 
00118    ast_config_destroy(cfg);
00119 
00120    if (enablecdr && !newenablecdr)
00121       ast_cdr_unregister(name);
00122    else if (!enablecdr && newenablecdr)
00123       ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log);
00124    enablecdr = newenablecdr;
00125 
00126    return 0;
00127 }

static int load_module ( void   )  [static]

Definition at line 198 of file cdr_manager.c.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and load_config().

00199 {
00200    if (load_config(0)) {
00201       return AST_MODULE_LOAD_DECLINE;
00202    }
00203 
00204    return AST_MODULE_LOAD_SUCCESS;
00205 }

static int manager_log ( struct ast_cdr cdr  )  [static]

Definition at line 129 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_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_str::str, ast_cdr::uniqueid, and ast_cdr::userfield.

Referenced by load_config().

00130 {
00131    struct ast_tm timeresult;
00132    char strStartTime[80] = "";
00133    char strAnswerTime[80] = "";
00134    char strEndTime[80] = "";
00135    char buf[CUSTOM_FIELDS_BUF_SIZE];
00136    struct ast_channel dummy;
00137 
00138    if (!enablecdr)
00139       return 0;
00140 
00141    ast_localtime(&cdr->start, &timeresult, NULL);
00142    ast_strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
00143    
00144    if (cdr->answer.tv_sec) {
00145       ast_localtime(&cdr->answer, &timeresult, NULL);
00146       ast_strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
00147    }
00148 
00149    ast_localtime(&cdr->end, &timeresult, NULL);
00150    ast_strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
00151 
00152    buf[0] = '\0';
00153    ast_rwlock_rdlock(&customfields_lock);
00154    if (customfields && ast_str_strlen(customfields)) {
00155       memset(&dummy, 0, sizeof(dummy));
00156       dummy.cdr = cdr;
00157       pbx_substitute_variables_helper(&dummy, customfields->str, buf, sizeof(buf) - 1);
00158    }
00159    ast_rwlock_unlock(&customfields_lock);
00160 
00161    manager_event(EVENT_FLAG_CDR, "Cdr",
00162        "AccountCode: %s\r\n"
00163        "Source: %s\r\n"
00164        "Destination: %s\r\n"
00165        "DestinationContext: %s\r\n"
00166        "CallerID: %s\r\n"
00167        "Channel: %s\r\n"
00168        "DestinationChannel: %s\r\n"
00169        "LastApplication: %s\r\n"
00170        "LastData: %s\r\n"
00171        "StartTime: %s\r\n"
00172        "AnswerTime: %s\r\n"
00173        "EndTime: %s\r\n"
00174        "Duration: %ld\r\n"
00175        "BillableSeconds: %ld\r\n"
00176        "Disposition: %s\r\n"
00177        "AMAFlags: %s\r\n"
00178        "UniqueID: %s\r\n"
00179        "UserField: %s\r\n"
00180        "%s",
00181        cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel,
00182        cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime,
00183        cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition),
00184        ast_cdr_flags2str(cdr->amaflags), cdr->uniqueid, cdr->userfield,buf);
00185 
00186    return 0;
00187 }

static int reload ( void   )  [static]

Definition at line 207 of file cdr_manager.c.

References load_config().

00208 {
00209    return load_config(1);
00210 }

static int unload_module ( void   )  [static]

Definition at line 189 of file cdr_manager.c.

References ast_cdr_unregister(), and ast_free.

00190 {
00191    ast_cdr_unregister(name);
00192    if (customfields)
00193       ast_free(customfields);
00194 
00195    return 0;
00196 }


Variable Documentation

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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } [static]

Definition at line 216 of file cdr_manager.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 216 of file cdr_manager.c.

struct ast_str* customfields [static]

Definition at line 50 of file cdr_manager.c.

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.


Generated on Wed Oct 28 11:45:51 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6