From 28f974f00f43d3a04c0bcae32e7cfc85ee66df20 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Sat, 25 Oct 2003 14:13:49 +0000 Subject: [project @ 2003-10-25 14:13:49 by bursa] URL encoded POST support. svn path=/import/netsurf/; revision=375 --- render/box.c | 36 +++++++++++++++++++++++------------- render/form.c | 2 +- render/form.h | 10 +++++++--- render/html.c | 14 +++++++------- 4 files changed, 38 insertions(+), 24 deletions(-) (limited to 'render') diff --git a/render/box.c b/render/box.c index 3ad80ffad..6e9518931 100644 --- a/render/box.c +++ b/render/box.c @@ -14,7 +14,7 @@ #include #include #include "libxml/HTMLparser.h" -#include "netsurf/content/fetchcache.h" +#include "netsurf/content/content.h" #include "netsurf/css/css.h" #include "netsurf/render/box.h" #include "netsurf/render/font.h" @@ -737,22 +737,31 @@ struct result box_image(xmlNode *n, struct status *status, struct result box_form(xmlNode *n, struct status *status, struct css_style *style) { - char* s; + char *s, *s2; struct box *box; struct form *form; box = box_create(style, status->href, status->title); - status->current_form = form = xcalloc(1, sizeof(*form)); - - if ((s = (char *) xmlGetProp(n, (const xmlChar *) "action"))) { - form->action = s; + s = (char *) xmlGetProp(n, (const xmlChar *) "action"); + if (!s) { + /* the action attribute is required */ + return (struct result) {box, 1}; } + status->current_form = form = xcalloc(1, sizeof(*form)); + form->action = s; + form->method = method_GET; if ((s = (char *) xmlGetProp(n, (const xmlChar *) "method"))) { - if (stricmp(s, "post") == 0) - form->method = method_POST; + if (strcasecmp(s, "post") == 0) { + form->method = method_POST_URLENC; + if ((s2 = (char *) xmlGetProp(n, (const xmlChar *) "enctype"))) { + if (strcasecmp(s2, "multipart/form-data") == 0) + form->method = method_POST_MULTIPART; + xmlFree(s2); + } + } xmlFree(s); } @@ -913,13 +922,18 @@ void add_option(xmlNode* n, struct form_control* current_select, char *text) current_select->data.select.last_item->next = option; current_select->data.select.last_item = option; + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value"))) { + option->value = s; + } else { + option->value = xstrdup(text); + } + for (c = text; *c; c++) if (*c == ' ') *c = 160; option->selected = option->initial_selected = false; option->text = text; - option->value = 0; if ((s = (char *) xmlGetProp(n, (const xmlChar *) "selected"))) { xmlFree(s); @@ -930,10 +944,6 @@ void add_option(xmlNode* n, struct form_control* current_select, char *text) current_select->data.select.current = option; } } - - if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value"))) { - option->value = s; - } } struct result box_input(xmlNode *n, struct status *status, diff --git a/render/form.c b/render/form.c index f4ed0a9f8..eade477ba 100644 --- a/render/form.c +++ b/render/form.c @@ -74,7 +74,7 @@ struct form_successful_control *form_successful_controls(struct form *form, if (control->type == GADGET_SELECT) { for (option = control->data.select.items; option; option = option->next) { - if (option->selected && option->value) { + if (option->selected) { success_new = xcalloc(1, sizeof(*success_new)); success_new->name = xstrdup(control->name); success_new->value = xstrdup(option->value); diff --git a/render/form.h b/render/form.h index b81abf01a..10e357ec7 100644 --- a/render/form.h +++ b/render/form.h @@ -14,15 +14,19 @@ #define _NETSURF_RENDER_FORM_H_ #include -#include "netsurf/render/box.h" +struct box; struct form_control; struct form_option; /** HTML form. */ struct form { - char *action; /* url */ - enum {method_GET, method_POST} method; + char *action; /**< Url to submit to. */ + enum { + method_GET, /**< GET, always url encoded. */ + method_POST_URLENC, /**< POST, url encoded. */ + method_POST_MULTIPART /**< POST, multipart/form-data. */ + } method; /**< Method and enctype. */ struct form_control *controls; /**< Linked list of controls. */ struct form_control *last_control; /**< Last control in list. */ }; diff --git a/render/html.c b/render/html.c index 0d868f996..e023de9e8 100644 --- a/render/html.c +++ b/render/html.c @@ -185,7 +185,7 @@ void html_convert_css_callback(content_msg msg, struct content *css, c->active--; c->data.html.stylesheet_content[i] = fetchcache( error, c->url, html_convert_css_callback, - c, i, css->width, css->height, true); + c, i, css->width, css->height, true, 0, 0); if (c->data.html.stylesheet_content[i] != 0 && c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE) c->active++; @@ -238,7 +238,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head) #endif c->url, html_convert_css_callback, - c, 0, c->width, c->height, true); + c, 0, c->width, c->height, true, 0, 0); assert(c->data.html.stylesheet_content[0] != 0); if (c->data.html.stylesheet_content[0]->status != CONTENT_STATUS_DONE) c->active++; @@ -289,7 +289,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head) (i + 1) * sizeof(*c->data.html.stylesheet_content)); c->data.html.stylesheet_content[i] = fetchcache(url, c->url, html_convert_css_callback, c, i, - c->width, c->height, true); + c->width, c->height, true, 0, 0); if (c->data.html.stylesheet_content[i] && c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE) c->active++; @@ -376,8 +376,8 @@ void html_fetch_object(struct content *c, char *url, struct box *box) /* start fetch */ c->data.html.object[i].content = fetchcache(url, c->url, html_object_callback, - c, i, - c->width, c->height, true); /* we don't know the object's + c, i, c->width, c->height, + true, 0, 0); /* we don't know the object's dimensions yet; use parent's as an estimate */ if (c->data.html.object[i].content) { @@ -467,7 +467,7 @@ void html_object_callback(content_msg msg, struct content *object, c->data.html.object[i].url = xstrdup(error); c->data.html.object[i].content = fetchcache( error, c->url, html_object_callback, - c, i, 0, 0, true); + c, i, 0, 0, true, 0, 0); if (c->data.html.object[i].content) { c->active++; if (c->data.html.object[i].content->status == CONTENT_STATUS_DONE) @@ -556,7 +556,7 @@ void html_revive(struct content *c, unsigned int width, unsigned int height) c->data.html.object[i].content = fetchcache( c->data.html.object[i].url, c->url, html_object_callback, - c, i, 0, 0, true); + c, i, 0, 0, true, 0, 0); if (c->data.html.object[i].content && c->data.html.object[i].content->status != CONTENT_STATUS_DONE) c->active++; -- cgit v1.2.3