From: phk Date: Wed, 12 Mar 2008 13:46:34 +0000 (+0000) Subject: Add a CLI support function for concatenating two cli_proto tables X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41b67dd965d2d25a5ef2bf1d0f5a6844814271c2;p=varnish Add a CLI support function for concatenating two cli_proto tables in malloc'ed memory. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2597 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/include/cli_priv.h b/varnish-cache/include/cli_priv.h index 6dfb7762..74ce9677 100644 --- a/varnish-cache/include/cli_priv.h +++ b/varnish-cache/include/cli_priv.h @@ -60,3 +60,4 @@ void cli_result(struct cli *cli, unsigned r); /* 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 *); diff --git a/varnish-cache/lib/libvarnish/cli.c b/varnish-cache/lib/libvarnish/cli.c index 1690d2a6..eb04d091 100644 --- a/varnish-cache/lib/libvarnish/cli.c +++ b/varnish-cache/lib/libvarnish/cli.c @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -131,3 +132,28 @@ cli_dispatch(struct cli *cli, struct cli_proto *clp, const char *line) } 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); +} +