lib/libvarnish/vcli_serve.c
static int
cls_exec(struct VCLS_fd *cfd, char * const *av)
{
	struct VCLS *cs;
	struct cli_proto *clp;
	struct cli *cli;
	int na;
	ssize_t len;
	char *s;
	unsigned lim;
	int retval = 0;

	CHECK_OBJ_NOTNULL(cfd, VCLS_FD_MAGIC);
	cs = cfd->cls;
	CHECK_OBJ_NOTNULL(cs, VCLS_MAGIC);

	cli = cfd->cli;
	CHECK_OBJ_NOTNULL(cli, CLI_MAGIC);
	AN(cli->cmd);

	cli->cls = cs;

	cli->result = CLIS_UNKNOWN;
	VSB_clear(cli->sb);
	VCLI_Out(cli, "Unknown request.\nType 'help' for more info.\n");

	if (cs->before != NULL)
		cs->before(cli);

	do {
		if (av[0] != NULL) {
			VCLI_Out(cli, "Syntax Error: %s\n", av[0]);
			VCLI_SetResult(cli, CLIS_SYNTAX);
			break;
		}

		if (av[1] == NULL) {
			VCLI_Out(cli, "Empty CLI command.\n");
			VCLI_SetResult(cli, CLIS_SYNTAX);
			break;
		}

		if (isupper(av[1][0])) {
			VCLI_Out(cli, "all commands are in lower-case.\n");
			VCLI_SetResult(cli, CLIS_UNKNOWN);
			break;
		}

		if (!islower(av[1][0]))
			break;

		for (na = 0; av[na + 1] != NULL; na++)
			continue;

		VTAILQ_FOREACH(clp, &cs->funcs, list) {
			if (clp->auth > cli->auth)
				continue;
			if (!strcmp(clp->desc->request, av[1])) {
				cls_dispatch(cli, clp, av, na);
				break;
			}
		}
		if (clp == NULL &&
		    cs->wildcard && cs->wildcard->auth <= cli->auth)
			cls_dispatch(cli, cs->wildcard, av, na);

	} while (0);

	AZ(VSB_finish(cli->sb));

	if (cs->after != NULL)
		cs->after(cli);

	cli->cls = NULL;

	s = VSB_data(cli->sb);
	len = VSB_len(cli->sb);
	lim = *cs->limit;
	if (len > lim) {
		if (cli->result == CLIS_OK)
			cli->result = CLIS_TRUNCATED;
		s[lim - 1] = '\0';
		assert(strlen(s) <= lim);
	}
	if (VCLI_WriteResult(cfd->fdo, cli->result, s) ||
	    cli->result == CLIS_CLOSE)
		retval = 1;

	/*
	 * In unauthenticated mode we are very intolerant, and close the
	 * connection at the least provocation.
	 */
	if (cli->auth == 0 && cli->result != CLIS_OK)
		retval = 1;

	return (retval);
}
/*--------------------------------------------------------------------
 * We have collected a full cli line, parse it and execute, if possible.
 */
We have collected a full cli line, parse it and execute, if possible.
We have collected a full cli line parse it and execute if possible .
static int
cls_exec(struct VCLS_fd *cfd, char * const *av)
{
	struct VCLS *cs;
	struct cli_proto *clp;
	struct cli *cli;
	int na;
	ssize_t len;
	char *s;
	unsigned lim;
	int retval = 0;
	CHECK_OBJ_NOTNULL(cfd, VCLS_FD_MAGIC);
	cs = cfd->cls;
	CHECK_OBJ_NOTNULL(cs, VCLS_MAGIC);
	cli = cfd->cli;
	CHECK_OBJ_NOTNULL(cli, CLI_MAGIC);
	AN(cli->cmd);
	cli->cls = cs;
	cli->result = CLIS_UNKNOWN;
	VSB_clear(cli->sb);
	VCLI_Out(cli, "Unknown request.\nType 'help' for more info.\n");
	if (cs->before != NULL)
		cs->before(cli);
	do {
		if (av[0] != NULL) {
			VCLI_Out(cli, "Syntax Error: %s\n", av[0]);
			VCLI_SetResult(cli, CLIS_SYNTAX);
			break;
		}
		if (av[1] == NULL) {
			VCLI_Out(cli, "Empty CLI command.\n");
			VCLI_SetResult(cli, CLIS_SYNTAX);
			break;
		}
		if (isupper(av[1][0])) {
			VCLI_Out(cli, "all commands are in lower-case.\n");
			VCLI_SetResult(cli, CLIS_UNKNOWN);
			break;
		}
		if (!islower(av[1][0]))
			break;
		for (na = 0; av[na + 1] != NULL; na++)
			continue;
		VTAILQ_FOREACH(clp, &cs->funcs, list) {
			if (clp->auth > cli->auth)
				continue;
			if (!strcmp(clp->desc->request, av[1])) {
				cls_dispatch(cli, clp, av, na);
				break;
			}
		}
		if (clp == NULL &&
		    cs->wildcard && cs->wildcard->auth <= cli->auth)
			cls_dispatch(cli, cs->wildcard, av, na);
	} while (0);
	AZ(VSB_finish(cli->sb));
	if (cs->after != NULL)
		cs->after(cli);
	cli->cls = NULL;
	s = VSB_data(cli->sb);
	len = VSB_len(cli->sb);
	lim = *cs->limit;
	if (len > lim) {
		if (cli->result == CLIS_OK)
			cli->result = CLIS_TRUNCATED;
		s[lim - 1] = '\0';
		assert(strlen(s) <= lim);
	}
	if (VCLI_WriteResult(cfd->fdo, cli->result, s) ||
	    cli->result == CLIS_CLOSE)
		retval = 1;
	if (cli->auth == 0 && cli->result != CLIS_OK)
		retval = 1;
	return (retval);
}
static int cls_exec ( struct VCLS_fd * cfd , char * const * av ) { struct VCLS * cs ; struct cli_proto * clp ; struct cli * cli ; int na ; ssize_t len ; char * s ; unsigned lim ; int retval = 0 ; CHECK_OBJ_NOTNULL ( cfd , VCLS_FD_MAGIC ) ; cs = cfd -> cls ; CHECK_OBJ_NOTNULL ( cs , VCLS_MAGIC ) ; cli = cfd -> cli ; CHECK_OBJ_NOTNULL ( cli , CLI_MAGIC ) ; AN ( cli -> cmd ) ; cli -> cls = cs ; cli -> result = CLIS_UNKNOWN ; VSB_clear ( cli -> sb ) ; VCLI_Out ( cli , " \n \n " ) ; if ( cs -> before != NULL ) cs -> before ( cli ) ; do { if ( av [ 0 ] != NULL ) { VCLI_Out ( cli , " \n " , av [ 0 ] ) ; VCLI_SetResult ( cli , CLIS_SYNTAX ) ; break ; } if ( av [ 1 ] == NULL ) { VCLI_Out ( cli , " \n " ) ; VCLI_SetResult ( cli , CLIS_SYNTAX ) ; break ; } if ( isupper ( av [ 1 ] [ 0 ] ) ) { VCLI_Out ( cli , " \n " ) ; VCLI_SetResult ( cli , CLIS_UNKNOWN ) ; break ; } if ( ! islower ( av [ 1 ] [ 0 ] ) ) break ; for ( na = 0 ; av [ na + 1 ] != NULL ; na ++ ) continue ; VTAILQ_FOREACH ( clp , & cs -> funcs , list ) { if ( clp -> auth > cli -> auth ) continue ; if ( ! strcmp ( clp -> desc -> request , av [ 1 ] ) ) { cls_dispatch ( cli , clp , av , na ) ; break ; } } if ( clp == NULL && cs -> wildcard && cs -> wildcard -> auth <= cli -> auth ) cls_dispatch ( cli , cs -> wildcard , av , na ) ; } while ( 0 ) ; AZ ( VSB_finish ( cli -> sb ) ) ; if ( cs -> after != NULL ) cs -> after ( cli ) ; cli -> cls = NULL ; s = VSB_data ( cli -> sb ) ; len = VSB_len ( cli -> sb ) ; lim = * cs -> limit ; if ( len > lim ) { if ( cli -> result == CLIS_OK ) cli -> result = CLIS_TRUNCATED ; s [ lim - 1 ] = ' \0 ' ; assert ( strlen ( s ) <= lim ) ; } if ( VCLI_WriteResult ( cfd -> fdo , cli -> result , s ) || cli -> result == CLIS_CLOSE ) retval = 1 ; if ( cli -> auth == 0 && cli -> result != CLIS_OK ) retval = 1 ; return ( retval ) ; }
We have collected a full cli line, parse it and execute, if possible.
We have collected a full cli line parse it and execute if possible .
/*
	 * In unauthenticated mode we are very intolerant, and close the
	 * connection at the least provocation.
	 */