[master] 570a04f Add a VSL_List2Tags function for finding tags.

Martin Blix Grydeland martin at varnish-cache.org
Tue Oct 1 14:48:18 CEST 2013


commit 570a04f5cd88f8fdd61211236b15f839e4d3a1ca
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Sep 24 15:03:41 2013 +0200

    Add a VSL_List2Tags function for finding tags.
    
    This function takes a commaseparated list and feeds each part to
    VSL_Glob2Tags.

diff --git a/include/vapi/vsl.h b/include/vapi/vsl.h
index 7c998de..4371521 100644
--- a/include/vapi/vsl.h
+++ b/include/vapi/vsl.h
@@ -96,13 +96,14 @@ typedef int VSLQ_dispatch_f(struct VSL_data *vsl,
 	 *   !=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:
 	 *    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];
@@ -126,7 +127,7 @@ int VSL_Name2Tag(const char *name, int l);
 	 *	-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
 	 * 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);
 	 *     -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);
 	/*
 	 * Convert string to grouping (= enum VSL_grouping_e)
diff --git a/lib/libvarnishapi/libvarnishapi.map b/lib/libvarnishapi/libvarnishapi.map
index 42315a0..8862129 100644
--- a/lib/libvarnishapi/libvarnishapi.map
+++ b/lib/libvarnishapi/libvarnishapi.map
@@ -116,5 +116,6 @@ LIBVARNISHAPI_1.3 {
 	VSLQ_Flush;
 	VSLQ_Name2Grouping;
 	VSL_Glob2Tags;
+	VSL_List2Tags;
 	# Variables:
 } LIBVARNISHAPI_1.0;
diff --git a/lib/libvarnishapi/vsl_arg.c b/lib/libvarnishapi/vsl_arg.c
index da54295..efc2eb8 100644
--- a/lib/libvarnishapi/vsl_arg.c
+++ b/lib/libvarnishapi/vsl_arg.c
@@ -84,7 +84,7 @@ VSL_Name2Tag(const char *name, int l)
 }
 
 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 pre = 0;
@@ -152,6 +152,36 @@ VSL_Glob2Tags(const char *glob, int l, VSL_glob2tags_f *func, void *priv)
 	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[] = {
 	[VSL_g_raw]	= "raw",
 	[VSL_g_vxid]	= "vxid",



More information about the varnish-commit mailing list