Updated embedded PCRE to version 7.4 to avoid 2 CVE issues:-
[exim.git] / src / src / pcre / pcre_fullinfo.c
CommitLineData
47db1125 1/* $Cambridge: exim/src/src/pcre/pcre_fullinfo.c,v 1.6 2007/11/12 13:02:19 nm4 Exp $ */
8ac170f3
PH
2
3/*************************************************
4* Perl-Compatible Regular Expressions *
5*************************************************/
6
7/*PCRE is a library of functions to support regular expressions whose syntax
8and semantics are as close as possible to those of the Perl 5 language.
9
10 Written by Philip Hazel
64f2600a 11 Copyright (c) 1997-2007 University of Cambridge
8ac170f3
PH
12
13-----------------------------------------------------------------------------
14Redistribution and use in source and binary forms, with or without
15modification, are permitted provided that the following conditions are met:
16
17 * Redistributions of source code must retain the above copyright notice,
18 this list of conditions and the following disclaimer.
19
20 * Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the following disclaimer in the
22 documentation and/or other materials provided with the distribution.
23
24 * Neither the name of the University of Cambridge nor the names of its
25 contributors may be used to endorse or promote products derived from
26 this software without specific prior written permission.
27
28THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38POSSIBILITY OF SUCH DAMAGE.
39-----------------------------------------------------------------------------
40*/
41
42
43/* This module contains the external function pcre_fullinfo(), which returns
44information about a compiled pattern. */
45
46
47db1125
NM
47#ifdef HAVE_CONFIG_H
48#include "config.h"
49#endif
50
8ac170f3
PH
51#include "pcre_internal.h"
52
53
54/*************************************************
55* Return info about compiled pattern *
56*************************************************/
57
58/* This is a newer "info" function which has an extensible interface so
59that additional items can be added compatibly.
60
61Arguments:
62 argument_re points to compiled code
63 extra_data points extra data, or NULL
64 what what information is required
65 where where to put the information
66
67Returns: 0 if data returned, negative on error
68*/
69
64f2600a 70PCRE_EXP_DEFN int
8ac170f3
PH
71pcre_fullinfo(const pcre *argument_re, const pcre_extra *extra_data, int what,
72 void *where)
73{
74real_pcre internal_re;
75pcre_study_data internal_study;
76const real_pcre *re = (const real_pcre *)argument_re;
77const pcre_study_data *study = NULL;
78
79if (re == NULL || where == NULL) return PCRE_ERROR_NULL;
80
81if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_STUDY_DATA) != 0)
82 study = (const pcre_study_data *)extra_data->study_data;
83
84if (re->magic_number != MAGIC_NUMBER)
85 {
86 re = _pcre_try_flipped(re, &internal_re, study, &internal_study);
87 if (re == NULL) return PCRE_ERROR_BADMAGIC;
88 if (study != NULL) study = &internal_study;
89 }
90
91switch (what)
92 {
93 case PCRE_INFO_OPTIONS:
94 *((unsigned long int *)where) = re->options & PUBLIC_OPTIONS;
95 break;
96
97 case PCRE_INFO_SIZE:
98 *((size_t *)where) = re->size;
99 break;
100
101 case PCRE_INFO_STUDYSIZE:
102 *((size_t *)where) = (study == NULL)? 0 : study->size;
103 break;
104
105 case PCRE_INFO_CAPTURECOUNT:
106 *((int *)where) = re->top_bracket;
107 break;
108
109 case PCRE_INFO_BACKREFMAX:
110 *((int *)where) = re->top_backref;
111 break;
112
113 case PCRE_INFO_FIRSTBYTE:
114 *((int *)where) =
47db1125
NM
115 ((re->flags & PCRE_FIRSTSET) != 0)? re->first_byte :
116 ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2;
8ac170f3
PH
117 break;
118
119 /* Make sure we pass back the pointer to the bit vector in the external
120 block, not the internal copy (with flipped integer fields). */
121
122 case PCRE_INFO_FIRSTTABLE:
123 *((const uschar **)where) =
124 (study != NULL && (study->options & PCRE_STUDY_MAPPED) != 0)?
125 ((const pcre_study_data *)extra_data->study_data)->start_bits : NULL;
126 break;
127
128 case PCRE_INFO_LASTLITERAL:
129 *((int *)where) =
47db1125 130 ((re->flags & PCRE_REQCHSET) != 0)? re->req_byte : -1;
8ac170f3
PH
131 break;
132
133 case PCRE_INFO_NAMEENTRYSIZE:
134 *((int *)where) = re->name_entry_size;
135 break;
136
137 case PCRE_INFO_NAMECOUNT:
138 *((int *)where) = re->name_count;
139 break;
140
141 case PCRE_INFO_NAMETABLE:
142 *((const uschar **)where) = (const uschar *)re + re->name_table_offset;
143 break;
144
145 case PCRE_INFO_DEFAULT_TABLES:
146 *((const uschar **)where) = (const uschar *)(_pcre_default_tables);
147 break;
148
64f2600a 149 case PCRE_INFO_OKPARTIAL:
47db1125 150 *((int *)where) = (re->flags & PCRE_NOPARTIAL) == 0;
64f2600a
PH
151 break;
152
153 case PCRE_INFO_JCHANGED:
47db1125
NM
154 *((int *)where) = (re->flags & PCRE_JCHANGED) != 0;
155 break;
156
157 case PCRE_INFO_HASCRORLF:
158 *((int *)where) = (re->flags & PCRE_HASCRORLF) != 0;
64f2600a
PH
159 break;
160
8ac170f3
PH
161 default: return PCRE_ERROR_BADOPTION;
162 }
163
164return 0;
165}
166
167/* End of pcre_fullinfo.c */