aboutsummaryrefslogtreecommitdiffstats
path: root/url.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-09-15 11:19:50 +0000
committerTatsuya Kinoshita <tats@debian.org>2020-09-15 11:19:50 +0000
commit0efa713058dc574a83c9d4c3c761ce644fa0f380 (patch)
tree3b9f575ce3a4134be888855049bbd5f993acc209 /url.c
parentMerge branch 'upstream' into master (diff)
downloadw3m-0efa713058dc574a83c9d4c3c761ce644fa0f380.tar.gz
w3m-0efa713058dc574a83c9d4c3c761ce644fa0f380.zip
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
Diffstat (limited to 'url.c')
-rw-r--r--url.c36
1 files changed, 31 insertions, 5 deletions
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 <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -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;