From 675a07083acbfd276c4d80fbf5df4d18fb8e5742 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 20 Feb 2011 21:04:53 +0000 Subject: add options display to about: scheme svn path=/trunk/netsurf/; revision=11733 --- content/fetchers/about.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) (limited to 'content/fetchers') diff --git a/content/fetchers/about.c b/content/fetchers/about.c index c0507aaa4..c93fdbad4 100644 --- a/content/fetchers/about.c +++ b/content/fetchers/about.c @@ -175,6 +175,120 @@ fetch_about_credits_handler_aborted: return false; } +static bool fetch_about_config_handler(struct fetch_about_context *ctx) +{ + char buffer[1024]; + int code = 200; + int slen; + unsigned int opt_loop = 0; + int res = 0; + + /* content is going to return ok */ + fetch_set_http_code(ctx->fetchh, code); + + /* content type */ + if (fetch_about_send_header(ctx, "Content-Type: text/html")) + goto fetch_about_config_handler_aborted; + + slen = snprintf(buffer, sizeof buffer, + "NetSurf Browser Config" + "" + "

NetSurf Browser Config

" + ""); + + do { + res = snoptionf(buffer + slen, sizeof buffer - slen, opt_loop, + ""); + if (res <= 0) + break; /* last option */ + + if (res >= (sizeof buffer - slen)) { + /* last entry would not fit in buffer, submit buffer */ + if (fetch_about_send_callback(FETCH_DATA, ctx, buffer, + slen, FETCH_ERROR_NO_ERROR)) + goto fetch_about_config_handler_aborted; + slen = 0; + } else { + /* normal addition */ + slen += res; + opt_loop++; + } + } while (res > 0); + + slen += snprintf(buffer + slen, sizeof buffer - slen, + "
%k%t%V
"); + + if (fetch_about_send_callback(FETCH_DATA, ctx, buffer, slen, + FETCH_ERROR_NO_ERROR)) + goto fetch_about_config_handler_aborted; + + fetch_about_send_callback(FETCH_FINISHED, ctx, 0, 0, + FETCH_ERROR_NO_ERROR); + + return true; + +fetch_about_config_handler_aborted: + return false; +} + +/** Generate the text of a Choices file which represents the current + * in use options. + */ +static bool fetch_about_choices_handler(struct fetch_about_context *ctx) +{ + char buffer[1024]; + int code = 200; + int slen; + unsigned int opt_loop = 0; + int res = 0; + + /* content is going to return ok */ + fetch_set_http_code(ctx->fetchh, code); + + /* content type */ + if (fetch_about_send_header(ctx, "Content-Type: text/plain")) + goto fetch_about_choices_handler_aborted; + + slen = snprintf(buffer, sizeof buffer, + "# Automatically generated current NetSurf browser Choices\n"); + + do { + res = snoptionf(buffer + slen, + sizeof buffer - slen, + opt_loop, + "%k:%v\n"); + if (res <= 0) + break; /* last option */ + + if (res >= (sizeof buffer - slen)) { + /* last entry would not fit in buffer, submit buffer */ + if (fetch_about_send_callback(FETCH_DATA, ctx, buffer, + slen, FETCH_ERROR_NO_ERROR)) + goto fetch_about_choices_handler_aborted; + slen = 0; + } else { + /* normal addition */ + slen += res; + opt_loop++; + } + } while (res > 0); + + if (fetch_about_send_callback(FETCH_DATA, ctx, buffer, slen, + FETCH_ERROR_NO_ERROR)) + goto fetch_about_choices_handler_aborted; + + fetch_about_send_callback(FETCH_FINISHED, ctx, 0, 0, + FETCH_ERROR_NO_ERROR); + + return true; + +fetch_about_choices_handler_aborted: + return false; +} + + struct about_handlers { const char *name; fetch_about_handler handler; @@ -182,6 +296,8 @@ struct about_handlers { struct about_handlers about_handler_list[] = { { "credits", fetch_about_credits_handler }, + { "config", fetch_about_config_handler }, + { "Choices", fetch_about_choices_handler }, { "blank", fetch_about_blank_handler } /* The default */ }; -- cgit v1.2.3