Commit e9f4df5a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a CLI support function for concatenating two cli_proto tables

in malloc'ed memory.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2597 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent ef865c23
......@@ -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 *);
......@@ -35,6 +35,7 @@
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <cli.h>
......@@ -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);
}
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