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.
diff --git a/src/checks.c b/src/checks.c
index 3b3df67..6f46ef3 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -654,10 +654,10 @@
switch (expect->type) {
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;
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;
case TCPCHK_EXPECT_REGEX:
chunk_appendf(chk, " (expect regex)");
@@ -2325,7 +2325,8 @@
chunk_strcat(msg, (match ? "TCPCHK matched unwanted content" : "TCPCHK did not match content"));
switch (rule->expect.type) {
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;
case TCPCHK_EXPECT_BINARY:
chunk_appendf(msg, " (binary) at step %d", tcpcheck_get_step_id(check, rule));
@@ -3113,7 +3114,7 @@
*/
if (!last_read) {
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;
goto out;
}
@@ -3129,7 +3130,7 @@
switch (expect->type) {
case TCPCHK_EXPECT_STRING:
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;
case TCPCHK_EXPECT_REGEX:
if (expect->with_capture)
@@ -3506,7 +3507,7 @@
switch (rule->expect.type) {
case TCPCHK_EXPECT_STRING:
case TCPCHK_EXPECT_BINARY:
- free(rule->expect.string);
+ free(rule->expect.data.ptr);
break;
case TCPCHK_EXPECT_REGEX:
case TCPCHK_EXPECT_REGEX_BINARY:
@@ -3757,12 +3758,11 @@
expect->ok_status = HCHK_STATUS_L7OKD;
expect->err_status = HCHK_STATUS_L7RSP;
expect->tout_status = HCHK_STATUS_L7TOUT;
- expect->string = strdup(str);
- if (!expect->string) {
+ expect->data = ist2(strdup(str), strlen(str));
+ if (!expect->data.ptr) {
pool_free(pool_head_tcpcheck_rule, tcpcheck);
return 0;
}
- expect->length = strlen(expect->string);
/* All tcp-check expect points back to the first inverse expect rule
* in a chain of one or more expect rule, potentially itself.
@@ -4994,15 +4994,14 @@
switch (chk->expect.type) {
case TCPCHK_EXPECT_STRING:
- chk->expect.string = strdup(pattern);
- chk->expect.length = strlen(pattern);
- if (!chk->expect.string) {
+ chk->expect.data = ist2(strdup(pattern), strlen(pattern));
+ if (!chk->expect.data.ptr) {
memprintf(errmsg, "out of memory");
goto error;
}
break;
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);
goto error;
}