From: Martin Kraemer Date: Tue, 29 Jan 2002 17:56:42 +0000 (+0000) Subject: If the ftp proxy could not guess the output format of the ftp server's X-Git-Tag: 2.0.31~42 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6452dfac8e32d6b852eb75e5a640596ea224f366;p=thirdparty%2Fapache%2Fhttpd.git If the ftp proxy could not guess the output format of the ftp server's 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 --- diff --git a/modules/proxy/proxy_ftp.c b/modules/proxy/proxy_ftp.c index 13b2ed56350..523deea1323 100644 --- a/modules/proxy/proxy_ftp.c +++ b/modules/proxy/proxy_ftp.c @@ -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)), + "", + ap_escape_html(p, filename), "\n", NULL); + } else { strcat(ctx->buffer, "\n"); /* re-append the newline */ str = ap_escape_html(p, ctx->buffer);