From: Fabian Keil Date: Thu, 24 Apr 2008 16:12:38 +0000 (+0000) Subject: In cgi_show_status(), load the requested file at once. X-Git-Tag: v_3_0_9~142 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=98680dd7a1a8ca55e4cd3228f3710cd136514be1 In cgi_show_status(), load the requested file at once. Using string_join() for every line really doesn't scale. --- diff --git a/ChangeLog b/ChangeLog index eb8db938..950fb792 100644 --- a/ChangeLog +++ b/ChangeLog @@ -39,6 +39,12 @@ ChangeLog for Privoxy inactive actions are listed separately. Patch provided by Lee. - The GNUmakefile supports the DESTDIR variable. Patch for the install target submitted by Radoslaw Zielinski. +- Embedding the content of configuration files in the show-status + page is significantly faster now. For a largish action file (1 MB) + a speedup of about 2450 times has been measured. This is mostly + interesting if you are using large action files or regularly use + Privoxy-Regression-Test while running Privoxy through Valgrind, + for stock configuration files it doesn't really matter. - The obsolete kill-popups action has been removed as the PCRS-based popup filters can do the same and are less unreliable. diff --git a/cgisimple.c b/cgisimple.c index 373cb978..d9de78e4 100644 --- a/cgisimple.c +++ b/cgisimple.c @@ -1,4 +1,4 @@ -const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.68 2008/03/27 18:27:21 fabiankeil Exp $"; +const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.69 2008/04/17 14:40:48 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgisimple.c,v $ @@ -36,6 +36,10 @@ const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.68 2008/03/27 18:27:21 fabian * * Revisions : * $Log: cgisimple.c,v $ + * Revision 1.69 2008/04/17 14:40:48 fabiankeil + * Provide get_http_time() with the buffer size so it doesn't + * have to blindly assume that the buffer is big enough. + * * Revision 1.68 2008/03/27 18:27:21 fabiankeil * Remove kill-popups action. * @@ -1168,7 +1172,7 @@ jb_err cgi_show_status(struct client_state *csp, return JB_ERR_MEMORY; } - if ((fp = fopen(filename, "r")) == NULL) + if ((fp = fopen(filename, "rb")) == NULL) { if (map(exports, "content", 1, "

ERROR OPENING FILE!

", 1)) { @@ -1178,13 +1182,40 @@ jb_err cgi_show_status(struct client_state *csp, } else { - s = strdup(""); - while ((s != NULL) && fgets(buf, sizeof(buf), fp)) + /* + * XXX: this code is "quite similar" to the one + * in cgi_send_user_manual() and should be refactored. + * While at it, the return codes for ftell() and fseek + * should be verified. + */ + size_t length; + /* Get file length */ + fseek(fp, 0, SEEK_END); + length = (size_t)ftell(fp); + fseek(fp, 0, SEEK_SET); + + s = (char *)zalloc(length+1); + if (NULL == s) + { + fclose(fp); + return JB_ERR_MEMORY; + } + if (!fread(s, length, 1, fp)) { - string_join (&s, html_encode(buf)); + /* + * May happen if the file size changes between fseek() and fread(). + * If it does, we just log it and serve what we got. + */ + log_error(LOG_LEVEL_ERROR, "Couldn't completely read file %s.", filename); } fclose(fp); + s = html_encode_and_free_original(s); + if (NULL == s) + { + return JB_ERR_MEMORY; + } + if (map(exports, "contents", 1, s, 0)) { free_map(exports);