[asterisk-commits] kpfleming: trunk r49679 - /trunk/main/manager.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Jan 5 15:52:17 MST 2007


Author: kpfleming
Date: Fri Jan  5 16:52:16 2007
New Revision: 49679

URL: http://svn.digium.com/view/asterisk?view=rev&rev=49679
Log:
use mmap() to read in the results of the manager action for an HTTP request, instead of reading it into a buffer

Modified:
    trunk/main/manager.c

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?view=diff&rev=49679&r1=49678&r2=49679
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Fri Jan  5 16:52:16 2007
@@ -57,6 +57,7 @@
 #include <signal.h>
 #include <errno.h>
 #include <unistd.h>
+#include <sys/mman.h>
 
 #include "asterisk/channel.h"
 #include "asterisk/file.h"
@@ -2751,9 +2752,6 @@
 			contenttype[format],
 			s->managerid, httptimeout);
 
-	if (format == FORMAT_HTML)
-		ast_str_append(&out, 0, "<title>Asterisk&trade; Manager Interface</title>");
-
 	if (format == FORMAT_XML) {
 		ast_str_append(&out, 0, "<ajax-response>\n");
 	} else if (format == FORMAT_HTML) {
@@ -2764,6 +2762,7 @@
 	user <input name=\"username\"> pass <input type=\"password\" name=\"secret\"><br> \
 	<input type=\"submit\"></form>"
 
+		ast_str_append(&out, 0, "<title>Asterisk&trade; Manager Interface</title>");
 		ast_str_append(&out, 0, "<body bgcolor=\"#ffffff\"><table align=center bgcolor=\"#f1f1f1\" width=\"500\">\r\n");
 		ast_str_append(&out, 0, ROW_FMT, "<h1>Manager Tester</h1>");
 		ast_str_append(&out, 0, ROW_FMT, TEST_STRING);
@@ -2771,25 +2770,21 @@
 
 	if (s->f != NULL) {	/* have temporary output */
 		char *buf;
-		int l = ftell(s->f);
-
-		/* always return something even if len == 0 */
-		if ((buf = ast_calloc(1, l + 1))) {
-			if (l > 0) {
-				fseek(s->f, 0, SEEK_SET);
-				fread(buf, 1, l, s->f);
+		size_t l = ftell(s->f);
+
+		fclose(s->f);
+		if (format == FORMAT_XML || format == FORMAT_HTML) {
+			if (l) {
+				if ((buf = mmap(NULL, l, PROT_READ, MAP_SHARED, s->fd, 0)))
+					xml_translate(&out, buf, params, format);
+			} else {
+				xml_translate(&out, "", params, format);
 			}
-			if (format == FORMAT_XML || format == FORMAT_HTML)
-				xml_translate(&out, buf, params, format);
-			free(buf);
-		}
-		fclose(s->f);
+		}
 		s->f = NULL;
 		s->fd = -1;
 	}
 
-	/* Still okay because c would safely be pointing to workspace even
-	   if retval failed to allocate above */
 	if (format == FORMAT_XML) {
 		ast_str_append(&out, 0, "</ajax-response>\n");
 	} else if (format == FORMAT_HTML)



More information about the asterisk-commits mailing list