[Freeswitch-svn] [commit] r6491 - in freeswitch/trunk/src: . include mod/applications/mod_commands mod/xml_int/mod_xml_rpc

Freeswitch SVN anthm at freeswitch.org
Tue Dec 4 11:22:02 EST 2007


Author: anthm
Date: Tue Dec  4 11:22:02 2007
New Revision: 6491

Modified:
   freeswitch/trunk/src/include/switch_utils.h
   freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
   freeswitch/trunk/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c
   freeswitch/trunk/src/switch_utils.c

Log:
adress MODAPP-55

Modified: freeswitch/trunk/src/include/switch_utils.h
==============================================================================
--- freeswitch/trunk/src/include/switch_utils.h	(original)
+++ freeswitch/trunk/src/include/switch_utils.h	Tue Dec  4 11:22:02 2007
@@ -57,6 +57,7 @@
 
 SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen);
 SWITCH_DECLARE(switch_status_t) switch_b64_decode(char *in, char *out, switch_size_t olen);
+SWITCH_DECLARE(char *) switch_amp_encode(char *s, char *buf, switch_size_t len);
 
 static inline switch_bool_t switch_is_digit_string(const char *s) {
 

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	Tue Dec  4 11:22:02 2007
@@ -1545,9 +1545,13 @@
 	for (x = 0; x < argc; x++) {
 		char *val = switch_str_nil(argv[x]);
 
+
 		if (holder->http) {
+			char aval[512];
+
+			switch_amp_encode(argv[x], aval, sizeof(aval));
 			holder->stream->write_function(holder->stream, "<td>");
-			holder->stream->write_function(holder->stream, "%s%s", val, x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
+			holder->stream->write_function(holder->stream, "%s%s", aval, x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
 		} else {
 			holder->stream->write_function(holder->stream, "%s%s", val, x == (argc - 1) ? "\n" : holder->delim);
 		}
@@ -1582,7 +1586,7 @@
 		}
 	}
 	
-	if (!as && stream->event) {
+	if (stream->event) {
 		holder.http = switch_event_get_header(stream->event, "http-host");
 	}
 

Modified: freeswitch/trunk/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c
==============================================================================
--- freeswitch/trunk/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c	(original)
+++ freeswitch/trunk/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c	Tue Dec  4 11:22:02 2007
@@ -364,6 +364,7 @@
 	char *fs_user = NULL, *fs_domain = NULL;
 	char *path_info = NULL;
 	abyss_bool ret = TRUE;
+	int html = 0;
 
 	stream.data = r;
 	stream.write_function = http_stream_write;
@@ -371,6 +372,9 @@
 
 	if ((command = strstr(r->uri, "/api/"))) {
 		command += 5;
+	} else if ((command = strstr(r->uri, "/webapi/"))) {
+		command += 8;
+		html++;
 	} else {
 		ret = FALSE;
 		goto end;
@@ -554,6 +558,10 @@
 	/* Generation of the server field */
 	ResponseAddField(r,"Server", "FreeSWITCH-" SWITCH_VERSION_FULL "-mod_xml_rpc");
 
+	if (html) {
+		ResponseAddField(r, "Content-Type", "text/html");
+	}
+
 	for (i=0;i<r->response_headers.size;i++) {
 		ti=&r->response_headers.item[i];
 		ConnWrite(r->conn, ti->name, (uint32_t)strlen(ti->name));
@@ -566,6 +574,10 @@
 	snprintf(buf, sizeof(buf), "Connection: close\r\n");
 	ConnWrite(r->conn, buf, (uint32_t) strlen(buf));
 	
+	if (html) {
+		ConnWrite(r->conn, "\r\n", 2);
+	}
+
 
 	if (switch_api_execute(command, r->query, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
 		ResponseStatus(r, 200);

Modified: freeswitch/trunk/src/switch_utils.c
==============================================================================
--- freeswitch/trunk/src/switch_utils.c	(original)
+++ freeswitch/trunk/src/switch_utils.c	Tue Dec  4 11:22:02 2007
@@ -55,6 +55,53 @@
 	return total;
 }
 
+SWITCH_DECLARE(char *) switch_amp_encode(char *s, char *buf, switch_size_t len)
+{
+	char *p, *q;
+	int x = 0;
+	assert(s);
+
+	q = buf;
+
+	for(p = s; x < len; p++) {
+		switch(*p) {
+		case '<':
+			if (x + 4 > len -1) {
+				goto end;
+			}
+			*q++ = '&';
+			*q++ = 'l';
+			*q++ = 't';
+			*q++ = ';';
+			x += 4;
+			break;
+		case '>':
+			if (x + 4 > len -1) {
+				goto end;
+			}
+			*q++ = '&';
+			*q++ = 'g';
+			*q++ = 't';
+			*q++ = ';';
+			x += 4;
+			break;
+		default:
+			if (x + 1 > len -1) {
+				goto end;
+			}
+			*q++ = *p;
+			x++;
+			if (*p == '\0') {
+				goto end;
+			}
+			break;
+		}
+	}
+
+ end:
+
+	return buf;
+}
 
 
 static const char switch_b64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";



More information about the Freeswitch-svn mailing list