Commit 570a04f5 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Add a VSL_List2Tags function for finding tags.

This function takes a commaseparated list and feeds each part to
VSL_Glob2Tags.
parent a2519bc9
...@@ -96,13 +96,14 @@ typedef int VSLQ_dispatch_f(struct VSL_data *vsl, ...@@ -96,13 +96,14 @@ typedef int VSLQ_dispatch_f(struct VSL_data *vsl,
* !=0: Makes VSLQ_Dispatch return with this return value immediatly * !=0: Makes VSLQ_Dispatch return with this return value immediatly
*/ */
typedef void VSL_glob2tags_f(int tag, void *priv); typedef void VSL_tagfind_f(int tag, void *priv);
/* /*
* The callback function type for use with VSL_Glob2Tags. * The callback function type for use with VSL_Glob2Tags and
* VSL_List2Tags..
* *
* Arguments: * Arguments:
* tag: Tag number (= enum VSL_tag_e) * tag: Tag number (= enum VSL_tag_e)
* priv: The priv argument from VSL_Glob2Tag * priv: The priv argument
*/ */
extern const char *VSL_tags[SLT__MAX]; extern const char *VSL_tags[SLT__MAX];
...@@ -126,7 +127,7 @@ int VSL_Name2Tag(const char *name, int l); ...@@ -126,7 +127,7 @@ int VSL_Name2Tag(const char *name, int l);
* -2: Multiple tags match substring * -2: Multiple tags match substring
*/ */
int VSL_Glob2Tags(const char *glob, int l, VSL_glob2tags_f *func, void *priv); int VSL_Glob2Tags(const char *glob, int l, VSL_tagfind_f *func, void *priv);
/* /*
* Convert a string to multiple tag matches. The string can have * Convert a string to multiple tag matches. The string can have
* either a prefix or postfix wildcard (*) character. For each * either a prefix or postfix wildcard (*) character. For each
...@@ -145,6 +146,25 @@ int VSL_Glob2Tags(const char *glob, int l, VSL_glob2tags_f *func, void *priv); ...@@ -145,6 +146,25 @@ int VSL_Glob2Tags(const char *glob, int l, VSL_glob2tags_f *func, void *priv);
* -3: Syntax error * -3: Syntax error
*/ */
int VSL_List2Tags(const char *list, int l, VSL_tagfind_f *func, void *priv);
/*
* Convert a comma-separated list of tag globs to tag
* matches. Calls VSL_Glob2Tags for each comma-separated part of
* list.
*
* Arguments:
* list: The list of globs
* l: The length of list. -1 to use strlen
* func: The function to call (can be NULL)
* priv: An argument that will be passed to func.
*
* Return valus:
* >0: Number of times func was called for matching tags.
* -1: No tag matches for list element
* -2: Multiple tags match non-glob list element
* -3: Syntax error
*/
int VSLQ_Name2Grouping(const char *name, int l); int VSLQ_Name2Grouping(const char *name, int l);
/* /*
* Convert string to grouping (= enum VSL_grouping_e) * Convert string to grouping (= enum VSL_grouping_e)
......
...@@ -116,5 +116,6 @@ LIBVARNISHAPI_1.3 { ...@@ -116,5 +116,6 @@ LIBVARNISHAPI_1.3 {
VSLQ_Flush; VSLQ_Flush;
VSLQ_Name2Grouping; VSLQ_Name2Grouping;
VSL_Glob2Tags; VSL_Glob2Tags;
VSL_List2Tags;
# Variables: # Variables:
} LIBVARNISHAPI_1.0; } LIBVARNISHAPI_1.0;
...@@ -84,7 +84,7 @@ VSL_Name2Tag(const char *name, int l) ...@@ -84,7 +84,7 @@ VSL_Name2Tag(const char *name, int l)
} }
int int
VSL_Glob2Tags(const char *glob, int l, VSL_glob2tags_f *func, void *priv) VSL_Glob2Tags(const char *glob, int l, VSL_tagfind_f *func, void *priv)
{ {
int i, r, l2; int i, r, l2;
int pre = 0; int pre = 0;
...@@ -152,6 +152,36 @@ VSL_Glob2Tags(const char *glob, int l, VSL_glob2tags_f *func, void *priv) ...@@ -152,6 +152,36 @@ VSL_Glob2Tags(const char *glob, int l, VSL_glob2tags_f *func, void *priv)
return (r); return (r);
} }
int
VSL_List2Tags(const char *list, int l, VSL_tagfind_f *func, void *priv)
{
const char *p, *q, *e;
int r, t;
if (l < 0)
l = strlen(list);
p = list;
e = p + l;
t = 0;
while (p < e) {
while (p < e && *p == ',')
p++;
if (p == e)
break;
q = p;
while (q < e && *q != ',')
q++;
r = VSL_Glob2Tags(p, q - p, func, priv);
if (r < 0)
return (r);
t += r;
p = q;
}
if (t == 0)
return (-1);
return (t);
}
static const char * const vsl_grouping[] = { static const char * const vsl_grouping[] = {
[VSL_g_raw] = "raw", [VSL_g_raw] = "raw",
[VSL_g_vxid] = "vxid", [VSL_g_vxid] = "vxid",
......
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