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 --- desktop/browser.c | 74 ++++++++++++++++++++++++++++++++++--------------------- desktop/browser.h | 4 ++- 2 files changed, 49 insertions(+), 29 deletions(-) (limited to 'desktop') diff --git a/desktop/browser.c b/desktop/browser.c index 67a4670dc..16fc03126 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -38,6 +38,9 @@ static int redraw_box_list(struct browser_window* bw, struct box* current, static void browser_window_redraw_boxes(struct browser_window* bw, struct box_position* start, struct box_position* end); static void browser_window_follow_link(struct browser_window* bw, unsigned long click_x, unsigned long click_y, int click_type); +static void browser_window_open_location_post(struct browser_window* bw, + const char* url0, char *post_urlenc, + struct form_successful_control *post_multipart); static void browser_window_callback(content_msg msg, struct content *c, void *p1, void *p2, const char *error); static void download_window_callback(content_msg msg, struct content *c, @@ -117,7 +120,7 @@ void browser_window_back(struct browser_window* bw) if (bw->history->earlier != NULL) { bw->history = bw->history->earlier; - browser_window_open_location_historical(bw, bw->history->url); + browser_window_open_location_historical(bw, bw->history->url, 0, 0); } } } @@ -129,7 +132,7 @@ void browser_window_forward(struct browser_window* bw) if (bw->history->later != NULL) { bw->history = bw->history->later; - browser_window_open_location_historical(bw, bw->history->url); + browser_window_open_location_historical(bw, bw->history->url, 0, 0); } } } @@ -241,7 +244,9 @@ void browser_window_destroy(struct browser_window* bw) LOG(("end")); } -void browser_window_open_location_historical(struct browser_window* bw, const char* url) +void browser_window_open_location_historical(struct browser_window* bw, + const char* url, char *post_urlenc, + struct form_successful_control *post_multipart) { LOG(("bw = %p, url = %s", bw, url)); @@ -251,7 +256,8 @@ void browser_window_open_location_historical(struct browser_window* bw, const ch browser_window_start_throbber(bw); bw->time0 = clock(); bw->loading_content = fetchcache(url, 0, browser_window_callback, bw, 0, - gui_window_get_width(bw->window), 0, false); + gui_window_get_width(bw->window), 0, false, + post_urlenc, post_multipart); if (bw->loading_content == 0) { browser_window_set_status(bw, "Unable to fetch document"); return; @@ -265,12 +271,19 @@ void browser_window_open_location_historical(struct browser_window* bw, const ch } void browser_window_open_location(struct browser_window* bw, const char* url0) +{ + browser_window_open_location_post(bw, url0, 0, 0); +} + +void browser_window_open_location_post(struct browser_window* bw, + const char* url0, char *post_urlenc, + struct form_successful_control *post_multipart) { char *url; LOG(("bw = %p, url0 = %s", bw, url0)); assert(bw != 0 && url0 != 0); url = url_join(url0, bw->url); - browser_window_open_location_historical(bw, url); + browser_window_open_location_historical(bw, url, post_urlenc, post_multipart); /* TODO: move this to somewhere below CONTENT_MSG_READY below */ if (bw->history == NULL) bw->history = history_create(NULL, url); @@ -1569,36 +1582,41 @@ void browser_window_redraw_boxes(struct browser_window* bw, struct box_position* } +/** + * Collect controls and submit a form. + */ + void browser_form_submit(struct browser_window *bw, struct form *form, struct form_control *submit_button) { + char *data, *url; struct form_successful_control *success; success = form_successful_controls(form, submit_button); - if (form->method == method_GET) { - /*GET request*/ - /*GET basically munges the entire form data - into one URL. */ - - char *data = form_url_encode(success); - char *url = xcalloc(1, strlen(form->action) + strlen(data) + 2); - sprintf(url, "%s?%s", form->action, data); - free(data); - browser_window_open_location(bw, url); - xfree(url); - - } else { - /*POST request*/ - assert(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.*/ - } + switch (form->method) { + case method_GET: + data = form_url_encode(success); + url = xcalloc(1, strlen(form->action) + strlen(data) + 2); + sprintf(url, "%s?%s", form->action, data); + free(data); + browser_window_open_location(bw, url); + free(url); + break; + + case method_POST_URLENC: + data = form_url_encode(success); + browser_window_open_location_post(bw, form->action, data, 0); + free(data); + break; + + case method_POST_MULTIPART: + browser_window_open_location_post(bw, form->action, 0, success); + break; + + default: + assert(0); + } form_free_successful(success); } diff --git a/desktop/browser.h b/desktop/browser.h index 38dc3628b..2afbd83bb 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -99,7 +99,9 @@ struct box_selection struct browser_window* create_browser_window(int flags, int width, int height); void browser_window_destroy(struct browser_window* bw); void browser_window_open_location(struct browser_window* bw, const char* url); -void browser_window_open_location_historical(struct browser_window* bw, const char* url); +void browser_window_open_location_historical(struct browser_window* bw, + const char* url, char *post_urlenc, + struct form_successful_control *post_multipart); int browser_window_action(struct browser_window* bw, struct browser_action* act); void browser_window_set_status(struct browser_window* bw, const char* text); -- cgit v1.2.3