Clean up cdr.conf parsing for [csv] section

Review: https://reviewboard.asterisk.org/r/1427/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@335556 65c4cc65-6c06-0410-ace0-fbb531ad65f3
certified/11.2
Paul Belanger 14 years ago
parent 61b369ac76
commit 2d18de5f8f

@ -32,7 +32,7 @@ Configuration Files:
parses configuration files. This makes configuration files more consistent parses configuration files. This makes configuration files more consistent
with what is expected across modules. with what is expected across modules.
- cdr.conf: [general] section - cdr.conf: [general] and [csv] sections
- dnsmgr.conf - dnsmgr.conf
SIP SIP

@ -50,7 +50,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#define DATE_FORMAT "%Y-%m-%d %T" #define DATE_FORMAT "%Y-%m-%d %T"
static int usegmtime = 0; static int usegmtime = 0;
static int accountlogs; static int accountlogs = 1;
static int loguniqueid = 0; static int loguniqueid = 0;
static int loguserfield = 0; static int loguserfield = 0;
static int loaded = 0; static int loaded = 0;
@ -95,52 +95,38 @@ AST_MUTEX_DEFINE_STATIC(acf_lock);
static int load_config(int reload) static int load_config(int reload)
{ {
struct ast_config *cfg; struct ast_config *cfg;
struct ast_variable *var; struct ast_variable *v;
const char *tmp;
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
if (!(cfg = ast_config_load(config, config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) { if (!(cfg = ast_config_load(config, config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
ast_log(LOG_WARNING, "unable to load config: %s\n", config); ast_log(LOG_WARNING, "unable to load config: %s\n", config);
return 0; return 0;
} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
return 1; return 1;
}
accountlogs = 1; accountlogs = 1;
usegmtime = 0; usegmtime = 0;
loguniqueid = 0; loguniqueid = 0;
loguserfield = 0; loguserfield = 0;
if (!(var = ast_variable_browse(cfg, "csv"))) { if (!(v = ast_variable_browse(cfg, "csv"))) {
ast_config_destroy(cfg); ast_config_destroy(cfg);
return 0; return 0;
} }
if ((tmp = ast_variable_retrieve(cfg, "csv", "usegmtime"))) { for (; v; v = v->next) {
usegmtime = ast_true(tmp); if (!strcasecmp(v->name, "usegmtime")) {
if (usegmtime) usegmtime = ast_true(v->value);
ast_debug(1, "logging time in GMT\n"); } else if (!strcasecmp(v->name, "accountlogs")) {
} /* Turn on/off separate files per accountcode. Default is on (as before) */
accountlogs = ast_true(v->value);
/* Turn on/off separate files per accountcode. Default is on (as before) */ } else if (!strcasecmp(v->name, "loguniqueid")) {
if ((tmp = ast_variable_retrieve(cfg, "csv", "accountlogs"))) { loguniqueid = ast_true(v->value);
accountlogs = ast_true(tmp); } else if (!strcasecmp(v->name, "loguserfield")) {
if (accountlogs) { loguserfield = ast_true(v->value);
ast_debug(1, "logging in separate files per accountcode\n"); }
}
}
if ((tmp = ast_variable_retrieve(cfg, "csv", "loguniqueid"))) {
loguniqueid = ast_true(tmp);
if (loguniqueid)
ast_debug(1, "logging CDR field UNIQUEID\n");
}
if ((tmp = ast_variable_retrieve(cfg, "csv", "loguserfield"))) {
loguserfield = ast_true(tmp);
if (loguserfield)
ast_debug(1, "logging CDR user-defined field\n");
} }
ast_config_destroy(cfg); ast_config_destroy(cfg);
return 1; return 1;
} }
@ -337,8 +323,9 @@ static int load_module(void)
{ {
int res; int res;
if(!load_config(0)) if (!load_config(0)) {
return AST_MODULE_LOAD_DECLINE; return AST_MODULE_LOAD_DECLINE;
}
if ((res = ast_cdr_register(name, ast_module_info->description, csv_log))) { if ((res = ast_cdr_register(name, ast_module_info->description, csv_log))) {
ast_log(LOG_ERROR, "Unable to register CSV CDR handling\n"); ast_log(LOG_ERROR, "Unable to register CSV CDR handling\n");

Loading…
Cancel
Save