diff options
53 files changed, 815 insertions, 597 deletions
diff --git a/amiga/login.c b/amiga/login.c index 496898113..35115bc2a 100755 --- a/amiga/login.c +++ b/amiga/login.c @@ -48,23 +48,24 @@ struct gui_login_window { Object *objects[GID_LAST]; nserror (*cb)(bool proceed, void *pw); void *cbpw; - char *url; + nsurl *url; char *realm; - char *host; + lwc_string *host; char uname[256]; char pwd[256]; }; -void gui_401login_open(const char *url, const char *realm, +void gui_401login_open(nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw) { const char *auth; struct gui_login_window *lw = AllocVec(sizeof(struct gui_login_window),MEMF_PRIVATE | MEMF_CLEAR); - char *host; + lwc_string *host = nsurl_get_component(url, NSURL_HOST); + + assert(host != NULL); - url_host(url, &host); lw->host = host; - lw->url = (char *)url; + lw->url = nsurl_ref(url); lw->realm = (char *)realm; lw->cb = cb; lw->cbpw = cbpw; @@ -105,7 +106,7 @@ void gui_401login_open(const char *url, const char *realm, WINDOW_Position, WPOS_CENTERSCREEN, WINDOW_ParentGroup, lw->objects[GID_MAIN] = VGroupObject, LAYOUT_AddChild, StringObject, - STRINGA_TextVal,lw->host, + STRINGA_TextVal,lw->lwc_string_data(host), GA_ReadOnly,TRUE, StringEnd, CHILD_Label, LabelObject, @@ -171,7 +172,8 @@ void ami_401login_close(struct gui_login_window *lw) lw->cb(false, lw->cbpw); DisposeObject(lw->objects[OID_MAIN]); - free(lw->host); + lwc_string_unref(lw->host); + nsurl_unref(lw->url); DelObject(lw->node); } diff --git a/amiga/sslcert.c b/amiga/sslcert.c index 8eede70f2..dcf9a6d7d 100644 --- a/amiga/sslcert.c +++ b/amiga/sslcert.c @@ -20,7 +20,7 @@ #include "amiga/tree.h" #include "amiga/sslcert.h" -void gui_cert_verify(const char *url, +void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { diff --git a/amiga/stringview/urlhistory.c b/amiga/stringview/urlhistory.c index af9c35b13..ec56987f9 100644 --- a/amiga/stringview/urlhistory.c +++ b/amiga/stringview/urlhistory.c @@ -69,7 +69,7 @@ struct List * URLHistory_GetList( void ) return &PageList; } -static bool URLHistoryFound(const char *url, const struct url_data *data) +static bool URLHistoryFound(nsurl *url, const struct url_data *data) { struct Node *node; @@ -77,16 +77,16 @@ static bool URLHistoryFound(const char *url, const struct url_data *data) if(data->visits <= 0) return true; /* skip this URL if it is already in the list */ - if(URLHistory_FindPage(url)) return true; + if(URLHistory_FindPage(nsurl_access(url))) return true; node = AllocVec( sizeof( struct Node ), MEMF_SHARED|MEMF_CLEAR ); if ( node ) { - STRPTR urladd = (STRPTR) AllocVec( strlen ( url ) + 1, MEMF_SHARED|MEMF_CLEAR ); + STRPTR urladd = (STRPTR) AllocVec( strlen ( nsurl_access(url) ) + 1, MEMF_SHARED|MEMF_CLEAR ); if ( urladd ) { - strcpy(urladd, url); + strcpy(urladd, nsurl_access(url)); node->ln_Name = urladd; AddTail( &PageList, node ); } diff --git a/amiga/thumbnail.c b/amiga/thumbnail.c index 08ab90a95..f1738d29d 100755 --- a/amiga/thumbnail.c +++ b/amiga/thumbnail.c @@ -37,7 +37,7 @@ #include <sys/param.h> bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, - const char *url) + nsurl *url) { struct BitScaleArgs bsa; int plot_width; diff --git a/atari/gui.c b/atari/gui.c index b780985dc..0b76d39ba 100755 --- a/atari/gui.c +++ b/atari/gui.c @@ -743,12 +743,12 @@ void gui_launch_url(const char *url) LOG(("launch file: %s\n", url));
}
-void gui_401login_open(const char *url, const char *realm,
+void gui_401login_open(nsurl *url, const char *realm,
nserror (*cb)(bool proceed, void *pw), void *cbpw)
{
bool bres;
char * out = NULL;
- bres = login_form_do( (char*)url, (char*)realm, &out );
+ bres = login_form_do( url, (char*)realm, &out );
if( bres ) {
LOG(("url: %s, realm: %s, auth: %s\n", url, realm, out ));
urldb_set_auth_details(url, realm, out );
@@ -760,7 +760,7 @@ void gui_401login_open(const char *url, const char *realm, cb(bres, cbpw);
}
-void gui_cert_verify(const char *url, const struct ssl_cert_info *certs,
+void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
unsigned long num,
nserror (*cb)(bool proceed, void *pw), void *cbpw)
{
@@ -951,15 +951,15 @@ static void gui_init(int argc, char** argv) LOG(("Enabling core select menu"));
nsoption_set_bool(core_select_menu, true);
- +
LOG(("Loading url.db from: %s", nsoption_charp(url_file) ));
if( strlen(nsoption_charp(url_file)) ){
urldb_load(nsoption_charp(url_file));
- } - - if (nsoption_charp(cookie_file) == NULL ){ - nsoption_set_charp(cookie_file, (char*)"cookies"); - } + }
+
+ if (nsoption_charp(cookie_file) == NULL ){
+ nsoption_set_charp(cookie_file, (char*)"cookies");
+ }
LOG(("Loading cookies from: %s", nsoption_charp(cookie_file) ));
if( strlen(nsoption_charp(cookie_file)) ){
urldb_load_cookies(nsoption_charp(cookie_file));
diff --git a/atari/login.c b/atari/login.c index 2dc766f56..ddcfeba43 100755 --- a/atari/login.c +++ b/atari/login.c @@ -42,7 +42,7 @@ extern void * h_gem_rsrc; -bool login_form_do( char * url, char * realm, char ** out ) +bool login_form_do( nsurl * url, char * realm, char ** out ) { OBJECT *tree, *newtree; WINDOW * form; @@ -51,19 +51,21 @@ bool login_form_do( char * url, char * realm, char ** out ) bool bres = false; int res = 0; const char * auth; - char * host; - assert( url_host( url, &host) == URL_FUNC_OK ); + lwc_string * host = nsurl_get_component(url, NSURL_HOST); + assert(host != NULL); if( realm == NULL ){ realm = (char*)"Secure Area"; } - int len = strlen(realm) + strlen(host) + 4; + int len = strlen(realm) + lwc_string_length(host) + 4; char * title = malloc( len ); strncpy(title, realm, len ); strncpy(title, ": ", len-strlen(realm) ); - strncat(title, host, len-strlen(realm)+2 ); - + strncat(title, lwc_string_data(host), len-strlen(realm)+2 ); + + lwc_string_unref(host); + auth = urldb_get_auth_details(url, realm); user[0] = 0; pass[0] = 0; diff --git a/atari/login.h b/atari/login.h index 52a4832c9..345f91df3 100755 --- a/atari/login.h +++ b/atari/login.h @@ -19,6 +19,8 @@ #ifndef NS_LOGIN_H_INCLUDED
#define NS_LOGIN_H_INCLUDED
-bool login_form_do( char * host, char * realm, char **cbpw );
+#include "utils/nsurl.h"
+
+bool login_form_do( nsurl * host, char * realm, char **cbpw );
#endif
diff --git a/atari/thumbnail.c b/atari/thumbnail.c index ff1c09eed..4783103bd 100755 --- a/atari/thumbnail.c +++ b/atari/thumbnail.c @@ -19,7 +19,7 @@ #include "desktop/thumbnail.h" bool thumbnail_create(struct hlcache_handle *content, struct bitmap *bitmap, - const char *url) + nsurl *url) { return false; } diff --git a/beos/gui.cpp b/beos/gui.cpp index 4b16022f0..dc3c33538 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1009,7 +1009,7 @@ void die(const char * const error) exit(EXIT_FAILURE); } -void gui_cert_verify(const char *url, const struct ssl_cert_info *certs, +void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { diff --git a/beos/thumbnail.cpp b/beos/thumbnail.cpp index ea03d29d8..128462f57 100644 --- a/beos/thumbnail.cpp +++ b/beos/thumbnail.cpp @@ -57,7 +57,7 @@ extern status_t ScaleBitmap(const BBitmap& inBitmap, BBitmap& outBitmap); * \param url the URL the thumnail belongs to, or NULL */ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, - const char *url) + nsurl *url) { BBitmap *thumbnail; BBitmap *small; diff --git a/cocoa/gui.m b/cocoa/gui.m index a76924b5c..94de3753b 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -310,7 +310,7 @@ void gui_launch_url(const char *url) struct ssl_cert_info; -void gui_cert_verify(const char *url, const struct ssl_cert_info *certs, +void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { @@ -318,7 +318,7 @@ void gui_cert_verify(const char *url, const struct ssl_cert_info *certs, } -void gui_401login_open(const char *url, const char *realm, +void gui_401login_open(nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw) { cb( false, cbpw ); diff --git a/cocoa/thumbnail.m b/cocoa/thumbnail.m index fd287a523..7e524b754 100644 --- a/cocoa/thumbnail.m +++ b/cocoa/thumbnail.m @@ -26,8 +26,7 @@ #import "image/bitmap.h" /* In platform specific thumbnail.c. */ -bool thumbnail_create(struct hlcache_handle *content, struct bitmap *bitmap, - const char *url) +bool thumbnail_create(struct hlcache_handle *content, struct bitmap *bitmap, nsurl *url) { int bwidth = bitmap_get_width( bitmap ); int bheight = bitmap_get_height( bitmap ); diff --git a/content/fetch.c b/content/fetch.c index 2b16512fa..51eed0e2f 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -730,7 +730,7 @@ fetch_set_cookie(struct fetch *fetch, const char *data) /* If the transaction's verifiable, we don't require * that the request uri and the parent domain match, * so don't pass in any referer/parent in this case. */ - urldb_set_cookie(data, nsurl_access(fetch->url), NULL); + urldb_set_cookie(data, fetch->url, NULL); } else if (fetch->referer != NULL) { /* Permit the cookie to be set if the fetch is unverifiable * and the fetch URI domain matches the referer. */ @@ -739,8 +739,7 @@ fetch_set_cookie(struct fetch *fetch, const char *data) * where a nested object requests a fetch, the origin URI * is the nested object's parent URI, whereas the referer * for the fetch will be the nested object's URI. */ - urldb_set_cookie(data, nsurl_access(fetch->url), - nsurl_access(fetch->referer)); + urldb_set_cookie(data, fetch->url, fetch->referer); } } diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c index 70252b4cc..f33dfde50 100644 --- a/content/fetchers/curl.c +++ b/content/fetchers/curl.c @@ -597,14 +597,14 @@ fetch_curl_set_options(struct curl_fetch_info *f) SETOPT(CURLOPT_HTTPGET, 1L); } - f->cookie_string = urldb_get_cookie(nsurl_access(f->url)); + f->cookie_string = urldb_get_cookie(f->url); if (f->cookie_string) { SETOPT(CURLOPT_COOKIE, f->cookie_string); } else { SETOPT(CURLOPT_COOKIE, NULL); } - if ((auth = urldb_get_auth_details(nsurl_access(f->url), NULL)) != NULL) { + if ((auth = urldb_get_auth_details(f->url, NULL)) != NULL) { SETOPT(CURLOPT_HTTPAUTH, CURLAUTH_ANY); SETOPT(CURLOPT_USERPWD, auth); } else { @@ -633,7 +633,7 @@ fetch_curl_set_options(struct curl_fetch_info *f) SETOPT(CURLOPT_PROXY, NULL); } - if (urldb_get_cert_permissions(nsurl_access(f->url))) { + if (urldb_get_cert_permissions(f->url)) { /* Disable certificate verification */ SETOPT(CURLOPT_SSL_VERIFYPEER, 0L); SETOPT(CURLOPT_SSL_VERIFYHOST, 0L); diff --git a/content/llcache.c b/content/llcache.c index 29f1a557c..ed5cc6eda 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -1453,7 +1453,7 @@ static nserror llcache_fetch_auth(llcache_object *object, const char *realm) if (realm == NULL) realm = nsurl_access(object->url); - auth = urldb_get_auth_details(nsurl_access(object->url), realm); + auth = urldb_get_auth_details(object->url, realm); if (auth == NULL || object->fetch.tried_with_auth == true) { /* No authentication details, or tried what we had, so ask */ diff --git a/content/urldb.c b/content/urldb.c index 6776ebe1a..7be508bef 100644 --- a/content/urldb.c +++ b/content/urldb.c @@ -107,6 +107,7 @@ #include "riscos/bitmap.h" #endif #include "utils/log.h" +#include "utils/corestrings.h" #include "utils/filename.h" #include "utils/url.h" #include "utils/utils.h" @@ -135,7 +136,7 @@ struct cookie_internal_data { * This structure lives as linked list element in a leaf host_part struct * so we need additional scheme and port to have a canonical_root_url. */ struct prot_space_data { - char *scheme; /**< URL scheme of canonical hostname of this + lwc_string *scheme; /**< URL scheme of canonical hostname of this * protection space. */ unsigned int port; /**< Port number of canonical hostname of this * protection space. When 0, it means the @@ -161,8 +162,8 @@ struct url_internal_data { }; struct path_data { - char *url; /**< Full URL */ - char *scheme; /**< URL scheme for data */ + nsurl *url; /**< Full URL */ + lwc_string *scheme; /**< URL scheme for data */ unsigned int port; /**< Port number for data. When 0, it means * the default port for given scheme, i.e. * 80 (http), 443 (https). */ @@ -237,34 +238,34 @@ static void urldb_write_paths(const struct path_data *parent, /* Iteration */ static bool urldb_iterate_partial_host(struct search_node *root, - const char *prefix, bool (*callback)(const char *url, + const char *prefix, bool (*callback)(nsurl *url, const struct url_data *data)); static bool urldb_iterate_partial_path(const struct path_data *parent, - const char *prefix, bool (*callback)(const char *url, + const char *prefix, bool (*callback)(nsurl *url, const struct url_data *data)); static bool urldb_iterate_entries_host(struct search_node *parent, - bool (*url_callback)(const char *url, + bool (*url_callback)(nsurl *url, const struct url_data *data), bool (*cookie_callback)(const struct cookie_data *data)); static bool urldb_iterate_entries_path(const struct path_data *parent, - bool (*url_callback)(const char *url, + bool (*url_callback)(nsurl *url, const struct url_data *data), bool (*cookie_callback)(const struct cookie_data *data)); /* Insertion */ static struct host_part *urldb_add_host_node(const char *part, struct host_part *parent); -static struct path_data *urldb_add_path_node(const char *scheme, - unsigned int port, const char *segment, const char *fragment, +static struct path_data *urldb_add_path_node(lwc_string *scheme, + unsigned int port, const char *segment, lwc_string *fragment, struct path_data *parent); static int urldb_add_path_fragment_cmp(const void *a, const void *b); static struct path_data *urldb_add_path_fragment(struct path_data *segment, - const char *fragment); + lwc_string *fragment); /* Lookup */ -static struct path_data *urldb_find_url(const char *url); +static struct path_data *urldb_find_url(nsurl *url); static struct path_data *urldb_match_path(const struct path_data *parent, - const char *path, const char *scheme, unsigned short port); + const char *path, lwc_string *scheme, unsigned short port); static struct search_node **urldb_get_search_tree_direct(const char *host); static struct search_node *urldb_get_search_tree(const char *host); @@ -291,12 +292,12 @@ static int urldb_search_match_prefix(const struct host_part *a, const char *b); /* Cookies */ -static struct cookie_internal_data *urldb_parse_cookie(const char *url, +static struct cookie_internal_data *urldb_parse_cookie(nsurl *url, const char **cookie); static bool urldb_parse_avpair(struct cookie_internal_data *c, char *n, char *v, bool was_quoted); static bool urldb_insert_cookie(struct cookie_internal_data *c, - const char *scheme, const char *url); + lwc_string *scheme, nsurl *url); static void urldb_free_cookie(struct cookie_internal_data *c); static bool urldb_concat_cookie(struct cookie_internal_data *c, int version, int *used, int *alloc, char **buf); @@ -415,6 +416,10 @@ void urldb_load(const char *filename) char url[64 + 3 + 256 + 6 + 4096 + 1]; unsigned int port; bool is_file = false; + nsurl *nsurl; + lwc_string *scheme_lwc, *fragment_lwc; + char *path_query; + size_t len; if (!fgets(scheme, sizeof scheme, fp)) break; @@ -444,13 +449,39 @@ void urldb_load(const char *filename) (port ? ports : ""), s); - p = urldb_add_path(scheme, port, h, s, NULL, NULL, - url); + /* TODO: store URLs in pre-parsed state, and make + * a nsurl_load to generate the nsurl more + * swiftly. + * Need a nsurl_save too. + */ + if (nsurl_create(url, &nsurl) != NSERROR_OK) { + LOG(("Failed inserting '%s'", url)); + die("Memory exhausted whilst loading " + "URL file"); + } + + /* Copy and merge path/query strings */ + if (nsurl_get(nsurl, NSURL_PATH | NSURL_QUERY, + &path_query, &len) != NSERROR_OK) { + LOG(("Failed inserting '%s'", url)); + die("Memory exhausted whilst loading " + "URL file"); + } + + scheme_lwc = nsurl_get_component(nsurl, NSURL_SCHEME); + fragment_lwc = nsurl_get_component(nsurl, + NSURL_FRAGMENT); + p = urldb_add_path(scheme_lwc, port, h, path_query, + fragment_lwc, nsurl); if (!p) { LOG(("Failed inserting '%s'", url)); die("Memory exhausted whilst loading " "URL file"); } + nsurl_unref(nsurl); + lwc_string_unref(scheme_lwc); + if (fragment_lwc != NULL) + lwc_string_unref(fragment_lwc); if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) break; @@ -673,7 +704,7 @@ void urldb_write_paths(const struct path_data *parent, const char *host, /* leaf node */ if (p->persistent ||((p->urld.last_visit > expiry) && (p->urld.visits > 0))) { - fprintf(fp, "%s\n", p->scheme); + fprintf(fp, "%s\n", lwc_string_data(p->scheme)); if (p->port) fprintf(fp,"%d\n", p->port); @@ -743,7 +774,7 @@ void urldb_write_paths(const struct path_data *parent, const char *host, * \param url Absolute URL to persist * \param persist True to persist, false otherwise */ -void urldb_set_url_persistence(const char *url, bool persist) +void urldb_set_url_persistence(nsurl *url, bool persist) { struct path_data *p; @@ -762,62 +793,66 @@ void urldb_set_url_persistence(const char *url, bool persist) * \param url Absolute URL to insert * \return true on success, false otherwise */ -bool urldb_add_url(const char *url) +bool urldb_add_url(nsurl *url) { struct host_part *h; struct path_data *p; - char *colon; - const char *host; - unsigned short port; - url_func_result ret; - struct url_components components; + lwc_string *scheme; + lwc_string *port; + lwc_string *host; + lwc_string *fragment; + const char *host_str; + char *path_query; + size_t len; + bool match; + unsigned int port_int; assert(url); - /* extract url components */ - ret = url_get_components(url, &components); - if (ret != URL_FUNC_OK) + /* Copy and merge path/query strings */ + if (nsurl_get(url, NSURL_PATH | NSURL_QUERY, &path_query, &len) != + NSERROR_OK) { return false; + } + + scheme = nsurl_get_component(url, NSURL_SCHEME); + if (scheme == NULL) + return false; + + host = nsurl_get_component(url, NSURL_HOST); + if (host != NULL) { + host_str = lwc_string_data(host); + lwc_string_unref(host); - /* Ensure scheme and authority exist */ - if (!(components.scheme && components.authority)) { - url_destroy_components(&components); + } else if (lwc_string_isequal(scheme, corestring_lwc_file, &match) == + lwc_error_ok && match == true) { + host_str = "localhost"; + + } else { + lwc_string_unref(scheme); return false; } - /* Extract host part from authority */ - host = strchr(components.authority, '@'); - if (!host) - host = components.authority; - else - host++; + fragment = nsurl_get_component(url, NSURL_FRAGMENT); - /* get port and remove from host */ - port = 0; - if (host[strlen(host) - 1] != ']') { - colon = strrchr(host, ':'); - if (colon) { - *colon = '\0'; - port = atoi(colon + 1); - } + port = nsurl_get_component(url, NSURL_PORT); + if (port != NULL) { + port_int = atoi(lwc_string_data(port)); + lwc_string_unref(port); + } else { + port_int = 0; } /* Get host entry */ - if (strcasecmp(components.scheme, "file") == 0) - h = urldb_add_host("localhost"); - else - h = urldb_add_host(host); - if (!h) { - url_destroy_components(&components); - return false; - } + h = urldb_add_host(host_str); /* Get path entry */ - p = urldb_add_path(components.scheme, port, h, - components.path ? components.path : "", - components.query, components.fragment, url); + p = (h != NULL) ? urldb_add_path(scheme, port_int, h, path_query, + fragment, url) : NULL; - url_destroy_components(&components); + lwc_string_unref(scheme); + if (fragment != NULL) + lwc_string_unref(fragment); return (p != NULL); } @@ -828,7 +863,7 @@ bool urldb_add_url(const char *url) * \param url The URL to look for * \param title The title string to use (copied) */ -void urldb_set_url_title(const char *url, const char *title) +void urldb_set_url_title(nsurl *url, const char *title) { struct path_data *p; char *temp; @@ -853,7 +888,7 @@ void urldb_set_url_title(const char *url, const char *title) * \param url The URL to look for * \param type The type to set */ -void urldb_set_url_content_type(const char *url, content_type type) +void urldb_set_url_content_type(nsurl *url, content_type type) { struct path_data *p; @@ -871,7 +906,7 @@ void urldb_set_url_content_type(const char *url, content_type type) * * \param url The URL to update */ -void urldb_update_url_visit_data(const char *url) +void urldb_update_url_visit_data(nsurl *url) { struct path_data *p; @@ -890,7 +925,7 @@ void urldb_update_url_visit_data(const char *url) * * \param url The URL to reset */ -void urldb_reset_url_visit_data(const char *url) +void urldb_reset_url_visit_data(nsurl *url) { struct path_data *p; @@ -911,7 +946,7 @@ void urldb_reset_url_visit_data(const char *url) * \param url Absolute URL to look for * \return Pointer to result struct, or NULL */ -const struct url_data *urldb_get_url_data(const char *url) +const struct url_data *urldb_get_url_data(nsurl *url) { struct path_data *p; struct url_internal_data *u; @@ -933,7 +968,7 @@ const struct url_data *urldb_get_url_data(const char *url) * \param url URL to extract * \return Pointer to database's copy of URL or NULL if not found */ -const char *urldb_get_url(const char *url) +nsurl *urldb_get_url(nsurl *url) { struct path_data *p; @@ -954,7 +989,7 @@ const char *urldb_get_url(const char *url) * the protection space when that's not been done before for given URL. * \return Pointer to authentication details, or NULL if not found */ -const char *urldb_get_auth_details(const char *url, const char *realm) +const char *urldb_get_auth_details(nsurl *url, const char *realm) { struct path_data *p, *p_cur, *p_top; @@ -980,13 +1015,17 @@ const char *urldb_get_auth_details(const char *url, const char *realm) if (realm != NULL) { const struct host_part *h = (const struct host_part *)p_top; const struct prot_space_data *space; + bool match; /* Search for a possible matching protection space. */ for (space = h->prot_space; space != NULL; space = space->next) { - if (!strcmp(space->realm, realm) - && !strcmp(space->scheme, p->scheme) - && space->port == p->port) { + if (!strcmp(space->realm, realm) && + lwc_string_isequal(space->scheme, + p->scheme, &match) == + lwc_error_ok && + match == true && + space->port == p->port) { p->prot_space = space; return p->prot_space->auth; } @@ -1003,7 +1042,7 @@ const char *urldb_get_auth_details(const char *url, const char *realm) * \return true to permit connections to hosts with invalid certificates, * false otherwise. */ -bool urldb_get_cert_permissions(const char *url) +bool urldb_get_cert_permissions(nsurl *url) { struct path_data *p; const struct host_part *h; @@ -1030,13 +1069,14 @@ bool urldb_get_cert_permissions(const char *url) * \param realm The authentication realm * \param auth The authentication details (in form username:password) */ -void urldb_set_auth_details(const char *url, const char *realm, +void urldb_set_auth_details(nsurl *url, const char *realm, const char *auth) { struct path_data *p, *pi; struct host_part *h; struct prot_space_data *space, *space_alloc; - char *realm_alloc, *auth_alloc, *scheme_alloc; + char *realm_alloc, *auth_alloc; + bool match; assert(url && realm && auth); @@ -1055,9 +1095,11 @@ void urldb_set_auth_details(const char *url, const char *realm, /* Search if given URL belongs to a protection space we already know of. */ for (space = h->prot_space; space; space = space->next) { - if (!strcmp(space->realm, realm) - && !strcmp(space->scheme, p->scheme) - && space->port == p->port) + if (!strcmp(space->realm, realm) && + lwc_string_isequal(space->scheme, p->scheme, + &match) == lwc_error_ok && + match == true && + space->port == p->port) break; } @@ -1068,20 +1110,17 @@ void urldb_set_auth_details(const char *url, const char *realm, } else { /* Create a new protection space. */ space = space_alloc = malloc(sizeof(struct prot_space_data)); - scheme_alloc = strdup(p->scheme); realm_alloc = strdup(realm); auth_alloc = strdup(auth); - if (!space_alloc || !scheme_alloc - || !realm_alloc || !auth_alloc) { + if (!space_alloc || !realm_alloc || !auth_alloc) { free(space_alloc); - free(scheme_alloc); free(realm_alloc); free(auth_alloc); return; } - space->scheme = scheme_alloc; + space->scheme = lwc_string_ref(p->scheme); space->port = p->port; space->realm = realm_alloc; space->auth = auth_alloc; @@ -1098,7 +1137,7 @@ void urldb_set_auth_details(const char *url, const char *realm, * \param url URL to consider * \param permit Set to true to allow invalid certificates */ -void urldb_set_cert_permissions(const char *url, bool permit) +void urldb_set_cert_permissions(nsurl *url, bool permit) { struct path_data *p; struct host_part *h; @@ -1127,7 +1166,7 @@ void urldb_set_cert_permissions(const char *url, bool permit) * \param url Absolute URL to consider * \param bitmap Opaque pointer to thumbnail data, or NULL to invalidate */ -void urldb_set_thumbnail(const char *url, struct bitmap *bitmap) +void urldb_set_thumbnail(nsurl *url, struct bitmap *bitmap) { struct path_data *p; @@ -1149,7 +1188,7 @@ void urldb_set_thumbnail(const char *url, struct bitmap *bitmap) * \param url Absolute URL to search for * \return Pointer to thumbnail data, or NULL if not found. */ -struct bitmap *urldb_get_thumbnail(const char *url) +struct bitmap *urldb_get_thumbnail(nsurl *url) { struct path_data *p; @@ -1169,7 +1208,7 @@ struct bitmap *urldb_get_thumbnail(const char *url) * \param callback Callback function */ void urldb_iterate_partial(const char *prefix, - bool (*callback)(const char *url, + bool (*callback)(nsurl *url, const struct url_data *data)) { char host[256]; @@ -1242,7 +1281,7 @@ void urldb_iterate_partial(const char *prefix, * \return true to continue, false otherwise */ bool urldb_iterate_partial_host(struct search_node *root, const char *prefix, - bool (*callback)(const char *url, const struct url_data *data)) + bool (*callback)(nsurl *url, const struct url_data *data)) { int c; @@ -1292,7 +1331,7 @@ bool urldb_iterate_partial_host(struct search_node *root, const char *prefix, * \return true to continue, false otherwise */ bool urldb_iterate_partial_path(const struct path_data *parent, - const char *prefix, bool (*callback)(const char *url, + const char *prefix, bool (*callback)(nsurl *url, const struct url_data *data)) { const struct path_data *p = parent->children; @@ -1372,7 +1411,7 @@ bool urldb_iterate_partial_path(const struct path_data *parent, * * \param callback Function to callback for each entry */ -void urldb_iterate_entries(bool (*callback)(const char *url, +void urldb_iterate_entries(bool (*callback)(nsurl *url, const struct url_data *data)) { int i; @@ -1413,7 +1452,7 @@ void urldb_iterate_cookies(bool (*callback)(const struct cookie_data *data)) * \return true to continue, false otherwise */ bool urldb_iterate_entries_host(struct search_node *parent, - bool (*url_callback)(const char *url, + bool (*url_callback)(nsurl *url, const struct url_data *data), bool (*cookie_callback)(const struct cookie_data *data)) { @@ -1449,7 +1488,7 @@ bool urldb_iterate_entries_host(struct search_node *parent, * \return true to continue, false otherwise */ bool urldb_iterate_entries_path(const struct path_data *parent, - bool (*url_callback)(const char *url, + bool (*url_callback)(nsurl *url, const struct url_data *data), bool (*cookie_callback)(const struct cookie_data *data)) { @@ -1632,8 +1671,8 @@ struct host_part *urldb_add_host(const char *host) * \param parent Parent node to add to * \return Pointer to added node, or NULL on memory exhaustion */ -struct path_data *urldb_add_path_node(const char *scheme, unsigned int port, - const char *segment, const char *fragment, +struct path_data *urldb_add_path_node(lwc_string *scheme, unsigned int port, + const char *segment, lwc_string *fragment, struct path_data *parent) { struct path_data *d, *e; @@ -1644,17 +1683,13 @@ struct path_data *urldb_add_path_node(const char *scheme, unsigned int port, if (!d) return NULL; - d->scheme = strdup(scheme); - if (!d->scheme) { - free(d); - return NULL; - } + d->scheme = lwc_string_ref(scheme); d->port = port; d->segment = strdup(segment); if (!d->segment) { - free(d->scheme); + lwc_string_unref(d->scheme); free(d); return NULL; } @@ -1662,7 +1697,7 @@ struct path_data *urldb_add_path_node(const char *scheme, unsigned int port, if (fragment) { if (!urldb_add_path_fragment(d, fragment)) { free(d->segment); - free(d->scheme); + lwc_string_unref(d->scheme); free(d); return NULL; } @@ -1700,44 +1735,24 @@ struct path_data *urldb_add_path_node(const char *scheme, unsigned int port, * \param scheme URL scheme associated with path * \param port Port number on host associated with path * \param host Host tree node to attach to - * \param path Absolute path to add - * \param query Path query to add + * \param path_query Absolute path plus query to add (freed) * \param fragment URL fragment, or NULL * \param url URL (fragment ignored) * \return Pointer to leaf node, or NULL on memory exhaustion */ -struct path_data *urldb_add_path(const char *scheme, unsigned int port, - const struct host_part *host, const char *path, - const char *query, const char *fragment, const char *url) +struct path_data *urldb_add_path(lwc_string *scheme, unsigned int port, + const struct host_part *host, char *path_query, + lwc_string *fragment, nsurl *url) { struct path_data *d, *e; - char *buf, *copy; + char *buf = path_query; char *segment, *slash; - int len = 0; + bool match; assert(scheme && host && url); - assert(path || query); d = (struct path_data *) &host->paths; - /* Copy and merge path/query strings, so we can corrupt them */ - if (path) - len += strlen(path); - if (query) - len += strlen(query) + 1; - buf = malloc(len + 1); - if (!buf) - return NULL; - copy = buf; - if (path) { - strcpy(copy, path); - copy += strlen(path); - } - if (query) { - *copy++ = '?'; - strcpy(copy, query); - } - /* skip leading '/' */ segment = buf; if (*segment == '/') @@ -1751,8 +1766,10 @@ struct path_data *urldb_add_path(const char *scheme, unsigned int port, /* look for existing entry */ for (e = d->children; e; e = e->next) if (strcmp(segment, e->segment) == 0 && - strcasecmp(scheme, - e->scheme) == 0 && + lwc_string_isequal(scheme, + e->scheme, &match) == + lwc_error_ok && + match == true && e->port == port) break; @@ -1767,29 +1784,30 @@ struct path_data *urldb_add_path(const char *scheme, unsigned int port, /* look for existing entry */ for (e = d->children; e; e = e->next) if (strcmp(segment, e->segment) == 0 && - strcasecmp(scheme, e->scheme) == 0 && + lwc_string_isequal(scheme, e->scheme, + &match) == lwc_error_ok && + match == true && e->port == port) break; - d = e ? e : urldb_add_path_node(scheme, port, segment, - NULL, d); + d = e ? e : urldb_add_path_node(scheme, port, segment, NULL, d); if (!d) break; segment = slash + 1; } while (1); - free(buf); + free(path_query); if (d && !d->url) { /* Insert URL */ - d->url = strdup(url); - if (!d->url) - return NULL; - /** remove fragment */ - segment = strrchr(d->url, '#'); - if (segment) - *segment = '\0'; + if (nsurl_has_component(url, NSURL_FRAGMENT)) { + nserror err = nsurl_defragment(url, &d->url); + if (err != NSERROR_OK) + return NULL; + } else { + d->url = nsurl_ref(url); + } } return d; @@ -1811,7 +1829,7 @@ int urldb_add_path_fragment_cmp(const void *a, const void *b) * \return segment or NULL on memory exhaustion */ struct path_data *urldb_add_path_fragment(struct path_data *segment, - const char *fragment) + lwc_string *fragment) { char **temp; @@ -1829,7 +1847,8 @@ struct path_data *urldb_add_path_fragment(struct path_data *segment, return NULL; segment->fragment = temp; - segment->fragment[segment->frag_cnt] = strdup(fragment); + segment->fragment[segment->frag_cnt] = + strdup(lwc_string_data(fragment)); if (!segment->fragment[segment->frag_cnt]) { /* Don't free temp - it's now our buffer */ return NULL; @@ -1851,94 +1870,65 @@ struct path_data *urldb_add_path_fragment(struct path_data *segment, * \param url Absolute URL to find * \return Pointer to path data, or NULL if not found */ -struct path_data *urldb_find_url(const char *url) +struct path_data *urldb_find_url(nsurl *url) { const struct host_part *h; struct path_data *p; struct search_node *tree; - char *plq, *copy, *colon; - const char *host; - unsigned short port; - url_func_result ret; - struct url_components components; - int len = 0; + char *plq; + const char *host_str; + lwc_string *scheme, *host, *port; + size_t len = 0; + unsigned int port_int; + bool match; assert(url); - /* Extract url components */ - ret = url_get_components(url, &components); - if (ret != URL_FUNC_OK) + scheme = nsurl_get_component(url, NSURL_SCHEME); + if (scheme == NULL) return NULL; - /* Ensure scheme and authority exist */ - if (!(components.scheme && components.authority)) { - url_destroy_components(&components); - return NULL; - } + host = nsurl_get_component(url, NSURL_HOST); + if (host != NULL) { + host_str = lwc_string_data(host); + lwc_string_unref(host); - /* Extract host part from authority */ - host = strchr(components.authority, '@'); - if (!host) - host = components.authority; - else - host++; + } else if (lwc_string_isequal(scheme, corestring_lwc_file, &match) == + lwc_error_ok && match == true) { + host_str = "localhost"; - /* get port and remove from host */ - colon = strrchr(host, ':'); - if (!colon) { - port = 0; } else { - *colon = '\0'; - port = atoi(colon + 1); + lwc_string_unref(scheme); + return NULL; } - /* file urls have no host, so manufacture one */ - if (strcasecmp(components.scheme, "file") == 0) - host = "localhost"; - - tree = urldb_get_search_tree(host); - h = urldb_search_find(tree, host); + tree = urldb_get_search_tree(host_str); + h = urldb_search_find(tree, host_str); if (!h) { - url_destroy_components(&components); + lwc_string_unref(scheme); return NULL; } /* generate plq (path, leaf, query) */ - if (components.path) - len += strlen(components.path); - else - len += SLEN("/"); - - if (components.query) - len += strlen(components.query) + 1; - - plq = malloc(len + 1); - if (!plq) { - url_destroy_components(&components); + if (nsurl_get(url, NSURL_PATH | NSURL_QUERY, &plq, &len) != + NSERROR_OK) { + lwc_string_unref(scheme); return NULL; } - /* Ensure plq is terminated */ - *plq = '\0'; - - copy = plq; - if (components.path) { - strcpy(copy, components.path); - copy += strlen(components.path); + /* Get port */ + port = nsurl_get_component(url, NSURL_PORT); + if (port != NULL) { + port_int = atoi(lwc_string_data(port)); + lwc_string_unref(port); } else { - strcpy(copy, "/"); - copy += SLEN("/"); + port_int = 0; } - if (components.query) { - *copy++ = '?'; - strcpy(copy, components.query); - } - - p = urldb_match_path(&h->paths, plq, components.scheme, port); + p = urldb_match_path(&h->paths, plq, scheme, port_int); - url_destroy_components(&components); free(plq); + lwc_string_unref(scheme); return p; } @@ -1953,10 +1943,11 @@ struct path_data *urldb_find_url(const char *url) * \return Pointer to path data or NULL if not found. */ struct path_data *urldb_match_path(const struct path_data *parent, - const char *path, const char *scheme, unsigned short port) + const char *path, lwc_string *scheme, unsigned short port) { const struct path_data *p; const char *slash; + bool match; assert(parent != NULL); assert(parent->segment == NULL); @@ -1971,7 +1962,9 @@ struct path_data *urldb_match_path(const struct path_data *parent, slash = path + strlen(path); if (strncmp(p->segment, path + 1, slash - path - 1) == 0 && - strcmp(p->scheme, scheme) == 0 && + lwc_string_isequal(p->scheme, scheme, &match) == + lwc_error_ok && + match == true && p->port == port) { if (*slash == '\0') { /* Complete match */ @@ -2066,7 +2059,7 @@ void urldb_dump_paths(struct path_data *parent) do { if (p->segment != NULL) { - LOG(("\t%s : %u", p->scheme, p->port)); + LOG(("\t%s : %u", lwc_string_data(p->scheme), p->port)); LOG(("\t\t'%s'", p->segment)); @@ -2429,21 +2422,22 @@ struct search_node *urldb_search_split(struct search_node *root) * \param url URL being fetched * \return Cookies string for libcurl (on heap), or NULL on error/no cookies */ -char *urldb_get_cookie(const char *url) +char *urldb_get_cookie(nsurl *url) { const struct path_data *p, *q; const struct host_part *h; + lwc_string *path_lwc; struct cookie_internal_data *c; int count = 0, version = COOKIE_RFC2965; struct cookie_internal_data **matched_cookies; int matched_cookies_size = 20; int ret_alloc = 4096, ret_used = 1; - char *path; + const char *path; char *ret; - char *scheme; + lwc_string *scheme; time_t now; - url_func_result res; int i; + bool match; assert(url != NULL); @@ -2472,7 +2466,6 @@ char *urldb_get_cookie(const char *url) sizeof(struct cookie_internal_data *)); \ \ if (temp == NULL) { \ - free(path); \ free(ret); \ free(matched_cookies); \ return NULL; \ @@ -2491,12 +2484,14 @@ char *urldb_get_cookie(const char *url) ret[0] = '\0'; - res = url_path(url, &path); - if (res != URL_FUNC_OK) { + path_lwc = nsurl_get_component(url, NSURL_PATH); + if (path_lwc == NULL) { free(ret); free(matched_cookies); return NULL; } + path = lwc_string_data(path_lwc); + lwc_string_unref(path_lwc); now = time(NULL); @@ -2514,8 +2509,11 @@ char *urldb_get_cookie(const char *url) /* cookie has expired => ignore */ continue; - if (c->secure && strcasecmp( - q->scheme, "https")) + if (c->secure && lwc_string_isequal( + q->scheme, + corestring_lwc_https, + &match) && + match == false) /* secure cookie for insecure host. * ignore */ continue; @@ -2546,8 +2544,11 @@ char *urldb_get_cookie(const char *url) /* cookie has expired => ignore */ continue; - if (c->secure && strcasecmp( - q->scheme, "https")) + if (c->secure && lwc_string_isequal( + q->scheme, + corestring_lwc_https, + &match) && + match == false) /* Secure cookie for insecure server * => ignore */ continue; @@ -2587,7 +2588,10 @@ char *urldb_get_cookie(const char *url) /* paths don't match => ignore */ continue; - if (c->secure && strcasecmp(p->scheme, "https")) + if (c->secure && lwc_string_isequal(p->scheme, + corestring_lwc_https, + &match) && + match == false) /* Secure cookie for insecure server * => ignore */ continue; @@ -2618,7 +2622,10 @@ char *urldb_get_cookie(const char *url) /* paths don't match => ignore */ continue; - if (c->secure && strcasecmp(scheme, "https")) + if (c->secure && lwc_string_isequal(scheme, + corestring_lwc_https, + &match) && + match == false) /* secure cookie for insecure host. ignore */ continue; @@ -2636,7 +2643,6 @@ char *urldb_get_cookie(const char *url) if (count == 0) { /* No cookies found */ - free(path); free(ret); free(matched_cookies); return NULL; @@ -2651,7 +2657,6 @@ char *urldb_get_cookie(const char *url) for (i = 0; i < count; i++) { if (!urldb_concat_cookie(matched_cookies[i], version, &ret_used, &ret_alloc, &ret)) { - free(path); free(ret); free(matched_cookies); return NULL; @@ -2668,7 +2673,6 @@ char *urldb_get_cookie(const char *url) { char *temp = realloc(ret, ret_used); if (!temp) { - free(path); free(ret); free(matched_cookies); return NULL; @@ -2677,7 +2681,6 @@ char *urldb_get_cookie(const char *url) ret = temp; } - free(path); free(matched_cookies); return ret; @@ -2693,66 +2696,68 @@ char *urldb_get_cookie(const char *url) * \param referer Referring resource, or 0 for verifiable transaction * \return true on success, false otherwise */ -bool urldb_set_cookie(const char *header, const char *url, - const char *referer) +bool urldb_set_cookie(const char *header, nsurl *url, nsurl *referer) { const char *cur = header, *end; - char *path, *host, *scheme, *urlt; - url_func_result res; + lwc_string *path, *host, *scheme; + nsurl *urlt; + bool match; assert(url && header); - /* strip fragment */ - urlt = strdup(url); - if (!urlt) - return false; - - scheme = strchr(urlt, '#'); - if (scheme) - *scheme = '\0'; + /* Get defragmented URL, as 'urlt' */ + if (nsurl_has_component(url, NSURL_FRAGMENT)) { + if (nsurl_defragment(url, &urlt) != NSERROR_OK) + return NULL; + } else { + urlt = nsurl_ref(url); + } - res = url_scheme(url, &scheme); - if (res != URL_FUNC_OK) { - free(urlt); + scheme = nsurl_get_component(url, NSURL_SCHEME); + if (scheme == NULL) { + nsurl_unref(urlt); return false; } - res = url_path(url, &path); - if (res != URL_FUNC_OK) { - free(scheme); - free(urlt); + path = nsurl_get_component(url, NSURL_PATH); + if (path == NULL) { + lwc_string_unref(scheme); + nsurl_unref(urlt); return false; } - res = url_host(url, &host); - if (res != URL_FUNC_OK) { - free(path); - free(scheme); - free(urlt); + host = nsurl_get_component(url, NSURL_HOST); + if (host == NULL) { + lwc_string_unref(path); + lwc_string_unref(scheme); + nsurl_unref(urlt); return false; } if (referer) { - char *rhost; + lwc_string *rhost; /* Ensure that url's host name domain matches * referer's (4.3.5) */ - res = url_host(referer, &rhost); - if (res != URL_FUNC_OK) { + rhost = nsurl_get_component(url, NSURL_HOST); + if (rhost == NULL) { goto error; } /* Domain match host names */ - if (strcasecmp(host, rhost) != 0) { + if (lwc_string_isequal(host, rhost, &match) == lwc_error_ok && + match == false) { const char *hptr; const char *rptr; const char *dot; + const char *host_data = lwc_string_data(host); + const char *rhost_data = lwc_string_data(rhost); /* Ensure neither host nor rhost are IP addresses */ - if (url_host_is_ip_address(host) || - url_host_is_ip_address(rhost)) { + if (url_host_is_ip_address(host_data) || + url_host_is_ip_address(rhost_data)) { /* IP address, so no partial match */ - free(rhost); + lwc_string_unref(rhost); goto error; } @@ -2777,11 +2782,11 @@ bool urldb_set_cookie(const char *header, const char *url, * instead of just looking for embedded dots. */ - hptr = host + strlen(host) - 1; - rptr = rhost + strlen(rhost) - 1; + hptr = host_data + lwc_string_length(host) - 1; + rptr = rhost_data + lwc_string_length(rhost) - 1; /* 1 */ - while (hptr >= host && rptr >= rhost) { + while (hptr >= host_data && rptr >= rhost_data) { if (*hptr != *rptr) break; hptr--; @@ -2800,12 +2805,12 @@ bool urldb_set_cookie(const char *header, const char *url, if (*hptr == '\0' || (dot = strchr(hptr + 1, '.')) == NULL || *(dot + 1) == '\0') { - free(rhost); + lwc_string_unref(rhost); goto error; } } - free(rhost); + lwc_string_unref(rhost); } end = cur + strlen(cur) - 2 /* Trailing CRLF */; @@ -2813,6 +2818,7 @@ bool urldb_set_cookie(const char *header, const char *url, do { struct cookie_internal_data *c; char *dot; + size_t len; c = urldb_parse_cookie(url, &cur); if (!c) { @@ -2829,8 +2835,10 @@ bool urldb_set_cookie(const char *header, const char *url, } /* 4.3.2:i Cookie path must be a prefix of URL path */ - if (strlen(c->path) > strlen(path) || - strncmp(c->path, path, strlen(c->path)) != 0) { + len = strlen(c->path); + if (len > lwc_string_length(path) || + strncmp(c->path, lwc_string_data(path), + len) != 0) { urldb_free_cookie(c); goto error; } @@ -2844,7 +2852,7 @@ bool urldb_set_cookie(const char *header, const char *url, } /* Domain match fetch host with cookie domain */ - if (strcasecmp(host, c->domain) != 0) { + if (strcasecmp(lwc_string_data(host), c->domain) != 0) { int hlen, dlen; char *domain = c->domain; @@ -2863,13 +2871,13 @@ bool urldb_set_cookie(const char *header, const char *url, assert(c->domain[0] == '.'); /* 4.3.2:iii */ - if (url_host_is_ip_address(host)) { + if (url_host_is_ip_address(lwc_string_data(host))) { /* IP address, so no partial match */ urldb_free_cookie(c); goto error; } - hlen = strlen(host); + hlen = lwc_string_length(host); dlen = strlen(c->domain); if (hlen <= dlen && hlen != dlen - 1) { @@ -2885,7 +2893,8 @@ bool urldb_set_cookie(const char *header, const char *url, dlen--; } - if (strcasecmp(host + (hlen - dlen), domain)) { + if (strcasecmp(lwc_string_data(host) + (hlen - dlen), + domain)) { urldb_free_cookie(c); goto error; } @@ -2918,18 +2927,18 @@ bool urldb_set_cookie(const char *header, const char *url, goto error; } while (cur < end); - free(host); - free(path); - free(scheme); - free(urlt); + lwc_string_unref(host); + lwc_string_unref(path); + lwc_string_unref(scheme); + nsurl_unref(urlt); return true; error: - free(host); - free(path); - free(scheme); - free(urlt); + lwc_string_unref(host); + lwc_string_unref(path); + lwc_string_unref(scheme); + nsurl_unref(urlt); return false; } @@ -2941,7 +2950,7 @@ error: * \param cookie Pointer to cookie string (updated on exit) * \return Pointer to cookie structure (on heap, caller frees) or NULL */ -struct cookie_internal_data *urldb_parse_cookie(const char *url, +struct cookie_internal_data *urldb_parse_cookie(nsurl *url, const char **cookie) { struct cookie_internal_data *c; @@ -2953,7 +2962,6 @@ struct cookie_internal_data *urldb_parse_cookie(const char *url, bool value_verbatim = false; bool quoted = false; bool was_quoted = false; - url_func_result res; assert(url && cookie && *cookie); @@ -3145,40 +3153,50 @@ struct cookie_internal_data *urldb_parse_cookie(const char *url, /* Now fix-up default values */ if (c->domain == NULL) { - res = url_host(url, &c->domain); - if (res != URL_FUNC_OK) { + lwc_string *host = nsurl_get_component(url, NSURL_HOST); + if (host == NULL) { urldb_free_cookie(c); return NULL; } + c->domain = strdup(lwc_string_data(host)); + lwc_string_unref(host); } if (c->path == NULL) { - char *path; - char *slash; + const char *path_data; + char *path, *slash; + lwc_string *path_lwc; - res = url_path(url, &path); - if (res != URL_FUNC_OK) { + path_lwc = nsurl_get_component(url, NSURL_PATH); + if (path_lwc == NULL) { urldb_free_cookie(c); return NULL; } + path_data = lwc_string_data(path_lwc); /* Strip leafname and trailing slash (4.3.1) */ - slash = strrchr(path, '/'); + slash = strrchr(path_data, '/'); if (slash != NULL) { /* Special case: retain first slash in path */ - if (slash == path) + if (slash == path_data) slash++; - slash = strndup(path, slash - path); + slash = strndup(path_data, slash - path_data); if (slash == NULL) { - free(path); + lwc_string_unref(path_lwc); urldb_free_cookie(c); return NULL; } - free(path); - path = slash; + lwc_string_unref(path_lwc); + } else { + path = strdup(lwc_string_data(path_lwc)); + lwc_string_unref(path_lwc); + if (path == NULL) { + urldb_free_cookie(c); + return NULL; + } } c->path = path; @@ -3303,15 +3321,15 @@ bool urldb_parse_avpair(struct cookie_internal_data *c, char *n, char *v, * \param url URL (sans fragment) associated with cookie * \return true on success, false on memory exhaustion (c will be freed) */ -bool urldb_insert_cookie(struct cookie_internal_data *c, const char *scheme, - const char *url) +bool urldb_insert_cookie(struct cookie_internal_data *c, lwc_string *scheme, + nsurl *url) { struct cookie_internal_data *d; const struct host_part *h; struct path_data *p; time_t now = time(NULL); - assert(c && scheme && url); + assert(c); if (c->domain[0] == '.') { h = urldb_search_find( @@ -3327,6 +3345,10 @@ bool urldb_insert_cookie(struct cookie_internal_data *c, const char *scheme, p = (struct path_data *) &h->paths; } else { + /* Need to have a URL and scheme, if it's not a domain cookie */ + assert(url != NULL); + assert(scheme != NULL); + h = urldb_search_find( urldb_get_search_tree(c->domain), c->domain); @@ -3341,7 +3363,7 @@ bool urldb_insert_cookie(struct cookie_internal_data *c, const char *scheme, /* find path */ p = urldb_add_path(scheme, 0, h, - c->path, NULL, NULL, url); + strdup(c->path), NULL, url); if (!p) { urldb_free_cookie(c); return false; @@ -3705,10 +3727,34 @@ void urldb_load_cookies(const char *filename) break; } - /* And insert it into database */ - if (!urldb_insert_cookie(c, scheme, url)) { - /* Cookie freed for us */ - break; + if (c->domain[0] != '.') { + lwc_string *scheme_lwc = NULL; + nsurl *url_nsurl = NULL; + + assert(scheme[0] != 'u'); + + if (nsurl_create(url, &url_nsurl) != NSERROR_OK) { + urldb_free_cookie(c); + break; + } + scheme_lwc = nsurl_get_component(url_nsurl, + NSURL_SCHEME); + + /* And insert it into database */ + if (!urldb_insert_cookie(c, scheme_lwc, url_nsurl)) { + /* Cookie freed for us */ + nsurl_unref(url_nsurl); + lwc_string_unref(scheme_lwc); + break; + } + nsurl_unref(url_nsurl); + lwc_string_unref(scheme_lwc); + + } else { + if (!urldb_insert_cookie(c, NULL, NULL)) { + /* Cookie freed for us */ + break; + } } } @@ -3873,8 +3919,10 @@ void urldb_save_cookie_paths(FILE *fp, struct path_data *parent) (int)c->expires, (int)c->last_used, c->no_destroy, c->name, c->value, c->value_was_quoted, - p->scheme ? p->scheme : "unused", - p->url ? p->url : "unused", + p->scheme ? lwc_string_data(p->scheme) : + "unused", + p->url ? nsurl_access(p->url) : + "unused", c->comment ? c->comment : ""); } } @@ -3998,8 +4046,12 @@ void urldb_destroy_path_node_content(struct path_data *node) struct cookie_internal_data *a, *b; unsigned int i; - free(node->url); - free(node->scheme); + if (node->url != NULL) + nsurl_unref(node->url); + + if (node->scheme != NULL) + lwc_string_unref(node->scheme); + free(node->segment); for (i = 0; i < node->frag_cnt; i++) free(node->fragment[i]); @@ -4039,7 +4091,7 @@ void urldb_destroy_cookie(struct cookie_internal_data *c) */ void urldb_destroy_prot_space(struct prot_space_data *space) { - free(space->scheme); + lwc_string_unref(space->scheme); free(space->realm); free(space->auth); diff --git a/content/urldb.h b/content/urldb.h index bbf378332..00af8e312 100644 --- a/content/urldb.h +++ b/content/urldb.h @@ -27,6 +27,7 @@ #include <time.h> #include "content/content.h" #include "content/content_type.h" +#include "utils/nsurl.h" typedef enum { COOKIE_NETSCAPE = 0, @@ -69,44 +70,43 @@ void urldb_destroy(void); /* Persistence support */ void urldb_load(const char *filename); void urldb_save(const char *filename); -void urldb_set_url_persistence(const char *url, bool persist); +void urldb_set_url_persistence(nsurl *url, bool persist); /* URL insertion */ -bool urldb_add_url(const char *url); +bool urldb_add_url(nsurl *url); struct host_part *urldb_add_host(const char *host); -struct path_data *urldb_add_path(const char *scheme, - unsigned int port, const struct host_part *host, - const char *path, const char *query, const char *fragment, - const char *url); +struct path_data *urldb_add_path(lwc_string *scheme, unsigned int port, + const struct host_part *host, char *path_query, + lwc_string *fragment, nsurl *url); /* URL data modification / lookup */ -void urldb_set_url_title(const char *url, const char *title); -void urldb_set_url_content_type(const char *url, content_type type); -void urldb_update_url_visit_data(const char *url); -void urldb_reset_url_visit_data(const char *url); -const struct url_data *urldb_get_url_data(const char *url); -const char *urldb_get_url(const char *url); +void urldb_set_url_title(nsurl *url, const char *title); +void urldb_set_url_content_type(nsurl *url, content_type type); +void urldb_update_url_visit_data(nsurl *url); +void urldb_reset_url_visit_data(nsurl *url); +const struct url_data *urldb_get_url_data(nsurl *url); +nsurl *urldb_get_url(nsurl *url); /* Authentication modification / lookup */ -void urldb_set_auth_details(const char *url, const char *realm, +void urldb_set_auth_details(nsurl *url, const char *realm, const char *auth); -const char *urldb_get_auth_details(const char *url, const char *realm); +const char *urldb_get_auth_details(nsurl *url, const char *realm); /* SSL certificate permissions */ -void urldb_set_cert_permissions(const char *url, bool permit); -bool urldb_get_cert_permissions(const char *url); +void urldb_set_cert_permissions(nsurl *url, bool permit); +bool urldb_get_cert_permissions(nsurl *url); /* Thumbnail handling */ -void urldb_set_thumbnail(const char *url, struct bitmap *bitmap); -struct bitmap *urldb_get_thumbnail(const char *url); +void urldb_set_thumbnail(nsurl *url, struct bitmap *bitmap); +struct bitmap *urldb_get_thumbnail(nsurl *url); /* URL completion */ void urldb_iterate_partial(const char *prefix, - bool (*callback)(const char *url, + bool (*callback)(nsurl *url, const struct url_data *data)); /* Iteration */ -void urldb_iterate_entries(bool (*callback)(const char *url, +void urldb_iterate_entries(bool (*callback)(nsurl *url, const struct url_data *data)); void urldb_iterate_cookies(bool (*callback)(const struct cookie_data *cookie)); @@ -114,9 +114,8 @@ void urldb_iterate_cookies(bool (*callback)(const struct cookie_data *cookie)); void urldb_dump(void); /* Cookies */ -bool urldb_set_cookie(const char *header, const char *url, - const char *referer); -char *urldb_get_cookie(const char *url); +bool urldb_set_cookie(const char *header, nsurl *url, nsurl *referer); +char *urldb_get_cookie(nsurl *url); void urldb_delete_cookie(const char *domain, const char *path, const char *name); void urldb_load_cookies(const char *filename); void urldb_save_cookies(const char *filename); diff --git a/desktop/401login.h b/desktop/401login.h index dec3fa5e1..1c8140bae 100644 --- a/desktop/401login.h +++ b/desktop/401login.h @@ -22,9 +22,10 @@ #include <stdbool.h> #include "utils/config.h" +#include "utils/nsurl.h" #include "utils/errors.h" -void gui_401login_open(const char *url, const char *realm, +void gui_401login_open(nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw); #endif diff --git a/desktop/browser.c b/desktop/browser.c index 33d16cd8d..46fd14b8d 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1266,7 +1266,7 @@ nserror browser_window_callback(hlcache_handle *c, /* history */ if (bw->history_add && bw->history) { - const char *url = nsurl_access(hlcache_handle_get_url(c)); + nsurl *url = hlcache_handle_get_url(c); history_add(bw->history, c, bw->frag_id == NULL ? NULL : lwc_string_data(bw->frag_id)); diff --git a/desktop/browser.h b/desktop/browser.h index a78735806..f3c68fa09 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -324,7 +324,7 @@ void browser_window_debug_dump(struct browser_window *bw, FILE *f); void hotlist_visited(struct hlcache_handle *c); /* In platform specific global_history.c. */ -void global_history_add(const char *url); +void global_history_add(nsurl *url); /* In platform specific theme_install.c. */ #ifdef WITH_THEME_INSTALL diff --git a/desktop/gui.h b/desktop/gui.h index aa3fc8191..48684c3c5 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -133,7 +133,7 @@ void gui_launch_url(const char *url); struct ssl_cert_info; -void gui_cert_verify(const char *url, const struct ssl_cert_info *certs, +void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); diff --git a/desktop/history_core.c b/desktop/history_core.c index 21e402f1e..177de6b29 100644 --- a/desktop/history_core.c +++ b/desktop/history_core.c @@ -227,6 +227,7 @@ void history_add(struct history *history, hlcache_handle *content, const char *frag_id) { struct history_entry *entry; + nsurl *nsurl = hlcache_handle_get_url(content); char *url; char *title; struct bitmap *bitmap; @@ -242,8 +243,7 @@ void history_add(struct history *history, hlcache_handle *content, return; /* TODO: use a nsurl? */ - error = nsurl_get(hlcache_handle_get_url(content), NSURL_WITH_FRAGMENT, - &url, &url_len); + error = nsurl_get(nsurl, NSURL_WITH_FRAGMENT, &url, &url_len); if (error != NSERROR_OK) { warn_user("NoMemory", 0); free(entry); @@ -281,7 +281,7 @@ void history_add(struct history *history, hlcache_handle *content, /* if we have a thumbnail, don't update until the page has finished * loading */ - bitmap = urldb_get_thumbnail(url); + bitmap = urldb_get_thumbnail(nsurl); if (!bitmap) { bitmap = bitmap_create(WIDTH, HEIGHT, BITMAP_NEW | BITMAP_CLEAR_MEMORY | @@ -290,7 +290,7 @@ void history_add(struct history *history, hlcache_handle *content, warn_user("NoMemory", 0); return; } - if (thumbnail_create(content, bitmap, url) == false) { + if (thumbnail_create(content, bitmap, nsurl) == false) { /* Thumbnailing failed. Ignore it silently */ bitmap_destroy(bitmap); bitmap = NULL; @@ -329,7 +329,7 @@ void history_update(struct history *history, hlcache_handle *content) free(history->current->page.title); history->current->page.title = title; - thumbnail_create(content, history->current->bitmap, 0); + thumbnail_create(content, history->current->bitmap, NULL); } diff --git a/desktop/history_global_core.c b/desktop/history_global_core.c index a73bd7c2b..de67bf869 100644 --- a/desktop/history_global_core.c +++ b/desktop/history_global_core.c @@ -94,8 +94,7 @@ static struct node *history_global_find(const char *url) * \param data URL data associated with URL * \return true (for urldb_iterate_entries) */ -static bool global_history_add_internal(const char *url, - const struct url_data *data) +static bool global_history_add_internal(nsurl *url, const struct url_data *data) { int i, j; struct node *parent = NULL; @@ -143,7 +142,7 @@ static bool global_history_add_internal(const char *url, /* find any previous occurance */ if (global_history_initialised == false) { - node = history_global_find(url); + node = history_global_find(nsurl_access(url)); if (node != NULL) { tree_update_URL_node(global_history_tree, node, url, data); @@ -327,7 +326,7 @@ void history_global_cleanup(void) * * \param url the url to be added */ -void global_history_add(const char *url) +void global_history_add(nsurl *url) { const struct url_data *data; diff --git a/desktop/hotlist.c b/desktop/hotlist.c index 788722d20..b6eac3634 100644 --- a/desktop/hotlist.c +++ b/desktop/hotlist.c @@ -58,7 +58,7 @@ static const struct { #define HOTLIST_ENTRIES_COUNT (sizeof(hotlist_default_entries) / sizeof(hotlist_default_entries[0])) static node_callback_resp hotlist_node_callback(void *user_data, - struct node_msg_data *msg_data) + struct node_msg_data *msg_data) { struct node *node = msg_data->node; const char *text; @@ -116,7 +116,8 @@ static node_callback_resp hotlist_node_callback(void *user_data, } /* exported interface documented in hotlist.h */ -bool hotlist_initialise(struct tree *tree, const char *hotlist_path, const char* folder_icon_name) +bool hotlist_initialise(struct tree *tree, const char *hotlist_path, + const char* folder_icon_name) { struct node *node; const struct url_data *url_data; @@ -137,10 +138,8 @@ bool hotlist_initialise(struct tree *tree, const char *hotlist_path, const char* hotlist_tree = tree; hotlist_tree_root = tree_get_root(hotlist_tree); - if (tree_urlfile_load(hotlist_path, - hotlist_tree, - hotlist_node_callback, - NULL)) { + if (tree_urlfile_load(hotlist_path, hotlist_tree, + hotlist_node_callback, NULL)) { return true; } @@ -153,7 +152,7 @@ bool hotlist_initialise(struct tree *tree, const char *hotlist_path, const char* return false; } node = tree_create_folder_node(hotlist_tree, hotlist_tree_root, - name, true, false, false); + name, true, false, false); if (node == NULL) { free(name); return false; @@ -163,24 +162,24 @@ bool hotlist_initialise(struct tree *tree, const char *hotlist_path, const char* tree_set_node_icon(hotlist_tree, node, folder_icon); for (hlst_loop = 0; hlst_loop != HOTLIST_ENTRIES_COUNT; hlst_loop++) { - url_data = urldb_get_url_data(hotlist_default_entries[hlst_loop].url); + nsurl *url; + if (nsurl_create(hotlist_default_entries[hlst_loop].url, + &url) != NSERROR_OK) { + return false; + } + url_data = urldb_get_url_data(url); if (url_data == NULL) { - urldb_add_url(hotlist_default_entries[hlst_loop].url); - urldb_set_url_persistence( - hotlist_default_entries[hlst_loop].url, - true); - url_data = urldb_get_url_data( - hotlist_default_entries[hlst_loop].url); + urldb_add_url(url); + urldb_set_url_persistence(url, true); + url_data = urldb_get_url_data(url); } if (url_data != NULL) { - tree_create_URL_node(hotlist_tree, node, - hotlist_default_entries[hlst_loop].url, + tree_create_URL_node(hotlist_tree, node, url, messages_get(hotlist_default_entries[hlst_loop].msg_key), hotlist_node_callback, NULL); - tree_update_URL_node(hotlist_tree, node, - hotlist_default_entries[hlst_loop].url, - url_data); + tree_update_URL_node(hotlist_tree, node, url, url_data); } + nsurl_unref(url); } return true; @@ -221,21 +220,22 @@ static void hotlist_visited_internal(hlcache_handle *content, struct node *node) struct node *child; const char *text; const char *url; + nsurl *nsurl; if (content == NULL || hlcache_handle_get_url(content) == NULL || hotlist_tree == NULL) return; - /* TODO: do this with a nsurl instead */ - url = nsurl_access(hlcache_handle_get_url(content)); + nsurl = hlcache_handle_get_url(content); + url = nsurl_access(nsurl); for (; node; node = tree_node_get_next(node)) { if (!tree_node_is_folder(node)) { text = tree_url_node_get_url(node); if (strcmp(text, url) == 0) { tree_update_URL_node(hotlist_tree, node, - url, NULL); + nsurl, NULL); } } child = tree_node_get_child(node); @@ -416,6 +416,7 @@ void hotlist_add_entry(bool selected) struct node *node; struct node *parent = NULL; creating_node = true; + nsurl *url; if (selected == true) { parent = tree_get_selected_node(tree_get_root(hotlist_tree)); @@ -428,8 +429,12 @@ void hotlist_add_entry(bool selected) parent = tree_get_default_folder_node(hotlist_tree); } - node = tree_create_URL_node(hotlist_tree, parent, "Address", - "Untitled", hotlist_node_callback, NULL); + if (nsurl_create("http://netsurf-browser.org/", &url) != NSERROR_OK) + return; + node = tree_create_URL_node(hotlist_tree, parent, url, "Untitled", + hotlist_node_callback, NULL); + + nsurl_unref(url); if (node == NULL) return; @@ -444,17 +449,23 @@ void hotlist_add_page(const char *url) { const struct url_data *data; struct node *node, *parent; + nsurl *nsurl; if (url == NULL) return; - data = urldb_get_url_data(url); + + if (nsurl_create(url, &nsurl) != NSERROR_OK) + return; + + data = urldb_get_url_data(nsurl); if (data == NULL) return; parent = tree_get_default_folder_node(hotlist_tree); - node = tree_create_URL_node(hotlist_tree, parent, url, NULL, - hotlist_node_callback, NULL); - tree_update_URL_node(hotlist_tree, node, url, data); + node = tree_create_URL_node(hotlist_tree, parent, nsurl, NULL, + hotlist_node_callback, NULL); + tree_update_URL_node(hotlist_tree, node, nsurl, data); + nsurl_unref(nsurl); } /** @@ -468,19 +479,27 @@ void hotlist_add_page_xy(const char *url, int x, int y) const struct url_data *data; struct node *link, *node; bool before; + nsurl *nsurl; + + if (url == NULL) + return; + + if (nsurl_create(url, &nsurl) != NSERROR_OK) + return; - data = urldb_get_url_data(url); + data = urldb_get_url_data(nsurl); if (data == NULL) { - urldb_add_url(url); - urldb_set_url_persistence(url, true); - data = urldb_get_url_data(url); + urldb_add_url(nsurl); + urldb_set_url_persistence(nsurl, true); + data = urldb_get_url_data(nsurl); } if (data != NULL) { link = tree_get_link_details(hotlist_tree, x, y, &before); - node = tree_create_URL_node(NULL, NULL, url, + node = tree_create_URL_node(NULL, NULL, nsurl, NULL, hotlist_node_callback, NULL); tree_link_node(hotlist_tree, link, node, before); } + nsurl_unref(nsurl); } /** diff --git a/desktop/netsurf.c b/desktop/netsurf.c index d2010d80b..65765fae4 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -94,15 +94,14 @@ static nserror netsurf_llcache_query_handler(const llcache_query *query, { switch (query->type) { case LLCACHE_QUERY_AUTH: - gui_401login_open(nsurl_access(query->url), - query->data.auth.realm, cb, cbpw); + gui_401login_open(query->url, query->data.auth.realm, cb, cbpw); break; case LLCACHE_QUERY_REDIRECT: /** \todo Need redirect query dialog */ /* For now, do nothing, as this query type isn't emitted yet */ break; case LLCACHE_QUERY_SSL: - gui_cert_verify(nsurl_access(query->url), query->data.ssl.certs, + gui_cert_verify(query->url, query->data.ssl.certs, query->data.ssl.num, cb, cbpw); break; } diff --git a/desktop/sslcert.c b/desktop/sslcert.c index d63d3a2eb..b7a424465 100644 --- a/desktop/sslcert.c +++ b/desktop/sslcert.c @@ -34,6 +34,7 @@ #include "desktop/tree.h" #include "utils/log.h" #include "utils/messages.h" +#include "utils/nsurl.h" #include "utils/utils.h" /** Flags for each type of ssl tree node. */ @@ -49,7 +50,7 @@ enum tree_element_ssl { /** ssl certificate verification context. */ struct sslcert_session_data { unsigned long num; /**< The number of ssl certificates in the chain */ - char *url; /**< The url of the certificate */ + nsurl *url; /**< The url of the certificate */ struct tree *tree; /**< The root of the treeview */ llcache_query_response cb; /**< callback when cert is accepted or rejected */ void *cbpw; /**< context passed to callback */ @@ -84,7 +85,7 @@ void sslcert_cleanup(void) struct sslcert_session_data * sslcert_create_session_data(unsigned long num, - const char *url, + nsurl *url, llcache_query_response cb, void *cbpw) { @@ -95,7 +96,7 @@ sslcert_create_session_data(unsigned long num, warn_user("NoMemory", 0); return NULL; } - data->url = strdup(url); + data->url = nsurl_ref(url); if (data->url == NULL) { free(data); warn_user("NoMemory", 0); @@ -246,7 +247,9 @@ static void sslcert_cleanup_session(struct sslcert_session_data *session) { assert(session != NULL); - free(session->url); + if (session->url) + nsurl_unref(session->url); + free(session); } diff --git a/desktop/sslcert.h b/desktop/sslcert.h index 8fe534846..a9a2587fc 100644 --- a/desktop/sslcert.h +++ b/desktop/sslcert.h @@ -31,7 +31,7 @@ unsigned int sslcert_get_tree_flags(void); void sslcert_cleanup(void); struct sslcert_session_data *sslcert_create_session_data(unsigned long num, - const char *url, llcache_query_response cb, void *cbpw); + nsurl *url, llcache_query_response cb, void *cbpw); bool sslcert_load_tree(struct tree *tree, const struct ssl_cert_info *certs, struct sslcert_session_data *data); diff --git a/desktop/thumbnail.h b/desktop/thumbnail.h index 655c25339..05bae7abc 100644 --- a/desktop/thumbnail.h +++ b/desktop/thumbnail.h @@ -24,6 +24,7 @@ #define _NETSURF_DESKTOP_THUMBNAIL_H_ #include <stdbool.h> +#include "utils/nsurl.h" #include "utils/types.h" struct hlcache_handle; @@ -52,6 +53,6 @@ bool thumbnail_redraw(struct hlcache_handle *content, /* In platform specific thumbnail.c. */ bool thumbnail_create(struct hlcache_handle *content, struct bitmap *bitmap, - const char *url); + nsurl *url); #endif diff --git a/desktop/tree_url_node.c b/desktop/tree_url_node.c index d477249c9..a69a1375e 100644 --- a/desktop/tree_url_node.c +++ b/desktop/tree_url_node.c @@ -126,14 +126,14 @@ void tree_url_node_cleanup() * \return the node created, or NULL for failure */ struct node *tree_create_URL_node(struct tree *tree, struct node *parent, - const char *url, const char *title, + nsurl *url, const char *title, tree_node_user_callback user_callback, void *callback_data) { struct node *node; struct node_element *element; char *text_cp, *squashed; - squashed = squash_whitespace(title ? title : url); + squashed = squash_whitespace(title ? title : nsurl_access(url)); text_cp = strdup(squashed); if (text_cp == NULL) { LOG(("malloc failed")); @@ -161,7 +161,7 @@ struct node *tree_create_URL_node(struct tree *tree, struct node *parent, element = tree_create_node_element(node, NODE_ELEMENT_TEXT, TREE_ELEMENT_URL, true); if (element != NULL) { - text_cp = strdup(url); + text_cp = strdup(nsurl_access(url)); if (text_cp == NULL) { tree_delete_node(tree, node, false); LOG(("malloc failed")); @@ -184,7 +184,7 @@ struct node *tree_create_URL_node(struct tree *tree, struct node *parent, * \return the node created, or NULL for failure */ struct node *tree_create_URL_node_readonly(struct tree *tree, - struct node *parent, const char *url, + struct node *parent, nsurl *url, const struct url_data *data, tree_node_user_callback user_callback, void *callback_data) { @@ -197,7 +197,7 @@ struct node *tree_create_URL_node_readonly(struct tree *tree, if (data->title != NULL) { title = strdup(data->title); } else { - title = strdup(url); + title = strdup(nsurl_access(url)); } if (title == NULL) @@ -223,7 +223,8 @@ struct node *tree_create_URL_node_readonly(struct tree *tree, element = tree_create_node_element(node, NODE_ELEMENT_TEXT, TREE_ELEMENT_URL, false); if (element != NULL) { - tree_update_node_element(tree, element, url, NULL); + tree_update_node_element(tree, element, nsurl_access(url), + NULL); } tree_update_URL_node(tree, node, url, data); @@ -238,7 +239,7 @@ struct node *tree_create_URL_node_readonly(struct tree *tree, * \param node the node to update */ void tree_update_URL_node(struct tree *tree, struct node *node, - const char *url, const struct url_data *data) + nsurl *url, const struct url_data *data) { struct node_element *element; struct bitmap *bitmap = NULL; @@ -253,7 +254,7 @@ void tree_update_URL_node(struct tree *tree, struct node *node, if (data != NULL) { if (data->title == NULL) - urldb_set_url_title(url, url); + urldb_set_url_title(url, nsurl_access(url)); if (data->title == NULL) return; @@ -367,8 +368,13 @@ node_callback_resp tree_url_node_callback(void *user_data, */ case TREE_ELEMENT_URL: /* reset URL characteristics */ - urldb_reset_url_visit_data( - msg_data->data.text); + error = nsurl_create(msg_data->data.text, &nsurl); + if (error != NSERROR_OK) { + warn_user("NoMemory", 0); + return NODE_CALLBACK_REJECT; + } + urldb_reset_url_visit_data(nsurl); + nsurl_unref(nsurl); return NODE_CALLBACK_HANDLED; case TREE_ELEMENT_TITLE: return NODE_CALLBACK_HANDLED; @@ -386,7 +392,7 @@ node_callback_resp tree_url_node_callback(void *user_data, text = tree_node_element_get_text(element); if (msg_data->flag == TREE_ELEMENT_LAUNCH_IN_TABS) { msg_data->data.bw = browser_window_create(text, - msg_data->data.bw, 0, true, true); + msg_data->data.bw, 0, true, true); } else { browser_window_create(text, NULL, 0, true, false); @@ -407,7 +413,6 @@ node_callback_resp tree_url_node_callback(void *user_data, } error = nsurl_get(nsurl, NSURL_WITH_FRAGMENT, &norm_text, &len); - nsurl_unref(nsurl); if (error != NSERROR_OK) { warn_user("NoMemory", 0); return NODE_CALLBACK_REJECT; @@ -415,18 +420,20 @@ node_callback_resp tree_url_node_callback(void *user_data, msg_data->data.text = norm_text; - data = urldb_get_url_data(norm_text); + data = urldb_get_url_data(nsurl); if (data == NULL) { - urldb_add_url(norm_text); - urldb_set_url_persistence(norm_text, - true); - data = urldb_get_url_data(norm_text); - if (data == NULL) + urldb_add_url(nsurl); + urldb_set_url_persistence(nsurl, true); + data = urldb_get_url_data(nsurl); + if (data == NULL) { + nsurl_unref(nsurl); return NODE_CALLBACK_REJECT; + } } tree = user_data; tree_update_URL_node(tree, msg_data->node, - norm_text, NULL); + nsurl, NULL); + nsurl_unref(nsurl); } else if (msg_data->flag == TREE_ELEMENT_TITLE) { while (isspace(*text)) @@ -529,12 +536,12 @@ static void tree_url_load_entry(xmlNode *li, struct tree *tree, /* No longer need this */ xmlFree(url1); - data = urldb_get_url_data(nsurl_access(url)); + data = urldb_get_url_data(url); if (data == NULL) { /* No entry in database, so add one */ - urldb_add_url(nsurl_access(url)); + urldb_add_url(url); /* now attempt to get url data */ - data = urldb_get_url_data(nsurl_access(url)); + data = urldb_get_url_data(url); } if (data == NULL) { xmlFree(title); @@ -544,19 +551,19 @@ static void tree_url_load_entry(xmlNode *li, struct tree *tree, } /* Make this URL persistent */ - urldb_set_url_persistence(nsurl_access(url), true); + urldb_set_url_persistence(url, true); /* Force the title in the hotlist */ - urldb_set_url_title(nsurl_access(url), title); + urldb_set_url_title(url, title); - entry = tree_create_URL_node(tree, directory, nsurl_access(url), title, + entry = tree_create_URL_node(tree, directory, url, title, callback, callback_data); if (entry == NULL) { /** \todo why isn't this fatal? */ warn_user("NoMemory", 0); } else { - tree_update_URL_node(tree, entry, nsurl_access(url), data); + tree_update_URL_node(tree, entry, url, data); } diff --git a/desktop/tree_url_node.h b/desktop/tree_url_node.h index 1fa89cdba..1f0231df1 100644 --- a/desktop/tree_url_node.h +++ b/desktop/tree_url_node.h @@ -26,20 +26,21 @@ #include "desktop/tree.h" +#include "utils/nsurl.h" struct url_data; void tree_url_node_init(const char *folder_icon_name); void tree_url_node_cleanup(void); struct node *tree_create_URL_node(struct tree *tree, - struct node *parent, const char *url, const char *title, + struct node *parent, nsurl *url, const char *title, tree_node_user_callback, void *callback_data); struct node *tree_create_URL_node_readonly(struct tree *tree, - struct node *parent, const char *url, + struct node *parent, nsurl *url, const struct url_data *data, tree_node_user_callback, void *callback_data); -void tree_update_URL_node(struct tree *tree,struct node *node, - const char *url, const struct url_data *data); +void tree_update_URL_node(struct tree *tree, struct node *node, + nsurl *url, const struct url_data *data); const char *tree_url_node_get_title(struct node *node); const char *tree_url_node_get_url(struct node *node); void tree_url_node_edit_title(struct tree *tree, struct node *node); diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 3bcc1be57..b8bb5cede 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1799,7 +1799,7 @@ gui_launch_url(const char *url) } void -gui_cert_verify(const char *url, +gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), diff --git a/framebuffer/login.c b/framebuffer/login.c index c1afab350..7a5e195f4 100644 --- a/framebuffer/login.c +++ b/framebuffer/login.c @@ -18,7 +18,7 @@ #include "desktop/401login.h" -void gui_401login_open(const char *url, const char *realm, +void gui_401login_open(nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw) { cb(false, cbpw); diff --git a/framebuffer/thumbnail.c b/framebuffer/thumbnail.c index 1729d7775..53ff33609 100644 --- a/framebuffer/thumbnail.c +++ b/framebuffer/thumbnail.c @@ -32,7 +32,7 @@ bool thumbnail_create(struct hlcache_handle *content, struct bitmap *bitmap, - const char *url) + nsurl *url) { nsfb_t *tbm = (nsfb_t *)bitmap; /* target bitmap */ nsfb_t *bm; /* temporary bitmap */ diff --git a/gtk/completion.c b/gtk/completion.c index 8782c876e..d249db160 100644 --- a/gtk/completion.c +++ b/gtk/completion.c @@ -26,7 +26,7 @@ GtkListStore *nsgtk_completion_list; static void nsgtk_completion_empty(void); -static bool nsgtk_completion_udb_callback(const char *url, +static bool nsgtk_completion_udb_callback(nsurl *url, const struct url_data *data); void nsgtk_completion_init(void) @@ -56,13 +56,14 @@ void nsgtk_completion_empty(void) gtk_list_store_clear(nsgtk_completion_list); } -bool nsgtk_completion_udb_callback(const char *url, const struct url_data *data) +bool nsgtk_completion_udb_callback(nsurl *url, const struct url_data *data) { GtkTreeIter iter; if (data->visits != 0) { gtk_list_store_append(nsgtk_completion_list, &iter); - gtk_list_store_set(nsgtk_completion_list, &iter, 0, url, -1); + gtk_list_store_set(nsgtk_completion_list, &iter, 0, + nsurl_access(url), -1); } return true; } @@ -702,7 +702,7 @@ void die(const char * const error) } -void gui_cert_verify(const char *url, const struct ssl_cert_info *certs, +void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { diff --git a/gtk/login.c b/gtk/login.c index 41f66de20..3b8d68254 100644 --- a/gtk/login.c +++ b/gtk/login.c @@ -35,8 +35,8 @@ #include "utils/utils.h" struct session_401 { - char *url; /**< URL being fetched */ - char *host; /**< Host for user display */ + nsurl *url; /**< URL being fetched */ + lwc_string *host; /**< Host for user display */ char *realm; /**< Authentication realm */ nserror (*cb)(bool proceed, void *pw); /**< Continuation callback */ void *cbpw; /**< Continuation data */ @@ -46,7 +46,7 @@ struct session_401 { GtkEntry *pass; /**< Widget with password */ }; -static void create_login_window(const char *url, const char *host, +static void create_login_window(nsurl *url, lwc_string *host, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw); static void destroy_login_window(struct session_401 *session); @@ -54,21 +54,20 @@ static void nsgtk_login_next(GtkWidget *w, gpointer data); static void nsgtk_login_ok_clicked(GtkButton *w, gpointer data); static void nsgtk_login_cancel_clicked(GtkButton *w, gpointer data); -void gui_401login_open(const char *url, const char *realm, +void gui_401login_open(nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw) { - char *host; - url_func_result res; + lwc_string *host; - res = url_host(url, &host); - assert(res == URL_FUNC_OK); + host = nsurl_get_component(url, NSURL_HOST); + assert(host != NULL); create_login_window(url, host, realm, cb, cbpw); - free(host); + lwc_string_unref(host); } -void create_login_window(const char *url, const char *host, const char *realm, +void create_login_window(nsurl *url, lwc_string *host, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw) { struct session_401 *session; @@ -101,8 +100,8 @@ void create_login_window(const char *url, const char *host, const char *realm, /* create and fill in our session structure */ session = calloc(1, sizeof(struct session_401)); - session->url = strdup(url); - session->host = strdup(host); + session->url = nsurl_ref(url); + session->host = lwc_string_ref(host); session->realm = strdup(realm ? realm : "Secure Area"); session->cb = cb; session->cbpw = cbpw; @@ -113,7 +112,7 @@ void create_login_window(const char *url, const char *host, const char *realm, /* fill in our new login window */ - gtk_label_set_text(GTK_LABEL(lhost), host); + gtk_label_set_text(GTK_LABEL(lhost), lwc_string_data(host)); gtk_label_set_text(lrealm, realm); gtk_entry_set_text(euser, ""); gtk_entry_set_text(epass, ""); @@ -145,8 +144,8 @@ void create_login_window(const char *url, const char *host, const char *realm, void destroy_login_window(struct session_401 *session) { - free(session->url); - free(session->host); + nsurl_unref(session->url); + lwc_string_unref(session->host); free(session->realm); gtk_widget_destroy(GTK_WIDGET(session->wnd)); g_object_unref(G_OBJECT(session->x)); diff --git a/gtk/thumbnail.c b/gtk/thumbnail.c index b09b8dd2f..19c5fc193 100644 --- a/gtk/thumbnail.c +++ b/gtk/thumbnail.c @@ -50,7 +50,7 @@ * \param url the URL the thumnail belongs to, or NULL */ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, - const char *url) + nsurl *url) { cairo_surface_t *dsurface = bitmap->surface; cairo_surface_t *surface; @@ -121,7 +121,7 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, /* register the thumbnail with the URL */ if (url) - urldb_set_thumbnail(url, bitmap); + urldb_set_thumbnail(url, bitmap); return true; } diff --git a/monkey/401login.c b/monkey/401login.c index a079ef30d..b2bff3182 100644 --- a/monkey/401login.c +++ b/monkey/401login.c @@ -25,7 +25,7 @@ typedef struct monkey401 { struct monkey401 *r_next, *r_prev; uint32_t num; - char *host; /* Ignore */ + lwc_string *host; /* Ignore */ nserror (*cb)(bool,void*); void *pw; } monkey401_t; @@ -33,7 +33,7 @@ typedef struct monkey401 { static monkey401_t *m4_ring = NULL; static uint32_t m4_ctr = 0; -void gui_401login_open(const char *url, const char *realm, +void gui_401login_open(nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw) { monkey401_t *m4t = calloc(sizeof(*m4t), 1); @@ -46,7 +46,7 @@ void gui_401login_open(const char *url, const char *realm, RING_INSERT(m4_ring, m4t); fprintf(stdout, "401LOGIN OPEN M4 %u URL %s REALM %s\n", - m4t->num, url, realm); + m4t->num, nsurl_access(url), realm); } diff --git a/monkey/cert.c b/monkey/cert.c index 265a32678..d7f44d11e 100644 --- a/monkey/cert.c +++ b/monkey/cert.c @@ -34,7 +34,7 @@ static monkey_cert_t *cert_ring = NULL; static uint32_t cert_ctr = 0; void -gui_cert_verify(const char *url, const struct ssl_cert_info *certs, +gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { @@ -48,7 +48,7 @@ gui_cert_verify(const char *url, const struct ssl_cert_info *certs, RING_INSERT(cert_ring, m4t); fprintf(stdout, "SSLCERT VERIFY CERT %u URL %s\n", - m4t->num, url); + m4t->num, nsurl_access(url)); } diff --git a/monkey/thumbnail.c b/monkey/thumbnail.c index 7a237bba6..334889510 100644 --- a/monkey/thumbnail.c +++ b/monkey/thumbnail.c @@ -20,12 +20,12 @@ #include "desktop/thumbnail.h" bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, - const char *url) + nsurl *url) { struct gui_window *win = monkey_find_window_by_content(content); if (win == NULL) { - fprintf(stdout, "GENERIC THUMBNAIL URL %s\n", url); + fprintf(stdout, "GENERIC THUMBNAIL URL %s\n", nsurl_access(url)); } - fprintf(stdout, "WINDOW THUMBNAIL WIN %u URL %s\n", win->win_num, url); + fprintf(stdout, "WINDOW THUMBNAIL WIN %u URL %s\n", win->win_num, nsurl_access(url)); return false; } diff --git a/riscos/401login.c b/riscos/401login.c index a81a20e3d..6740f54e5 100644 --- a/riscos/401login.c +++ b/riscos/401login.c @@ -45,17 +45,17 @@ static void ro_gui_401login_close(wimp_w w); static bool ro_gui_401login_apply(wimp_w w); -static void ro_gui_401login_open(const char *url, const char *host, +static void ro_gui_401login_open(nsurl *url, lwc_string *host, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw); static wimp_window *dialog_401_template; struct session_401 { - char *host; /**< Host for user display */ + lwc_string *host; /**< Host for user display */ char *realm; /**< Authentication realm */ char uname[256]; /**< Buffer for username */ - char *url; /**< URL being fetched */ + nsurl *url; /**< URL being fetched */ char pwd[256]; /**< Buffer for password */ nserror (*cb)(bool proceed, void *pw); /**< Continuation callback */ void *cbpw; /**< Continuation callback data */ @@ -75,18 +75,15 @@ void ro_gui_401login_init(void) /** * Open the login dialog */ -void gui_401login_open(const char *url, const char *realm, +void gui_401login_open(nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw) { - char *host; - url_func_result res; - - res = url_host(url, &host); - assert(res == URL_FUNC_OK); + lwc_string *host = nsurl_get_component(url, NSURL_HOST); + assert(host != NULL); ro_gui_401login_open(url, host, realm, cb, cbpw); - free(host); + lwc_string_unref(host); } @@ -94,7 +91,7 @@ void gui_401login_open(const char *url, const char *realm, * Open a 401 login window. */ -void ro_gui_401login_open(const char *url, const char *host, const char *realm, +void ro_gui_401login_open(nsurl *url, lwc_string *host, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw) { struct session_401 *session; @@ -107,12 +104,7 @@ void ro_gui_401login_open(const char *url, const char *host, const char *realm, return; } - session->url = strdup(url); - if (!session->url) { - free(session); - warn_user("NoMemory", 0); - return; - } + session->url = nsurl_ref(url); if (realm == NULL) realm = "Secure Area"; auth = urldb_get_auth_details(session->url, realm); @@ -133,14 +125,14 @@ void ro_gui_401login_open(const char *url, const char *host, const char *realm, memcpy(session->pwd, pwd, pwd_len); session->pwd[pwd_len] = '\0'; } - session->host = strdup(host); + session->host = lwc_string_ref(host); session->realm = strdup(realm); session->cb = cb; session->cbpw = cbpw; - if ((!session->host) || (!session->realm)) { - free(session->host); - free(session->realm); + if (!session->realm) { + nsurl_unref(session->url); + lwc_string_unref(session->host); free(session); warn_user("NoMemory", 0); return; @@ -148,9 +140,11 @@ void ro_gui_401login_open(const char *url, const char *host, const char *realm, /* fill in download window icons */ dialog_401_template->icons[ICON_401LOGIN_HOST].data. - indirected_text.text = session->host; + indirected_text.text = + (char *)lwc_string_data(session->host); dialog_401_template->icons[ICON_401LOGIN_HOST].data. - indirected_text.size = strlen(session->host) + 1; + indirected_text.size = + lwc_string_length(session->host) + 1; dialog_401_template->icons[ICON_401LOGIN_REALM].data. indirected_text.text = session->realm; dialog_401_template->icons[ICON_401LOGIN_REALM].data. @@ -194,9 +188,9 @@ void ro_gui_401login_close(wimp_w w) if (session->cb != NULL) session->cb(false, session->cbpw); - free(session->host); + nsurl_unref(session->url); + lwc_string_unref(session->host); free(session->realm); - free(session->url); free(session); error = xwimp_delete_window(w); diff --git a/riscos/hotlist.c b/riscos/hotlist.c index a01b9256e..53212c12f 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -468,6 +468,7 @@ bool ro_gui_hotlist_check_menu(wimp_menu *menu) void ro_gui_hotlist_add_page(const char *url) { + nsurl *nsurl; const struct url_data *data; wimp_message message; struct ro_hotlist_message_hotlist_addurl *add_url = @@ -494,9 +495,12 @@ void ro_gui_hotlist_add_page(const char *url) LOG(("Sending Hotlist AddURL to potential hotlist clients.")); - data = urldb_get_url_data(url); + if (nsurl_create(url, &nsurl) != NSERROR_OK) + return; + data = urldb_get_url_data(nsurl); if (data == NULL) return; + nsurl_unref(nsurl); hotlist_url = osmodule_alloc(strlen(url) + 1); hotlist_title = osmodule_alloc(strlen(data->title) + 1); diff --git a/riscos/sslcert.c b/riscos/sslcert.c index 11392c7f9..2490e2e6c 100644 --- a/riscos/sslcert.c +++ b/riscos/sslcert.c @@ -108,7 +108,7 @@ void ro_gui_cert_postinitialise(void) * \param num The number of certificates included. */ -void gui_cert_verify(const char *url, +void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { diff --git a/riscos/thumbnail.c b/riscos/thumbnail.c index 43100cab1..2a140ce17 100644 --- a/riscos/thumbnail.c +++ b/riscos/thumbnail.c @@ -80,7 +80,7 @@ static void thumbnail_restore_output(struct thumbnail_save_area *save_area); * \param url the URL the thumbnail belongs to, or NULL */ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, - const char *url) + nsurl *url) { struct thumbnail_save_area *save_area; osspriteop_area *sprite_area = NULL; diff --git a/riscos/url_complete.c b/riscos/url_complete.c index d962f195d..4d5f9d213 100644 --- a/riscos/url_complete.c +++ b/riscos/url_complete.c @@ -40,7 +40,7 @@ #define MAXIMUM_VISIBLE_LINES 7 -static const char **url_complete_matches = NULL; +static nsurl **url_complete_matches = NULL; static int url_complete_matches_allocated = 0; static int url_complete_matches_available = 0; static char *url_complete_matched_string = NULL; @@ -51,7 +51,7 @@ static bool url_complete_matches_reset = false; static char *url_complete_original_url = NULL; static bool url_complete_memory_exhausted = false; -static const char *url_complete_redraw[MAXIMUM_VISIBLE_LINES]; +static nsurl *url_complete_redraw[MAXIMUM_VISIBLE_LINES]; static char url_complete_icon_null[] = ""; static char url_complete_icon_sprite[12]; static wimp_icon url_complete_icon; @@ -59,7 +59,7 @@ static wimp_icon url_complete_sprite; static int mouse_x; static int mouse_y; -static bool url_complete_callback(const char *url, +static bool url_complete_callback(nsurl *url, const struct url_data *data); @@ -303,12 +303,13 @@ bool ro_gui_url_complete_keypress(struct toolbar *toolbar, uint32_t key) url_complete_original_url, true, false); } else { ro_toolbar_set_url(toolbar, - url_complete_matches[ - url_complete_matches_selection], + nsurl_access(url_complete_matches[ + url_complete_matches_selection]), true, false); free(url_complete_matched_string); - url_complete_matched_string = strdup(url_complete_matches[ - url_complete_matches_selection]); + url_complete_matched_string = strdup(nsurl_access( + url_complete_matches[ + url_complete_matches_selection])); } url_complete_keypress_selection = url_complete_matches_selection; @@ -350,9 +351,9 @@ bool ro_gui_url_complete_keypress(struct toolbar *toolbar, uint32_t key) * \return true to continue iteration, false otherwise */ -bool url_complete_callback(const char *url, const struct url_data *data) +bool url_complete_callback(nsurl *url, const struct url_data *data) { - const char **array_extend; + nsurl **array_extend; /* Ignore unvisited URLs */ if (data->visits == 0) @@ -363,9 +364,9 @@ bool url_complete_callback(const char *url, const struct url_data *data) if (url_complete_matches_available > url_complete_matches_allocated) { - array_extend = (const char **)realloc(url_complete_matches, + array_extend = (nsurl **)realloc(url_complete_matches, (url_complete_matches_allocated + 64) * - sizeof(char *)); + sizeof(nsurl *)); if (!array_extend) { url_complete_memory_exhausted = true; return false; @@ -578,9 +579,11 @@ void ro_gui_url_complete_redraw(wimp_draw *redraw) url_complete_icon.extent.y1 = -line * 44; url_complete_icon.extent.y0 = -(line + 1) * 44; url_complete_icon.data.indirected_text.text = - (char *)url_complete_matches[line]; + (char *)nsurl_access( + url_complete_matches[line]); url_complete_icon.data.indirected_text.size = - strlen(url_complete_matches[line]); + nsurl_length( + url_complete_matches[line]); error = xwimp_plot_icon(&url_complete_icon); if (error) { @@ -700,8 +703,8 @@ bool ro_gui_url_complete_click(wimp_pointer *pointer) /* Select sets the text and launches */ if (pointer->buttons == wimp_CLICK_SELECT) { ro_toolbar_set_url(g->toolbar, - url_complete_matches[ - url_complete_matches_selection], + nsurl_access(url_complete_matches[ + url_complete_matches_selection]), true, false); /** \todo The interaction of components here is hideous */ @@ -714,16 +717,16 @@ bool ro_gui_url_complete_click(wimp_pointer *pointer) */ browser_window_go(g->bw, - url_complete_matches[ - url_complete_matches_selection], + nsurl_access(url_complete_matches[ + url_complete_matches_selection]), 0, true); ro_gui_url_complete_close(); /* Adjust just sets the text */ } else if (pointer->buttons == wimp_CLICK_ADJUST) { ro_toolbar_set_url(g->toolbar, - url_complete_matches[ - url_complete_matches_selection], + nsurl_access(url_complete_matches[ + url_complete_matches_selection]), true, false); ro_gui_url_complete_keypress(g->toolbar, 0); } diff --git a/riscos/url_suggest.c b/riscos/url_suggest.c index be766e1bd..32e772cca 100644 --- a/riscos/url_suggest.c +++ b/riscos/url_suggest.c @@ -34,7 +34,7 @@ struct url_suggest_item { struct url_suggest_item *next; /*< The next URL in the list. */ }; -static bool ro_gui_url_suggest_callback(const char *url, +static bool ro_gui_url_suggest_callback(nsurl *url, const struct url_data *data); static int suggest_entries; @@ -152,7 +152,7 @@ bool ro_gui_url_suggest_prepare_menu(void) * \return true to continue iteration, false otherwise */ -bool ro_gui_url_suggest_callback(const char *url, const struct url_data *data) +bool ro_gui_url_suggest_callback(nsurl *url, const struct url_data *data) { int count; unsigned int weight; @@ -190,7 +190,10 @@ bool ro_gui_url_suggest_callback(const char *url, const struct url_data *data) if (new != NULL) { suggest_entries++; - new->url = url; + /* TODO: keeping pointers to URLdb data is bad. + * should be nsurl_ref(url) or + * take a copy of the string. */ + new->url = nsurl_access(url); new->weight = weight; new->next = *list; @@ -205,6 +208,7 @@ bool ro_gui_url_suggest_callback(const char *url, const struct url_data *data) while (suggest_list != NULL && suggest_entries > URL_SUGGEST_MAX_URLS) { old = suggest_list; suggest_list = suggest_list->next; + free(old); suggest_entries--; } @@ -222,7 +226,7 @@ bool ro_gui_url_suggest_callback(const char *url, const struct url_data *data) const char *ro_gui_url_suggest_get_selection(wimp_selection *selection) { - const char *url = NULL; + const char *url = NULL; if (selection->items[0] >= 0) url = ro_gui_url_suggest_menu->entries[selection->items[0]]. diff --git a/test/Makefile b/test/Makefile index 43b45dda2..759d5f9c8 100644 --- a/test/Makefile +++ b/test/Makefile @@ -16,10 +16,11 @@ llcache_SRCS := content/fetch.c content/fetchers/curl.c \ urldbtest_SRCS := content/urldb.c utils/url.c utils/utils.c utils/log.c \ desktop/options.c utils/messages.c utils/hashtable.c \ - utils/filename.c test/urldbtest.c + utils/filename.c utils/nsurl.c utils/corestrings.c \ + test/urldbtest.c -urldbtest_CFLAGS := $(shell pkg-config --cflags libwapcaplet) -O2 -urldbtest_LDFLAGS := $(shell pkg-config --libs libwapcaplet) +urldbtest_CFLAGS := $(shell pkg-config --cflags libwapcaplet libdom) -O2 +urldbtest_LDFLAGS := $(shell pkg-config --libs libwapcaplet libdom) nsurl_SRCS := utils/log.c utils/nsurl.c test/nsurl.c nsurl_CFLAGS := $(shell pkg-config --cflags libwapcaplet) diff --git a/test/urldbtest.c b/test/urldbtest.c index 396735f7c..9a683546c 100644 --- a/test/urldbtest.c +++ b/test/urldbtest.c @@ -39,6 +39,7 @@ #include "riscos/bitmap.h" #endif #include "utils/log.h" +#include "utils/corestrings.h" #include "utils/filename.h" #include "utils/url.h" #include "utils/utils.h" @@ -46,6 +47,11 @@ int option_expire_url = 0; bool verbose_log = true; +static void netsurf_lwc_iterator(lwc_string *str, void *pw) +{ + LOG(("[%3u] %.*s", str->refcnt, (int) lwc_string_length(str), lwc_string_data(str))); +} + bool cookies_schedule_update(const struct cookie_data *data) { return true; @@ -81,13 +87,82 @@ char *path_to_url(const char *path) return r; } +nsurl *make_url(const char *url) +{ + nsurl *nsurl; + if (nsurl_create(url, &nsurl) != NSERROR_OK) { + LOG(("failed creating nsurl")); + exit(1); + } + return nsurl; +} + +char *make_path_query(nsurl *url) +{ + size_t len; + char *path_query; + if (nsurl_get(url, NSURL_PATH | NSURL_QUERY, &path_query, &len) != + NSERROR_OK) { + LOG(("failed creating path_query")); + exit(1); + } + return path_query; +} + +lwc_string *make_lwc(const char *str) +{ + lwc_string *lwc; + if (lwc_intern_string(str, strlen(str), &lwc) != lwc_error_ok) { + LOG(("failed creating lwc_string")); + exit(1); + } + return lwc; +} + + +bool test_urldb_set_cookie(const char *header, const char *url, + const char *referer) +{ + nsurl *r = NULL; + nsurl *nsurl = make_url(url); + bool ret; + + if (referer != NULL) + r = make_url(referer); + + ret = urldb_set_cookie(header, nsurl, r); + + if (referer != NULL) + nsurl_unref(r); + nsurl_unref(nsurl); + + return ret; +} + +char *test_urldb_get_cookie(const char *url) +{ + nsurl *nsurl = make_url(url); + char *ret; + + ret = urldb_get_cookie(nsurl); + nsurl_unref(nsurl); + + return ret; +} + int main(void) { struct host_part *h; struct path_data *p; const struct url_data *u; int i; + lwc_string *scheme; + lwc_string *fragment; + nsurl *url; + nsurl *urlr; + char *path_query; + corestrings_init(); url_init(); h = urldb_add_host("127.0.0.1"); @@ -102,16 +177,20 @@ int main(void) return 1; } - p = urldb_add_path("http", 0, h, "/", NULL, NULL, "http://intranet/"); + url = make_url("http://intranet/"); + scheme = nsurl_get_component(url, NSURL_SCHEME); + p = urldb_add_path(scheme, 0, h, strdup("/"), NULL, url); if (!p) { LOG(("failed adding path")); return 1; } + lwc_string_unref(scheme); - urldb_set_url_title("http://intranet/", "foo"); + urldb_set_url_title(url, "foo"); - u = urldb_get_url_data("http://intranet/"); + u = urldb_get_url_data(url); assert(u && strcmp(u->title, "foo") == 0); + nsurl_unref(url); /* Get host entry */ h = urldb_add_host("netsurf.strcprstskrzkrk.co.uk"); @@ -121,142 +200,186 @@ int main(void) } /* Get path entry */ - p = urldb_add_path("http", 0, h, "/path/to/resource.htm", "a=b", "zz", - "http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm?a=b"); + url = make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm?a=b"); + scheme = nsurl_get_component(url, NSURL_SCHEME); + path_query = make_path_query(url); + fragment = make_lwc("zz"); + p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url); if (!p) { LOG(("failed adding path")); return 1; } + lwc_string_unref(fragment); - p = urldb_add_path("http", 0, h, "/path/to/resource.htm", "a=b", "aa", - "http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm?a=b"); + fragment = make_lwc("aa"); + p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url); if (!p) { LOG(("failed adding path")); return 1; } + lwc_string_unref(fragment); - p = urldb_add_path("http", 0, h, "/path/to/resource.htm", "a=b", "yy", - "http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm?a=b"); + fragment = make_lwc("yy"); + p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url); if (!p) { LOG(("failed adding path")); return 1; } + free(path_query); + lwc_string_unref(fragment); + lwc_string_unref(scheme); + nsurl_unref(url); + + url = make_url("file:///home/"); + urldb_add_url(url); + nsurl_unref(url); - urldb_set_cookie("mmblah=foo; path=/; expires=Thur, 31-Dec-2099 00:00:00 GMT\r\n", "http://www.minimarcos.org.uk/cgi-bin/forum/Blah.pl?,v=login,p=2", NULL); + url = make_url("http://www.minimarcos.org.uk/cgi-bin/forum/Blah.pl?,v=login,p=2"); + urldb_set_cookie("mmblah=foo; path=/; expires=Thur, 31-Dec-2099 00:00:00 GMT\r\n", url, NULL); + nsurl_unref(url); - urldb_set_cookie("BlahPW=bar; path=/; expires=Thur, 31-Dec-2099 00:00:00 GMT\r\n", "http://www.minimarcos.org.uk/cgi-bin/forum/Blah.pl?,v=login,p=2", NULL); + url = make_url("http://www.minimarcos.org.uk/cgi-bin/forum/Blah.pl?,v=login,p=2"); + urldb_set_cookie("BlahPW=bar; path=/; expires=Thur, 31-Dec-2099 00:00:00 GMT\r\n", url, NULL); + nsurl_unref(url); - urldb_set_cookie("details=foo|bar|Sun, 03-Jun-2007;expires=Mon, 24-Jul-2006 09:53:45 GMT\r\n", "http://ccdb.cropcircleresearch.com/", NULL); + url = make_url("http://ccdb.cropcircleresearch.com/"); + urldb_set_cookie("details=foo|bar|Sun, 03-Jun-2007;expires=Mon, 24-Jul-2006 09:53:45 GMT\r\n", url, NULL); + nsurl_unref(url); - urldb_set_cookie("PREF=ID=a:TM=b:LM=c:S=d; path=/; domain=.google.com\r\n", "http://www.google.com/", NULL); + url = make_url("http://www.google.com/"); + urldb_set_cookie("PREF=ID=a:TM=b:LM=c:S=d; path=/; domain=.google.com\r\n", url, NULL); + nsurl_unref(url); - urldb_set_cookie("test=foo, bar, baz; path=/, quux=blah; path=/", "http://www.bbc.co.uk/", NULL); + url = make_url("http://www.bbc.co.uk/"); + urldb_set_cookie("test=foo, bar, baz; path=/, quux=blah; path=/", url, NULL); + nsurl_unref(url); // urldb_set_cookie("a=b; path=/; domain=.a.com", "http://a.com/", NULL); - urldb_set_cookie("foo=bar;Path=/blah;Secure\r\n", "https://www.foo.com/blah/moose", "https://www.foo.com/blah/moose"); + url = make_url("https://www.foo.com/blah/moose"); + urlr = make_url("https://www.foo.com/blah/moose"); + urldb_set_cookie("foo=bar;Path=/blah;Secure\r\n", url, urlr); + nsurl_unref(url); + nsurl_unref(urlr); - urldb_get_cookie("https://www.foo.com/blah/wxyzabc"); + url = make_url("https://www.foo.com/blah/wxyzabc"); + urldb_get_cookie(url); + nsurl_unref(url); /* 1563546 */ - assert(urldb_add_url("http:moodle.org") == false); - assert(urldb_get_url("http:moodle.org") == NULL); + url = make_url("http:moodle.org"); + assert(urldb_add_url(url) == true); + assert(urldb_get_url(url) != NULL); + nsurl_unref(url); /* also 1563546 */ - assert(urldb_add_url("http://a_a/")); - assert(urldb_get_url("http://a_a/")); + url = make_url("http://a_a/"); + assert(urldb_add_url(url)); + assert(urldb_get_url(url)); + nsurl_unref(url); /* 1597646 */ - if (urldb_add_url("http://foo@moose.com/")) { - LOG(("added http://foo@moose.com/")); - assert(urldb_get_url("http://foo@moose.com/") != NULL); + url = make_url("http://foo@moose.com/"); + if (urldb_add_url(url)) { + LOG(("added %s", nsurl_access(url))); + assert(urldb_get_url(url) != NULL); } + nsurl_unref(url); /* 1535120 */ - assert(urldb_add_url("http://www2.2checkout.com/")); - assert(urldb_get_url("http://www2.2checkout.com/")); + url = make_url("http://www2.2checkout.com/"); + assert(urldb_add_url(url)); + assert(urldb_get_url(url)); + nsurl_unref(url); /* Numeric subdomains */ - assert(urldb_add_url("http://2.bp.blogspot.com/_448y6kVhntg/TSekubcLJ7I/AAAAAAAAHJE/yZTsV5xT5t4/s1600/covers.jpg")); - assert(urldb_get_url("http://2.bp.blogspot.com/_448y6kVhntg/TSekubcLJ7I/AAAAAAAAHJE/yZTsV5xT5t4/s1600/covers.jpg")); + url = make_url("http://2.bp.blogspot.com/_448y6kVhntg/TSekubcLJ7I/AAAAAAAAHJE/yZTsV5xT5t4/s1600/covers.jpg"); + assert(urldb_add_url(url)); + assert(urldb_get_url(url)); + nsurl_unref(url); /* Valid path */ - assert(urldb_set_cookie("name=value;Path=/\r\n", "http://www.google.com/", NULL)); + assert(test_urldb_set_cookie("name=value;Path=/\r\n", "http://www.google.com/", NULL)); /* Valid path (non-root directory) */ - assert(urldb_set_cookie("name=value;Path=/foo/bar/\r\n", "http://www.example.org/foo/bar/", NULL)); + assert(test_urldb_set_cookie("name=value;Path=/foo/bar/\r\n", "http://www.example.org/foo/bar/", NULL)); /* Defaulted path */ - assert(urldb_set_cookie("name=value\r\n", "http://www.example.org/foo/bar/baz/bat.html", NULL)); - assert(urldb_get_cookie("http://www.example.org/foo/bar/baz/quux.htm")); + assert(test_urldb_set_cookie("name=value\r\n", "http://www.example.org/foo/bar/baz/bat.html", NULL)); + assert(test_urldb_get_cookie("http://www.example.org/foo/bar/baz/quux.htm")); /* Defaulted path with no non-leaf path segments */ - assert(urldb_set_cookie("name=value\r\n", "http://no-non-leaf.example.org/index.html", NULL)); - assert(urldb_get_cookie("http://no-non-leaf.example.org/page2.html")); - assert(urldb_get_cookie("http://no-non-leaf.example.org/")); + assert(test_urldb_set_cookie("name=value\r\n", "http://no-non-leaf.example.org/index.html", NULL)); + assert(test_urldb_get_cookie("http://no-non-leaf.example.org/page2.html")); + assert(test_urldb_get_cookie("http://no-non-leaf.example.org/")); /* Valid path (includes leafname) */ - assert(urldb_set_cookie("name=value;Version=1;Path=/index.cgi\r\n", "http://example.org/index.cgi", NULL)); - assert(urldb_get_cookie("http://example.org/index.cgi")); + assert(test_urldb_set_cookie("name=value;Version=1;Path=/index.cgi\r\n", "http://example.org/index.cgi", NULL)); + assert(test_urldb_get_cookie("http://example.org/index.cgi")); /* Valid path (includes leafname in non-root directory) */ - assert(urldb_set_cookie("name=value;Path=/foo/index.html\r\n", "http://www.example.org/foo/index.html", NULL)); + assert(test_urldb_set_cookie("name=value;Path=/foo/index.html\r\n", "http://www.example.org/foo/index.html", NULL)); /* Should _not_ match the above, as the leafnames differ */ - assert(urldb_get_cookie("http://www.example.org/foo/bar.html") == NULL); + assert(test_urldb_get_cookie("http://www.example.org/foo/bar.html") == NULL); /* Invalid path (contains different leafname) */ - assert(urldb_set_cookie("name=value;Path=/index.html\r\n", "http://example.org/index.htm", NULL) == false); + assert(test_urldb_set_cookie("name=value;Path=/index.html\r\n", "http://example.org/index.htm", NULL) == false); /* Invalid path (contains leafname in different directory) */ - assert(urldb_set_cookie("name=value;Path=/foo/index.html\r\n", "http://www.example.org/bar/index.html", NULL) == false); + assert(test_urldb_set_cookie("name=value;Path=/foo/index.html\r\n", "http://www.example.org/bar/index.html", NULL) == false); /* Test partial domain match with IP address failing */ - assert(urldb_set_cookie("name=value;Domain=.foo.org\r\n", "http://192.168.0.1/", NULL) == false); + assert(test_urldb_set_cookie("name=value;Domain=.foo.org\r\n", "http://192.168.0.1/", NULL) == false); /* Test handling of non-domain cookie sent by server (domain part should * be ignored) */ - assert(urldb_set_cookie("foo=value;Domain=blah.com\r\n", "http://www.example.com/", NULL)); - assert(strcmp(urldb_get_cookie("http://www.example.com/"), "foo=value") == 0); + assert(test_urldb_set_cookie("foo=value;Domain=blah.com\r\n", "http://www.example.com/", NULL)); + assert(strcmp(test_urldb_get_cookie("http://www.example.com/"), "foo=value") == 0); /* Test handling of domain cookie from wrong host (strictly invalid but * required to support the real world) */ - assert(urldb_set_cookie("name=value;Domain=.example.com\r\n", "http://foo.bar.example.com/", NULL)); - assert(strcmp(urldb_get_cookie("http://www.example.com/"), "foo=value; name=value") == 0); + assert(test_urldb_set_cookie("name=value;Domain=.example.com\r\n", "http://foo.bar.example.com/", NULL)); + assert(strcmp(test_urldb_get_cookie("http://www.example.com/"), "foo=value; name=value") == 0); /* Test presence of separators in cookie value */ - assert(urldb_set_cookie("name=\"value=foo\\\\bar\\\\\\\";\\\\baz=quux\";Version=1\r\n", "http://www.example.org/", NULL)); - assert(strcmp(urldb_get_cookie("http://www.example.org/"), "$Version=1; name=\"value=foo\\\\bar\\\\\\\";\\\\baz=quux\"") == 0); + assert(test_urldb_set_cookie("name=\"value=foo\\\\bar\\\\\\\";\\\\baz=quux\";Version=1\r\n", "http://www.example.org/", NULL)); + assert(strcmp(test_urldb_get_cookie("http://www.example.org/"), "$Version=1; name=\"value=foo\\\\bar\\\\\\\";\\\\baz=quux\"") == 0); /* Test cookie with blank value */ - assert(urldb_set_cookie("a=\r\n", "http://www.example.net/", NULL)); - assert(strcmp(urldb_get_cookie("http://www.example.net/"), "a=") == 0); + assert(test_urldb_set_cookie("a=\r\n", "http://www.example.net/", NULL)); + assert(strcmp(test_urldb_get_cookie("http://www.example.net/"), "a=") == 0); /* Test specification of multiple cookies in one header */ - assert(urldb_set_cookie("a=b, foo=bar; Path=/\r\n", "http://www.example.net/", NULL)); - assert(strcmp(urldb_get_cookie("http://www.example.net/"), "a=b; foo=bar") == 0); + assert(test_urldb_set_cookie("a=b, foo=bar; Path=/\r\n", "http://www.example.net/", NULL)); + assert(strcmp(test_urldb_get_cookie("http://www.example.net/"), "a=b; foo=bar") == 0); /* Test use of separators in unquoted cookie value */ - assert(urldb_set_cookie("foo=moo@foo:blah?moar\\ text\r\n", "http://example.com/", NULL)); - assert(strcmp(urldb_get_cookie("http://example.com/"), "foo=moo@foo:blah?moar\\ text; name=value") == 0); + assert(test_urldb_set_cookie("foo=moo@foo:blah?moar\\ text\r\n", "http://example.com/", NULL)); + assert(strcmp(test_urldb_get_cookie("http://example.com/"), "foo=moo@foo:blah?moar\\ text; name=value") == 0); /* Test use of unnecessary quotes */ - assert(urldb_set_cookie("foo=\"hello\";Version=1,bar=bat\r\n", "http://example.com/", NULL)); - assert(strcmp(urldb_get_cookie("http://example.com/"), "foo=\"hello\"; bar=bat; name=value") == 0); + assert(test_urldb_set_cookie("foo=\"hello\";Version=1,bar=bat\r\n", "http://example.com/", NULL)); + assert(strcmp(test_urldb_get_cookie("http://example.com/"), "foo=\"hello\"; bar=bat; name=value") == 0); /* Test domain matching in unverifiable transactions */ - assert(urldb_set_cookie("foo=bar; domain=.example.tld\r\n", "http://www.foo.example.tld/", "http://bar.example.tld/")); - assert(strcmp(urldb_get_cookie("http://www.foo.example.tld/"), "foo=bar") == 0); + assert(test_urldb_set_cookie("foo=bar; domain=.example.tld\r\n", "http://www.foo.example.tld/", "http://bar.example.tld/")); + assert(strcmp(test_urldb_get_cookie("http://www.foo.example.tld/"), "foo=bar") == 0); /* Test expiry */ - assert(urldb_set_cookie("foo=bar", "http://expires.com/", NULL)); - assert(strcmp(urldb_get_cookie("http://expires.com/"), "foo=bar") == 0); - assert(urldb_set_cookie("foo=bar; expires=Thu, 01-Jan-1970 00:00:01 GMT\r\n", "http://expires.com/", NULL)); - assert(urldb_get_cookie("http://expires.com/") == NULL); + assert(test_urldb_set_cookie("foo=bar", "http://expires.com/", NULL)); + assert(strcmp(test_urldb_get_cookie("http://expires.com/"), "foo=bar") == 0); + assert(test_urldb_set_cookie("foo=bar; expires=Thu, 01-Jan-1970 00:00:01 GMT\r\n", "http://expires.com/", NULL)); + assert(test_urldb_get_cookie("http://expires.com/") == NULL); urldb_dump(); + urldb_destroy(); printf("PASS\n"); + corestrings_fini(); + LOG(("Remaining lwc strings:")); + lwc_iterate_strings(netsurf_lwc_iterator, NULL); + return 0; } diff --git a/utils/corestrings.c b/utils/corestrings.c index 86f2c4cb4..0e2428e19 100644 --- a/utils/corestrings.c +++ b/utils/corestrings.c @@ -58,6 +58,7 @@ lwc_string *corestring_lwc_head; lwc_string *corestring_lwc_hidden; lwc_string *corestring_lwc_hr; lwc_string *corestring_lwc_html; +lwc_string *corestring_lwc_https; lwc_string *corestring_lwc_iframe; lwc_string *corestring_lwc_image; lwc_string *corestring_lwc_img; @@ -198,6 +199,7 @@ void corestrings_fini(void) CSS_LWC_STRING_UNREF(hidden); CSS_LWC_STRING_UNREF(hr); CSS_LWC_STRING_UNREF(html); + CSS_LWC_STRING_UNREF(https); CSS_LWC_STRING_UNREF(iframe); CSS_LWC_STRING_UNREF(image); CSS_LWC_STRING_UNREF(img); @@ -358,6 +360,7 @@ nserror corestrings_init(void) CSS_LWC_STRING_INTERN(hidden); CSS_LWC_STRING_INTERN(hr); CSS_LWC_STRING_INTERN(html); + CSS_LWC_STRING_INTERN(https); CSS_LWC_STRING_INTERN(iframe); CSS_LWC_STRING_INTERN(image); CSS_LWC_STRING_INTERN(img); diff --git a/utils/corestrings.h b/utils/corestrings.h index a64f62f65..5ecc3aa63 100644 --- a/utils/corestrings.h +++ b/utils/corestrings.h @@ -62,6 +62,7 @@ extern lwc_string *corestring_lwc_head; extern lwc_string *corestring_lwc_hidden; extern lwc_string *corestring_lwc_hr; extern lwc_string *corestring_lwc_html; +extern lwc_string *corestring_lwc_https; extern lwc_string *corestring_lwc_iframe; extern lwc_string *corestring_lwc_image; extern lwc_string *corestring_lwc_img; diff --git a/windows/gui.c b/windows/gui.c index f7d8c4ccd..048b50fd5 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -1821,7 +1821,7 @@ void gui_create_form_select_menu(struct browser_window *bw, } -void gui_cert_verify(const char *url, const struct ssl_cert_info *certs, +void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { diff --git a/windows/login.c b/windows/login.c index c1afab350..7a5e195f4 100644 --- a/windows/login.c +++ b/windows/login.c @@ -18,7 +18,7 @@ #include "desktop/401login.h" -void gui_401login_open(const char *url, const char *realm, +void gui_401login_open(nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw) { cb(false, cbpw); diff --git a/windows/thumbnail.c b/windows/thumbnail.c index 4ce0aba1c..e87745bae 100644 --- a/windows/thumbnail.c +++ b/windows/thumbnail.c @@ -35,7 +35,7 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, - const char *url) + nsurl *url) { int width; int height; @@ -53,7 +53,7 @@ thumbnail_create(hlcache_handle *content, bitmap->width; LOG(("bitmap %p for url %s content %p width %d, height %d", - bitmap, url, content, width, height)); + bitmap, nsurl_access(url), content, width, height)); /* create two memory device contexts to put the bitmaps in */ bufferdc = CreateCompatibleDC(NULL); |