diff --git a/desktop/browser.c b/desktop/browser.c index fb2980486..2ca710d1e 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1,5 +1,5 @@ /** - * $Id: browser.c,v 1.36 2003/05/10 11:13:34 bursa Exp $ + * $Id: browser.c,v 1.37 2003/05/22 13:21:45 bursa Exp $ */ #include "netsurf/content/cache.h" @@ -11,6 +11,7 @@ #include "netsurf/utils/utils.h" #include "libxml/uri.h" #include "libxml/debugXML.h" +#include "curl/curl.h" #include #include #include @@ -36,6 +37,9 @@ static void gui_redraw_gadget2(struct browser_window* bw, struct box* box, struc unsigned long x, unsigned long y); static void browser_window_gadget_select(struct browser_window* bw, struct gui_gadget* g, int item); static int browser_window_gadget_click(struct browser_window* bw, unsigned long click_x, unsigned long click_y); +static void browser_form_submit(struct browser_window *bw, struct form *form); +static char* browser_form_construct_get(struct page_elements *elements, struct formsubmit* fs); +static void browser_form_get_append(char **s, int *length, char sep, char *name, char *value); void browser_window_start_throbber(struct browser_window* bw) @@ -418,8 +422,11 @@ int browser_window_gadget_click(struct browser_window* bw, unsigned long click_x gui_redraw_gadget(bw, g); break; case GADGET_ACTIONBUTTON: + /* redraw button */ g->data.actionbutt.pressed = -1; gui_redraw_gadget(bw, g); + if (stricmp(g->data.actionbutt.butttype,"submit") == 0) + browser_form_submit(bw, g->form); break; case GADGET_TEXTAREA: gui_edit_textarea(bw, g); @@ -866,3 +873,115 @@ void browser_window_redraw_boxes(struct browser_window* bw, struct box_position* } +void browser_form_submit(struct browser_window *bw, struct form *form) +{ + /*create submission request*/ + struct formsubmit* fs = (struct formsubmit*) xcalloc(1, sizeof(struct formsubmit)); + fs->form = form; + /*fs->items = g;*/ + LOG(("Submission request created")); + + if (fs->form->method == method_GET) { + /*GET request*/ + /*GET basically munges the entire form data + into one URL. */ + + char *url = browser_form_construct_get(&bw->current_content->data.html.elements, + fs); + + LOG(("GET request")); + + /*send request*/ + browser_window_open_location(bw, url); + xfree(url); + + } else { + /*POST request*/ + assert(fs->form->method == method_POST); + + LOG(("POST request - not implemented yet")); + + /*POST is a standard HTTP method. + Basically, it creates a new request + and sends the form data as the request + body.*/ + } + + xfree(fs); +} + + +char* browser_form_construct_get(struct page_elements *elements, struct formsubmit* fs) +{ + char *ret; + int i,j, length; + struct formoption* opt; + + ret = xstrdup(fs->form->action); + length = strlen(ret); + + j=0; + for (i=0;inumGadgets;i++){ + if(elements->gadgets[i]->form == fs->form){ + + if(elements->gadgets[i]->name != 0){ + char *value = 0; + + switch(elements->gadgets[i]->type){ + + case GADGET_HIDDEN: value = elements->gadgets[i]->data.hidden.value; + break; + case GADGET_TEXTBOX: value = elements->gadgets[i]->data.textbox.text; + break; + case GADGET_RADIO: if(elements->gadgets[i]->data.radio.selected == -1) + value = elements->gadgets[i]->data.radio.value; + break; + case GADGET_CHECKBOX: if(elements->gadgets[i]->data.checkbox.selected == 1) + value = elements->gadgets[i]->data.checkbox.value; + break; + case GADGET_SELECT: opt = elements->gadgets[i]->data.select.items; + while(opt != NULL){ + if(opt->selected == -1 || opt->selected == 1) { + browser_form_get_append(&ret, &length, j == 0 ? '?' : '&', + elements->gadgets[i]->name, opt->value); + j++; + } + opt = opt->next; + } + break; + case GADGET_TEXTAREA: value = elements->gadgets[i]->data.textarea.text; + break; + default: break; + } + + if (value != 0) { + browser_form_get_append(&ret, &length, j == 0 ? '?' : '&', + elements->gadgets[i]->name, value); + j++; + } + } + + } + } + return ret; +} + + +void browser_form_get_append(char **s, int *length, char sep, char *name, char *value) +{ + unsigned int length1; + + name = curl_escape(name, 0); + value = curl_escape(value, 0); + length1 = 2 + strlen(name) + strlen(value); + + LOG(("append %c%s=%s, length1 %i, *s %p", sep, name, value, length1, *s)); + *s = xrealloc(*s, *length + length1 + 1); + + sprintf(*s + *length, "%c%s=%s", sep, name, value); + *length += length1; + + curl_free(name); + curl_free(value); +} + diff --git a/developer b/developer index 7bb818285..a8c443cec 100644 --- a/developer +++ b/developer @@ -103,6 +103,7 @@ http://netsurf.strcprstskrzkrk.co.uk/developer/ libxml (XML and HTML parser) http://xmlsoft.org/ libcurl (HTTP, FTP, etc) http://curl.haxx.se/libcurl/ OSLib (C interface to RISC OS SWIs) http://ro-oslib.sourceforge.net/ -libutf-8 http://www.whizkidtech.redprince.net/i18n/ +libpng (PNG support) http://www.libpng.org/pub/png/libpng.html +zlib http://www.gzip.org/zlib/ ________________________________________________________________________________ diff --git a/render/box.c b/render/box.c index 9e0788fc0..188132745 100644 --- a/render/box.c +++ b/render/box.c @@ -1,5 +1,5 @@ /** - * $Id: box.c,v 1.43 2003/04/25 08:03:15 bursa Exp $ + * $Id: box.c,v 1.44 2003/05/22 13:21:45 bursa Exp $ */ #include @@ -1270,6 +1270,9 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current if ((s = (char *) xmlGetProp(n, (const xmlChar *) "name"))) { box->gadget->name = s; } + + box->gadget->data.actionbutt.butttype = strdup(type); + add_gadget_element(elements, box->gadget); } diff --git a/render/box.h b/render/box.h index 5adb69554..fb5e4c5bd 100644 --- a/render/box.h +++ b/render/box.h @@ -1,5 +1,5 @@ /** - * $Id: box.h,v 1.24 2003/04/15 17:53:00 bursa Exp $ + * $Id: box.h,v 1.25 2003/05/22 13:21:45 bursa Exp $ */ #ifndef _NETSURF_RENDER_BOX_H_ @@ -49,6 +49,7 @@ struct gui_gadget { int size; } textbox; struct { + char* butttype; char* label; int pressed; } actionbutt; diff --git a/utils/utils.c b/utils/utils.c index a2fab4e12..bfe089fac 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -1,5 +1,5 @@ /** - * $Id: utils.c,v 1.8 2003/04/11 21:06:51 bursa Exp $ + * $Id: utils.c,v 1.9 2003/05/22 13:21:45 bursa Exp $ */ #include @@ -135,11 +135,48 @@ char *squash_tolat1(xmlChar *s) char *url_join(const char* new, const char* base) { - char* ret; - int i; + char* ret, *nn; + int i,j,k; LOG(("new = %s, base = %s", new, base)); + /* deal with spaces and quotation marks in URLs etc. + also removes spaces from end of links. + There's definitely a better way to do this */ + nn = xcalloc(strlen(new) * 3 + 40, sizeof(char)); + j=0; + for(i=0;i