xref: /PHP-7.4/ext/pcre/pcre2lib/pcre2_context.c (revision 225117af)
1a5bc5aedSAnatol Belski /*************************************************
2a5bc5aedSAnatol Belski *      Perl-Compatible Regular Expressions       *
3a5bc5aedSAnatol Belski *************************************************/
4a5bc5aedSAnatol Belski 
5a5bc5aedSAnatol Belski /* PCRE is a library of functions to support regular expressions whose syntax
6a5bc5aedSAnatol Belski and semantics are as close as possible to those of the Perl 5 language.
7a5bc5aedSAnatol Belski 
8a5bc5aedSAnatol Belski                        Written by Philip Hazel
9a5bc5aedSAnatol Belski      Original API code Copyright (c) 1997-2012 University of Cambridge
10aa9433e9SAnatol Belski           New API code Copyright (c) 2016-2018 University of Cambridge
11a5bc5aedSAnatol Belski 
12a5bc5aedSAnatol Belski -----------------------------------------------------------------------------
13a5bc5aedSAnatol Belski Redistribution and use in source and binary forms, with or without
14a5bc5aedSAnatol Belski modification, are permitted provided that the following conditions are met:
15a5bc5aedSAnatol Belski 
16a5bc5aedSAnatol Belski     * Redistributions of source code must retain the above copyright notice,
17a5bc5aedSAnatol Belski       this list of conditions and the following disclaimer.
18a5bc5aedSAnatol Belski 
19a5bc5aedSAnatol Belski     * Redistributions in binary form must reproduce the above copyright
20a5bc5aedSAnatol Belski       notice, this list of conditions and the following disclaimer in the
21a5bc5aedSAnatol Belski       documentation and/or other materials provided with the distribution.
22a5bc5aedSAnatol Belski 
23a5bc5aedSAnatol Belski     * Neither the name of the University of Cambridge nor the names of its
24a5bc5aedSAnatol Belski       contributors may be used to endorse or promote products derived from
25a5bc5aedSAnatol Belski       this software without specific prior written permission.
26a5bc5aedSAnatol Belski 
27a5bc5aedSAnatol Belski THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28a5bc5aedSAnatol Belski AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29a5bc5aedSAnatol Belski IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30a5bc5aedSAnatol Belski ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31a5bc5aedSAnatol Belski LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32a5bc5aedSAnatol Belski CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33a5bc5aedSAnatol Belski SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34a5bc5aedSAnatol Belski INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35a5bc5aedSAnatol Belski CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36a5bc5aedSAnatol Belski ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37a5bc5aedSAnatol Belski POSSIBILITY OF SUCH DAMAGE.
38a5bc5aedSAnatol Belski -----------------------------------------------------------------------------
39a5bc5aedSAnatol Belski */
40a5bc5aedSAnatol Belski 
41a5bc5aedSAnatol Belski 
42a5bc5aedSAnatol Belski #ifdef HAVE_CONFIG_H
43a5bc5aedSAnatol Belski #include "config.h"
44a5bc5aedSAnatol Belski #endif
45a5bc5aedSAnatol Belski 
46a5bc5aedSAnatol Belski #include "pcre2_internal.h"
47a5bc5aedSAnatol Belski 
48a5bc5aedSAnatol Belski 
49a5bc5aedSAnatol Belski 
50a5bc5aedSAnatol Belski /*************************************************
51a5bc5aedSAnatol Belski *          Default malloc/free functions         *
52a5bc5aedSAnatol Belski *************************************************/
53a5bc5aedSAnatol Belski 
54a5bc5aedSAnatol Belski /* Ignore the "user data" argument in each case. */
55a5bc5aedSAnatol Belski 
default_malloc(size_t size,void * data)56a5bc5aedSAnatol Belski static void *default_malloc(size_t size, void *data)
57a5bc5aedSAnatol Belski {
58a5bc5aedSAnatol Belski (void)data;
59a5bc5aedSAnatol Belski return malloc(size);
60a5bc5aedSAnatol Belski }
61a5bc5aedSAnatol Belski 
62a5bc5aedSAnatol Belski 
default_free(void * block,void * data)63a5bc5aedSAnatol Belski static void default_free(void *block, void *data)
64a5bc5aedSAnatol Belski {
65a5bc5aedSAnatol Belski (void)data;
66a5bc5aedSAnatol Belski free(block);
67a5bc5aedSAnatol Belski }
68a5bc5aedSAnatol Belski 
69a5bc5aedSAnatol Belski 
70a5bc5aedSAnatol Belski 
71a5bc5aedSAnatol Belski /*************************************************
72a5bc5aedSAnatol Belski *        Get a block and save memory control     *
73a5bc5aedSAnatol Belski *************************************************/
74a5bc5aedSAnatol Belski 
75a5bc5aedSAnatol Belski /* This internal function is called to get a block of memory in which the
76a5bc5aedSAnatol Belski memory control data is to be stored at the start for future use.
77a5bc5aedSAnatol Belski 
78a5bc5aedSAnatol Belski Arguments:
79a5bc5aedSAnatol Belski   size        amount of memory required
80a5bc5aedSAnatol Belski   memctl      pointer to a memctl block or NULL
81a5bc5aedSAnatol Belski 
82a5bc5aedSAnatol Belski Returns:      pointer to memory or NULL on failure
83a5bc5aedSAnatol Belski */
84a5bc5aedSAnatol Belski 
85a5bc5aedSAnatol Belski extern void *
PRIV(memctl_malloc)86a5bc5aedSAnatol Belski PRIV(memctl_malloc)(size_t size, pcre2_memctl *memctl)
87a5bc5aedSAnatol Belski {
88a5bc5aedSAnatol Belski pcre2_memctl *newmemctl;
89a5bc5aedSAnatol Belski void *yield = (memctl == NULL)? malloc(size) :
90a5bc5aedSAnatol Belski   memctl->malloc(size, memctl->memory_data);
91a5bc5aedSAnatol Belski if (yield == NULL) return NULL;
92a5bc5aedSAnatol Belski newmemctl = (pcre2_memctl *)yield;
93a5bc5aedSAnatol Belski if (memctl == NULL)
94a5bc5aedSAnatol Belski   {
95a5bc5aedSAnatol Belski   newmemctl->malloc = default_malloc;
96a5bc5aedSAnatol Belski   newmemctl->free = default_free;
97a5bc5aedSAnatol Belski   newmemctl->memory_data = NULL;
98a5bc5aedSAnatol Belski   }
99a5bc5aedSAnatol Belski else *newmemctl = *memctl;
100a5bc5aedSAnatol Belski return yield;
101a5bc5aedSAnatol Belski }
102a5bc5aedSAnatol Belski 
103a5bc5aedSAnatol Belski 
104a5bc5aedSAnatol Belski 
105a5bc5aedSAnatol Belski /*************************************************
106a5bc5aedSAnatol Belski *          Create and initialize contexts        *
107a5bc5aedSAnatol Belski *************************************************/
108a5bc5aedSAnatol Belski 
109a5bc5aedSAnatol Belski /* Initializing for compile and match contexts is done in separate, private
110a5bc5aedSAnatol Belski functions so that these can be called from functions such as pcre2_compile()
111a5bc5aedSAnatol Belski when an external context is not supplied. The initializing functions have an
112a5bc5aedSAnatol Belski option to set up default memory management. */
113a5bc5aedSAnatol Belski 
114a5bc5aedSAnatol Belski PCRE2_EXP_DEFN pcre2_general_context * PCRE2_CALL_CONVENTION
pcre2_general_context_create(void * (* private_malloc)(size_t,void *),void (* private_free)(void *,void *),void * memory_data)115a5bc5aedSAnatol Belski pcre2_general_context_create(void *(*private_malloc)(size_t, void *),
116a5bc5aedSAnatol Belski   void (*private_free)(void *, void *), void *memory_data)
117a5bc5aedSAnatol Belski {
118a5bc5aedSAnatol Belski pcre2_general_context *gcontext;
119a5bc5aedSAnatol Belski if (private_malloc == NULL) private_malloc = default_malloc;
120a5bc5aedSAnatol Belski if (private_free == NULL) private_free = default_free;
121a5bc5aedSAnatol Belski gcontext = private_malloc(sizeof(pcre2_real_general_context), memory_data);
122a5bc5aedSAnatol Belski if (gcontext == NULL) return NULL;
123a5bc5aedSAnatol Belski gcontext->memctl.malloc = private_malloc;
124a5bc5aedSAnatol Belski gcontext->memctl.free = private_free;
125a5bc5aedSAnatol Belski gcontext->memctl.memory_data = memory_data;
126a5bc5aedSAnatol Belski return gcontext;
127a5bc5aedSAnatol Belski }
128a5bc5aedSAnatol Belski 
129a5bc5aedSAnatol Belski 
130a5bc5aedSAnatol Belski /* A default compile context is set up to save having to initialize at run time
131a5bc5aedSAnatol Belski when no context is supplied to the compile function. */
132a5bc5aedSAnatol Belski 
133a5bc5aedSAnatol Belski const pcre2_compile_context PRIV(default_compile_context) = {
134a5bc5aedSAnatol Belski   { default_malloc, default_free, NULL },    /* Default memory handling */
135a5bc5aedSAnatol Belski   NULL,                                      /* Stack guard */
136a5bc5aedSAnatol Belski   NULL,                                      /* Stack guard data */
137a5bc5aedSAnatol Belski   PRIV(default_tables),                      /* Character tables */
138a5bc5aedSAnatol Belski   PCRE2_UNSET,                               /* Max pattern length */
139a5bc5aedSAnatol Belski   BSR_DEFAULT,                               /* Backslash R default */
140a5bc5aedSAnatol Belski   NEWLINE_DEFAULT,                           /* Newline convention */
141a5bc5aedSAnatol Belski   PARENS_NEST_LIMIT,                         /* As it says */
142a5bc5aedSAnatol Belski   0 };                                       /* Extra options */
143a5bc5aedSAnatol Belski 
144a5bc5aedSAnatol Belski /* The create function copies the default into the new memory, but must
145a5bc5aedSAnatol Belski override the default memory handling functions if a gcontext was provided. */
146a5bc5aedSAnatol Belski 
147a5bc5aedSAnatol Belski PCRE2_EXP_DEFN pcre2_compile_context * PCRE2_CALL_CONVENTION
pcre2_compile_context_create(pcre2_general_context * gcontext)148a5bc5aedSAnatol Belski pcre2_compile_context_create(pcre2_general_context *gcontext)
149a5bc5aedSAnatol Belski {
150a5bc5aedSAnatol Belski pcre2_compile_context *ccontext = PRIV(memctl_malloc)(
151a5bc5aedSAnatol Belski   sizeof(pcre2_real_compile_context), (pcre2_memctl *)gcontext);
152a5bc5aedSAnatol Belski if (ccontext == NULL) return NULL;
153a5bc5aedSAnatol Belski *ccontext = PRIV(default_compile_context);
154a5bc5aedSAnatol Belski if (gcontext != NULL)
155a5bc5aedSAnatol Belski   *((pcre2_memctl *)ccontext) = *((pcre2_memctl *)gcontext);
156a5bc5aedSAnatol Belski return ccontext;
157a5bc5aedSAnatol Belski }
158a5bc5aedSAnatol Belski 
159a5bc5aedSAnatol Belski 
160a5bc5aedSAnatol Belski /* A default match context is set up to save having to initialize at run time
161a5bc5aedSAnatol Belski when no context is supplied to a match function. */
162a5bc5aedSAnatol Belski 
163a5bc5aedSAnatol Belski const pcre2_match_context PRIV(default_match_context) = {
164a5bc5aedSAnatol Belski   { default_malloc, default_free, NULL },
165a5bc5aedSAnatol Belski #ifdef SUPPORT_JIT
166aa9433e9SAnatol Belski   NULL,          /* JIT callback */
167aa9433e9SAnatol Belski   NULL,          /* JIT callback data */
168a5bc5aedSAnatol Belski #endif
169aa9433e9SAnatol Belski   NULL,          /* Callout function */
170aa9433e9SAnatol Belski   NULL,          /* Callout data */
171aa9433e9SAnatol Belski   NULL,          /* Substitute callout function */
172aa9433e9SAnatol Belski   NULL,          /* Substitute callout data */
173a5bc5aedSAnatol Belski   PCRE2_UNSET,   /* Offset limit */
174a5bc5aedSAnatol Belski   HEAP_LIMIT,
175a5bc5aedSAnatol Belski   MATCH_LIMIT,
176a5bc5aedSAnatol Belski   MATCH_LIMIT_DEPTH };
177a5bc5aedSAnatol Belski 
178a5bc5aedSAnatol Belski /* The create function copies the default into the new memory, but must
179a5bc5aedSAnatol Belski override the default memory handling functions if a gcontext was provided. */
180a5bc5aedSAnatol Belski 
181a5bc5aedSAnatol Belski PCRE2_EXP_DEFN pcre2_match_context * PCRE2_CALL_CONVENTION
pcre2_match_context_create(pcre2_general_context * gcontext)182a5bc5aedSAnatol Belski pcre2_match_context_create(pcre2_general_context *gcontext)
183a5bc5aedSAnatol Belski {
184a5bc5aedSAnatol Belski pcre2_match_context *mcontext = PRIV(memctl_malloc)(
185a5bc5aedSAnatol Belski   sizeof(pcre2_real_match_context), (pcre2_memctl *)gcontext);
186a5bc5aedSAnatol Belski if (mcontext == NULL) return NULL;
187a5bc5aedSAnatol Belski *mcontext = PRIV(default_match_context);
188a5bc5aedSAnatol Belski if (gcontext != NULL)
189a5bc5aedSAnatol Belski   *((pcre2_memctl *)mcontext) = *((pcre2_memctl *)gcontext);
190a5bc5aedSAnatol Belski return mcontext;
191a5bc5aedSAnatol Belski }
192a5bc5aedSAnatol Belski 
193a5bc5aedSAnatol Belski 
194a5bc5aedSAnatol Belski /* A default convert context is set up to save having to initialize at run time
195a5bc5aedSAnatol Belski when no context is supplied to the convert function. */
196a5bc5aedSAnatol Belski 
197a5bc5aedSAnatol Belski const pcre2_convert_context PRIV(default_convert_context) = {
198a5bc5aedSAnatol Belski   { default_malloc, default_free, NULL },    /* Default memory handling */
199a5bc5aedSAnatol Belski #ifdef _WIN32
200a5bc5aedSAnatol Belski   CHAR_BACKSLASH,                            /* Default path separator */
201a5bc5aedSAnatol Belski   CHAR_GRAVE_ACCENT                          /* Default escape character */
202a5bc5aedSAnatol Belski #else  /* Not Windows */
203a5bc5aedSAnatol Belski   CHAR_SLASH,                                /* Default path separator */
204a5bc5aedSAnatol Belski   CHAR_BACKSLASH                             /* Default escape character */
205a5bc5aedSAnatol Belski #endif
206a5bc5aedSAnatol Belski   };
207a5bc5aedSAnatol Belski 
208a5bc5aedSAnatol Belski /* The create function copies the default into the new memory, but must
209a5bc5aedSAnatol Belski override the default memory handling functions if a gcontext was provided. */
210a5bc5aedSAnatol Belski 
211a5bc5aedSAnatol Belski PCRE2_EXP_DEFN pcre2_convert_context * PCRE2_CALL_CONVENTION
pcre2_convert_context_create(pcre2_general_context * gcontext)212a5bc5aedSAnatol Belski pcre2_convert_context_create(pcre2_general_context *gcontext)
213a5bc5aedSAnatol Belski {
214a5bc5aedSAnatol Belski pcre2_convert_context *ccontext = PRIV(memctl_malloc)(
215a5bc5aedSAnatol Belski   sizeof(pcre2_real_convert_context), (pcre2_memctl *)gcontext);
216a5bc5aedSAnatol Belski if (ccontext == NULL) return NULL;
217a5bc5aedSAnatol Belski *ccontext = PRIV(default_convert_context);
218a5bc5aedSAnatol Belski if (gcontext != NULL)
219a5bc5aedSAnatol Belski   *((pcre2_memctl *)ccontext) = *((pcre2_memctl *)gcontext);
220a5bc5aedSAnatol Belski return ccontext;
221a5bc5aedSAnatol Belski }
222a5bc5aedSAnatol Belski 
223a5bc5aedSAnatol Belski 
224a5bc5aedSAnatol Belski /*************************************************
225a5bc5aedSAnatol Belski *              Context copy functions            *
226a5bc5aedSAnatol Belski *************************************************/
227a5bc5aedSAnatol Belski 
228a5bc5aedSAnatol Belski PCRE2_EXP_DEFN pcre2_general_context * PCRE2_CALL_CONVENTION
pcre2_general_context_copy(pcre2_general_context * gcontext)229a5bc5aedSAnatol Belski pcre2_general_context_copy(pcre2_general_context *gcontext)
230a5bc5aedSAnatol Belski {
231a5bc5aedSAnatol Belski pcre2_general_context *new =
232a5bc5aedSAnatol Belski   gcontext->memctl.malloc(sizeof(pcre2_real_general_context),
233a5bc5aedSAnatol Belski   gcontext->memctl.memory_data);
234a5bc5aedSAnatol Belski if (new == NULL) return NULL;
235a5bc5aedSAnatol Belski memcpy(new, gcontext, sizeof(pcre2_real_general_context));
236a5bc5aedSAnatol Belski return new;
237a5bc5aedSAnatol Belski }
238a5bc5aedSAnatol Belski 
239a5bc5aedSAnatol Belski 
240a5bc5aedSAnatol Belski PCRE2_EXP_DEFN pcre2_compile_context * PCRE2_CALL_CONVENTION
pcre2_compile_context_copy(pcre2_compile_context * ccontext)241a5bc5aedSAnatol Belski pcre2_compile_context_copy(pcre2_compile_context *ccontext)
242a5bc5aedSAnatol Belski {
243a5bc5aedSAnatol Belski pcre2_compile_context *new =
244a5bc5aedSAnatol Belski   ccontext->memctl.malloc(sizeof(pcre2_real_compile_context),
245a5bc5aedSAnatol Belski   ccontext->memctl.memory_data);
246a5bc5aedSAnatol Belski if (new == NULL) return NULL;
247a5bc5aedSAnatol Belski memcpy(new, ccontext, sizeof(pcre2_real_compile_context));
248a5bc5aedSAnatol Belski return new;
249a5bc5aedSAnatol Belski }
250a5bc5aedSAnatol Belski 
251a5bc5aedSAnatol Belski 
252a5bc5aedSAnatol Belski PCRE2_EXP_DEFN pcre2_match_context * PCRE2_CALL_CONVENTION
pcre2_match_context_copy(pcre2_match_context * mcontext)253a5bc5aedSAnatol Belski pcre2_match_context_copy(pcre2_match_context *mcontext)
254a5bc5aedSAnatol Belski {
255a5bc5aedSAnatol Belski pcre2_match_context *new =
256a5bc5aedSAnatol Belski   mcontext->memctl.malloc(sizeof(pcre2_real_match_context),
257a5bc5aedSAnatol Belski   mcontext->memctl.memory_data);
258a5bc5aedSAnatol Belski if (new == NULL) return NULL;
259a5bc5aedSAnatol Belski memcpy(new, mcontext, sizeof(pcre2_real_match_context));
260a5bc5aedSAnatol Belski return new;
261a5bc5aedSAnatol Belski }
262a5bc5aedSAnatol Belski 
263a5bc5aedSAnatol Belski 
264a5bc5aedSAnatol Belski 
265a5bc5aedSAnatol Belski PCRE2_EXP_DEFN pcre2_convert_context * PCRE2_CALL_CONVENTION
pcre2_convert_context_copy(pcre2_convert_context * ccontext)266a5bc5aedSAnatol Belski pcre2_convert_context_copy(pcre2_convert_context *ccontext)
267a5bc5aedSAnatol Belski {
268a5bc5aedSAnatol Belski pcre2_convert_context *new =
269a5bc5aedSAnatol Belski   ccontext->memctl.malloc(sizeof(pcre2_real_convert_context),
270a5bc5aedSAnatol Belski   ccontext->memctl.memory_data);
271a5bc5aedSAnatol Belski if (new == NULL) return NULL;
272a5bc5aedSAnatol Belski memcpy(new, ccontext, sizeof(pcre2_real_convert_context));
273a5bc5aedSAnatol Belski return new;
274a5bc5aedSAnatol Belski }
275a5bc5aedSAnatol Belski 
276a5bc5aedSAnatol Belski 
277a5bc5aedSAnatol Belski /*************************************************
278a5bc5aedSAnatol Belski *              Context free functions            *
279a5bc5aedSAnatol Belski *************************************************/
280a5bc5aedSAnatol Belski 
281a5bc5aedSAnatol Belski PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
pcre2_general_context_free(pcre2_general_context * gcontext)282a5bc5aedSAnatol Belski pcre2_general_context_free(pcre2_general_context *gcontext)
283a5bc5aedSAnatol Belski {
284a5bc5aedSAnatol Belski if (gcontext != NULL)
285a5bc5aedSAnatol Belski   gcontext->memctl.free(gcontext, gcontext->memctl.memory_data);
286a5bc5aedSAnatol Belski }
287a5bc5aedSAnatol Belski 
288a5bc5aedSAnatol Belski 
289a5bc5aedSAnatol Belski PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
pcre2_compile_context_free(pcre2_compile_context * ccontext)290a5bc5aedSAnatol Belski pcre2_compile_context_free(pcre2_compile_context *ccontext)
291a5bc5aedSAnatol Belski {
292a5bc5aedSAnatol Belski if (ccontext != NULL)
293a5bc5aedSAnatol Belski   ccontext->memctl.free(ccontext, ccontext->memctl.memory_data);
294a5bc5aedSAnatol Belski }
295a5bc5aedSAnatol Belski 
296a5bc5aedSAnatol Belski 
297a5bc5aedSAnatol Belski PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
pcre2_match_context_free(pcre2_match_context * mcontext)298a5bc5aedSAnatol Belski pcre2_match_context_free(pcre2_match_context *mcontext)
299a5bc5aedSAnatol Belski {
300a5bc5aedSAnatol Belski if (mcontext != NULL)
301a5bc5aedSAnatol Belski   mcontext->memctl.free(mcontext, mcontext->memctl.memory_data);
302a5bc5aedSAnatol Belski }
303a5bc5aedSAnatol Belski 
304a5bc5aedSAnatol Belski 
305a5bc5aedSAnatol Belski PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
pcre2_convert_context_free(pcre2_convert_context * ccontext)306a5bc5aedSAnatol Belski pcre2_convert_context_free(pcre2_convert_context *ccontext)
307a5bc5aedSAnatol Belski {
308a5bc5aedSAnatol Belski if (ccontext != NULL)
309a5bc5aedSAnatol Belski   ccontext->memctl.free(ccontext, ccontext->memctl.memory_data);
310a5bc5aedSAnatol Belski }
311a5bc5aedSAnatol Belski 
312a5bc5aedSAnatol Belski 
313a5bc5aedSAnatol Belski /*************************************************
314a5bc5aedSAnatol Belski *             Set values in contexts             *
315a5bc5aedSAnatol Belski *************************************************/
316a5bc5aedSAnatol Belski 
317a5bc5aedSAnatol Belski /* All these functions return 0 for success or PCRE2_ERROR_BADDATA if invalid
318a5bc5aedSAnatol Belski data is given. Only some of the functions are able to test the validity of the
319a5bc5aedSAnatol Belski data. */
320a5bc5aedSAnatol Belski 
321a5bc5aedSAnatol Belski 
322a5bc5aedSAnatol Belski /* ------------ Compile context ------------ */
323a5bc5aedSAnatol Belski 
324a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_character_tables(pcre2_compile_context * ccontext,const uint8_t * tables)325a5bc5aedSAnatol Belski pcre2_set_character_tables(pcre2_compile_context *ccontext,
326*225117afSChristoph M. Becker   const uint8_t *tables)
327a5bc5aedSAnatol Belski {
328a5bc5aedSAnatol Belski ccontext->tables = tables;
329a5bc5aedSAnatol Belski return 0;
330a5bc5aedSAnatol Belski }
331a5bc5aedSAnatol Belski 
332a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_bsr(pcre2_compile_context * ccontext,uint32_t value)333a5bc5aedSAnatol Belski pcre2_set_bsr(pcre2_compile_context *ccontext, uint32_t value)
334a5bc5aedSAnatol Belski {
335a5bc5aedSAnatol Belski switch(value)
336a5bc5aedSAnatol Belski   {
337a5bc5aedSAnatol Belski   case PCRE2_BSR_ANYCRLF:
338a5bc5aedSAnatol Belski   case PCRE2_BSR_UNICODE:
339a5bc5aedSAnatol Belski   ccontext->bsr_convention = value;
340a5bc5aedSAnatol Belski   return 0;
341a5bc5aedSAnatol Belski 
342a5bc5aedSAnatol Belski   default:
343a5bc5aedSAnatol Belski   return PCRE2_ERROR_BADDATA;
344a5bc5aedSAnatol Belski   }
345a5bc5aedSAnatol Belski }
346a5bc5aedSAnatol Belski 
347a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_max_pattern_length(pcre2_compile_context * ccontext,PCRE2_SIZE length)348a5bc5aedSAnatol Belski pcre2_set_max_pattern_length(pcre2_compile_context *ccontext, PCRE2_SIZE length)
349a5bc5aedSAnatol Belski {
350a5bc5aedSAnatol Belski ccontext->max_pattern_length = length;
351a5bc5aedSAnatol Belski return 0;
352a5bc5aedSAnatol Belski }
353a5bc5aedSAnatol Belski 
354a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_newline(pcre2_compile_context * ccontext,uint32_t newline)355a5bc5aedSAnatol Belski pcre2_set_newline(pcre2_compile_context *ccontext, uint32_t newline)
356a5bc5aedSAnatol Belski {
357a5bc5aedSAnatol Belski switch(newline)
358a5bc5aedSAnatol Belski   {
359a5bc5aedSAnatol Belski   case PCRE2_NEWLINE_CR:
360a5bc5aedSAnatol Belski   case PCRE2_NEWLINE_LF:
361a5bc5aedSAnatol Belski   case PCRE2_NEWLINE_CRLF:
362a5bc5aedSAnatol Belski   case PCRE2_NEWLINE_ANY:
363a5bc5aedSAnatol Belski   case PCRE2_NEWLINE_ANYCRLF:
364a5bc5aedSAnatol Belski   case PCRE2_NEWLINE_NUL:
365a5bc5aedSAnatol Belski   ccontext->newline_convention = newline;
366a5bc5aedSAnatol Belski   return 0;
367a5bc5aedSAnatol Belski 
368a5bc5aedSAnatol Belski   default:
369a5bc5aedSAnatol Belski   return PCRE2_ERROR_BADDATA;
370a5bc5aedSAnatol Belski   }
371a5bc5aedSAnatol Belski }
372a5bc5aedSAnatol Belski 
373a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_parens_nest_limit(pcre2_compile_context * ccontext,uint32_t limit)374a5bc5aedSAnatol Belski pcre2_set_parens_nest_limit(pcre2_compile_context *ccontext, uint32_t limit)
375a5bc5aedSAnatol Belski {
376a5bc5aedSAnatol Belski ccontext->parens_nest_limit = limit;
377a5bc5aedSAnatol Belski return 0;
378a5bc5aedSAnatol Belski }
379a5bc5aedSAnatol Belski 
380a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_compile_extra_options(pcre2_compile_context * ccontext,uint32_t options)381a5bc5aedSAnatol Belski pcre2_set_compile_extra_options(pcre2_compile_context *ccontext, uint32_t options)
382a5bc5aedSAnatol Belski {
383a5bc5aedSAnatol Belski ccontext->extra_options = options;
384a5bc5aedSAnatol Belski return 0;
385a5bc5aedSAnatol Belski }
386a5bc5aedSAnatol Belski 
387a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_compile_recursion_guard(pcre2_compile_context * ccontext,int (* guard)(uint32_t,void *),void * user_data)388a5bc5aedSAnatol Belski pcre2_set_compile_recursion_guard(pcre2_compile_context *ccontext,
389a5bc5aedSAnatol Belski   int (*guard)(uint32_t, void *), void *user_data)
390a5bc5aedSAnatol Belski {
391a5bc5aedSAnatol Belski ccontext->stack_guard = guard;
392a5bc5aedSAnatol Belski ccontext->stack_guard_data = user_data;
393a5bc5aedSAnatol Belski return 0;
394a5bc5aedSAnatol Belski }
395a5bc5aedSAnatol Belski 
396a5bc5aedSAnatol Belski 
397a5bc5aedSAnatol Belski /* ------------ Match context ------------ */
398a5bc5aedSAnatol Belski 
399a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_callout(pcre2_match_context * mcontext,int (* callout)(pcre2_callout_block *,void *),void * callout_data)400a5bc5aedSAnatol Belski pcre2_set_callout(pcre2_match_context *mcontext,
401a5bc5aedSAnatol Belski   int (*callout)(pcre2_callout_block *, void *), void *callout_data)
402a5bc5aedSAnatol Belski {
403a5bc5aedSAnatol Belski mcontext->callout = callout;
404a5bc5aedSAnatol Belski mcontext->callout_data = callout_data;
405a5bc5aedSAnatol Belski return 0;
406a5bc5aedSAnatol Belski }
407a5bc5aedSAnatol Belski 
408aa9433e9SAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_substitute_callout(pcre2_match_context * mcontext,int (* substitute_callout)(pcre2_substitute_callout_block *,void *),void * substitute_callout_data)409aa9433e9SAnatol Belski pcre2_set_substitute_callout(pcre2_match_context *mcontext,
410aa9433e9SAnatol Belski   int (*substitute_callout)(pcre2_substitute_callout_block *, void *),
411aa9433e9SAnatol Belski     void *substitute_callout_data)
412aa9433e9SAnatol Belski {
413aa9433e9SAnatol Belski mcontext->substitute_callout = substitute_callout;
414aa9433e9SAnatol Belski mcontext->substitute_callout_data = substitute_callout_data;
415aa9433e9SAnatol Belski return 0;
416aa9433e9SAnatol Belski }
417aa9433e9SAnatol Belski 
418a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_heap_limit(pcre2_match_context * mcontext,uint32_t limit)419a5bc5aedSAnatol Belski pcre2_set_heap_limit(pcre2_match_context *mcontext, uint32_t limit)
420a5bc5aedSAnatol Belski {
421a5bc5aedSAnatol Belski mcontext->heap_limit = limit;
422a5bc5aedSAnatol Belski return 0;
423a5bc5aedSAnatol Belski }
424a5bc5aedSAnatol Belski 
425a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_match_limit(pcre2_match_context * mcontext,uint32_t limit)426a5bc5aedSAnatol Belski pcre2_set_match_limit(pcre2_match_context *mcontext, uint32_t limit)
427a5bc5aedSAnatol Belski {
428a5bc5aedSAnatol Belski mcontext->match_limit = limit;
429a5bc5aedSAnatol Belski return 0;
430a5bc5aedSAnatol Belski }
431a5bc5aedSAnatol Belski 
432a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_depth_limit(pcre2_match_context * mcontext,uint32_t limit)433a5bc5aedSAnatol Belski pcre2_set_depth_limit(pcre2_match_context *mcontext, uint32_t limit)
434a5bc5aedSAnatol Belski {
435a5bc5aedSAnatol Belski mcontext->depth_limit = limit;
436a5bc5aedSAnatol Belski return 0;
437a5bc5aedSAnatol Belski }
438a5bc5aedSAnatol Belski 
439a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_offset_limit(pcre2_match_context * mcontext,PCRE2_SIZE limit)440a5bc5aedSAnatol Belski pcre2_set_offset_limit(pcre2_match_context *mcontext, PCRE2_SIZE limit)
441a5bc5aedSAnatol Belski {
442a5bc5aedSAnatol Belski mcontext->offset_limit = limit;
443a5bc5aedSAnatol Belski return 0;
444a5bc5aedSAnatol Belski }
445a5bc5aedSAnatol Belski 
446a5bc5aedSAnatol Belski /* This function became obsolete at release 10.30. It is kept as a synonym for
447a5bc5aedSAnatol Belski backwards compatibility. */
448a5bc5aedSAnatol Belski 
449a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_recursion_limit(pcre2_match_context * mcontext,uint32_t limit)450a5bc5aedSAnatol Belski pcre2_set_recursion_limit(pcre2_match_context *mcontext, uint32_t limit)
451a5bc5aedSAnatol Belski {
452a5bc5aedSAnatol Belski return pcre2_set_depth_limit(mcontext, limit);
453a5bc5aedSAnatol Belski }
454a5bc5aedSAnatol Belski 
455a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_recursion_memory_management(pcre2_match_context * mcontext,void * (* mymalloc)(size_t,void *),void (* myfree)(void *,void *),void * mydata)456a5bc5aedSAnatol Belski pcre2_set_recursion_memory_management(pcre2_match_context *mcontext,
457a5bc5aedSAnatol Belski   void *(*mymalloc)(size_t, void *), void (*myfree)(void *, void *),
458a5bc5aedSAnatol Belski   void *mydata)
459a5bc5aedSAnatol Belski {
460a5bc5aedSAnatol Belski (void)mcontext;
461a5bc5aedSAnatol Belski (void)mymalloc;
462a5bc5aedSAnatol Belski (void)myfree;
463a5bc5aedSAnatol Belski (void)mydata;
464a5bc5aedSAnatol Belski return 0;
465a5bc5aedSAnatol Belski }
466a5bc5aedSAnatol Belski 
467a5bc5aedSAnatol Belski /* ------------ Convert context ------------ */
468a5bc5aedSAnatol Belski 
469a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_glob_separator(pcre2_convert_context * ccontext,uint32_t separator)470a5bc5aedSAnatol Belski pcre2_set_glob_separator(pcre2_convert_context *ccontext, uint32_t separator)
471a5bc5aedSAnatol Belski {
472a5bc5aedSAnatol Belski if (separator != CHAR_SLASH && separator != CHAR_BACKSLASH &&
473a5bc5aedSAnatol Belski     separator != CHAR_DOT) return PCRE2_ERROR_BADDATA;
474a5bc5aedSAnatol Belski ccontext->glob_separator = separator;
475a5bc5aedSAnatol Belski return 0;
476a5bc5aedSAnatol Belski }
477a5bc5aedSAnatol Belski 
478a5bc5aedSAnatol Belski PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_glob_escape(pcre2_convert_context * ccontext,uint32_t escape)479a5bc5aedSAnatol Belski pcre2_set_glob_escape(pcre2_convert_context *ccontext, uint32_t escape)
480a5bc5aedSAnatol Belski {
481a5bc5aedSAnatol Belski if (escape > 255 || (escape != 0 && !ispunct(escape)))
482a5bc5aedSAnatol Belski   return PCRE2_ERROR_BADDATA;
483a5bc5aedSAnatol Belski ccontext->glob_escape = escape;
484a5bc5aedSAnatol Belski return 0;
485a5bc5aedSAnatol Belski }
486a5bc5aedSAnatol Belski 
487a5bc5aedSAnatol Belski /* End of pcre2_context.c */
488a5bc5aedSAnatol Belski 
489