about summary refs log tree commit diff stats
path: root/WWW/Library/Implementation
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2008-12-14 20:04:30 -0500
committerThomas E. Dickey <dickey@invisible-island.net>2008-12-14 20:04:30 -0500
commitda2bf8f62108075b8a876b8ad1d881370162bbcf (patch)
treec712a78bcb05f0e919a03f833b6337f35b915a05 /WWW/Library/Implementation
parent5bbfb76d074c9acc27ac789ff721a5ebd609a55f (diff)
downloadlynx-snapshots-da2bf8f62108075b8a876b8ad1d881370162bbcf.tar.gz
snapshot of project "lynx", label v2-8-7dev_10e
Diffstat (limited to 'WWW/Library/Implementation')
-rw-r--r--WWW/Library/Implementation/HTFormat.c4
-rw-r--r--WWW/Library/Implementation/HTMIME.c3
-rw-r--r--WWW/Library/Implementation/HTParse.c88
-rw-r--r--WWW/Library/Implementation/HTParse.h17
-rw-r--r--WWW/Library/Implementation/HTTP.c33
-rw-r--r--WWW/Library/Implementation/HTUtils.h20
-rw-r--r--WWW/Library/Implementation/HTVMS_WaisUI.c9
7 files changed, 116 insertions, 58 deletions
diff --git a/WWW/Library/Implementation/HTFormat.c b/WWW/Library/Implementation/HTFormat.c
index 0aaead00..4a02c57e 100644
--- a/WWW/Library/Implementation/HTFormat.c
+++ b/WWW/Library/Implementation/HTFormat.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTFormat.c,v 1.64 2008/12/07 15:53:54 tom Exp $
+ * $LynxId: HTFormat.c,v 1.65 2008/12/14 17:11:58 tom Exp $
  *
  *		Manage different file formats			HTFormat.c
  *		=============================
@@ -1157,7 +1157,7 @@ static int HTZzFileCopy(FILE *zzfp, HTStream *sink)
     status = inflateInit(&s);
     if (status != Z_OK) {
 	CTRACE((tfp, "HTZzFileCopy inflateInit() %s\n", zError(status)));
-	exit_immediately(1);
+	exit_immediately(EXIT_FAILURE);
     }
     s.avail_in = 0;
     s.next_out = (Bytef *) output_buffer;
diff --git a/WWW/Library/Implementation/HTMIME.c b/WWW/Library/Implementation/HTMIME.c
index 6f3fb58b..bda69913 100644
--- a/WWW/Library/Implementation/HTMIME.c
+++ b/WWW/Library/Implementation/HTMIME.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTMIME.c,v 1.66 2008/12/07 20:23:52 tom Exp $
+ * $LynxId: HTMIME.c,v 1.67 2008/12/14 18:46:52 tom Exp $
  *
  *			MIME Message Parse			HTMIME.c
  *			==================
@@ -1089,6 +1089,7 @@ static void HTMIME_put_character(HTStream *me,
 	if (c == CR) {
 	    return;
 	}
+	/* FALLTHRU */
 
     case mcCHUNKED_DATA_LF:
 	me->state = MIME_CHUNKED;
diff --git a/WWW/Library/Implementation/HTParse.c b/WWW/Library/Implementation/HTParse.c
index bf0b9665..33a4154a 100644
--- a/WWW/Library/Implementation/HTParse.c
+++ b/WWW/Library/Implementation/HTParse.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTParse.c,v 1.48 2008/01/10 00:57:31 tom Exp $
+ * $LynxId: HTParse.c,v 1.50 2008/12/14 15:38:54 tom Exp $
  *
  *		Parse HyperText Document Address		HTParse.c
  *		================================
@@ -194,6 +194,46 @@ static char *strchr_or_end(char *string, int ch)
     return result;
 }
 
+/*
+ * Given a host specification that may end with a port number, e.g.,
+ *	foobar:123
+ * point to the ':' which begins the ":port" to make it simple to handle the
+ * substring.
+ *
+ * If no port is found (or a syntax error), return null.
+ */
+char *HTParsePort(char *host, int *portp)
+{
+    int brackets = 0;
+    char *result = NULL;
+
+    *portp = 0;
+    if (host != NULL) {
+	while (*host != '\0' && result == 0) {
+	    switch (*host++) {
+	    case ':':
+		if (brackets == 0 && isdigit(UCH(*host))) {
+		    char *next = NULL;
+
+		    *portp = strtol(host, &next, 10);
+		    if (next != 0 && next != host && *next == '\0') {
+			result = (host - 1);
+			CTRACE((tfp, "HTParsePort %d\n", *portp));
+		    }
+		}
+		break;
+	    case '[':		/* for ipv6 */
+		++brackets;
+		break;
+	    case ']':		/* for ipv6 */
+		--brackets;
+		break;
+	    }
+	}
+    }
+    return result;
+}
+
 /*	Parse a Name relative to another name.			HTParse()
  *	--------------------------------------
  *
@@ -356,37 +396,33 @@ char *HTParse(const char *aName,
 	     */
 	    {
 		char *p2, *h;
+		int portnumber;
 
 		if ((p2 = strchr(result, '@')) != NULL)
 		    tail = (p2 + 1);
-		p2 = strchr(tail, ':');
-		if (p2 != NULL && !isdigit(UCH(p2[1])))
-		    /*
-		     * Colon not followed by a port number.
-		     */
-		    *p2 = '\0';
-		if (p2 != NULL && *p2 != '\0' && acc_method != NULL) {
+		p2 = HTParsePort(result, &portnumber);
+		if (p2 != NULL && acc_method != NULL) {
 		    /*
 		     * Port specified.
 		     */
-#define ACC_METHOD(a,b) (!strcmp(acc_method, a) && !strcmp(p2, b))
-		    if (ACC_METHOD("http", ":80") ||
-			ACC_METHOD("https", ":443") ||
-			ACC_METHOD("gopher", ":70") ||
-			ACC_METHOD("ftp", ":21") ||
-			ACC_METHOD("wais", ":210") ||
-			ACC_METHOD("nntp", ":119") ||
-			ACC_METHOD("news", ":119") ||
-			ACC_METHOD("newspost", ":119") ||
-			ACC_METHOD("newsreply", ":119") ||
-			ACC_METHOD("snews", ":563") ||
-			ACC_METHOD("snewspost", ":563") ||
-			ACC_METHOD("snewsreply", ":563") ||
-			ACC_METHOD("finger", ":79") ||
-			ACC_METHOD("telnet", ":23") ||
-			ACC_METHOD("tn3270", ":23") ||
-			ACC_METHOD("rlogin", ":513") ||
-			ACC_METHOD("cso", ":105"))
+#define ACC_METHOD(a,b) (!strcmp(acc_method, a) && (portnumber == b))
+		    if (ACC_METHOD("http", 80) ||
+			ACC_METHOD("https", 443) ||
+			ACC_METHOD("gopher", 70) ||
+			ACC_METHOD("ftp", 21) ||
+			ACC_METHOD("wais", 210) ||
+			ACC_METHOD("nntp", 119) ||
+			ACC_METHOD("news", 119) ||
+			ACC_METHOD("newspost", 119) ||
+			ACC_METHOD("newsreply", 119) ||
+			ACC_METHOD("snews", 563) ||
+			ACC_METHOD("snewspost", 563) ||
+			ACC_METHOD("snewsreply", 563) ||
+			ACC_METHOD("finger", 79) ||
+			ACC_METHOD("telnet", 23) ||
+			ACC_METHOD("tn3270", 23) ||
+			ACC_METHOD("rlogin", 513) ||
+			ACC_METHOD("cso", 105))
 			*p2 = '\0';	/* It is the default: ignore it */
 		}
 		if (p2 == NULL) {
diff --git a/WWW/Library/Implementation/HTParse.h b/WWW/Library/Implementation/HTParse.h
index cb95d722..b6c368fe 100644
--- a/WWW/Library/Implementation/HTParse.h
+++ b/WWW/Library/Implementation/HTParse.h
@@ -1,4 +1,6 @@
-/*                                   HTParse:  URL parsing in the WWW Library
+/*
+ * $LynxId: HTParse.h,v 1.19 2008/12/14 15:31:47 tom Exp $
+ *				HTParse:  URL parsing in the WWW Library
  *				HTPARSE
  *
  *  This module of the WWW library contains code to parse URLs and various
@@ -50,6 +52,19 @@ extern "C" {
  *	All trailing white space is OVERWRITTEN with zero.
  */ extern char *HTStrip(char *s);
 
+/*
+ *	Parse a port number
+ *	-------------------
+ *
+ * On entry,
+ *	host            A pointer to hostname possibly followed by port
+ *
+ * On exit,
+ *	returns         A pointer to the ":" before the port
+ *	sets            the port number via the pointer portp.
+ */
+    extern char *HTParsePort(char *host, int *portp);
+
 /*	Parse a Name relative to another name.			HTParse()
  *	--------------------------------------
  *
diff --git a/WWW/Library/Implementation/HTTP.c b/WWW/Library/Implementation/HTTP.c
index 6f016442..2aa7e850 100644
--- a/WWW/Library/Implementation/HTTP.c
+++ b/WWW/Library/Implementation/HTTP.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTTP.c,v 1.96 2008/07/06 12:55:40 tom Exp $
+ * $LynxId: HTTP.c,v 1.99 2008/12/14 18:05:36 tom Exp $
  *
  * HyperText Tranfer Protocol	- Client implementation		HTTP.c
  * ==========================
@@ -530,6 +530,7 @@ static int HTLoadHTTP(const char *arg,
     char ssl_dn[1024];
     char *cert_host;
     char *ssl_host;
+    int port_number;
     char *p;
     char *msg = NULL;
     int status_sslcertcheck;
@@ -566,10 +567,12 @@ static int HTLoadHTTP(const char *arg,
     }
 #ifdef USE_SSL
     if (using_proxy && !strncmp(url, "http://", 7)) {
+	int portnumber;
+
 	if ((connect_url = strstr((url + 7), "https://"))) {
 	    do_connect = TRUE;
 	    connect_host = HTParse(connect_url, "https", PARSE_HOST);
-	    if (!strchr(connect_host, ':')) {
+	    if (!HTParsePort(connect_host, &portnumber)) {
 		sprintf(temp, ":%d", HTTPS_PORT);
 		StrAllocCat(connect_host, temp);
 	    }
@@ -578,7 +581,7 @@ static int HTLoadHTTP(const char *arg,
 	} else if ((connect_url = strstr((url + 7), "snews://"))) {
 	    do_connect = TRUE;
 	    connect_host = HTParse(connect_url, "snews", PARSE_HOST);
-	    if (!strchr(connect_host, ':')) {
+	    if (!HTParsePort(connect_host, &portnumber)) {
 		sprintf(temp, ":%d", SNEWS_PORT);
 		StrAllocCat(connect_host, temp);
 	    }
@@ -773,10 +776,8 @@ static int HTLoadHTTP(const char *arg,
 	/* get host we're connecting to */
 	ssl_host = HTParse(url, "", PARSE_HOST);
 	/* strip port number or extract hostname component */
-	if ((p = strchr(ssl_host, (ssl_host[0] == '[') ? ']' : ':')) != NULL)
+	if ((p = HTParsePort(ssl_host, &port_number)) != 0)
 	    *p = '\0';
-	if (ssl_host[0] == '[')
-	    ssl_host++;
 
 	/* validate all CNs found in DN */
 	CTRACE((tfp, "Validating CNs in '%s'\n", ssl_dn_start));
@@ -791,11 +792,8 @@ static int HTLoadHTTP(const char *arg,
 	    } else
 		ssl_dn_start = NULL;
 	    /* strip port number (XXX [ip]:port encap here too? -TG) */
-	    if ((p = strchr(cert_host,
-			    (cert_host[0] == '[') ? ']' : ':')) != NULL)
+	    if ((p = HTParsePort(cert_host, &port_number)) != 0)
 		*p = '\0';
-	    if (cert_host[0] == '[')
-		cert_host++;
 
 	    /* verify this CN */
 	    CTRACE((tfp, "Matching\n\tssl_host  '%s'\n\tcert_host '%s'\n",
@@ -889,11 +887,8 @@ static int HTLoadHTTP(const char *arg,
 			continue;
 		    status_sslcertcheck = 1;	/* got at least one */
 		    /* verify this SubjectAltName (see above) */
-		    if ((p = strchr(cert_host,
-				    (cert_host[0] == '[') ? ']' : ':')) != NULL)
+		    if ((p = HTParsePort(cert_host, &port_number)) != 0)
 			*p = '\0';
-		    if (cert_host[0] == '[')
-			cert_host++;
 		    if (!(gn->type == GEN_IPADD ? strcasecomp :
 			  strcasecomp_asterisk) (ssl_host, cert_host)) {
 			status_sslcertcheck = 2;
@@ -1208,9 +1203,8 @@ static int HTLoadHTTP(const char *arg,
 	    docname = HTParse(arg, "", PARSE_PATH);
 	    hostname = HTParse(arg, "", PARSE_HOST);
 	    if (hostname &&
-		NULL != (colon = strchr(hostname, ':'))) {
-		*(colon++) = '\0';	/* Chop off port number */
-		portnumber = atoi(colon);
+		NULL != (colon = HTParsePort(hostname, &portnumber))) {
+		*colon = '\0';	/* Chop off port number */
 	    } else if (!strncmp(arg, "https", 5)) {
 		portnumber = HTTPS_PORT;
 	    } else {
@@ -1234,11 +1228,9 @@ static int HTLoadHTTP(const char *arg,
 		host2 = HTParse(docname, "", PARSE_HOST);
 		path2 = HTParse(docname, "", PARSE_PATH | PARSE_PUNCTUATION);
 		if (host2) {
-		    if ((colon = strchr(host2, ':')) != NULL) {
+		    if ((colon = HTParsePort(host2, &port2)) != NULL) {
 			/* Use non-default port number */
 			*colon = '\0';
-			colon++;
-			port2 = atoi(colon);
 		    }
 		}
 		/*
@@ -2441,6 +2433,7 @@ static int HTLoadHTTP(const char *arg,
 	SSL_handle = handle = NULL;
     }
 #endif /* USE_SSL */
+    dump_server_status = server_status;
     return status;
 }
 
diff --git a/WWW/Library/Implementation/HTUtils.h b/WWW/Library/Implementation/HTUtils.h
index 0bc6a66d..5cd1bef6 100644
--- a/WWW/Library/Implementation/HTUtils.h
+++ b/WWW/Library/Implementation/HTUtils.h
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTUtils.h,v 1.89 2008/09/24 00:20:35 tom Exp $
+ * $LynxId: HTUtils.h,v 1.90 2008/12/14 19:34:34 tom Exp $
  *
  * Utility macros for the W3 code library
  * MACROS FOR GENERAL USE
@@ -547,17 +547,24 @@ extern int WWW_TraceMask;
  */
 #if defined(HAVE_INTTYPES_H) && defined(SIZEOF_OFF_T)
 #if (SIZEOF_OFF_T == 8) && defined(PRId64)
+
 #define PRI_off_t	PRId64
 #define SCN_off_t	SCNd64
 #define CAST_off_t(n)	(int64_t)(n)
+
 #elif (SIZEOF_OFF_T == 4) && defined(PRId32)
+
 #define PRI_off_t	PRId32
 #define SCN_off_t	SCNd32
-#if (SIZEOF_LONG == 4)
+
+#if (SIZEOF_INT == 4)
+#define CAST_off_t(n)	(int)(n)
+#elif (SIZEOF_LONG == 4)
 #define CAST_off_t(n)	(long)(n)
 #else
 #define CAST_off_t(n)	(int32_t)(n)
 #endif
+
 #endif
 #endif
 
@@ -578,17 +585,24 @@ extern int WWW_TraceMask;
  */
 #if defined(HAVE_INTTYPES_H) && defined(SIZEOF_TIME_T)
 #if (SIZEOF_TIME_T == 8) && defined(PRId64)
+
 #define PRI_time_t	PRId64
 #define SCN_time_t	SCNd64
 #define CAST_time_t(n)	(int64_t)(n)
+
 #elif (SIZEOF_TIME_T == 4) && defined(PRId32)
+
 #define PRI_time_t	PRId32
 #define SCN_time_t	SCNd32
-#if (SIZEOF_LONG == 4)
+
+#if (SIZEOF_INT == 4)
+#define CAST_time_t(n)	(int)(n)
+#elif (SIZEOF_LONG == 4)
 #define CAST_time_t(n)	(long)(n)
 #else
 #define CAST_time_t(n)	(int32_t)(n)
 #endif
+
 #endif
 #endif
 
diff --git a/WWW/Library/Implementation/HTVMS_WaisUI.c b/WWW/Library/Implementation/HTVMS_WaisUI.c
index 31bfa4fb..f46b4372 100644
--- a/WWW/Library/Implementation/HTVMS_WaisUI.c
+++ b/WWW/Library/Implementation/HTVMS_WaisUI.c
@@ -1,4 +1,6 @@
-/*							HTVMS_WAISUI.c
+/*
+ * $LynxId: HTVMS_WaisUI.c,v 1.15 2008/12/14 18:06:19 tom Exp $
+ *								HTVMS_WAISUI.c
  *
  *	Adaptation for Lynx by F.Macrides (macrides@sci.wfeb.edu)
  *
@@ -2119,10 +2121,7 @@ static void exitAction(long error);
 
 static void exitAction(long error GCC_UNUSED)
 {
-    long i;
-
-    for (i = 0; i < 100000; i++) ;
-    exit_immediately(0);
+    exit_immediately(EXIT_SUCCESS);
 }
 
 /*----------------------------------------------------------------------*/