From: Daniel Carl Date: Wed, 15 Nov 2017 09:22:09 +0000 (+0100) Subject: Move sanitize_uri to utils. X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=b028fee7356d1c33c2ab79040f8b2e7a6615907a;p=vimb.git Move sanitize_uri to utils. This will allow us to used this in other parts too. --- diff --git a/src/main.c b/src/main.c index 0e629a5..02f079a 100644 --- a/src/main.c +++ b/src/main.c @@ -91,7 +91,6 @@ static gboolean quit(Client *c); static void read_from_stdin(Client *c); static void register_cleanup(Client *c); static void update_title(Client *c); -static gchar *sanitize_uri(const gchar *uri); static void update_urlbar(Client *c); static void set_statusbar_style(Client *c, StatusType type); static void set_title(Client *c, const char *title); @@ -1340,13 +1339,13 @@ static void on_webview_mouse_target_changed(WebKitWebView *webview, c->state.hit_test_result = g_object_ref(result); if (webkit_hit_test_result_context_is_link(result)) { - uri = sanitize_uri(webkit_hit_test_result_get_link_uri(result)); + uri = util_sanitize_uri(webkit_hit_test_result_get_link_uri(result)); msg = g_strconcat("Link: ", uri, NULL); gtk_label_set_text(GTK_LABEL(c->statusbar.left), msg); g_free(msg); g_free(uri); } else if (webkit_hit_test_result_context_is_image(result)) { - uri = sanitize_uri(webkit_hit_test_result_get_image_uri(result)); + uri = util_sanitize_uri(webkit_hit_test_result_get_image_uri(result)); msg = g_strconcat("Image: ", uri, NULL); gtk_label_set_text(GTK_LABEL(c->statusbar.left), msg); g_free(msg); @@ -1520,21 +1519,6 @@ static void update_title(Client *c) } } -/** - * Strips password from a uri. - */ -static gchar *sanitize_uri(const gchar *uri_str) -{ - SoupURI *uri; - gchar *sanitized_uri; - - uri = soup_uri_new(uri_str); - sanitized_uri = soup_uri_to_string(uri, FALSE); - soup_uri_free(uri); - - return sanitized_uri; -} - /** * Update the contents of the url bar on the left of the statu bar according * to current opened url and position in back forward history. @@ -1552,7 +1536,7 @@ static void update_urlbar(Client *c) } /* show current url, stripping password first */ - uri = sanitize_uri(c->state.uri); + uri = util_sanitize_uri(c->state.uri); g_string_append_printf(str, "%s", uri); /* show history indicator only if there is something to show */ diff --git a/src/util.c b/src/util.c index fac1157..8739ad5 100644 --- a/src/util.c +++ b/src/util.c @@ -733,6 +733,24 @@ char *util_sanitize_filename(char *filename) return g_strdelimit(filename, G_DIR_SEPARATOR_S, '_'); } +/** + * Strips password from a uri. + * + * Return newly allocated string. + */ +char *util_sanitize_uri(const char *uri_str) +{ + SoupURI *uri; + char *sanitized_uri; + + uri = soup_uri_new(uri_str); + sanitized_uri = soup_uri_to_string(uri, FALSE); + soup_uri_free(uri); + + return sanitized_uri; +} + + char *util_strcasestr(const char *haystack, const char *needle) { guchar c1, c2; diff --git a/src/util.h b/src/util.h index b0b73b4..0084939 100644 --- a/src/util.h +++ b/src/util.h @@ -53,6 +53,7 @@ double util_js_result_as_number(WebKitJavascriptResult *result); gboolean util_parse_expansion(Client *c, const char **input, GString *str, int flags, const char *quoteable); char *util_sanitize_filename(char *filename); +char *util_sanitize_uri(const char *uri_str); char *util_strcasestr(const char *haystack, const char *needle); char *util_str_replace(const char* search, const char* replace, const char* string); gboolean util_wildmatch(const char *pattern, const char *subject);