]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed ftpParseListing loop
authorwessels <>
Wed, 22 Apr 1998 02:41:20 +0000 (02:41 +0000)
committerwessels <>
Wed, 22 Apr 1998 02:41:20 +0000 (02:41 +0000)
Added full error message to ERR_FTP_FAIL error pages

src/errorpage.cc
src/ftp.cc
src/structs.h

index f56f686e0bff7dd524630c39dab18c56c063aa7e..4004e5a7a63495ed93eefb0b9af56f00381e6d37 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: errorpage.cc,v 1.124 1998/03/31 05:37:39 wessels Exp $
+ * $Id: errorpage.cc,v 1.125 1998/04/21 20:41:20 wessels Exp $
  *
  * DEBUG: section 4     Error Generation
  * AUTHOR: Duane Wessels
@@ -347,6 +347,7 @@ errorStateFree(ErrorState * err)
  * E - strerror()                               x
  * f - FTP request line                         x
  * F - FTP reply line                           x
+ * g - FTP server message                       x
  * h - cache hostname                           x
  * H - server host name                         x
  * i - client IP address                        x
@@ -372,6 +373,8 @@ errorConvert(char token, ErrorState * err)
     request_t *r = err->request;
     static char buf[CVT_BUF_SZ];
     const char *p = buf;
+    wordlist *w;
+    int o;
     switch (token) {
     case 'B':
        p = r ? ftpUrlWith2f(r) : "[no URL]";
@@ -399,6 +402,16 @@ errorConvert(char token, ErrorState * err)
        else
            p = "<none>";
        break;
+    case 'g':
+       /* FTP SERVER MESSAGE */
+       buf[0] = '\0';
+       o = 0;
+       for (w = err->ftp_server_msg; w; w = w->next) {
+           o += snprintf(buf + o, CVT_BUF_SZ - o, "%s\n", w->key);
+           if (o >= CVT_BUF_SZ)
+               break;
+       }
+       break;
     case 'h':
        snprintf(buf, CVT_BUF_SZ, "%s", getMyHostname());
        break;
index 77e98ce838bd2a6cf3c6dfefa26d95fe78bd6f01..37018071b34d4d9e1175abd17e6c9b6d0a6009be 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ftp.cc,v 1.218 1998/04/08 04:23:52 wessels Exp $
+ * $Id: ftp.cc,v 1.219 1998/04/21 20:41:21 wessels Exp $
  *
  * DEBUG: section 9     File Transfer Protocol (FTP)
  * AUTHOR: Harvest Derived
@@ -692,7 +692,7 @@ static void
 ftpParseListing(FtpStateData * ftpState, int len)
 {
     char *buf = ftpState->data.buf;
-    char *sbuf;                /* NULL-terminated copy of buf */
+    char *sbuf;                        /* NULL-terminated copy of buf */
     char *end;
     char *line;
     char *s;
@@ -700,29 +700,39 @@ ftpParseListing(FtpStateData * ftpState, int len)
     size_t linelen;
     size_t usable;
     StoreEntry *e = ftpState->entry;
+    /*
+     * There may have been 'data.offset' bytes left over from a previous
+     * call here
+     */
     len += ftpState->data.offset;
-    end = buf + len - 1;
-    while (*end != '\r' && *end != '\n' && end > buf)
+    /*
+     * We need a NULL-terminated buffer for scanning, ick
+     */
+    sbuf = xmalloc(len + 1);
+    xstrncpy(sbuf, buf, len + 1);
+    end = sbuf + len - 1;
+    while (*end != '\r' && *end != '\n' && end > sbuf)
        end--;
-    usable = end - buf;
+    usable = end - sbuf;
     if (usable == 0) {
        debug(9, 3) ("ftpParseListing: didn't find end for %s\n", storeUrl(e));
+       xfree(sbuf);
        return;
     }
+    debug(9, 3) ("ftpParseListing: %d bytes to play with\n", len);
     line = memAllocate(MEM_4K_BUF);
     end++;
-    /* XXX, buf needs to be NULL terminated, copying is gross */
-    sbuf = xmalloc(len+1);
-    xstrncpy(sbuf, buf, len+1);
     storeBuffer(e);
-    for (s = sbuf; s < end; s += strcspn(s, crlf), s += strspn(s, crlf)) {
+    for (s = sbuf; s < end; s += strcspn(s, crlf)) {
+       s += strspn(s, crlf);
+       debug(9, 3) ("ftpParseListing: s = {%s}\n", s);
        linelen = strcspn(s, crlf) + 1;
        if (linelen < 2)
            break;
        if (linelen > 4096)
            linelen = 4096;
        xstrncpy(line, s, linelen);
-       debug(9, 7) ("%s\n", line);
+       debug(9, 7) ("ftpParseListing: {%s}\n", line);
        if (!strncmp(line, "total", 5))
            continue;
        t = ftpHtmlifyListEntry(line, ftpState);
@@ -1160,6 +1170,7 @@ ftpReadControlReply(int fd, void *data)
                err = errorCon(ERR_FTP_FAILURE, HTTP_INTERNAL_SERVER_ERROR);
                err->xerrno = 0;
                err->request = requestLink(ftpState->request);
+               err->ftp_server_msg = ftpState->ctrl.message;
                errorAppendEntry(entry, err);
            }
        }
@@ -2025,6 +2036,7 @@ ftpFail(FtpStateData * ftpState)
     }
     err = errorCon(ERR_FTP_FAILURE, HTTP_INTERNAL_SERVER_ERROR);
     err->request = requestLink(ftpState->request);
+    err->ftp_server_msg = ftpState->ctrl.message;
     if (ftpState->old_request)
        err->ftp.request = ftpState->old_request;
     else
index aa4cfcf5e54babe17d8d0b7731429a2a32b68bc1..27dbe3b537d75bd0aca20f89854bf5df4281734d 100644 (file)
@@ -1138,6 +1138,7 @@ struct _ErrorState {
        char *reply;
     } ftp;
     char *request_hdrs;
+    wordlist *ftp_server_msg;
 };
 
 /*