Implement new config parser in mod_limit
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12494 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
b59ad5e456
commit
ec60a3ae0b
|
@ -166,45 +166,42 @@ static switch_bool_t limit_execute_sql_callback(switch_mutex_t *mutex, char *sql
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static switch_xml_config_string_options_t limit_config_dsn = { NULL, 0, "\\w+:\\w+:\\w+" };
|
||||||
|
|
||||||
|
static switch_xml_config_item_t config_settings[] = {
|
||||||
|
SWITCH_CONFIG_ITEM("odbc-dsn", SWITCH_CONFIG_STRING, 0, &globals.odbc_dsn, NULL, &limit_config_dsn,
|
||||||
|
"dsn:username:password", "If set, the ODBC DSN used by the limit and db applications"),
|
||||||
|
SWITCH_CONFIG_ITEM_END()
|
||||||
|
};
|
||||||
|
|
||||||
static switch_status_t do_config()
|
static switch_status_t do_config()
|
||||||
{
|
{
|
||||||
char *cf = "limit.conf";
|
|
||||||
switch_xml_t cfg, xml, settings, param;
|
|
||||||
switch_core_db_t *db;
|
switch_core_db_t *db;
|
||||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||||
char *odbc_user = NULL;
|
char *odbc_user = NULL;
|
||||||
char *odbc_pass = NULL;
|
char *odbc_pass = NULL;
|
||||||
char *sql = NULL;
|
char *sql = NULL;
|
||||||
|
|
||||||
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
limit_config_dsn.pool = globals.pool;
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
|
|
||||||
|
if (switch_xml_config_parse_module_settings("limit.conf", SWITCH_FALSE, config_settings) != SWITCH_STATUS_SUCCESS) {
|
||||||
return SWITCH_STATUS_TERM;
|
return SWITCH_STATUS_TERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((settings = switch_xml_child(cfg, "settings"))) {
|
if (globals.odbc_dsn) {
|
||||||
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
|
|
||||||
char *var = NULL;
|
|
||||||
char *val = NULL;
|
|
||||||
|
|
||||||
var = (char *) switch_xml_attr_soft(param, "name");
|
|
||||||
val = (char *) switch_xml_attr_soft(param, "value");
|
|
||||||
|
|
||||||
if (!strcasecmp(var, "odbc-dsn") && !switch_strlen_zero(val)) {
|
|
||||||
#ifdef SWITCH_HAVE_ODBC
|
#ifdef SWITCH_HAVE_ODBC
|
||||||
globals.odbc_dsn = switch_core_strdup(globals.pool, val);
|
if ((odbc_user = strchr(globals.odbc_dsn, ':'))) {
|
||||||
if ((odbc_user = strchr(globals.odbc_dsn, ':'))) {
|
*odbc_user++ = '\0';
|
||||||
*odbc_user++ = '\0';
|
if ((odbc_pass = strchr(odbc_user, ':'))) {
|
||||||
if ((odbc_pass = strchr(odbc_user, ':'))) {
|
*odbc_pass++ = '\0';
|
||||||
*odbc_pass++ = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (switch_strlen_zero(globals.odbc_dsn) || switch_strlen_zero(odbc_user) || switch_strlen_zero(odbc_pass)) {
|
if (switch_strlen_zero(globals.odbc_dsn) || switch_strlen_zero(odbc_user) || switch_strlen_zero(odbc_pass)) {
|
||||||
globals.dbname = "call_limit";
|
globals.dbname = "call_limit";
|
||||||
}
|
}
|
||||||
|
@ -291,8 +288,6 @@ static switch_status_t do_config()
|
||||||
limit_execute_sql(sql, globals.mutex);
|
limit_execute_sql(sql, globals.mutex);
|
||||||
switch_safe_free(sql);
|
switch_safe_free(sql);
|
||||||
|
|
||||||
switch_xml_free(xml);
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue