aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_regex.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-11-25 20:44:56 +0000
committerIgor Sysoev <igor@sysoev.ru>2003-11-25 20:44:56 +0000
commita8fa0a6a37b6e90324e0dcbf4733324199623841 (patch)
tree1a7edec9aa04946afc22299bf587823488fb492f /src/core/ngx_regex.c
parentd9d0ca12688034d481e2f1f5cf13a098338ec31d (diff)
downloadnginx-a8fa0a6a37b6e90324e0dcbf4733324199623841.tar.gz
nginx-a8fa0a6a37b6e90324e0dcbf4733324199623841.zip
nginx-0.0.1-2003-11-25-23:44:56 import
Diffstat (limited to 'src/core/ngx_regex.c')
-rw-r--r--src/core/ngx_regex.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/core/ngx_regex.c b/src/core/ngx_regex.c
new file mode 100644
index 000000000..377f998de
--- /dev/null
+++ b/src/core/ngx_regex.c
@@ -0,0 +1,71 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+static void *ngx_regex_malloc(size_t size);
+static void ngx_regex_free(void *p);
+
+
+/* THREADS: this pool should be private for each thread */
+static ngx_pool_t *ngx_pcre_pool;
+
+
+void ngx_regex_init()
+{
+ pcre_malloc = ngx_regex_malloc;
+ pcre_free = ngx_regex_free;
+}
+
+
+ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options,
+ ngx_pool_t *pool, ngx_str_t *err)
+{
+ int erroff;
+ const char *errstr;
+ ngx_regex_t *re;
+
+ ngx_pcre_pool = pool;
+
+ re = pcre_compile(pattern->data, (int) options, &errstr, &erroff, NULL);
+
+ if (re == NULL) {
+ if ((size_t) erroff == pattern->len) {
+ ngx_snprintf(err->data, err->len - 1,
+ "pcre_compile() failed: %s in \"%s\"",
+ errstr, pattern->data);
+ } else {
+ ngx_snprintf(err->data, err->len - 1,
+ "pcre_compile() failed: %s in \"%s\" at \"%s\"",
+ errstr, pattern->data, pattern->data + erroff);
+ }
+ }
+
+ return re;
+}
+
+
+ngx_int_t ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s)
+{
+ int rc;
+
+ rc = pcre_exec(re, NULL, s->data, s->len, 0, 0, NULL, 0);
+
+ if (rc == -1) {
+ return NGX_DECLINED;
+ }
+
+ return rc;
+}
+
+
+static void *ngx_regex_malloc(size_t size)
+{
+ return ngx_palloc(ngx_pcre_pool, size);
+}
+
+
+static void ngx_regex_free(void *p)
+{
+ return;
+}