diff options
Diffstat (limited to 'content/fetchers')
-rw-r--r-- | content/fetchers/Makefile | 2 | ||||
-rw-r--r-- | content/fetchers/about.c | 43 | ||||
-rw-r--r-- | content/fetchers/about.h | 2 | ||||
-rw-r--r-- | content/fetchers/curl.c | 169 | ||||
-rw-r--r-- | content/fetchers/data.c | 34 | ||||
-rw-r--r-- | content/fetchers/data.h | 2 | ||||
-rw-r--r-- | content/fetchers/file.c | 231 | ||||
-rw-r--r-- | content/fetchers/file.h | 2 | ||||
-rw-r--r-- | content/fetchers/resource.c | 49 | ||||
-rw-r--r-- | content/fetchers/resource.h | 2 |
10 files changed, 287 insertions, 249 deletions
diff --git a/content/fetchers/Makefile b/content/fetchers/Makefile index 06e38e4c8..855154232 100644 --- a/content/fetchers/Makefile +++ b/content/fetchers/Makefile @@ -5,4 +5,4 @@ S_FETCHERS := curl.c data.c file.c about.c resource.c S_FETCHERS := $(addprefix content/fetchers/,$(S_FETCHERS)) # The following files depend on the testament -content/fetchers/about.c: testament utils/testament.h +content/fetchers/about.c: testament $(OBJROOT)/testament.h diff --git a/content/fetchers/about.c b/content/fetchers/about.c index cac8b2b01..8c4d29a91 100644 --- a/content/fetchers/about.c +++ b/content/fetchers/about.c @@ -41,19 +41,20 @@ #include <libwapcaplet/libwapcaplet.h> +#include "testament.h" + #include "utils/config.h" -#include "content/dirlist.h" #include "content/fetch.h" +#include "content/fetchers.h" #include "content/fetchers/about.h" #include "content/urldb.h" #include "desktop/netsurf.h" #include "utils/nsoption.h" +#include "utils/corestrings.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/url.h" #include "utils/utils.h" #include "utils/ring.h" -#include "utils/testament.h" #include "image/image_cache.h" struct fetch_about_context; @@ -489,8 +490,8 @@ static bool fetch_about_testament_handler(struct fetch_about_context *ctx) slen = snprintf(buffer, sizeof buffer, - "Built by %s (%s) from %s at revision %s\n\n", - GECOS, USERNAME, WT_BRANCHPATH, WT_REVID); + "Built by %s (%s) from %s at revision %s on %s\n\n", + GECOS, USERNAME, WT_BRANCHPATH, WT_REVID, WT_COMPILEDATE); msg.data.header_or_data.len = slen; if (fetch_about_send_callback(&msg, ctx)) @@ -837,23 +838,19 @@ static void fetch_about_poll(lwc_string *scheme) } while ( (c = next) != ring && ring != NULL); } -void fetch_about_register(void) +nserror fetch_about_register(void) { - 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_can_fetch, - fetch_about_setup, - fetch_about_start, - fetch_about_abort, - fetch_about_free, - fetch_about_poll, - fetch_about_finalise); + lwc_string *scheme = lwc_string_ref(corestring_lwc_about); + const struct fetcher_operation_table fetcher_ops = { + .initialise = fetch_about_initialise, + .acceptable = fetch_about_can_fetch, + .setup = fetch_about_setup, + .start = fetch_about_start, + .abort = fetch_about_abort, + .free = fetch_about_free, + .poll = fetch_about_poll, + .finalise = fetch_about_finalise + }; + + return fetcher_add(scheme, &fetcher_ops); } diff --git a/content/fetchers/about.h b/content/fetchers/about.h index f22be6a5d..9544971a6 100644 --- a/content/fetchers/about.h +++ b/content/fetchers/about.h @@ -23,6 +23,6 @@ #ifndef NETSURF_CONTENT_FETCHERS_FETCH_ABOUT_H #define NETSURF_CONTENT_FETCHERS_FETCH_ABOUT_H -void fetch_about_register(void); +nserror fetch_about_register(void); #endif diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c index 1dfc44631..51b0f9974 100644 --- a/content/fetchers/curl.c +++ b/content/fetchers/curl.c @@ -19,7 +19,7 @@ */ /** \file - * Fetching of data from a URL (implementation). + * Fetching of data from an URL (implementation). * * This implementation uses libcurl's 'multi' interface. * @@ -36,32 +36,27 @@ #include <strings.h> #include <time.h> #include <sys/stat.h> +#include <openssl/ssl.h> #include <libwapcaplet/libwapcaplet.h> #include "utils/config.h" -#include <openssl/ssl.h> -#include "content/fetch.h" -#include "content/fetchers/curl.h" -#include "content/urldb.h" #include "desktop/netsurf.h" +#include "desktop/gui_factory.h" +#include "utils/corestrings.h" #include "utils/nsoption.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/schedule.h" #include "utils/utils.h" #include "utils/ring.h" #include "utils/useragent.h" +#include "utils/file.h" -/* BIG FAT WARNING: This is here because curl doesn't give you an FD to - * poll on, until it has processed a bit of the handle. So we need schedules - * in order to make this work. - */ -#include <desktop/browser.h> +#include "content/fetch.h" +#include "content/fetchers.h" +#include "content/fetchers/curl.h" +#include "content/urldb.h" -/* uncomment this to use scheduler based calling -#define FETCHER_CURLL_SCHEDULED 1 -*/ /** SSL certificate info */ struct cert_info { @@ -163,6 +158,16 @@ void fetch_curl_register(void) curl_version_info_data *data; int i; lwc_string *scheme; + const struct fetcher_operation_table fetcher_ops = { + .initialise = fetch_curl_initialise, + .acceptable = fetch_curl_can_fetch, + .setup = fetch_curl_setup, + .start = fetch_curl_start, + .abort = fetch_curl_abort, + .free = fetch_curl_free, + .poll = fetch_curl_poll, + .finalise = fetch_curl_finalise + }; LOG(("curl_version %s", curl_version())); @@ -176,6 +181,25 @@ void fetch_curl_register(void) die("Failed to initialise the fetch module " "(curl_multi_init failed)."); +#if LIBCURL_VERSION_NUM >= 0x071e00 + /* We've been built against 7.30.0 or later: configure caching */ + { + CURLMcode mcode; + int maxconnects = nsoption_int(max_fetchers) + + nsoption_int(max_cached_fetch_handles); + +#undef SETOPT +#define SETOPT(option, value) \ + mcode = curl_multi_setopt(fetch_curl_multi, option, value); \ + if (mcode != CURLM_OK) \ + goto curl_multi_setopt_failed; + + SETOPT(CURLMOPT_MAXCONNECTS, maxconnects); + SETOPT(CURLMOPT_MAX_TOTAL_CONNECTIONS, maxconnects); + SETOPT(CURLMOPT_MAX_HOST_CONNECTIONS, nsoption_int(max_fetchers_per_host)); + } +#endif + /* Create a curl easy handle with the options that are common to all fetches. */ fetch_blank_curl = curl_easy_init(); @@ -235,37 +259,17 @@ void fetch_curl_register(void) for (i = 0; data->protocols[i]; i++) { 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\")."); - } + scheme = lwc_string_ref(corestring_lwc_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\")."); - } + scheme = lwc_string_ref(corestring_lwc_https); } else { /* Ignore non-http(s) protocols */ continue; } - if (!fetch_add_fetcher(scheme, - fetch_curl_initialise, - fetch_curl_can_fetch, - fetch_curl_setup, - fetch_curl_start, - fetch_curl_abort, - fetch_curl_free, -#ifdef FETCHER_CURLL_SCHEDULED - NULL, -#else - fetch_curl_poll, -#endif - fetch_curl_finalise)) { + if (fetcher_add(scheme, &fetcher_ops) != NSERROR_OK) { LOG(("Unable to register cURL fetcher for %s", data->protocols[i])); } @@ -275,6 +279,12 @@ void fetch_curl_register(void) curl_easy_setopt_failed: die("Failed to initialise the fetch module " "(curl_easy_setopt failed)."); + +#if LIBCURL_VERSION_NUM >= 0x071e00 +curl_multi_setopt_failed: + die("Failed to initialise the fetch module " + "(curl_multi_setopt failed)."); +#endif } @@ -490,9 +500,7 @@ bool fetch_curl_initiate_fetch(struct curl_fetch_info *fetch, CURL *handle) /* add to the global curl multi handle */ codem = curl_multi_add_handle(fetch_curl_multi, fetch->curl_handle); assert(codem == CURLM_OK || codem == CURLM_CALL_MULTI_PERFORM); - - schedule(1, (schedule_callback_fn)fetch_curl_poll, NULL); - + return true; } @@ -524,6 +532,11 @@ CURL *fetch_curl_get_handle(lwc_string *host) void fetch_curl_cache_handle(CURL *handle, lwc_string *host) { +#if LIBCURL_VERSION_NUM >= 0x071e00 + /* 7.30.0 or later has its own connection caching; suppress ours */ + curl_easy_cleanup(handle); + return; +#else struct cache_handle *h = 0; int c; RING_FINDBYLWCHOST(curl_handle_ring, h, host); @@ -561,6 +574,7 @@ void fetch_curl_cache_handle(CURL *handle, lwc_string *host) h->handle = handle; h->host = lwc_string_ref(host); RING_INSERT(curl_handle_ring, h); +#endif } @@ -687,16 +701,14 @@ fetch_curl_sslctxfun(CURL *curl_handle, void *_sslctx, void *parm) parm); if (f->downgrade_tls) { + /* Disable TLS 1.1/1.2 if the server can't cope with them */ #ifdef SSL_OP_NO_TLSv1_1 - /* Disable TLS1.1, if the server can't cope with it */ options |= SSL_OP_NO_TLSv1_1; #endif - } - #ifdef SSL_OP_NO_TLSv1_2 - /* Disable TLS1.2, as it causes some servers to stall. */ - options |= SSL_OP_NO_TLSv1_2; + options |= SSL_OP_NO_TLSv1_2; #endif + } SSL_CTX_set_options(sslctx, options); @@ -817,12 +829,6 @@ void fetch_curl_poll(lwc_string *scheme_ignored) } curl_msg = curl_multi_info_read(fetch_curl_multi, &queue); } - -#ifdef FETCHER_CURLL_SCHEDULED - if (running != 0) { - schedule(1, (schedule_callback_fn)fetch_curl_poll, fetch_curl_poll); - } -#endif } @@ -915,10 +921,12 @@ void fetch_curl_done(CURL *curl_handle, CURLcode result) BIO_get_mem_ptr(mem, &buf); (void) BIO_set_close(mem, BIO_NOCLOSE); BIO_free(mem); - snprintf(ssl_certs[i].not_before, - min(sizeof ssl_certs[i].not_before, - (unsigned) buf->length + 1), - "%s", buf->data); + memcpy(ssl_certs[i].not_before, + buf->data, + min(sizeof(ssl_certs[i].not_before) - 1, + (unsigned)buf->length)); + ssl_certs[i].not_before[min(sizeof(ssl_certs[i].not_before) - 1, + (unsigned)buf->length)] = 0; BUF_MEM_free(buf); mem = BIO_new(BIO_s_mem()); @@ -927,10 +935,13 @@ void fetch_curl_done(CURL *curl_handle, CURLcode result) BIO_get_mem_ptr(mem, &buf); (void) BIO_set_close(mem, BIO_NOCLOSE); BIO_free(mem); - snprintf(ssl_certs[i].not_after, - min(sizeof ssl_certs[i].not_after, - (unsigned) buf->length + 1), - "%s", buf->data); + memcpy(ssl_certs[i].not_after, + buf->data, + min(sizeof(ssl_certs[i].not_after) - 1, + (unsigned)buf->length)); + ssl_certs[i].not_after[min(sizeof(ssl_certs[i].not_after) - 1, + (unsigned)buf->length)] = 0; + BUF_MEM_free(buf); ssl_certs[i].sig_type = @@ -946,24 +957,30 @@ void fetch_curl_done(CURL *curl_handle, CURLcode result) BIO_get_mem_ptr(mem, &buf); (void) BIO_set_close(mem, BIO_NOCLOSE); BIO_free(mem); - snprintf(ssl_certs[i].issuer, - min(sizeof ssl_certs[i].issuer, - (unsigned) buf->length + 1), - "%s", buf->data); + memcpy(ssl_certs[i].issuer, + buf->data, + min(sizeof(ssl_certs[i].issuer) - 1, + (unsigned) buf->length)); + ssl_certs[i].issuer[min(sizeof(ssl_certs[i].issuer) - 1, + (unsigned) buf->length)] = 0; BUF_MEM_free(buf); mem = BIO_new(BIO_s_mem()); X509_NAME_print_ex(mem, X509_get_subject_name(certs[i].cert), - 0, XN_FLAG_SEP_CPLUS_SPC | - XN_FLAG_DN_REV | XN_FLAG_FN_NONE); + 0, + XN_FLAG_SEP_CPLUS_SPC | + XN_FLAG_DN_REV | + XN_FLAG_FN_NONE); BIO_get_mem_ptr(mem, &buf); (void) BIO_set_close(mem, BIO_NOCLOSE); BIO_free(mem); - snprintf(ssl_certs[i].subject, - min(sizeof ssl_certs[i].subject, - (unsigned) buf->length + 1), - "%s", buf->data); + memcpy(ssl_certs[i].subject, + buf->data, + min(sizeof(ssl_certs[i].subject) - 1, + (unsigned)buf->length)); + ssl_certs[i].subject[min(sizeof(ssl_certs[i].subject) - 1, + (unsigned) buf->length)] = 0; BUF_MEM_free(buf); ssl_certs[i].cert_type = @@ -1263,15 +1280,15 @@ fetch_curl_post_convert(const struct fetch_multipart_data *control) { struct curl_httppost *post = 0, *last = 0; CURLFORMcode code; + nserror ret; for (; control; control = control->next) { if (control->file) { - char *leafname = 0; - - leafname = filename_from_path(control->value); - - if (leafname == NULL) + char *leafname = NULL; + ret = guit->file->basename(control->value, &leafname, NULL); + if (ret != NSERROR_OK) { continue; + } /* We have to special case filenames of "", so curl * a) actually attempts the fetch and @@ -1298,10 +1315,10 @@ fetch_curl_post_convert(const struct fetch_multipart_data *control) LOG(("curl_formadd: %d (%s)", code, control->name)); } else { - char *mimetype = fetch_mimetype(control->value); + char *mimetype = guit->fetch->mimetype(control->value); code = curl_formadd(&post, &last, CURLFORM_COPYNAME, control->name, - CURLFORM_FILE, control->value, + CURLFORM_FILE, control->rawfile, CURLFORM_FILENAME, leafname, CURLFORM_CONTENTTYPE, (mimetype != 0 ? mimetype : "text/plain"), diff --git a/content/fetchers/data.c b/content/fetchers/data.c index fbaa24780..94ba63827 100644 --- a/content/fetchers/data.c +++ b/content/fetchers/data.c @@ -31,13 +31,14 @@ #include "utils/config.h" #include "content/fetch.h" +#include "content/fetchers.h" #include "content/fetchers/data.h" #include "content/urldb.h" #include "desktop/netsurf.h" +#include "utils/corestrings.h" #include "utils/nsoption.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/url.h" #include "utils/utils.h" #include "utils/ring.h" #include "utils/base64.h" @@ -324,22 +325,19 @@ static void fetch_data_poll(lwc_string *scheme) } while ( (c = next) != ring && ring != NULL); } -void fetch_data_register(void) +nserror fetch_data_register(void) { - 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_can_fetch, - fetch_data_setup, - fetch_data_start, - fetch_data_abort, - fetch_data_free, - fetch_data_poll, - fetch_data_finalise); + lwc_string *scheme = lwc_string_ref(corestring_lwc_data); + const struct fetcher_operation_table fetcher_ops = { + .initialise = fetch_data_initialise, + .acceptable = fetch_data_can_fetch, + .setup = fetch_data_setup, + .start = fetch_data_start, + .abort = fetch_data_abort, + .free = fetch_data_free, + .poll = fetch_data_poll, + .finalise = fetch_data_finalise + }; + + return fetcher_add(scheme, &fetcher_ops); } diff --git a/content/fetchers/data.h b/content/fetchers/data.h index 76f02cb3b..f6017e07a 100644 --- a/content/fetchers/data.h +++ b/content/fetchers/data.h @@ -23,6 +23,6 @@ #ifndef NETSURF_CONTENT_FETCHERS_FETCH_DATA_H #define NETSURF_CONTENT_FETCHERS_FETCH_DATA_H -void fetch_data_register(void); +nserror fetch_data_register(void); #endif diff --git a/content/fetchers/file.c b/content/fetchers/file.c index c574c2160..f08be6288 100644 --- a/content/fetchers/file.c +++ b/content/fetchers/file.c @@ -18,6 +18,8 @@ /* file: URL handling. Based on the data fetcher by Rob Kendrick */ +#include "utils/config.h" + #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -34,26 +36,28 @@ #include <limits.h> #include <stdarg.h> -#include "utils/config.h" - #ifdef HAVE_MMAP #include <sys/mman.h> #endif #include <libwapcaplet/libwapcaplet.h> -#include "content/dirlist.h" -#include "content/fetch.h" -#include "content/fetchers/file.h" -#include "content/urldb.h" #include "desktop/netsurf.h" +#include "desktop/gui_factory.h" +#include "utils/corestrings.h" #include "utils/nsoption.h" #include "utils/errors.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/url.h" #include "utils/utils.h" #include "utils/ring.h" +#include "utils/file.h" + +#include "content/dirlist.h" +#include "content/fetch.h" +#include "content/fetchers.h" +#include "content/urldb.h" +#include "content/fetchers/file.h" /* Maximum size of read buffer */ #define FETCH_FILE_MAX_BUF_SIZE (1024 * 1024) @@ -135,13 +139,14 @@ fetch_file_setup(struct fetch *fetchh, { struct fetch_file_context *ctx; int i; + nserror ret; ctx = calloc(1, sizeof(*ctx)); if (ctx == NULL) return NULL; - ctx->path = url_to_path(nsurl_access(url)); - if (ctx->path == NULL) { + ret = guit->file->nsurl_to_path(url, &ctx->path); + if (ret != NSERROR_OK) { free(ctx); return NULL; } @@ -304,7 +309,7 @@ static void fetch_file_process_plain(struct fetch_file_context *ctx, /* content type */ if (fetch_file_send_header(ctx, "Content-Type: %s", - fetch_filetype(ctx->path))) + guit->fetch->filetype(ctx->path))) goto fetch_file_process_aborted; /* content length */ @@ -384,7 +389,7 @@ fetch_file_process_aborted: /* content type */ if (fetch_file_send_header(ctx, "Content-Type: %s", - fetch_filetype(ctx->path))) + guit->fetch->filetype(ctx->path))) goto fetch_file_process_aborted; /* content length */ @@ -487,6 +492,98 @@ static char *gen_nice_title(char *path) return title; } +/** + * generate an output row of the directory listing. + * + * @param ent current directory entry. + */ +static nserror +process_dir_ent(struct fetch_file_context *ctx, + struct dirent *ent, + bool even, + char *buffer, + size_t buffer_len) +{ + nserror ret; + char *urlpath = NULL; /* buffer for leaf entry path */ + struct stat ent_stat; /* stat result of leaf entry */ + char datebuf[64]; /* buffer for date text */ + char timebuf[64]; /* buffer for time text */ + nsurl *url; + + /* skip hidden files */ + if (ent->d_name[0] == '.') { + return NSERROR_BAD_PARAMETER; + } + + ret = netsurf_mkpath(&urlpath, NULL, 2, ctx->path, ent->d_name); + if (ret != NSERROR_OK) { + return ret; + } + + if (stat(urlpath, &ent_stat) != 0) { + ent_stat.st_mode = 0; + datebuf[0] = 0; + timebuf[0] = 0; + } else { + /* Get date in output format */ + if (strftime((char *)&datebuf, sizeof datebuf, "%a %d %b %Y", + localtime(&ent_stat.st_mtime)) == 0) { + datebuf[0] = '-'; + datebuf[1] = 0; + } + + /* Get time in output format */ + if (strftime((char *)&timebuf, sizeof timebuf, "%H:%M", + localtime(&ent_stat.st_mtime)) == 0) { + timebuf[0] = '-'; + timebuf[1] = 0; + } + } + + ret = guit->file->path_to_nsurl(urlpath, &url); + if (ret != NSERROR_OK) { + free(urlpath); + return ret; + } + + if (S_ISREG(ent_stat.st_mode)) { + /* regular file */ + dirlist_generate_row(even, + false, + url, + ent->d_name, + guit->fetch->filetype(urlpath), + ent_stat.st_size, + datebuf, timebuf, + buffer, buffer_len); + } else if (S_ISDIR(ent_stat.st_mode)) { + /* directory */ + dirlist_generate_row(even, + true, + url, + ent->d_name, + messages_get("FileDirectory"), + -1, + datebuf, timebuf, + buffer, buffer_len); + } else { + /* something else */ + dirlist_generate_row(even, + false, + url, + ent->d_name, + "", + -1, + datebuf, timebuf, + buffer, buffer_len); + } + + nsurl_unref(url); + free(urlpath); + + return NSERROR_OK; +} static void fetch_file_process_dir(struct fetch_file_context *ctx, struct stat *fdstat) @@ -497,13 +594,7 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx, char *title; /* pretty printed title */ nserror err; /* result from url routines */ nsurl *up; /* url of parent */ - char *path; /* url for list entries */ - struct stat ent_stat; /* stat result of leaf entry */ - char datebuf[64]; /* buffer for date text */ - char timebuf[64]; /* buffer for time text */ - char urlpath[PATH_MAX]; /* buffer for leaf entry path */ - struct dirent *ent; /* current directory entry */ struct dirent **listing = NULL; /* directory entry listing */ int i; /* directory entry index */ int n; /* number of directory entries */ @@ -568,78 +659,17 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx, goto fetch_file_process_dir_aborted; for (i = 0; i < n; i++) { - ent = listing[i]; - - if (ent->d_name[0] == '.') - continue; - - strncpy(urlpath, ctx->path, sizeof urlpath); - if (path_add_part(urlpath, sizeof urlpath, - ent->d_name) == false) - continue; - - if (stat(urlpath, &ent_stat) != 0) { - ent_stat.st_mode = 0; - datebuf[0] = 0; - timebuf[0] = 0; - } else { - /* Get date in output format */ - if (strftime((char *)&datebuf, sizeof datebuf, - "%a %d %b %Y", - localtime(&ent_stat.st_mtime)) == 0) { - strncpy(datebuf, "-", sizeof datebuf); - } - /* Get time in output format */ - if (strftime((char *)&timebuf, sizeof timebuf, - "%H:%M", - localtime(&ent_stat.st_mtime)) == 0) { - strncpy(timebuf, "-", sizeof timebuf); - } - } + err = process_dir_ent(ctx, listing[i], even, buffer, + sizeof(buffer)); - if((path = path_to_url(urlpath)) == NULL) - continue; + if (err == NSERROR_OK) { + msg.data.header_or_data.len = strlen(buffer); + if (fetch_file_send_callback(&msg, ctx)) + goto fetch_file_process_dir_aborted; - if (S_ISREG(ent_stat.st_mode)) { - /* regular file */ - dirlist_generate_row(even, - false, - path, - ent->d_name, - fetch_filetype(urlpath), - ent_stat.st_size, - datebuf, timebuf, - buffer, sizeof(buffer)); - } else if (S_ISDIR(ent_stat.st_mode)) { - /* directory */ - dirlist_generate_row(even, - true, - path, - ent->d_name, - messages_get("FileDirectory"), - -1, - datebuf, timebuf, - buffer, sizeof(buffer)); - } else { - /* something else */ - dirlist_generate_row(even, - false, - path, - ent->d_name, - "", - -1, - datebuf, timebuf, - buffer, sizeof(buffer)); + even = !even; } - - free(path); - - msg.data.header_or_data.len = strlen(buffer); - if (fetch_file_send_callback(&msg, ctx)) - goto fetch_file_process_dir_aborted; - - even = !even; } /* directory listing bottom */ @@ -731,22 +761,19 @@ static void fetch_file_poll(lwc_string *scheme) } while ( (c = next) != ring && ring != NULL); } -void fetch_file_register(void) +nserror fetch_file_register(void) { - 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_can_fetch, - fetch_file_setup, - fetch_file_start, - fetch_file_abort, - fetch_file_free, - fetch_file_poll, - fetch_file_finalise); + lwc_string *scheme = lwc_string_ref(corestring_lwc_file); + const struct fetcher_operation_table fetcher_ops = { + .initialise = fetch_file_initialise, + .acceptable = fetch_file_can_fetch, + .setup = fetch_file_setup, + .start = fetch_file_start, + .abort = fetch_file_abort, + .free = fetch_file_free, + .poll = fetch_file_poll, + .finalise = fetch_file_finalise + }; + + return fetcher_add(scheme, &fetcher_ops); } diff --git a/content/fetchers/file.h b/content/fetchers/file.h index d1621b9ba..b3c39db9f 100644 --- a/content/fetchers/file.h +++ b/content/fetchers/file.h @@ -23,6 +23,6 @@ #ifndef NETSURF_CONTENT_FETCHERS_FETCH_FILE_H #define NETSURF_CONTENT_FETCHERS_FETCH_FILE_H -void fetch_file_register(void); +nserror fetch_file_register(void); #endif diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c index 0119c6b3b..18e302140 100644 --- a/content/fetchers/resource.c +++ b/content/fetchers/resource.c @@ -37,17 +37,19 @@ #include <libwapcaplet/libwapcaplet.h> #include "utils/config.h" -#include "content/dirlist.h" -#include "content/fetch.h" -#include "content/fetchers/resource.h" -#include "content/urldb.h" -#include "desktop/gui.h" +#include "utils/errors.h" +#include "utils/corestrings.h" #include "utils/nsoption.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/url.h" #include "utils/utils.h" #include "utils/ring.h" +#include "desktop/gui_factory.h" + +#include "content/fetch.h" +#include "content/fetchers.h" +#include "content/fetchers/resource.h" +#include "content/urldb.h" struct fetch_resource_context; @@ -81,6 +83,7 @@ static const char *fetch_resource_paths[] = { "licence.html", "welcome.html", "favicon.ico", + "default.ico", "netsurf.png", "icons/arrow-l.png", "icons/content.png", @@ -206,7 +209,7 @@ static bool fetch_resource_initialise(lwc_string *scheme) } } - e->url = gui_get_resource_url(fetch_resource_paths[i]); + e->url = guit->fetch->get_resource_url(fetch_resource_paths[i]); if (e->url == NULL) { lwc_string_unref(e->path); } else { @@ -353,23 +356,19 @@ static void fetch_resource_poll(lwc_string *scheme) } while ( (c = next) != ring && ring != NULL); } -void fetch_resource_register(void) +nserror fetch_resource_register(void) { - 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_can_fetch, - fetch_resource_setup, - fetch_resource_start, - fetch_resource_abort, - fetch_resource_free, - fetch_resource_poll, - fetch_resource_finalise); + lwc_string *scheme = lwc_string_ref(corestring_lwc_resource); + const struct fetcher_operation_table fetcher_ops = { + .initialise = fetch_resource_initialise, + .acceptable = fetch_resource_can_fetch, + .setup = fetch_resource_setup, + .start = fetch_resource_start, + .abort = fetch_resource_abort, + .free = fetch_resource_free, + .poll = fetch_resource_poll, + .finalise = fetch_resource_finalise + }; + + return fetcher_add(scheme, &fetcher_ops); } diff --git a/content/fetchers/resource.h b/content/fetchers/resource.h index 79d8e37c4..cf4d6edac 100644 --- a/content/fetchers/resource.h +++ b/content/fetchers/resource.h @@ -35,6 +35,6 @@ * * should only be called from the fetch initialise */ -void fetch_resource_register(void); +nserror fetch_resource_register(void); #endif |