From dc96942b88d51a25de167ac0b44c9a2441280f78 Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthony.minessale@gmail.com>
Date: Fri, 30 Nov 2007 23:45:27 +0000
Subject: [PATCH] update

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6455 d0543943-73ff-0310-b7d9-9358b9ac24b2
---
 src/include/switch_xml.h                           |  4 ++--
 src/mod/applications/mod_commands/mod_commands.c   | 14 +++++---------
 src/mod/applications/mod_fifo/mod_fifo.c           |  2 +-
 src/mod/applications/mod_voicemail/mod_voicemail.c |  2 +-
 src/mod/endpoints/mod_dingaling/mod_dingaling.c    |  4 ++--
 .../mod_event_socket/mod_event_socket.c            |  2 +-
 .../event_handlers/mod_event_test/mod_event_test.c |  2 +-
 .../languages/mod_spidermonkey/mod_spidermonkey.c  |  6 +++---
 src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c          |  2 +-
 src/switch_xml.cpp                                 | 11 ++++++-----
 10 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/src/include/switch_xml.h b/src/include/switch_xml.h
index 2f6e27a0ee..1c2ce13161 100644
--- a/src/include/switch_xml.h
+++ b/src/include/switch_xml.h
@@ -190,8 +190,8 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_get(switch_xml_t xml,...);
 ///\ must be freed.
 ///\param xml the xml node
 ///\return the xml text string
-SWITCH_DECLARE(char *) switch_xml_toxml(switch_xml_t xml);
-SWITCH_DECLARE(char *) switch_xml_toxml_buf(switch_xml_t xml, char *buf, switch_size_t buflen, switch_size_t offset);
+SWITCH_DECLARE(char *) switch_xml_toxml(switch_xml_t xml, switch_bool_t prn_header);
+SWITCH_DECLARE(char *) switch_xml_toxml_buf(switch_xml_t xml, char *buf, switch_size_t buflen, switch_size_t offset, switch_bool_t prn_header);
 
 ///\brief returns a NULL terminated array of processing instructions for the given
 ///\ target
diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c
index 342eb88532..947395d5a6 100644
--- a/src/mod/applications/mod_commands/mod_commands.c
+++ b/src/mod/applications/mod_commands/mod_commands.c
@@ -47,7 +47,7 @@ SWITCH_STANDARD_API(find_user_function)
 	int argc;
     char *mydata = NULL, *argv[3];
 	char *key, *user, *domain;
-	char *xmlstr, *xs;
+	char *xmlstr;
 
     if (!cmd) {
 		stream->write_function(stream,  "bad args\n");
@@ -82,14 +82,10 @@ SWITCH_STANDARD_API(find_user_function)
  end:
 
 	if (xml && x_user) {
-		xmlstr = switch_xml_toxml(x_user);
+		xmlstr = switch_xml_toxml(x_user, SWITCH_FALSE);
 		assert(xmlstr);
-		if ((xs = strstr(xmlstr, "?>"))) {
-			xs += 2;
-		} else {
-			xs = xmlstr;
-		}
-		stream->write_function(stream,  "%s", xs);
+
+		stream->write_function(stream,  "%s", xmlstr);
 		free(xmlstr);
 		switch_xml_free(xml);
 		
@@ -1607,7 +1603,7 @@ SWITCH_STANDARD_API(show_function)
 			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));
-			xmlstr = switch_xml_toxml(holder.xml);
+			xmlstr = switch_xml_toxml(holder.xml, SWITCH_FALSE);
 
 			if (xmlstr) {
 				holder.stream->write_function(holder.stream, "%s", xmlstr);
diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c
index 5af3cfa51f..2d3e5567c3 100644
--- a/src/mod/applications/mod_fifo/mod_fifo.c
+++ b/src/mod/applications/mod_fifo/mod_fifo.c
@@ -527,7 +527,7 @@ SWITCH_STANDARD_API(fifo_api_function)
                 switch_mutex_unlock(node->mutex);
             }
         }
-        xml_text = switch_xml_toxml(x_report);
+        xml_text = switch_xml_toxml(x_report, SWITCH_FALSE);
         assert(xml_text);
         stream->write_function(stream, "%s\n", xml_text);
         switch_xml_free(x_report);
diff --git a/src/mod/applications/mod_voicemail/mod_voicemail.c b/src/mod/applications/mod_voicemail/mod_voicemail.c
index c54138d917..411f8ea0f0 100644
--- a/src/mod/applications/mod_voicemail/mod_voicemail.c
+++ b/src/mod/applications/mod_voicemail/mod_voicemail.c
@@ -2595,7 +2595,7 @@ static void do_rss(vm_profile_t *profile, char *user, char *domain, char *host,
     sql = switch_mprintf("select * from voicemail_data where user='%s' and domain='%s' order by read_flags", user, domain);
     vm_execute_sql_callback(profile, profile->mutex, sql, rss_callback, &holder);
 
-    xmlstr = switch_xml_toxml(holder.xml);
+    xmlstr = switch_xml_toxml(holder.xml, SWITCH_TRUE);
 
     stream->write_function(stream, "%s", xmlstr);
 
diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c
index 9497d35e03..844a5c7bc1 100644
--- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c
+++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c
@@ -731,7 +731,7 @@ static void dl_logger(char *file, const char *func, int line, int level, char *f
 					*xmltxt++ = '\0';
 					if (strlen(xmltxt) > 2) {
 						xml = switch_xml_parse_str(xmltxt, strlen(xmltxt));
-						form = switch_xml_toxml(xml);
+						form = switch_xml_toxml(xml, SWITCH_FALSE);
 						switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, level,
 										  "%s:\n-------------------------------------------------------------------------------\n"
 										  "%s\n", ll, form);
@@ -2301,7 +2301,7 @@ static void do_vcard(ldl_handle_t *handle, char *to, char *from, char *id)
 
 	switch_xml_set_attr(vcard, "xmlns", "vcard-tmp");
 
-	if ((xmlstr = switch_xml_toxml(vcard))) {
+	if ((xmlstr = switch_xml_toxml(vcard, SWITCH_FALSE))) {
 		ldl_handle_send_vcard(handle, to, from, id, xmlstr);
 		sent = 1;
 	} else {
diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
index 014d8206bb..247f5b3cea 100644
--- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
+++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
@@ -471,7 +471,7 @@ static switch_status_t read_packet(listener_t * listener, switch_event_t **event
 						etype = "xml";
 
 						if ((xml = switch_event_xmlize(event, "%s", ""))) {
-							listener->ebuf = switch_xml_toxml(xml);
+							listener->ebuf = switch_xml_toxml(xml, SWITCH_FALSE);
 							switch_xml_free(xml);
 						} else {
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "XML ERROR!\n");
diff --git a/src/mod/event_handlers/mod_event_test/mod_event_test.c b/src/mod/event_handlers/mod_event_test/mod_event_test.c
index 10ca5bd7f0..7548bfa6e8 100644
--- a/src/mod/event_handlers/mod_event_test/mod_event_test.c
+++ b/src/mod/event_handlers/mod_event_test/mod_event_test.c
@@ -50,7 +50,7 @@ static void event_handler(switch_event_t *event)
 	default:
 		switch_event_serialize(event, &buf);
 		if ((xml = switch_event_xmlize(event, NULL))) {
-			xmlstr = switch_xml_toxml(xml);
+			xmlstr = switch_xml_toxml(xml, SWITCH_FALSE);
 			dofree++;
 		}
 
diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
index ba7a1fdff1..00ca044f07 100644
--- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
+++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
@@ -237,7 +237,7 @@ static JSBool request_dump_env(JSContext *cx, JSObject *obj, uintN argc, jsval *
 		switch_xml_t xml;
 		char *xmlstr;
 		if ((xml = switch_event_xmlize(ro->stream->event, SWITCH_VA_NONE))) {
-            xmlstr = switch_xml_toxml(xml);
+            xmlstr = switch_xml_toxml(xml, SWITCH_FALSE);
 			*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, xmlstr));
 			return JS_TRUE;
         } 
@@ -646,7 +646,7 @@ static JSBool event_serialize(JSContext * cx, JSObject * obj, uintN argc, jsval
 		switch_xml_t xml;
 		char *xmlstr;
 		if ((xml = switch_event_xmlize(eo->event, SWITCH_VA_NONE))) {
-			xmlstr = switch_xml_toxml(xml);
+			xmlstr = switch_xml_toxml(xml, SWITCH_FALSE);
 			*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, xmlstr));
 			switch_xml_free(xml);
 			free(xmlstr);
@@ -1898,7 +1898,7 @@ static JSBool session_cdr(JSContext * cx, JSObject * obj, uintN argc, jsval * ar
 
 	if (switch_ivr_generate_xml_cdr(jss->session, &cdr) == SWITCH_STATUS_SUCCESS) {
 		char *xml_text;
-		if ((xml_text = switch_xml_toxml(cdr))) {
+		if ((xml_text = switch_xml_toxml(cdr, SWITCH_FALSE))) {
 			*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, xml_text));
 		}
 		switch_safe_free(xml_text);
diff --git a/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c b/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
index e7e90fb87c..cc0beb0589 100644
--- a/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
+++ b/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
@@ -76,7 +76,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
 
 	if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
 		/* build the XML */
-		if (!(xml_text = switch_xml_toxml(cdr))) {
+		if (!(xml_text = switch_xml_toxml(cdr, SWITCH_TRUE))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
 			goto error;
 		}
diff --git a/src/switch_xml.cpp b/src/switch_xml.cpp
index 419450e51f..228b29a174 100644
--- a/src/switch_xml.cpp
+++ b/src/switch_xml.cpp
@@ -1595,16 +1595,16 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len,
 	}
 }
 
-SWITCH_DECLARE(char *) switch_xml_toxml(switch_xml_t xml)
+SWITCH_DECLARE(char *) switch_xml_toxml(switch_xml_t xml, switch_bool_t prn_header)
 {
 	char *s;
 	s = (char *)malloc(SWITCH_XML_BUFSIZE);
-	return switch_xml_toxml_buf(xml, s, SWITCH_XML_BUFSIZE, 0);
+	return switch_xml_toxml_buf(xml, s, SWITCH_XML_BUFSIZE, 0, prn_header);
 }
 
 // converts an switch_xml structure back to xml, returning a string of xml date that
 // must be freed
-SWITCH_DECLARE(char *) switch_xml_toxml_buf(switch_xml_t xml, char *buf, switch_size_t buflen, switch_size_t offset)
+SWITCH_DECLARE(char *) switch_xml_toxml_buf(switch_xml_t xml, char *buf, switch_size_t buflen, switch_size_t offset, switch_bool_t prn_header)
 {
 	switch_xml_t p = (xml) ? xml->parent : NULL, o = (xml) ? xml->ordered : NULL;
 	switch_xml_root_t root = (switch_xml_root_t) xml;
@@ -1617,8 +1617,9 @@ SWITCH_DECLARE(char *) switch_xml_toxml_buf(switch_xml_t xml, char *buf, switch_
 	assert(s != NULL);
 	memset(s, 0, max);
 	len += offset;
-	len += sprintf(s + len, "<?xml version=\"1.0\"?>\n");
-
+	if (prn_header) {
+		len += sprintf(s + len, "<?xml version=\"1.0\"?>\n");
+	}
 	
 	if (!xml || !xml->name) {
 		if (!(r = (char *)realloc(s, len + 1))) {