From d9e7d5810678c1470808c3de63f7bde412b3d17b Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 11 Oct 2012 11:20:02 +0100 Subject: Fix up ripples from urldb change. --- riscos/401login.c | 44 +++++++++++++++++++------------------------- riscos/hotlist.c | 6 +++++- riscos/sslcert.c | 2 +- riscos/thumbnail.c | 2 +- riscos/url_complete.c | 41 ++++++++++++++++++++++------------------- riscos/url_suggest.c | 12 ++++++++---- 6 files changed, 56 insertions(+), 51 deletions(-) (limited to 'riscos') 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]]. -- cgit v1.2.3