Commit d6d30486 authored by Geoff Simmons's avatar Geoff Simmons

Add the .subroutine() method.

parent 5cea4e6d
......@@ -438,8 +438,8 @@ Examples::
.. _xset.add():
VOID xset.add(STRING, [STRING string], [STRING regex], [BACKEND backend], [INT integer], [BOOL bool])
-----------------------------------------------------------------------------------------------------
VOID xset.add(STRING, [STRING string], [STRING regex], [BACKEND backend], [INT integer], [BOOL bool], [SUB sub])
----------------------------------------------------------------------------------------------------------------
::
......@@ -449,7 +449,8 @@ VOID xset.add(STRING, [STRING string], [STRING regex], [BACKEND backend], [INT i
[STRING regex],
[BACKEND backend],
[INT integer],
[BOOL bool]
[BOOL bool],
[SUB sub]
)
Add the given string to the set. As indicated above, elements added to
......@@ -1056,6 +1057,21 @@ Example::
# /foo/bar/1/2/* is rewritten as /foo/bar/2/1/*
# /foo/bar/baz/1/2/* is rewritten as /foo/bar/baz/2/1/*
.. _xset.subroutine():
SUB xset.subroutine(INT n, STRING element, ENUM select)
-------------------------------------------------------
::
SUB xset.subroutine(
INT n=0,
STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE
)
XXX ...
.. _selector.version():
STRING version()
......
......@@ -273,3 +273,21 @@ vmod_set_bool(VRT_CTX, struct VPFX(selector_set) *set, VCL_INT n,
return (set->table[idx]->bool);
}
VCL_SUB
vmod_set_subroutine(VRT_CTX, struct VPFX(selector_set) *set, VCL_INT n,
VCL_STRING element, VCL_ENUM selects)
{
unsigned idx;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(set, VMOD_SELECTOR_SET_MAGIC);
idx = get_idx(ctx, n, set, "subroutine", element, selects);
if (idx == UINT_MAX)
return (NULL);
if (!check_added(ctx, set, idx, SUB, "subroutine", "subroutine"))
return (NULL);
return (set->table[idx]->sub);
}
This diff is collapsed.
......@@ -506,7 +506,7 @@ vmod_set_add(VRT_CTX, struct vmod_selector_set *set,
}
if (!args->valid_string && re == NULL && !args->valid_backend
&& !args->valid_integer && !args->valid_bool)
&& !args->valid_integer && !args->valid_bool && !args->valid_sub)
return;
set->table = realloc(set->table, n * sizeof(struct entry *));
......@@ -534,6 +534,10 @@ vmod_set_add(VRT_CTX, struct vmod_selector_set *set,
entry->bool = args->bool;
set_added(set, n - 1, BOOLEAN);
}
if (args->valid_sub) {
entry->sub = args->sub;
set_added(set, n - 1, SUB);
}
set->table[n - 1] = entry;
}
......
......@@ -48,11 +48,12 @@
struct entry {
unsigned magic;
#define VMOD_SELECTOR_ENTRY_MAGIC 0x733dbe63
VCL_BOOL bool;
char *string;
VCL_BACKEND backend;
VCL_SUB sub;
vre_t *re;
VCL_INT integer;
VCL_BOOL bool;
};
enum bitmap_e {
......@@ -61,6 +62,7 @@ enum bitmap_e {
REGEX,
INTEGER,
BOOLEAN,
SUB,
__MAX_BITMAP,
};
......
......@@ -423,7 +423,7 @@ Examples::
}
$Method VOID .add(STRING, [STRING string], [STRING regex], [BACKEND backend],
[INT integer], [BOOL bool])
[INT integer], [BOOL bool], [SUB sub])
Add the given string to the set. As indicated above, elements added to
the set are implicitly numbered in the order in which they are added
......@@ -931,6 +931,12 @@ Example::
# /foo/bar/1/2/* is rewritten as /foo/bar/2/1/*
# /foo/bar/baz/1/2/* is rewritten as /foo/bar/baz/2/1/*
$Method SUB .subroutine(INT n=0, STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST}
select=UNIQUE)
XXX ...
$Function STRING version()
Return the version string for this VMOD.
......
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