From: Kevin P. Fleming Date: Fri, 5 Jan 2007 22:52:16 +0000 (+0000) Subject: use mmap() to read in the results of the manager action for an HTTP request, instead... X-Git-Tag: 1.6.0-beta1~3^2~3546 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d376fca97de876b7258fc962718d1ca86e145e1;p=thirdparty%2Fasterisk.git use mmap() to read in the results of the manager action for an HTTP request, instead of reading it into a buffer git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@49679 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/manager.c b/main/manager.c index 345a94ecad..72b0cc9b5e 100644 --- a/main/manager.c +++ b/main/manager.c @@ -57,6 +57,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include #include #include +#include #include "asterisk/channel.h" #include "asterisk/file.h" @@ -2751,9 +2752,6 @@ static struct ast_str *generic_http_callback(enum output_format format, contenttype[format], s->managerid, httptimeout); - if (format == FORMAT_HTML) - ast_str_append(&out, 0, "Asterisk™ Manager Interface"); - if (format == FORMAT_XML) { ast_str_append(&out, 0, "\n"); } else if (format == FORMAT_HTML) { @@ -2764,6 +2762,7 @@ static struct ast_str *generic_http_callback(enum output_format format, user pass
\ " + ast_str_append(&out, 0, "Asterisk™ Manager Interface"); ast_str_append(&out, 0, "\r\n"); ast_str_append(&out, 0, ROW_FMT, "

Manager Tester

"); ast_str_append(&out, 0, ROW_FMT, TEST_STRING); @@ -2771,25 +2770,21 @@ static struct ast_str *generic_http_callback(enum output_format format, if (s->f != NULL) { /* have temporary output */ char *buf; - int l = ftell(s->f); + size_t 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); + 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, "\n"); } else if (format == FORMAT_HTML)