Sat Sep 16 05:47:41 2006

Asterisk developer's documentation


cdr_manager.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2004 - 2005
00005  *
00006  * See http://www.asterisk.org for more information about
00007  * the Asterisk project. Please do not directly contact
00008  * any of the maintainers of this project for assistance;
00009  * the project provides a web site, mailing lists and IRC
00010  * channels for your use.
00011  *
00012  * This program is free software, distributed under the terms of
00013  * the GNU General Public License Version 2. See the LICENSE file
00014  * at the top of the source tree.
00015  */
00016 
00017 /*! \file
00018  *
00019  * \brief Asterisk Call Manager CDR records.
00020  * 
00021  * See also
00022  * \arg \ref AstCDR
00023  * \arg \ref AstAMI
00024  * \arg \ref Config_ami
00025  * \ingroup cdr_drivers
00026  */
00027 
00028 #include <sys/types.h>
00029 #include <strings.h>
00030 #include <unistd.h>
00031 #include <time.h>
00032 
00033 #include "asterisk.h"
00034 
00035 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 11503 $")
00036 
00037 #include "asterisk/channel.h"
00038 #include "asterisk/cdr.h"
00039 #include "asterisk/module.h"
00040 #include "asterisk/logger.h"
00041 #include "asterisk/utils.h"
00042 #include "asterisk/manager.h"
00043 #include "asterisk/config.h"
00044 
00045 #define DATE_FORMAT  "%Y-%m-%d %T"
00046 #define CONF_FILE "cdr_manager.conf"
00047 
00048 static char *desc = "Asterisk Call Manager CDR Backend";
00049 static char *name = "cdr_manager";
00050 
00051 static int enablecdr = 0;
00052 
00053 static void loadconfigurationfile(void)
00054 {
00055    char *cat;
00056    struct ast_config *cfg;
00057    struct ast_variable *v;
00058    
00059    cfg = ast_config_load(CONF_FILE);
00060    if (!cfg) {
00061       /* Standard configuration */
00062       enablecdr = 0;
00063       return;
00064    }
00065    
00066    cat = ast_category_browse(cfg, NULL);
00067    while (cat) {
00068       if (!strcasecmp(cat, "general")) {
00069          v = ast_variable_browse(cfg, cat);
00070          while (v) {
00071             if (!strcasecmp(v->name, "enabled")) {
00072                enablecdr = ast_true(v->value);
00073             }
00074             
00075             v = v->next;
00076          }
00077       }
00078    
00079       /* Next category */
00080       cat = ast_category_browse(cfg, cat);
00081    }
00082    
00083    ast_config_destroy(cfg);
00084 }
00085 
00086 static int manager_log(struct ast_cdr *cdr)
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    localtime_r(&t, &timeresult);
00099    strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
00100    
00101    if (cdr->answer.tv_sec) {
00102          t = cdr->answer.tv_sec;
00103          localtime_r(&t, &timeresult);
00104       strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
00105    }
00106 
00107    t = cdr->end.tv_sec;
00108    localtime_r(&t, &timeresult);
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 }
00137 
00138 char *description(void)
00139 {
00140    return desc;
00141 }
00142 
00143 int unload_module(void)
00144 {
00145    ast_cdr_unregister(name);
00146    return 0;
00147 }
00148 
00149 int load_module(void)
00150 {
00151    int res;
00152 
00153    /* Configuration file */
00154    loadconfigurationfile();
00155    
00156    res = ast_cdr_register(name, desc, manager_log);
00157    if (res) {
00158       ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CDR handling\n");
00159    }
00160    
00161    return res;
00162 }
00163 
00164 int reload(void)
00165 {
00166    loadconfigurationfile();
00167    return 0;
00168 }
00169 
00170 int usecount(void)
00171 {
00172    return 0;
00173 }
00174 
00175 char *key()
00176 {
00177    return ASTERISK_GPL_KEY;
00178 }

Generated on Sat Sep 16 05:47:41 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.7