From c94271edf591226f9a5de88ac59719c4b5290a1b Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Mon, 26 Sep 2011 21:07:19 +0000 Subject: Fetchers register with an lwc_string, rather than a string. svn path=/trunk/netsurf/; revision=12891 --- content/fetch.c | 34 ++++++++++++++++------------ content/fetch.h | 11 +++++---- content/fetchers/about.c | 18 +++++++++++---- content/fetchers/curl.c | 55 +++++++++++++++++++++++++++++---------------- content/fetchers/data.c | 21 ++++++++++++----- content/fetchers/file.c | 17 ++++++++++---- content/fetchers/resource.c | 18 +++++++++++---- 7 files changed, 119 insertions(+), 55 deletions(-) (limited to 'content') diff --git a/content/fetch.c b/content/fetch.c index 3ef441e7b..820e3cd56 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -59,7 +59,7 @@ bool fetch_active; /**< Fetches in progress, please call fetch_poll(). */ /** Information about a fetcher for a given scheme. */ typedef struct scheme_fetcher_s { - char *scheme_name; /**< The scheme. */ + lwc_string *scheme_name; /**< The scheme. */ fetcher_setup_fetch setup_fetch; /**< Set up a fetch. */ fetcher_start_fetch start_fetch; /**< Start a fetch. */ fetcher_abort_fetch abort_fetch; /**< Abort a fetch. */ @@ -129,7 +129,7 @@ void fetch_quit(void) while (fetchers != NULL) { if (fetchers->refcount != 1) { LOG(("Fetcher for scheme %s still active?!", - fetchers->scheme_name)); + lwc_string_data(fetchers->scheme_name))); /* We shouldn't do this, but... */ fetchers->refcount = 1; } @@ -138,7 +138,7 @@ void fetch_quit(void) } -bool fetch_add_fetcher(const char *scheme, +bool fetch_add_fetcher(lwc_string *scheme, fetcher_initialise initialiser, fetcher_setup_fetch setup_fetch, fetcher_start_fetch start_fetch, @@ -155,12 +155,7 @@ bool fetch_add_fetcher(const char *scheme, finaliser(scheme); return false; } - new_fetcher->scheme_name = strdup(scheme); - if (new_fetcher->scheme_name == NULL) { - free(new_fetcher); - finaliser(scheme); - return false; - } + new_fetcher->scheme_name = scheme; new_fetcher->refcount = 0; new_fetcher->setup_fetch = setup_fetch; new_fetcher->start_fetch = start_fetch; @@ -179,7 +174,7 @@ void fetch_unref_fetcher(scheme_fetcher *fetcher) { if (--fetcher->refcount == 0) { fetcher->finaliser(fetcher->scheme_name); - free(fetcher->scheme_name); + lwc_string_unref(fetcher->scheme_name); if (fetcher == fetchers) { fetchers = fetcher->next_fetcher; if (fetchers) @@ -310,7 +305,8 @@ struct fetch * fetch_start(const char *url, const char *referer, /* Pick the scheme ops */ while (fetcher) { - if (strcmp(fetcher->scheme_name, scheme) == 0) { + if (strcmp(lwc_string_data(fetcher->scheme_name), + scheme) == 0) { fetch->ops = fetcher; break; } @@ -508,7 +504,8 @@ void fetch_poll(void) if (!fetch_active) return; /* No point polling, there's no fetch active. */ while (fetcher != NULL) { - /* LOG(("Polling fetcher for %s", fetcher->scheme_name)); */ + /* LOG(("Polling fetcher for %s", + lwc_string_data(fetcher->scheme_name))); */ next_fetcher = fetcher->next_fetcher; fetcher->poll_fetcher(fetcher->scheme_name); fetcher = next_fetcher; @@ -528,18 +525,27 @@ bool fetch_can_fetch(const char *url) const char *semi; size_t len; scheme_fetcher *fetcher = fetchers; + lwc_string *scheme; + bool match; if ((semi = strchr(url, ':')) == NULL) return false; len = semi - url; + if (lwc_intern_string(url, len, &scheme) != lwc_error_ok) + return false; + while (fetcher != NULL) { - if (strlen(fetcher->scheme_name) == len && - strncmp(fetcher->scheme_name, url, len) == 0) + lwc_string_isequal(fetcher->scheme_name, scheme, &match); + if (match == true) { + lwc_string_unref(scheme); return true; + } fetcher = fetcher->next_fetcher; } + lwc_string_unref(scheme); + return false; } diff --git a/content/fetch.h b/content/fetch.h index 8bf59a17c..fc395ae67 100644 --- a/content/fetch.h +++ b/content/fetch.h @@ -24,6 +24,9 @@ #define _NETSURF_DESKTOP_FETCH_H_ #include + +#include + #include "utils/config.h" typedef enum { @@ -106,7 +109,7 @@ struct fetch_multipart_data *fetch_multipart_data_clone( /* API for fetchers themselves */ -typedef bool (*fetcher_initialise)(const char *); +typedef bool (*fetcher_initialise)(lwc_string *); typedef void* (*fetcher_setup_fetch)(struct fetch *, const char *, bool, const char *, const struct fetch_multipart_data *, @@ -114,10 +117,10 @@ typedef void* (*fetcher_setup_fetch)(struct fetch *, const char *, typedef bool (*fetcher_start_fetch)(void *); typedef void (*fetcher_abort_fetch)(void *); typedef void (*fetcher_free_fetch)(void *); -typedef void (*fetcher_poll_fetcher)(const char *); -typedef void (*fetcher_finalise)(const char *); +typedef void (*fetcher_poll_fetcher)(lwc_string *); +typedef void (*fetcher_finalise)(lwc_string *); -bool fetch_add_fetcher(const char *scheme, +bool fetch_add_fetcher(lwc_string *scheme, fetcher_initialise initialiser, fetcher_setup_fetch setup_fetch, fetcher_start_fetch start_fetch, diff --git a/content/fetchers/about.c b/content/fetchers/about.c index 59461ee9f..2a5475d97 100644 --- a/content/fetchers/about.c +++ b/content/fetchers/about.c @@ -39,6 +39,8 @@ #include #include +#include + #include "utils/config.h" #include "content/dirlist.h" #include "content/fetch.h" @@ -486,13 +488,13 @@ fetch_about_config_handler_aborted: /** callback to initialise the about fetcher. */ -static bool fetch_about_initialise(const char *scheme) +static bool fetch_about_initialise(lwc_string *scheme) { return true; } /** callback to initialise the about fetcher. */ -static void fetch_about_finalise(const char *scheme) +static void fetch_about_finalise(lwc_string *scheme) { } @@ -561,7 +563,7 @@ static void fetch_about_abort(void *ctx) /** callback to poll for additional about fetch contents */ -static void fetch_about_poll(const char *scheme) +static void fetch_about_poll(lwc_string *scheme) { struct fetch_about_context *c, *next; @@ -603,7 +605,15 @@ static void fetch_about_poll(const char *scheme) void fetch_about_register(void) { - fetch_add_fetcher("about", + lwc_string *scheme; + + if (lwc_intern_string("about", SLEN("about"), + &scheme) != lwc_error_ok) { + die("Failed to initialise the fetch module " + "(couldn't intern \"about\")."); + } + + fetch_add_fetcher(scheme, fetch_about_initialise, fetch_about_setup, fetch_about_start, diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c index 6fedda539..eb74fd7b6 100644 --- a/content/fetchers/curl.c +++ b/content/fetchers/curl.c @@ -37,6 +37,8 @@ #include #include +#include + #include "utils/config.h" #include #include "content/fetch.h" @@ -105,8 +107,8 @@ static bool curl_with_openssl; static char fetch_error_buffer[CURL_ERROR_SIZE]; /**< Error buffer for cURL. */ static char fetch_proxy_userpwd[100]; /**< Proxy authentication details. */ -static bool fetch_curl_initialise(const char *scheme); -static void fetch_curl_finalise(const char *scheme); +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, bool only_2xx, const char *post_urlenc, const struct fetch_multipart_data *post_multipart, @@ -122,7 +124,7 @@ static CURLcode fetch_curl_sslctxfun(CURL *curl_handle, void *_sslctx, static void fetch_curl_abort(void *vf); static void fetch_curl_stop(struct curl_fetch_info *f); static void fetch_curl_free(void *f); -static void fetch_curl_poll(const char *scheme_ignored); +static void fetch_curl_poll(lwc_string *scheme_ignored); static void fetch_curl_done(CURL *curl_handle, CURLcode result); static int fetch_curl_progress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); @@ -155,6 +157,7 @@ void fetch_curl_register(void) CURLcode code; curl_version_info_data *data; int i; + lwc_string *scheme; LOG(("curl_version %s", curl_version())); @@ -224,19 +227,33 @@ void fetch_curl_register(void) data = curl_version_info(CURLVERSION_NOW); for (i = 0; data->protocols[i]; i++) { - /* Ignore non-http(s) protocols */ - if (strcmp(data->protocols[i], "http") != 0 && - strcmp(data->protocols[i], "https") != 0) + if (strcmp(data->protocols[i], "http") == 0) { + if (lwc_intern_string("http", SLEN("http"), + &scheme) != lwc_error_ok) { + die("Failed to initialise the fetch module " + "(couldn't intern \"http\")."); + } + + } else if (strcmp(data->protocols[i], "https") == 0) { + if (lwc_intern_string("https", SLEN("https"), + &scheme) != lwc_error_ok) { + die("Failed to initialise the fetch module " + "(couldn't intern \"https\")."); + } + + } else { + /* Ignore non-http(s) protocols */ continue; + } - if (!fetch_add_fetcher(data->protocols[i], - fetch_curl_initialise, - fetch_curl_setup, - fetch_curl_start, - fetch_curl_abort, - fetch_curl_free, - fetch_curl_poll, - fetch_curl_finalise)) { + if (!fetch_add_fetcher(scheme, + fetch_curl_initialise, + fetch_curl_setup, + fetch_curl_start, + fetch_curl_abort, + fetch_curl_free, + fetch_curl_poll, + fetch_curl_finalise)) { LOG(("Unable to register cURL fetcher for %s", data->protocols[i])); } @@ -253,9 +270,9 @@ curl_easy_setopt_failed: * Initialise a cURL fetcher. */ -bool fetch_curl_initialise(const char *scheme) +bool fetch_curl_initialise(lwc_string *scheme) { - LOG(("Initialise cURL fetcher for %s", scheme)); + LOG(("Initialise cURL fetcher for %s", lwc_string_data(scheme))); curl_fetchers_registered++; return true; /* Always succeeds */ } @@ -265,10 +282,10 @@ bool fetch_curl_initialise(const char *scheme) * Finalise a cURL fetcher */ -void fetch_curl_finalise(const char *scheme) +void fetch_curl_finalise(lwc_string *scheme) { curl_fetchers_registered--; - LOG(("Finalise cURL fetcher %s", scheme)); + LOG(("Finalise cURL fetcher %s", lwc_string_data(scheme))); if (curl_fetchers_registered == 0) { CURLMcode codem; /* All the fetchers have been finalised. */ @@ -716,7 +733,7 @@ void fetch_curl_free(void *vf) * Must be called regularly to make progress on fetches. */ -void fetch_curl_poll(const char *scheme_ignored) +void fetch_curl_poll(lwc_string *scheme_ignored) { int running, queue; CURLMcode codem; diff --git a/content/fetchers/data.c b/content/fetchers/data.c index 5abe2d6dd..d9d7f768a 100644 --- a/content/fetchers/data.c +++ b/content/fetchers/data.c @@ -27,6 +27,8 @@ #include /* for URL unescaping functions */ +#include + #include "utils/config.h" #include "content/fetch.h" #include "content/fetchers/data.h" @@ -58,18 +60,18 @@ static struct fetch_data_context *ring = NULL; static CURL *curl; -static bool fetch_data_initialise(const char *scheme) +static bool fetch_data_initialise(lwc_string *scheme) { - LOG(("fetch_data_initialise called for %s", scheme)); + LOG(("fetch_data_initialise called for %s", lwc_string_data(scheme))); if ( (curl = curl_easy_init()) == NULL) return false; else return true; } -static void fetch_data_finalise(const char *scheme) +static void fetch_data_finalise(lwc_string *scheme) { - LOG(("fetch_data_finalise called for %s", scheme)); + LOG(("fetch_data_finalise called for %s", lwc_string_data(scheme))); curl_easy_cleanup(curl); } @@ -226,7 +228,7 @@ static bool fetch_data_process(struct fetch_data_context *c) return true; } -static void fetch_data_poll(const char *scheme) +static void fetch_data_poll(lwc_string *scheme) { struct fetch_data_context *c, *next; @@ -306,7 +308,14 @@ static void fetch_data_poll(const char *scheme) void fetch_data_register(void) { - fetch_add_fetcher("data", + lwc_string *scheme; + + if (lwc_intern_string("data", SLEN("data"), &scheme) != lwc_error_ok) { + die("Failed to initialise the fetch module " + "(couldn't intern \"data\")."); + } + + fetch_add_fetcher(scheme, fetch_data_initialise, fetch_data_setup, fetch_data_start, diff --git a/content/fetchers/file.c b/content/fetchers/file.c index 164fa5fd9..cc41e8c54 100644 --- a/content/fetchers/file.c +++ b/content/fetchers/file.c @@ -34,6 +34,8 @@ #include #include +#include + #include "utils/config.h" #include "content/dirlist.h" #include "content/fetch.h" @@ -98,13 +100,13 @@ static bool fetch_file_send_header(struct fetch_file_context *ctx, } /** callback to initialise the file fetcher. */ -static bool fetch_file_initialise(const char *scheme) +static bool fetch_file_initialise(lwc_string *scheme) { return true; } /** callback to initialise the file fetcher. */ -static void fetch_file_finalise(const char *scheme) +static void fetch_file_finalise(lwc_string *scheme) { } @@ -589,7 +591,7 @@ static void fetch_file_process(struct fetch_file_context *ctx) } /** callback to poll for additional file fetch contents */ -static void fetch_file_poll(const char *scheme) +static void fetch_file_poll(lwc_string *scheme) { struct fetch_file_context *c, *next; @@ -631,7 +633,14 @@ static void fetch_file_poll(const char *scheme) void fetch_file_register(void) { - fetch_add_fetcher("file", + lwc_string *scheme; + + if (lwc_intern_string("file", SLEN("file"), &scheme) != lwc_error_ok) { + die("Failed to initialise the fetch module " + "(couldn't intern \"file\")."); + } + + fetch_add_fetcher(scheme, fetch_file_initialise, fetch_file_setup, fetch_file_start, diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c index b0aac9067..27194ef06 100644 --- a/content/fetchers/resource.c +++ b/content/fetchers/resource.c @@ -34,6 +34,8 @@ #include #include +#include + #include "utils/config.h" #include "content/dirlist.h" #include "content/fetch.h" @@ -149,13 +151,13 @@ fetch_resource_notfound_handler_aborted: /** callback to initialise the resource fetcher. */ -static bool fetch_resource_initialise(const char *scheme) +static bool fetch_resource_initialise(lwc_string *scheme) { return true; } /** callback to initialise the resource fetcher. */ -static void fetch_resource_finalise(const char *scheme) +static void fetch_resource_finalise(lwc_string *scheme) { } @@ -225,7 +227,7 @@ static void fetch_resource_abort(void *ctx) /** callback to poll for additional resource fetch contents */ -static void fetch_resource_poll(const char *scheme) +static void fetch_resource_poll(lwc_string *scheme) { struct fetch_resource_context *c, *next; @@ -267,7 +269,15 @@ static void fetch_resource_poll(const char *scheme) void fetch_resource_register(void) { - fetch_add_fetcher("resource", + lwc_string *scheme; + + if (lwc_intern_string("resource", SLEN("resource"), + &scheme) != lwc_error_ok) { + die("Failed to initialise the fetch module " + "(couldn't intern \"resource\")."); + } + + fetch_add_fetcher(scheme, fetch_resource_initialise, fetch_resource_setup, fetch_resource_start, -- cgit v1.2.3