lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev 2.8.2dev.14 patch 1


From: Klaus Weide
Subject: lynx-dev 2.8.2dev.14 patch 1
Date: Wed, 20 Jan 1999 21:26:14 -0600 (CST)

Patches against 2.8.2dev.14:

* Added PARSE_STRICTPATH and PARSE_QUERY to interface of HTParse(),
  for requesting only the relevant part of what is returned for
  PARSE_PATH.  This isn't yet used anywhere.
* Changes to StrAllocVsprintf() to take width and precision in most
  format specifications into account, and to correct the memory
  allocation logic.  This was tested by setting GROW_SIZE to a small
  value of 8, so far no crashes, but it is certainly not right for
  all possible formats, especially involving floating point conversions.
* Changed HTSprintf0() to pass a string already existing in its output
  buffer on, this should save a few realloc's in StrAllocVsprintf().
* Changes to code handling LIST_FORMAT to avoid some unnecessary
  reallocations, to recognize some more format flags, and to treat
  invalid formats somewhat better.
* Corrected recent HTFile.c change for systems without S_ISVTX.
* Added memory cleanup for uid/gid cache functions in HTAAProt.c.
* Increased ATEXITSIZE to 40.
* Added TRACE output to HTAnchor.c's free_adult_table.  If this
  shows anything at program exit (if TRACE is on then), it means
  that HTAnchor structures have been missed by the normal automatic
  cleanup (walking the history list and following links).
* Changed more status codes in HTUtils.h to libwww5-like values.
* Added new function to check for a valid Internet hostname.
  Use it before actually trying to resolve an address, it should
  a. avoid the overhead of NSL_FORK if it would fail anyway,
  b. prevent DNS queries for invalid names, which may unnecessarily
     consume time, bandwidth, and DNS server cache memory, and
     may confuse some resolver libraries and servers,
  c. speed up address guessing sometimes if something was mistyped,
  d. thwart some attempts to crash Lynx with invalid URLs.
* This time really make "Alert" statusline prefix localizable.
* New function HTAlwaysAlert(), which can be called even when
  LYCursesON isn't true and should always produce a visible message.
* Use new valid_hostname to also check telnet, tn3270, and rlogin
  hostnames before calling the external program (after most invalid
  character have already been stripped).  Added a fflush(stdout)
  th make sure messages are visible before external program is called.
* Made changes equivalent to the 1998-12-31 HTSACopy and HTSACat
  modification to the LY_FIND_LEAKS versions of those functions.
  Having source and target string for StrAllocCopy or StrAllocCat
  overlap (or being equal) should be considered a programming error,
  but at least one place in LYEdit.c currently seems to do it and
  rely on the new behavior.  (Editing current file sometimes didn't
  work with LY_FIND_LEAKS).
* Closed memory leaks in LYKeymap.c, provided for memory cleanup at
  exit of LYCgi.c environment strings.
* Explicitly put HTTP_ACCEPT_LANGUAGE and HTTP_ACCEPT_CHARSET strings
  into lynxcgi environment only if they are non-empty, i.e. set to
  something in lynx.cfg or the personal configuration or Options screen.
  This makes the environment a lynxcgi scripts sees resemble more closely
  that of a remote CGI script handling a request from Lynx with the same
  configuration - HTTP.c also only sends Accept-{Language,Charset} headers
  if preferred language and preferred charset (respectively) have been set
  to non-empty strings.  (Strictly speaking, an empty Accept-* header has
  a different meaning from a non-existing one, but it doesn't make much
  sense to generate empty Accept-* headers, since they mean "nothing is
  accepted".)  There are other differences in the lynxcgi environment
  (e.g. HTTP_ACCEPT isn't set, ",iso-8859-1;q=0.01" etc. isn't appended
  to HTTP_ACCEPT_CHARSET, apart from missing redirections), but apparently
  nobody has needed a more exact CGI emulation for real scripts.
* Removed sending of "Negotiate: trans" in HTTP.c since it violates
  transparent content negotiation specs, added comments.

*** lynx2-8-2.old/src/HTAlert.c Wed Jan 13 05:37:34 1999
--- lynx2-8-2/src/HTAlert.c     Sun Jan 17 04:45:26 1999
***************
*** 30,38 ****
  {
      CTRACE(tfp, "\nAlert!: %s\n\n", Msg);
      CTRACE_FLUSH(tfp);
!     _user_message("Alert!: %s", Msg);
  
      sleep(AlertSecs);
  }
  
  /*    Issue an informational message.                 HTInfoMsg()
--- 30,61 ----
  {
      CTRACE(tfp, "\nAlert!: %s\n\n", Msg);
      CTRACE_FLUSH(tfp);
!     _user_message(ALERT_FORMAT, Msg);
  
      sleep(AlertSecs);
+ }
+ 
+ PUBLIC void HTAlwaysAlert ARGS2(
+       CONST char *,   extra_prefix,
+       CONST char *,   Msg)
+ {
+     if (!dump_output_immediately && LYCursesON) {
+       HTAlert(Msg);
+     } else {
+       if (extra_prefix) {
+           fprintf(((TRACE) ? stdout : stderr),
+                   "%s %s!\n",
+                   extra_prefix, Msg);
+       } else {
+           fprintf(((TRACE) ? stdout : stderr),
+                   ALERT_FORMAT,
+                   (Msg == 0) ? "" : Msg);
+       }
+       fflush(stdout);
+       sleep(AlertSecs);
+       CTRACE(tfp, "\nAlert!: %s\n\n", Msg);
+       CTRACE_FLUSH(tfp);
+     }
  }
  
  /*    Issue an informational message.                 HTInfoMsg()
*** lynx2-8-2.old/src/HTAlert.h Mon Jan 18 06:29:20 1999
--- lynx2-8-2/src/HTAlert.h     Sun Jan 17 05:05:08 1999
***************
*** 29,34 ****
--- 29,35 ----
  **              The input is a list of parameters for printf.
  */
  extern void HTAlert PARAMS((CONST char * Msg));
+ extern void HTAlwaysAlert PARAMS((CONST char * extra_prefix, CONST char * 
Msg));
  extern void HTInfoMsg PARAMS((CONST char * Msg));
  extern void HTUserMsg PARAMS((CONST char * Msg));
  extern void HTUserMsg2 PARAMS((CONST char * Msg, CONST char * Arg));
*** lynx2-8-2.old/src/LYLeaks.c Tue Nov 10 13:47:38 1998
--- lynx2-8-2/src/LYLeaks.c     Sat Jan 16 03:20:12 1999
***************
*** 465,470 ****
--- 465,476 ----
        CONST char *,   cp_File,
        CONST short,    ssi_Line)
  {
+     if (src != NULL && src == *dest) {
+       CTRACE(tfp,
+              "LYLeakSACopy: *dest equals src, contains \"%s\"\n",
+              src);
+       return *dest;
+     }
      if (*dest) {
        LYLeakFree(*dest, cp_File, ssi_Line);
        *dest = NULL;
***************
*** 490,495 ****
--- 496,507 ----
        CONST short,    ssi_Line)
  {
      if (src && *src) {
+       if (src == *dest) {
+           CTRACE(tfp,
+                  "LYLeakSACat:  *dest equals src, contains \"%s\"\n",
+                  src);
+           return *dest;
+       }
        if (*dest) {
            int length = strlen(*dest);
            *dest = (char *)LYLeakRealloc(*dest,
*** lynx2-8-2.old/src/LYKeymap.c        Wed Jan 13 05:37:34 1999
--- lynx2-8-2/src/LYKeymap.c    Sat Jan 16 04:58:26 1999
***************
*** 701,710 ****
--- 701,712 ----
      if (prev_lynx_edit_mode && !no_dired_support &&
          (buf = format_binding(key_override, i)) != 0) {
        (*target->isa->put_block)(target, buf, strlen(buf));
+       FREE(buf);
      } else
  #endif /* DIRED_SUPPORT && OK_OVERRIDE */
      if ((buf = format_binding(keymap, i)) != 0) {
        (*target->isa->put_block)(target, buf, strlen(buf));
+       FREE(buf);
      }
  }
  
*** lynx2-8-2.old/src/LYCgi.c   Wed Jan 13 05:37:34 1999
--- lynx2-8-2/src/LYCgi.c       Wed Jan 20 19:42:34 1999
***************
*** 58,68 ****
  PRIVATE char **env = NULL;  /* Environment variables */
  PRIVATE int envc_size = 0;  /* Slots in environment array */
  PRIVATE int envc = 0;     /* Slots used so far */
  #ifdef LYNXCGI_LINKS
! PRIVATE char *user_agent;
! PRIVATE char *server_software;
! PRIVATE char *accept_language;
! PRIVATE char *post_len;
  #endif /* LYNXCGI_LINKS */
  
  PRIVATE void add_environment_value PARAMS((char *env_value));
--- 58,69 ----
  PRIVATE char **env = NULL;  /* Environment variables */
  PRIVATE int envc_size = 0;  /* Slots in environment array */
  PRIVATE int envc = 0;     /* Slots used so far */
+ PRIVATE HTList *alloced = NULL;
  #ifdef LYNXCGI_LINKS
! PRIVATE char *user_agent = NULL;
! PRIVATE char *server_software = NULL;
! PRIVATE char *accept_language = NULL;
! PRIVATE char *post_len = NULL;
  #endif /* LYNXCGI_LINKS */
  
  PRIVATE void add_environment_value PARAMS((char *env_value));
***************
*** 80,85 ****
--- 81,107 ----
  }
  #endif /* HAVE_STRERROR */
  
+ PRIVATE void free_alloced_lynxcgi NOARGS
+ {
+     void *ptr;
+     while ((ptr = HTList_removeLastObject(alloced)) != NULL) {
+       FREE(ptr);
+     }
+     FREE(alloced);
+     FREE(user_agent);
+     FREE(server_software);
+ }
+ 
+ PRIVATE void remember_alloced ARGS1(
+     void *,           ptr)
+ {
+     if (!alloced) {
+       alloced = HTList_new();
+       atexit(free_alloced_lynxcgi);
+     }
+     HTList_addObject(alloced, ptr);
+ }
+ 
  /*
   * Simple routine for expanding the environment array and adding a value to
   * it
***************
*** 89,101 ****
  {
      if (envc == envc_size) {   /* Need some more slots */
        envc_size += 10;
!       if (env)
            env = (char **)realloc(env,
                                   sizeof(env[0]) * (envc_size + 2));
                                                /* + terminator and base 0 */
!       else
            env = (char **)malloc(sizeof(env[0]) * (envc_size + 2));
                                                /* + terminator and base 0 */
        if (env == NULL) {
            outofmem(__FILE__, "LYCgi");
        }
--- 111,125 ----
  {
      if (envc == envc_size) {   /* Need some more slots */
        envc_size += 10;
!       if (env) {
            env = (char **)realloc(env,
                                   sizeof(env[0]) * (envc_size + 2));
                                                /* + terminator and base 0 */
!       } else {
            env = (char **)malloc(sizeof(env[0]) * (envc_size + 2));
                                                /* + terminator and base 0 */
+           remember_alloced(env);
+       }
        if (env == NULL) {
            outofmem(__FILE__, "LYCgi");
        }
***************
*** 127,132 ****
--- 151,157 ----
        strcat(add_value, "=");
        strcat(add_value, env_value);
        add_environment_value(add_value);
+       remember_alloced(add_value);
      }
  }
  
***************
*** 464,473 ****
                dup2(fd2[1], fileno(stderr));
                close(fd2[1]);
  
                HTSprintf0(&accept_language, "HTTP_ACCEPT_LANGUAGE=%s", 
language);
                add_environment_value(accept_language);
  
!               if (pref_charset) {
                    cp = NULL;
                    StrAllocCopy(cp, "HTTP_ACCEPT_CHARSET=");
                    StrAllocCat(cp, pref_charset);
--- 489,500 ----
                dup2(fd2[1], fileno(stderr));
                close(fd2[1]);
  
+               if (language && *language) {
                HTSprintf0(&accept_language, "HTTP_ACCEPT_LANGUAGE=%s", 
language);
                add_environment_value(accept_language);
+               }
  
!               if (pref_charset && *pref_charset) {
                    cp = NULL;
                    StrAllocCopy(cp, "HTTP_ACCEPT_CHARSET=");
                    StrAllocCat(cp, pref_charset);
*** lynx2-8-2.old/WWW/Library/Implementation/HTParse.c  Sat Dec 12 22:10:36 1998
--- lynx2-8-2/WWW/Library/Implementation/HTParse.c      Sun Jan 17 20:44:48 1999
***************
*** 189,194 ****
--- 189,201 ----
  
      CTRACE(tfp, "HTParse: aName:%s   relatedName:%s\n", aName, relatedName);
  
+     if (wanted & (PARSE_STRICTPATH | PARSE_QUERY)) { /* if detail wanted... */
+       if ((wanted & (PARSE_STRICTPATH | PARSE_QUERY))
+           == (PARSE_STRICTPATH | PARSE_QUERY)) /* if strictpath AND query */
+           wanted |= PARSE_PATH; /* then treat as if PARSE_PATH wanted */
+       if (wanted & PARSE_PATH) /* if PARSE_PATH wanted */
+           wanted &= ~(PARSE_STRICTPATH | PARSE_QUERY); /* ignore details */
+     }
      /*
      **        Allocate the output string.
      */
***************
*** 341,347 ****
      /*
      **        Handle the path.
      */
!     if (wanted & PARSE_PATH) {
        if (acc_method && !given.absolute && given.relative) {
            if (!strcasecomp(acc_method, "nntp") ||
                !strcasecomp(acc_method, "snews") ||
--- 348,358 ----
      /*
      **        Handle the path.
      */
!     if (wanted & (PARSE_PATH | PARSE_STRICTPATH | PARSE_QUERY)) {
!       char *tail;
!       int want_detail = (wanted & (PARSE_STRICTPATH | PARSE_QUERY));
!       if (want_detail)
!           tail = result + strlen(result);
        if (acc_method && !given.absolute && given.relative) {
            if (!strcasecomp(acc_method, "nntp") ||
                !strcasecomp(acc_method, "snews") ||
***************
*** 390,395 ****
--- 401,423 ----
            if (!strcmp(result, "news:/";))
                result[5] = '*';
            CTRACE(tfp, "5\n");
+       }
+       if (want_detail) {
+           p = strchr(tail, '?');      /* Search part? */
+           if (p) {
+               if (PARSE_STRICTPATH) {
+                   *p = '\0';
+               } else {
+                   if (!(wanted & PARSE_PUNCTUATION))
+                       p++;
+                   do {
+                       *tail++ = *p;
+                   } while (*p++);
+               }
+           } else {
+               if (wanted & PARSE_QUERY)
+                   *tail = '\0';
+           }
        }
      }
  
*** lynx2-8-2.old/WWW/Library/Implementation/HTParse.h  Sat Dec 12 22:10:36 1998
--- lynx2-8-2/WWW/Library/Implementation/HTParse.h      Sun Jan 17 20:38:18 1999
***************
*** 20,25 ****
--- 20,34 ----
  #define PARSE_ANCHOR             2
  #define PARSE_PUNCTUATION        1
  #define PARSE_ALL               31
+ /*
+ **  Additional flag bits for more details on components already
+ **  covered by the above.  The PARSE_PATH above doesn't really
+ **  strictly refer to the path component in the sense of the URI
+ **  specs only, but rather to that combined with a possible query
+ **  component. - kw
+ */
+ #define PARSE_STRICTPATH        32
+ #define PARSE_QUERY             64
  
  /*
  **  The following are valid mask values.  The terms are the BNF names
*** lynx2-8-2.old/WWW/Library/Implementation/HTFile.c   Mon Jan 18 06:29:20 1999
--- lynx2-8-2/WWW/Library/Implementation/HTFile.c       Tue Jan 19 19:41:34 1999
***************
*** 151,176 ****
  PRIVATE void free_suffixes NOPARAMS;
  
  #ifdef LONG_LIST
! PRIVATE char *FormatStr ARGS2(
      char *,   start,
      char *,   entry)
  {
      char fmt[512];
!     char *buf = 0;
!     sprintf(fmt, "%%%.*ss", (int) sizeof(fmt) - 3, start);
!     HTSprintf0(&buf, fmt, entry);
!     return buf;
  }
  
! PRIVATE char *FormatNum ARGS2(
      char *,   start,
      int,      entry)
  {
      char fmt[512];
!     char *buf = 0;
!     sprintf(fmt, "%%%.*sd", (int) sizeof(fmt) - 3, start);
!     HTSprintf0(&buf, fmt, entry);
!     return buf;
  }
  
  PRIVATE void LYListFmtParse ARGS5(
--- 151,185 ----
  PRIVATE void free_suffixes NOPARAMS;
  
  #ifdef LONG_LIST
! PRIVATE char *FormatStr ARGS3(
!     char **,  bufp,
      char *,   start,
      char *,   entry)
  {
      char fmt[512];
!     if (*start) {
!       sprintf(fmt, "%%%.*ss", (int) sizeof(fmt) - 3, start);
!       HTSprintf0(bufp, fmt, entry);
!     } else {
!       HTSprintf0(bufp, "%s", entry);
!     }
!     return *bufp;
  }
  
! PRIVATE char *FormatNum ARGS3(
!     char **,  bufp,
      char *,   start,
      int,      entry)
  {
      char fmt[512];
!     if (*start) {
!       sprintf(fmt, "%%%.*sd", (int) sizeof(fmt) - 3, start);
!       HTSprintf0(bufp, fmt, entry);
!     } else {
!       sprintf(fmt, "%d", entry);
!       StrAllocCat(*bufp, fmt);
!     }
!     return *bufp;
  }
  
  PRIVATE void LYListFmtParse ARGS5(
***************
*** 205,211 ****
                "r-T", "r-t", "rwT", "rwt", 0 };
  #define PTBIT(a, s)  (s) ? ptbits[(a) & 0x7] : pbits[(a) & 0x7]
  #else
! #define PTBIT(a, s)  (a, 0, 0)
  #endif
  
        if (lstat(file, &st) < 0)
--- 214,220 ----
                "r-T", "r-t", "rwT", "rwt", 0 };
  #define PTBIT(a, s)  (s) ? ptbits[(a) & 0x7] : pbits[(a) & 0x7]
  #else
! #define PTBIT(a, s)  PBIT(a, 0, 0)
  #endif
  
        if (lstat(file, &st) < 0)
***************
*** 234,252 ****
                if (s == end)
                        break;
                start = ++s;
!               while (isdigit(*s) || *s == '.' || *s == '-')
                        s++;
                c = *s;         /* the format char. or \0 */
                *s = '\0';
  
                switch (c) {
                case '\0':
!                       break;
  
                case 'A':
                case 'a':       /* anchor */
                        HTDirEntry(target, tail, entry);
!                       buf = FormatStr(start, entry);
                        PUTS(buf);
                        END(HTML_A);
                        *buf = '\0';
--- 243,263 ----
                if (s == end)
                        break;
                start = ++s;
!               while (isdigit(*s) || *s == '.' || *s == '-' || *s == ' ' ||
!                   *s == '#' || *s == '+' || *s == '\'')
                        s++;
                c = *s;         /* the format char. or \0 */
                *s = '\0';
  
                switch (c) {
                case '\0':
!                       PUTS(start);
!                       continue;
  
                case 'A':
                case 'a':       /* anchor */
                        HTDirEntry(target, tail, entry);
!                       FormatStr(&buf, start, entry);
                        PUTS(buf);
                        END(HTML_A);
                        *buf = '\0';
***************
*** 274,294 ****
                                */
                                sprintf(tmp, "%.7s %.4s ", datestr + 4,
                                        datestr + 20);
!                       buf = FormatStr(start, tmp);
                        break;
  
                case 's':       /* size in bytes */
!                       buf = FormatNum(start, st.st_size);
                        break;
  
                case 'K':       /* size in Kilobytes but not for directories */
                        if (S_ISDIR(st.st_mode)) {
!                               buf = FormatStr(start, "");
                                break;
                        }
                        /* FALL THROUGH */
                case 'k':       /* size in Kilobytes */
!                       buf = FormatNum(start, (st.st_size+1023)/1024);
                        StrAllocCat(buf, "K");
                        break;
  
--- 285,305 ----
                                */
                                sprintf(tmp, "%.7s %.4s ", datestr + 4,
                                        datestr + 20);
!                       FormatStr(&buf, start, tmp);
                        break;
  
                case 's':       /* size in bytes */
!                       FormatNum(&buf, start, st.st_size);
                        break;
  
                case 'K':       /* size in Kilobytes but not for directories */
                        if (S_ISDIR(st.st_mode)) {
!                               FormatStr(&buf, start, "");
                                break;
                        }
                        /* FALL THROUGH */
                case 'k':       /* size in Kilobytes */
!                       FormatNum(&buf, start, (st.st_size+1023)/1024);
                        StrAllocCat(buf, "K");
                        break;
  
***************
*** 319,347 ****
                                PBIT(st.st_mode, 6, st.st_mode & S_ISUID),
                                PBIT(st.st_mode, 3, st.st_mode & S_ISGID),
                                PTBIT(st.st_mode,   st.st_mode & S_ISVTX));
!                       buf = FormatStr(start, tmp);
                        break;
  
                case 'o':       /* owner */
                        name = HTAA_UidToName (st.st_uid);
                        if (*name) {
!                               buf = FormatStr(start, name);
                        } else {
!                               buf = FormatNum(start, st.st_uid);
                        }
                        break;
  
                case 'g':       /* group */
                        name = HTAA_GidToName(st.st_gid);
                        if (*name) {
!                               buf = FormatStr(start, name);
                        } else {
!                               buf = FormatNum(start, st.st_gid);
                        }
                        break;
  
                case 'l':       /* link count */
!                       buf = FormatNum(start, st.st_nlink);
                        break;
  
                default:
--- 330,362 ----
                                PBIT(st.st_mode, 6, st.st_mode & S_ISUID),
                                PBIT(st.st_mode, 3, st.st_mode & S_ISGID),
                                PTBIT(st.st_mode,   st.st_mode & S_ISVTX));
!                       FormatStr(&buf, start, tmp);
                        break;
  
                case 'o':       /* owner */
                        name = HTAA_UidToName (st.st_uid);
                        if (*name) {
!                               FormatStr(&buf, start, name);
                        } else {
!                               FormatNum(&buf, start, st.st_uid);
                        }
                        break;
  
                case 'g':       /* group */
                        name = HTAA_GidToName(st.st_gid);
                        if (*name) {
!                               FormatStr(&buf, start, name);
                        } else {
!                               FormatNum(&buf, start, st.st_gid);
                        }
                        break;
  
                case 'l':       /* link count */
!                       FormatNum(&buf, start, st.st_nlink);
!                       break;
! 
!               case '%':       /* literal % with flags/width */
!                       FormatStr(&buf, start, "%");
                        break;
  
                default:
***************
*** 349,359 ****
                        "Unknown format character `%c' in list format\n", c);
                        break;
                }
!               PUTS(buf);
!               FREE(buf);
  
                s++;
        }
        END(HTML_PRE);
        PUTS("\n");
        FREE(str);
--- 364,375 ----
                        "Unknown format character `%c' in list format\n", c);
                        break;
                }
!               if (buf)
!                   PUTS(buf);
  
                s++;
        }
+       FREE(buf);
        END(HTML_PRE);
        PUTS("\n");
        FREE(str);
*** lynx2-8-2.old/WWW/Library/Implementation/HTString.c Wed Jan 13 05:37:34 1999
--- lynx2-8-2/WWW/Library/Implementation/HTString.c     Tue Jan 19 19:18:12 1999
***************
*** 368,373 ****
--- 368,376 ----
  #define VA_POINT(type) pval = (void *)va_arg((*ap), type)
  
  #define NUM_WIDTH 10  /* allow for width substituted for "*" in "%*s" */
+               /* also number of chars assumed to be needed in addition
+                  to a given precision in floating point formats */
+    
  #define GROW_EXPR(n) (((n) * 3) / 2)
  #define GROW_SIZE 256
  
***************
*** 397,402 ****
--- 400,406 ----
        dst_ptr = HTAlloc(dst_ptr, have = GROW_SIZE + need);
      } else {
        have = strlen(dst_ptr) + 1;
+       need += dst_len;
        if (have < need)
            dst_ptr = HTAlloc(dst_ptr, have = GROW_SIZE + need);
      }
***************
*** 482,498 ****
                        break;
                    case 'c':
                        VA_INTGR(int);
!                       used = 'i';
                        break;
                    case 's':
                        VA_POINT(char *);
                        if (prec < 0)
                            prec = strlen(pval);
!                       if (prec > (int)tmp_len) {
!                           tmp_len = GROW_EXPR(tmp_len + prec);
!                           tmp_ptr = HTAlloc(tmp_ptr, tmp_len);
!                       }
!                       used = 'p';
                        break;
                    case 'p':
                        VA_POINT(void *);
--- 486,498 ----
                        break;
                    case 'c':
                        VA_INTGR(int);
!                       used = 'c';
                        break;
                    case 's':
                        VA_POINT(char *);
                        if (prec < 0)
                            prec = strlen(pval);
!                       used = 's';
                        break;
                    case 'p':
                        VA_POINT(void *);
***************
*** 511,522 ****
                    state = Prec;
                } else if (*fmt == '%') {
                    done = TRUE;
!                   used = 'p';
                }
            }
            fmt_ptr[f] = '\0';
            switch (used) {
            case 'i':
                sprintf(tmp_ptr, fmt_ptr, ival);
                break;
            case 'f':
--- 511,546 ----
                    state = Prec;
                } else if (*fmt == '%') {
                    done = TRUE;
!                   used = '%';
                }
            }
            fmt_ptr[f] = '\0';
+ 
+           if (prec > 0) {
+               switch (used) {
+               case 'f':
+                   if (width < prec + NUM_WIDTH)
+                       width = prec + NUM_WIDTH;
+               case 'i':
+               case 'p':
+                   if (width < prec + 2)
+                       width = prec + 2; /* leading sign/space/zero, "0x" */
+               case 'c':
+               case '%':
+                   break;
+               default:
+                   if (width < prec)
+                       width = prec;
+               }
+           }
+           if (width >= (int)tmp_len) {
+               tmp_len = GROW_EXPR(tmp_len + width);
+               tmp_ptr = HTAlloc(tmp_ptr, tmp_len);
+           }
+ 
            switch (used) {
            case 'i':
+           case 'c':
                sprintf(tmp_ptr, fmt_ptr, ival);
                break;
            case 'f':
***************
*** 533,538 ****
--- 557,565 ----
            strcpy(dst_ptr + dst_len, tmp_ptr);
            dst_len += strlen(tmp_ptr);
        } else {
+           if ((dst_len + 2) >= have) {
+               dst_ptr = HTAlloc(dst_ptr, (have += GROW_SIZE));
+           }
            dst_ptr[dst_len++] = *fmt++;
        }
      }
***************
*** 597,604 ****
        char **         pstr = va_arg(ap, char **);
        CONST char *    fmt  = va_arg(ap, CONST char *);
  #endif
-       if (pstr != 0)
-           *pstr = 0;
        result = StrAllocVsprintf(pstr, 0, fmt, &ap);
      }
      va_end(ap);
--- 624,629 ----
*** lynx2-8-2.old/WWW/Library/Implementation/HTAAProt.c Sat Dec 12 22:10:36 1998
--- lynx2-8-2/WWW/Library/Implementation/HTAAProt.c     Sat Jan 16 04:46:30 1999
***************
*** 575,588 ****
        int user;
        } USER_DATA;
  
! PRIVATE HTList *known_grp;
! PRIVATE HTList *known_pwd;
  
  PRIVATE void save_gid_info ARGS2(char *, name, int, user)
  {
      USER_DATA *data = calloc(1, sizeof(USER_DATA));
!     if (HTList_isEmpty(known_grp))
        known_grp = HTList_new();
      StrAllocCopy(data->name, name);
      data->user = user;
      HTList_addObject (known_grp, data);
--- 575,613 ----
        int user;
        } USER_DATA;
  
! PRIVATE HTList *known_grp = NULL;
! PRIVATE HTList *known_pwd = NULL;
! PRIVATE BOOL uidgid_cache_inited = NO;
! 
! PRIVATE void clear_uidgid_cache NOARGS
! {
!     USER_DATA *data;
!     if (known_grp) {
!       while ((data = HTList_removeLastObject(known_grp)) != NULL) {
!           FREE(data->name);
!           FREE(data);
!       }
!       FREE(known_grp);
!     }
!     if (known_pwd) {
!       while ((data = HTList_removeLastObject(known_pwd)) != NULL) {
!           FREE(data->name);
!           FREE(data);
!       }
!       FREE(known_pwd);
!     }
! }
  
  PRIVATE void save_gid_info ARGS2(char *, name, int, user)
  {
      USER_DATA *data = calloc(1, sizeof(USER_DATA));
!     if (!data)
!       return;
!     if (!known_grp) {
        known_grp = HTList_new();
+       if (!uidgid_cache_inited)
+           atexit(clear_uidgid_cache);
+     }
      StrAllocCopy(data->name, name);
      data->user = user;
      HTList_addObject (known_grp, data);
***************
*** 591,598 ****
  PRIVATE void save_uid_info ARGS2(char *, name, int, user)
  {
      USER_DATA *data = calloc(1, sizeof(USER_DATA));
!     if (HTList_isEmpty(known_pwd))
        known_pwd = HTList_new();
      StrAllocCopy(data->name, name);
      data->user = user;
      HTList_addObject (known_pwd, data);
--- 616,628 ----
  PRIVATE void save_uid_info ARGS2(char *, name, int, user)
  {
      USER_DATA *data = calloc(1, sizeof(USER_DATA));
!     if (!data)
!       return;
!     if (!known_pwd) {
        known_pwd = HTList_new();
+       if (!uidgid_cache_inited)
+           atexit(clear_uidgid_cache);
+     }
      StrAllocCopy(data->name, name);
      data->user = user;
      HTList_addObject (known_pwd, data);
*** lynx2-8-2.old/WWW/Library/Implementation/LYexit.h   Wed Nov 18 13:23:54 1998
--- lynx2-8-2/WWW/Library/Implementation/LYexit.h       Sat Jan 16 07:02:04 1999
***************
*** 30,36 ****
  
  #define exit LYexit
  #define atexit LYatexit
! #define ATEXITSIZE 32
  
  /*
   *    Data structures
--- 30,36 ----
  
  #define exit LYexit
  #define atexit LYatexit
! #define ATEXITSIZE 40
  
  /*
   *    Data structures
*** lynx2-8-2.old/WWW/Library/Implementation/HTAnchor.c Thu Dec 24 05:27:22 1998
--- lynx2-8-2/WWW/Library/Implementation/HTAnchor.c     Sat Jan 16 21:49:32 1999
***************
*** 302,307 ****
--- 302,312 ----
            adult_table[i_counter] = HTAp_freeme->next;
            if (HTAp_freeme->object) {
                parent = (HTParentAnchor *)HTAp_freeme->object;
+               CTRACE(tfp, "delete anchor:%d/%d,%d,%d %s\n",
+                      i_counter, HTList_count(HTAp_freeme) + 1,
+                      (parent->physical ? 1 : 0),
+                      (int)parent->underway,
+                      (parent->address ? parent->address : "(no address)"));
                parent->underway = FALSE;
                HTAnchor_delete(parent);
            }
*** lynx2-8-2.old/WWW/Library/Implementation/HTUtils.h  Wed Dec 16 15:56:42 1998
--- lynx2-8-2/WWW/Library/Implementation/HTUtils.h      Sun Jan 17 04:14:08 1999
***************
*** 311,320 ****
  
  Sucess (>=0) and failure (<0) codes
  
   */
  
! #define HT_REDIRECTING 29996
! #define HT_LOADED 29997                 /* Instead of a socket */
  #define HT_PARTIAL_CONTENT      206     /* Partial Content */
  #define HT_INTERRUPTED -29998
  #define HT_NOT_LOADED -29999
--- 311,323 ----
  
  Sucess (>=0) and failure (<0) codes
  
+ Some of the values are chosen to be HTTP-like, but status return values
+ are generally not the response status from any specific protocol.
+ 
   */
  
! #define HT_REDIRECTING 399
! #define HT_LOADED 200                   /* Instead of a socket */
  #define HT_PARTIAL_CONTENT      206     /* Partial Content */
  #define HT_INTERRUPTED -29998
  #define HT_NOT_LOADED -29999
***************
*** 323,332 ****
  #define HT_ERROR                -1      /* Generic failure */
  
  #define HT_CANNOT_TRANSLATE -4
! #define HT_NO_ACCESS    -10             /* Access not available */
! #define HT_FORBIDDEN    -11             /* Access forbidden */
  #define HT_NO_DATA            -204    /* OK but no data was loaded - */
                                        /* possibly other app started or forked 
*/
  #define HT_INTERNAL             -900    /* Weird -- should never happen. */
  #define HT_BAD_EOF      -12             /* Premature EOF */
  
--- 326,338 ----
  #define HT_ERROR                -1      /* Generic failure */
  
  #define HT_CANNOT_TRANSLATE -4
! 
  #define HT_NO_DATA            -204    /* OK but no data was loaded - */
                                        /* possibly other app started or forked 
*/
+ #define HT_NO_ACCESS            -401    /* Access not available */
+ #define HT_FORBIDDEN            -403    /* Access forbidden */
+ #define HT_NOT_ACCEPTABLE       -406    /* Not Acceptable */
+ 
  #define HT_INTERNAL             -900    /* Weird -- should never happen. */
  #define HT_BAD_EOF      -12             /* Premature EOF */
  
*** lynx2-8-2.old/WWW/Library/Implementation/HTTCP.h    Sat Dec 12 22:10:36 1998
--- lynx2-8-2/WWW/Library/Implementation/HTTCP.h        Sun Jan 17 05:04:28 1999
***************
*** 69,74 ****
--- 69,75 ----
                  char            **pp,
                  unsigned int    max_value));
  
+ extern BOOL valid_hostname PARAMS((CONST char * name));
  
  /*      Parse an internet node address and port
  **      ---------------------------------------
*** lynx2-8-2.old/WWW/Library/Implementation/HTTCP.c    Mon Jan 18 06:29:20 1999
--- lynx2-8-2/WWW/Library/Implementation/HTTCP.c        Tue Jan 19 20:03:24 1999
***************
*** 309,314 ****
--- 309,360 ----
  }
  #endif /* !DECNET */
  
+ /*    Check whether string is a valid Internet hostname - kw
+ **    -------------------------------------------------
+ **
+ **  Checks whether
+ **  - contains only valid chars for domain names (actually, the
+ **    restrictions are somewhat relaxed),
+ **  - no leading dots or empty segments,
+ **  - max. length of dot-separated segment <= 63 (RFC 1034,1035),
+ **  - total length <= 254 (if it ends with dot) or 253 (otherwise)
+ **     [an interpretation of RFC 1034,1035, although RFC 1123
+ **      suggests 255 as limit - kw].
+ **
+ **  Note: user (before '@') and port (after ':') components from
+ **      host part of URL should be already stripped (if appropriate)
+ **      from the input string.
+ **
+ **  On exit,
+ **    returns 1 if valid, otherwise 0.
+ */
+ PUBLIC BOOL valid_hostname ARGS1(
+       CONST char *,   name)
+ {
+     int i=1, iseg = 0;
+     CONST char *cp = name;
+     if (!(name && *name))
+       return NO;
+     for (; (*cp && i <= 253); cp++, i++) {
+       if (*cp == '.') {
+           if (iseg == 0) {
+               return NO;
+           } else {
+               iseg = 0;
+               continue;
+           }
+       } else if (++iseg > 63) {
+               return NO;
+       }
+       if (!isalnum((unsigned char)*cp) &&
+           *cp != '-' && *cp != '_' &&
+           *cp != '$' && *cp != '+') {
+           return NO;
+       }
+     }
+     return (*cp == '\0' || (*cp == '.' && iseg != 0 && cp[1] == '\0'));
+ }
+ 
  #ifdef NSL_FORK
  /*
  **  Function to allow us to be killed with a normal signal (not
***************
*** 440,445 ****
--- 486,498 ----
        FREE(host);
  #endif /* _WINDOWS_NSL */
      } else {              /* Alphanumeric node name: */
+       if (!valid_hostname(host)) {
+ #ifndef _WINDOWS_NSL
+           FREE(host);
+ #endif /* _WINDOWS_NSL */
+           return HT_NOT_ACCEPTABLE; /* only HTDoConnect checks this. */
+       }
+ 
  #ifdef MVS    /* Outstanding problem with crash in MVS gethostbyname */
        CTRACE(tfp, "HTParseInet: Calling gethostbyname(%s)\n", host);
  #endif /* MVS */
***************
*** 886,893 ****
      status = HTParseInet(soc_in, host);
      if (status) {
        if (status != HT_INTERRUPTED) {
!           sprintf (line, gettext("Unable to locate remote host %s."), host);
!           _HTProgress(line);
            status = HT_NO_DATA;
        }
        FREE(host);
--- 939,955 ----
      status = HTParseInet(soc_in, host);
      if (status) {
        if (status != HT_INTERRUPTED) {
!           if (status == HT_NOT_ACCEPTABLE) {
!               /*  Not HTProgress, so warning won't be overwritten
!                *  immediately; but not HTAlert, because typically
!                *  there will be other alerts from the callers. - kw
!                */
!               HTUserMsg2(gettext("Invalid hostname %s"), host);
!           } else {
!               sprintf (line,
!                        gettext("Unable to locate remote host %s."), host);
!               _HTProgress(line);
!           }
            status = HT_NO_DATA;
        }
        FREE(host);
*** lynx2-8-2.old/WWW/Library/Implementation/HTTelnet.c Wed Dec 16 15:56:42 1998
--- lynx2-8-2/WWW/Library/Implementation/HTTelnet.c     Sun Jan 17 04:53:24 1999
***************
*** 88,93 ****
--- 88,105 ----
        if (!hostname || *hostname == '\0') {
            CTRACE(tfp, "HTTelnet: No host specified!\n");
            return HT_NO_DATA;
+       } else if (!valid_hostname(hostname)) {
+           char *prefix = NULL;
+           char *line = NULL;
+           CTRACE(tfp, "HTTelnet: Invalid hostname %s!\n", host);
+           HTSprintf0(&prefix,
+                      gettext("remote %s session:"), acc_method);
+           HTSprintf0(&line,
+                      gettext("Invalid hostname %s"), host);
+           HTAlwaysAlert(prefix, line);
+           FREE(prefix);
+           FREE(line);
+           return HT_NO_DATA;
        }
  
        if (user) {
***************
*** 131,136 ****
--- 143,149 ----
            printf("When you are connected, log in as:  %s\n", user);
        if (password && login_protocol != rlogin)
            printf("                  The password is:  %s\n", password);
+       fflush(stdout);
  
  /*
   *    NeXTSTEP is the implied version of the NeXT operating system.
*** lynx2-8-2.old/WWW/Library/Implementation/HTTP.c     Thu Dec 24 05:27:22 1998
--- lynx2-8-2/WWW/Library/Implementation/HTTP.c Wed Jan 20 21:07:26 1999
***************
*** 305,318 ****
--- 305,338 ----
          StrAllocCat(command, line);
        }
  
+ #if 0
        /*
        **  Promote 300 (Multiple Choices) replies, if supported,
        **  over 406 (Not Acceptable) replies. - FM
+       **
+       **  This used to be done in versions 2.7 and 2.8*, but violates
+       **  the specs for transparent content negotiation and has the
+       **  effect that servers supporting those specs will send 300
+       **  (Multiple Choices) instead of a normal response (e.g. 200 OK),
+       **  since they will assume that the client wants to make the
+       **  choice.  It is not clear whether there are any servers or sites
+       **  for which sending this header really improves anything.
+       **  
+       **  If there ever is a need to send "Negotiate: trans" and really
+       **  mean it, we should send "Negotiate: trans,trans" or similar,
+       **  since that is semantically equivalent and some servers may
+       **  ignore "Negotiate: trans" as a special case when it comes from
+       **  Lynx (to work around the old faulty behavior). - kw
+       **
+       **  References:
+       **  RFC 2295 (see also RFC 2296), and mail to lynx-dev and
+       **  address@hidden from Koen Holtman, Jan 1999.
        */
        if (!do_post) {
          sprintf(line, "Negotiate: trans%c%c", CR, LF);
          StrAllocCat(command, line);
        }
+ #endif /* 0 */
  
        /*
        **  When reloading give no-cache pragma to proxy server to make

reply via email to

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