static switch_status_t load_config(switch_bool_t reload) { switch_xml_t cfg, xml = NULL, settings, param, x_profiles, x_profile; if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf); return SWITCH_STATUS_TERM; } switch_mutex_lock(globals.mutex); 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, "debug")) { globals.debug = atoi(val); } } } if ((x_profiles = switch_xml_child(cfg, "profiles"))) { for (x_profile = switch_xml_child(x_profiles, "profile"); x_profile; x_profile = x_profile->next) { load_profile(switch_xml_attr_soft(x_profile, "name")); } } switch_mutex_unlock(globals.mutex); switch_xml_free(xml); return SWITCH_STATUS_SUCCESS; }
/** * Configure module * @param pool memory pool to use * @return SWITCH_STATUS_SUCCESS if module is configured */ static switch_status_t do_config(switch_memory_pool_t *pool) { char *cf = "ssml.conf"; switch_xml_t cfg, xml; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); return SWITCH_STATUS_TERM; } /* get voices */ do_config_voices(pool, switch_xml_child(cfg, "tts-voices"), globals.tts_voice_map, "tts"); do_config_voices(pool, switch_xml_child(cfg, "say-voices"), globals.say_voice_map, "say"); /* get languages */ { switch_xml_t languages = switch_xml_child(cfg, "language-map"); if (languages) { switch_xml_t language; for (language = switch_xml_child(languages, "language"); language; language = language->next) { const char *iso = switch_xml_attr_soft(language, "iso"); const char *say_module = switch_xml_attr_soft(language, "say-module"); const char *lang = switch_xml_attr_soft(language, "language"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "language map: %s = (%s, %s) \n", iso, say_module, lang); if (!zstr(iso) && !zstr(say_module) && !zstr(lang)) { struct language *l = (struct language *)switch_core_alloc(pool, sizeof(*l)); l->iso = switch_core_strdup(pool, iso); l->say_module = switch_core_strdup(pool, say_module); l->language = switch_core_strdup(pool, lang); switch_core_hash_insert(globals.language_map, iso, l); } } } } /* get macros */ { switch_xml_t macros = switch_xml_child(cfg, "macros"); if (macros) { switch_xml_t macro; for (macro = switch_xml_child(macros, "macro"); macro; macro = macro->next) { const char *name = switch_xml_attr_soft(macro, "name"); const char *method = switch_xml_attr_soft(macro, "method"); const char *type = switch_xml_attr_soft(macro, "type"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "macro: %s = (%s, %s) \n", name, method, type); if (!zstr(name) && !zstr(type)) { struct macro *m = (struct macro *)switch_core_alloc(pool, sizeof(*m)); m->name = switch_core_strdup(pool, name); m->method = switch_core_strdup(pool, method); m->type = switch_core_strdup(pool, type); switch_core_hash_insert(globals.interpret_as_map, name, m); } } } } switch_xml_free(xml); return SWITCH_STATUS_SUCCESS; }
static switch_status_t load_config(void) { char *cf = "shout.conf"; switch_xml_t cfg, xml, settings, param; memset(&globals, 0, sizeof(globals)); if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); return SWITCH_STATUS_TERM; } 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 (!strcmp(var, "decoder")) { switch_set_string(globals.decoder, val); } else if (!strcmp(var, "volume")) { globals.vol = (float) atof(val); } else if (!strcmp(var, "outscale")) { int tmp = atoi(val); if (tmp > 0) { globals.outscale = tmp; } } } } switch_xml_free(xml); return SWITCH_STATUS_SUCCESS; }
static switch_status_t do_config(void) { char *cf = "python.conf"; switch_xml_t cfg, xml, settings, param; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); return SWITCH_STATUS_TERM; } 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 (!strcmp(var, "xml-handler-script")) { globals.xml_handler = switch_core_strdup(globals.pool, val); } else if (!strcmp(var, "xml-handler-bindings")) { if (!zstr(globals.xml_handler)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "binding '%s' to '%s'\n", globals.xml_handler, val); switch_xml_bind_search_function(python_fetch, switch_xml_parse_section_string(val), NULL); } } else if (!strcmp(var, "startup-script")) { if (val) { py_thread(val); } } } } switch_xml_free(xml); return SWITCH_STATUS_SUCCESS; }
static int launch_streams(const char *name) { switch_xml_t cfg, xml, directory; int x = 0; if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf); return 0; } if (zstr(name)) { for (directory = switch_xml_child(cfg, "directory"); directory; directory = directory->next) { char *name = (char *) switch_xml_attr(directory, "name"); char *path = (char *) switch_xml_attr(directory, "path"); launch_thread(name, path, directory); x++; } } else if ((directory = switch_xml_find_child(cfg, "directory", "name", name))) { char *path = (char *) switch_xml_attr(directory, "path"); launch_thread(name, path, directory); x++; } switch_xml_free(xml); return x; }
static int load_tts_commandline_config(void) { char *cf = "tts_commandline.conf"; switch_xml_t cfg, xml, settings, param; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); } else { 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 (!strcmp(var, "command")) { set_global_command(val); } } } switch_xml_free(xml); } if (zstr(globals.command)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No command set, please edit %s\n", cf); } return SWITCH_STATUS_SUCCESS; }
/* * Load from console.conf XML file the section: * <keybindings> * <key name="1" value="show calls"/> * </keybindings> */ static switch_status_t console_xml_config(void) { char *cf = "switch.conf"; switch_xml_t cfg, xml, settings, param; /* clear the keybind array */ int i; for (i = 0; i < 12; i++) { console_fnkeys[i] = NULL; } if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); return SWITCH_STATUS_TERM; } if ((settings = switch_xml_child(cfg, "cli-keybindings"))) { for (param = switch_xml_child(settings, "key"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); i = atoi(var); if ((i < 1) || (i > 12)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Keybind %s is invalid, range is from 1 to 12\n", var); } else { /* Add the command to the fnkey array */ console_fnkeys[i - 1] = switch_core_permanent_strdup(val); } } } switch_xml_free(xml); return SWITCH_STATUS_SUCCESS; }
static void load_config(void) { char *cf = "dialplan_directory.conf"; switch_xml_t cfg, xml, settings, param; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); return; } 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 (!strcmp(var, "directory-name") && val) { set_global_directory_name(val); } else if (!strcmp(var, "host") && val) { set_global_host(val); } else if (!strcmp(var, "dn") && val) { set_global_dn(val); } else if (!strcmp(var, "pass") && val) { set_global_pass(val); } else if (!strcmp(var, "base") && val) { set_global_base(val); } } } switch_xml_free(xml); }
static void event_handler(switch_event_t *event) { char *buf; switch_xml_t xml; char *xmlstr = "N/A"; uint8_t dofree = 0; switch (event->event_id) { case SWITCH_EVENT_LOG: return; default: switch_event_serialize(event, &buf, SWITCH_TRUE); if ((xml = switch_event_xmlize(event, SWITCH_VA_NONE))) { xmlstr = switch_xml_toxml(xml, SWITCH_FALSE); dofree++; } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\nEVENT (text version)\n--------------------------------\n%s", buf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\nEVENT (xml version)\n--------------------------------\n%s\n", xmlstr); break; } switch_safe_free(buf); if (dofree) { if (xml) { switch_xml_free(xml); } if (xmlstr) { free(xmlstr); } } }
static switch_status_t load_config(switch_bool_t reload) { switch_status_t status = SWITCH_STATUS_SUCCESS; switch_xml_t cfg, xml = NULL, settings, param, x_profiles, x_profile; switch_cache_db_handle_t *dbh = NULL; if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf); return SWITCH_STATUS_TERM; } switch_mutex_lock(globals.mutex); 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)) { if (switch_odbc_available()) { switch_set_string(globals.odbc_dsn, val); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n"); } } else if (!strcasecmp(var, "dbname") && !zstr(val)) { globals.dbname = switch_core_strdup(globals.pool, val); } if (!strcasecmp(var, "debug")) { globals.debug = atoi(val); } } } if ((x_profiles = switch_xml_child(cfg, "profiles"))) { for (x_profile = switch_xml_child(x_profiles, "profile"); x_profile; x_profile = x_profile->next) { load_profile(switch_xml_attr_soft(x_profile, "name")); } } if (zstr(globals.odbc_dsn) && zstr(globals.dbname)) { globals.dbname = switch_core_sprintf(globals.pool, "directory"); } dbh = directory_get_db_handle(); if (dbh) { if (!reload) { switch_cache_db_test_reactive(dbh, "delete from directory_search where uuid != '' and name_visible != '' ", "drop table directory_search", dir_sql); } switch_cache_db_release_db_handle(&dbh); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot open DB!2\n"); status = SWITCH_STATUS_TERM; goto end; } end: switch_mutex_unlock(globals.mutex); switch_xml_free(xml); return status; }
void populate_profile_menu_event(vmivr_profile_t *profile, vmivr_menu_profile_t *menu) { switch_xml_t cfg, xml, x_profiles, x_profile, x_keys, x_phrases, x_menus, x_menu; free_profile_menu_event(menu); if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf); goto end; } if (!(x_profiles = switch_xml_child(cfg, "profiles"))) { goto end; } if ((x_profile = switch_xml_find_child(x_profiles, "profile", "name", profile->name))) { if ((x_menus = switch_xml_child(x_profile, "menus"))) { if ((x_menu = switch_xml_find_child(x_menus, "menu", "name", menu->name))) { if ((x_keys = switch_xml_child(x_menu, "keys"))) { switch_event_import_xml(switch_xml_child(x_keys, "key"), "dtmf", "action", &menu->event_keys_dtmf); switch_event_import_xml(switch_xml_child(x_keys, "key"), "action", "dtmf", &menu->event_keys_action); switch_event_import_xml(switch_xml_child(x_keys, "key"), "action", "variable", &menu->event_keys_varname); } if ((x_phrases = switch_xml_child(x_menu, "phrases"))) { switch_event_import_xml(switch_xml_child(x_phrases, "phrase"), "name", "value", &menu->event_phrases); } } } } end: if (xml) switch_xml_free(xml); return; }
static int load_config(void) { switch_xml_t cfg, xml, settings, param; if (!(xml = switch_xml_open_cfg(OREKA_XML_CONFIG, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open XML configuration '%s'\n", OREKA_XML_CONFIG); return -1; } 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"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found parameter %s=%s\n", var, val); if (!strcasecmp(var, "sip-server-addr")) { snprintf(globals.sip_server_addr_str, sizeof(globals.sip_server_addr_str), "%s", val); } else if (!strcasecmp(var, "sip-server-port")) { globals.sip_server_port = atoi(val); } else if (!strcasecmp(var, "mux-all-streams")) { globals.mux_streams = 1; } } } switch_xml_free(xml); return 0; }
SWITCH_DECLARE(const char *)Event::serialize(const char *format) { this_check(""); switch_safe_free(serialized_string); if (!event) { return ""; } if (format && !strcasecmp(format, "xml")) { switch_xml_t xml; if ((xml = switch_event_xmlize(event, SWITCH_VA_NONE))) { serialized_string = switch_xml_toxml(xml, SWITCH_FALSE); switch_xml_free(xml); return serialized_string; } else { return ""; } } else if (format && !strcasecmp(format, "json")) { switch_event_serialize_json(event, &serialized_string); return serialized_string; } else { if (switch_event_serialize(event, &serialized_string, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) { char *new_serialized_string = switch_mprintf("'%s'", serialized_string); free(serialized_string); serialized_string = new_serialized_string; return serialized_string; } } return ""; }
static switch_status_t load_config(void) { switch_xml_t cfg, xml, settings, param; int num_servers = 0; int i = 0; my_timeout = "5"; my_retries = "3"; my_deadtime = "0"; strncpy(my_seqfile, "/var/run/radius.seq", PATH_MAX - 1); strncpy(my_dictionary, "/usr/local/freeswitch/conf/radius/dictionary", PATH_MAX - 1); for (i = 0; i < SERVER_MAX; i++) { my_servers[i][0] = '\0'; } if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); return SWITCH_STATUS_TERM; } 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 (!strcmp(var, "acctserver")) { if (num_servers < SERVER_MAX) { strncpy(my_servers[num_servers], val, 255 - 1); num_servers++; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "you can only specify %d radius servers, ignoring excess server entry\n", SERVER_MAX); } } else if (!strcmp(var, "dictionary")) { strncpy(my_dictionary, val, PATH_MAX - 1); } else if (!strcmp(var, "seqfile")) { strncpy(my_seqfile, val, PATH_MAX - 1); } else if (!strcmp(var, "radius_timeout")) { my_timeout = strdup(val); } else if (!strcmp(var, "radius_retries")) { my_retries = strdup(val); } else if (!strcmp(var, "radius_deadtime")) { my_deadtime = strdup(val); } } } switch_xml_free(xml); if (num_servers < 1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "you must specify at least 1 radius server\n"); return SWITCH_STATUS_TERM; } /* If we made it this far, we succeeded */ return SWITCH_STATUS_SUCCESS; }
static switch_status_t load_config(void) { char *cf = "translate.conf"; switch_xml_t cfg, xml, rule, profile, profiles; 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_FALSE; goto done; } if ((profiles = switch_xml_child(cfg, "profiles"))) { for (profile = switch_xml_child(profiles, "profile"); profile; profile = profile->next) { translate_rule_t *rules_list = NULL; char *name = (char *) switch_xml_attr_soft(profile, "name"); if (!name) { continue; } for (rule = switch_xml_child(profile, "rule"); rule; rule = rule->next) { char *regex = (char *) switch_xml_attr_soft(rule, "regex"); char *replace = (char *) switch_xml_attr_soft(rule, "replace"); if (regex && replace) { translate_rule_t *this_rule = NULL, *rl = NULL; this_rule = switch_core_alloc(globals.pool, sizeof(translate_rule_t)); this_rule->regex = switch_core_strdup(globals.pool, regex); this_rule->replace = switch_core_strdup(globals.pool, replace); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Replace number matching [%s] with [%s]\n", regex, replace); if (rules_list == NULL) { rules_list = switch_core_alloc(globals.pool, sizeof(translate_rule_t)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "starting with an empty list\n"); rules_list = this_rule; } else { for (rl = rules_list; rl && rl->next; rl = rl->next); rl->next = this_rule; } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Translation!\n"); } } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding rules to profile [%s]\n", name); switch_core_hash_insert_wrlock(globals.translate_profiles, name, rules_list, globals.profile_hash_rwlock); } } done: if (xml) { switch_xml_free(xml); } return status; }
static switch_status_t config_logger(void) { char *cf = "console.conf"; switch_xml_t cfg, xml, settings, param; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); return SWITCH_STATUS_TERM; } if (log_hash) { switch_core_hash_destroy(&log_hash); } switch_core_hash_init(&log_hash, module_pool); if ((settings = switch_xml_child(cfg, "mappings"))) { 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"); add_mapping(var, val, 1); } for (param = switch_xml_child(settings, "map"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); add_mapping(var, val, 0); } } 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, "colorize") && switch_true(val)) { #ifdef WIN32 hStdout = GetStdHandle(STD_OUTPUT_HANDLE); if (switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) { wOldColorAttrs = csbiInfo.wAttributes; COLORIZE = 1; } #else COLORIZE = 1; #endif } else if (!strcasecmp(var, "loglevel") && !zstr(val)) { hard_log_level = switch_log_str2level(val); } else if (!strcasecmp(var, "uuid") && switch_true(val)) { log_uuid = SWITCH_TRUE; } } } switch_xml_free(xml); return SWITCH_STATUS_SUCCESS; }
static switch_status_t do_config(void) { char *cf = "xml_rpc.conf"; switch_xml_t cfg, xml, settings, param; char *realm, *user, *pass, *default_domain; default_domain = realm = user = pass = NULL; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); return SWITCH_STATUS_TERM; } globals.virtual_host = SWITCH_TRUE; 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 (!zstr(var) && !zstr(val)) { if (!strcasecmp(var, "auth-realm")) { realm = val; } else if (!strcasecmp(var, "auth-user")) { user = val; } else if (!strcasecmp(var, "auth-pass")) { pass = val; } else if (!strcasecmp(var, "http-port")) { globals.port = (uint16_t) atoi(val); } else if (!strcasecmp(var, "default-domain")) { default_domain = val; } else if (!strcasecmp(var, "virtual-host")) { globals.virtual_host = switch_true(val); } else if (!strcasecmp(var, "enable-websocket")) { globals.enable_websocket = switch_true(val); } } } } if (!globals.port) { globals.port = 8080; } if (realm) { set_global_realm(realm); if (user && pass) { set_global_user(user); set_global_pass(pass); } } if (default_domain) { set_global_default_domain(default_domain); } switch_xml_free(xml); return SWITCH_STATUS_SUCCESS; }
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; }
void utils_reloadxml() { const char *err; switch_xml_t xml_root; if ((xml_root = switch_xml_open_root(1, &err))) { switch_xml_free(xml_root); } else switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"Reload XML [%s]\n", err); return; }
static dir_profile_t *load_profile(const char *profile_name) { dir_profile_t *profile = NULL; switch_xml_t x_profiles, x_profile, cfg, xml = NULL; switch_event_t *event = NULL; if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf); return profile; } if (!(x_profiles = switch_xml_child(cfg, "profiles"))) { goto end; } if ((x_profile = switch_xml_find_child(x_profiles, "profile", "name", profile_name))) { switch_memory_pool_t *pool; int count; if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n"); goto end; } if (!(profile = switch_core_alloc(pool, sizeof(dir_profile_t)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n"); switch_core_destroy_memory_pool(&pool); goto end; } profile->pool = pool; profile_set_config(profile); /* Add the params to the event structure */ count = (int)switch_event_import_xml(switch_xml_child(x_profile, "param"), "name", "value", &event); if (switch_xml_config_parse_event(event, count, SWITCH_FALSE, profile->config) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to process configuration\n"); switch_core_destroy_memory_pool(&pool); goto end; } switch_thread_rwlock_create(&profile->rwlock, pool); profile->name = switch_core_strdup(pool, profile_name); switch_mutex_init(&profile->mutex, SWITCH_MUTEX_NESTED, profile->pool); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added Profile %s\n", profile->name); switch_core_hash_insert(globals.profile_hash, profile->name, profile); } end: switch_xml_free(xml); return profile; }
static switch_status_t config(void) { const char *cf = "mongo.conf"; switch_xml_t cfg, xml, settings, param; switch_status_t status = SWITCH_STATUS_SUCCESS; const char *conn_str = "127.0.0.1"; switch_size_t min_connections = 1, max_connections = 1; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); return SWITCH_STATUS_GENERR; } 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"); int tmp; if (!strcmp(var, "host")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "'host' is deprecated. use 'connection-string'\n"); conn_str = val; } else if (!strcmp(var, "connection-string")) { conn_str = val; } else if (!strcmp(var, "min-connections")) { if ((tmp = atoi(val)) > 0) { min_connections = tmp; } } else if (!strcmp(var, "max-connections")) { if ((tmp = atoi(val)) > 0) { max_connections = tmp; } } else if (!strcmp(var, "map")) { globals.map = strdup(val); } else if (!strcmp(var, "reduce")) { globals.reduce = strdup(val); } else if (!strcmp(var, "finalize")) { globals.finalize = strdup(val); } } } if (mongo_connection_pool_create(&globals.conn_pool, min_connections, max_connections, conn_str) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Can't create connection pool\n"); status = SWITCH_STATUS_GENERR; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Mongo connection pool created [%s %d/%d]\n", conn_str, (int)min_connections, (int)max_connections); } switch_xml_free(xml); return status; }
static switch_status_t load_config(void) { char *cf = "reference.conf"; switch_xml_t cfg, xml, settings, param; memset(&globals, 0, sizeof(globals)); switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); return SWITCH_STATUS_TERM; } 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 (!strcmp(var, "debug")) { globals.debug = atoi(val); } else if (!strcmp(var, "port")) { globals.port = atoi(val); } else if (!strcmp(var, "ip")) { set_global_ip(val); } else if (!strcmp(var, "codec-master")) { if (!strcasecmp(val, "us")) { switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS); } } else if (!strcmp(var, "dialplan")) { set_global_dialplan(val); } else if (!strcmp(var, "codec-prefs")) { set_global_codec_string(val); globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS); } else if (!strcmp(var, "codec-rates")) { set_global_codec_rates_string(val); globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS); } } } if (!globals.dialplan) { set_global_dialplan("default"); } if (!globals.port) { globals.port = 4569; } switch_xml_free(xml); return SWITCH_STATUS_SUCCESS; }
static switch_status_t do_config(switch_bool_t reload) { /* Load up blacklists */ switch_xml_t xml, cfg, lists, list; switch_hash_index_t *hi = NULL; if (!(xml = switch_xml_open_cfg("mod_blacklist.conf", &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't load configuration section\n"); return SWITCH_STATUS_FALSE; } switch_mutex_lock(globals.lists_mutex); /* Destroy any active lists */ while ((hi = switch_core_hash_first_iter( globals.lists, hi))) { const void *key; void *val; switch_core_hash_this(hi, &key, NULL, &val); blacklist_free((blacklist_t*)val); switch_core_hash_delete(globals.lists, (const char*)key); } if ((lists = switch_xml_child(cfg, "lists"))) { for (list = switch_xml_child(lists, "list"); list; list = list->next) { const char *name = switch_xml_attr_soft(list, "name"); const char *filename = switch_xml_attr_soft(list, "filename"); if (zstr(name)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "list has no name\n"); continue; } if (zstr(filename)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "list [%s] has no filename\n", name); continue; } load_list(name, filename); } } switch_mutex_unlock(globals.lists_mutex); if (xml) { switch_xml_free(xml); xml = NULL; } return SWITCH_STATUS_SUCCESS; }
SWITCH_DECLARE(void) switch_nat_republish(void) { switch_xml_t natxml = NULL; switch_xml_t row = NULL; switch_xml_t child = NULL; switch_stream_handle_t stream = { 0 }; SWITCH_STANDARD_STREAM(stream); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Refreshing nat maps\n"); switch_api_execute("show", "nat_map as xml", NULL, &stream); if (!(natxml = switch_xml_parse_str_dup(stream.data))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to parse XML: %s\n", (char *) stream.data); switch_safe_free(stream.data); return; } /* iterate the xml and publish the mappings */ row = switch_xml_find_child(natxml, "row", "row_id", "1"); while (row != NULL) { char *sport = NULL; char *sproto = NULL; switch_port_t port; switch_nat_ip_proto_t proto; if ((child = switch_xml_child(row, "port"))) { sport = child->txt; } if ((child = switch_xml_child(row, "proto_num"))) { sproto = child->txt; } if (sport && sproto) { port = (switch_port_t) (atoi(sport)); proto = (switch_nat_ip_proto_t) (atoi(sproto)); switch_nat_add_mapping_internal(port, proto, NULL, SWITCH_FALSE, SWITCH_FALSE); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to parse port/proto info: XML: %s\n", (char *) stream.data); } row = switch_xml_next(row); } switch_safe_free(stream.data); switch_xml_free(natxml); }
static switch_status_t load_config(void) { char *cf = "syslog.conf"; switch_xml_t cfg, xml, settings, param; /* default log level */ log_level = SWITCH_LOG_WARNING; /* default facility */ globals.facility = DEFAULT_FACILITY; globals.log_uuid = SWITCH_TRUE; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); } else { 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 (!strcmp(var, "ident")) { set_global_ident(val); } else if (!strcmp(var, "format")) { set_global_format(val); } else if (!strcmp(var, "facility")) { set_global_facility(val); } else if (!strcasecmp(var, "loglevel") && !zstr(val)) { log_level = switch_log_str2level(val); if (log_level == SWITCH_LOG_INVALID) { log_level = SWITCH_LOG_WARNING; } } else if (!strcasecmp(var, "uuid")) { globals.log_uuid = switch_true(val); } } } switch_xml_free(xml); } if (zstr(globals.ident)) { set_global_ident(DEFAULT_IDENT); } if (zstr(globals.format)) { set_global_format(DEFAULT_FORMAT); } return 0; }
static void do_config(switch_bool_t reload) { switch_xml_t xml = NULL, x_lists = NULL, x_list = NULL, cfg = NULL; if ((xml = switch_xml_open_cfg("hash.conf", &cfg, NULL))) { if ((x_lists = switch_xml_child(cfg, "remotes"))) { for (x_list = switch_xml_child(x_lists, "remote"); x_list; x_list = x_list->next) { const char *name = switch_xml_attr(x_list, "name"); const char *host = switch_xml_attr(x_list, "host"); const char *szport = switch_xml_attr(x_list, "port"); const char *username = switch_xml_attr(x_list, "username"); const char *password = switch_xml_attr(x_list, "password"); const char *szinterval = switch_xml_attr(x_list, "interval"); uint16_t port = 0; int interval = 0; limit_remote_t *remote; switch_threadattr_t *thd_attr = NULL; if (reload) { switch_thread_rwlock_rdlock(globals.remote_hash_rwlock); if (switch_core_hash_find(globals.remote_hash, name)) { switch_thread_rwlock_unlock(globals.remote_hash_rwlock); continue; } switch_thread_rwlock_unlock(globals.remote_hash_rwlock); } if (!zstr(szport)) { port = (uint16_t)atoi(szport); } if (!zstr(szinterval)) { interval = atoi(szinterval); } remote = limit_remote_create(name, host, port, username, password, interval); remote->state = REMOTE_DOWN; switch_threadattr_create(&thd_attr, remote->pool); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_thread_create(&remote->thread, thd_attr, limit_remote_thread, remote, remote->pool); } } switch_xml_free(xml); } }
SWITCH_DECLARE(char *) CoreSession::getXMLCDR() { switch_xml_t cdr; this_check((char *)""); sanity_check((char *)""); switch_safe_free(xml_cdr_text); if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) { xml_cdr_text = switch_xml_toxml(cdr, SWITCH_FALSE); switch_xml_free(cdr); } return (char *) (xml_cdr_text ? xml_cdr_text : ""); }
SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_module_settings(const char *file, switch_bool_t reload, switch_xml_config_item_t *instructions) { switch_xml_t cfg, xml, settings; switch_status_t status = SWITCH_STATUS_SUCCESS; if (!(xml = switch_xml_open_cfg(file, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not open %s\n", file); return SWITCH_STATUS_FALSE; } if ((settings = switch_xml_child(cfg, "settings"))) { status = switch_xml_config_parse(switch_xml_child(settings, "param"), reload, instructions); } switch_xml_free(xml); return status; }
static switch_status_t opus_load_config(switch_bool_t reload) { char *cf = "opus.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, "Opening of %s failed\n", cf); return status; } if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { char *key = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcasecmp(key, "use-vbr") && !zstr(val)) { opus_prefs.use_vbr = atoi(val); } else if (!strcasecmp(key, "complexity")) { opus_prefs.complexity = atoi(val); } else if (!strcasecmp(key, "maxaveragebitrate")) { opus_prefs.maxaveragebitrate = atoi(val); if ( opus_prefs.maxaveragebitrate < 6000 || opus_prefs.maxaveragebitrate > 510000 ) { opus_prefs.maxaveragebitrate = 0; /* values outside the range between 6000 and 510000 SHOULD be ignored */ } } else if (!strcasecmp(key, "maxplaybackrate")) { opus_prefs.maxplaybackrate = atoi(val); if ( opus_prefs.maxplaybackrate != 8000 && opus_prefs.maxplaybackrate != 12000 && opus_prefs.maxplaybackrate != 16000 && opus_prefs.maxplaybackrate != 24000 && opus_prefs.maxplaybackrate != 48000) { opus_prefs.maxplaybackrate = 0; /* value not supported */ } } } } if (xml) { switch_xml_free(xml); } return status; }
void switch_load_timezones(switch_bool_t reload) { switch_xml_t xml = NULL, x_lists = NULL, x_list = NULL, cfg = NULL; unsigned total = 0; if (TIMEZONES_LIST.hash) { switch_core_hash_destroy(&TIMEZONES_LIST.hash); } if (TIMEZONES_LIST.pool) { switch_core_destroy_memory_pool(&TIMEZONES_LIST.pool); } memset(&TIMEZONES_LIST, 0, sizeof(TIMEZONES_LIST)); switch_core_new_memory_pool(&TIMEZONES_LIST.pool); switch_core_hash_init(&TIMEZONES_LIST.hash, TIMEZONES_LIST.pool); if ((xml = switch_xml_open_cfg("timezones.conf", &cfg, NULL))) { if ((x_lists = switch_xml_child(cfg, "timezones"))) { for (x_list = switch_xml_child(x_lists, "zone"); x_list; x_list = x_list->next) { const char *name = switch_xml_attr(x_list, "name"); const char *value = switch_xml_attr(x_list, "value"); if (zstr(name)) { continue; } if (zstr(value)) { continue; } switch_core_hash_insert(TIMEZONES_LIST.hash, name, switch_core_strdup(TIMEZONES_LIST.pool, value)); total++; } } switch_xml_free(xml); } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Timezone %sloaded %d definitions\n", reload ? "re" : "", total); }