Commit c6c63621 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Dridi Boukelmoune

Make help -j output real JSON, and push backend.list -j into

the schema intended for JSON output.

Conflicts:
	bin/varnishd/cache/cache_backend.c
	bin/varnishd/cache/cache_backend_probe.c
	bin/varnishd/cache/cache_director.c
	bin/varnishtest/tests/d00005.vtc
	bin/varnishtest/tests/v00014.vtc

Only help -j is fixed, the backend changes are left out.
parent 980a4a9e
......@@ -26,7 +26,7 @@ varnish v1 -start
varnish v1 -cliok "help"
varnish v1 -cliok "help -j"
varnish v1 -clijson "help -j"
varnish v1 -clierr 106 "param.set waiter HASH(0x8839c4c)"
......
......@@ -85,7 +85,8 @@ int VCLI_Overflow(struct cli *cli);
void VCLI_Out(struct cli *cli, const char *fmt, ...) v_printflike_(2, 3);
void VCLI_Quote(struct cli *cli, const char *str);
void VCLI_JSON_str(struct cli *cli, const char *str);
void VCLI_JSON_ver(struct cli *cli, unsigned ver, const char * const * av);
void VCLI_JSON_begin(struct cli *cli, unsigned ver, const char * const * av);
void VCLI_JSON_end(struct cli *cli);
void VCLI_SetResult(struct cli *cli, unsigned r);
typedef int cls_cb_f(void *priv);
......
......@@ -159,26 +159,35 @@ VCLS_func_help_json(struct cli *cli, const char * const *av, void *priv)
cs = cli->cls;
CHECK_OBJ_NOTNULL(cs, VCLS_MAGIC);
VCLI_JSON_ver(cli, 1, av);
VCLI_JSON_begin(cli, 1, av);
VTAILQ_FOREACH(clp, &cs->funcs, list) {
if (clp->auth > cli->auth)
continue;
VCLI_Out(cli, ",\n {");
VCLI_Out(cli, "\n \"request\": ");
VCLI_Out(cli, ",\n {\n");
VSB_indent(cli->sb, 2);
VCLI_Out(cli, "\"request\": ");
VCLI_JSON_str(cli, clp->desc->request);
VCLI_Out(cli, ",\n \"syntax\": ");
VCLI_Out(cli, ",\n");
VCLI_Out(cli, "\"syntax\": ");
VCLI_JSON_str(cli, clp->desc->syntax);
VCLI_Out(cli, ",\n \"help\": ");
VCLI_Out(cli, ",\n");
VCLI_Out(cli, "\"help\": ");
VCLI_JSON_str(cli, clp->desc->help);
VCLI_Out(cli, ",\n \"minarg\": %d", clp->desc->minarg);
VCLI_Out(cli, ", \"maxarg\": %d", clp->desc->maxarg);
VCLI_Out(cli, ", \"flags\": ");
VCLI_Out(cli, ",\n");
VCLI_Out(cli, "\"minarg\": %d", clp->desc->minarg);
VCLI_Out(cli, ",\n");
VCLI_Out(cli, "\"maxarg\": %d", clp->desc->maxarg);
VCLI_Out(cli, ",\n");
VCLI_Out(cli, "\"flags\": ");
VCLI_JSON_str(cli, clp->flags);
VCLI_Out(cli, ", \"json\": %s",
VCLI_Out(cli, ",\n");
VCLI_Out(cli, "\"json\": %s",
clp->jsonfunc == NULL ? "false" : "true");
VCLI_Out(cli, "\n }");
VCLI_Out(cli, "\n");
VSB_indent(cli->sb, -2);
VCLI_Out(cli, "}");
}
VCLI_Out(cli, "\n]\n");
VCLI_JSON_end(cli);
}
/*--------------------------------------------------------------------
......@@ -641,12 +650,14 @@ VCLI_JSON_str(struct cli *cli, const char *s)
{
CHECK_OBJ_NOTNULL(cli, CLI_MAGIC);
VSB_putc(cli->sb, '"');
VSB_quote(cli->sb, s, -1, VSB_QUOTE_JSON);
VSB_putc(cli->sb, '"');
}
/*lint -e{818} cli could be const */
void
VCLI_JSON_ver(struct cli *cli, unsigned ver, const char * const * av)
VCLI_JSON_begin(struct cli *cli, unsigned ver, const char * const * av)
{
int i;
......@@ -658,6 +669,15 @@ VCLI_JSON_ver(struct cli *cli, unsigned ver, const char * const * av)
VCLI_Out(cli, ", ");
}
VCLI_Out(cli, "]");
VSB_indent(cli->sb, 2);
}
void
VCLI_JSON_end(struct cli *cli)
{
VSB_indent(cli->sb, -2);
VCLI_Out(cli, "\n");
VCLI_Out(cli, "]\n");
}
/*lint -e{818} cli could be const */
......
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