about summary refs log tree commit diff stats
path: root/WWW/Library
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2008-12-08 01:31:28 -0500
committerThomas E. Dickey <dickey@invisible-island.net>2008-12-08 01:31:28 -0500
commitfe7fe1904f61ce9b03d28f34640687d887cca01c (patch)
treed34e27795f9e1ac515c64f2f0e77d63534e60fd8 /WWW/Library
parent711a9d1b98ce96d750833e0782afad12c3cfb286 (diff)
downloadlynx-snapshots-fe7fe1904f61ce9b03d28f34640687d887cca01c.tar.gz
snapshot of project "lynx", label v2-8-7dev_10c
Diffstat (limited to 'WWW/Library')
-rw-r--r--WWW/Library/Implementation/HTFile.c93
-rw-r--r--WWW/Library/Implementation/HTFile.h24
-rw-r--r--WWW/Library/Implementation/HTFormat.c22
-rw-r--r--WWW/Library/Implementation/HTMIME.c168
-rw-r--r--WWW/Library/Implementation/HTTCP.c32
-rw-r--r--WWW/Library/Implementation/HTUtils.h18
-rw-r--r--WWW/Library/Implementation/SGML.c4
7 files changed, 271 insertions, 90 deletions
diff --git a/WWW/Library/Implementation/HTFile.c b/WWW/Library/Implementation/HTFile.c
index bfd79410..2ab38a3c 100644
--- a/WWW/Library/Implementation/HTFile.c
+++ b/WWW/Library/Implementation/HTFile.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTFile.c,v 1.105 2008/09/18 21:34:25 tom Exp $
+ * $LynxId: HTFile.c,v 1.110 2008/12/07 18:49:34 tom Exp $
  *
  *			File Access				HTFile.c
  *			===========
@@ -1247,6 +1247,62 @@ CompressFileType HTCompressFileType(const char *filename,
 }
 
 /*
+ *  Determine expected file-suffix from the compression method.
+ */
+const char *HTCompressTypeToSuffix(CompressFileType method)
+{
+    const char *result = "";
+
+    switch (method) {
+    default:
+    case cftNone:
+	result = "";
+	break;
+    case cftGzip:
+	result = ".gz";
+	break;
+    case cftCompress:
+	result = ".Z";
+	break;
+    case cftBzip2:
+	result = ".bz2";
+	break;
+    case cftDeflate:
+	result = ".zz";
+	break;
+    }
+    return result;
+}
+
+/*
+ *  Determine compression encoding from the compression method.
+ */
+const char *HTCompressTypeToEncoding(CompressFileType method)
+{
+    const char *result = NULL;
+
+    switch (method) {
+    default:
+    case cftNone:
+	result = NULL;
+	break;
+    case cftGzip:
+	result = "gzip";
+	break;
+    case cftCompress:
+	result = "compress";
+	break;
+    case cftBzip2:
+	result = "bzip2";
+	break;
+    case cftDeflate:
+	result = "deflate";
+	break;
+    }
+    return result;
+}
+
+/*
  * Check if the token from "Content-Encoding" corresponds to a compression
  * type.  RFC 2068 (and cut/paste into RFC 2616) lists these:
  *	gzip
@@ -1276,6 +1332,41 @@ CompressFileType HTEncodingToCompressType(const char *coding)
     return result;
 }
 
+CompressFileType HTContentTypeToCompressType(const char *ct)
+{
+    CompressFileType method = cftNone;
+
+    if (!strncasecomp(ct, "application/gzip", 16) ||
+	!strncasecomp(ct, "application/x-gzip", 18)) {
+	method = cftGzip;
+    } else if (!strncasecomp(ct, "application/compress", 20) ||
+	       !strncasecomp(ct, "application/x-compress", 22)) {
+	method = cftCompress;
+    } else if (!strncasecomp(ct, "application/bzip2", 17) ||
+	       !strncasecomp(ct, "application/x-bzip2", 19)) {
+	method = cftBzip2;
+    }
+    return method;
+}
+
+/*
+ * Check the anchor's content_type and content_encoding elements for a gzip or
+ * Unix compressed file -FM, TD
+ */
+CompressFileType HTContentToCompressType(HTParentAnchor *anchor)
+{
+    CompressFileType method = cftNone;
+    const char *ct = HTAnchor_content_type(anchor);
+    const char *ce = HTAnchor_content_encoding(anchor);
+
+    if (ce == NULL && ct != 0) {
+	method = HTContentTypeToCompressType(ct);
+    } else if (ce != 0) {
+	method = HTEncodingToCompressType(ce);
+    }
+    return method;
+}
+
 /*	Determine write access to a file.
  *	---------------------------------
  *
diff --git a/WWW/Library/Implementation/HTFile.h b/WWW/Library/Implementation/HTFile.h
index 38f407f2..b7a514d6 100644
--- a/WWW/Library/Implementation/HTFile.h
+++ b/WWW/Library/Implementation/HTFile.h
@@ -1,4 +1,6 @@
-/*							File access in libwww
+/*
+ * $LynxId: HTFile.h,v 1.31 2008/12/07 18:49:53 tom Exp $
+ *							File access in libwww
  *				FILE ACCESS
  *
  *  These are routines for local file access used by WWW browsers and servers.
@@ -221,15 +223,25 @@ extern "C" {
 					       int *rootlen);
 
 /*
- *  Determine compression type from the content-type.
+ *  Determine compression type from the content-encoding.
  */
-    extern CompressFileType HTContentToCompressType(const char *encoding);
-
+    extern CompressFileType HTEncodingToCompressType(const char *encoding);
 /*
  *  Determine compression type from the content-encoding.
  */
-    extern CompressFileType HTEncodingToCompressType(const char *encoding);
-
+    extern CompressFileType HTContentTypeToCompressType(const char *ct);
+/*
+ *  Determine compression type from the content-type and/or content-encoding.
+ */
+    extern CompressFileType HTContentToCompressType(HTParentAnchor *anchor);
+/*
+ *  Determine compression encoding from the compression method.
+ */
+    extern const char *HTCompressTypeToEncoding(CompressFileType method);
+/*
+ *  Determine expected file-suffix from the compression method.
+ */
+    extern const char *HTCompressTypeToSuffix(CompressFileType method);
 /*
  *  Determine write access to a file.
  *
diff --git a/WWW/Library/Implementation/HTFormat.c b/WWW/Library/Implementation/HTFormat.c
index 5818e8a6..0aaead00 100644
--- a/WWW/Library/Implementation/HTFormat.c
+++ b/WWW/Library/Implementation/HTFormat.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTFormat.c,v 1.63 2008/09/10 23:22:59 tom Exp $
+ * $LynxId: HTFormat.c,v 1.64 2008/12/07 15:53:54 tom Exp $
  *
  *		Manage different file formats			HTFormat.c
  *		=============================
@@ -396,8 +396,9 @@ static HTPresentation *HTFindPresentation(HTFormat rep_in,
 	    if (pres->rep_out == rep_out) {
 		if (failsMailcap(pres, anchor))
 		    continue;
-		CTRACE((tfp, "FindPresentation: found exact match: %s\n",
-			HTAtom_name(pres->rep)));
+		CTRACE((tfp, "FindPresentation: found exact match: %s -> %s\n",
+			HTAtom_name(pres->rep),
+			HTAtom_name(pres->rep_out)));
 		return pres;
 
 	    } else if (!fill_in) {
@@ -412,8 +413,9 @@ static HTPresentation *HTFindPresentation(HTFormat rep_in,
 			strong_wildcard_match = pres;
 		    /* otherwise use the first one */
 		    CTRACE((tfp,
-			    "StreamStack: found strong wildcard match: %s\n",
-			    HTAtom_name(pres->rep)));
+			    "StreamStack: found strong wildcard match: %s -> %s\n",
+			    HTAtom_name(pres->rep),
+			    HTAtom_name(pres->rep_out)));
 		}
 	    }
 
@@ -429,8 +431,9 @@ static HTPresentation *HTFindPresentation(HTFormat rep_in,
 		    strong_subtype_wildcard_match = pres;
 		/* otherwise use the first one */
 		CTRACE((tfp,
-			"StreamStack: found strong subtype wildcard match: %s\n",
-			HTAtom_name(pres->rep)));
+			"StreamStack: found strong subtype wildcard match: %s -> %s\n",
+			HTAtom_name(pres->rep),
+			HTAtom_name(pres->rep_out)));
 	    }
 	}
 
@@ -515,8 +518,9 @@ HTStream *HTStreamStack(HTFormat rep_in,
 	if (match == &temp) {
 	    CTRACE((tfp, "StreamStack: Using %s\n", HTAtom_name(temp.rep_out)));
 	} else {
-	    CTRACE((tfp, "StreamStack: found exact match: %s\n",
-		    HTAtom_name(match->rep)));
+	    CTRACE((tfp, "StreamStack: found exact match: %s -> %s\n",
+		    HTAtom_name(match->rep),
+		    HTAtom_name(match->rep_out)));
 	}
 	result = (*match->converter) (match, anchor, sink);
     } else {
diff --git a/WWW/Library/Implementation/HTMIME.c b/WWW/Library/Implementation/HTMIME.c
index df5115b6..6f3fb58b 100644
--- a/WWW/Library/Implementation/HTMIME.c
+++ b/WWW/Library/Implementation/HTMIME.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTMIME.c,v 1.64 2008/09/17 00:04:44 tom Exp $
+ * $LynxId: HTMIME.c,v 1.66 2008/12/07 20:23:52 tom Exp $
  *
  *			MIME Message Parse			HTMIME.c
  *			==================
@@ -215,8 +215,66 @@ static void dequote(char *url)
     }
 }
 
+/*
+ * Strip off any compression-suffix from the address and check if the result
+ * looks like one of the presentable suffixes.  If so, return the corresponding
+ * MIME type.
+ */
+static const char *UncompressedContentType(HTStream *me, CompressFileType method)
+{
+    const char *result = 0;
+    char *address = me->anchor->address;
+    const char *expected = HTCompressTypeToSuffix(method);
+    const char *actual = strrchr(address, '.');
+
+    /*
+     * We have to ensure the suffix is consistent, to use HTFileFormat().
+     */
+    if (actual != 0 && !strcasecomp(actual, expected)) {
+	HTFormat format;
+	HTAtom *pencoding = 0;
+	const char *description = 0;
+
+	format = HTFileFormat(address, &pencoding, &description);
+	result = HTAtom_name(format);
+    }
+
+    return result;
+}
+
 static int pumpData(HTStream *me)
 {
+    CompressFileType method;
+    const char *new_encoding;
+    const char *new_content;
+
+    CTRACE((tfp, "Begin pumpData\n"));
+    /*
+     * If the content-type says it is compressed, and there is no
+     * content-encoding, check further and see if the address (omitting the
+     * suffix for a compressed type) looks like a type we can present.  If so,
+     * rearrange things so we'll present the StreamStack code with the
+     * presentable type, already marked as compressed.
+     */
+    CTRACE((tfp, "...address{%s}\n", me->anchor->address));
+    method = HTContentTypeToCompressType(me->anchor->content_type_params);
+    if ((method != cftNone)
+	&& isEmpty(me->anchor->content_encoding)
+	&& (new_content = UncompressedContentType(me, method)) != 0) {
+
+	new_encoding = HTCompressTypeToEncoding(method);
+	CTRACE((tfp, "reinterpreting as content-type:%s, encoding:%s\n",
+		new_content, new_encoding));
+
+	StrAllocCopy(me->anchor->content_encoding, new_encoding);
+	FREE(me->compression_encoding);
+	StrAllocCopy(me->compression_encoding, new_encoding);
+
+	strcpy(me->value, new_content);
+	StrAllocCopy(me->anchor->content_type_params, me->value);
+	me->format = HTAtom_for(me->value);
+    }
+
     if (strchr(HTAtom_name(me->format), ';') != NULL) {
 	char *cp = NULL, *cp1, *cp2, *cp3 = NULL, *cp4;
 
@@ -451,68 +509,72 @@ static int pumpData(HTStream *me)
 	    }
 	}
     }
+    CTRACE((tfp, "...pumpData finished reading header\n"));
     if (me->head_only) {
 	/* We are done! - kw */
 	me->state = MIME_IGNORE;
-	return HT_OK;
-    }
-
-    if (me->no_streamstack) {
-	me->target = me->sink;
     } else {
-	if (!me->compression_encoding) {
-	    CTRACE((tfp,
-		    "HTMIME: MIME Content-Type is '%s', converting to '%s'\n",
-		    HTAtom_name(me->format), HTAtom_name(me->targetRep)));
+
+	if (me->no_streamstack) {
+	    me->target = me->sink;
 	} else {
+	    if (!me->compression_encoding) {
+		CTRACE((tfp,
+			"HTMIME: MIME Content-Type is '%s', converting to '%s'\n",
+			HTAtom_name(me->format), HTAtom_name(me->targetRep)));
+	    } else {
+		/*
+		 * Change the format to that for "www/compressed" and set up a
+		 * stream to deal with it.  - FM
+		 */
+		CTRACE((tfp, "HTMIME: MIME Content-Type is '%s',\n",
+			HTAtom_name(me->format)));
+		me->format = HTAtom_for("www/compressed");
+		CTRACE((tfp, "        Treating as '%s'.  Converting to '%s'\n",
+			HTAtom_name(me->format), HTAtom_name(me->targetRep)));
+		FREE(me->compression_encoding);
+	    }
+	    me->target = HTStreamStack(me->format, me->targetRep,
+				       me->sink, me->anchor);
+	    if (!me->target) {
+		CTRACE((tfp, "HTMIME: Can't translate! ** \n"));
+		me->target = me->sink;	/* Cheat */
+	    }
+	}
+	if (me->target) {
+	    me->targetClass = *me->target->isa;
 	    /*
-	     * Change the format to that for "www/compressed" and set up a
-	     * stream to deal with it.  - FM
+	     * Pump rest of data right through, according to the transfer encoding.
 	     */
-	    CTRACE((tfp, "HTMIME: MIME Content-Type is '%s',\n", HTAtom_name(me->format)));
-	    me->format = HTAtom_for("www/compressed");
-	    CTRACE((tfp, "        Treating as '%s'.  Converting to '%s'\n",
-		    HTAtom_name(me->format), HTAtom_name(me->targetRep)));
-	    FREE(me->compression_encoding);
-	}
-	me->target = HTStreamStack(me->format, me->targetRep,
-				   me->sink, me->anchor);
-	if (!me->target) {
-	    CTRACE((tfp, "HTMIME: Can't translate! ** \n"));
-	    me->target = me->sink;	/* Cheat */
+	    me->state = (me->chunked_encoding
+			 ? MIME_CHUNKED
+			 : MIME_TRANSPARENT);
+	} else {
+	    me->state = MIME_IGNORE;	/* What else to do? */
 	}
-    }
-    if (me->target) {
-	me->targetClass = *me->target->isa;
-	/*
-	 * Pump rest of data right through, according to the transfer encoding.
-	 */
-	me->state = (me->chunked_encoding
-		     ? MIME_CHUNKED
-		     : MIME_TRANSPARENT);
-    } else {
-	me->state = MIME_IGNORE;	/* What else to do? */
-    }
-    if (me->refresh_url != NULL && !content_is_compressed(me)) {
-	char *url = NULL;
-	char *num = NULL;
-	char *txt = NULL;
-	const char *base = "";	/* FIXME: refresh_url may be relative to doc */
-
-	LYParseRefreshURL(me->refresh_url, &num, &url);
-	if (url != NULL && me->format == WWW_HTML) {
-	    CTRACE((tfp, "Formatting refresh-url as first line of result\n"));
-	    HTSprintf0(&txt, gettext("Refresh: "));
-	    HTSprintf(&txt, gettext("%s seconds "), num);
-	    dequote(url);
-	    HTSprintf(&txt, "<a href=\"%s%s\">%s</a><br>", base, url, url);
-	    CTRACE((tfp, "URL %s%s\n", base, url));
-	    (me->isa->put_string) (me, txt);
-	    free(txt);
+	if (me->refresh_url != NULL && !content_is_compressed(me)) {
+	    char *url = NULL;
+	    char *num = NULL;
+	    char *txt = NULL;
+	    const char *base = "";	/* FIXME: refresh_url may be relative to doc */
+
+	    LYParseRefreshURL(me->refresh_url, &num, &url);
+	    if (url != NULL && me->format == WWW_HTML) {
+		CTRACE((tfp,
+			"Formatting refresh-url as first line of result\n"));
+		HTSprintf0(&txt, gettext("Refresh: "));
+		HTSprintf(&txt, gettext("%s seconds "), num);
+		dequote(url);
+		HTSprintf(&txt, "<a href=\"%s%s\">%s</a><br>", base, url, url);
+		CTRACE((tfp, "URL %s%s\n", base, url));
+		(me->isa->put_string) (me, txt);
+		free(txt);
+	    }
+	    FREE(num);
+	    FREE(url);
 	}
-	FREE(num);
-	FREE(url);
     }
+    CTRACE((tfp, "...end of pumpData\n"));
     return HT_OK;
 }
 
diff --git a/WWW/Library/Implementation/HTTCP.c b/WWW/Library/Implementation/HTTCP.c
index ee7c52b5..033815f1 100644
--- a/WWW/Library/Implementation/HTTCP.c
+++ b/WWW/Library/Implementation/HTTCP.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTTCP.c,v 1.97 2008/09/20 14:32:29 tom Exp $
+ * $LynxId: HTTCP.c,v 1.98 2008/12/07 21:10:36 tom Exp $
  *
  *			Generic Communication Code		HTTCP.c
  *			==========================
@@ -1548,6 +1548,17 @@ static BOOL HTWasInterrupted(int *status)
     return result;
 }
 
+#define TRIES_PER_SECOND 10
+
+/*
+ * Set the select-timeout to 0.1 seconds.
+ */
+static void set_timeout(struct timeval *timeoutp)
+{
+    timeoutp->tv_sec = 0;
+    timeoutp->tv_usec = 100000;
+}
+
 #ifndef MULTINET		/* SOCKET_ERRNO != errno ? */
 #if !defined(UCX) || !defined(VAXC)	/* errno not modifiable ? */
 #define SOCKET_DEBUG_TRACE	/* show errno status after some system calls */
@@ -1748,7 +1759,7 @@ int HTDoConnect(const char *url,
 		/*
 		 * Protect against an infinite loop.
 		 */
-		if ((tries++ / 10) >= connect_timeout) {
+		if ((tries++ / TRIES_PER_SECOND) >= connect_timeout) {
 		    HTAlert(gettext("Connection failed (too many retries)."));
 #ifdef INET6
 		    FREE(line);
@@ -1757,13 +1768,7 @@ int HTDoConnect(const char *url,
 #endif /* INET6 */
 		    return HT_NO_DATA;
 		}
-#ifdef _WINDOWS_NSL
-		select_timeout.tv_sec = connect_timeout;
-		select_timeout.tv_usec = 0;
-#else
-		select_timeout.tv_sec = 0;
-		select_timeout.tv_usec = 100000;
-#endif /* _WINDOWS_NSL */
+		set_timeout(&select_timeout);
 		FD_ZERO(&writefds);
 		FD_SET((unsigned) *s, &writefds);
 #ifdef SOCKS
@@ -2007,14 +2012,14 @@ int HTDoRead(int fildes,
 	/*
 	 * Protect against an infinite loop.
 	 */
-	if (tries++ >= 180000) {
-	    HTAlert(gettext("Socket read failed for 180,000 tries."));
+	if ((tries++ / TRIES_PER_SECOND) >= reading_timeout) {
+	    HTAlert(gettext("Socket read failed (too many tries)."));
 	    SET_EINTR;
 	    result = HT_INTERRUPTED;
 	    break;
 	}
 #ifdef USE_READPROGRESS
-	if (tries - otries > 10) {
+	if (tries - otries > TRIES_PER_SECOND) {
 	    time_t t = time((time_t *) 0);
 
 	    otries = tries;
@@ -2030,8 +2035,7 @@ int HTDoRead(int fildes,
 	 * Allow for this possibility.  - JED
 	 */
 	do {
-	    select_timeout.tv_sec = 0;
-	    select_timeout.tv_usec = 100000;
+	    set_timeout(&select_timeout);
 	    FD_ZERO(&readfds);
 	    FD_SET((unsigned) fildes, &readfds);
 #ifdef SOCKS
diff --git a/WWW/Library/Implementation/HTUtils.h b/WWW/Library/Implementation/HTUtils.h
index cdc3442d..0bc6a66d 100644
--- a/WWW/Library/Implementation/HTUtils.h
+++ b/WWW/Library/Implementation/HTUtils.h
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTUtils.h,v 1.87 2008/09/17 16:31:34 tom Exp $
+ * $LynxId: HTUtils.h,v 1.89 2008/09/24 00:20:35 tom Exp $
  *
  * Utility macros for the W3 code library
  * MACROS FOR GENERAL USE
@@ -550,15 +550,19 @@ extern int WWW_TraceMask;
 #define PRI_off_t	PRId64
 #define SCN_off_t	SCNd64
 #define CAST_off_t(n)	(int64_t)(n)
-#elif defined(PRId32)
+#elif (SIZEOF_OFF_T == 4) && defined(PRId32)
 #define PRI_off_t	PRId32
 #define SCN_off_t	SCNd32
+#if (SIZEOF_LONG == 4)
+#define CAST_off_t(n)	(long)(n)
+#else
 #define CAST_off_t(n)	(int32_t)(n)
 #endif
 #endif
+#endif
 
 #ifndef PRI_off_t
-#if (SIZEOF_OFF_T == 8)
+#if (SIZEOF_OFF_T > SIZEOF_LONG)
 #define PRI_off_t	"lld"
 #define SCN_off_t	"lld"
 #define CAST_off_t(n)	(long long)(n)
@@ -577,15 +581,19 @@ extern int WWW_TraceMask;
 #define PRI_time_t	PRId64
 #define SCN_time_t	SCNd64
 #define CAST_time_t(n)	(int64_t)(n)
-#elif defined(PRId32)
+#elif (SIZEOF_TIME_T == 4) && defined(PRId32)
 #define PRI_time_t	PRId32
 #define SCN_time_t	SCNd32
+#if (SIZEOF_LONG == 4)
+#define CAST_time_t(n)	(long)(n)
+#else
 #define CAST_time_t(n)	(int32_t)(n)
 #endif
 #endif
+#endif
 
 #ifndef PRI_time_t
-#if (SIZEOF_TIME_T == 8)
+#if (SIZEOF_TIME_T > SIZEOF_LONG)
 #define PRI_time_t	"lld"
 #define SCN_time_t	"lld"
 #define CAST_time_t(n)	(long long)(n)
diff --git a/WWW/Library/Implementation/SGML.c b/WWW/Library/Implementation/SGML.c
index fe8f9ecd..73e762c3 100644
--- a/WWW/Library/Implementation/SGML.c
+++ b/WWW/Library/Implementation/SGML.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: SGML.c,v 1.117 2008/09/21 18:34:39 tom Exp $
+ * $LynxId: SGML.c,v 1.118 2008/09/22 23:21:46 tom Exp $
  *
  *			General SGML Parser code		SGML.c
  *			========================
@@ -1564,7 +1564,7 @@ static void discard_empty(HTStream *context)
 }
 
 #ifdef USE_PRETTYSRC
-static BOOL end_if_prettysrc(HTStream *context, HTChunk *string, int end_ch)
+static BOOL end_if_prettysrc(HTStream *context, HTChunk *string, char end_ch)
 {
     BOOL result = psrc_view;