diff --git a/src/include/switch_xml.h b/src/include/switch_xml.h index e8e2a2bf92..5ea600a550 100644 --- a/src/include/switch_xml.h +++ b/src/include/switch_xml.h @@ -266,8 +266,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_add_child(_In_ switch_xml_t xml, _In_z_ ///\param xml the xml node ///\param name the name of the child ///\param off the offset -#define switch_xml_add_child_d(xml, name, off) \ - switch_xml_set_flag(switch_xml_add_child(xml, strdup(name), off), SWITCH_XML_NAMEM) +SWITCH_DECLARE(switch_xml_t) switch_xml_add_child_d(_In_ switch_xml_t xml, _In_z_ const char *name, _In_ switch_size_t off); ///\brief sets the character content for the given tag and returns the tag ///\param xml the xml node @@ -280,8 +279,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt(switch_xml_t xml, const char *tx ///\param xml the xml node ///\param txt the text ///\return an xml node or NULL -#define switch_xml_set_txt_d(xml, txt) \ - switch_xml_set_flag(switch_xml_set_txt(xml, strdup(txt)), SWITCH_XML_TXTM) +SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt_d(switch_xml_t xml, const char *txt); ///\brief Sets the given tag attribute or adds a new attribute if not found. A value ///\ of NULL will remove the specified attribute. @@ -296,11 +294,14 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr(switch_xml_t xml, const char *n ///\param name the attribute name ///\param value the attribute value ///\return an xml node or NULL -#define switch_xml_set_attr_d(xml, name, value) \ - switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(switch_str_nil(value))) +SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr_d(switch_xml_t xml, const char *name, const char *value); -#define switch_xml_set_attr_d_buf(xml, name, value) \ - switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(value)) +///\brief Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL +///\param xml the xml node +///\param name the attribute name +///\param value the attribute value +///\return an xml node or NULL +SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr_d_buf(switch_xml_t xml, const char *name, const char *value); ///\brief sets a flag for the given tag and returns the tag ///\param xml the xml node diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index ef9d1bb880..3ab5007ee3 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -5473,7 +5473,7 @@ static int show_as_xml_callback(void *pArg, int argc, char **argv, char **column switch_snprintf(id, sizeof(id), "%d", holder->rows); - switch_xml_set_attr(switch_xml_set_flag(row, SWITCH_XML_DUP), strdup("row_id"), strdup(id)); + switch_xml_set_attr_d_buf(row, "row_id", id); for (x = 0; x < argc; x++) { char *name = columnNames[x]; @@ -5864,7 +5864,7 @@ SWITCH_STANDARD_API(show_function) char *xmlstr; switch_snprintf(count, sizeof(count), "%d", holder.count); - switch_xml_set_attr(switch_xml_set_flag(holder.xml, SWITCH_XML_DUP), strdup("row_count"), strdup(count)); + switch_xml_set_attr(holder.xml, "row_count", count); xmlstr = switch_xml_toxml(holder.xml, SWITCH_FALSE); switch_xml_free(holder.xml); diff --git a/src/switch_xml.c b/src/switch_xml.c index 9229d9214b..60004f29d6 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -2942,6 +2942,14 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_add_child(switch_xml_t xml, const char * return switch_xml_insert(child, xml, off); } +/* Adds a child tag. off is the offset of the child tag relative to the start + of the parent tag's character content. Returns the child tag */ +SWITCH_DECLARE(switch_xml_t) switch_xml_add_child_d(switch_xml_t xml, const char *name, switch_size_t off) +{ + if (!xml) return NULL; + return switch_xml_set_flag(switch_xml_add_child(xml, strdup(name), off), SWITCH_XML_NAMEM); +} + /* sets the character content for the given tag and returns the tag */ SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt(switch_xml_t xml, const char *txt) { @@ -2954,6 +2962,13 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt(switch_xml_t xml, const char *tx return xml; } +/* sets the character content for the given tag and returns the tag */ +SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt_d(switch_xml_t xml, const char *txt) +{ + if (!xml) return NULL; + return switch_xml_set_flag(switch_xml_set_txt(xml, strdup(txt)), SWITCH_XML_TXTM); +} + /* Sets the given tag attribute or adds a new attribute if not found. A value of NULL will remove the specified attribute. Returns the tag given */ SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr(switch_xml_t xml, const char *name, const char *value) @@ -3005,6 +3020,22 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr(switch_xml_t xml, const char *n return xml; } +/* Sets the given tag attribute or adds a new attribute if not found. A value + of NULL will remove the specified attribute. Returns the tag given */ +SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr_d(switch_xml_t xml, const char *name, const char *value) +{ + if (!xml) return NULL; + return switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(switch_str_nil(value))); +} + +/* Sets the given tag attribute or adds a new attribute if not found. A value + of NULL will remove the specified attribute. Returns the tag given */ +SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr_d_buf(switch_xml_t xml, const char *name, const char *value) +{ + if (!xml) return NULL; + return switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(value)); +} + /* sets a flag for the given tag and returns the tag */ SWITCH_DECLARE(switch_xml_t) switch_xml_set_flag(switch_xml_t xml, switch_xml_flag_t flag) {