[Freeswitch-svn] [commit] r6860 - freeswitch/trunk/src/mod/xml_int/mod_xml_curl

Freeswitch SVN anthm at freeswitch.org
Tue Dec 18 09:16:44 EST 2007


Author: anthm
Date: Tue Dec 18 09:16:43 2007
New Revision: 6860

Modified:
   freeswitch/trunk/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c

Log:
add better debug line to xml_curl

Modified: freeswitch/trunk/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c
==============================================================================
--- freeswitch/trunk/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c	(original)
+++ freeswitch/trunk/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c	Tue Dec 18 09:16:43 2007
@@ -128,16 +128,14 @@
 		return xml;
 	}
 
-	if (!(data = switch_mprintf("hostname=%s&section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s",
-								hostname,
-								section,
-								tag_name ? tag_name : "",
-								key_name ? key_name : "",
-								key_value ? key_value : "", params ? strchr(params, '=') ? "&" : "&params=" : "", params ? params : ""))) {
-
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-		return NULL;
-	}
+	data = switch_mprintf("hostname=%s&section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s",
+						  hostname,
+						  section,
+						  switch_str_nil(tag_name),
+						  switch_str_nil(key_name),
+						  switch_str_nil(key_value), 
+						  params ? strchr(params, '=') ? "&" : "&params=" : "", params ? params : "");
+	switch_assert(data);
 
 	switch_uuid_get(&uuid);
 	switch_uuid_format(uuid_str, &uuid);
@@ -166,7 +164,7 @@
 		curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
 
 		if (binding->disable100continue) {
-			slist = curl_slist_append(slist,"Expect:"); 
+			slist = curl_slist_append(slist, "Expect:"); 
 			curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist); 
 		}
 
@@ -175,7 +173,7 @@
 		}
 
 		curl_easy_perform(curl_handle);
-		curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE,&httpRes);
+		curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
 		curl_easy_cleanup(curl_handle);
 		curl_slist_free_all(headers);
 		close(config_data.fd);
@@ -183,19 +181,17 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening temp file!\n");
 	}
 
-	switch_safe_free(data);
-
-	if(httpRes==200) {
+	if (httpRes == 200) {
 		if (!(xml = switch_xml_parse_file(filename))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
 		}
 	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received HTTP error %ld trying to fetch %s\n",httpRes,key_value);
-		xml=NULL;
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received HTTP error %ld trying to fetch %s\ndata: [%s]\n", httpRes, binding->url, data);
+		xml = NULL;
 	}
 
 	/* Debug by leaving the file behind for review */
-	if(keep_files_around) {
+	if (keep_files_around) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "XML response is in %s\n", filename);
 	} else {
 		if (unlink(filename) != 0) {
@@ -203,6 +199,8 @@
 		}
 	}
 
+	switch_safe_free(data);
+
 	return xml;
 }
 



More information about the Freeswitch-svn mailing list