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_MATCH "MATCH_"
92 /* Arguments for ap_pcre_version_string */
93 enum {
96 };
97 
98 /* Error values: */
99 enum {
104 };
105 
106 /* The structure representing a compiled regular expression. */
107 typedef struct {
108  void *re_pcre;
109  int re_nsub;
111 } ap_regex_t;
112 
113 /* The structure in which a captured offset is returned. */
114 typedef struct {
115  int rm_so;
116  int rm_eo;
117 } ap_regmatch_t;
118 
119 /* The functions */
120 
128 AP_DECLARE(const char *) ap_pcre_version_string(int which);
129 
135 
140 AP_DECLARE(void) ap_regcomp_set_default_cflags(int cflags);
141 
149 
158 AP_DECLARE(int) ap_regcomp(ap_regex_t *preg, const char *regex, int cflags);
159 
170 AP_DECLARE(int) ap_regexec(const ap_regex_t *preg, const char *string,
171  apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags);
172 
185 AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff,
186  apr_size_t len, apr_size_t nmatch,
187  ap_regmatch_t *pmatch, int eflags);
188 
196 AP_DECLARE(apr_size_t) ap_regerror(int errcode, const ap_regex_t *preg,
197  char *errbuf, apr_size_t errbuf_size);
198 
207 AP_DECLARE(int) ap_regname(const ap_regex_t *preg,
208  apr_array_header_t *names, const char *prefix,
209  int upper);
210 
214 AP_DECLARE(void) ap_regfree(ap_regex_t *preg);
215 
216 /* ap_rxplus: higher-level regexps */
217 
218 typedef struct {
221  const char *subs;
222  const char *match;
225 } ap_rxplus_t;
226 
242 AP_DECLARE(ap_rxplus_t*) ap_rxplus_compile(apr_pool_t *pool, const char *pattern);
256  const char *pattern, char **newpattern);
257 #ifdef DOXYGEN
258 
265 #else
266 #define ap_rxplus_nmatch(rx) (((rx)->match != NULL) ? (rx)->nmatch : 0)
267 #endif
268 
277 AP_DECLARE(void) ap_rxplus_match(ap_rxplus_t *rx, int n, int *len,
278  const char **match);
288 AP_DECLARE(char*) ap_rxplus_pmatch(apr_pool_t *pool, ap_rxplus_t *rx, int n);
289 
290 #ifdef __cplusplus
291 } /* extern "C" */
292 #endif
293 
294 #endif /* AP_REGEX_H */
Definition: ap_regex.h:218
Definition: ap_regex.h:101
size_t apr_size_t
Definition: apr.h:375
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:552
#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:224
int ap_regcomp_get_default_cflags(void)
const char * ap_pcre_version_string(int which)
const char * prefix
Definition: mod_dav.h:614
int rm_so
Definition: ap_regex.h:115
int ap_rxplus_nmatch(ap_rxplus_t *rx)
apr_size_t nmatch
Definition: ap_regex.h:223
void ap_rxplus_match(ap_rxplus_t *rx, int n, int *len, const char **match)
int re_nsub
Definition: ap_regex.h:109
const char * match
Definition: ap_regex.h:222
int rm_eo
Definition: ap_regex.h:116
int ap_rxplus_exec(apr_pool_t *pool, ap_rxplus_t *rx, const char *pattern, char **newpattern)
Definition: ap_regex.h:107
Definition: ap_regex.h:95
unsigned int apr_uint32_t
Definition: apr.h:334
APR Platform Definitions.
int ap_regcomp_default_cflag_by_name(const char *name)
ap_regex_t rx
Definition: ap_regex.h:219
Definition: ap_regex.h:102
apr_uint32_t flags
Definition: ap_regex.h:220
const char * name
Definition: mod_dav.h:726
void * re_pcre
Definition: ap_regex.h:108
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
Definition: ap_regex.h:114
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:110
const char * subs
Definition: ap_regex.h:221
Definition: ap_regex.h:100
Definition: ap_regex.h:103
Definition: ap_regex.h:94
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)