[Freeswitch-svn] [commit] r5823 - in freeswitch/trunk: conf src src/include src/mod/endpoints/mod_sofia src/mod/xml_int/mod_xml_cdr

Freeswitch SVN anthm at freeswitch.org
Fri Oct 5 20:30:04 EDT 2007


Author: anthm
Date: Fri Oct  5 20:30:04 2007
New Revision: 5823

Modified:
   freeswitch/trunk/conf/xml_cdr.conf.xml
   freeswitch/trunk/src/include/switch_utils.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
   freeswitch/trunk/src/switch_utils.c

Log:
make encoding optional none, base64 or url encoding

Modified: freeswitch/trunk/conf/xml_cdr.conf.xml
==============================================================================
--- freeswitch/trunk/conf/xml_cdr.conf.xml	(original)
+++ freeswitch/trunk/conf/xml_cdr.conf.xml	Fri Oct  5 20:30:04 2007
@@ -15,7 +15,10 @@
     <!-- optional: if not present we do not log every record to disk -->
     <!-- either an absolute path, a relative path assuming ${prefix}/logs or a blank value will default to ${prefix}/logs/xml_cdr -->
     <param name="log-dir" value=""/>
-
+    
+    <!-- encode the post data may be 'true' for url encoding, 'false' for no encoding or 'base64' for base64 encoding -->
+    <!--<param name="encode" value="true"/>-->
+    
     <!-- optional: full path to the error log dir for failed web posts if not specified its the same as log-dir -->
     <!-- either an absolute path, a relative path assuming ${prefix}/logs or a blank or omitted value will default to ${prefix}/logs/xml_cdr -->
     <!-- <param name="err-log-dir" value="/tmp"/> -->

Modified: freeswitch/trunk/src/include/switch_utils.h
==============================================================================
--- freeswitch/trunk/src/include/switch_utils.h	(original)
+++ freeswitch/trunk/src/include/switch_utils.h	Fri Oct  5 20:30:04 2007
@@ -55,6 +55,8 @@
 #define switch_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR))
 #endif
 
+SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen);
+
 static inline switch_bool_t switch_is_digit_string(const char *s) {
 
 	while(s && *s) {

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	Fri Oct  5 20:30:04 2007
@@ -341,6 +341,7 @@
 	nua_set_params(profile->nua,
 				   NUTAG_APPL_METHOD("OPTIONS"),
 				   NUTAG_APPL_METHOD("NOTIFY"),
+				   NUTAG_APPL_METHOD("INFO"),
 				   //NUTAG_EARLY_MEDIA(1),                 
 				   NUTAG_AUTOANSWER(0),
 				   NUTAG_AUTOALERT(0),

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 20:30:04 2007
@@ -43,6 +43,7 @@
 	uint32_t retries;
 	uint32_t shutdown;
 	uint32_t ignore_cacert_check;
+	int encode;
 } globals;
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load);
@@ -81,9 +82,6 @@
 			goto error;
 		}
 
-		/* do we log to the disk no matter what? */
-		/* all previous functionality is retained */
-
 		if (!(logdir = switch_channel_get_variable(channel, "xml_cdr_base"))) {
 			logdir = globals.log_dir;
 		}
@@ -111,15 +109,23 @@
 		/* try to post it to the web server */
 		if (!switch_strlen_zero(globals.url)) {
 			curl_handle = curl_easy_init();
-
-			xml_text_escaped = curl_easy_escape(curl_handle, (const char*) xml_text, (int)strlen(xml_text));
-
-			if (switch_strlen_zero(xml_text_escaped)) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-				goto error;
-			}
-
-			if (!(curl_xml_text = switch_mprintf("cdr=%s", xml_text_escaped))) {
+			
+			if (globals.encode) {
+				switch_size_t need_bytes = strlen(xml_text) * 3;
+
+				xml_text_escaped = malloc(need_bytes);
+				assert(xml_text_escaped);
+				memset(xml_text_escaped, 0, sizeof(xml_text_escaped));
+				if (globals.encode == 1) {
+					switch_url_encode(xml_text, xml_text_escaped, need_bytes - 1);
+				} else {
+					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;
+			} 
+			
+			if (!(curl_xml_text = switch_mprintf("cdr=%s", xml_text))) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
 				goto error;
 			}
@@ -193,9 +199,8 @@
 		curl_easy_cleanup(curl_handle);
 	}
 	switch_safe_free(curl_xml_text);
-	switch_safe_free(xml_text_escaped);
-	switch_safe_free(path);
 	switch_safe_free(xml_text);
+	switch_safe_free(path);
 	switch_xml_free(cdr);
 
 	return status;
@@ -241,6 +246,12 @@
 				globals.url = strdup(val);
 			} else if (!strcasecmp(var, "delay")) {
 				globals.delay = (uint32_t) atoi(val);
+			} else if (!strcasecmp(var, "encode")) {
+				if (!strcasecmp(val, "base64")) {
+					globals.encode = 2;
+				} else {
+					globals.encode = switch_true(val);
+				}
 			} else if (!strcasecmp(var, "retries")) {
 				globals.retries = (uint32_t) atoi(val);
 			} else if (!strcasecmp(var, "log-dir")) {
@@ -286,7 +297,9 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "retries set but delay 0 setting to 5000ms\n");
 		globals.delay = 5000;
 	}
-	
+
+	globals.retries++;
+
 	switch_xml_free(xml);
 	return status;
 }

Modified: freeswitch/trunk/src/switch_utils.c
==============================================================================
--- freeswitch/trunk/src/switch_utils.c	(original)
+++ freeswitch/trunk/src/switch_utils.c	Fri Oct  5 20:30:04 2007
@@ -34,6 +34,40 @@
 #include <arpa/inet.h>
 #endif
 
+static const char switch_b64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+#define B64BUFFLEN 1024
+SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen)
+{
+    int y = 0, bytes = 0;
+    size_t x = 0;
+    unsigned int b = 0,l = 0;
+
+    for(x = 0; x < ilen; x++) {
+        b = (b<<8) + in[x];
+        l += 8;
+        while (l >= 6) {
+            out[bytes++] = switch_b64_table[(b>>(l-=6))%64];
+            if(++y != 72) {
+                continue;
+            }
+            //out[bytes++] = '\n';
+            y=0;
+        }
+    }
+
+    if (l > 0) {
+        out[bytes++] = switch_b64_table[((b%16)<<(6-l))%64];
+    }
+    if (l != 0) {
+		while (l < 6) {
+			out[bytes++] = '=', l += 2;
+		}
+	}
+
+    return SWITCH_STATUS_SUCCESS;
+}
+
+
 SWITCH_DECLARE(switch_status_t) switch_find_local_ip(char *buf, int len, int family)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;



More information about the Freeswitch-svn mailing list