From 476643d9072ea79de66f5324845988e52933ce6f Mon Sep 17 00:00:00 2001 From: Marco Peereboom Date: Wed, 24 Aug 2011 00:53:12 +0000 Subject: use an actual working heuristic to determine if something is a valid url; this makes guess_search work a little better. requested by mcbride who apparentely uses it. --- xxxterm.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/xxxterm.c b/xxxterm.c index 127cb29..423bba3 100644 --- a/xxxterm.c +++ b/xxxterm.c @@ -1616,27 +1616,20 @@ guess_url_type(char *url_in) { struct stat sb; char *url_out = NULL, *enc_search = NULL; + SoupURI *uri = NULL; url_out = match_alias(url_in); if (url_out != NULL) return (url_out); if (guess_search) { - /* - * If there is no dot nor slash in the string and it isn't a - * path to a local file and doesn't resolves to an IP, assume - * that the user wants to search for the string. - */ - - if (strchr(url_in, '.') == NULL && - strchr(url_in, '/') == NULL && - stat(url_in, &sb) != 0 && - gethostbyname(url_in) == NULL) { - + uri = soup_uri_new(url_in); + if (uri == NULL || !SOUP_URI_VALID_FOR_HTTP(uri)) { + /* invalid URI so search instead */ enc_search = soup_uri_encode(url_in, XT_RESERVED_CHARS); url_out = g_strdup_printf(search_string, enc_search); g_free(enc_search); - return (url_out); + goto done; } } @@ -1645,8 +1638,10 @@ guess_url_type(char *url_in) url_out = g_strdup_printf("file://%s", url_in); else url_out = g_strdup_printf("http://%s", url_in); /* guess http */ - +done: DNPRINTF(XT_D_URL, "guess_url_type: guessed %s\n", url_out); + if (uri) + soup_uri_free(uri); return (url_out); } -- cgit 1.4.1-2-gfad0