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 /* Derived from PCRE's pcreposix.h.
18 
19  Copyright (c) 1997-2004 University of Cambridge
20 
21 -----------------------------------------------------------------------------
22 Redistribution and use in source and binary forms, with or without
23 modification, are permitted provided that the following conditions are met:
24 
25  * Redistributions of source code must retain the above copyright notice,
26  this list of conditions and the following disclaimer.
27 
28  * Redistributions in binary form must reproduce the above copyright
29  notice, this list of conditions and the following disclaimer in the
30  documentation and/or other materials provided with the distribution.
31 
32  * Neither the name of the University of Cambridge nor the names of its
33  contributors may be used to endorse or promote products derived from
34  this software without specific prior written permission.
35 
36 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
37 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
40 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
41 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
42 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
44 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46 POSSIBILITY OF SUCH DAMAGE.
47 -----------------------------------------------------------------------------
48 */
49 
55 #ifndef AP_REGEX_H
56 #define AP_REGEX_H
57 
58 #include "apr.h"
59 
60 /* Allow for C++ users */
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 /* Options for ap_regcomp, ap_regexec, and ap_rxplus versions: */
67 
68 #define AP_REG_ICASE 0x01
69 #define AP_REG_NEWLINE 0x02
70 #define AP_REG_NOTBOL 0x04
71 #define AP_REG_NOTEOL 0x08
73 #define AP_REG_EXTENDED (0)
74 #define AP_REG_NOSUB (0)
76 #define AP_REG_MULTI 0x10
77 #define AP_REG_NOMEM 0x20
78 #define AP_REG_DOTALL 0x40
80 #define AP_REG_MATCH "MATCH_"
82 /* Arguments for ap_pcre_version_string */
83 enum {
86 };
87 
88 /* Error values: */
89 enum {
94 };
95 
96 /* The structure representing a compiled regular expression. */
97 typedef struct {
98  void *re_pcre;
99  int re_nsub;
101 } ap_regex_t;
102 
103 /* The structure in which a captured offset is returned. */
104 typedef struct {
105  int rm_so;
106  int rm_eo;
107 } ap_regmatch_t;
108 
109 /* The functions */
110 
118 AP_DECLARE(const char *) ap_pcre_version_string(int which);
119 
128 AP_DECLARE(int) ap_regcomp(ap_regex_t *preg, const char *regex, int cflags);
129 
140 AP_DECLARE(int) ap_regexec(const ap_regex_t *preg, const char *string,
141  apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags);
142 
155 AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff,
156  apr_size_t len, apr_size_t nmatch,
157  ap_regmatch_t *pmatch, int eflags);
158 
166 AP_DECLARE(apr_size_t) ap_regerror(int errcode, const ap_regex_t *preg,
167  char *errbuf, apr_size_t errbuf_size);
168 
177 AP_DECLARE(int) ap_regname(const ap_regex_t *preg,
178  apr_array_header_t *names, const char *prefix,
179  int upper);
180 
184 AP_DECLARE(void) ap_regfree(ap_regex_t *preg);
185 
186 /* ap_rxplus: higher-level regexps */
187 
188 typedef struct {
191  const char *subs;
192  const char *match;
195 } ap_rxplus_t;
196 
212 AP_DECLARE(ap_rxplus_t*) ap_rxplus_compile(apr_pool_t *pool, const char *pattern);
226  const char *pattern, char **newpattern);
227 #ifdef DOXYGEN
228 
235 #else
236 #define ap_rxplus_nmatch(rx) (((rx)->match != NULL) ? (rx)->nmatch : 0)
237 #endif
238 
247 AP_DECLARE(void) ap_rxplus_match(ap_rxplus_t *rx, int n, int *len,
248  const char **match);
258 AP_DECLARE(char*) ap_rxplus_pmatch(apr_pool_t *pool, ap_rxplus_t *rx, int n);
259 
260 #ifdef __cplusplus
261 } /* extern "C" */
262 #endif
263 
264 #endif /* AP_REGEX_H */
Definition: ap_regex.h:188
Definition: ap_regex.h:91
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)
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:556
#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:194
const char * ap_pcre_version_string(int which)
const char * prefix
Definition: mod_dav.h:618
int rm_so
Definition: ap_regex.h:105
int ap_rxplus_nmatch(ap_rxplus_t *rx)
apr_size_t nmatch
Definition: ap_regex.h:193
void ap_rxplus_match(ap_rxplus_t *rx, int n, int *len, const char **match)
int re_nsub
Definition: ap_regex.h:99
const char * match
Definition: ap_regex.h:192
int rm_eo
Definition: ap_regex.h:106
int ap_rxplus_exec(apr_pool_t *pool, ap_rxplus_t *rx, const char *pattern, char **newpattern)
Definition: ap_regex.h:97
Definition: ap_regex.h:85
unsigned int apr_uint32_t
Definition: apr.h:334
APR Platform Definitions.
ap_regex_t rx
Definition: ap_regex.h:189
Definition: ap_regex.h:92
apr_uint32_t flags
Definition: ap_regex.h:190
void * re_pcre
Definition: ap_regex.h:98
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
Definition: ap_regex.h:104
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:100
const char * subs
Definition: ap_regex.h:191
Definition: ap_regex.h:90
Definition: ap_regex.h:93
Definition: ap_regex.h:84
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)