]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Move ap_pregcomp and ap_pregfree from APR to Apache proper, since these
authorManoj Kasichainula <manoj@apache.org>
Mon, 20 Sep 1999 22:18:51 +0000 (22:18 +0000)
committerManoj Kasichainula <manoj@apache.org>
Mon, 20 Sep 1999 22:18:51 +0000 (22:18 +0000)
functions depend on Apache's regex libraries. This also should fix
compilation on platforms not using hsregex.

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

include/httpd.h
server/util.c

index 6ec8b340db5e08abe4912efe9adfc9c8370289a4..9e76702c95782e84441c5d07c1f87ddbf020a18e 100644 (file)
@@ -962,6 +962,9 @@ void os2pathname(char *path);
 char *ap_double_quotes(ap_context_t *p, char *str);
 #endif
 
+API_EXPORT(regex_t *) ap_pregcomp(ap_context_t *p, const char *pattern,
+                                  int cflags);
+API_EXPORT(void) ap_pregfree(ap_context_t *p, regex_t *reg);
 API_EXPORT(int)    ap_regexec(const regex_t *preg, const char *string,
                               size_t nmatch, regmatch_t pmatch[], int eflags);
 API_EXPORT(size_t) ap_regerror(int errcode, const regex_t *preg, 
index 9e142e0ae264e3404c33e088c617847263f491bd..a44632e2a71f9300a542a92b2847bb357a8eadaa 100644 (file)
@@ -348,6 +348,42 @@ API_EXPORT(int) ap_is_matchexp(const char *str)
     return 0;
 }
 
+/*
+ * Here's a pool-based interface to POSIX regex's regcomp().
+ * Note that we return regex_t instead of being passed one.
+ * The reason is that if you use an already-used regex_t structure,
+ * the memory that you've already allocated gets forgotten, and
+ * regfree() doesn't clear it. So we don't allow it.
+ */
+
+static ap_status_t regex_cleanup(void *preg)
+{
+    regfree((regex_t *) preg);
+    return APR_SUCCESS;
+}
+
+API_EXPORT(regex_t *) ap_pregcomp(ap_context_t *p, const char *pattern,
+                                  int cflags)
+{
+    regex_t *preg = ap_palloc(p, sizeof(regex_t));
+
+    if (regcomp(preg, pattern, cflags)) {
+       return NULL;
+    }
+
+    ap_register_cleanup(p, (void *) preg, regex_cleanup, regex_cleanup);
+
+    return preg;
+}
+
+API_EXPORT(void) ap_pregfree(ap_context_t *p, regex_t * reg)
+{
+    ap_block_alarms();
+    regfree(reg);
+    ap_kill_cleanup(p, (void *) reg, regex_cleanup);
+    ap_unblock_alarms();
+}
+
 /* 
  * Apache stub function for the regex libraries regexec() to make sure the
  * whole regex(3) API is available through the Apache (exported) namespace.