Exemplo n.º 1
0
static void
cmd_http_expect(CMD_ARGS)
{
    struct http *hp;
    const char *lhs;
    char *cmp;
    const char *rhs;
    vre_t *vre;
    const char *error;
    int erroroffset;
    int i;

    (void)cmd;
    (void)vl;
    CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
    assert(!strcmp(av[0], "expect"));
    av++;

    AN(av[0]);
    AN(av[1]);
    AN(av[2]);
    AZ(av[3]);
    lhs = cmd_var_resolve(hp, av[0]);
    cmp = av[1];
    rhs = cmd_var_resolve(hp, av[2]);
    if (!strcmp(cmp, "==")) {
        if (strcmp(lhs, rhs))
            vtc_log(hp->vl, 0, "EXPECT %s (%s) %s %s (%s) failed",
                    av[0], lhs, av[1], av[2], rhs);
        else
            vtc_log(hp->vl, 4, "EXPECT %s (%s) %s %s (%s) match",
                    av[0], lhs, av[1], av[2], rhs);
    } else if (!strcmp(cmp, "!=")) {
        if (!strcmp(lhs, rhs))
            vtc_log(hp->vl, 0, "EXPECT %s (%s) %s %s (%s) failed",
                    av[0], lhs, av[1], av[2], rhs);
        else
            vtc_log(hp->vl, 4, "EXPECT %s (%s) %s %s (%s) match",
                    av[0], lhs, av[1], av[2], rhs);
    } else if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) {
        vre = VRE_compile(rhs, 0, &error, &erroroffset);
        if (vre == NULL)
            vtc_log(hp->vl, 0, "REGEXP error: %s (@%d) (%s)",
                    error, erroroffset, rhs);
        i = VRE_exec(vre, lhs, strlen(lhs), 0, 0, NULL, 0, 0);
        if ((i >= 0 && *cmp == '~') || (i < 0 && *cmp == '!'))
            vtc_log(hp->vl, 4, "EXPECT %s (%s) %s \"%s\" match",
                    av[0], lhs, cmp, rhs);
        else
            vtc_log(hp->vl, 0, "EXPECT %s (%s) %s \"%s\" failed",
                    av[0], lhs, cmp, rhs);
        VRE_free(&vre);
    } else {
        vtc_log(hp->vl, 0,
                "EXPECT %s (%s) %s %s (%s) test not implemented",
                av[0], lhs, av[1], av[2], rhs);
    }
}
Exemplo n.º 2
0
static void
cmd_http_expect(CMD_ARGS)
{
	struct http *hp;
	const char *lhs;
	char *cmp;
	const char *rhs;

	(void)cmd;
	(void)vl;
	CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
	assert(!strcmp(av[0], "expect"));
	av++;

	AN(av[0]);
	AN(av[1]);
	AN(av[2]);
	AZ(av[3]);
	lhs = cmd_var_resolve(hp, av[0]);
	cmp = av[1];
	rhs = cmd_var_resolve(hp, av[2]);
	if (!strcmp(cmp, "==")) {
		if (strcmp(lhs, rhs))
			vtc_log(hp->vl, 0, "EXPECT %s (%s) %s %s (%s) failed",
			    av[0], lhs, av[1], av[2], rhs);
		else
			vtc_log(hp->vl, 4, "EXPECT %s (%s) %s %s (%s) match",
			    av[0], lhs, av[1], av[2], rhs);
	} else if (!strcmp(cmp, "!=")) {
		if (!strcmp(lhs, rhs))
			vtc_log(hp->vl, 0, "EXPECT %s (%s) %s %s (%s) failed",
			    av[0], lhs, av[1], av[2], rhs);
		else
			vtc_log(hp->vl, 4, "EXPECT %s (%s) %s %s (%s) match",
			    av[0], lhs, av[1], av[2], rhs);
	} else {
		vtc_log(hp->vl, 0,
		    "EXPECT %s (%s) %s %s (%s) test not implemented",
		    av[0], lhs, av[1], av[2], rhs);
	}
}
Exemplo n.º 3
0
static void
cmd_http_expect(CMD_ARGS)
{
	struct http *hp;
	const char *lhs, *clhs;
	char *cmp;
	const char *rhs, *crhs;
	vre_t *vre;
	const char *error;
	int erroroffset;
	int i, retval = -1;

	(void)cmd;
	(void)vl;
	CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
	AZ(strcmp(av[0], "expect"));
	av++;

	AN(av[0]);
	AN(av[1]);
	AN(av[2]);
	AZ(av[3]);
	lhs = cmd_var_resolve(hp, av[0]);
	cmp = av[1];
	rhs = cmd_var_resolve(hp, av[2]);

	clhs = lhs ? lhs : "<undef>";
	crhs = rhs ? rhs : "<undef>";

	if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) {
		vre = VRE_compile(crhs, 0, &error, &erroroffset);
		if (vre == NULL)
			vtc_log(hp->vl, 0, "REGEXP error: %s (@%d) (%s)",
			    error, erroroffset, crhs);
		i = VRE_exec(vre, clhs, strlen(clhs), 0, 0, NULL, 0, 0);
		retval = (i >= 0 && *cmp == '~') || (i < 0 && *cmp == '!');
		VRE_free(&vre);
	} else if (!strcmp(cmp, "==")) {
		retval = strcmp(clhs, crhs) == 0;
	} else if (!strcmp(cmp, "!=")) {
		retval = strcmp(clhs, crhs) != 0;
	} else if (lhs == NULL || rhs == NULL) {
		// fail inequality comparisons if either side is undef'ed
		retval = 0;
	} else if (!strcmp(cmp, "<")) {
		retval = isless(VNUM(lhs), VNUM(rhs));
	} else if (!strcmp(cmp, ">")) {
		retval = isgreater(VNUM(lhs), VNUM(rhs));
	} else if (!strcmp(cmp, "<=")) {
		retval = islessequal(VNUM(lhs), VNUM(rhs));
	} else if (!strcmp(cmp, ">=")) {
		retval = isgreaterequal(VNUM(lhs), VNUM(rhs));
	}

	if (retval == -1)
		vtc_log(hp->vl, 0,
		    "EXPECT %s (%s) %s %s (%s) test not implemented",
		    av[0], clhs, av[1], av[2], crhs);
	else
		vtc_log(hp->vl, retval ? 4 : 0, "EXPECT %s (%s) %s \"%s\" %s",
		    av[0], clhs, cmp, crhs, retval ? "match" : "failed");
}