[Freeswitch-svn] [commit] r5824 - in freeswitch/trunk/src: . include mod/xml_int/mod_xml_cdr

Freeswitch SVN anthm at freeswitch.org
Fri Oct 5 21:05:55 EDT 2007


Author: anthm
Date: Fri Oct  5 21:05:55 2007
New Revision: 5824

Modified:
   freeswitch/trunk/src/include/switch_xml.h
   freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
   freeswitch/trunk/src/switch_xml.c

Log:
add headers

Modified: freeswitch/trunk/src/include/switch_xml.h
==============================================================================
--- freeswitch/trunk/src/include/switch_xml.h	(original)
+++ freeswitch/trunk/src/include/switch_xml.h	Fri Oct  5 21:05:55 2007
@@ -191,6 +191,7 @@
 ///\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);
 
 ///\brief returns a NULL terminated array of processing instructions for the given
 ///\ target

Modified: freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
==============================================================================
--- freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c	(original)
+++ freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c	Fri Oct  5 21:05:55 2007
@@ -75,7 +75,6 @@
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
 	if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
-
 		/* build the XML */
 		if (!(xml_text = switch_xml_toxml(cdr))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
@@ -108,6 +107,7 @@
 
 		/* try to post it to the web server */
 		if (!switch_strlen_zero(globals.url)) {
+			struct curl_slist *headers = NULL;
 			curl_handle = curl_easy_init();
 			
 			if (globals.encode) {
@@ -117,13 +117,17 @@
 				assert(xml_text_escaped);
 				memset(xml_text_escaped, 0, sizeof(xml_text_escaped));
 				if (globals.encode == 1) {
+					headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
 					switch_url_encode(xml_text, xml_text_escaped, need_bytes - 1);
 				} else {
+					headers = curl_slist_append(headers, "Content-Type: application/x-www-form-base64-encoded");
 					switch_b64_encode((unsigned char *)xml_text, need_bytes / 3, (unsigned char *)xml_text_escaped, need_bytes);
 				}
 				switch_safe_free(xml_text);
 				xml_text = xml_text_escaped;
-			} 
+			} else {
+				headers = curl_slist_append(headers, "Content-Type: application/x-www-form-plaintext");
+			}
 			
 			if (!(curl_xml_text = switch_mprintf("cdr=%s", xml_text))) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
@@ -135,12 +139,13 @@
 				curl_easy_setopt(curl_handle, CURLOPT_USERPWD, globals.cred);
 			}
 
-			curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
+			curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
+ 			curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
 			curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, curl_xml_text);
 			curl_easy_setopt(curl_handle, CURLOPT_URL, globals.url);
 			curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
 			curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, httpCallBack);
-
+			
 			if (globals.ignore_cacert_check) {
 				curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE);
 			}
@@ -164,6 +169,7 @@
 				
 			}
 			curl_easy_cleanup(curl_handle);
+			curl_slist_free_all(headers);
 			curl_handle = NULL;
 
 			/* if we are here the web post failed for some reason */

Modified: freeswitch/trunk/src/switch_xml.c
==============================================================================
--- freeswitch/trunk/src/switch_xml.c	(original)
+++ freeswitch/trunk/src/switch_xml.c	Fri Oct  5 21:05:55 2007
@@ -1509,21 +1509,29 @@
 	}
 }
 
+SWITCH_DECLARE(char *) switch_xml_toxml(switch_xml_t xml)
+{
+	char *s;
+	s = malloc(SWITCH_XML_BUFSIZE);
+	return switch_xml_toxml_buf(xml, s, SWITCH_XML_BUFSIZE, 0);
+}
+
 // converts an switch_xml structure back to xml, returning a string of xml date that
 // must be freed
-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_xml_t p = (xml) ? xml->parent : NULL, o = (xml) ? xml->ordered : NULL;
 	switch_xml_root_t root = (switch_xml_root_t) xml;
-	switch_size_t len = 0, max = SWITCH_XML_BUFSIZE;
+	switch_size_t len = 0, max = buflen;
 	char *s, *t, *n, *r;
 	int i, j, k;
 	uint32_t count = 0;
 	
-	s = malloc(max);
+	s = buf;
 	assert(s != NULL);
 	memset(s, 0, max);
-	len = sprintf(s, "<?xml version=\"1.0\"?>\n");
+	len += offset;
+	len += sprintf(s + len, "<?xml version=\"1.0\"?>\n");
 
 	
 	if (!xml || !xml->name) {



More information about the Freeswitch-svn mailing list