diff --git a/src/include/switch_xml.h b/src/include/switch_xml.h index 23bf972a57..82f305da84 100644 --- a/src/include/switch_xml.h +++ b/src/include/switch_xml.h @@ -172,6 +172,12 @@ switch_xml_t switch_xml_idx(switch_xml_t xml, int idx); ///\return the value SWITCH_DECLARE(const char *) switch_xml_attr(switch_xml_t xml, const char *attr); +///\brief returns the value of the requested tag attribute, or "" if not found +///\param xml the xml node +///\param attr the attribute +///\return the value +SWITCH_DECLARE(const char *) switch_xml_attr_soft(switch_xml_t xml, const char *attr); + ///\brief Traverses the switch_xml sturcture to retrieve a specific subtag. Takes a ///\ variable length list of tag names and indexes. The argument list must be ///\ terminated by either an index of -1 or an empty string tag name. Example: diff --git a/src/mod/applications/mod_ivrtest/mod_ivrtest.c b/src/mod/applications/mod_ivrtest/mod_ivrtest.c index 52930f1f9c..9ad8971d3e 100644 --- a/src/mod/applications/mod_ivrtest/mod_ivrtest.c +++ b/src/mod/applications/mod_ivrtest/mod_ivrtest.c @@ -63,7 +63,7 @@ static void xml_function(switch_core_session_t *session, char *data) const char *teamname; for (team = switch_xml_child(f1, "team"); team; team = team->next) { - teamname = switch_xml_attr(team, "name"); + teamname = switch_xml_attr_soft(team, "name"); for (driver = switch_xml_child(team, "driver"); driver; driver = driver->next) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, %s: %s\n", switch_xml_child(driver, "name")->txt, teamname, diff --git a/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c b/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c index 3dcb8d1ee6..1a4d516e02 100644 --- a/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c +++ b/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c @@ -64,8 +64,8 @@ static void load_config(void) if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + 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); diff --git a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c index f8ede626ce..5fb2d3a9bc 100644 --- a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c +++ b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c @@ -161,11 +161,11 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session) for (xexten = switch_xml_child(xcontext, "extension"); xexten; xexten = xexten->next) { int proceed = 0; - char *cont = (char *) switch_xml_attr(xexten, "continue"); + char *cont = (char *) switch_xml_attr_soft(xexten, "continue"); for (xcond = switch_xml_child(xexten, "condition"); xcond; xcond = xcond->next) { - char *field = (char *) switch_xml_attr(xcond, "field"); - char *expression = (char *) switch_xml_attr(xcond, "expression"); + char *field = (char *) switch_xml_attr_soft(xcond, "field"); + char *expression = (char *) switch_xml_attr_soft(xcond, "expression"); char *field_data = switch_caller_get_field_by_name(caller_profile, field); pcre *re = NULL; int ovector[30]; @@ -179,8 +179,8 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session) assert(re != NULL); for (xaction = switch_xml_child(xcond, "action"); xaction; xaction = xaction->next) { - char *application = (char*) switch_xml_attr(xaction, "application"); - char *data = (char *) switch_xml_attr(xaction, "data"); + char *application = (char*) switch_xml_attr_soft(xaction, "application"); + char *data = (char *) switch_xml_attr_soft(xaction, "data"); char substituted[1024] = ""; char *app_data = NULL; diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c index 1cd1d9bc7b..968efedc63 100644 --- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c +++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c @@ -1305,8 +1305,8 @@ static switch_status_t load_config(void) if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + 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); @@ -1324,8 +1324,8 @@ static switch_status_t load_config(void) for (xmlint = switch_xml_child(cfg, "interface"); xmlint; xmlint = xmlint->next) { for (param = switch_xml_child(xmlint, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); if (!globals.init) { ldl_global_init(globals.debug); diff --git a/src/mod/endpoints/mod_exosip/mod_exosip.c b/src/mod/endpoints/mod_exosip/mod_exosip.c index 5833f0d6da..b177a7794b 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip.c @@ -1880,8 +1880,8 @@ static int config_exosip(int reload) if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + 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); diff --git a/src/mod/endpoints/mod_iax/mod_iax.c b/src/mod/endpoints/mod_iax/mod_iax.c index 54b6013c06..81e521c92d 100644 --- a/src/mod/endpoints/mod_iax/mod_iax.c +++ b/src/mod/endpoints/mod_iax/mod_iax.c @@ -829,8 +829,8 @@ static switch_status_t load_config(void) if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + 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); diff --git a/src/mod/endpoints/mod_portaudio/mod_portaudio.c b/src/mod/endpoints/mod_portaudio/mod_portaudio.c index 368526f567..7bf50981c5 100644 --- a/src/mod/endpoints/mod_portaudio/mod_portaudio.c +++ b/src/mod/endpoints/mod_portaudio/mod_portaudio.c @@ -578,8 +578,8 @@ static switch_status_t load_config(void) if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + 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); diff --git a/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c b/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c index afef75e4f5..80aac0926c 100644 --- a/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c +++ b/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c @@ -1302,8 +1302,8 @@ static switch_status_t config_wanpipe(int reload) if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + 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); @@ -1322,8 +1322,8 @@ static switch_status_t config_wanpipe(int reload) for (span = switch_xml_child(cfg, "span"); span; span = span->next) { for (param = switch_xml_child(span, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcmp(var, "span")) { current_span = atoi(val); diff --git a/src/mod/endpoints/mod_woomera/mod_woomera.c b/src/mod/endpoints/mod_woomera/mod_woomera.c index c97933c228..2b4ac64f82 100644 --- a/src/mod/endpoints/mod_woomera/mod_woomera.c +++ b/src/mod/endpoints/mod_woomera/mod_woomera.c @@ -1317,8 +1317,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcmp(var, "noload") && atoi(val)) { return SWITCH_STATUS_TERM; @@ -1331,8 +1331,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod for (xmlp = switch_xml_child(cfg, "interface"); xmlp; xmlp = xmlp->next) { for (param = switch_xml_child(xmlp, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcmp(var, "audio_ip")) { strncpy(profile->audio_ip, val, sizeof(profile->audio_ip) - 1); } else if (!strcmp(var, "host")) { diff --git a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c index 655c1b5d60..c041a1c30b 100644 --- a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c +++ b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c @@ -66,8 +66,8 @@ static switch_status_t load_config(void) if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcasecmp(var, "address")) { set_global_address(val); diff --git a/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c b/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c index a2b2b530e0..f89d341d8a 100644 --- a/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c +++ b/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c @@ -111,8 +111,8 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_jid, globals.jid) if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcmp(var, "jid")) { set_global_jid(val); diff --git a/src/mod/event_handlers/mod_zeroconf/mod_zeroconf.c b/src/mod/event_handlers/mod_zeroconf/mod_zeroconf.c index 05234cbca9..0bb3fe12a4 100644 --- a/src/mod/event_handlers/mod_zeroconf/mod_zeroconf.c +++ b/src/mod/event_handlers/mod_zeroconf/mod_zeroconf.c @@ -206,8 +206,8 @@ static switch_status_t load_config(void) if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcmp(var, "browse")) { if ((oid = switch_core_alloc(module_pool, sizeof(*oid))) != 0) { diff --git a/src/mod/loggers/mod_console/mod_console.c b/src/mod/loggers/mod_console/mod_console.c index 4598265bd0..2145a5231f 100644 --- a/src/mod/loggers/mod_console/mod_console.c +++ b/src/mod/loggers/mod_console/mod_console.c @@ -93,8 +93,8 @@ static switch_status_t config_logger(void) if ((settings = switch_xml_child(cfg, "mappings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); add_mapping(var, val); } diff --git a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c index 5a3c73ead6..ca67b60dc9 100644 --- a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c +++ b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c @@ -146,11 +146,11 @@ static switch_status_t do_config(void) if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr(param, "name"); - char *val = (char *) switch_xml_attr(param, "value"); + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcasecmp(var, "gateway-url")) { - char *bindings = (char *) switch_xml_attr(param, "bindings"); + char *bindings = (char *) switch_xml_attr_soft(param, "bindings"); set_global_bindings(bindings); set_global_url(val); } else if (!strcasecmp(var, "http-port")) { diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 9a48f4ca9b..d1d2789701 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -476,7 +476,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init() if ((mods = switch_xml_child(cfg, "modules"))) { for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) { - const char *val = switch_xml_attr(ld, "module"); + const char *val = switch_xml_attr_soft(ld, "module"); if (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val); continue; @@ -496,7 +496,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init() if ((mods = switch_xml_child(cfg, "modules"))) { for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) { - const char *val = switch_xml_attr(ld, "module"); + const char *val = switch_xml_attr_soft(ld, "module"); if (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val); continue; diff --git a/src/switch_xml.c b/src/switch_xml.c index a3adf0440e..34607728d8 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -192,6 +192,14 @@ switch_xml_t switch_xml_idx(switch_xml_t xml, int idx) return xml; } +// returns the value of the requested tag attribute or "" if not found +SWITCH_DECLARE(const char *) switch_xml_attr_soft(switch_xml_t xml, const char *attr) +{ + const char *ret = switch_xml_attr(xml, attr); + + return ret ? ret : ""; +} + // returns the value of the requested tag attribute or NULL if not found SWITCH_DECLARE(const char *) switch_xml_attr(switch_xml_t xml, const char *attr) {