httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1185898 - in /httpd/httpd/trunk: modules/filters/mod_include.c modules/proxy/mod_proxy_ftp.c server/util_expr_eval.c
Date Tue, 18 Oct 2011 22:02:28 GMT
Author: sf
Date: Tue Oct 18 22:02:26 2011
New Revision: 1185898

URL: http://svn.apache.org/viewvc?rev=1185898&view=rev
Log:
regex related cleanups:
- use AP_MAX_REG_MATCH where appropriate
- in mod_proxy_ftp, compile the "ls -s1" regex only once instead of once per request
- add some coments

Modified:
    httpd/httpd/trunk/modules/filters/mod_include.c
    httpd/httpd/trunk/modules/proxy/mod_proxy_ftp.c
    httpd/httpd/trunk/server/util_expr_eval.c

Modified: httpd/httpd/trunk/modules/filters/mod_include.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/filters/mod_include.c?rev=1185898&r1=1185897&r2=1185898&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/filters/mod_include.c (original)
+++ httpd/httpd/trunk/modules/filters/mod_include.c Tue Oct 18 22:02:26 2011
@@ -674,12 +674,9 @@ static const char *get_include_var(const
             return NULL;
         }
         else if (re->match[idx].rm_so < 0 || re->match[idx].rm_eo < 0) {
-            /* I don't think this can happen if have_match is true.
-             * But let's not risk a regression by dropping this
-             */
+            /* This particular subpattern was not used by the regex */
             return NULL;
         }
-
         else {
             val = apr_pstrmemdup(ctx->dpool, re->source + re->match[idx].rm_so,
                                  re->match[idx].rm_eo - re->match[idx].rm_so);

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy_ftp.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy_ftp.c?rev=1185898&r1=1185897&r2=1185898&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy_ftp.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy_ftp.c Tue Oct 18 22:02:26 2011
@@ -363,6 +363,7 @@ typedef struct {
 /* fallback regex for ls -s1;  ($0..$2) == 3 */
 #define LS_REG_PATTERN "^ *([0-9]+) +([^ ]+)$"
 #define LS_REG_MATCH   3
+ap_regex_t *ls_regex = NULL;
 
 static apr_status_t proxy_send_dir_filter(ap_filter_t *f,
                                           apr_bucket_brigade *in)
@@ -524,14 +525,8 @@ static apr_status_t proxy_send_dir_filte
         char *filename;
         int found = 0;
         int eos = 0;
-
-        ap_regex_t *re = NULL;
         ap_regmatch_t re_result[LS_REG_MATCH];
 
-        /* Compile the output format of "ls -s1" as a fallback for non-unix ftp listings
*/
-        re = ap_pregcomp(p, LS_REG_PATTERN, AP_REG_EXTENDED);
-        ap_assert(re != NULL);
-
         /* get a complete line */
         /* if the buffer overruns - throw data away */
         while (!found && !APR_BRIGADE_EMPTY(ctx->in)) {
@@ -654,8 +649,11 @@ static apr_status_t proxy_send_dir_filte
             }
         }
         /* Try a fallback for listings in the format of "ls -s1" */
-        else if (0 == ap_regexec(re, ctx->buffer, LS_REG_MATCH, re_result, 0)) {
-
+        else if (0 == ap_regexec(ls_regex, ctx->buffer, LS_REG_MATCH, re_result, 0)) {
+            /*
+             * We don't need to check for rm_eo == rm_so == -1 here since ls_regex
+             * is such that $2 cannot be unset if we have a match.
+             */
             filename = apr_pstrndup(p, &ctx->buffer[re_result[2].rm_so], re_result[2].rm_eo
- re_result[2].rm_so);
 
             str = apr_pstrcat(p, ap_escape_html(p, apr_pstrndup(p, ctx->buffer, re_result[2].rm_so)),
@@ -2016,6 +2014,9 @@ static void ap_proxy_ftp_register_hook(a
     /* filters */
     ap_register_output_filter("PROXY_SEND_DIR", proxy_send_dir_filter,
                               NULL, AP_FTYPE_RESOURCE);
+    /* Compile the output format of "ls -s1" as a fallback for non-unix ftp listings */
+    ls_regex = ap_pregcomp(p, LS_REG_PATTERN, AP_REG_EXTENDED);
+    ap_assert(ls_regex != NULL);
 }
 
 static const command_rec proxy_ftp_cmds[] =

Modified: httpd/httpd/trunk/server/util_expr_eval.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/util_expr_eval.c?rev=1185898&r1=1185897&r2=1185898&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util_expr_eval.c (original)
+++ httpd/httpd/trunk/server/util_expr_eval.c Tue Oct 18 22:02:26 2011
@@ -749,7 +749,7 @@ AP_DECLARE(int) ap_expr_exec_re(request_
     ap_expr_eval_ctx_t ctx;
     int dont_vary = (info->flags & AP_EXPR_FLAG_DONT_VARY);
     const char *tmp_source = NULL, *vary_this = NULL;
-    ap_regmatch_t tmp_pmatch[10];
+    ap_regmatch_t tmp_pmatch[AP_MAX_REG_MATCH];
 
     AP_DEBUG_ASSERT((info->flags & AP_EXPR_FLAG_STRING_RESULT) == 0);
 
@@ -766,7 +766,7 @@ AP_DECLARE(int) ap_expr_exec_re(request_
     ctx.data = NULL;
 
     if (!pmatch) {
-        ctx.re_nmatch = 10;
+        ctx.re_nmatch = AP_MAX_REG_MATCH;
         ctx.re_pmatch = tmp_pmatch;
         ctx.re_source = &tmp_source;
     }
@@ -784,7 +784,7 @@ AP_DECLARE(const char *) ap_expr_str_exe
     ap_expr_eval_ctx_t ctx;
     int dont_vary, rc;
     const char *tmp_source = NULL, *vary_this = NULL;
-    ap_regmatch_t tmp_pmatch[10];
+    ap_regmatch_t tmp_pmatch[AP_MAX_REG_MATCH];
     const char *result;
 
     AP_DEBUG_ASSERT(info->flags & AP_EXPR_FLAG_STRING_RESULT);
@@ -811,7 +811,7 @@ AP_DECLARE(const char *) ap_expr_str_exe
     ctx.result_string = &result;
 
     if (!pmatch) {
-        ctx.re_nmatch = 10;
+        ctx.re_nmatch = AP_MAX_REG_MATCH;
         ctx.re_pmatch = tmp_pmatch;
         ctx.re_source = &tmp_source;
     }



Mime
View raw message