mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 14:21:25 +02:00
MINOR: checks: Use an indirect string to represent the expect matching string
Instead of having a string in the expect union with its length outside of the union, directly in the expect structure, an indirect string is now used.
This commit is contained in:
parent
404f919995
commit
f930e4c4df
@ -262,14 +262,13 @@ enum tcpcheck_expect_type {
|
|||||||
struct tcpcheck_expect {
|
struct tcpcheck_expect {
|
||||||
enum tcpcheck_expect_type type; /* Type of pattern used for matching. */
|
enum tcpcheck_expect_type type; /* Type of pattern used for matching. */
|
||||||
union {
|
union {
|
||||||
char *string; /* Matching a literal string / binary anywhere in the response. */
|
struct ist data; /* Matching a literal string / binary anywhere in the response. */
|
||||||
struct my_regex *regex; /* Matching a regex pattern. */
|
struct my_regex *regex; /* Matching a regex pattern. */
|
||||||
|
|
||||||
/* custom function to eval epxect rule */
|
/* custom function to eval epxect rule */
|
||||||
enum tcpcheck_eval_ret (*custom)(struct check *, struct tcpcheck_rule *, int);
|
enum tcpcheck_eval_ret (*custom)(struct check *, struct tcpcheck_rule *, int);
|
||||||
};
|
};
|
||||||
struct tcpcheck_rule *head; /* first expect of a chain. */
|
struct tcpcheck_rule *head; /* first expect of a chain. */
|
||||||
int length; /* Size in bytes of the pattern referenced by string / binary. */
|
|
||||||
int inverse; /* Match is inversed. */
|
int inverse; /* Match is inversed. */
|
||||||
int with_capture; /* Match will store captured groups for back-reference in comment. */
|
int with_capture; /* Match will store captured groups for back-reference in comment. */
|
||||||
int min_recv; /* Minimum amount of data before an expect can be applied. (default: -1, ignored) */
|
int min_recv; /* Minimum amount of data before an expect can be applied. (default: -1, ignored) */
|
||||||
|
25
src/checks.c
25
src/checks.c
@ -654,10 +654,10 @@ static void chk_report_conn_err(struct check *check, int errno_bck, int expired)
|
|||||||
|
|
||||||
switch (expect->type) {
|
switch (expect->type) {
|
||||||
case TCPCHK_EXPECT_STRING:
|
case TCPCHK_EXPECT_STRING:
|
||||||
chunk_appendf(chk, " (expect string '%s')", expect->string);
|
chunk_appendf(chk, " (expect string '%.*s')", (unsigned int)istlen(expect->data), expect->data.ptr);
|
||||||
break;
|
break;
|
||||||
case TCPCHK_EXPECT_BINARY:
|
case TCPCHK_EXPECT_BINARY:
|
||||||
chunk_appendf(chk, " (expect binary '%s')", expect->string);
|
chunk_appendf(chk, " (expect binary '%.*s')", (unsigned int)istlen(expect->data), expect->data.ptr);
|
||||||
break;
|
break;
|
||||||
case TCPCHK_EXPECT_REGEX:
|
case TCPCHK_EXPECT_REGEX:
|
||||||
chunk_appendf(chk, " (expect regex)");
|
chunk_appendf(chk, " (expect regex)");
|
||||||
@ -2325,7 +2325,8 @@ static void tcpcheck_onerror_message(struct buffer *msg, struct check *check, st
|
|||||||
chunk_strcat(msg, (match ? "TCPCHK matched unwanted content" : "TCPCHK did not match content"));
|
chunk_strcat(msg, (match ? "TCPCHK matched unwanted content" : "TCPCHK did not match content"));
|
||||||
switch (rule->expect.type) {
|
switch (rule->expect.type) {
|
||||||
case TCPCHK_EXPECT_STRING:
|
case TCPCHK_EXPECT_STRING:
|
||||||
chunk_appendf(msg, " '%s' at step %d", rule->expect.string, tcpcheck_get_step_id(check, rule));
|
chunk_appendf(msg, " '%.*s' at step %d", (unsigned int)istlen(rule->expect.data), rule->expect.data.ptr,
|
||||||
|
tcpcheck_get_step_id(check, rule));
|
||||||
break;
|
break;
|
||||||
case TCPCHK_EXPECT_BINARY:
|
case TCPCHK_EXPECT_BINARY:
|
||||||
chunk_appendf(msg, " (binary) at step %d", tcpcheck_get_step_id(check, rule));
|
chunk_appendf(msg, " (binary) at step %d", tcpcheck_get_step_id(check, rule));
|
||||||
@ -3113,7 +3114,7 @@ static enum tcpcheck_eval_ret tcpcheck_eval_expect(struct check *check, struct t
|
|||||||
*/
|
*/
|
||||||
if (!last_read) {
|
if (!last_read) {
|
||||||
if ((expect->type == TCPCHK_EXPECT_STRING || expect->type == TCPCHK_EXPECT_BINARY) &&
|
if ((expect->type == TCPCHK_EXPECT_STRING || expect->type == TCPCHK_EXPECT_BINARY) &&
|
||||||
(b_data(&check->bi) < expect->length)) {
|
(b_data(&check->bi) < istlen(expect->data))) {
|
||||||
ret = TCPCHK_EVAL_WAIT;
|
ret = TCPCHK_EVAL_WAIT;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -3129,7 +3130,7 @@ static enum tcpcheck_eval_ret tcpcheck_eval_expect(struct check *check, struct t
|
|||||||
switch (expect->type) {
|
switch (expect->type) {
|
||||||
case TCPCHK_EXPECT_STRING:
|
case TCPCHK_EXPECT_STRING:
|
||||||
case TCPCHK_EXPECT_BINARY:
|
case TCPCHK_EXPECT_BINARY:
|
||||||
match = my_memmem(b_head(&check->bi), b_data(&check->bi), expect->string, expect->length) != NULL;
|
match = my_memmem(b_head(&check->bi), b_data(&check->bi), expect->data.ptr, istlen(expect->data)) != NULL;
|
||||||
break;
|
break;
|
||||||
case TCPCHK_EXPECT_REGEX:
|
case TCPCHK_EXPECT_REGEX:
|
||||||
if (expect->with_capture)
|
if (expect->with_capture)
|
||||||
@ -3506,7 +3507,7 @@ static void free_tcpcheck(struct tcpcheck_rule *rule, int in_pool)
|
|||||||
switch (rule->expect.type) {
|
switch (rule->expect.type) {
|
||||||
case TCPCHK_EXPECT_STRING:
|
case TCPCHK_EXPECT_STRING:
|
||||||
case TCPCHK_EXPECT_BINARY:
|
case TCPCHK_EXPECT_BINARY:
|
||||||
free(rule->expect.string);
|
free(rule->expect.data.ptr);
|
||||||
break;
|
break;
|
||||||
case TCPCHK_EXPECT_REGEX:
|
case TCPCHK_EXPECT_REGEX:
|
||||||
case TCPCHK_EXPECT_REGEX_BINARY:
|
case TCPCHK_EXPECT_REGEX_BINARY:
|
||||||
@ -3757,12 +3758,11 @@ static int add_tcpcheck_expect_str(struct tcpcheck_rules *rules, const char *str
|
|||||||
expect->ok_status = HCHK_STATUS_L7OKD;
|
expect->ok_status = HCHK_STATUS_L7OKD;
|
||||||
expect->err_status = HCHK_STATUS_L7RSP;
|
expect->err_status = HCHK_STATUS_L7RSP;
|
||||||
expect->tout_status = HCHK_STATUS_L7TOUT;
|
expect->tout_status = HCHK_STATUS_L7TOUT;
|
||||||
expect->string = strdup(str);
|
expect->data = ist2(strdup(str), strlen(str));
|
||||||
if (!expect->string) {
|
if (!expect->data.ptr) {
|
||||||
pool_free(pool_head_tcpcheck_rule, tcpcheck);
|
pool_free(pool_head_tcpcheck_rule, tcpcheck);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
expect->length = strlen(expect->string);
|
|
||||||
|
|
||||||
/* All tcp-check expect points back to the first inverse expect rule
|
/* All tcp-check expect points back to the first inverse expect rule
|
||||||
* in a chain of one or more expect rule, potentially itself.
|
* in a chain of one or more expect rule, potentially itself.
|
||||||
@ -4994,15 +4994,14 @@ static struct tcpcheck_rule *parse_tcpcheck_expect(char **args, int cur_arg, str
|
|||||||
|
|
||||||
switch (chk->expect.type) {
|
switch (chk->expect.type) {
|
||||||
case TCPCHK_EXPECT_STRING:
|
case TCPCHK_EXPECT_STRING:
|
||||||
chk->expect.string = strdup(pattern);
|
chk->expect.data = ist2(strdup(pattern), strlen(pattern));
|
||||||
chk->expect.length = strlen(pattern);
|
if (!chk->expect.data.ptr) {
|
||||||
if (!chk->expect.string) {
|
|
||||||
memprintf(errmsg, "out of memory");
|
memprintf(errmsg, "out of memory");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TCPCHK_EXPECT_BINARY:
|
case TCPCHK_EXPECT_BINARY:
|
||||||
if (parse_binary(pattern, &chk->expect.string, &chk->expect.length, errmsg) == 0) {
|
if (parse_binary(pattern, &chk->expect.data.ptr, (int *)&chk->expect.data.len, errmsg) == 0) {
|
||||||
memprintf(errmsg, "invalid binary string (%s)", *errmsg);
|
memprintf(errmsg, "invalid binary string (%s)", *errmsg);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user