Convert fetchers to nsurl.

svn path=/trunk/netsurf/; revision=12910
This commit is contained in:
Michael Drake 2011-09-29 15:31:54 +00:00
parent 828d8e0de8
commit 6cfd37e60f
7 changed files with 30 additions and 32 deletions

View File

@ -317,8 +317,7 @@ struct fetch * fetch_start(nsurl *url, nsurl *referer,
goto failed;
/* Got a scheme fetcher, try and set up the fetch */
fetch->fetcher_handle =
fetch->ops->setup_fetch(fetch, nsurl_access(url),
fetch->fetcher_handle = fetch->ops->setup_fetch(fetch, url,
only_2xx, post_urlenc,
post_multipart, headers);

View File

@ -110,7 +110,7 @@ struct fetch_multipart_data *fetch_multipart_data_clone(
/* API for fetchers themselves */
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 *,
const struct fetch_multipart_data *,
const char **);

View File

@ -68,7 +68,7 @@ struct fetch_about_context {
bool aborted; /**< Flag indicating fetch has been aborted */
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;
};
@ -396,6 +396,7 @@ struct about_handlers {
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[] = {
{ "credits", fetch_about_credits_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. */
static void *
fetch_about_setup(struct fetch *fetchh,
const char *url,
nsurl *url,
bool only_2xx,
const char *post_urlenc,
const struct fetch_multipart_data *post_multipart,
@ -509,25 +510,27 @@ fetch_about_setup(struct fetch *fetchh,
{
struct fetch_about_context *ctx;
unsigned int handler_loop;
struct url_components urlcomp;
lwc_string *path;
ctx = calloc(1, sizeof(*ctx));
if (ctx == NULL)
return NULL;
url_get_components(url, &urlcomp);
path = nsurl_get_component(url, NSURL_PATH);
for (handler_loop = 0;
handler_loop < about_handler_list_len;
handler_loop++) {
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;
}
url_destroy_components(&urlcomp);
lwc_string_unref(path);
ctx->fetchh = fetchh;
ctx->url = nsurl_ref(url);
RING_INSERT(ring, ctx);
@ -538,7 +541,7 @@ fetch_about_setup(struct fetch *fetchh,
static void fetch_about_free(void *ctx)
{
struct fetch_about_context *c = ctx;
free(c->url);
nsurl_unref(c->url);
RING_REMOVE(ring, c);
free(ctx);
}

View File

@ -109,7 +109,7 @@ static char fetch_proxy_userpwd[100]; /**< Proxy authentication details. */
static bool fetch_curl_initialise(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,
const struct fetch_multipart_data *post_multipart,
const char **headers);
@ -324,7 +324,7 @@ void fetch_curl_finalise(lwc_string *scheme)
* 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,
const struct fetch_multipart_data *post_multipart,
const char **headers)
@ -341,7 +341,7 @@ void * fetch_curl_setup(struct fetch *parent_fetch, const char *url,
fetch->fetch_handle = parent_fetch;
res = url_host(url, &host);
res = url_host(nsurl_access(url), &host);
if (res != URL_FUNC_OK) {
/* we only fail memory exhaustion */
if (res == URL_FUNC_NOMEM)
@ -360,7 +360,7 @@ void * fetch_curl_setup(struct fetch *parent_fetch, const char *url,
fetch->abort = false;
fetch->stopped = false;
fetch->only_2xx = only_2xx;
fetch->url = strdup(url);
fetch->url = strdup(nsurl_access(url));
fetch->headers = 0;
fetch->host = host;
fetch->location = 0;

View File

@ -75,7 +75,7 @@ static void fetch_data_finalise(lwc_string *scheme)
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,
const struct fetch_multipart_data *post_multipart,
const char **headers)
@ -86,7 +86,8 @@ static void *fetch_data_setup(struct fetch *parent_fetch, const char *url,
return NULL;
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) {
free(ctx);

View File

@ -61,7 +61,7 @@ struct fetch_file_context {
bool aborted; /**< Flag indicating fetch has been aborted */
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() */
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. */
static void *
fetch_file_setup(struct fetch *fetchh,
const char *url,
nsurl *url,
bool only_2xx,
const char *post_urlenc,
const struct fetch_multipart_data *post_multipart,
@ -126,18 +126,13 @@ fetch_file_setup(struct fetch *fetchh,
if (ctx == NULL)
return NULL;
ctx->path = url_to_path(url);
ctx->path = url_to_path(nsurl_access(url));
if (ctx->path == NULL) {
free(ctx);
return NULL;
}
ctx->url = strdup(url);
if (ctx->url == NULL) {
free(ctx->path);
free(ctx);
return NULL;
}
ctx->url = nsurl_ref(url);
/* Scan request headers looking for If-None-Match */
for (i = 0; headers[i] != NULL; i++) {
@ -167,7 +162,7 @@ fetch_file_setup(struct fetch *fetchh,
static void fetch_file_free(void *ctx)
{
struct fetch_file_context *c = ctx;
free(c->url);
nsurl_unref(c->url);
free(c->path);
RING_REMOVE(ring, c);
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>"
"<body><h1>%s</h1>"
"<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),
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;
/* Print parent directory link */
res = url_parent(ctx->url, &up);
res = url_parent(nsurl_access(ctx->url), &up);
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) {
dirlist_generate_parent_link(up, buffer, sizeof buffer);

View File

@ -164,7 +164,7 @@ static void fetch_resource_finalise(lwc_string *scheme)
/** callback to set up a resource fetch context. */
static void *
fetch_resource_setup(struct fetch *fetchh,
const char *url,
nsurl *url,
bool only_2xx,
const char *post_urlenc,
const struct fetch_multipart_data *post_multipart,
@ -177,7 +177,7 @@ fetch_resource_setup(struct fetch *fetchh,
if (ctx == NULL)
return NULL;
url_get_components(url, &urlcomp);
url_get_components(nsurl_access(url), &urlcomp);
ctx->redirect_url = gui_get_resource_url(urlcomp.path);
if (ctx->redirect_url == NULL) {
@ -186,7 +186,7 @@ fetch_resource_setup(struct fetch *fetchh,
ctx->handler = fetch_resource_redirect_handler;
}
ctx->url = strdup(url);
ctx->url = strdup(nsurl_access(url));
url_destroy_components(&urlcomp);