Commit b1f80c92 authored by Geoff Simmons's avatar Geoff Simmons

Add the info_int() method.

parent b377c7b9
......@@ -94,6 +94,15 @@ regex.sub
STRING regex.sub(PRIV_CALL, PRIV_TASK, STRING subject, STRING replacement, INT len=0, BOOL anchored=0, INT match_limit=0, INT offset_limit=0, BOOL notbol=0, BOOL noteol=0, BOOL notempty=0, BOOL notempty_atstart=0, BOOL no_jit=0, BOOL no_utf_check=0, INT recursion_limit=0, BOOL suball=0, BOOL sub_extended=0, BOOL unknown_unset=0, BOOL unset_empty=0)
.. _func_regex.info_int:
regex.info_int
--------------
::
INT regex.info_int(ENUM {BACKREFMAX,CAPTURECOUNT,JITSIZE,MATCHLIMIT,MAXLOOKBEHIND,MINLENGTH,RECURSIONLIMIT,SIZE})
.. _func_match:
match
......
......@@ -8,7 +8,8 @@ libvmod_pcre2_la_LDFLAGS = -module -export-dynamic -avoid-version -shared
libvmod_pcre2_la_SOURCES = \
vmod_pcre2.h \
vmod_pcre2.c \
pcre2.c
pcre2.c \
info.c
nodist_libvmod_pcre2_la_SOURCES = \
vcc_if.c \
......@@ -20,6 +21,8 @@ vmod_pcre2.lo: vcc_if.c vcc_if.h vmod_pcre2.h
pcre2.lo: vmod_pcre2.h
info.lo: vcc_if.h vmod_pcre2.h
vcc_if.c: vcc_if.h
vcc_if.h vmod_pcre2.man.rst: @VMODTOOL@ $(top_srcdir)/src/vmod_pcre2.vcc
......
/*-
* 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 "vmod_pcre2.h"
#include "vcc_if.h"
VCL_INT
vmod_regex_info_int(VRT_CTX, struct vmod_pcre2_regex *regex, VCL_ENUM ints)
{
uint32_t what, where;
size_t sz;
int ret;
(void) ctx;
CHECK_OBJ_NOTNULL(regex, VMOD_PCRE2_REGEX_MAGIC);
if (strcmp(ints, "BACKREFMAX") == 0)
what = PCRE2_INFO_BACKREFMAX;
else if (strcmp(ints, "CAPTURECOUNT") == 0)
what = PCRE2_INFO_CAPTURECOUNT;
else if (strcmp(ints, "JITSIZE") == 0)
what = PCRE2_INFO_JITSIZE;
else if (strcmp(ints, "MATCHLIMIT") == 0)
what = PCRE2_INFO_MATCHLIMIT;
else if (strcmp(ints, "MAXLOOKBEHIND") == 0)
what = PCRE2_INFO_MAXLOOKBEHIND;
else if (strcmp(ints, "MINLENGTH") == 0)
what = PCRE2_INFO_MINLENGTH;
else if (strcmp(ints, "RECURSIONLIMIT") == 0)
what = PCRE2_INFO_RECURSIONLIMIT;
else if (strcmp(ints, "SIZE") == 0)
what = PCRE2_INFO_SIZE;
else
WRONG("illegal enum in info_int");
if (what == PCRE2_INFO_JITSIZE || what == PCRE2_INFO_SIZE) {
ret = pcre2_pattern_info(regex->code, what, &sz);
AZ(ret);
return sz;
}
ret = pcre2_pattern_info(regex->code, what, &where);
if (ret == PCRE2_ERROR_UNSET) {
assert(what == PCRE2_INFO_MATCHLIMIT
|| what == PCRE2_INFO_RECURSIONLIMIT);
return -1;
}
AZ(ret);
return where;
}
# looks like -*- vcl -*-
varnishtest "methods info_bool, _int and _str"
varnish v1 -vcl {
import pcre2 from "${vmod_topbuild}/src/.libs/libvmod_pcre2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new r1 = pcre2.regex(
"(*LIMIT_MATCH=20)(*LIMIT_RECURSION=30)(?<!bar|cattle)a(bc)\1");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.backrefmax = r1.info_int(BACKREFMAX);
set resp.http.capturecount = r1.info_int(CAPTURECOUNT);
set resp.http.jitsize = r1.info_int(JITSIZE);
set resp.http.matchlimit = r1.info_int(MATCHLIMIT);
set resp.http.maxlookbehind = r1.info_int(MAXLOOKBEHIND);
set resp.http.minlength = r1.info_int(MINLENGTH);
set resp.http.recursionlimit = r1.info_int(RECURSIONLIMIT);
set resp.http.size = r1.info_int(SIZE);
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.backrefmax == 1
expect resp.http.capturecount == 1
expect resp.http.jitsize >= 0
expect resp.http.matchlimit == 20
expect resp.http.maxlookbehind == 6
expect resp.http.minlength == 5
expect resp.http.recursionlimit == 30
expect resp.http.size > 0
} -run
......@@ -31,13 +31,6 @@
#include "vcc_if.h"
struct vmod_pcre2_regex {
unsigned magic;
#define VMOD_PCRE2_REGEX_MAGIC 0x3adb2a78
pcre2_code *code;
char *vcl_name;
};
/*
* PRIV_TASK scope. The general context is used by all methods and
* functions. The match_data is used by the match(), backref() and
......
......@@ -133,6 +133,13 @@
VCL_BOOL suball, VCL_BOOL sub_extended, VCL_BOOL unknown_unset, \
VCL_BOOL unset_empty
struct vmod_pcre2_regex {
unsigned magic;
#define VMOD_PCRE2_REGEX_MAGIC 0x3adb2a78
pcre2_code *code;
char *vcl_name;
};
/*
* 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
......
......@@ -51,6 +51,9 @@ $Method STRING .sub(PRIV_CALL, PRIV_TASK, STRING subject, STRING replacement,
BOOL sub_extended=0, BOOL unknown_unset=0,
BOOL unset_empty=0)
$Method INT .info_int(ENUM {BACKREFMAX, CAPTURECOUNT, JITSIZE, MATCHLIMIT,
MAXLOOKBEHIND, MINLENGTH, RECURSIONLIMIT, SIZE})
$Function BOOL match(PRIV_CALL, PRIV_TASK, STRING pattern, STRING subject,
BOOL allow_empty_class=0, BOOL anchored=0,
ENUM {ANYCRLF, UNICODE} bsr=0, BOOL alt_bsux=0,
......
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