[project @ 2003-10-25 14:13:49 by bursa]
URL encoded POST support. svn path=/import/netsurf/; revision=375
This commit is contained in:
parent
f1375fe19d
commit
28f974f00f
|
@ -29,6 +29,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include "netsurf/desktop/options.h"
|
#include "netsurf/desktop/options.h"
|
||||||
#include "netsurf/desktop/401login.h"
|
#include "netsurf/desktop/401login.h"
|
||||||
|
#include "netsurf/render/form.h"
|
||||||
#include "netsurf/utils/log.h"
|
#include "netsurf/utils/log.h"
|
||||||
#include "netsurf/utils/messages.h"
|
#include "netsurf/utils/messages.h"
|
||||||
#include "netsurf/utils/utils.h"
|
#include "netsurf/utils/utils.h"
|
||||||
|
@ -52,6 +53,7 @@ struct fetch {
|
||||||
char *location; /**< Response Location header, or 0. */
|
char *location; /**< Response Location header, or 0. */
|
||||||
unsigned long content_length; /**< Response Content-Length, or 0. */
|
unsigned long content_length; /**< Response Content-Length, or 0. */
|
||||||
char *realm; /**< HTTP Auth Realm */
|
char *realm; /**< HTTP Auth Realm */
|
||||||
|
char *post_urlenc; /**< Url encoded POST string, or 0. */
|
||||||
struct fetch *queue; /**< Next fetch for this host. */
|
struct fetch *queue; /**< Next fetch for this host. */
|
||||||
struct fetch *prev; /**< Previous active fetch in ::fetch_list. */
|
struct fetch *prev; /**< Previous active fetch in ::fetch_list. */
|
||||||
struct fetch *next; /**< Next active fetch in ::fetch_list. */
|
struct fetch *next; /**< Next active fetch in ::fetch_list. */
|
||||||
|
@ -138,8 +140,9 @@ void fetch_quit(void)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct fetch * fetch_start(char *url, char *referer,
|
struct fetch * fetch_start(char *url, char *referer,
|
||||||
void (*callback)(fetch_msg msg, void *p, char *data, unsigned long size),
|
void (*callback)(fetch_msg msg, void *p, char *data, unsigned long size),
|
||||||
void *p, bool only_2xx)
|
void *p, bool only_2xx, char *post_urlenc,
|
||||||
|
struct form_successful_control *post_multipart)
|
||||||
{
|
{
|
||||||
struct fetch *fetch = xcalloc(1, sizeof(*fetch)), *host_fetch;
|
struct fetch *fetch = xcalloc(1, sizeof(*fetch)), *host_fetch;
|
||||||
CURLcode code;
|
CURLcode code;
|
||||||
|
@ -170,6 +173,9 @@ struct fetch * fetch_start(char *url, char *referer,
|
||||||
if (uri->server != 0)
|
if (uri->server != 0)
|
||||||
fetch->host = xstrdup(uri->server);
|
fetch->host = xstrdup(uri->server);
|
||||||
fetch->content_length = 0;
|
fetch->content_length = 0;
|
||||||
|
fetch->post_urlenc = 0;
|
||||||
|
if (post_urlenc)
|
||||||
|
fetch->post_urlenc = xstrdup(post_urlenc);
|
||||||
fetch->queue = 0;
|
fetch->queue = 0;
|
||||||
fetch->prev = 0;
|
fetch->prev = 0;
|
||||||
fetch->next = 0;
|
fetch->next = 0;
|
||||||
|
@ -257,10 +263,19 @@ struct fetch * fetch_start(char *url, char *referer,
|
||||||
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
|
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
|
||||||
assert(code == CURLE_OK);
|
assert(code == CURLE_OK);
|
||||||
|
|
||||||
|
#ifdef riscos
|
||||||
if (LOGIN.string != NULL) {
|
if (LOGIN.string != NULL) {
|
||||||
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_USERPWD, LOGIN.string);
|
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_USERPWD, LOGIN.string);
|
||||||
assert(code == CURLE_OK);
|
assert(code == CURLE_OK);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* POST */
|
||||||
|
if (fetch->post_urlenc) {
|
||||||
|
code = curl_easy_setopt(fetch->curl_handle,
|
||||||
|
CURLOPT_POSTFIELDS, fetch->post_urlenc);
|
||||||
|
assert(code == CURLE_OK);
|
||||||
|
}
|
||||||
|
|
||||||
/* add to the global curl multi handle */
|
/* add to the global curl multi handle */
|
||||||
codem = curl_multi_add_handle(curl_multi, fetch->curl_handle);
|
codem = curl_multi_add_handle(curl_multi, fetch->curl_handle);
|
||||||
|
@ -327,11 +342,18 @@ void fetch_abort(struct fetch *f)
|
||||||
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_WRITEHEADER, fetch);
|
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_WRITEHEADER, fetch);
|
||||||
assert(code == CURLE_OK);
|
assert(code == CURLE_OK);
|
||||||
/* TODO: remove referer header if fetch->referer == 0 */
|
/* TODO: remove referer header if fetch->referer == 0 */
|
||||||
if (fetch->referer != 0) {
|
/*if (fetch->referer != 0)*/ {
|
||||||
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_REFERER, fetch->referer);
|
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_REFERER, fetch->referer);
|
||||||
assert(code == CURLE_OK);
|
assert(code == CURLE_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* POST */
|
||||||
|
if (fetch->post_urlenc) {
|
||||||
|
code = curl_easy_setopt(fetch->curl_handle,
|
||||||
|
CURLOPT_POSTFIELDS, fetch->post_urlenc);
|
||||||
|
assert(code == CURLE_OK);
|
||||||
|
}
|
||||||
|
|
||||||
/* add to the global curl multi handle */
|
/* add to the global curl multi handle */
|
||||||
codem = curl_multi_add_handle(curl_multi, fetch->curl_handle);
|
codem = curl_multi_add_handle(curl_multi, fetch->curl_handle);
|
||||||
assert(codem == CURLM_OK || codem == CURLM_CALL_MULTI_PERFORM);
|
assert(codem == CURLM_OK || codem == CURLM_CALL_MULTI_PERFORM);
|
||||||
|
@ -346,6 +368,7 @@ void fetch_abort(struct fetch *f)
|
||||||
free(f->referer);
|
free(f->referer);
|
||||||
free(f->location);
|
free(f->location);
|
||||||
free(f->realm);
|
free(f->realm);
|
||||||
|
free(f->post_urlenc);
|
||||||
xfree(f);
|
xfree(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,6 +525,7 @@ bool fetch_process_headers(struct fetch *f)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef riscos
|
||||||
/* handle HTTP 401 (Authentication errors) */
|
/* handle HTTP 401 (Authentication errors) */
|
||||||
if (http_code == 401) {
|
if (http_code == 401) {
|
||||||
/* this shouldn't be here... */
|
/* this shouldn't be here... */
|
||||||
|
@ -510,6 +534,7 @@ bool fetch_process_headers(struct fetch *f)
|
||||||
f->callback(FETCH_ERROR, f->p, "",0);
|
f->callback(FETCH_ERROR, f->p, "",0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* handle HTTP errors (non 2xx response codes) */
|
/* handle HTTP errors (non 2xx response codes) */
|
||||||
if (f->only_2xx && strncmp(f->url, "http", 4) == 0 &&
|
if (f->only_2xx && strncmp(f->url, "http", 4) == 0 &&
|
||||||
|
|
|
@ -18,11 +18,13 @@ typedef enum {FETCH_TYPE, FETCH_DATA, FETCH_FINISHED, FETCH_ERROR, FETCH_REDIREC
|
||||||
|
|
||||||
struct content;
|
struct content;
|
||||||
struct fetch;
|
struct fetch;
|
||||||
|
struct form_successful_control;
|
||||||
|
|
||||||
void fetch_init(void);
|
void fetch_init(void);
|
||||||
struct fetch * fetch_start(char *url, char *referer,
|
struct fetch * fetch_start(char *url, char *referer,
|
||||||
void (*callback)(fetch_msg msg, void *p, char *data, unsigned long size),
|
void (*callback)(fetch_msg msg, void *p, char *data, unsigned long size),
|
||||||
void *p, bool only_2xx);
|
void *p, bool only_2xx, char *post_urlenc,
|
||||||
|
struct form_successful_control *post_multipart);
|
||||||
void fetch_abort(struct fetch *f);
|
void fetch_abort(struct fetch *f);
|
||||||
void fetch_poll(void);
|
void fetch_poll(void);
|
||||||
void fetch_quit(void);
|
void fetch_quit(void);
|
||||||
|
|
|
@ -42,7 +42,8 @@ struct content * fetchcache(const char *url0, char *referer,
|
||||||
void (*callback)(content_msg msg, struct content *c, void *p1,
|
void (*callback)(content_msg msg, struct content *c, void *p1,
|
||||||
void *p2, const char *error),
|
void *p2, const char *error),
|
||||||
void *p1, void *p2, unsigned long width, unsigned long height,
|
void *p1, void *p2, unsigned long width, unsigned long height,
|
||||||
bool only_2xx)
|
bool only_2xx, char *post_urlenc,
|
||||||
|
struct form_successful_control *post_multipart)
|
||||||
{
|
{
|
||||||
struct content *c;
|
struct content *c;
|
||||||
char *url = xstrdup(url0);
|
char *url = xstrdup(url0);
|
||||||
|
@ -67,7 +68,8 @@ struct content * fetchcache(const char *url0, char *referer,
|
||||||
c->fetch_size = 0;
|
c->fetch_size = 0;
|
||||||
c->width = width;
|
c->width = width;
|
||||||
c->height = height;
|
c->height = height;
|
||||||
c->fetch = fetch_start(url, referer, fetchcache_callback, c, only_2xx);
|
c->fetch = fetch_start(url, referer, fetchcache_callback, c, only_2xx,
|
||||||
|
post_urlenc, post_multipart);
|
||||||
free(url);
|
free(url);
|
||||||
if (c->fetch == 0) {
|
if (c->fetch == 0) {
|
||||||
LOG(("warning: fetch_start failed"));
|
LOG(("warning: fetch_start failed"));
|
||||||
|
|
|
@ -18,10 +18,13 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "netsurf/content/content.h"
|
#include "netsurf/content/content.h"
|
||||||
|
|
||||||
|
struct form_successful_control;
|
||||||
|
|
||||||
struct content * fetchcache(const char *url, char *referer,
|
struct content * fetchcache(const char *url, char *referer,
|
||||||
void (*callback)(content_msg msg, struct content *c, void *p1,
|
void (*callback)(content_msg msg, struct content *c, void *p1,
|
||||||
void *p2, const char *error),
|
void *p2, const char *error),
|
||||||
void *p1, void *p2, unsigned long width, unsigned long height,
|
void *p1, void *p2, unsigned long width, unsigned long height,
|
||||||
bool only_2xx);
|
bool only_2xx, char *post_urlenc,
|
||||||
|
struct form_successful_control *post_multipart);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -173,7 +173,7 @@ void css_revive(struct content *c, unsigned int width, unsigned int height)
|
||||||
c->data.css.import_content[i] = fetchcache(
|
c->data.css.import_content[i] = fetchcache(
|
||||||
c->data.css.import_url[i], c->url,
|
c->data.css.import_url[i], c->url,
|
||||||
css_atimport_callback, c, i,
|
css_atimport_callback, c, i,
|
||||||
c->width, c->height, true);
|
c->width, c->height, true, 0, 0);
|
||||||
if (c->data.css.import_content[i] == 0)
|
if (c->data.css.import_content[i] == 0)
|
||||||
continue;
|
continue;
|
||||||
if (c->data.css.import_content[i]->status != CONTENT_STATUS_DONE)
|
if (c->data.css.import_content[i]->status != CONTENT_STATUS_DONE)
|
||||||
|
@ -333,7 +333,7 @@ void css_atimport(struct content *c, struct css_node *node)
|
||||||
c->data.css.import_url[i] = url_join(url, c->url);
|
c->data.css.import_url[i] = url_join(url, c->url);
|
||||||
c->data.css.import_content[i] = fetchcache(
|
c->data.css.import_content[i] = fetchcache(
|
||||||
c->data.css.import_url[i], c->url, css_atimport_callback,
|
c->data.css.import_url[i], c->url, css_atimport_callback,
|
||||||
c, i, c->width, c->height, true);
|
c, i, c->width, c->height, true, 0, 0);
|
||||||
if (c->data.css.import_content[i] &&
|
if (c->data.css.import_content[i] &&
|
||||||
c->data.css.import_content[i]->status != CONTENT_STATUS_DONE)
|
c->data.css.import_content[i]->status != CONTENT_STATUS_DONE)
|
||||||
c->active++;
|
c->active++;
|
||||||
|
@ -381,7 +381,7 @@ void css_atimport_callback(content_msg msg, struct content *css,
|
||||||
c->data.css.import_url[i] = xstrdup(error);
|
c->data.css.import_url[i] = xstrdup(error);
|
||||||
c->data.css.import_content[i] = fetchcache(
|
c->data.css.import_content[i] = fetchcache(
|
||||||
c->data.css.import_url[i], c->url, css_atimport_callback,
|
c->data.css.import_url[i], c->url, css_atimport_callback,
|
||||||
c, i, css->width, css->height, true);
|
c, i, css->width, css->height, true, 0, 0);
|
||||||
if (c->data.css.import_content[i] &&
|
if (c->data.css.import_content[i] &&
|
||||||
c->data.css.import_content[i]->status != CONTENT_STATUS_DONE)
|
c->data.css.import_content[i]->status != CONTENT_STATUS_DONE)
|
||||||
c->active++;
|
c->active++;
|
||||||
|
@ -568,7 +568,7 @@ void css_parse_property_list(struct css_style * style, char * str)
|
||||||
void *parser;
|
void *parser;
|
||||||
YY_BUFFER_STATE buffer;
|
YY_BUFFER_STATE buffer;
|
||||||
int token;
|
int token;
|
||||||
struct parse_params param = {1, 0, 0};
|
struct parse_params param = {1, 0, 0, false};
|
||||||
|
|
||||||
css_lex_init(&lexer);
|
css_lex_init(&lexer);
|
||||||
parser = css_parser_Alloc(malloc);
|
parser = css_parser_Alloc(malloc);
|
||||||
|
|
|
@ -45,7 +45,7 @@ int main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
url[strlen(url) - 1] = 0;
|
url[strlen(url) - 1] = 0;
|
||||||
destroyed = 0;
|
destroyed = 0;
|
||||||
c = fetchcache(url, 0, callback, 0, 0, 100, 1000, false);
|
c = fetchcache(url, 0, callback, 0, 0, 100, 1000, false, 0, 0);
|
||||||
if (c) {
|
if (c) {
|
||||||
done = c->status == CONTENT_STATUS_DONE;
|
done = c->status == CONTENT_STATUS_DONE;
|
||||||
while (!done)
|
while (!done)
|
||||||
|
|
|
@ -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_redraw_boxes(struct browser_window* bw, struct box_position* start, struct box_position* end);
|
||||||
static void browser_window_follow_link(struct browser_window* bw,
|
static void browser_window_follow_link(struct browser_window* bw,
|
||||||
unsigned long click_x, unsigned long click_y, int click_type);
|
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,
|
static void browser_window_callback(content_msg msg, struct content *c,
|
||||||
void *p1, void *p2, const char *error);
|
void *p1, void *p2, const char *error);
|
||||||
static void download_window_callback(content_msg msg, struct content *c,
|
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)
|
if (bw->history->earlier != NULL)
|
||||||
{
|
{
|
||||||
bw->history = bw->history->earlier;
|
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)
|
if (bw->history->later != NULL)
|
||||||
{
|
{
|
||||||
bw->history = bw->history->later;
|
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"));
|
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));
|
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);
|
browser_window_start_throbber(bw);
|
||||||
bw->time0 = clock();
|
bw->time0 = clock();
|
||||||
bw->loading_content = fetchcache(url, 0, browser_window_callback, bw, 0,
|
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) {
|
if (bw->loading_content == 0) {
|
||||||
browser_window_set_status(bw, "Unable to fetch document");
|
browser_window_set_status(bw, "Unable to fetch document");
|
||||||
return;
|
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)
|
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;
|
char *url;
|
||||||
LOG(("bw = %p, url0 = %s", bw, url0));
|
LOG(("bw = %p, url0 = %s", bw, url0));
|
||||||
assert(bw != 0 && url0 != 0);
|
assert(bw != 0 && url0 != 0);
|
||||||
url = url_join(url0, bw->url);
|
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 */
|
/* TODO: move this to somewhere below CONTENT_MSG_READY below */
|
||||||
if (bw->history == NULL)
|
if (bw->history == NULL)
|
||||||
bw->history = history_create(NULL, url);
|
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,
|
void browser_form_submit(struct browser_window *bw, struct form *form,
|
||||||
struct form_control *submit_button)
|
struct form_control *submit_button)
|
||||||
{
|
{
|
||||||
|
char *data, *url;
|
||||||
struct form_successful_control *success;
|
struct form_successful_control *success;
|
||||||
|
|
||||||
success = form_successful_controls(form, submit_button);
|
success = form_successful_controls(form, submit_button);
|
||||||
|
|
||||||
if (form->method == method_GET) {
|
switch (form->method) {
|
||||||
/*GET request*/
|
case method_GET:
|
||||||
/*GET basically munges the entire form data
|
data = form_url_encode(success);
|
||||||
into one URL. */
|
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;
|
||||||
|
|
||||||
char *data = form_url_encode(success);
|
case method_POST_URLENC:
|
||||||
char *url = xcalloc(1, strlen(form->action) + strlen(data) + 2);
|
data = form_url_encode(success);
|
||||||
sprintf(url, "%s?%s", form->action, data);
|
browser_window_open_location_post(bw, form->action, data, 0);
|
||||||
free(data);
|
free(data);
|
||||||
browser_window_open_location(bw, url);
|
break;
|
||||||
xfree(url);
|
|
||||||
|
|
||||||
} else {
|
case method_POST_MULTIPART:
|
||||||
/*POST request*/
|
browser_window_open_location_post(bw, form->action, 0, success);
|
||||||
assert(form->method == method_POST);
|
break;
|
||||||
|
|
||||||
LOG(("POST request - not implemented yet"));
|
default:
|
||||||
|
assert(0);
|
||||||
/*POST is a standard HTTP method.
|
}
|
||||||
Basically, it creates a new request
|
|
||||||
and sends the form data as the request
|
|
||||||
body.*/
|
|
||||||
}
|
|
||||||
|
|
||||||
form_free_successful(success);
|
form_free_successful(success);
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,9 @@ struct box_selection
|
||||||
struct browser_window* create_browser_window(int flags, int width, int height);
|
struct browser_window* create_browser_window(int flags, int width, int height);
|
||||||
void browser_window_destroy(struct browser_window* bw);
|
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(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);
|
int browser_window_action(struct browser_window* bw, struct browser_action* act);
|
||||||
void browser_window_set_status(struct browser_window* bw, const char* text);
|
void browser_window_set_status(struct browser_window* bw, const char* text);
|
||||||
|
|
||||||
|
|
36
render/box.c
36
render/box.c
|
@ -14,7 +14,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "libxml/HTMLparser.h"
|
#include "libxml/HTMLparser.h"
|
||||||
#include "netsurf/content/fetchcache.h"
|
#include "netsurf/content/content.h"
|
||||||
#include "netsurf/css/css.h"
|
#include "netsurf/css/css.h"
|
||||||
#include "netsurf/render/box.h"
|
#include "netsurf/render/box.h"
|
||||||
#include "netsurf/render/font.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 result box_form(xmlNode *n, struct status *status,
|
||||||
struct css_style *style)
|
struct css_style *style)
|
||||||
{
|
{
|
||||||
char* s;
|
char *s, *s2;
|
||||||
struct box *box;
|
struct box *box;
|
||||||
struct form *form;
|
struct form *form;
|
||||||
|
|
||||||
box = box_create(style, status->href, status->title);
|
box = box_create(style, status->href, status->title);
|
||||||
|
|
||||||
status->current_form = form = xcalloc(1, sizeof(*form));
|
s = (char *) xmlGetProp(n, (const xmlChar *) "action");
|
||||||
|
if (!s) {
|
||||||
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "action"))) {
|
/* the action attribute is required */
|
||||||
form->action = s;
|
return (struct result) {box, 1};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status->current_form = form = xcalloc(1, sizeof(*form));
|
||||||
|
form->action = s;
|
||||||
|
|
||||||
form->method = method_GET;
|
form->method = method_GET;
|
||||||
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "method"))) {
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "method"))) {
|
||||||
if (stricmp(s, "post") == 0)
|
if (strcasecmp(s, "post") == 0) {
|
||||||
form->method = method_POST;
|
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);
|
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->next = option;
|
||||||
current_select->data.select.last_item = 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++)
|
for (c = text; *c; c++)
|
||||||
if (*c == ' ')
|
if (*c == ' ')
|
||||||
*c = 160;
|
*c = 160;
|
||||||
|
|
||||||
option->selected = option->initial_selected = false;
|
option->selected = option->initial_selected = false;
|
||||||
option->text = text;
|
option->text = text;
|
||||||
option->value = 0;
|
|
||||||
|
|
||||||
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "selected"))) {
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "selected"))) {
|
||||||
xmlFree(s);
|
xmlFree(s);
|
||||||
|
@ -930,10 +944,6 @@ void add_option(xmlNode* n, struct form_control* current_select, char *text)
|
||||||
current_select->data.select.current = option;
|
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,
|
struct result box_input(xmlNode *n, struct status *status,
|
||||||
|
|
|
@ -74,7 +74,7 @@ struct form_successful_control *form_successful_controls(struct form *form,
|
||||||
if (control->type == GADGET_SELECT) {
|
if (control->type == GADGET_SELECT) {
|
||||||
for (option = control->data.select.items; option;
|
for (option = control->data.select.items; option;
|
||||||
option = option->next) {
|
option = option->next) {
|
||||||
if (option->selected && option->value) {
|
if (option->selected) {
|
||||||
success_new = xcalloc(1, sizeof(*success_new));
|
success_new = xcalloc(1, sizeof(*success_new));
|
||||||
success_new->name = xstrdup(control->name);
|
success_new->name = xstrdup(control->name);
|
||||||
success_new->value = xstrdup(option->value);
|
success_new->value = xstrdup(option->value);
|
||||||
|
|
|
@ -14,15 +14,19 @@
|
||||||
#define _NETSURF_RENDER_FORM_H_
|
#define _NETSURF_RENDER_FORM_H_
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "netsurf/render/box.h"
|
|
||||||
|
|
||||||
|
struct box;
|
||||||
struct form_control;
|
struct form_control;
|
||||||
struct form_option;
|
struct form_option;
|
||||||
|
|
||||||
/** HTML form. */
|
/** HTML form. */
|
||||||
struct form {
|
struct form {
|
||||||
char *action; /* url */
|
char *action; /**< Url to submit to. */
|
||||||
enum {method_GET, method_POST} method;
|
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 *controls; /**< Linked list of controls. */
|
||||||
struct form_control *last_control; /**< Last control in list. */
|
struct form_control *last_control; /**< Last control in list. */
|
||||||
};
|
};
|
||||||
|
|
|
@ -185,7 +185,7 @@ void html_convert_css_callback(content_msg msg, struct content *css,
|
||||||
c->active--;
|
c->active--;
|
||||||
c->data.html.stylesheet_content[i] = fetchcache(
|
c->data.html.stylesheet_content[i] = fetchcache(
|
||||||
error, c->url, html_convert_css_callback,
|
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 &&
|
if (c->data.html.stylesheet_content[i] != 0 &&
|
||||||
c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE)
|
c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE)
|
||||||
c->active++;
|
c->active++;
|
||||||
|
@ -238,7 +238,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
|
||||||
#endif
|
#endif
|
||||||
c->url,
|
c->url,
|
||||||
html_convert_css_callback,
|
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);
|
assert(c->data.html.stylesheet_content[0] != 0);
|
||||||
if (c->data.html.stylesheet_content[0]->status != CONTENT_STATUS_DONE)
|
if (c->data.html.stylesheet_content[0]->status != CONTENT_STATUS_DONE)
|
||||||
c->active++;
|
c->active++;
|
||||||
|
@ -289,7 +289,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
|
||||||
(i + 1) * sizeof(*c->data.html.stylesheet_content));
|
(i + 1) * sizeof(*c->data.html.stylesheet_content));
|
||||||
c->data.html.stylesheet_content[i] = fetchcache(url, c->url,
|
c->data.html.stylesheet_content[i] = fetchcache(url, c->url,
|
||||||
html_convert_css_callback, c, i,
|
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] &&
|
if (c->data.html.stylesheet_content[i] &&
|
||||||
c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE)
|
c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE)
|
||||||
c->active++;
|
c->active++;
|
||||||
|
@ -376,8 +376,8 @@ void html_fetch_object(struct content *c, char *url, struct box *box)
|
||||||
/* start fetch */
|
/* start fetch */
|
||||||
c->data.html.object[i].content = fetchcache(url, c->url,
|
c->data.html.object[i].content = fetchcache(url, c->url,
|
||||||
html_object_callback,
|
html_object_callback,
|
||||||
c, i,
|
c, i, c->width, c->height,
|
||||||
c->width, c->height, true); /* we don't know the object's
|
true, 0, 0); /* we don't know the object's
|
||||||
dimensions yet; use
|
dimensions yet; use
|
||||||
parent's as an estimate */
|
parent's as an estimate */
|
||||||
if (c->data.html.object[i].content) {
|
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].url = xstrdup(error);
|
||||||
c->data.html.object[i].content = fetchcache(
|
c->data.html.object[i].content = fetchcache(
|
||||||
error, c->url, html_object_callback,
|
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) {
|
if (c->data.html.object[i].content) {
|
||||||
c->active++;
|
c->active++;
|
||||||
if (c->data.html.object[i].content->status == CONTENT_STATUS_DONE)
|
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].content = fetchcache(
|
||||||
c->data.html.object[i].url, c->url,
|
c->data.html.object[i].url, c->url,
|
||||||
html_object_callback,
|
html_object_callback,
|
||||||
c, i, 0, 0, true);
|
c, i, 0, 0, true, 0, 0);
|
||||||
if (c->data.html.object[i].content &&
|
if (c->data.html.object[i].content &&
|
||||||
c->data.html.object[i].content->status != CONTENT_STATUS_DONE)
|
c->data.html.object[i].content->status != CONTENT_STATUS_DONE)
|
||||||
c->active++;
|
c->active++;
|
||||||
|
|
|
@ -136,5 +136,5 @@ void do_thing() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (gw != NULL)
|
if (gw != NULL)
|
||||||
browser_window_open_location_historical(gw->data.browser.bw, url);
|
browser_window_open_location_historical(gw->data.browser.bw, url, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -732,7 +732,8 @@ void ro_gui_toolbar_click(gui_window* g, wimp_pointer* pointer)
|
||||||
}
|
}
|
||||||
else if (pointer->i == ro_theme_icon(current_theme, THEME_TOOLBAR, "TOOLBAR_RELOAD"))
|
else if (pointer->i == ro_theme_icon(current_theme, THEME_TOOLBAR, "TOOLBAR_RELOAD"))
|
||||||
{
|
{
|
||||||
browser_window_open_location_historical(g->data.browser.bw, g->data.browser.bw->url);
|
browser_window_open_location_historical(g->data.browser.bw,
|
||||||
|
g->data.browser.bw->url, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ void ro_gui_mouse_action(gui_window *g) {
|
||||||
|
|
||||||
case mouseaction_RELOAD:
|
case mouseaction_RELOAD:
|
||||||
browser_window_open_location_historical(g->data.browser.bw,
|
browser_window_open_location_historical(g->data.browser.bw,
|
||||||
g->data.browser.bw->url);
|
g->data.browser.bw->url, 0, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue