lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lynx-dev 2.8.2dev.16 patch 2 - 8-bit clean protocols


From: Klaus Weide
Subject: lynx-dev 2.8.2dev.16 patch 2 - 8-bit clean protocols
Date: Mon, 15 Feb 1999 02:10:40 -0600 (CST)

While we're messing with HTNews.c...

To verify that there is a problem: post a news test message
containing a hex FF byte, then try to read it with lynx.

  Klaus

* Changed HTGetCharacter to be 8-bit clean, it could not distinguish
  between a character value 255 and EOF.  Changes affect several
  protocols: nntp, gopher, finger, ftp.  Most notably, news articles
  containing byte value 255 could not be completely read.
* Removed a memory leak in HTFTP.c for some directory data, added
  a few gettext calls.
* Added ability to show file type description in local Unix directory
  listings: new format codes for use in LIST_FORMAT %t, %T, they are
  not used by default.

--- lynx2-8-2.old/WWW/Library/Implementation/HTFormat.h Sun Dec 13 03:10:36 1998
+++ lynx2-8-2/WWW/Library/Implementation/HTFormat.h     Thu Feb 11 21:52:51 1999
@@ -348,7 +348,7 @@
 
  */
 extern int interrupted_in_htgetcharacter;
-extern char HTGetCharacter NOPARAMS;
+extern int HTGetCharacter NOPARAMS;
 
 
 /*
--- lynx2-8-2.old/WWW/Library/Implementation/HTFormat.c Thu Dec 24 10:27:22 1998
+++ lynx2-8-2/WWW/Library/Implementation/HTFormat.c     Thu Feb 11 21:52:48 1999
@@ -218,7 +218,7 @@
 }
 
 PUBLIC int interrupted_in_htgetcharacter = 0;
-PUBLIC char HTGetCharacter NOARGS
+PUBLIC int HTGetCharacter NOARGS
 {
     char ch;
     interrupted_in_htgetcharacter = 0;
@@ -228,15 +228,15 @@
                                 input_buffer, INPUT_BUFFER_SIZE);
            if (status <= 0) {
                if (status == 0)
-                   return (char)EOF;
+                   return EOF;
                if (status == HT_INTERRUPTED) {
                    CTRACE(tfp, "HTFormat: Interrupted in HTGetCharacter\n");
                    interrupted_in_htgetcharacter = 1;
-                   return (char)EOF;
+                   return EOF;
                }
                CTRACE(tfp, "HTFormat: File read error %d\n", status);
-               return (char)EOF; /* -1 is returned by UCX
-                                    at end of HTTP link */
+               return EOF; /* -1 is returned by UCX
+                              at end of HTTP link */
            }
            input_pointer = input_buffer;
            input_limit = input_buffer + status;
@@ -244,7 +244,7 @@
        ch = *input_pointer++;
     } while (ch == (char) 13); /* Ignore ASCII carriage return */
 
-    return FROMASCII(ch);
+    return FROMASCII((unsigned char)ch);
 }
 
 /*  Match maintype to any MIME type starting with maintype,
--- lynx2-8-2.old/WWW/Library/Implementation/HTFinger.c Thu Dec 24 10:27:22 1998
+++ lynx2-8-2/WWW/Library/Implementation/HTFinger.c     Thu Feb 11 21:52:49 1999
@@ -179,7 +179,7 @@
     PUTS("\n");
     START(HTML_PRE);
 
-    while ((ch=NEXT_CHAR) != (char)EOF) {
+    while ((ch=NEXT_CHAR) != EOF) {
 
        if (interrupted_in_htgetcharacter) {
            CTRACE(tfp, "HTFinger: Interrupted in HTGetCharacter, 
apparently.\n");
--- lynx2-8-2.old/WWW/Library/Implementation/HTGopher.c Thu Dec 24 10:27:22 1998
+++ lynx2-8-2/WWW/Library/Implementation/HTGopher.c     Thu Feb 11 21:52:50 1999
@@ -209,7 +209,7 @@
        HTParentAnchor *,       anAnchor)
 {
     char gtype;
-    char ch;
+    int ich;
     char line[BIG];
     char *name = NULL, *selector = NULL;       /* Gopher menu fields */
     char *host = NULL;
@@ -248,15 +248,15 @@
     END(HTML_H1);
     PUTS("\n");
     START(HTML_PRE);
-    while ((ch=NEXT_CHAR) != (char)EOF) {
+    while ((ich=NEXT_CHAR) != EOF) {
 
        if (interrupted_in_htgetcharacter) {
            CTRACE(tfp, "HTGopher: Interrupted in HTGetCharacter, 
apparently.\n");
            goto end_html;
        }
 
-       if (ch != LF) {
-           *p = ch;            /* Put character in line */
+       if ((char)ich != LF) {
+           *p = ich;           /* Put character in line */
            if (p< &line[BIG-1]) p++;
 
        } else {
@@ -462,7 +462,7 @@
        CONST char *,           arg,
        HTParentAnchor *,       anAnchor)
 {
-    char ch;
+    int ich;
     char line[BIG];
     char *p = line;
     char *second_colon, last_char='\0';
@@ -493,11 +493,11 @@
     /*
     ** Start grabbing chars from the network.
     */
-    while ((ch=NEXT_CHAR) != (char)EOF)
+    while ((ich=NEXT_CHAR) != EOF)
        {
-           if (ch != LF)
+           if ((char)ich != LF)
                {
-                   *p = ch;            /* Put character in line */
+                   *p = ich;           /* Put character in line */
                    if (p< &line[BIG-1]) p++;
                }
            else
@@ -924,7 +924,7 @@
        char *,         buf,
        int,            size)
 {
-    char ch;
+    int ich;
     char *p = buf;
     int i, code = 0, prev_code;
     size_t alen;
@@ -938,7 +938,7 @@
     /*
     ** Start grabbing chars from the network.
     */
-    while ((ch = NEXT_CHAR) != (char)EOF) {
+    while ((ich = NEXT_CHAR) != EOF) {
        if (interrupted_in_htgetcharacter) {
            CTRACE(tfp, "HTLoadCSO: Interrupted in HTGetCharacter, 
apparently.\n");
            free_CSOfields();
@@ -946,8 +946,8 @@
            return HT_INTERRUPTED;
        }
 
-       if (ch != LF) {
-           *p = ch;            /* Put character in buffer */
+       if ((char)ich != LF) {
+           *p = ich;           /* Put character in buffer */
            if (p < &buf[size-1]) {
                p++;
            }
@@ -1219,7 +1219,7 @@
 PRIVATE int generate_cso_report ARGS1(
        HTStream *,     Target)
 {
-    char ch;
+    int ich;
     char line[BIG];
     char *buf = 0;
     char *p = line, *href = NULL;
@@ -1235,15 +1235,15 @@
     /*
     ** Start grabbing chars from the network.
     */
-    while (!stop && (ch = NEXT_CHAR) != (char)EOF) {
+    while (!stop && (ich = NEXT_CHAR) != EOF) {
        if (interrupted_in_htgetcharacter) {
            CTRACE(tfp, "HTLoadCSO: Interrupted in HTGetCharacter, 
apparently.\n");
            _HTProgress (CONNECTION_INTERRUPTED);
            goto end_CSOreport;
        }
 
-       if (ch != LF) {
-           *p = ch;            /* Put character in line */
+       if ((char)ich != LF) {
+           *p = ich;           /* Put character in line */
            if (p < &line[BIG-1]) {
                p++;
            }
--- lynx2-8-2.old/WWW/Library/Implementation/HTNews.c   Mon Feb  8 09:32:58 1999
+++ lynx2-8-2/WWW/Library/Implementation/HTNews.c       Sun Feb 14 23:14:38 1999
@@ -227,7 +227,7 @@
 {
     int result;
     char * p = response_text;
-    char ch;
+    int ich;
 
     if (command) {
        int status;
@@ -255,7 +255,8 @@
     } /* if command to be sent */
 
     for (;;) {
-       if (((*p++ = NEXT_CHAR) == LF) ||
+       ich = NEXT_CHAR;
+       if (((*p++ = ich) == LF) ||
            (p == &response_text[LINE_LENGTH])) {
            *--p = '\0';                        /* Terminate the string */
            CTRACE(tfp, "NNTP Response: %s\n", response_text);
@@ -263,7 +264,7 @@
            return result;
        } /* if end of line */
 
-       if ((ch = *(p-1)) == (char)EOF) {
+       if (ich == EOF) {
            *(p-1) = '\0';
            if (interrupted_in_htgetcharacter) {
                CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
@@ -428,7 +429,7 @@
 
     if (status == 381) {
        /*
-       **  Handle the password. - FM
+        **  Handle the password. - FM
        */
        tries = 3;
        while (tries) {
@@ -965,8 +966,9 @@
     */
     if (!diagnostic && !rawtext) {
        while (!done) {
-           char ch = *p++ = NEXT_CHAR;
-           if (ch == (char)EOF) {
+           int ich = NEXT_CHAR;
+           *p++ = ich;
+           if (ich == EOF) {
                if (interrupted_in_htgetcharacter) {
                    interrupted_in_htgetcharacter = 0;
                    CTRACE(tfp, "HTNews: Interrupted on read, closing socket 
%d\n",
@@ -978,7 +980,7 @@
                abort_socket();         /* End of file, close socket */
                return(HT_LOADED);      /* End of file on response */
            }
-           if ((ch == LF) || (p == &line[LINE_LENGTH])) {
+           if (((char)ich == LF) || (p == &line[LINE_LENGTH])) {
                *--p = '\0';                    /* Terminate the string */
                CTRACE(tfp, "H %s\n", line);
 
@@ -1216,7 +1218,7 @@
                END(HTML_A);
            } else {
                PUTS("poster");
-           }
+           }           
            MAYBE_END(HTML_DT);
            PUTC('\n');
            FREE(followupto);
@@ -1309,8 +1311,9 @@
 
     p = line;
     while (!done) {
-       char ch = *p++ = NEXT_CHAR;
-       if (ch == (char)EOF) {
+       int ich = NEXT_CHAR;
+       *p++ = ich;
+       if (ich == EOF) {
            if (interrupted_in_htgetcharacter) {
                interrupted_in_htgetcharacter = 0;
                CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
@@ -1322,7 +1325,7 @@
            abort_socket();     /* End of file, close socket */
            return(HT_LOADED);  /* End of file on response */
        }
-       if ((ch == LF) || (p == &line[LINE_LENGTH])) {
+       if (((char)ich == LF) || (p == &line[LINE_LENGTH])) {
            *p++ = '\0';                        /* Terminate the string */
            CTRACE(tfp, "B %s", line);
            if (line[0] == '.') {
@@ -1513,8 +1516,9 @@
     START(HTML_DLC);
     PUTC('\n');
     while (!done) {
-       char ch = NEXT_CHAR;
-       if (ch == (char)EOF) {
+       int ich = NEXT_CHAR;
+       char ch = ich;
+       if (ich == EOF) {
            if (interrupted_in_htgetcharacter) {
                interrupted_in_htgetcharacter = 0;
                CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
@@ -1738,8 +1742,9 @@
        if (status == 221) {
            p = line;
            while (!done) {
-               char ch = *p++ = NEXT_CHAR;
-               if (ch == (char)EOF) {
+               int ich = NEXT_CHAR;
+               *p++ = ich;
+               if (ich == EOF) {
                    if (interrupted_in_htgetcharacter) {
                        interrupted_in_htgetcharacter = 0;
                        CTRACE(tfp, "HTNews: Interrupted on read, closing 
socket %d\n",
@@ -1751,7 +1756,7 @@
                    abort_socket();     /* End of file, close socket */
                    return(HT_LOADED);  /* End of file on response */
                }
-               if ((ch == '\n') || (p == &line[LINE_LENGTH])) {
+               if (((char)ich == '\n') || (p == &line[LINE_LENGTH])) {
                    *p = '\0';          /* Terminate the string */
                    CTRACE(tfp, "X %s", line);
                    if (line[0] == '.') {
@@ -1841,8 +1846,9 @@
                p = line;                               /* Write pointer */
                done = NO;
                while( !done ) {
-                   char ch = *p++ = NEXT_CHAR;
-                   if (ch == (char)EOF) {
+                   int ich = NEXT_CHAR;
+                   *p++ = ich;
+                   if (ich == EOF) {
                        if (interrupted_in_htgetcharacter) {
                            interrupted_in_htgetcharacter = 0;
                            CTRACE(tfp, "HTNews: Interrupted on read, closing 
socket %d\n",
@@ -1854,7 +1860,7 @@
                        abort_socket();         /* End of file, close socket */
                        return(HT_LOADED);      /* End of file on response */
                    }
-                   if ((ch == LF) ||
+                   if (((char)ich == LF) ||
                        (p == &line[LINE_LENGTH])) {
 
                        *--p = '\0';            /* Terminate  & chop LF*/
--- lynx2-8-2.old/WWW/Library/Implementation/HTFTP.c    Thu Dec 24 10:27:22 1998
+++ lynx2-8-2/WWW/Library/Implementation/HTFTP.c        Thu Feb 11 22:55:20 1999
@@ -303,7 +303,7 @@
 /*     Procedure: Read a character from the data connection
 **     ----------------------------------------------------
 */
-PRIVATE char next_data_char NOARGS
+PRIVATE int next_data_char NOARGS
 {
     int status;
     if (data_read_pointer >= data_write_pointer) {
@@ -311,7 +311,7 @@
       if (status == HT_INTERRUPTED)
        interrupted_in_next_data_char = 1;
       if (status <= 0)
-       return (char)-1;
+       return -1;
       data_write_pointer = data_buffer + status;
       data_read_pointer = data_buffer;
     }
@@ -321,7 +321,7 @@
        return FROMASCII(c);
     }
 #else
-    return *data_read_pointer++;
+    return (unsigned char)(*data_read_pointer++);
 #endif /* NOT_ASCII */
 }
 
@@ -439,7 +439,8 @@
     do {
        char *p = response_text;
        for (;;) {
-           if (((*p++ = NEXT_CHAR) == LF)
+           int ich = NEXT_CHAR;
+           if (((*p++ = ich) == LF)
                        || (p == &response_text[LINE_LENGTH])) {
 
                char continuation;
@@ -479,7 +480,7 @@
                return HT_INTERRUPTED;
            }
 
-           if (*(p-1) == (char) EOF) {
+           if (ich == EOF) {
                CTRACE(tfp, "Error on rx: closing socket %d\n",
                            control->socket);
                strcpy(response_text, "000 *** TCP read error on response\n");
@@ -1349,7 +1350,7 @@
                StrAllocCopy(info->date, ct);
                break;
            case '/':
-               StrAllocCopy(info->type, "Directory");
+               StrAllocCopy(info->type, gettext("Directory"));
            default:
                while (*cp) {
                    if (*cp++ == ',')
@@ -1579,7 +1580,7 @@
        if (isdigit(*cps)) {
            entry_info->size = atoi(cps);
        } else {
-           StrAllocCopy(entry_info->type, "Directory");
+           StrAllocCopy(entry_info->type, gettext("Directory"));
        }
     } else {
        StrAllocCopy(entry_info->type, "");
@@ -1715,7 +1716,7 @@
        if (isdigit(*cps)) {
            entry_info->size = atoi(cps);
        } else {
-           StrAllocCopy(entry_info->type, "Directory");
+           StrAllocCopy(entry_info->type, gettext("Directory"));
        }
     } else {
        StrAllocCopy(entry_info->type, "");
@@ -1772,7 +1773,7 @@
     *cps++ ='\0';
     if ((0 == strcasecomp(cp, "DIR")) && (cp - line) > 17) {
        /** It's an SFS directory. **/
-       StrAllocCopy(entry_info->type, "Directory");
+       StrAllocCopy(entry_info->type, gettext("Directory"));
        entry_info->size = 0;
     } else {
        /** It's a file. **/
@@ -1945,7 +1946,7 @@
                /*
                **  It's a directory.
                */
-               StrAllocCopy(entry_info->type, "Directory");
+               StrAllocCopy(entry_info->type, gettext("Directory"));
                remove_size=TRUE; /* size is not useful */
            } else if (entry[0] == 'l') {
                /*
@@ -1953,7 +1954,7 @@
                **  knowing if it is symbolic?  I think so since
                **  it might be a directory.
                */
-               StrAllocCopy(entry_info->type, "Symbolic Link");
+               StrAllocCopy(entry_info->type, gettext("Symbolic Link"));
                remove_size=TRUE; /* size is not useful */
 
                /*
@@ -2000,7 +2001,7 @@
            len = strlen(entry_info->filename);
            if ((len > 4) && !strcmp(&entry_info->filename[len-4], ".dir")) {
                entry_info->filename[len-4] = '\0';
-               StrAllocCopy(entry_info->type, "Directory");
+               StrAllocCopy(entry_info->type, gettext("Directory"));
                remove_size=TRUE; /* size is not useful */
            }
            /*
@@ -2087,7 +2088,7 @@
                **  It's a dir, remove / and mark it as such.
                */
                entry[len-1] = '\0';
-               StrAllocCopy(entry_info->type, "Directory");
+               StrAllocCopy(entry_info->type, gettext("Directory"));
                remove_size=TRUE; /* size is not useful */
            }
            /*
@@ -2353,13 +2354,13 @@
 
     {
        HTBTree * bt = HTBTree_new((HTComparer)compare_EntryInfo_structs);
-       char c;
+       int ic;
        HTChunk * chunk = HTChunkCreate(128);
        int BytesReceived = 0;
        int BytesReported = 0;
        char NumBytes[64];
        PUTS("\n");  /* prettier LJM */
-       for (c = 0; c != (char)EOF;) {  /* For each entry in the directory */
+       for (ic = 0; ic != EOF;) {      /* For each entry in the directory */
            HTChunkClear(chunk);
 
            if (HTCheckForInterrupt()) {
@@ -2376,7 +2377,7 @@
            /*   read directory entry
             */
            for (;;) {                 /* Read in one line as filename */
-               c = NEXT_DATA_CHAR;
+               ic = NEXT_DATA_CHAR;
 AgainForMultiNet:
                if (interrupted_in_next_data_char) {
                    WasInterrupted = TRUE;
@@ -2387,7 +2388,7 @@
                        HTBTreeAndObject_free(bt);
                        return HT_INTERRUPTED;
                    }
-               } else if (c == CR || c == LF) {    /* Terminator? */
+               } else if ((char)ic == CR || (char)ic == LF) {    /* 
Terminator? */
                    if (chunk->size != 0) {  /* got some text */
                        /* Deal with MultiNet's wrapping of long lines */
                        if (server_type == VMS_SERVER) {
@@ -2403,7 +2404,7 @@
                                    goto AgainForMultiNet;
                                }
                                if (status <= 0) {
-                                   c = (char)EOF;
+                                   ic = EOF;
                                    break;
                                }
                                data_write_pointer = data_buffer + status;
@@ -2419,10 +2420,10 @@
                        else
                            break;            /* finish getting one entry */
                    }
-               } else if (c == (char)EOF) {
+               } else if (ic == EOF) {
                    break;             /* End of file */
                } else {
-                   HTChunkPutc(chunk, c);
+                   HTChunkPutc(chunk, (char)ic);
                }
            }
            HTChunkTerminate(chunk);
@@ -2434,7 +2435,7 @@
                BytesReported = BytesReceived;
            }
 
-           if (c == (char) EOF && chunk->size == 1)
+           if (ic == EOF && chunk->size == 1)
            /* 1 means empty: includes terminating 0 */
                break;
            CTRACE(tfp, "HTFTP: Line in %s is %s\n",
@@ -2446,6 +2447,7 @@
                            entry_info->filename);
                HTBTree_add(bt, (EntryInfo *)entry_info);
            } else {
+               free_entryinfo_struct_contents(entry_info);
                FREE(entry_info);
            }
 
--- lynx2-8-2.old/WWW/Library/Implementation/HTFile.c   Thu Jan 28 15:31:28 1999
+++ lynx2-8-2/WWW/Library/Implementation/HTFile.c       Thu Feb 11 15:29:55 1999
@@ -154,7 +154,7 @@
 PRIVATE char *FormatStr ARGS3(
     char **,   bufp,
     char *,    start,
-    char *,    entry)
+    CONST char *,      entry)
 {
     char fmt[512];
     if (*start) {
@@ -218,7 +218,7 @@
 #endif
 
        if (lstat(file, &st) < 0)
-               fmtstr = "%a";  /* can't stat so just do anchor */
+               fmtstr = "    %a";      /* can't stat so just do anchor */
 
        StrAllocCopy(str, fmtstr);
        s = str;
@@ -270,6 +270,37 @@
                        }
 #endif
                        break;
+
+               case 'T':       /* MIME type */
+               case 't':       /* MIME type description */
+                   if (S_ISDIR(st.st_mode)) {
+                       if (c != 'T') {
+                           FormatStr(&buf, start, gettext("Directory"));
+                       } else {
+                           FormatStr(&buf, start, "");
+                       }
+                   } else {
+                       CONST char *cp2;
+                       HTFormat format;
+                       format = HTFileFormat(file, NULL, &cp2);
+
+                       if (c != 'T') {
+                           if (cp2 == NULL) {
+                               if (!strncmp(HTAtom_name(format),
+                                            "application",11)) {
+                                   cp2 = HTAtom_name(format) + 12;
+                                   if (!strncmp(cp2,"x-",2))
+                                       cp2 += 2;
+                               } else {
+                                   cp2 = HTAtom_name(format);
+                               }
+                           }
+                           FormatStr(&buf, start, cp2);
+                       } else {
+                           FormatStr(&buf, start, HTAtom_name(format));
+                       }
+                   }
+               break;
 
                case 'd':       /* date */
                        now = time(0);
--- lynx2-8-2.old/lynx.cfg      Mon Feb  8 04:32:58 1999
+++ lynx2-8-2/lynx.cfg  Sun Feb 14 23:42:38 1999
@@ -1671,6 +1671,8 @@
 #      %d      date of last modification
 #      %a      anchor pointing to file or directory
 #      %A      as above but don't show symbolic links
+#      %t      type of file (description derived from MIME type)
+#      %T      MIME type as known by Lynx (from mime.types or default)
 #      %k      size of file in Kilobytes
 #      %K      as above but omit size for directories
 #      %s      size of file in bytes

reply via email to

[Prev in Thread] Current Thread [Next in Thread]