#include "asterisk.h"
#include <time.h>
#include "asterisk/paths.h"
#include "asterisk/channel.h"
#include "asterisk/cdr.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
Go to the source code of this file.
Defines | |
#define | CUSTOM_LOG_DIR "/cdr_custom" |
#define | DATE_FORMAT "%Y-%m-%d %T" |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | custom_log (struct ast_cdr *cdr) |
static int | load_config (int reload) |
static int | load_module (void) |
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 = "Customizable Comma Separated Values 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 |
static char | format [1024] = "" |
static ast_mutex_t | lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) |
static char | master [PATH_MAX] |
static ast_mutex_t | mf_lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) |
static char * | name = "cdr-custom" |
Definition in file cdr_custom.c.
#define CUSTOM_LOG_DIR "/cdr_custom" |
Definition at line 48 of file cdr_custom.c.
#define DATE_FORMAT "%Y-%m-%d %T" |
Definition at line 50 of file cdr_custom.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 169 of file cdr_custom.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 169 of file cdr_custom.c.
static int custom_log | ( | struct ast_cdr * | cdr | ) | [static] |
Definition at line 105 of file cdr_custom.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_strlen_zero(), buf, ast_channel::cdr, dummy(), errno, LOG_ERROR, mf_lock, and pbx_substitute_variables_helper().
Referenced by load_module().
00106 { 00107 FILE *mf = NULL; 00108 00109 /* Make sure we have a big enough buf */ 00110 char buf[2048]; 00111 struct ast_channel dummy; 00112 00113 /* Abort if no master file is specified */ 00114 if (ast_strlen_zero(master)) 00115 return 0; 00116 00117 /* Quite possibly the first use of a static struct ast_channel, we need it so the var funcs will work */ 00118 memset(&dummy, 0, sizeof(dummy)); 00119 dummy.cdr = cdr; 00120 pbx_substitute_variables_helper(&dummy, format, buf, sizeof(buf) - 1); 00121 00122 /* because of the absolutely unconditional need for the 00123 highest reliability possible in writing billing records, 00124 we open write and close the log file each time */ 00125 ast_mutex_lock(&mf_lock); 00126 mf = fopen(master, "a"); 00127 if (mf) { 00128 fputs(buf, mf); 00129 fflush(mf); /* be particularly anal here */ 00130 fclose(mf); 00131 mf = NULL; 00132 ast_mutex_unlock(&mf_lock); 00133 } else { 00134 ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n", master, strerror(errno)); 00135 ast_mutex_unlock(&mf_lock); 00136 } 00137 00138 return 0; 00139 }
static int load_config | ( | int | reload | ) | [static] |
Definition at line 60 of file cdr_custom.c.
References ast_config_AST_LOG_DIR, ast_config_destroy(), ast_config_load, ast_copy_string(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_strlen_zero(), ast_variable_browse(), CONFIG_FLAG_FILEUNCHANGED, config_flags, CONFIG_STATUS_FILEUNCHANGED, lock, LOG_NOTICE, LOG_WARNING, and var.
00061 { 00062 struct ast_config *cfg; 00063 struct ast_variable *var; 00064 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; 00065 int res = -1; 00066 00067 if ((cfg = ast_config_load("cdr_custom.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) 00068 return 0; 00069 00070 strcpy(format, ""); 00071 strcpy(master, ""); 00072 ast_mutex_lock(&lock); 00073 if (cfg) { 00074 var = ast_variable_browse(cfg, "mappings"); 00075 while(var) { 00076 if (!ast_strlen_zero(var->name) && !ast_strlen_zero(var->value)) { 00077 if (strlen(var->value) > (sizeof(format) - 1)) 00078 ast_log(LOG_WARNING, "Format string too long, will be truncated, at line %d\n", var->lineno); 00079 ast_copy_string(format, var->value, sizeof(format) - 1); 00080 strcat(format,"\n"); 00081 snprintf(master, sizeof(master),"%s/%s/%s", ast_config_AST_LOG_DIR, name, var->name); 00082 if (var->next) { 00083 ast_log(LOG_NOTICE, "Sorry, only one mapping is supported at this time, mapping '%s' will be ignored at line %d.\n", var->next->name, var->next->lineno); 00084 break; 00085 } 00086 } else 00087 ast_log(LOG_NOTICE, "Mapping must have both filename and format at line %d\n", var->lineno); 00088 var = var->next; 00089 } 00090 ast_config_destroy(cfg); 00091 res = 0; 00092 } else { 00093 if (reload) 00094 ast_log(LOG_WARNING, "Failed to reload configuration file.\n"); 00095 else 00096 ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n"); 00097 } 00098 ast_mutex_unlock(&lock); 00099 00100 return res; 00101 }
static int load_module | ( | void | ) | [static] |
Definition at line 147 of file cdr_custom.c.
References ast_cdr_register(), ast_log(), AST_MODULE_LOAD_DECLINE, custom_log(), load_config(), and LOG_ERROR.
00148 { 00149 int res = 0; 00150 00151 if (!load_config(0)) { 00152 res = ast_cdr_register(name, ast_module_info->description, custom_log); 00153 if (res) 00154 ast_log(LOG_ERROR, "Unable to register custom CDR handling\n"); 00155 return res; 00156 } else 00157 return AST_MODULE_LOAD_DECLINE; 00158 }
static int reload | ( | void | ) | [static] |
Definition at line 160 of file cdr_custom.c.
References load_config().
00161 { 00162 return load_config(1); 00163 }
static int unload_module | ( | void | ) | [static] |
Definition at line 141 of file cdr_custom.c.
References ast_cdr_unregister().
00142 { 00143 ast_cdr_unregister(name); 00144 return 0; 00145 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Customizable Comma Separated Values 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 169 of file cdr_custom.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 169 of file cdr_custom.c.
char format[1024] = "" [static] |
Definition at line 58 of file cdr_custom.c.
ast_mutex_t lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static] |
Definition at line 52 of file cdr_custom.c.
char master[PATH_MAX] [static] |
Definition at line 57 of file cdr_custom.c.
Referenced by dahdi_bridge(), dahdi_link(), and dahdi_unlink().
ast_mutex_t mf_lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static] |
Definition at line 53 of file cdr_custom.c.
char* name = "cdr-custom" [static] |
Definition at line 55 of file cdr_custom.c.