From: Manoj Kasichainula Date: Mon, 20 Sep 1999 22:18:51 +0000 (+0000) Subject: Move ap_pregcomp and ap_pregfree from APR to Apache proper, since these X-Git-Tag: 1.3.10~319 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8412e9e365c89f5d2c66f52625c2dd38a1d32e74;p=thirdparty%2Fapache%2Fhttpd.git Move ap_pregcomp and ap_pregfree from APR to Apache proper, since these 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 --- diff --git a/include/httpd.h b/include/httpd.h index 6ec8b340db5..9e76702c957 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -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, diff --git a/server/util.c b/server/util.c index 9e142e0ae26..a44632e2a71 100644 --- a/server/util.c +++ b/server/util.c @@ -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.