about summary refs log tree commit diff stats
path: root/WWW/Library/Implementation/HTNews.c
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>1998-11-06 16:18:09 -0500
committerThomas E. Dickey <dickey@invisible-island.net>1998-11-06 16:18:09 -0500
commit18024037b515bfff83e0230b35151babe6005e18 (patch)
treeb8c80055282a00883284722a3dd6bb25234e07f0 /WWW/Library/Implementation/HTNews.c
parent3d8ecbe48af249fa0d77ce4d273e32ce4b7e6e18 (diff)
downloadlynx-snapshots-18024037b515bfff83e0230b35151babe6005e18.tar.gz
snapshot of project "lynx", label v2-8-1dev_4
Diffstat (limited to 'WWW/Library/Implementation/HTNews.c')
-rw-r--r--WWW/Library/Implementation/HTNews.c196
1 files changed, 146 insertions, 50 deletions
diff --git a/WWW/Library/Implementation/HTNews.c b/WWW/Library/Implementation/HTNews.c
index 331b4fa7..89048385 100644
--- a/WWW/Library/Implementation/HTNews.c
+++ b/WWW/Library/Implementation/HTNews.c
@@ -7,6 +7,7 @@
 */
 
 #include <HTUtils.h>		/* Coding convention macros */
+#include <tcp.h>
 
 /* Implements:
 */
@@ -15,7 +16,8 @@
 #include <HTCJK.h>
 #include <HTMIME.h>
 #include <HTTCP.h>
-#include <LYUtils.h>
+
+#define FREE(x) if (x) {free(x); x = NULL;}
 
 /* this define should be in HTFont.h :( */
 #define HT_NON_BREAK_SPACE ((char)1)   /* For now */
@@ -37,6 +39,8 @@ PUBLIC int HTNewsMaxChunk = 40; /* Largest number of articles in one window */
 #define NEWS_NETCLOSE  NETCLOSE
 #define NEXT_CHAR HTGetCharacter()
 
+#include <ctype.h>
+
 #include <HTML.h>
 #include <HTParse.h>
 #include <HTFormat.h>
@@ -185,16 +189,17 @@ PRIVATE BOOL initialize NOARGS
 #else
     if (getenv("NNTPSERVER")) {
 	StrAllocCopy(HTNewsHost, (char *)getenv("NNTPSERVER"));
-	CTRACE(tfp, "HTNews: NNTPSERVER defined as `%s'\n",
-		    HTNewsHost);
+	if (TRACE) fprintf(stderr, "HTNews: NNTPSERVER defined as `%s'\n",
+		HTNewsHost);
     } else {
 	char server_name[256];
 	FILE* fp = fopen(SERVER_FILE, "r");
 	if (fp) {
 	    if (fscanf(fp, "%s", server_name)==1) {
 		StrAllocCopy(HTNewsHost, server_name);
-		CTRACE(tfp, "HTNews: File %s defines news host as `%s'\n",
-			    SERVER_FILE, HTNewsHost);
+		if (TRACE) fprintf(stderr,
+		"HTNews: File %s defines news host as `%s'\n",
+			SERVER_FILE, HTNewsHost);
 	    }
 	    fclose(fp);
 	}
@@ -227,7 +232,7 @@ PRIVATE int response ARGS1(CONST char *,command)
     if (command) {
 	int status;
 	int length = strlen(command);
-	CTRACE(tfp, "NNTP command to be sent: %s", command);
+	if (TRACE) fprintf(stderr, "NNTP command to be sent: %s", command);
 #ifdef NOT_ASCII
 	{
 	    CONST char	* p;
@@ -242,7 +247,8 @@ PRIVATE int response ARGS1(CONST char *,command)
 	status = NEWS_NETWRITE(s, (char *)command, length);
 #endif /* NOT_ASCII */
 	if (status < 0){
-	    CTRACE(tfp, "HTNews: Unable to send command. Disconnecting.\n");
+	    if (TRACE) fprintf(stderr,
+		"HTNews: Unable to send command. Disconnecting.\n");
 	    NEWS_NETCLOSE(s);
 	    s = -1;
 	    return status;
@@ -253,19 +259,24 @@ PRIVATE int response ARGS1(CONST char *,command)
 	if (((*p++ = NEXT_CHAR) == LF) ||
 	    (p == &response_text[LINE_LENGTH])) {
 	    *--p = '\0';			/* Terminate the string */
-	    CTRACE(tfp, "NNTP Response: %s\n", response_text);
+	    if (TRACE)
+		fprintf(stderr, "NNTP Response: %s\n", response_text);
 	    sscanf(response_text, "%d", &result);
 	    return result;
 	} /* if end of line */
 
 	if ((ch = *(p-1)) == (char)EOF) {
 	    *(p-1) = '\0';
-	    if (interrupted_in_htgetcharacter) {
-		CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
+	    if (TRACE) {
+		if (interrupted_in_htgetcharacter) {
+		    fprintf(stderr,
+			    "HTNews: Interrupted on read, closing socket %d\n",
 			    s);
-	    } else {
-		CTRACE(tfp, "HTNews: EOF on read, closing socket %d\n",
+		} else {
+		    fprintf(stderr,
+			    "HTNews: EOF on read, closing socket %d\n",
 			    s);
+		}
 	    }
 	    NEWS_NETCLOSE(s);	/* End of file, close socket */
 	    s = -1;
@@ -549,7 +560,8 @@ PRIVATE char * author_name ARGS1 (char *,email)
     char *p, *e;
 
     StrAllocCopy(name, email);
-    CTRACE(tfp,"Trying to find name in: %s\n",name);
+    if (TRACE)
+	fprintf(stderr,"Trying to find name in: %s\n",name);
 
     if ((p = strchr(name, '(')) && (e = strchr(name, ')'))) {
 	if (e > p) {
@@ -586,7 +598,8 @@ PRIVATE char * author_address ARGS1(char *,email)
     char *p, *at, *e;
 
     StrAllocCopy(address, email);
-    CTRACE(tfp,"Trying to find address in: %s\n",address);
+    if (TRACE)
+	fprintf(stderr,"Trying to find address in: %s\n",address);
 
     if ((p = strchr(address, '<'))) {
 	if ((e = strchr(p, '>')) && (at = strchr(p, '@'))) {
@@ -757,7 +770,9 @@ PRIVATE void write_anchors ARGS1 (char *,text)
 */
 PRIVATE void abort_socket NOARGS
 {
-    CTRACE(tfp, "HTNews: EOF on read, closing socket %d\n", s);
+    if (TRACE)
+	fprintf(stderr,
+		"HTNews: EOF on read, closing socket %d\n", s);
     NEWS_NETCLOSE(s);	/* End of file, close socket */
     PUTS("Network Error: connection lost");
     PUTC('\n');
@@ -894,7 +909,12 @@ PRIVATE void post_article ARGS1(
 	}
     }
     fclose(fd);
-    HTSYS_remove(postfile);
+#ifdef VMS
+    while (remove(postfile) == 0)
+	; /* loop through all versions */
+#else
+    remove(postfile);
+#endif /* VMS */
 
     /*
     **	Send the nntp EOF and get the server's response. - FM
@@ -963,7 +983,9 @@ PRIVATE int read_article NOARGS
 	    if (ch == (char)EOF) {
 		if (interrupted_in_htgetcharacter) {
 		    interrupted_in_htgetcharacter = 0;
-		    CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
+		    if (TRACE)
+			fprintf(stderr,
+			   "HTNews: Interrupted on read, closing socket %d\n",
 				s);
 		    NEWS_NETCLOSE(s);
 		    s = -1;
@@ -974,7 +996,8 @@ PRIVATE int read_article NOARGS
 	    }
 	    if ((ch == LF) || (p == &line[LINE_LENGTH])) {
 		*--p = '\0';			/* Terminate the string */
-		CTRACE(tfp, "H %s\n", line);
+		if (TRACE)
+		    fprintf(stderr, "H %s\n", line);
 
 		if (line[0] == '\t' || line[0] == ' ') {
 		    int i = 0;
@@ -1230,7 +1253,9 @@ PRIVATE int read_article NOARGS
 	if (ch == (char)EOF) {
 	    if (interrupted_in_htgetcharacter) {
 		interrupted_in_htgetcharacter = 0;
-		CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
+		if (TRACE)
+		    fprintf(stderr,
+			  "HTNews: Interrupted on read, closing socket %d\n",
 			    s);
 		NEWS_NETCLOSE(s);
 		s = -1;
@@ -1241,7 +1266,8 @@ PRIVATE int read_article NOARGS
 	}
 	if ((ch == LF) || (p == &line[LINE_LENGTH])) {
 	    *p++ = '\0';			/* Terminate the string */
-	    CTRACE(tfp, "B %s", line);
+	    if (TRACE)
+		fprintf(stderr, "B %s", line);
 	    if (line[0] == '.') {
 		/*
 		**  End of article?
@@ -1434,7 +1460,9 @@ PRIVATE int read_list ARGS1(char *, arg)
 	if (ch == (char)EOF) {
 	    if (interrupted_in_htgetcharacter) {
 		interrupted_in_htgetcharacter = 0;
-		CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
+		if (TRACE)
+		    fprintf(stderr,
+			  "HTNews: Interrupted on read, closing socket %d\n",
 			    s);
 		NEWS_NETCLOSE(s);
 		s = -1;
@@ -1454,7 +1482,9 @@ PRIVATE int read_list ARGS1(char *, arg)
 		continue;
 	    }
 	} else if (p == &line[LINE_LENGTH]) {
-	    CTRACE(tfp, "b %.*s%c[...]\n", (LINE_LENGTH), line, ch);
+	    if (TRACE) {
+		fprintf(stderr, "b %.*s%c[...]\n", (LINE_LENGTH), line, ch);
+	    }
 	    *p = '\0';
 	    if (ch == LF) {
 		;		/* Will be dealt with below */
@@ -1464,7 +1494,9 @@ PRIVATE int read_list ARGS1(char *, arg)
 	    } else if (strchr(line, ' ') == NULL &&
 		       strchr(line, '\t') == NULL) {
 		/* No separator found */
-		CTRACE(tfp, "HTNews..... group name too long, discarding.\n");
+		if (TRACE)
+		    fprintf(stderr,
+			    "HTNews..... group name too long, discarding.\n");
 		skip_this_line = YES; /* ignore whole line */
 		continue;
 	    } else {
@@ -1476,7 +1508,8 @@ PRIVATE int read_list ARGS1(char *, arg)
 	if (ch == LF) {
 	    skip_rest_of_line = NO;	/* done, reset flag */
 	    *p = '\0';			/* Terminate the string */
-	    CTRACE(tfp, "B %s", line);
+	    if (TRACE)
+		fprintf(stderr, "B %s", line);
 	    if (line[0] == '.') {
 		/*
 		**  End of article?
@@ -1584,7 +1617,9 @@ PRIVATE int read_group ARGS3(
     PUTC('\n');
 
     sscanf(response_text, " %d %d %d %d", &status, &count, &first, &last);
-    CTRACE(tfp, "Newsgroup status=%d, count=%d, (%d-%d) required:(%d-%d)\n",
+    if (TRACE)
+	fprintf(stderr,
+		"Newsgroup status=%d, count=%d, (%d-%d) required:(%d-%d)\n",
 		status, count, first, last, first_required, last_required);
     if (last == 0) {
 	PUTS("\nNo articles in this group.\n");
@@ -1607,8 +1642,9 @@ PRIVATE int read_group ARGS3(
     if (last_required-first_required+1 > HTNewsMaxChunk) { /* Trim this block */
 	first_required = last_required-HTNewsChunkSize+1;
     }
-    CTRACE(tfp, "    Chunk will be (%d-%d)\n",
-		first_required, last_required);
+    if (TRACE)
+	fprintf(stderr, "    Chunk will be (%d-%d)\n",
+			first_required, last_required);
 
     /*
     **	Set window title.
@@ -1631,7 +1667,8 @@ PRIVATE int read_group ARGS3(
 	    before = first_required-HTNewsChunkSize;
 	sprintf(buffer, "%s%s/%d-%d", NewsHREF, groupName,
 				      before, first_required-1);
-	CTRACE(tfp, "    Block before is %s\n", buffer);
+	if (TRACE)
+	    fprintf(stderr, "    Block before is %s\n", buffer);
 	PUTC('(');
 	start_anchor(buffer);
 	PUTS("Earlier articles");
@@ -1659,7 +1696,9 @@ PRIVATE int read_group ARGS3(
 		if (ch == (char)EOF) {
 		    if (interrupted_in_htgetcharacter) {
 			interrupted_in_htgetcharacter = 0;
-			CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
+			if (TRACE)
+			    fprintf(stderr,
+			   "HTNews: Interrupted on read, closing socket %d\n",
 				    s);
 			NEWS_NETCLOSE(s);
 			s = -1;
@@ -1670,7 +1709,8 @@ PRIVATE int read_group ARGS3(
 		}
 		if ((ch == '\n') || (p == &line[LINE_LENGTH])) {
 		    *p = '\0';		/* Terminate the string */
-		    CTRACE(tfp, "X %s", line);
+		    if (TRACE)
+			fprintf(stderr, "X %s", line);
 		    if (line[0] == '.') {
 			/*
 			**  End of article?
@@ -1762,7 +1802,9 @@ PRIVATE int read_group ARGS3(
 		    if (ch == (char)EOF) {
 			if (interrupted_in_htgetcharacter) {
 			    interrupted_in_htgetcharacter = 0;
-			    CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
+			    if (TRACE)
+				fprintf(stderr,
+			   "HTNews: Interrupted on read, closing socket %d\n",
 					s);
 			    NEWS_NETCLOSE(s);
 			    s = -1;
@@ -1776,7 +1818,8 @@ PRIVATE int read_group ARGS3(
 
 			*--p = '\0';		/* Terminate  & chop LF*/
 			p = line;		/* Restart at beginning */
-			CTRACE(tfp, "G %s\n", line);
+			if (TRACE)
+			    fprintf(stderr, "G %s\n", line);
 			switch(line[0]) {
 
 			case '.':
@@ -1870,7 +1913,9 @@ PRIVATE int read_group ARGS3(
 		*/
 	    } else if (status == HT_INTERRUPTED) {
 		interrupted_in_htgetcharacter = 0;
-		CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
+		if (TRACE)
+		    fprintf(stderr,
+			  "HTNews: Interrupted on read, closing socket %d\n",
 			    s);
 		NEWS_NETCLOSE(s);
 		s = -1;
@@ -1912,7 +1957,8 @@ PRIVATE int read_group ARGS3(
 	else
 	    sprintf(buffer, "%s%s/%d-%d", NewsHREF, groupName,
 					  last_required+1, after);
-	CTRACE(tfp, "    Block after is %s\n", buffer);
+	if (TRACE)
+	    fprintf(stderr, "    Block after is %s\n", buffer);
 	PUTC('(');
 	start_anchor(buffer);
 	PUTS("Later articles");
@@ -1983,7 +2029,7 @@ PRIVATE int HTLoadNews ARGS4(
 		  format_out == HTAtom_for("www/dump"));
     rawtext = NO;
 
-    CTRACE(tfp, "HTNews: Looking for %s\n", arg);
+    if (TRACE) fprintf(stderr, "HTNews: Looking for %s\n", arg);
 
     if (!initialized)
 	initialized = initialize();
@@ -2184,7 +2230,9 @@ PRIVATE int HTLoadNews ARGS4(
 	    command[258] = '\0';
 	    FREE(cp);
 	    sprintf(proxycmd, "GET %.251s%c%c%c%c", command, CR, LF, CR, LF);
-	    CTRACE(tfp, "HTNews: Proxy command is '%.*s'\n",
+	    if (TRACE)
+		fprintf(stderr,
+			"HTNews: Proxy command is '%.*s'\n",
 			(int)(strlen(proxycmd) - 4), proxycmd);
 	    strcat(command, "/");
 	    StrAllocCopy(ProxyHREF, NewsHREF);
@@ -2326,7 +2374,8 @@ PRIVATE int HTLoadNews ARGS4(
 	    } else {
 		sprintf (url, "%.259s", NewsHREF);
 	    }
-	    CTRACE (tfp, "News: doing HTDoConnect on '%s'\n", url);
+	    if (TRACE)
+		fprintf (stderr, "News: doing HTDoConnect on '%s'\n", url);
 
 	    _HTProgress("Connecting to NewsHost ...");
 
@@ -2335,7 +2384,9 @@ PRIVATE int HTLoadNews ARGS4(
 		/*
 		**  Interrupt cleanly.
 		*/
-		CTRACE(tfp, "HTNews: Interrupted on connect; recovering cleanly.\n");
+		if (TRACE)
+		    fprintf(stderr,
+		     "HTNews: Interrupted on connect; recovering cleanly.\n");
 		_HTProgress("Connection interrupted.");
 		if (!(post_wanted || reply_wanted ||
 		      spost_wanted || sreply_wanted)) {
@@ -2347,7 +2398,12 @@ PRIVATE int HTLoadNews ARGS4(
 		FREE(ProxyHREF);
 		FREE(ListArg);
 		if (postfile) {
-		    HTSYS_remove(postfile);
+#ifdef VMS
+		    while (remove(postfile) == 0)
+			; /* loop through all versions */
+#else
+		    remove(postfile);
+#endif /* VMS */
 		    FREE(postfile);
 		}
 		return HT_NOT_LOADED;
@@ -2356,7 +2412,9 @@ PRIVATE int HTLoadNews ARGS4(
 		char message[256];
 		NEWS_NETCLOSE(s);
 		s = -1;
-		CTRACE(tfp, "HTNews: Unable to connect to news host.\n");
+		if (TRACE)
+		    fprintf(stderr,
+			    "HTNews: Unable to connect to news host.\n");
 		if (retries < 1)
 		    continue;
 		sprintf(message, "Could not access %s.", NewsHost);
@@ -2366,17 +2424,25 @@ PRIVATE int HTLoadNews ARGS4(
 		FREE(ProxyHREF);
 		FREE(ListArg);
 		if (postfile) {
-		    HTSYS_remove(postfile);
+#ifdef VMS
+		    while (remove(postfile) == 0)
+			; /* loop through all versions */
+#else
+		    remove(postfile);
+#endif /* VMS */
 		    FREE(postfile);
 		}
 		return HTLoadError(stream, 500, message);
 	    } else {
-		CTRACE(tfp, "HTNews: Connected to news host %s.\n",
-			    NewsHost);
+		if (TRACE)
+		    fprintf(stderr, "HTNews: Connected to news host %s.\n",
+				    NewsHost);
 		HTInitInput(s); 	/* set up buffering */
 		if (proxycmd[0]) {
 		    status = NEWS_NETWRITE(s, proxycmd, strlen(proxycmd));
-		    CTRACE(tfp, "HTNews: Proxy command returned status '%d'.\n",
+		    if (TRACE)
+			fprintf(stderr,
+			     "HTNews: Proxy command returned status '%d'.\n",
 				status);
 		}
 		if (((status = response(NULL)) / 100) != 2) {
@@ -2395,7 +2461,12 @@ PRIVATE int HTLoadNews ARGS4(
 			    FREE(ProxyHREF);
 			    FREE(ListArg);
 			    if (postfile) {
-				HTSYS_remove(postfile);
+#ifdef VMS
+				while (remove(postfile) == 0)
+				    ; /* loop through all versions */
+#else
+				remove(postfile);
+#endif /* VMS */
 				FREE(postfile);
 			    }
 			    return(HT_NOT_LOADED);
@@ -2422,7 +2493,12 @@ PRIVATE int HTLoadNews ARGS4(
 			}
 			FREE(ListArg);
 			if (postfile) {
-			    HTSYS_remove(postfile);
+#ifdef VMS
+			    while (remove(postfile) == 0)
+				; /* loop through all versions */
+#else
+			    remove(postfile);
+#endif /* VMS */
 			    FREE(postfile);
 			}
 			return(HT_NOT_LOADED);
@@ -2443,7 +2519,12 @@ PRIVATE int HTLoadNews ARGS4(
 		}
 		FREE(ListArg);
 		if (postfile) {
-		    HTSYS_remove(postfile);
+#ifdef VMS
+		    while (remove(postfile) == 0)
+			; /* loop through all versions */
+#else
+		    remove(postfile);
+#endif /* VMS */
 		    FREE(postfile);
 		}
 		return(HT_NOT_LOADED);
@@ -2588,7 +2669,12 @@ Send_NNTP_command:
 	    if (status != 340) {
 		HTAlert("Cannot POST to this host.");
 		if (postfile) {
-		    HTSYS_remove(postfile);
+#ifdef VMS
+		    while (remove(postfile) == 0)
+			; /* loop through all versions */
+#else
+		    remove(postfile);
+#endif /* VMS */
 		}
 	    } else {
 		post_article(postfile);
@@ -2650,7 +2736,12 @@ Send_NNTP_command:
 	}
 	FREE(ListArg);
 	if (postfile) {
-	    HTSYS_remove(postfile);
+#ifdef VMS
+	    while (remove(postfile) == 0)
+		; /* loop through all versions */
+#else
+	    remove(postfile);
+#endif /* VMS */
 	    FREE(postfile);
 	}
 	return status;
@@ -2673,7 +2764,12 @@ Send_NNTP_command:
     }
     FREE(ListArg);
     if (postfile) {
-	HTSYS_remove(postfile);
+#ifdef VMS
+	while (remove(postfile) == 0)
+	    ; /* loop through all versions */
+#else
+	remove(postfile);
+#endif /* VMS */
 	FREE(postfile);
     }
     return HT_NOT_LOADED;