From 0efa713058dc574a83c9d4c3c761ce644fa0f380 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 15 Sep 2020 20:19:50 +0900 Subject: Add support for file://hostname/... URLs Origin: https://github.com/tats/w3m/files/3488813/file-hostname-support.diff.gz Bug-Debian: https://github.com/tats/w3m/issues/120 --- url.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'url.c') diff --git a/url.c b/url.c index a9e4108..972f14b 100644 --- a/url.c +++ b/url.c @@ -1,6 +1,7 @@ /* $Id: url.c,v 1.100 2010/12/15 10:50:24 htrb Exp $ */ #include "fm.h" #ifndef __MINGW32_VERSION +#include #include #include #include @@ -40,6 +41,10 @@ #define close(fd) closesocket(fd) #endif +#ifndef HOST_NAME_MAX +#define HOST_NAME_MAX 64 +#endif + #ifdef INET6 /* see rc.c, "dns_order" and dnsorders[] */ int ai_family_order_table[7][3] = { @@ -720,13 +725,34 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current) copyParsedURL(p_url, current); goto do_label; } + if (!strncasecmp(url, "file://", 7)) { #if defined( __EMX__ ) || defined( __CYGWIN__ ) - if (!strncasecmp(url, "file://localhost/", 17)) { - p_url->scheme = SCM_LOCAL; - p += 17 - 1; - url += 17 - 1; - } + if (!strncasecmp(url + 7, "localhost/", 10)) { + p_url->scheme = SCM_LOCAL; + p += 7 + 10 - 1; + url += 7 + 10 - 1; + } else #endif + { + /* Recognize the machine's host name. This is necessary for URLs + * produced by 'ls --hyperlink' or similar. */ + char hostname[HOST_NAME_MAX + 2]; + if (gethostname (hostname, HOST_NAME_MAX + 2) == 0) { + size_t hostname_len; + /* Don't use hostname if it is truncated. */ + hostname[HOST_NAME_MAX + 1] = '\0'; + hostname_len = strlen (hostname); + if (hostname_len <= HOST_NAME_MAX) { + if (!strncasecmp(url + 7, hostname, hostname_len) + && *(url + 7 + hostname_len) == '/') { + p_url->scheme = SCM_LOCAL; + p += 7 + hostname_len; + url += 7 + hostname_len; + } + } + } + } + } #ifdef SUPPORT_DOS_DRIVE_PREFIX if (IS_ALPHA(*p) && (p[1] == ':' || p[1] == '|')) { p_url->scheme = SCM_LOCAL; -- cgit v1.2.3