diff options
-rw-r--r-- | content/fetchers/about.c | 123 | ||||
-rw-r--r-- | desktop/options.c | 94 |
2 files changed, 154 insertions, 63 deletions
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 <http://www.gnu.org/licenses/>. */ -/* 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, "<html>\n<head>\n" "<title>NetSurf Browser Image Cache Status</title>\n" "<link rel=\"stylesheet\" type=\"text/css\" " @@ -215,7 +215,7 @@ static bool fetch_about_imagecache_handler(struct fetch_about_context *ctx) goto fetch_about_imagecache_handler_aborted; /* image cache summary */ - slen = image_cache_snsummaryf(buffer, sizeof(buffer), + slen = image_cache_snsummaryf(buffer, sizeof(buffer), "<p>Configured limit of %a hysteresis of %b</p>\n" "<p>Total bitmap size in use %c (in %d)</p>\n" "<p>Age %es</p>\n" @@ -224,7 +224,7 @@ static bool fetch_about_imagecache_handler(struct fetch_about_context *ctx) "<p>Cache total/hit/miss/fail (counts) %j/%k/%l/%m " "(%pj%%/%pk%%/%pl%%/%pm%%)</p>\n" "<p>Cache total/hit/miss/fail (size) %n/%o/%q/%r " - "(%pn%%/%po%%/%pq%%/%pr%%)</p>\n" + "(%pn%%/%po%%/%pq%%/%pr%%)</p>\n" "<p>Total images never rendered: %s " "(includes %t that were converted)</p>\n" "<p>Total number of excessive conversions: %u " @@ -232,7 +232,7 @@ static bool fetch_about_imagecache_handler(struct fetch_about_context *ctx) "</p>\n" "<p>Bitmap of size %w had most (%x) conversions</p>\n" "<h2>Current image cache contents</h2>\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, "<p class=\"imagecachelist\">\n" "<strong>" "<span>Entry</span>" @@ -266,7 +266,7 @@ static bool fetch_about_imagecache_handler(struct fetch_about_context *ctx) "<span>%s</span>" "<span>%o</span>" "</a>\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, "</p>\n</body>\n</html>\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, "<html>\n<head>\n" "<title>NetSurf Browser Config</title>\n" "<link rel=\"stylesheet\" type=\"text/css\" " @@ -330,14 +334,23 @@ static bool fetch_about_config_handler(struct fetch_about_context *ctx) "<img src=\"resource:netsurf.png\" alt=\"NetSurf\"></a>" "</p>\n" "<h1>NetSurf Browser Config</h1>\n" +#ifdef NS_WITH_INTERACTIVE_ABOUT_CONFIG + "<form action=\"about:config\" method=\"GET\">" +#endif "<table class=\"config\">\n" "<tr><th></th><th></th><th></th></tr>\n"); do { +#ifdef NS_WITH_INTERACTIVE_ABOUT_CONFIG + res = nsoption_snoptionf(buffer + slen, sizeof buffer - slen, + opt_loop, + "<tr><th>%k</th><td>%t</td><td>%I</td></tr>\n"); +#else res = nsoption_snoptionf(buffer + slen, sizeof buffer - slen, opt_loop, "<tr><th>%k</th><td>%t</td><td>%V</td></tr>\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, + "</table>\n"); + slen += snprintf(buffer + slen, sizeof buffer - slen, + "<br/><center>" + "<input type=\"hidden\" name=\"token\" value=\"\" />\n" + "<input type=\"submit\" name=\"action\" value=\"Save\" />\n" + "<input type=\"submit\" name=\"action\" value=\"Abort\" />\n" + "</center><br/>\n" + "</form>\n" "</table>\n</body>\n</html>\n"); +#else + slen += snprintf(buffer + slen, sizeof buffer - slen, + "</table>\n</body>\n</html>\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, "<html>\n<head>\n" "<title>NetSurf List of About pages</title>\n" "<link rel=\"stylesheet\" type=\"text/css\" " @@ -653,11 +680,11 @@ static bool fetch_about_about_handler(struct fetch_about_context *ctx) if (about_handler_list[abt_loop].hidden) continue; - res = snprintf(buffer + slen, sizeof buffer - slen, - "<li><a href=\"about:%s\">about:%s</a></li>\n", - about_handler_list[abt_loop].name, + res = snprintf(buffer + slen, sizeof buffer - slen, + "<li><a href=\"about:%s\">about:%s</a></li>\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, "</ul>\n</body>\n</html>\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) diff --git a/desktop/options.c b/desktop/options.c index 2a080d564..4bdac6d24 100644 --- a/desktop/options.c +++ b/desktop/options.c @@ -67,7 +67,7 @@ struct option_entry_s option_table[] = { /** * Set an option value based on a string */ -static bool +static bool strtooption(const char *value, struct option_entry_s *option_entry) { bool ret = false; @@ -188,12 +188,12 @@ void nsoption_write(const char *path) for (entry = 0; entry != option_table_entries; entry++) { switch (option_table[entry].type) { case OPTION_BOOL: - fprintf(fp, "%s:%c\n", option_table[entry].key, + fprintf(fp, "%s:%c\n", option_table[entry].key, *((bool *) option_table[entry].p) ? '1' : '0'); break; case OPTION_INTEGER: - fprintf(fp, "%s:%i\n", option_table[entry].key, + fprintf(fp, "%s:%i\n", option_table[entry].key, *((int *) option_table[entry].p)); break; @@ -204,12 +204,12 @@ void nsoption_write(const char *path) option_table[entry].p)) << 0) | ((0x00FF0000 & *((colour *) option_table[entry].p)) >> 16); - fprintf(fp, "%s:%06x\n", option_table[entry].key, + fprintf(fp, "%s:%06x\n", option_table[entry].key, rgbcolour); break; case OPTION_STRING: - if (((*((char **) option_table[entry].p)) != NULL) && + if (((*((char **) option_table[entry].p)) != NULL) && (*(*((char **) option_table[entry].p)) != 0)) { fprintf(fp, "%s:%s\n", option_table[entry].key, *((char **) option_table[entry].p)); @@ -231,7 +231,7 @@ void nsoption_write(const char *path) * \param string The string in which to output the value. * \return The number of bytes written to string or -1 on error */ -static size_t +static size_t nsoption_output_value_html(struct option_entry_s *option, size_t size, size_t pos, char *string) { @@ -274,6 +274,66 @@ nsoption_output_value_html(struct option_entry_s *option, return slen; } +/** + * Output an option value into a string, in HTML form element format. + * + * \param option The option to output the value of. + * \param size The size of the string buffer. + * \param pos The current position in string + * \param string The string in which to output the value. + * \return The number of bytes written to string or -1 on error + */ +static size_t +nsoption_output_value_html_input(struct option_entry_s *option, + size_t size, size_t pos, char *string) +{ + size_t slen = 0; /* length added to string */ + colour rgbcolour; /* RRGGBB */ + char hexcolour[7]; + + switch (option->type) { + case OPTION_BOOL: + slen = snprintf(string + pos, size - pos, + "<select name=\"%s\">" + "<option value=1 %s>Enabled" + "<option value=0 %s>Disabled" + "</select>", + option->key, + *((bool *)option->p) ? "selected" : "", + *((bool *)option->p) ? "" : "selected"); + break; + + case OPTION_INTEGER: + slen = snprintf(string + pos, size - pos, + "<input type=\"text\" name=\"%s\" value=\"%i\"/>", + option->key, *((int *)option->p)); + break; + + case OPTION_COLOUR: + rgbcolour = ((0x000000FF & *((colour *) option->p)) << 16) | + ((0x0000FF00 & *((colour *) option->p)) << 0) | + ((0x00FF0000 & *((colour *) option->p)) >> 16); + slen = snprintf(string + pos, size - pos, + "<input type=\"text\" name=\"%s\" value=\"%06x\"/> " + "<span style=\"background-color: #%06x; color: #%06x; \">" + " </span>", + option->key, rgbcolour, + rgbcolour, (~rgbcolour) & 0xffffff); + break; + + case OPTION_STRING: + slen = snprintf(string + pos, size - pos, + "<input type=\"text\" name=\"%s\" value=\"%s\"/>", + option->key, + (*((char **)option->p) != NULL) ? + *((char **)option->p) : + "NULL"); + break; + } + + return slen; +} + /** * Output an option value into a string, in plain text format. @@ -284,7 +344,7 @@ nsoption_output_value_html(struct option_entry_s *option, * \param string The string in which to output the value. * \return The number of bytes written to string or -1 on error */ -static size_t +static size_t nsoption_output_value_text(struct option_entry_s *option, size_t size, size_t pos, char *string) { @@ -321,7 +381,7 @@ nsoption_output_value_text(struct option_entry_s *option, } /* exported interface documented in options.h */ -void +void nsoption_commandline(int *pargc, char **argv) { char *arg; @@ -360,14 +420,14 @@ nsoption_commandline(int *pargc, char **argv) LOG(("%.*s = %s",arglen,arg,val)); - for (entry_loop = 0; - entry_loop < option_table_entries; + for (entry_loop = 0; + entry_loop < option_table_entries; entry_loop++) { - if (strncmp(arg, option_table[entry_loop].key, - arglen) == 0) { + if (strncmp(arg, option_table[entry_loop].key, + arglen) == 0) { strtooption(val, option_table + entry_loop); break; - } + } } idx++; @@ -381,7 +441,7 @@ nsoption_commandline(int *pargc, char **argv) } /* exported interface documented in options.h */ -int +int nsoption_snoptionf(char *string, size_t size, unsigned int option, const char *fmt) { size_t slen = 0; /* current output string length */ @@ -440,6 +500,10 @@ nsoption_snoptionf(char *string, size_t size, unsigned int option, const char *f slen += nsoption_output_value_text(option_entry, size, slen, string); break; + case 'I': + slen += nsoption_output_value_html_input(option_entry, + size, slen, string); + break; } fmtc++; } else { @@ -456,7 +520,7 @@ nsoption_snoptionf(char *string, size_t size, unsigned int option, const char *f } /* exported interface documented in options.h */ -void +void nsoption_dump(FILE *outf) { char buffer[256]; |