mux/src/pcre.cpp File Reference

#include "autoconf.h"
#include "config.h"
#include <limits.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <stddef.h>
#include "pcre.h"
#include "externs.h"
#include "timeutil.h"

Include dependency graph for pcre.cpp:

Go to the source code of this file.

Data Structures

struct  real_pcre
struct  pcre_study_data
struct  compile_data
struct  branch_chain
struct  recursion_info
struct  match_data
struct  eptrblock

Defines

#define LINK_SIZE   2
#define MATCH_LIMIT   100000
#define NEWLINE   '\n'
#define PUT(a, n, d)
#define GET(a, n)   (((a)[n] << 8) | (a)[(n)+1])
#define MAX_PATTERN_SIZE   (1 << 16)
#define PUTINC(a, n, d)   PUT(a,n,d), a += LINK_SIZE
#define PUT2(a, n, d)
#define GET2(a, n)   (((a)[n] << 8) | (a)[(n)+1])
#define PUT2INC(a, n, d)   PUT2(a,n,d), a += 2
#define PCRE_IMS   (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL)
#define PCRE_FIRSTSET   0x40000000
#define PCRE_REQCHSET   0x20000000
#define PCRE_STARTLINE   0x10000000
#define PCRE_ICHANGED   0x08000000
#define PCRE_STUDY_MAPPED   0x01
#define PUBLIC_OPTIONS
#define PUBLIC_EXEC_OPTIONS   (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK)
#define PUBLIC_STUDY_OPTIONS   0
#define MAGIC_NUMBER   0x50435245UL
#define REQ_UNSET   (-2)
#define REQ_NONE   (-1)
#define REQ_CASELESS   0x0100
#define REQ_VARY   0x0200
#define ESC_e   27
#define ESC_f   '\f'
#define ESC_n   NEWLINE
#define ESC_r   '\r'
#define ESC_tee   '\t'
#define XCL_NOT   0x01
#define XCL_MAP   0x02
#define XCL_END   0
#define XCL_SINGLE   1
#define XCL_RANGE   2
#define OP_NAME_LIST
#define OP_LENGTHS
#define EXTRACT_BASIC_MAX   150
#define CREF_RECURSE   0xffff
#define ERR1   "\\ at end of pattern"
#define ERR2   "\\c at end of pattern"
#define ERR3   "unrecognized character follows \\"
#define ERR4   "numbers out of order in {} quantifier"
#define ERR5   "number too big in {} quantifier"
#define ERR6   "missing terminating ] for character class"
#define ERR7   "invalid escape sequence in character class"
#define ERR8   "range out of order in character class"
#define ERR9   "nothing to repeat"
#define ERR10   "operand of unlimited repeat could match the empty string"
#define ERR11   "internal error: unexpected repeat"
#define ERR12   "unrecognized character after (?"
#define ERR13   "POSIX named classes are supported only within a class"
#define ERR14   "missing )"
#define ERR15   "reference to non-existent subpattern"
#define ERR16   "erroffset passed as NULL"
#define ERR17   "unknown option bit(s) set"
#define ERR18   "missing ) after comment"
#define ERR19   "parentheses nested too deeply"
#define ERR20   "regular expression too large"
#define ERR21   "failed to get memory"
#define ERR22   "unmatched parentheses"
#define ERR23   "internal error: code overflow"
#define ERR24   "unrecognized character after (?<"
#define ERR25   "lookbehind assertion is not fixed length"
#define ERR26   "malformed number after (?("
#define ERR27   "conditional group contains more than two branches"
#define ERR28   "assertion expected after (?("
#define ERR29   "(?R or (?digits must be followed by )"
#define ERR30   "unknown POSIX class name"
#define ERR31   "POSIX collating elements are not supported"
#define ERR32   "this version of PCRE is not compiled with PCRE_UTF8 support"
#define ERR33   "spare error"
#define ERR34   "character value in \\x{...} sequence is too large"
#define ERR35   "invalid condition (?(0)"
#define ERR36   "\\C not allowed in lookbehind assertion"
#define ERR37   "PCRE does not support \\L, \\l, \\N, \\P, \\p, \\U, \\u, or \\X"
#define ERR38   "number after (?C is > 255"
#define ERR39   "closing ) for (?C expected"
#define ERR40   "recursive call could loop indefinitely"
#define ERR41   "unrecognized character after (?P"
#define ERR42   "syntax error after (?P"
#define ERR43   "two named groups have the same name"
#define ERR44   "invalid UTF-8 string"
#define ctype_space   0x01
#define ctype_letter   0x02
#define ctype_digit   0x04
#define ctype_xdigit   0x08
#define ctype_word   0x10
#define ctype_meta   0x80
#define cbit_space   0
#define cbit_xdigit   32
#define cbit_digit   64
#define cbit_upper   96
#define cbit_lower   128
#define cbit_word   160
#define cbit_graph   192
#define cbit_print   224
#define cbit_punct   256
#define cbit_cntrl   288
#define cbit_length   320
#define lcc_offset   0
#define fcc_offset   256
#define cbits_offset   512
#define ctypes_offset   (cbits_offset + cbit_length)
#define tables_length   (ctypes_offset + 256)
#define DPRINTF(p)
#define BRASTACK_SIZE   200
#define REC_STACK_SAVE_MAX   30
#define MAXLIT   250
#define REQ_BYTE_MAX   1000
#define match_condassert   0x01
#define match_isgroup   0x02
#define MATCH_MATCH   1
#define MATCH_NOMATCH   0
#define GETCHAR(c, eptr)   c = *eptr;
#define GETCHARINC(c, eptr)   c = *eptr++;
#define GETCHARINCTEST(c, eptr)   c = *eptr++;
#define GETCHARLEN(c, eptr, len)   c = *eptr;
#define BACKCHAR(eptr)
#define REGISTER   register
#define RMATCH(rx, ra, rb, rc, rd, re, rf, rg)   rx = match(ra,rb,rc,rd,re,rf,rg)
#define RRETURN(ra)   return ra
#define fi   i
#define fc   c

Typedefs

typedef unsigned char uschar

Enumerations

enum  {
  ESC_A = 1, ESC_G, ESC_B, ESC_b,
  ESC_D, ESC_d, ESC_S, ESC_s,
  ESC_W, ESC_w, ESC_dum1, ESC_C,
  ESC_Z, ESC_z, ESC_E, ESC_Q,
  ESC_REF
}
enum  {
  OP_END, OP_SOD, OP_SOM, OP_NOT_WORD_BOUNDARY,
  OP_WORD_BOUNDARY, OP_NOT_DIGIT, OP_DIGIT, OP_NOT_WHITESPACE,
  OP_WHITESPACE, OP_NOT_WORDCHAR, OP_WORDCHAR, OP_ANY,
  OP_ANYBYTE, OP_EODN, OP_EOD, OP_OPT,
  OP_CIRC, OP_DOLL, OP_CHARS, OP_NOT,
  OP_STAR, OP_MINSTAR, OP_PLUS, OP_MINPLUS,
  OP_QUERY, OP_MINQUERY, OP_UPTO, OP_MINUPTO,
  OP_EXACT, OP_NOTSTAR, OP_NOTMINSTAR, OP_NOTPLUS,
  OP_NOTMINPLUS, OP_NOTQUERY, OP_NOTMINQUERY, OP_NOTUPTO,
  OP_NOTMINUPTO, OP_NOTEXACT, OP_TYPESTAR, OP_TYPEMINSTAR,
  OP_TYPEPLUS, OP_TYPEMINPLUS, OP_TYPEQUERY, OP_TYPEMINQUERY,
  OP_TYPEUPTO, OP_TYPEMINUPTO, OP_TYPEEXACT, OP_CRSTAR,
  OP_CRMINSTAR, OP_CRPLUS, OP_CRMINPLUS, OP_CRQUERY,
  OP_CRMINQUERY, OP_CRRANGE, OP_CRMINRANGE, OP_CLASS,
  OP_NCLASS, OP_XCLASS, OP_REF, OP_RECURSE,
  OP_CALLOUT, OP_ALT, OP_KET, OP_KETRMAX,
  OP_KETRMIN, OP_ASSERT, OP_ASSERT_NOT, OP_ASSERTBACK,
  OP_ASSERTBACK_NOT, OP_REVERSE, OP_ONCE, OP_COND,
  OP_CREF, OP_BRAZERO, OP_BRAMINZERO, OP_BRANUMBER,
  OP_BRA
}

Functions

int pcre_copy_substring (const char *subject, int *ovector, int stringcount, int stringnumber, char *buffer, int size)
const unsigned char * pcre_maketables (void)
static void set_bit (uschar *start_bits, int c, bool caseless, compile_data *cd)
static bool set_start_bits (const uschar *code, uschar *start_bits, bool caseless, bool utf8, compile_data *cd)
pcre_extrapcre_study (const pcre *external_re, int options, const char **errorptr)
static bool compile_regex (int, int, int *, uschar **, const uschar **, const char **, bool, int, int *, int *, branch_chain *, compile_data *)
static int check_escape (const uschar **ptrptr, const char **errorptr, int bracount, int options, bool isclass)
static bool is_counted_repeat (const uschar *p)
static const uscharread_repeat_counts (const uschar *p, int *minp, int *maxp, const char **errorptr)
static const uscharfirst_significant_code (const uschar *code, int *options, int optbit)
static int find_fixedlength (uschar *code, int options)
static const uscharfind_bracket (const uschar *code, int number)
static const uscharfind_recurse (const uschar *code, bool utf8)
static bool could_be_empty_branch (const uschar *code, const uschar *endcode, bool utf8)
static bool could_be_empty (const uschar *code, const uschar *endcode, branch_chain *bcptr, bool utf8)
static bool check_posix_syntax (const uschar *ptr, const uschar **endptr, compile_data *cd)
static int check_posix_name (const uschar *ptr, int len)
static void adjust_recurse (uschar *group, int adjust, bool utf8, compile_data *cd)
static bool compile_branch (int *optionsptr, int *brackets, uschar **codeptr, const uschar **ptrptr, const char **errorptr, int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr, compile_data *cd)
static bool is_anchored (register const uschar *code, int *options, unsigned int bracket_map, unsigned int backref_map)
static bool is_startline (const uschar *code, unsigned int bracket_map, unsigned int backref_map)
static int find_firstassertedchar (const uschar *code, int *options, bool inassert)
pcrepcre_compile (const char *pattern, int options, const char **errorptr, int *erroroffset, const unsigned char *tables)
static bool match_ref (int offset, register const uschar *eptr, int length, match_data *md, unsigned long int ims)
static int match (REGISTER const uschar *eptr, REGISTER const uschar *ecode, int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, int flags)
int pcre_exec (const pcre *external_re, const pcre_extra *extra_data, const char *subject, int length, int start_offset, int options, int *offsets, int offsetcount)

Variables

static unsigned char pcre_default_tables []
static const uschar OP_lengths [] = { OP_LENGTHS }
static const char rep_min [] = { 0, 0, 1, 1, 0, 0 }
static const char rep_max [] = { 0, 0, 0, 0, 1, 1 }
static const short int escapes []
static const char *const posix_names []
static const uschar posix_name_lengths []
static const int posix_class_maps []
static const unsigned char digitab []
int(*) pcre_callout (pcre_callout_block *) = NULL


Define Documentation

#define BACKCHAR ( eptr   ) 

Definition at line 1500 of file pcre.cpp.

#define BRASTACK_SIZE   200

Definition at line 1314 of file pcre.cpp.

Referenced by pcre_compile().

#define cbit_cntrl   288

Definition at line 585 of file pcre.cpp.

Referenced by pcre_maketables().

#define cbit_digit   64

Definition at line 578 of file pcre.cpp.

Referenced by compile_branch(), pcre_maketables(), and set_start_bits().

#define cbit_graph   192

Definition at line 582 of file pcre.cpp.

Referenced by pcre_maketables().

#define cbit_length   320

Definition at line 586 of file pcre.cpp.

Referenced by pcre_maketables().

#define cbit_lower   128

Definition at line 580 of file pcre.cpp.

Referenced by pcre_maketables().

#define cbit_print   224

Definition at line 583 of file pcre.cpp.

Referenced by pcre_maketables().

#define cbit_punct   256

Definition at line 584 of file pcre.cpp.

Referenced by pcre_maketables().

#define cbit_space   0

Definition at line 576 of file pcre.cpp.

Referenced by compile_branch(), pcre_maketables(), and set_start_bits().

#define cbit_upper   96

Definition at line 579 of file pcre.cpp.

Referenced by pcre_maketables().

#define cbit_word   160

Definition at line 581 of file pcre.cpp.

Referenced by compile_branch(), pcre_maketables(), and set_start_bits().

#define cbit_xdigit   32

Definition at line 577 of file pcre.cpp.

Referenced by pcre_maketables().

#define cbits_offset   512

Definition at line 593 of file pcre.cpp.

Referenced by pcre_compile(), and pcre_study().

#define CREF_RECURSE   0xffff

Definition at line 405 of file pcre.cpp.

Referenced by compile_branch(), and match().

#define ctype_digit   0x04

Definition at line 568 of file pcre.cpp.

Referenced by check_escape(), compile_branch(), is_counted_repeat(), match(), pcre_compile(), pcre_maketables(), and read_repeat_counts().

#define ctype_letter   0x02

Definition at line 567 of file pcre.cpp.

Referenced by check_posix_syntax(), pcre_maketables(), and set_bit().

#define ctype_meta   0x80

Definition at line 571 of file pcre.cpp.

Referenced by compile_branch(), pcre_compile(), and pcre_maketables().

#define ctype_space   0x01

Definition at line 566 of file pcre.cpp.

Referenced by compile_branch(), match(), pcre_compile(), and pcre_maketables().

#define ctype_word   0x10

Definition at line 570 of file pcre.cpp.

Referenced by match(), pcre_compile(), and pcre_maketables().

#define ctype_xdigit   0x08

Definition at line 569 of file pcre.cpp.

Referenced by check_escape(), and pcre_maketables().

#define ctypes_offset   (cbits_offset + cbit_length)

Definition at line 594 of file pcre.cpp.

Referenced by pcre_compile(), pcre_exec(), and pcre_study().

#define DPRINTF (  ) 

Definition at line 1306 of file pcre.cpp.

Referenced by compile_regex(), match(), pcre_compile(), and pcre_exec().

#define ERR1   "\\ at end of pattern"

Definition at line 412 of file pcre.cpp.

Referenced by check_escape().

#define ERR10   "operand of unlimited repeat could match the empty string"

Definition at line 421 of file pcre.cpp.

#define ERR11   "internal error: unexpected repeat"

Definition at line 422 of file pcre.cpp.

Referenced by compile_branch().

#define ERR12   "unrecognized character after (?"

Definition at line 423 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR13   "POSIX named classes are supported only within a class"

Definition at line 424 of file pcre.cpp.

Referenced by compile_branch().

#define ERR14   "missing )"

Definition at line 425 of file pcre.cpp.

Referenced by compile_branch().

#define ERR15   "reference to non-existent subpattern"

Definition at line 426 of file pcre.cpp.

Referenced by compile_branch(), and pcre_compile().

#define ERR16   "erroffset passed as NULL"

Definition at line 427 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR17   "unknown option bit(s) set"

Definition at line 428 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR18   "missing ) after comment"

Definition at line 429 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR19   "parentheses nested too deeply"

Definition at line 430 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR2   "\\c at end of pattern"

Definition at line 413 of file pcre.cpp.

Referenced by check_escape().

#define ERR20   "regular expression too large"

Definition at line 431 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR21   "failed to get memory"

Definition at line 432 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR22   "unmatched parentheses"

Definition at line 433 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR23   "internal error: code overflow"

Definition at line 434 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR24   "unrecognized character after (?<"

Definition at line 435 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR25   "lookbehind assertion is not fixed length"

Definition at line 436 of file pcre.cpp.

Referenced by compile_regex().

#define ERR26   "malformed number after (?("

Definition at line 437 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR27   "conditional group contains more than two branches"

Definition at line 438 of file pcre.cpp.

Referenced by compile_branch().

#define ERR28   "assertion expected after (?("

Definition at line 439 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR29   "(?R or (?digits must be followed by )"

Definition at line 440 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR3   "unrecognized character follows \\"

Definition at line 414 of file pcre.cpp.

Referenced by check_escape().

#define ERR30   "unknown POSIX class name"

Definition at line 441 of file pcre.cpp.

Referenced by compile_branch().

#define ERR31   "POSIX collating elements are not supported"

Definition at line 442 of file pcre.cpp.

Referenced by compile_branch().

#define ERR32   "this version of PCRE is not compiled with PCRE_UTF8 support"

Definition at line 443 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR33   "spare error"

Definition at line 444 of file pcre.cpp.

#define ERR34   "character value in \\x{...} sequence is too large"

Definition at line 445 of file pcre.cpp.

#define ERR35   "invalid condition (?(0)"

Definition at line 446 of file pcre.cpp.

Referenced by compile_branch().

#define ERR36   "\\C not allowed in lookbehind assertion"

Definition at line 447 of file pcre.cpp.

Referenced by compile_regex().

#define ERR37   "PCRE does not support \\L, \\l, \\N, \\P, \\p, \\U, \\u, or \\X"

Definition at line 448 of file pcre.cpp.

Referenced by check_escape().

#define ERR38   "number after (?C is > 255"

Definition at line 449 of file pcre.cpp.

Referenced by compile_branch().

#define ERR39   "closing ) for (?C expected"

Definition at line 450 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR4   "numbers out of order in {} quantifier"

Definition at line 415 of file pcre.cpp.

Referenced by read_repeat_counts().

#define ERR40   "recursive call could loop indefinitely"

Definition at line 451 of file pcre.cpp.

Referenced by compile_branch().

#define ERR41   "unrecognized character after (?P"

Definition at line 452 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR42   "syntax error after (?P"

Definition at line 453 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR43   "two named groups have the same name"

Definition at line 454 of file pcre.cpp.

Referenced by compile_branch().

#define ERR44   "invalid UTF-8 string"

Definition at line 455 of file pcre.cpp.

#define ERR5   "number too big in {} quantifier"

Definition at line 416 of file pcre.cpp.

Referenced by read_repeat_counts().

#define ERR6   "missing terminating ] for character class"

Definition at line 417 of file pcre.cpp.

Referenced by pcre_compile().

#define ERR7   "invalid escape sequence in character class"

Definition at line 418 of file pcre.cpp.

Referenced by compile_branch().

#define ERR8   "range out of order in character class"

Definition at line 419 of file pcre.cpp.

Referenced by compile_branch().

#define ERR9   "nothing to repeat"

Definition at line 420 of file pcre.cpp.

Referenced by compile_branch().

#define ESC_e   27

Definition at line 160 of file pcre.cpp.

#define ESC_f   '\f'

Definition at line 164 of file pcre.cpp.

#define ESC_n   NEWLINE

Definition at line 168 of file pcre.cpp.

#define ESC_r   '\r'

Definition at line 172 of file pcre.cpp.

#define ESC_tee   '\t'

Definition at line 179 of file pcre.cpp.

#define EXTRACT_BASIC_MAX   150

Definition at line 401 of file pcre.cpp.

Referenced by compile_branch(), find_bracket(), is_anchored(), is_startline(), match(), and pcre_compile().

#define fc   c

Referenced by do_mail_stats(), and match().

#define fcc_offset   256

Definition at line 592 of file pcre.cpp.

Referenced by pcre_compile(), pcre_exec(), and pcre_study().

#define fi   i

Referenced by match().

#define GET ( a,
 )     (((a)[n] << 8) | (a)[(n)+1])

Definition at line 82 of file pcre.cpp.

Referenced by adjust_recurse(), compile_branch(), compile_regex(), could_be_empty_branch(), find_firstassertedchar(), find_fixedlength(), first_significant_code(), is_anchored(), is_startline(), match(), and set_start_bits().

#define GET2 ( a,
 )     (((a)[n] << 8) | (a)[(n)+1])

Definition at line 101 of file pcre.cpp.

Referenced by compile_branch(), could_be_empty_branch(), find_bracket(), find_fixedlength(), is_anchored(), is_startline(), and match().

#define GETCHAR ( c,
eptr   )     c = *eptr;

Definition at line 1496 of file pcre.cpp.

#define GETCHARINC ( c,
eptr   )     c = *eptr++;

Definition at line 1497 of file pcre.cpp.

#define GETCHARINCTEST ( c,
eptr   )     c = *eptr++;

Definition at line 1498 of file pcre.cpp.

Referenced by match().

#define GETCHARLEN ( c,
eptr,
len   )     c = *eptr;

Definition at line 1499 of file pcre.cpp.

#define lcc_offset   0

Definition at line 591 of file pcre.cpp.

Referenced by pcre_compile(), pcre_exec(), and pcre_study().

#define LINK_SIZE   2

Definition at line 57 of file pcre.cpp.

Referenced by adjust_recurse(), compile_branch(), compile_regex(), could_be_empty_branch(), find_bracket(), find_firstassertedchar(), find_fixedlength(), is_anchored(), is_startline(), match(), pcre_compile(), and set_start_bits().

#define MAGIC_NUMBER   0x50435245UL

Definition at line 140 of file pcre.cpp.

Referenced by pcre_compile(), pcre_exec(), and pcre_study().

#define match_condassert   0x01

Definition at line 1468 of file pcre.cpp.

Referenced by match().

#define match_isgroup   0x02

Definition at line 1469 of file pcre.cpp.

Referenced by match(), and pcre_exec().

#define MATCH_LIMIT   100000

Definition at line 58 of file pcre.cpp.

Referenced by pcre_exec().

#define MATCH_MATCH   1

Definition at line 1474 of file pcre.cpp.

Referenced by match(), and pcre_exec().

#define MATCH_NOMATCH   0

Definition at line 1475 of file pcre.cpp.

Referenced by match(), and pcre_exec().

#define MAX_PATTERN_SIZE   (1 << 16)

Definition at line 85 of file pcre.cpp.

Referenced by pcre_compile().

#define MAXLIT   250

Definition at line 1329 of file pcre.cpp.

Referenced by compile_branch(), and pcre_compile().

#define NEWLINE   '\n'

Definition at line 59 of file pcre.cpp.

Referenced by compile_branch(), match(), pcre_compile(), and pcre_exec().

#define OP_LENGTHS

Definition at line 353 of file pcre.cpp.

#define OP_NAME_LIST

Value:

"End", "\\A", "\\G", "\\B", "\\b", "\\D", "\\d",                \
  "\\S", "\\s", "\\W", "\\w", "Any", "Anybyte", "\\Z", "\\z",     \
  "Opt", "^", "$", "chars", "not",                                \
  "*", "*?"</