From f06fcc848fa5a5b15d170bf5cc34986ed6164621 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Thu, 12 Feb 2015 16:47:56 +0200 Subject: Rename batchset to regset --- src/variable.c | 27 ++++++++++++--------------- src/variable.vcc | 2 +- tests/Makefile.am | 2 +- tests/batchset.at | 39 --------------------------------------- tests/regset.at | 39 +++++++++++++++++++++++++++++++++++++++ tests/testsuite.at | 2 +- 6 files changed, 54 insertions(+), 57 deletions(-) delete mode 100644 tests/batchset.at create mode 100644 tests/regset.at diff --git a/src/variable.c b/src/variable.c index 9442b6b..667cfc0 100644 --- a/src/variable.c +++ b/src/variable.c @@ -617,8 +617,7 @@ bref_expand(const char *str, const char *input, pcre *re, } VCL_VOID -vmod_batchset(VARIABLE_CTX ctx, - VCL_STRING vars, VCL_STRING rxs, VCL_STRING input) +vmod_regset(VARIABLE_CTX ctx, VCL_STRING vars, VCL_STRING rxs, VCL_STRING input) { struct symtab *vt = get_symtab(ctx); struct vardef *head = NULL, *tail = NULL, *def; @@ -638,7 +637,7 @@ vmod_batchset(VARIABLE_CTX ctx, pcre *re; if (!vars || !rxs || !input) { - log_error("variable.batchset: bad arguments: vars=%s, rxs=%s, input=%s", + log_error("variable.regset: bad arguments: vars=%s, rxs=%s, input=%s", S(vars), S(rxs), S(input)); return; } @@ -699,7 +698,7 @@ vmod_batchset(VARIABLE_CTX ctx, re = pcre_compile(rxs, cflags, &error_ptr, &error_offset, NULL); if (!re) { - log_error("variable.batchset: %s: compilation failed near %s: %s", + log_error("variable.regset: %s: compilation failed near %s: %s", rxs, rxs + error_offset, error_ptr); vardef_free(head); return; @@ -713,7 +712,7 @@ vmod_batchset(VARIABLE_CTX ctx, } if (n < count) { - log_error("variable.batchset: %s: too few subexpressions to satisfy %s", + log_error("variable.regset: %s: too few subexpressions to satisfy %s", rxs, vars); vardef_free(head); return; @@ -724,13 +723,11 @@ vmod_batchset(VARIABLE_CTX ctx, rc = pcre_exec(re, 0, input, strlen(input), 0, 0, ovector, ovsize); if (rc <= 0) { - if (rc == 0) - log_error("matched, but too many substrings"); - else - /*FIXME*/; + if (rc != PCRE_ERROR_NOMATCH) + log_error("variable.regset: pcre_exec failed: %d", rc); vardef_free(head); return; - } + } for (def = head; def; def = def->next, i++) { char *s = bref_expand(def->repl, input, re, ovsize, ovector); @@ -743,14 +740,14 @@ vmod_batchset(VARIABLE_CTX ctx, errno = 0; lval = strtol(s, &p, 10); if (*p) { - log_error("variable.batchset: %s(%s)#%d: not an integer", rxs, input, i); + log_error("variable.regset: %s(%s)#%d: not an integer", rxs, input, i); value.i = 0; } else if (errno) { - log_error("variable.batchset: %s(%s)#%d: %s", + log_error("variable.regset: %s(%s)#%d: %s", rxs, input, i, strerror(errno)); value.i = 0; } else if (lval < INT_MIN || lval > INT_MAX) { - log_error("variable.batchset: %s(%s)#%d: value out of range", + log_error("variable.regset: %s(%s)#%d: value out of range", rxs, input, i); value.i = 0; } else @@ -761,10 +758,10 @@ vmod_batchset(VARIABLE_CTX ctx, errno = 0; value.r = strtod(s, &p); if (*p) { - log_error("variable.batchset: %s(%s)#%d: not a valid number", rxs, input, i); + log_error("variable.regset: %s(%s)#%d: not a valid number", rxs, input, i); value.r = 0; } else if (errno) { - log_error("variable.batchset: %s(%s)#%d: %s", + log_error("variable.regset: %s(%s)#%d: %s", rxs, input, i, strerror(errno)); value.r = 0; } diff --git a/src/variable.vcc b/src/variable.vcc index b8eb8e2..7fca518 100644 --- a/src/variable.vcc +++ b/src/variable.vcc @@ -33,5 +33,5 @@ $Function VOID clear() $Function INT defined(STRING) $Function STRING type_of(STRING) $Function VOID undef(STRING) -$Function VOID batchset(STRING, STRING, STRING) +$Function VOID regset(STRING, STRING, STRING) diff --git a/tests/Makefile.am b/tests/Makefile.am index 1a81bea..99769ae 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -41,7 +41,6 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac TESTSUITE_AT = \ testsuite.at\ - batchset.at\ complex.at\ clear.at\ defined.at\ @@ -49,6 +48,7 @@ TESTSUITE_AT = \ gstring.at\ int.at\ real.at\ + regset.at\ string.at\ type_of.at\ undef.at diff --git a/tests/batchset.at b/tests/batchset.at deleted file mode 100644 index 506fe78..0000000 --- a/tests/batchset.at +++ /dev/null @@ -1,39 +0,0 @@ -# This file is part of vmod-variable -*- autotest -*- -# Copyright (C) 2015 Sergey Poznyakoff -# -# Vmod-variable is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# Vmod-variable is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with vmod-variable. If not, see . - -AT_SETUP(batchset) -AT_KEYWORDS(batchset) - -AT_VARNISHTEST([ -sub vcl_recv { - variable.batchset("y:i,x,time:d=\3s", "^/(\d+)/(.+)/(\d+)", req.url); -} -sub vcl_deliver { - set resp.http.X-X = variable.get("x"); - set resp.http.X-Y = variable.get_int("y"); - set resp.http.X-Time = variable.get_duration("time"); -} -],[ -txreq -url /10/test/60 -rxresp -expect resp.http.X-X == "test" -expect resp.http.X-Y == "10" -expect resp.http.X-Time == "60.000" -]) -AT_CLEANUP - - - \ No newline at end of file diff --git a/tests/regset.at b/tests/regset.at new file mode 100644 index 0000000..cc92578 --- /dev/null +++ b/tests/regset.at @@ -0,0 +1,39 @@ +# This file is part of vmod-variable -*- autotest -*- +# Copyright (C) 2015 Sergey Poznyakoff +# +# Vmod-variable is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# Vmod-variable is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with vmod-variable. If not, see . + +AT_SETUP(regset) +AT_KEYWORDS(regset) + +AT_VARNISHTEST([ +sub vcl_recv { + variable.regset("y:i,x,time:d=\3s", "^/(\d+)/(.+)/(\d+)", req.url); +} +sub vcl_deliver { + set resp.http.X-X = variable.get("x"); + set resp.http.X-Y = variable.get_int("y"); + set resp.http.X-Time = variable.get_duration("time"); +} +],[ +txreq -url /10/test/60 +rxresp +expect resp.http.X-X == "test" +expect resp.http.X-Y == "10" +expect resp.http.X-Time == "60.000" +]) +AT_CLEANUP + + + \ No newline at end of file diff --git a/tests/testsuite.at b/tests/testsuite.at index 7312433..d0cc846 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -54,7 +54,7 @@ m4_include([clear.at]) m4_include([defined.at]) m4_include([type_of.at]) m4_include([undef.at]) -m4_include([batchset.at]) +m4_include([regset.at]) m4_include([gstring.at]) # End of testsuite.at -- cgit v1.2.1