Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 <ph10@cam.ac.uk>, 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 -----------------------------------------------------------------------------
27 Redistribution and use in source and binary forms, with or without
28 modification, 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 
41 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
42 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
45 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
46 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
48 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51 POSSIBILITY 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
68 extern "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
82 #define AP_REG_NOMEM 0x20
83 #define AP_REG_DOTALL 0x40
85 #define AP_REG_NOTEMPTY 0x080
86 #define AP_REG_ANCHORED 0x100
88 #define AP_REG_DOLLAR_ENDONLY 0x200
90 #define AP_REG_NO_DEFAULT 0x400
92 #define AP_REG_MATCH "MATCH_"
94 #define AP_REG_DEFAULT (AP_REG_DOTALL|AP_REG_DOLLAR_ENDONLY)
95 
96 /* Arguments for ap_pcre_version_string */
97 enum {
100 };
101 
102 /* Error values: */
103 enum {
108 };
109 
110 /* The structure representing a compiled regular expression. */
111 typedef struct {
112  void *re_pcre;
113  int re_nsub;
115 } ap_regex_t;
116 
117 /* The structure in which a captured offset is returned. */
118 typedef struct {
119  int rm_so;
120  int rm_eo;
121 } ap_regmatch_t;
122 
123 /* The functions */
124 
132 AP_DECLARE(const char *) ap_pcre_version_string(int which);
133 
139 
144 AP_DECLARE(void) ap_regcomp_set_default_cflags(int cflags);
145 
153 
162 AP_DECLARE(int) ap_regcomp(ap_regex_t *preg, const char *regex, int cflags);
163 
174 AP_DECLARE(int) ap_regexec(const ap_regex_t *preg, const char *string,
175  apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags);
176 
189 AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff,
190  apr_size_t len, apr_size_t nmatch,
191  ap_regmatch_t *pmatch, int eflags);
192 
200 AP_DECLARE(apr_size_t) ap_regerror(int errcode, const ap_regex_t *preg,
201  char *errbuf, apr_size_t errbuf_size);
202 
211 AP_DECLARE(int) ap_regname(const ap_regex_t *preg,
212  apr_array_header_t *names, const char *prefix,
213  int upper);
214 
218 AP_DECLARE(void) ap_regfree(ap_regex_t *preg);
219 
220 /* ap_rxplus: higher-level regexps */
221 
222 typedef struct {
225  const char *subs;
226  const char *match;
229 } ap_rxplus_t;
230 
246 AP_DECLARE(ap_rxplus_t*) ap_rxplus_compile(apr_pool_t *pool, const char *pattern);
260  const char *pattern, char **newpattern);
261 #ifdef DOXYGEN
262 
269 #else
270 #define ap_rxplus_nmatch(rx) (((rx)->match != NULL) ? (rx)->nmatch : 0)
271 #endif
272 
281 AP_DECLARE(void) ap_rxplus_match(ap_rxplus_t *rx, int n, int *len,
282  const char **match);
292 AP_DECLARE(char*) ap_rxplus_pmatch(apr_pool_t *pool, ap_rxplus_t *rx, int n);
293 
294 #ifdef __cplusplus
295 } /* extern "C" */
296 #endif
297 
298 #endif /* AP_REGEX_H */
Definition: ap_regex.h:222
Definition: ap_regex.h:105
size_t apr_size_t
Definition: apr.h:393
Definition: apr_tables.h:62
int ap_regcomp(ap_regex_t *preg, const char *regex, int cflags)
void ap_regcomp_set_default_cflags(int cflags)
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:555
#define AP_DECLARE(x)
Definition: macros.h:1
ap_rxplus_t * ap_rxplus_compile(apr_pool_t *pool, const char *pattern)
char * ap_rxplus_pmatch(apr_pool_t *pool, ap_rxplus_t *rx, int n)
int ap_regname(const ap_regex_t *preg, apr_array_header_t *names, const char *prefix, int upper)
apr_size_t ap_regerror(int errcode, const ap_regex_t *preg, char *errbuf, apr_size_t errbuf_size)
ap_regmatch_t * pmatch
Definition: ap_regex.h:228
int ap_regcomp_get_default_cflags(void)
const char * ap_pcre_version_string(int which)
const char * prefix
Definition: mod_dav.h:631
int rm_so
Definition: ap_regex.h:119
int ap_rxplus_nmatch(ap_rxplus_t *rx)
apr_size_t nmatch
Definition: ap_regex.h:227
void ap_rxplus_match(ap_rxplus_t *rx, int n, int *len, const char **match)
int re_nsub
Definition: ap_regex.h:113
const char * match
Definition: ap_regex.h:226
int rm_eo
Definition: ap_regex.h:120
int ap_rxplus_exec(apr_pool_t *pool, ap_rxplus_t *rx, const char *pattern, char **newpattern)
Definition: ap_regex.h:111
Definition: ap_regex.h:99
unsigned int apr_uint32_t
Definition: apr.h:347
APR Platform Definitions.
int ap_regcomp_default_cflag_by_name(const char *name)
ap_regex_t rx
Definition: ap_regex.h:223
Definition: ap_regex.h:106
apr_uint32_t flags
Definition: ap_regex.h:224
const char * name
Definition: mod_dav.h:805
void * re_pcre
Definition: ap_regex.h:112
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
Definition: ap_regex.h:118
int ap_regexec_len(const ap_regex_t *preg, const char *buff, apr_size_t len, apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags)
apr_size_t re_erroffset
Definition: ap_regex.h:114
const char * subs
Definition: ap_regex.h:225
Definition: ap_regex.h:104
Definition: ap_regex.h:107
Definition: ap_regex.h:98
void ap_regfree(ap_regex_t *preg)
int ap_regexec(const ap_regex_t *preg, const char *string, apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags)