Apache HTTPD
ap_regex.h
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* This code is based on pcreposix.h from the PCRE Library distribution,
18 * as originally written by Philip Hazel <[email protected]>, and forked by
19 * the Apache HTTP Server project to provide POSIX-style regex function
20 * wrappers around underlying PCRE library functions for httpd.
21 *
22 * The original source file pcreposix.h is copyright and licensed as follows;
23
24 Copyright (c) 1997-2004 University of Cambridge
25
26-----------------------------------------------------------------------------
27Redistribution and use in source and binary forms, with or without
28modification, are permitted provided that the following conditions are met:
29
30 * Redistributions of source code must retain the above copyright notice,
31 this list of conditions and the following disclaimer.
32
33 * Redistributions in binary form must reproduce the above copyright
34 notice, this list of conditions and the following disclaimer in the
35 documentation and/or other materials provided with the distribution.
36
37 * Neither the name of the University of Cambridge nor the names of its
38 contributors may be used to endorse or promote products derived from
39 this software without specific prior written permission.
40
41THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
42AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
45LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
46CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
48INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51POSSIBILITY OF SUCH DAMAGE.
52-----------------------------------------------------------------------------
53*/
54
60#ifndef AP_REGEX_H
61#define AP_REGEX_H
62
63#include "apr.h"
64
65/* Allow for C++ users */
66
67#ifdef __cplusplus
68extern "C" {
69#endif
70
71/* Options for ap_regcomp, ap_regexec, and ap_rxplus versions: */
72
73#define AP_REG_ICASE 0x01
74#define AP_REG_NEWLINE 0x02
75#define AP_REG_NOTBOL 0x04
76#define AP_REG_NOTEOL 0x08
78#define AP_REG_EXTENDED (0)
79#define AP_REG_NOSUB (0)
81#define AP_REG_MULTI 0x10 /* perl's /g (needs fixing) */
82#define AP_REG_NOMEM 0x20 /* nomem in our code */
83#define AP_REG_DOTALL 0x40 /* perl's /s flag */
84
85#define AP_REG_DOLLAR_ENDONLY 0x200 /* '$' matches at end of subject string only */
86
87#define AP_REG_NO_DEFAULT 0x400
89#define AP_REG_MATCH "MATCH_"
91#define AP_REG_DEFAULT (AP_REG_DOTALL|AP_REG_DOLLAR_ENDONLY)
92
93/* Arguments for ap_pcre_version_string */
94enum {
97};
98
99/* Error values: */
100enum {
106
107/* The structure representing a compiled regular expression. */
108typedef struct {
109 void *re_pcre;
111 apr_size_t re_erroffset;
112} ap_regex_t;
113
114/* The structure in which a captured offset is returned. */
115typedef struct {
116 int rm_so;
117 int rm_eo;
119
120/* The functions */
121
129AP_DECLARE(const char *) ap_pcre_version_string(int which);
130
135AP_DECLARE(int) ap_regcomp_get_default_cflags(void);
136
141AP_DECLARE(void) ap_regcomp_set_default_cflags(int cflags);
142
149AP_DECLARE(int) ap_regcomp_default_cflag_by_name(const char *name);
150
159AP_DECLARE(int) ap_regcomp(ap_regex_t *preg, const char *regex, int cflags);
160
171AP_DECLARE(int) ap_regexec(const ap_regex_t *preg, const char *string,
172 apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags);
173
186AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff,
187 apr_size_t len, apr_size_t nmatch,
189
197AP_DECLARE(apr_size_t) ap_regerror(int errcode, const ap_regex_t *preg,
198 char *errbuf, apr_size_t errbuf_size);
199
208AP_DECLARE(int) ap_regname(const ap_regex_t *preg,
210 int upper);
211
215AP_DECLARE(void) ap_regfree(ap_regex_t *preg);
216
217/* ap_rxplus: higher-level regexps */
218
219typedef struct {
221 apr_uint32_t flags;
222 const char *subs;
223 const char *match;
224 apr_size_t nmatch;
227
257 const char *pattern, char **newpattern);
258#ifdef DOXYGEN
266#else
267#define ap_rxplus_nmatch(rx) (((rx)->match != NULL) ? (rx)->nmatch : 0)
268#endif
279 const char **match);
290
291#ifdef __cplusplus
292} /* extern "C" */
293#endif
294
295#endif /* AP_REGEX_T */
296
@ AP_REG_PCRE_LOADED
Definition ap_regex.h:96
@ AP_REG_PCRE_COMPILED
Definition ap_regex.h:95
int n
Definition ap_regex.h:278
int int const char ** match
Definition ap_regex.h:279
const char * pattern
Definition ap_regex.h:243
const char apr_size_t ap_regmatch_t * pmatch
Definition ap_regex.h:172
const char * buff
Definition ap_regex.h:186
const char int cflags
Definition ap_regex.h:159
const ap_regex_t * preg
Definition ap_regex.h:197
apr_array_header_t const char int upper
Definition ap_regex.h:210
const ap_regex_t char apr_size_t errbuf_size
Definition ap_regex.h:198
ap_rxplus_t * rx
Definition ap_regex.h:256
const char * regex
Definition ap_regex.h:159
const char apr_size_t ap_regmatch_t int eflags
Definition ap_regex.h:172
#define ap_rxplus_nmatch(rx)
Definition ap_regex.h:267
const char apr_size_t len
Definition ap_regex.h:187
ap_rxplus_t const char char ** newpattern
Definition ap_regex.h:257
const char apr_size_t nmatch
Definition ap_regex.h:172
@ AP_REG_ESPACE
Definition ap_regex.h:102
@ AP_REG_NOMATCH
Definition ap_regex.h:104
@ AP_REG_INVARG
Definition ap_regex.h:103
@ AP_REG_ASSERT
Definition ap_regex.h:101
const ap_regex_t char * errbuf
Definition ap_regex.h:198
AP_DECLARE(void) ap_regcomp_set_default_cflags(int cflags)
int * errcode
Definition apr_dbm.h:183
const char int apr_pool_t * pool
Definition apr_cstr.h:84
apr_interface_e which
char * name
apr_size_t re_erroffset
Definition ap_regex.h:111
int re_nsub
Definition ap_regex.h:110
void * re_pcre
Definition ap_regex.h:109
ap_regex_t rx
Definition ap_regex.h:220
const char * subs
Definition ap_regex.h:222
const char * match
Definition ap_regex.h:223
apr_uint32_t flags
Definition ap_regex.h:221
ap_regmatch_t * pmatch
Definition ap_regex.h:225
apr_size_t nmatch
Definition ap_regex.h:224
int ap_rxplus_exec(apr_pool_t *pool, ap_rxplus_t *rx, const char *pattern, char **newpattern)
Definition util_regex.c:141
char * ap_rxplus_pmatch(apr_pool_t *pool, ap_rxplus_t *rx, int n)
Definition util_regex.c:205
ap_rxplus_t * ap_rxplus_compile(apr_pool_t *pool, const char *pattern)
Definition util_regex.c:31
void ap_rxplus_match(ap_rxplus_t *rx, int n, int *len, const char **match)
Definition util_regex.c:193