mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 12:36:51 +03:00
Convert fetchers to nsurl.
svn path=/trunk/netsurf/; revision=12910
This commit is contained in:
parent
828d8e0de8
commit
6cfd37e60f
@ -317,8 +317,7 @@ struct fetch * fetch_start(nsurl *url, nsurl *referer,
|
|||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
/* Got a scheme fetcher, try and set up the fetch */
|
/* Got a scheme fetcher, try and set up the fetch */
|
||||||
fetch->fetcher_handle =
|
fetch->fetcher_handle = fetch->ops->setup_fetch(fetch, url,
|
||||||
fetch->ops->setup_fetch(fetch, nsurl_access(url),
|
|
||||||
only_2xx, post_urlenc,
|
only_2xx, post_urlenc,
|
||||||
post_multipart, headers);
|
post_multipart, headers);
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ struct fetch_multipart_data *fetch_multipart_data_clone(
|
|||||||
/* API for fetchers themselves */
|
/* API for fetchers themselves */
|
||||||
|
|
||||||
typedef bool (*fetcher_initialise)(lwc_string *);
|
typedef bool (*fetcher_initialise)(lwc_string *);
|
||||||
typedef void* (*fetcher_setup_fetch)(struct fetch *, const char *,
|
typedef void* (*fetcher_setup_fetch)(struct fetch *, nsurl *,
|
||||||
bool, const char *,
|
bool, const char *,
|
||||||
const struct fetch_multipart_data *,
|
const struct fetch_multipart_data *,
|
||||||
const char **);
|
const char **);
|
||||||
|
@ -68,7 +68,7 @@ struct fetch_about_context {
|
|||||||
bool aborted; /**< Flag indicating fetch has been aborted */
|
bool aborted; /**< Flag indicating fetch has been aborted */
|
||||||
bool locked; /**< Flag indicating entry is already entered */
|
bool locked; /**< Flag indicating entry is already entered */
|
||||||
|
|
||||||
char *url; /**< The full url the fetch refers to */
|
nsurl *url; /**< The full url the fetch refers to */
|
||||||
|
|
||||||
fetch_about_handler handler;
|
fetch_about_handler handler;
|
||||||
};
|
};
|
||||||
@ -396,6 +396,7 @@ struct about_handlers {
|
|||||||
bool hidden; /* Flag indicating if entry should be show in listing */
|
bool hidden; /* Flag indicating if entry should be show in listing */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* TODO: lwc_string identifiers, since they're compared to an lwc_string */
|
||||||
struct about_handlers about_handler_list[] = {
|
struct about_handlers about_handler_list[] = {
|
||||||
{ "credits", fetch_about_credits_handler, false },
|
{ "credits", fetch_about_credits_handler, false },
|
||||||
{ "licence", fetch_about_licence_handler, false },
|
{ "licence", fetch_about_licence_handler, false },
|
||||||
@ -501,7 +502,7 @@ static void fetch_about_finalise(lwc_string *scheme)
|
|||||||
/** callback to set up a about fetch context. */
|
/** callback to set up a about fetch context. */
|
||||||
static void *
|
static void *
|
||||||
fetch_about_setup(struct fetch *fetchh,
|
fetch_about_setup(struct fetch *fetchh,
|
||||||
const char *url,
|
nsurl *url,
|
||||||
bool only_2xx,
|
bool only_2xx,
|
||||||
const char *post_urlenc,
|
const char *post_urlenc,
|
||||||
const struct fetch_multipart_data *post_multipart,
|
const struct fetch_multipart_data *post_multipart,
|
||||||
@ -509,25 +510,27 @@ fetch_about_setup(struct fetch *fetchh,
|
|||||||
{
|
{
|
||||||
struct fetch_about_context *ctx;
|
struct fetch_about_context *ctx;
|
||||||
unsigned int handler_loop;
|
unsigned int handler_loop;
|
||||||
struct url_components urlcomp;
|
lwc_string *path;
|
||||||
|
|
||||||
ctx = calloc(1, sizeof(*ctx));
|
ctx = calloc(1, sizeof(*ctx));
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
url_get_components(url, &urlcomp);
|
path = nsurl_get_component(url, NSURL_PATH);
|
||||||
|
|
||||||
for (handler_loop = 0;
|
for (handler_loop = 0;
|
||||||
handler_loop < about_handler_list_len;
|
handler_loop < about_handler_list_len;
|
||||||
handler_loop++) {
|
handler_loop++) {
|
||||||
ctx->handler = about_handler_list[handler_loop].handler;
|
ctx->handler = about_handler_list[handler_loop].handler;
|
||||||
if (strcmp(about_handler_list[handler_loop].name, urlcomp.path) == 0)
|
if (strcmp(about_handler_list[handler_loop].name,
|
||||||
|
lwc_string_data(path)) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
url_destroy_components(&urlcomp);
|
lwc_string_unref(path);
|
||||||
|
|
||||||
ctx->fetchh = fetchh;
|
ctx->fetchh = fetchh;
|
||||||
|
ctx->url = nsurl_ref(url);
|
||||||
|
|
||||||
RING_INSERT(ring, ctx);
|
RING_INSERT(ring, ctx);
|
||||||
|
|
||||||
@ -538,7 +541,7 @@ fetch_about_setup(struct fetch *fetchh,
|
|||||||
static void fetch_about_free(void *ctx)
|
static void fetch_about_free(void *ctx)
|
||||||
{
|
{
|
||||||
struct fetch_about_context *c = ctx;
|
struct fetch_about_context *c = ctx;
|
||||||
free(c->url);
|
nsurl_unref(c->url);
|
||||||
RING_REMOVE(ring, c);
|
RING_REMOVE(ring, c);
|
||||||
free(ctx);
|
free(ctx);
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ static char fetch_proxy_userpwd[100]; /**< Proxy authentication details. */
|
|||||||
|
|
||||||
static bool fetch_curl_initialise(lwc_string *scheme);
|
static bool fetch_curl_initialise(lwc_string *scheme);
|
||||||
static void fetch_curl_finalise(lwc_string *scheme);
|
static void fetch_curl_finalise(lwc_string *scheme);
|
||||||
static void * fetch_curl_setup(struct fetch *parent_fetch, const char *url,
|
static void * fetch_curl_setup(struct fetch *parent_fetch, nsurl *url,
|
||||||
bool only_2xx, const char *post_urlenc,
|
bool only_2xx, const char *post_urlenc,
|
||||||
const struct fetch_multipart_data *post_multipart,
|
const struct fetch_multipart_data *post_multipart,
|
||||||
const char **headers);
|
const char **headers);
|
||||||
@ -324,7 +324,7 @@ void fetch_curl_finalise(lwc_string *scheme)
|
|||||||
* callbacks will contain this.
|
* callbacks will contain this.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void * fetch_curl_setup(struct fetch *parent_fetch, const char *url,
|
void * fetch_curl_setup(struct fetch *parent_fetch, nsurl *url,
|
||||||
bool only_2xx, const char *post_urlenc,
|
bool only_2xx, const char *post_urlenc,
|
||||||
const struct fetch_multipart_data *post_multipart,
|
const struct fetch_multipart_data *post_multipart,
|
||||||
const char **headers)
|
const char **headers)
|
||||||
@ -341,7 +341,7 @@ void * fetch_curl_setup(struct fetch *parent_fetch, const char *url,
|
|||||||
|
|
||||||
fetch->fetch_handle = parent_fetch;
|
fetch->fetch_handle = parent_fetch;
|
||||||
|
|
||||||
res = url_host(url, &host);
|
res = url_host(nsurl_access(url), &host);
|
||||||
if (res != URL_FUNC_OK) {
|
if (res != URL_FUNC_OK) {
|
||||||
/* we only fail memory exhaustion */
|
/* we only fail memory exhaustion */
|
||||||
if (res == URL_FUNC_NOMEM)
|
if (res == URL_FUNC_NOMEM)
|
||||||
@ -360,7 +360,7 @@ void * fetch_curl_setup(struct fetch *parent_fetch, const char *url,
|
|||||||
fetch->abort = false;
|
fetch->abort = false;
|
||||||
fetch->stopped = false;
|
fetch->stopped = false;
|
||||||
fetch->only_2xx = only_2xx;
|
fetch->only_2xx = only_2xx;
|
||||||
fetch->url = strdup(url);
|
fetch->url = strdup(nsurl_access(url));
|
||||||
fetch->headers = 0;
|
fetch->headers = 0;
|
||||||
fetch->host = host;
|
fetch->host = host;
|
||||||
fetch->location = 0;
|
fetch->location = 0;
|
||||||
|
@ -75,7 +75,7 @@ static void fetch_data_finalise(lwc_string *scheme)
|
|||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *fetch_data_setup(struct fetch *parent_fetch, const char *url,
|
static void *fetch_data_setup(struct fetch *parent_fetch, nsurl *url,
|
||||||
bool only_2xx, const char *post_urlenc,
|
bool only_2xx, const char *post_urlenc,
|
||||||
const struct fetch_multipart_data *post_multipart,
|
const struct fetch_multipart_data *post_multipart,
|
||||||
const char **headers)
|
const char **headers)
|
||||||
@ -86,7 +86,8 @@ static void *fetch_data_setup(struct fetch *parent_fetch, const char *url,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ctx->parent_fetch = parent_fetch;
|
ctx->parent_fetch = parent_fetch;
|
||||||
ctx->url = strdup(url);
|
/* TODO: keep as nsurl to avoid copy */
|
||||||
|
ctx->url = strdup(nsurl_access(url));
|
||||||
|
|
||||||
if (ctx->url == NULL) {
|
if (ctx->url == NULL) {
|
||||||
free(ctx);
|
free(ctx);
|
||||||
|
@ -61,7 +61,7 @@ struct fetch_file_context {
|
|||||||
bool aborted; /**< Flag indicating fetch has been aborted */
|
bool aborted; /**< Flag indicating fetch has been aborted */
|
||||||
bool locked; /**< Flag indicating entry is already entered */
|
bool locked; /**< Flag indicating entry is already entered */
|
||||||
|
|
||||||
char *url; /**< The full url the fetch refers to */
|
nsurl *url; /**< The full url the fetch refers to */
|
||||||
char *path; /**< The actual path to be used with open() */
|
char *path; /**< The actual path to be used with open() */
|
||||||
|
|
||||||
time_t file_etag; /**< Request etag for file (previous st.m_time) */
|
time_t file_etag; /**< Request etag for file (previous st.m_time) */
|
||||||
@ -113,7 +113,7 @@ static void fetch_file_finalise(lwc_string *scheme)
|
|||||||
/** callback to set up a file fetch context. */
|
/** callback to set up a file fetch context. */
|
||||||
static void *
|
static void *
|
||||||
fetch_file_setup(struct fetch *fetchh,
|
fetch_file_setup(struct fetch *fetchh,
|
||||||
const char *url,
|
nsurl *url,
|
||||||
bool only_2xx,
|
bool only_2xx,
|
||||||
const char *post_urlenc,
|
const char *post_urlenc,
|
||||||
const struct fetch_multipart_data *post_multipart,
|
const struct fetch_multipart_data *post_multipart,
|
||||||
@ -126,18 +126,13 @@ fetch_file_setup(struct fetch *fetchh,
|
|||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ctx->path = url_to_path(url);
|
ctx->path = url_to_path(nsurl_access(url));
|
||||||
if (ctx->path == NULL) {
|
if (ctx->path == NULL) {
|
||||||
free(ctx);
|
free(ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->url = strdup(url);
|
ctx->url = nsurl_ref(url);
|
||||||
if (ctx->url == NULL) {
|
|
||||||
free(ctx->path);
|
|
||||||
free(ctx);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Scan request headers looking for If-None-Match */
|
/* Scan request headers looking for If-None-Match */
|
||||||
for (i = 0; headers[i] != NULL; i++) {
|
for (i = 0; headers[i] != NULL; i++) {
|
||||||
@ -167,7 +162,7 @@ fetch_file_setup(struct fetch *fetchh,
|
|||||||
static void fetch_file_free(void *ctx)
|
static void fetch_file_free(void *ctx)
|
||||||
{
|
{
|
||||||
struct fetch_file_context *c = ctx;
|
struct fetch_file_context *c = ctx;
|
||||||
free(c->url);
|
nsurl_unref(c->url);
|
||||||
free(c->path);
|
free(c->path);
|
||||||
RING_REMOVE(ring, c);
|
RING_REMOVE(ring, c);
|
||||||
free(ctx);
|
free(ctx);
|
||||||
@ -226,7 +221,7 @@ static void fetch_file_process_error(struct fetch_file_context *ctx, int code)
|
|||||||
snprintf(buffer, sizeof buffer, "<html><head><title>%s</title></head>"
|
snprintf(buffer, sizeof buffer, "<html><head><title>%s</title></head>"
|
||||||
"<body><h1>%s</h1>"
|
"<body><h1>%s</h1>"
|
||||||
"<p>Error %d while fetching file %s</p></body></html>",
|
"<p>Error %d while fetching file %s</p></body></html>",
|
||||||
title, title, code, ctx->url);
|
title, title, code, nsurl_access(ctx->url));
|
||||||
|
|
||||||
if (fetch_file_send_callback(FETCH_DATA, ctx, buffer, strlen(buffer),
|
if (fetch_file_send_callback(FETCH_DATA, ctx, buffer, strlen(buffer),
|
||||||
FETCH_ERROR_NO_ERROR))
|
FETCH_ERROR_NO_ERROR))
|
||||||
@ -445,9 +440,9 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx,
|
|||||||
goto fetch_file_process_dir_aborted;
|
goto fetch_file_process_dir_aborted;
|
||||||
|
|
||||||
/* Print parent directory link */
|
/* Print parent directory link */
|
||||||
res = url_parent(ctx->url, &up);
|
res = url_parent(nsurl_access(ctx->url), &up);
|
||||||
if (res == URL_FUNC_OK) {
|
if (res == URL_FUNC_OK) {
|
||||||
res = url_compare(ctx->url, up, false, &compare);
|
res = url_compare(nsurl_access(ctx->url), up, false, &compare);
|
||||||
if ((res == URL_FUNC_OK) && compare == false) {
|
if ((res == URL_FUNC_OK) && compare == false) {
|
||||||
dirlist_generate_parent_link(up, buffer, sizeof buffer);
|
dirlist_generate_parent_link(up, buffer, sizeof buffer);
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ static void fetch_resource_finalise(lwc_string *scheme)
|
|||||||
/** callback to set up a resource fetch context. */
|
/** callback to set up a resource fetch context. */
|
||||||
static void *
|
static void *
|
||||||
fetch_resource_setup(struct fetch *fetchh,
|
fetch_resource_setup(struct fetch *fetchh,
|
||||||
const char *url,
|
nsurl *url,
|
||||||
bool only_2xx,
|
bool only_2xx,
|
||||||
const char *post_urlenc,
|
const char *post_urlenc,
|
||||||
const struct fetch_multipart_data *post_multipart,
|
const struct fetch_multipart_data *post_multipart,
|
||||||
@ -177,7 +177,7 @@ fetch_resource_setup(struct fetch *fetchh,
|
|||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
url_get_components(url, &urlcomp);
|
url_get_components(nsurl_access(url), &urlcomp);
|
||||||
|
|
||||||
ctx->redirect_url = gui_get_resource_url(urlcomp.path);
|
ctx->redirect_url = gui_get_resource_url(urlcomp.path);
|
||||||
if (ctx->redirect_url == NULL) {
|
if (ctx->redirect_url == NULL) {
|
||||||
@ -186,7 +186,7 @@ fetch_resource_setup(struct fetch *fetchh,
|
|||||||
ctx->handler = fetch_resource_redirect_handler;
|
ctx->handler = fetch_resource_redirect_handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->url = strdup(url);
|
ctx->url = strdup(nsurl_access(url));
|
||||||
|
|
||||||
url_destroy_components(&urlcomp);
|
url_destroy_components(&urlcomp);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user