diff options
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/401login.h | 3 | ||||
-rw-r--r-- | desktop/browser.c | 3 | ||||
-rw-r--r-- | desktop/browser.h | 2 | ||||
-rw-r--r-- | desktop/gui.h | 2 | ||||
-rw-r--r-- | desktop/history_core.c | 10 | ||||
-rw-r--r-- | desktop/history_global_core.c | 7 | ||||
-rw-r--r-- | desktop/hotlist.c | 85 | ||||
-rw-r--r-- | desktop/netsurf.c | 5 | ||||
-rw-r--r-- | desktop/sslcert.c | 11 | ||||
-rw-r--r-- | desktop/sslcert.h | 2 | ||||
-rw-r--r-- | desktop/thumbnail.h | 3 | ||||
-rw-r--r-- | desktop/tree_url_node.c | 59 | ||||
-rw-r--r-- | desktop/tree_url_node.h | 9 |
13 files changed, 115 insertions, 86 deletions
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 7647cbb25..46fd14b8d 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1276,8 +1276,7 @@ nserror browser_window_callback(hlcache_handle *c, urldb_set_url_content_type(url, content_get_type(c)); /* This is safe as we've just added the URL */ - global_history_add( - nsurl_access(urldb_get_url(url))); + global_history_add(urldb_get_url(url)); } } 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); |