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

Freeswitch SVN anthm at freeswitch.org
Fri Aug 1 11:06:57 EDT 2008


Author: anthm
Date: Fri Aug  1 11:06:56 2008
New Revision: 9216

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

Log:
fix MDXMLINT-31

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	Fri Aug  1 11:06:56 2008
@@ -570,6 +570,7 @@
 	switch_core_time_duration_t duration = { 0 };
 	char *http = NULL;
 	int sps = 0, last_sps = 0;
+	const char *var;
 
 	if (session) {
 		return SWITCH_STATUS_FALSE;
@@ -581,6 +582,14 @@
 		http = switch_event_get_header(stream->param_event, "http-host");
 	}
 
+	if ((var = switch_event_get_header(stream->param_event, "content-type"))) {
+		if (!strcasecmp(var, "text/plain")) {
+			http = NULL;
+		}
+	} else {
+		stream->write_function(stream, "%s", "Content-Type: text/html\n\n");
+	}
+
 	if (http || (cmd && strstr(cmd, "html"))) {
 		html = 1;
 		stream->write_function(stream, "<h1>FreeSWITCH Status</h1>\n<b>");
@@ -2008,7 +2017,17 @@
 	}
 
 	if (stream->param_event) {
+		const char *var;
 		holder.http = switch_event_get_header(stream->param_event, "http-host");
+		
+		if ((var = switch_event_get_header(stream->param_event, "content-type"))) {
+			if (!strcasecmp(var, "text/plain")) {
+				holder.http = NULL;
+			}
+		} else {
+			stream->write_function(stream, "%s", "Content-Type: text/html\n\n");
+		}
+
 	}
 
 	holder.print_title = 1;

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	Fri Aug  1 11:06:56 2008
@@ -158,6 +158,7 @@
 	const char *box;
 	int at = 0;
 	switch_event_t *params = NULL;
+	char *dp;
 
 	p = RequestHeaderValue(r, "authorization");
 
@@ -166,17 +167,20 @@
 		x = GetToken(&p);
 		if (x) {
 			if (!strcasecmp(x, "basic")) {
-
-
 				NextToken((const char **const) &p);
 				switch_b64_decode(p, user, sizeof(user));
 				if ((pass = strchr(user, ':'))) {
 					*pass++ = '\0';
 				}
-
+				
+				if ((dp = strchr(user, '@'))) {
+					*dp++ = '\0';
+					domain_name = dp;
+				}
+				
 				if (!domain_name) {
-					if ((domain_name = strchr(user, '@'))) {
-						*domain_name++ = '\0';
+					if (dp) {
+						domain_name = dp;
 						at++;
 					} else {
 						domain_name = (char *) r->requestInfo.host;
@@ -209,7 +213,7 @@
 
 				switch_event_destroy(&params);
 				box = switch_xml_attr_soft(x_user, "mailbox");
-
+				
 				for (x_param = switch_xml_child(x_domain, "param"); x_param; x_param = x_param->next) {
 					const char *var = switch_xml_attr_soft(x_param, "name");
 					const char *val = switch_xml_attr_soft(x_param, "value");
@@ -224,6 +228,7 @@
 				}
 
 				if (!(x_params = switch_xml_child(x_user, "params"))) {
+					r->requestInfo.user = strdup(user);
 					goto authed;
 				}
 
@@ -306,15 +311,17 @@
 				goto fail;
 
 			  authed:
+				
+				if (r->requestInfo.user && domain_name) {
+					ResponseAddField(r, "freeswitch-user", r->requestInfo.user);
+					ResponseAddField(r, "freeswitch-domain", domain_name);
 
-				ResponseAddField(r, "freeswitch-user", r->requestInfo.user);
-				ResponseAddField(r, "freeswitch-domain", domain_name);
+					if (x_domain_root) {
+						switch_xml_free(x_domain_root);
+					}
 
-				if (x_domain_root) {
-					switch_xml_free(x_domain_root);
+					return TRUE;
 				}
-
-				return TRUE;
 			}
 		}
 	}
@@ -437,7 +444,7 @@
 	char *fs_user = NULL, *fs_domain = NULL;
 	char *path_info = NULL;
 	abyss_bool ret = TRUE;
-	int html = 0;
+	int html = 0, text = 0;
 
 	stream.data = r;
 	stream.write_function = http_stream_write;
@@ -452,6 +459,9 @@
 	} else if ((command = strstr(r->requestInfo.uri, "/webapi/"))) {
 		command += 8;
 		html++;
+	} else if ((command = strstr(r->requestInfo.uri, "/txtapi/"))) {
+		command += 8;
+		text++;
 	} else {
 		return FALSE;
 	}
@@ -509,7 +519,11 @@
 
 	if (switch_event_create(&stream.param_event, SWITCH_EVENT_API) == SWITCH_STATUS_SUCCESS) {
 		const char *const content_length = RequestHeaderValue(r, "content-length");
-
+		
+		if (html)
+			switch_event_add_header(stream.param_event, SWITCH_STACK_BOTTOM, "Content-type", "%s", "text/html");
+		else if (text)
+			switch_event_add_header(stream.param_event, SWITCH_STACK_BOTTOM, "Content-type", "%s", "text/plain");
 		if (fs_user)
 			switch_event_add_header(stream.param_event, SWITCH_STACK_BOTTOM, "FreeSWITCH-User", "%s", fs_user);
 		if (fs_domain)
@@ -633,6 +647,8 @@
 
 	if (html) {
 		ResponseAddField(r, "Content-Type", "text/html");
+	} else if (text) {
+		ResponseAddField(r, "Content-Type", "text/plain");
 	}
 
 	for (i = 0; i < r->response_headers.size; i++) {
@@ -646,7 +662,7 @@
 	switch_snprintf(buf, sizeof(buf), "Connection: close\r\n");
 	ConnWrite(r->conn, buf, (uint32_t) strlen(buf));
 
-	if (html) {
+	if (html || text) {
 		ConnWrite(r->conn, "\r\n", 2);
 	}
 



More information about the Freeswitch-svn mailing list