From 4b7f9bddf53a97a9bfcd6e2f50fb27536b305cfb Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 29 Jan 2007 16:58:37 +0000 Subject: [PATCH] merge changes from ezXML 0.8.6 - fixed a bug in ezxml_add_child() that can occur when adding tags out of order - for consistency, ezxml_set_attr() now returns the tag given - added ezxml_move() and supporting functions ezxml_cut() and ezxml_insert() - fixed a bug where parsing an empty file could cause a segfault git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4081 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_xml.h | 18 +++++-- src/switch_xml.c | 107 ++++++++++++++++++++++----------------- 2 files changed, 75 insertions(+), 50 deletions(-) diff --git a/src/include/switch_xml.h b/src/include/switch_xml.h index 909eefe1e9..589448b257 100644 --- a/src/include/switch_xml.h +++ b/src/include/switch_xml.h @@ -256,9 +256,10 @@ switch_xml_t switch_xml_set_txt(switch_xml_t xml, const char *txt); ///\param xml the xml node ///\param name the attribute name ///\param value the attribute value -SWITCH_DECLARE(void) switch_xml_set_attr(switch_xml_t xml, const char *name, const char *value); +///\return the tag given +SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr(switch_xml_t xml, const char *name, const char *value); -///\ Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL +///\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 @@ -272,10 +273,19 @@ SWITCH_DECLARE(void) switch_xml_set_attr(switch_xml_t xml, const char *name, con ///\return an xml node or NULL SWITCH_DECLARE(switch_xml_t) switch_xml_set_flag(switch_xml_t xml, switch_xml_flag_t flag); +///\brief removes a tag along with its subtags without freeing its memory +///\param xml the xml node +SWITCH_DECLARE(switch_xml_t) switch_xml_cut(switch_xml_t xml); + +///\brief inserts an existing tag into an ezxml structure +SWITCH_DECLARE(switch_xml_t) switch_xml_insert(switch_xml_t xml, switch_xml_t dest, switch_size_t off); + +///\brief Moves an existing tag to become a subtag of dest at the given offset from +///\ the start of dest's character content. Returns the moved tag. +#define switch_xml_move(xml, dest, off) switch_xml_insert(switch_xml_cut(xml), dest, off) ///\brief removes a tag along with all its subtags -///\param xml the xml node -SWITCH_DECLARE(void) switch_xml_remove(switch_xml_t xml); +#define switch_xml_remove(xml) switch_xml_free(switch_xml_cut(xml)) ///\brief open the Core xml root ///\param reload if it's is already open close it and open it again as soon as permissable (blocking) diff --git a/src/switch_xml.c b/src/switch_xml.c index 45d2594dcd..aabd5521cc 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -28,10 +28,10 @@ * * switch_xml.c -- XML PARSER * - * Derived from EZXML http://ezxml.sourceforge.net + * Derived from switch_xml http://switch_xml.sourceforge.net * Original Copyright * - * Copyright 2004, 2005 Aaron Voisine + * Copyright 2004, 2006 Aaron Voisine * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -696,7 +696,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_str(char *s, switch_size_t len) if (switch_xml_close_tag(root, d, s)) return &root->xml; if (isspace((int)(*s = q))) s += strspn(s, SWITCH_XML_WS); } - else if (! strncmp(s, "!--", 3)) { // comment + else if (! strncmp(s, "!--", 3)) { // xml comment if (! (s = strstr(s + 3, "--")) || (*(s += 2) != '>' && *s) || (! *s && e != '>')) return switch_xml_err(root, d, "unclosed