lib/libvarnish/vcli_serve.c
static void
cls_dispatch(struct cli *cli, const struct cli_proto *cp,
    char * const * av, int ac)
{
	int json = 0;

	AN(av);
	assert(ac >= 0);

	VSB_clear(cli->sb);

	if (ac > 1 && !strcmp(av[2], "-j"))
		json = 1;

	if (cp->func == NULL && !json) {
		VCLI_Out(cli, "Unimplemented\n");
		VCLI_SetResult(cli, CLIS_UNIMPL);
		return;
	}
	if (cp->jsonfunc == NULL && json) {
		VCLI_Out(cli, "JSON unimplemented\n");
		VCLI_SetResult(cli, CLIS_UNIMPL);
		return;
	}

	if (ac - 1 < cp->desc->minarg + json) {
		VCLI_Out(cli, "Too few parameters\n");
		VCLI_SetResult(cli, CLIS_TOOFEW);
		return;
	}

	if (cp->desc->maxarg >= 0 && ac - 1 > cp->desc->maxarg + json) {
		VCLI_Out(cli, "Too many parameters\n");
		VCLI_SetResult(cli, CLIS_TOOMANY);
		return;
	}

	cli->result = CLIS_OK;
	if (json)
		cp->jsonfunc(cli, (const char * const *)av, cp->priv);
	else
		cp->func(cli, (const char * const *)av, cp->priv);
}
/*--------------------------------------------------------------------
 * Look for a CLI command to execute
 */
Look for a CLI command to execute
Look for a CLI command to execute
static void
cls_dispatch(struct cli *cli, const struct cli_proto *cp,
    char * const * av, int ac)
{
	int json = 0;
	AN(av);
	assert(ac >= 0);
	VSB_clear(cli->sb);
	if (ac > 1 && !strcmp(av[2], "-j"))
		json = 1;
	if (cp->func == NULL && !json) {
		VCLI_Out(cli, "Unimplemented\n");
		VCLI_SetResult(cli, CLIS_UNIMPL);
		return;
	}
	if (cp->jsonfunc == NULL && json) {
		VCLI_Out(cli, "JSON unimplemented\n");
		VCLI_SetResult(cli, CLIS_UNIMPL);
		return;
	}
	if (ac - 1 < cp->desc->minarg + json) {
		VCLI_Out(cli, "Too few parameters\n");
		VCLI_SetResult(cli, CLIS_TOOFEW);
		return;
	}
	if (cp->desc->maxarg >= 0 && ac - 1 > cp->desc->maxarg + json) {
		VCLI_Out(cli, "Too many parameters\n");
		VCLI_SetResult(cli, CLIS_TOOMANY);
		return;
	}
	cli->result = CLIS_OK;
	if (json)
		cp->jsonfunc(cli, (const char * const *)av, cp->priv);
	else
		cp->func(cli, (const char * const *)av, cp->priv);
}
static void cls_dispatch ( struct cli * cli , const struct cli_proto * cp , char * const * av , int ac ) { int json = 0 ; AN ( av ) ; assert ( ac >= 0 ) ; VSB_clear ( cli -> sb ) ; if ( ac > 1 && ! strcmp ( av [ 2 ] , " " ) ) json = 1 ; if ( cp -> func == NULL && ! json ) { VCLI_Out ( cli , " \n " ) ; VCLI_SetResult ( cli , CLIS_UNIMPL ) ; return ; } if ( cp -> jsonfunc == NULL && json ) { VCLI_Out ( cli , " \n " ) ; VCLI_SetResult ( cli , CLIS_UNIMPL ) ; return ; } if ( ac - 1 < cp -> desc -> minarg + json ) { VCLI_Out ( cli , " \n " ) ; VCLI_SetResult ( cli , CLIS_TOOFEW ) ; return ; } if ( cp -> desc -> maxarg >= 0 && ac - 1 > cp -> desc -> maxarg + json ) { VCLI_Out ( cli , " \n " ) ; VCLI_SetResult ( cli , CLIS_TOOMANY ) ; return ; } cli -> result = CLIS_OK ; if ( json ) cp -> jsonfunc ( cli , ( const char * const * ) av , cp -> priv ) ; else cp -> func ( cli , ( const char * const * ) av , cp -> priv ) ; }
Look for a CLI command to execute
Look for a CLI command to execute