]> granicus.if.org Git - apache/blobdiff - server/util_regex.c
eventMPM:
[apache] / server / util_regex.c
index 458e4f6f14de4bf6efcbb94c48ef789c88429b53..81eac5308d28c8095209bdda1f6cb38ff972cd4b 100644 (file)
 #include "ap_regex.h"
 #include "httpd.h"
 
+static apr_status_t rxplus_cleanup(void *preg)
+{
+    ap_regfree((ap_regex_t *) preg);
+    return APR_SUCCESS;
+}
+
 AP_DECLARE(ap_rxplus_t*) ap_rxplus_compile(apr_pool_t *pool,
                                            const char *pattern)
 {
@@ -61,7 +67,7 @@ AP_DECLARE(ap_rxplus_t*) ap_rxplus_compile(apr_pool_t *pool,
     }
     if (!endp) { /* there's no delim  or flags */
         if (ap_regcomp(&ret->rx, pattern, 0) == 0) {
-            apr_pool_cleanup_register(pool, &ret->rx, (void*) ap_regfree,
+            apr_pool_cleanup_register(pool, &ret->rx, rxplus_cleanup,
                                       apr_pool_cleanup_null);
             return ret;
         }
@@ -100,7 +106,7 @@ AP_DECLARE(ap_rxplus_t*) ap_rxplus_compile(apr_pool_t *pool,
         }
     }
     if (ap_regcomp(&ret->rx, rxstr, ret->flags) == 0) {
-        apr_pool_cleanup_register(pool, &ret->rx, (void*) ap_regfree,
+        apr_pool_cleanup_register(pool, &ret->rx, rxplus_cleanup,
                                   apr_pool_cleanup_null);
     }
     else {
@@ -132,9 +138,7 @@ AP_DECLARE(ap_rxplus_t*) ap_rxplus_compile(apr_pool_t *pool,
 
 AP_DECLARE(int) ap_rxplus_exec(apr_pool_t *pool, ap_rxplus_t *rx,
                                const char *pattern, char **newpattern)
-                               //int max_iterations)
 {
-#if 1
     int ret = 1;
     int startl, oldl, newl, diffsz;
     const char *remainder;
@@ -158,7 +162,6 @@ AP_DECLARE(int) ap_rxplus_exec(apr_pool_t *pool, ap_rxplus_t *rx,
         remainder = pattern + startl + oldl;
         if (rx->flags & AP_REG_MULTI) {
             /* recurse to do any further matches */
-            char *subs;
             ret += ap_rxplus_exec(pool, rx, remainder, &subs);
             if (ret > 1) {
                 /* a further substitution happened */
@@ -173,61 +176,6 @@ AP_DECLARE(int) ap_rxplus_exec(apr_pool_t *pool, ap_rxplus_t *rx,
         *newpattern = subs;
     }
     return ret;
-        
-
-
-
-#else
-
-
-
-
-
-
-
-
-
-
-
-
-    if (!(rx->flags & AP_REG_MULTI) || (rx->subs == NULL)) {
-        max_iterations = 1;
-    }
-    /* FIXME: multi-matching is incorrect */
-    while (max_iterations-- > 0) {
-        if (ap_regexec(&rx->rx, pattern, rx->nmatch, rx->pmatch, rx->flags)
-            == 0) {
-            ret++;
-            if (rx->subs) {
-                rx->match = pattern;
-                *newpattern = ap_pregsub(pool, rx->subs, pattern,
-                                         rx->nmatch, rx->pmatch);
-                pattern = *newpattern;
-                if (pattern == NULL) {
-                    max_iterations = 0;
-                }
-            }
-        }
-        else {
-            max_iterations = 0;
-        }
-    }
-
-    if (ret == 0 || rx->flags&AP_REG_NOMEM) {
-        rx->match = NULL;  /* no match, so don't pretend to remember a match */
-    }
-    else {
-#if 0
-        /* FIXME - should we be 'safe' and take the performance hit,
-         * or just document thou-shalt-keep-pattern-in-scope?
-         */
-        if (rx->match == inpattern) {
-            rx->match = apr_pstrdup(pool, inpattern);
-        }
-#endif
-    }
-    return ret;
-#endif
 }
 #ifdef DOXYGEN
 AP_DECLARE(int) ap_rxplus_nmatch(ap_rxplus_t *rx)
@@ -257,5 +205,5 @@ AP_DECLARE(char*) ap_rxplus_pmatch(apr_pool_t *pool, ap_rxplus_t *rx, int n)
     int len;
     const char *match;
     ap_rxplus_match(rx, n, &len, &match);
-    return (match != NULL) ? apr_pstrndup(pool, match, len) : NULL;
+    return apr_pstrndup(pool, match, len);
 }