From 3bc7316ac8873d8b17ceef66168dfa5bb14928ff Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Fri, 21 Dec 2012 05:46:20 +0100 Subject: Render HTML Form for Choices submission. Causes memory corruption when submitted via GET. Retrieving Post data requires a bit more indepth knowledge about the fetcher. --- content/fetchers/about.c | 123 +++++++++++++++++++++++++++++------------------ 1 file changed, 75 insertions(+), 48 deletions(-) (limited to 'content/fetchers') diff --git a/content/fetchers/about.c b/content/fetchers/about.c index 78f22df01..81ff2e153 100644 --- a/content/fetchers/about.c +++ b/content/fetchers/about.c @@ -16,9 +16,9 @@ * along with this program. If not, see . */ -/* about: URL handling. +/* about: URL handling. * - * Based on the data fetcher by Rob Kendrick + * Based on the data fetcher by Rob Kendrick * This fetcher provides a simple scheme for the user to access * information from the browser from a known, fixed URL. */ @@ -198,7 +198,7 @@ static bool fetch_about_imagecache_handler(struct fetch_about_context *ctx) msg.data.header_or_data.buf = (const uint8_t *) buffer; /* page head */ - slen = snprintf(buffer, sizeof buffer, + slen = snprintf(buffer, sizeof buffer, "\n\n" "NetSurf Browser Image Cache Status\n" "Configured limit of %a hysteresis of %b

\n" "

Total bitmap size in use %c (in %d)

\n" "

Age %es

\n" @@ -224,7 +224,7 @@ static bool fetch_about_imagecache_handler(struct fetch_about_context *ctx) "

Cache total/hit/miss/fail (counts) %j/%k/%l/%m " "(%pj%%/%pk%%/%pl%%/%pm%%)

\n" "

Cache total/hit/miss/fail (size) %n/%o/%q/%r " - "(%pn%%/%po%%/%pq%%/%pr%%)

\n" + "(%pn%%/%po%%/%pq%%/%pr%%)

\n" "

Total images never rendered: %s " "(includes %t that were converted)

\n" "

Total number of excessive conversions: %u " @@ -232,7 +232,7 @@ static bool fetch_about_imagecache_handler(struct fetch_about_context *ctx) "

\n" "

Bitmap of size %w had most (%x) conversions

\n" "

Current image cache contents

\n"); - if (slen >= (int) (sizeof(buffer))) + if (slen >= (int) (sizeof(buffer))) goto fetch_about_imagecache_handler_aborted; /* overflow */ msg.data.header_or_data.len = slen; @@ -241,7 +241,7 @@ static bool fetch_about_imagecache_handler(struct fetch_about_context *ctx) /* image cache entry table */ - slen = snprintf(buffer, sizeof buffer, + slen = snprintf(buffer, sizeof buffer, "

\n" "" "Entry" @@ -266,7 +266,7 @@ static bool fetch_about_imagecache_handler(struct fetch_about_context *ctx) "%s" "%o" "\n"); - if (res <= 0) + if (res <= 0) break; /* last option */ if (res >= (int) (sizeof buffer - slen)) { @@ -282,7 +282,7 @@ static bool fetch_about_imagecache_handler(struct fetch_about_context *ctx) } } while (res > 0); - slen += snprintf(buffer + slen, sizeof buffer - slen, + slen += snprintf(buffer + slen, sizeof buffer - slen, "

\n\n\n"); msg.data.header_or_data.len = slen; @@ -307,6 +307,9 @@ static bool fetch_about_config_handler(struct fetch_about_context *ctx) int slen; unsigned int opt_loop = 0; int res = 0; + lwc_string *path; + url_func_result status; + /* content is going to return ok */ fetch_set_http_code(ctx->fetchh, code); @@ -318,7 +321,8 @@ static bool fetch_about_config_handler(struct fetch_about_context *ctx) msg.type = FETCH_DATA; msg.data.header_or_data.buf = (const uint8_t *) buffer; - slen = snprintf(buffer, sizeof buffer, +#define NS_WITH_INTERACTIVE_ABOUT_CONFIG 1 + slen = snprintf(buffer, sizeof buffer, "\n\n" "NetSurf Browser Config\n" "" "

\n" "

NetSurf Browser Config

\n" +#ifdef NS_WITH_INTERACTIVE_ABOUT_CONFIG + "
" +#endif "\n" "\n"); do { +#ifdef NS_WITH_INTERACTIVE_ABOUT_CONFIG + res = nsoption_snoptionf(buffer + slen, sizeof buffer - slen, + opt_loop, + "\n"); +#else res = nsoption_snoptionf(buffer + slen, sizeof buffer - slen, opt_loop, "\n"); - if (res <= 0) +#endif + if (res <= 0) break; /* last option */ if (res >= (int) (sizeof buffer - slen)) { @@ -353,8 +366,22 @@ static bool fetch_about_config_handler(struct fetch_about_context *ctx) } } while (res > 0); - slen += snprintf(buffer + slen, sizeof buffer - slen, +#ifdef NS_WITH_INTERACTIVE_ABOUT_CONFIG + slen += snprintf(buffer + slen, sizeof buffer - slen, + "
%k%t%I
%k%t%V
\n"); + slen += snprintf(buffer + slen, sizeof buffer - slen, + "
" + "\n" + "\n" + "\n" + "

\n" + "
\n" "\n\n\n"); +#else + slen += snprintf(buffer + slen, sizeof buffer - slen, + "\n\n\n"); +#endif + msg.data.header_or_data.len = slen; if (fetch_about_send_callback(&msg, ctx)) @@ -371,7 +398,7 @@ fetch_about_config_handler_aborted: /** Generate the text of a Choices file which represents the current - * in use options. + * in use options. */ static bool fetch_about_choices_handler(struct fetch_about_context *ctx) { @@ -392,15 +419,15 @@ static bool fetch_about_choices_handler(struct fetch_about_context *ctx) msg.type = FETCH_DATA; msg.data.header_or_data.buf = (const uint8_t *) buffer; - slen = snprintf(buffer, sizeof buffer, + slen = snprintf(buffer, sizeof buffer, "# Automatically generated current NetSurf browser Choices\n"); do { - res = nsoption_snoptionf(buffer + slen, - sizeof buffer - slen, - opt_loop, + res = nsoption_snoptionf(buffer + slen, + sizeof buffer - slen, + opt_loop, "%k:%v\n"); - if (res <= 0) + if (res <= 0) break; /* last option */ if (res >= (int) (sizeof buffer - slen)) { @@ -441,7 +468,7 @@ static bool fetch_about_testament_handler(struct fetch_about_context *ctx) int code = 200; int slen; int i; - + /* content is going to return ok */ fetch_set_http_code(ctx->fetchh, code); @@ -453,14 +480,14 @@ static bool fetch_about_testament_handler(struct fetch_about_context *ctx) msg.type = FETCH_DATA; msg.data.header_or_data.buf = (const uint8_t *) buffer; - slen = snprintf(buffer, sizeof buffer, + slen = snprintf(buffer, sizeof buffer, "# Automatically generated by NetSurf build system\n\n"); msg.data.header_or_data.len = slen; if (fetch_about_send_callback(&msg, ctx)) goto fetch_about_testament_handler_aborted; - - slen = snprintf(buffer, sizeof buffer, + + slen = snprintf(buffer, sizeof buffer, #if defined(WT_BRANCHISTRUNK) || defined(WT_BRANCHISMASTER) "# This is a *DEVELOPMENT* build from the main line.\n\n" #elif defined(WT_BRANCHISTAG) && (WT_MODIFIED == 0) @@ -482,29 +509,29 @@ static bool fetch_about_testament_handler(struct fetch_about_context *ctx) #endif ); - msg.data.header_or_data.len = slen; + msg.data.header_or_data.len = slen; if (fetch_about_send_callback(&msg, ctx)) goto fetch_about_testament_handler_aborted; - - slen = snprintf(buffer, sizeof buffer, + + slen = snprintf(buffer, sizeof buffer, "Built by %s (%s) from %s at revision %s\n\n", GECOS, USERNAME, WT_BRANCHPATH, WT_REVID); msg.data.header_or_data.len = slen; if (fetch_about_send_callback(&msg, ctx)) goto fetch_about_testament_handler_aborted; - - slen = snprintf(buffer, sizeof buffer, + + slen = snprintf(buffer, sizeof buffer, "Built on %s in %s\n\n", WT_HOSTNAME, WT_ROOT); msg.data.header_or_data.len = slen; if (fetch_about_send_callback(&msg, ctx)) goto fetch_about_testament_handler_aborted; - + if (WT_MODIFIED > 0) { - slen = snprintf(buffer, sizeof buffer, + slen = snprintf(buffer, sizeof buffer, "Working tree has %d modification%s\n\n", WT_MODIFIED, WT_MODIFIED == 1 ? "" : "s"); } else { @@ -515,7 +542,7 @@ static bool fetch_about_testament_handler(struct fetch_about_context *ctx) msg.data.header_or_data.len = slen; if (fetch_about_send_callback(&msg, ctx)) goto fetch_about_testament_handler_aborted; - + for (i = 0; i < WT_MODIFIED; ++i) { slen = snprintf(buffer, sizeof buffer, " %s %s\n", @@ -524,10 +551,10 @@ static bool fetch_about_testament_handler(struct fetch_about_context *ctx) msg.data.header_or_data.len = slen; if (fetch_about_send_callback(&msg, ctx)) goto fetch_about_testament_handler_aborted; - + } - msg.type = FETCH_FINISHED; + msg.type = FETCH_FINISHED; fetch_about_send_callback(&msg, ctx); return true; @@ -602,15 +629,15 @@ struct about_handlers about_handler_list[] = { fetch_about_imagecache_handler, true }, /* The default blank page */ { "blank", SLEN("blank"), NULL, - fetch_about_blank_handler, true } + fetch_about_blank_handler, true } }; #define about_handler_list_len (sizeof(about_handler_list) / \ sizeof(struct about_handlers)) /** - * List all the valid about: paths available - * + * List all the valid about: paths available + * * \param ctx The fetch context. * \return true for sucess or false to generate an error. */ @@ -633,7 +660,7 @@ static bool fetch_about_about_handler(struct fetch_about_context *ctx) msg.type = FETCH_DATA; msg.data.header_or_data.buf = (const uint8_t *) buffer; - slen = snprintf(buffer, sizeof buffer, + slen = snprintf(buffer, sizeof buffer, "\n\n" "NetSurf List of About pages\n" "about:%s\n", - about_handler_list[abt_loop].name, + res = snprintf(buffer + slen, sizeof buffer - slen, + "
  • about:%s
  • \n", + about_handler_list[abt_loop].name, about_handler_list[abt_loop].name); - if (res <= 0) + if (res <= 0) break; /* last option */ if (res >= (int)(sizeof buffer - slen)) { @@ -672,7 +699,7 @@ static bool fetch_about_about_handler(struct fetch_about_context *ctx) } } - slen += snprintf(buffer + slen, sizeof buffer - slen, + slen += snprintf(buffer + slen, sizeof buffer - slen, "\n\n\n"); msg.data.header_or_data.len = slen; @@ -696,8 +723,8 @@ static bool fetch_about_initialise(lwc_string *scheme) lwc_error error; for (abt_loop = 0; abt_loop < about_handler_list_len; abt_loop++) { - error = lwc_intern_string(about_handler_list[abt_loop].name, - about_handler_list[abt_loop].name_len, + error = lwc_intern_string(about_handler_list[abt_loop].name, + about_handler_list[abt_loop].name_len, &about_handler_list[abt_loop].lname); if (error != lwc_error_ok) { while (abt_loop-- != 0) { @@ -744,15 +771,15 @@ fetch_about_setup(struct fetch *fetchh, path = nsurl_get_component(url, NSURL_PATH); - for (handler_loop = 0; - handler_loop < about_handler_list_len; + for (handler_loop = 0; + handler_loop < about_handler_list_len; handler_loop++) { ctx->handler = about_handler_list[handler_loop].handler; - if (lwc_string_isequal(path, - about_handler_list[handler_loop].lname, + if (lwc_string_isequal(path, + about_handler_list[handler_loop].lname, &match) == lwc_error_ok && match) { break; - } + } } if (path != NULL) -- cgit v1.2.3