From f72305504d83034e0350d9291fdf8f54641ab764 Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Fri, 21 Dec 2012 06:39:51 +0100 Subject: Use multipart/form-data for data transmission. Requires some new nsoption functions to be saved. (Conversion -> option name to index) --- content/fetchers/about.c | 55 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'content/fetchers/about.c') diff --git a/content/fetchers/about.c b/content/fetchers/about.c index 81ff2e153..f0d7c9e77 100644 --- a/content/fetchers/about.c +++ b/content/fetchers/about.c @@ -71,6 +71,8 @@ struct fetch_about_context { nsurl *url; /**< The full url the fetch refers to */ + struct fetch_multipart_data *post_multipart; /**< Form data */ + fetch_about_handler handler; }; @@ -309,7 +311,43 @@ static bool fetch_about_config_handler(struct fetch_about_context *ctx) int res = 0; lwc_string *path; url_func_result status; + struct fetch_multipart_data *post_item; + bool do_save = false; + bool valid_token = false; + char token[9] = {"12345678"}; + + /* save settings: */ + post_item = ctx->post_multipart; + while (post_item != NULL) { + + if (strcmp(post_item->name, "token") == 0 + && sctrcmp(post_item->value, token) == 0) { + valid_token = true; + if (do_save == true) { + break; + } + } + + if (strcmp(post_item->name, "action") == 0 + && sctrcmp(post_item->value, "Save") == 0) { + do_save = true; + if (valid_token == true) { + break; + } + } + post_item = post_item->next; + } + if (do_save && valid_token) { + int opt = 0; + post_item = ctx->post_multipart; + while (post_item != NULL) { + printf("%s -> %s\n", post_item->name, post_item->value); + //opt = nsoption_get_index(post_item->name); + //nsoption_get_type(opt); + post_item = post_item->next; + } + } /* content is going to return ok */ fetch_set_http_code(ctx->fetchh, code); @@ -335,14 +373,15 @@ static bool fetch_about_config_handler(struct fetch_about_context *ctx) "

\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, + res = nsoption_snoptionf(buffer + slen, sizeof buffer - slen, opt_loop, "\n"); #else @@ -371,12 +410,13 @@ static bool fetch_about_config_handler(struct fetch_about_context *ctx) "
%k%t%I
\n"); slen += snprintf(buffer + slen, sizeof buffer - slen, "
" - "\n" + "\n" "\n" "\n" "

\n" "
\n" - "\n\n\n"); + "\n\n\n", + token); #else slen += snprintf(buffer + slen, sizeof buffer - slen, "\n\n\n"); @@ -788,6 +828,10 @@ fetch_about_setup(struct fetch *fetchh, ctx->fetchh = fetchh; ctx->url = nsurl_ref(url); + if (post_multipart != NULL) { + ctx->post_multipart = fetch_multipart_data_clone(post_multipart); + } + RING_INSERT(ring, ctx); return ctx; @@ -797,6 +841,9 @@ fetch_about_setup(struct fetch *fetchh, static void fetch_about_free(void *ctx) { struct fetch_about_context *c = ctx; + if (c->post_multipart) { + fetch_multipart_data_destroy(c->post_multipart); + } nsurl_unref(c->url); RING_REMOVE(ring, c); free(ctx); -- cgit v1.2.3