Custom Comma Separated Value CDR records. More...
#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 = "0901e4e500243c855563a2d78b0c03e4" , .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" |
Custom Comma Separated Value CDR records.
Logs in LOG_DIR/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 174 of file cdr_custom.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 174 of file cdr_custom.c.
| static int custom_log | ( | struct ast_cdr * | cdr | ) | [static] |
Definition at line 110 of file cdr_custom.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_strlen_zero(), buf, ast_channel::cdr, errno, LOG_ERROR, mf_lock, and pbx_substitute_variables_helper().
Referenced by load_module().
00111 { 00112 FILE *mf = NULL; 00113 00114 /* Make sure we have a big enough buf */ 00115 char buf[2048]; 00116 struct ast_channel dummy; 00117 00118 /* Abort if no master file is specified */ 00119 if (ast_strlen_zero(master)) 00120 return 0; 00121 00122 /* Quite possibly the first use of a static struct ast_channel, we need it so the var funcs will work */ 00123 memset(&dummy, 0, sizeof(dummy)); 00124 dummy.cdr = cdr; 00125 pbx_substitute_variables_helper(&dummy, format, buf, sizeof(buf) - 1); 00126 00127 /* because of the absolutely unconditional need for the 00128 highest reliability possible in writing billing records, 00129 we open write and close the log file each time */ 00130 ast_mutex_lock(&mf_lock); 00131 mf = fopen(master, "a"); 00132 if (mf) { 00133 fputs(buf, mf); 00134 fflush(mf); /* be particularly anal here */ 00135 fclose(mf); 00136 mf = NULL; 00137 ast_mutex_unlock(&mf_lock); 00138 } else { 00139 ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n", master, strerror(errno)); 00140 ast_mutex_unlock(&mf_lock); 00141 } 00142 00143 return 0; 00144 }
| 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_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, ast_variable::lineno, lock, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_variable::name, ast_variable::next, ast_variable::value, and var.
Referenced by load_module(), and reload().
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 if (cfg == CONFIG_STATUS_FILEINVALID) { 00071 ast_log(LOG_ERROR, "Invalid config file\n"); 00072 return 1; 00073 } 00074 00075 strcpy(format, ""); 00076 strcpy(master, ""); 00077 ast_mutex_lock(&lock); 00078 if (cfg) { 00079 var = ast_variable_browse(cfg, "mappings"); 00080 while(var) { 00081 if (!ast_strlen_zero(var->name) && !ast_strlen_zero(var->value)) { 00082 if (strlen(var->value) > (sizeof(format) - 1)) 00083 ast_log(LOG_WARNING, "Format string too long, will be truncated, at line %d\n", var->lineno); 00084 ast_copy_string(format, var->value, sizeof(format) - 1); 00085 strcat(format,"\n"); 00086 snprintf(master, sizeof(master),"%s/%s/%s", ast_config_AST_LOG_DIR, name, var->name); 00087 if (var->next) { 00088 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); 00089 break; 00090 } 00091 } else 00092 ast_log(LOG_NOTICE, "Mapping must have both filename and format at line %d\n", var->lineno); 00093 var = var->next; 00094 } 00095 ast_config_destroy(cfg); 00096 res = 0; 00097 } else { 00098 if (reload) 00099 ast_log(LOG_WARNING, "Failed to reload configuration file.\n"); 00100 else 00101 ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n"); 00102 } 00103 ast_mutex_unlock(&lock); 00104 00105 return res; 00106 }
| static int load_module | ( | void | ) | [static] |
Definition at line 152 of file cdr_custom.c.
References ast_cdr_register(), ast_log(), AST_MODULE_LOAD_DECLINE, custom_log(), load_config(), and LOG_ERROR.
00153 { 00154 int res = 0; 00155 00156 if (!load_config(0)) { 00157 res = ast_cdr_register(name, ast_module_info->description, custom_log); 00158 if (res) 00159 ast_log(LOG_ERROR, "Unable to register custom CDR handling\n"); 00160 return res; 00161 } else 00162 return AST_MODULE_LOAD_DECLINE; 00163 }
| static int reload | ( | void | ) | [static] |
Definition at line 165 of file cdr_custom.c.
References load_config().
00166 { 00167 return load_config(1); 00168 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 146 of file cdr_custom.c.
References ast_cdr_unregister().
00147 { 00148 ast_cdr_unregister(name); 00149 return 0; 00150 }
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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, .reload = reload, } [static] |
Definition at line 174 of file cdr_custom.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 174 of file cdr_custom.c.
char format[1024] = "" [static] |
Definition at line 58 of file cdr_custom.c.
Referenced by acf_sprintf(), acf_strftime(), acf_strptime(), action_originate(), add_codec_to_answer(), ast_codec_pref_getsize(), ast_getformatbyname(), ast_monitor_stop(), ast_openvstream(), ast_parse_allow_disallow(), ast_rtp_lookup_mime_multiple(), ast_speech_new(), ast_strftime(), build_peer(), build_user(), check_header(), echo_exec(), handle_saydatetime(), map_video_codec(), minivm_notify_exec(), process_sdp_a_audio(), reload_config(), sayunixtime_exec(), set_config(), socket_process(), start_monitor_action(), and start_monitor_exec().
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 __unload_module(), dahdi_bridge(), dahdi_restart(), handle_ss7_block_cic(), handle_ss7_block_linkset(), handle_ss7_unblock_cic(), handle_ss7_unblock_linkset(), and setup_dahdi().
ast_mutex_t mf_lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static] |
Definition at line 53 of file cdr_custom.c.
Referenced by custom_log().
char* name = "cdr-custom" [static] |
Definition at line 55 of file cdr_custom.c.
1.6.2