static switch_status_t load_config(void) { char *cf = "rednibblebill.conf"; switch_xml_t cfg, xml = NULL, param, settings; switch_status_t status = SWITCH_STATUS_SUCCESS; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); status = SWITCH_STATUS_SUCCESS; /* We don't fail because we can still write to a text file or buffer */ } if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcasecmp(var, "redis_host")) { set_global_redis_host(val); } else if (!strcasecmp(var, "redis_port")) { globals.redis_port = atoi(val); } else if (!strcasecmp(var, "redis_timeout")) { globals.redis_timeout = atoi(val); } else if (!strcasecmp(var, "percall_action")) { set_global_percall_action(val); } else if (!strcasecmp(var, "percall_max_amt")) { globals.percall_max_amt = atof(val); } else if (!strcasecmp(var, "lowbal_action")) { set_global_lowbal_action(val); } else if (!strcasecmp(var, "lowbal_amt")) { globals.lowbal_amt = atof(val); } else if (!strcasecmp(var, "nobal_action")) { set_global_nobal_action(val); } else if (!strcasecmp(var, "nobal_amt")) { globals.nobal_amt = atof(val); } else if (!strcasecmp(var, "global_heartbeat")) { globals.global_heartbeat = atoi(val); } } } if (zstr(globals.percall_action)) { set_global_percall_action("hangup"); } if (zstr(globals.lowbal_action)) { set_global_lowbal_action("play ding"); } if (zstr(globals.nobal_action)) { set_global_nobal_action("hangup"); } if (xml) { switch_xml_free(xml); } return status; }
static switch_status_t load_config(void) { char *cf = "nibblebill.conf"; switch_xml_t cfg, xml = NULL, param, settings; switch_status_t status = SWITCH_STATUS_SUCCESS; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); status = SWITCH_STATUS_SUCCESS; /* We don't fail because we can still write to a text file or buffer */ goto setdefaults; } if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcasecmp(var, "db_username")) { set_global_db_username(val); } else if (!strcasecmp(var, "db_password")) { set_global_db_password(val); } else if (!strcasecmp(var, "db_dsn")) { set_global_db_dsn(val); } else if (!strcasecmp(var, "db_table")) { set_global_db_table(val); } else if (!strcasecmp(var, "db_column_cash")) { set_global_db_column_cash(val); } else if (!strcasecmp(var, "db_column_account")) { set_global_db_column_account(val); } else if (!strcasecmp(var, "custom_sql_save")) { set_global_custom_sql_save(val); } else if (!strcasecmp(var, "custom_sql_lookup")) { set_global_custom_sql_lookup(val); } else if (!strcasecmp(var, "percall_action")) { set_global_percall_action(val); } else if (!strcasecmp(var, "percall_max_amt")) { globals.percall_max_amt = atof(val); } else if (!strcasecmp(var, "lowbal_action")) { set_global_lowbal_action(val); } else if (!strcasecmp(var, "lowbal_amt")) { globals.lowbal_amt = atof(val); } else if (!strcasecmp(var, "nobal_action")) { set_global_nobal_action(val); } else if (!strcasecmp(var, "nobal_amt")) { globals.nobal_amt = atof(val); } else if (!strcasecmp(var, "global_heartbeat")) { globals.global_heartbeat = atoi(val); } } } /* Set defaults for any variables still not set */ setdefaults: if (zstr(globals.percall_action)) { set_global_percall_action("hangup"); } if (zstr(globals.lowbal_action)) { set_global_lowbal_action("play ding"); } if (zstr(globals.nobal_action)) { set_global_nobal_action("hangup"); } if (switch_odbc_available() && globals.db_dsn) { if (!(globals.master_odbc = switch_odbc_handle_new(globals.db_dsn, globals.db_username, globals.db_password))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot create handle to ODBC Database!\n"); status = SWITCH_STATUS_FALSE; goto done; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opened ODBC Database handle!\n"); } if (switch_odbc_handle_connect(globals.master_odbc) != SWITCH_ODBC_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot connect to ODBC driver/database %s (user: %s / pass %s)!\n", globals.db_dsn, globals.db_username, globals.db_password); status = SWITCH_STATUS_FALSE; goto done; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opened ODBC Database!\n"); } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", globals.db_dsn); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "ODBC does not appear to be installed in the core or your dsn is empty. You need to run ./configure --enable-core-odbc-support\n"); } done: if (xml) { switch_xml_free(xml); } return status; }
static switch_status_t nibblebill_load_config(void) { char *cf = "nibblebill.conf"; switch_cache_db_handle_t *dbh = NULL; switch_xml_t cfg, xml = NULL, param, settings; switch_status_t status = SWITCH_STATUS_SUCCESS; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); status = SWITCH_STATUS_SUCCESS; /* We don't fail because we can still write to a text file or buffer */ goto setdefaults; } if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcasecmp(var, "odbc-dsn") && !zstr(val)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "odbc_dsn is %s\n", val); switch_safe_free(globals.odbc_dsn); globals.odbc_dsn = strdup(val); } else if (!strcasecmp(var, "db_dsn") && !zstr(val)) { /* For backwards-compatibility */ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "this nibblebill param(db_dsn) is deprecated and will be removed in 1.4 - odbc_dsn is %s\n", val); switch_safe_free(globals.odbc_dsn); globals.odbc_dsn = strdup(val); } else if (!strcasecmp(var, "db_table")) { set_global_db_table(val); } else if (!strcasecmp(var, "db_column_cash")) { set_global_db_column_cash(val); } else if (!strcasecmp(var, "db_column_account")) { set_global_db_column_account(val); } else if (!strcasecmp(var, "custom_sql_save")) { set_global_custom_sql_save(val); } else if (!strcasecmp(var, "custom_sql_lookup")) { set_global_custom_sql_lookup(val); } else if (!strcasecmp(var, "percall_action")) { set_global_percall_action(val); } else if (!strcasecmp(var, "percall_max_amt")) { globals.percall_max_amt = atof(val); } else if (!strcasecmp(var, "lowbal_action")) { set_global_lowbal_action(val); } else if (!strcasecmp(var, "lowbal_amt")) { globals.lowbal_amt = atof(val); } else if (!strcasecmp(var, "nobal_action")) { set_global_nobal_action(val); } else if (!strcasecmp(var, "nobal_amt")) { globals.nobal_amt = atof(val); } else if (!strcasecmp(var, "global_heartbeat")) { globals.global_heartbeat = atoi(val); } } } /* Set defaults for any variables still not set */ setdefaults: if (zstr(globals.percall_action)) { set_global_percall_action("hangup"); } if (zstr(globals.lowbal_action)) { set_global_lowbal_action("play ding"); } if (zstr(globals.nobal_action)) { set_global_nobal_action("hangup"); } if (globals.odbc_dsn) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG , "dsn is \"%s\"\n" , globals.odbc_dsn ); if (!(dbh = nibblebill_get_db_handle())) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n"); switch_goto_status(SWITCH_STATUS_FALSE, done); } } done: if (xml) { switch_xml_free(xml); } return status; }