]> granicus.if.org Git - apache/commitdiff
If the ftp proxy could not guess the output format of the ftp server's
authorMartin Kraemer <martin@apache.org>
Tue, 29 Jan 2002 17:56:42 +0000 (17:56 +0000)
committerMartin Kraemer <martin@apache.org>
Tue, 29 Jan 2002 17:56:42 +0000 (17:56 +0000)
directory listing, it makes another attempt: it tries a format similar to
the output of "ls -s1" (optional whitespace followed by size, followed by
whitespace, followed by filename, where filename may contain no more whitespace).
This format works at least with one FTP server for which previously only
the (non-clickable) output was displayed.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93081 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/proxy_ftp.c

index 13b2ed56350862cf5a160748e1c21c0e5c4830fd..523deea1323c7a287bf5eece74eea10e2214b1aa 100644 (file)
@@ -273,6 +273,8 @@ apr_status_t ap_proxy_send_dir_filter(ap_filter_t *f, apr_bucket_brigade *in)
     apr_bucket *e;
     apr_bucket_brigade *out = apr_brigade_create(p);
     apr_status_t rv;
+    regex_t *re = NULL; /* @@@ put this in the context */
+    regmatch_t re_result[3];
 
     register int n;
     char *dir, *path, *reldir, *site, *str;
@@ -281,6 +283,7 @@ apr_status_t ap_proxy_send_dir_filter(ap_filter_t *f, apr_bucket_brigade *in)
     const char *readme = apr_table_get(r->notes, "Directory-README");
 
     proxy_dir_ctx_t *ctx = f->ctx;
+
     if (!ctx) {
         f->ctx = ctx = apr_pcalloc(p, sizeof(*ctx));
         ctx->in = apr_brigade_create(p);
@@ -288,6 +291,9 @@ apr_status_t ap_proxy_send_dir_filter(ap_filter_t *f, apr_bucket_brigade *in)
         ctx->state = HEADER;
     }
 
+    /* Compile the output format of "ls -s1" as a fallback for non-unix ftp listings */
+    re = ap_pregcomp(p, "^ *([0-9]+) +([^ ]+)$", REG_EXTENDED);
+
     /* combine the stored and the new */
     APR_BRIGADE_CONCAT(ctx->in, in);
 
@@ -478,6 +484,15 @@ apr_status_t ap_proxy_send_dir_filter(ap_filter_t *f, apr_bucket_brigade *in)
                                    ap_escape_html(p, filename));
             }
         }
+        /* Try a fallback for listings in the format of "ls -s1" */
+        else if (0 == ap_regexec(re, ctx->buffer, 3, re_result, 0)) {
+
+            char *filename = apr_pstrndup(p, &ctx->buffer[re_result[2].rm_so], re_result[2].rm_eo - re_result[2].rm_so);
+
+            str = ap_pstrcat(p, ap_escape_html(p, apr_pstrndup(p, &ctx->buffer[0], re_result[2].rm_so)),
+                             "<a href=\"", ap_escape_uri(p, filename), "\">",
+                             ap_escape_html(p, filename), "</a>\n", NULL);
+        }
         else {
             strcat(ctx->buffer, "\n"); /* re-append the newline */
             str = ap_escape_html(p, ctx->buffer);