Commit 25beb0c3 authored by Geoff Simmons's avatar Geoff Simmons

Move some of the code out into a separate source and header.

This mostly moves out functions that are not on the fast path and
we don't try to inline. Also just clears up a lot of clutter.
parent a403707a
Pipeline #261 skipped
......@@ -6,7 +6,9 @@ vmod_LTLIBRARIES = libvmod_pcre2.la
libvmod_pcre2_la_LDFLAGS = -module -export-dynamic -avoid-version -shared
libvmod_pcre2_la_SOURCES = \
vmod_pcre2.c
vmod_pcre2.h \
vmod_pcre2.c \
pcre2.c
nodist_libvmod_pcre2_la_SOURCES = \
vcc_if.c \
......@@ -14,7 +16,9 @@ nodist_libvmod_pcre2_la_SOURCES = \
libvmod_pcre2_la_LIBADD = @PCRE2_LIBS@
vmod_pcre2.lo: vcc_if.c vcc_if.h
vmod_pcre2.lo: vcc_if.c vcc_if.h vmod_pcre2.h
pcre2.lo: vmod_pcre2.h
vcc_if.c: vcc_if.h
......
This diff is collapsed.
This diff is collapsed.
/*-
* Copyright 2017 UPLEX - Nils Goroll Systemoptimierung
* All rights reserved.
*
* Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include "vcl.h"
#include "cache/cache.h"
#include "vrt.h"
#include "vas.h"
#include "vdef.h"
#define PCRE2_CODE_UNIT_WIDTH 8
#include "pcre2.h"
#define ERR(ctx, msg) \
errmsg((ctx), "vmod pcre2 error: " msg)
#define VERR(ctx, fmt, ...) \
errmsg((ctx), "vmod pcre2 error: " fmt, __VA_ARGS__)
#define VERRNOMEM(ctx, fmt, ...) \
VERR((ctx), fmt ", out of space", __VA_ARGS__)
#define ERRNOMEM(ctx, msg) \
ERR((ctx), msg ", out of space")
#define COMPILE_OPTS \
VCL_BOOL allow_empty_class, VCL_BOOL anchored, VCL_ENUM bsrs, \
VCL_BOOL alt_bsux, VCL_BOOL alt_circumflex, \
VCL_BOOL alt_verbnames, VCL_BOOL caseless, \
VCL_BOOL dollar_endonly, VCL_BOOL dotall, \
VCL_BOOL dupnames, VCL_BOOL extended, VCL_BOOL firstline, \
VCL_STRING locale, VCL_BOOL match_unset_backref, \
VCL_INT max_pattern_length, VCL_BOOL multiline, \
VCL_BOOL never_backslash_c, VCL_BOOL never_ucp, \
VCL_BOOL never_utf, VCL_ENUM newlines, \
VCL_BOOL no_auto_capture, VCL_BOOL no_auto_possess, \
VCL_BOOL no_dotstar_anchor, VCL_BOOL no_start_optimize, \
VCL_BOOL no_utf_check, VCL_INT parens_nest_limit, \
VCL_BOOL ucp, VCL_BOOL ungreedy, \
VCL_BOOL use_offset_limit, VCL_BOOL utf
#define COMPILE_CTX_OPTS \
VCL_ENUM bsrs, VCL_STRING locale, VCL_INT max_pattern_length, \
VCL_ENUM newlines, VCL_INT parens_nest_limit
#define COMPILE_CTX_PARAMS \
bsrs, locale, max_pattern_length, newlines, parens_nest_limit
#define COMPILE_FLAGS \
VCL_BOOL allow_empty_class, VCL_BOOL anchored, VCL_BOOL alt_bsux, \
VCL_BOOL alt_circumflex, VCL_BOOL alt_verbnames, \
VCL_BOOL caseless, VCL_BOOL dollar_endonly, \
VCL_BOOL dotall, VCL_BOOL dupnames, VCL_BOOL extended, \
VCL_BOOL firstline, VCL_BOOL match_unset_backref, \
VCL_BOOL multiline, VCL_BOOL never_backslash_c, \
VCL_BOOL never_ucp, VCL_BOOL never_utf, \
VCL_BOOL no_auto_capture, VCL_BOOL no_auto_possess, \
VCL_BOOL no_dotstar_anchor, VCL_BOOL no_start_optimize, \
VCL_BOOL no_utf_check, VCL_BOOL ucp, VCL_BOOL ungreedy, \
VCL_BOOL use_offset_limit, VCL_BOOL utf
#define COMPILE_FLAGS_PARAMS \
allow_empty_class, anchored, alt_bsux, alt_circumflex, \
alt_verbnames, caseless, dollar_endonly, dotall, \
dupnames, extended, firstline, match_unset_backref, \
multiline, never_backslash_c, never_ucp, never_utf, \
no_auto_capture, no_auto_possess, no_dotstar_anchor, \
no_start_optimize, no_utf_check, ucp, ungreedy, \
use_offset_limit, utf
#define MATCH_OPTS \
VCL_INT len, VCL_BOOL anchored, VCL_INT match_limit, \
VCL_INT offset_limit, VCL_BOOL notbol, VCL_BOOL noteol, \
VCL_BOOL notempty, VCL_BOOL notempty_atstart, \
VCL_BOOL no_jit, VCL_BOOL no_utf_check, \
VCL_INT recursion_limit
/* Doesn't repeat the anchored and no_utf_check options */
#define MATCHF_OPTS \
VCL_INT len, VCL_INT match_limit, VCL_INT offset_limit, \
VCL_BOOL notbol, VCL_BOOL noteol, VCL_BOOL notempty, \
VCL_BOOL notempty_atstart, VCL_BOOL no_jit, \
VCL_INT recursion_limit
#define MATCH_CTX_OPTS \
VCL_INT match_limit, VCL_INT offset_limit, VCL_INT recursion_limit
#define MATCH_CTX_PARAMS \
match_limit, offset_limit, recursion_limit
#define MATCH_FLAGS \
VCL_BOOL anchored, VCL_BOOL notbol, VCL_BOOL noteol, \
VCL_BOOL notempty, VCL_BOOL notempty_atstart, \
VCL_BOOL no_jit, VCL_BOOL no_utf_check
#define MATCH_SUB_FLAGS_PARAMS \
anchored, notbol, noteol, notempty, notempty_atstart, no_jit, \
no_utf_check, suball, sub_extended, unknown_unset, \
unset_empty
#define MATCH_FLAGS_PARAMS \
anchored, notbol, noteol, notempty, notempty_atstart, no_jit, \
no_utf_check, 0, 0, 0, 0
#define SUB_OPTS \
VCL_BOOL suball, VCL_BOOL sub_extended, VCL_BOOL unknown_unset, \
VCL_BOOL unset_empty
/*
* PRIV_CALL scope. The match context and options are used by the match
* method and function. The compile context and options are used by the
* match function.
*/
struct match_call {
unsigned magic;
#define VMOD_PCRE2_MATCH_CALL_MAGIC 0x60e5bd33
pcre2_match_context *mctx;
pcre2_compile_context *cctx;
uint32_t match_options;
uint32_t compile_options;
};
void errmsg(VRT_CTX, const char *fmt, ...);
void report_pcre2_err(VRT_CTX, int errcode, const char * const restrict msg,
const char * const restrict post);
pcre2_compile_context *get_compile_opts(VRT_CTX, COMPILE_CTX_OPTS,
COMPILE_FLAGS, uint32_t *options,
const char * restrict const context,
const char * restrict const caller);
struct match_call *get_match_opts(VRT_CTX, struct vmod_priv *priv,
MATCH_CTX_OPTS, MATCH_FLAGS, SUB_OPTS,
const char *context, const char *caller);
pcre2_code *compile(VRT_CTX, pcre2_compile_context * restrict const cctx,
VCL_STRING const restrict pattern, uint32_t options,
int do_jit, const char * const restrict context,
const char * const restrict caller);
static inline int
check_uint32_range(VRT_CTX, long long limit, const char * const restrict name,
const char * const restrict context,
const char * const restrict caller)
{
if (limit < 0 || limit > UINT32_MAX) {
VERR(ctx, "%s (%lld) out of range in %s%s (must be >= 0 and "
"<= %" PRIu32 ")", name, limit, context, caller,
UINT32_MAX);
return 0;
}
return 1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment