r2597 - in trunk/varnish-cache: include lib/libvarnish

phk at projects.linpro.no phk at projects.linpro.no
Wed Mar 12 14:46:35 CET 2008


Author: phk
Date: 2008-03-12 14:46:34 +0100 (Wed, 12 Mar 2008)
New Revision: 2597

Modified:
   trunk/varnish-cache/include/cli_priv.h
   trunk/varnish-cache/lib/libvarnish/cli.c
Log:
Add a CLI support function for concatenating two cli_proto tables
in malloc'ed memory.


Modified: trunk/varnish-cache/include/cli_priv.h
===================================================================
--- trunk/varnish-cache/include/cli_priv.h	2008-03-12 10:29:43 UTC (rev 2596)
+++ trunk/varnish-cache/include/cli_priv.h	2008-03-12 13:46:34 UTC (rev 2597)
@@ -60,3 +60,4 @@
 /* From libvarnish/cli.c */
 void cli_dispatch(struct cli *cli, struct cli_proto *clp, const char *line);
 cli_func_t	cli_func_help;
+struct cli_proto *cli_concat(struct cli_proto *, struct cli_proto *);

Modified: trunk/varnish-cache/lib/libvarnish/cli.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/cli.c	2008-03-12 10:29:43 UTC (rev 2596)
+++ trunk/varnish-cache/lib/libvarnish/cli.c	2008-03-12 13:46:34 UTC (rev 2597)
@@ -35,6 +35,7 @@
 
 #include <ctype.h>
 #include <string.h>
+#include <stdlib.h>
 #include <stdio.h>
 
 #include <cli.h>
@@ -131,3 +132,28 @@
 	} while (0);
 	FreeArgv(av);
 }
+
+struct cli_proto *
+cli_concat(struct cli_proto *c1, struct cli_proto *c2)
+{
+	struct cli_proto *c;
+	int i1, i2;
+
+	i1 = 0;
+	for(c = c1; c != NULL && c->request != NULL; c++)
+		i1++;
+	i2 = 0;
+	for(c = c2; c != NULL && c->request != NULL; c++)
+		i2++;
+
+	c = malloc(sizeof(*c) * (i1 + i2 + 1));
+	if (c == NULL)
+		return (c);
+	if (c1 != NULL)
+		memcpy(c, c1, sizeof(*c1) * i1);
+	if (c2 != NULL)
+		memcpy(c + i1, c2, sizeof(*c2) * i2);
+	memset(c + i1 + i2, 0, sizeof(*c));
+	return (c);
+}
+




More information about the varnish-commit mailing list