int smp_resolve_args(struct proxy *p);
int smp_expr_output_type(struct sample_expr *expr);
int c_none(struct sample *smp);
+int smp_dup(struct sample *smp);
/*
* This function just apply a cast on sample. It returns 0 if the cast is not
SMP_T_IPV6, /* ipv6 type */
SMP_T_STR, /* char string type */
SMP_T_BIN, /* buffer type */
- SMP_T_CSTR, /* constant char string type, data need dup before conversion */
- SMP_T_CBIN, /* constant buffer type, data need dup before conversion */
SMP_TYPES /* number of types, must always be last */
};
SMP_F_VOL_TXN = 1 << 5, /* result sensitive to new transaction (eg: HTTP version) */
SMP_F_VOL_SESS = 1 << 6, /* result sensitive to new session (eg: src IP) */
SMP_F_VOLATILE = (1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6), /* any volatility condition */
+ SMP_F_CONST = 1 << 7, /* This sample use constant memory. May diplicate it before changes */
};
/* needed below */
if (!l4->comp_algo)
return 0;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags = SMP_F_CONST;
smp->data.str.str = l4->comp_algo->name;
smp->data.str.len = l4->comp_algo->name_len;
return 1;
chunk_reset(&trash);
/* execute pattern matching */
- sample.type = SMP_T_CSTR;
+ sample.type = SMP_T_STR;
+ sample.flags |= SMP_F_CONST;
sample.data.str.len = appctx->ctx.map.chunk.len;
sample.data.str.str = appctx->ctx.map.chunk.str;
pat = NULL;
else {
memcpy(&sample.data, &smp->data, sizeof(sample.data));
sample.type = smp->type;
- if (sample_casts[sample.type][SMP_T_CSTR] &&
- sample_casts[sample.type][SMP_T_CSTR](&sample))
+ if (sample_casts[sample.type][SMP_T_STR] &&
+ sample_casts[sample.type][SMP_T_STR](&sample))
chunk_appendf(&trash, "return=\"%s\", type=\"%s\"\n",
sample.data.str.str, smp_to_type[smp->type]);
else
/* Parse a string and store a pointer to it into the sample. The original
* string must be left in memory because we return a direct memory reference.
- * The output type is CSTR.
+ * The output type is SMP_T_STR. There is no risk that the data will be
+ * overwritten because sample_conv_map() makes a const sample with this
+ * output.
*/
int map_parse_str(const char *text, struct sample_storage *smp)
{
- /* The loose of the "const" is balanced by the SMP_T_CSTR type */
smp->data.str.str = (char *)text;
smp->data.str.len = strlen(text);
smp->data.str.size = smp->data.str.len + 1;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
return 1;
}
/* copy new data */
smp->type = sample->type;
+ smp->flags |= SMP_F_CONST;
memcpy(&smp->data, &sample->data, sizeof(smp->data));
return 1;
}
[PAT_MATCH_BOOL] = SMP_T_UINT,
[PAT_MATCH_INT] = SMP_T_UINT,
[PAT_MATCH_IP] = SMP_T_ADDR,
- [PAT_MATCH_BIN] = SMP_T_CBIN,
- [PAT_MATCH_LEN] = SMP_T_CSTR,
- [PAT_MATCH_STR] = SMP_T_CSTR,
- [PAT_MATCH_BEG] = SMP_T_CSTR,
- [PAT_MATCH_SUB] = SMP_T_CSTR,
- [PAT_MATCH_DIR] = SMP_T_CSTR,
- [PAT_MATCH_DOM] = SMP_T_CSTR,
- [PAT_MATCH_END] = SMP_T_CSTR,
- [PAT_MATCH_REG] = SMP_T_CSTR,
+ [PAT_MATCH_BIN] = SMP_T_BIN,
+ [PAT_MATCH_LEN] = SMP_T_STR,
+ [PAT_MATCH_STR] = SMP_T_STR,
+ [PAT_MATCH_BEG] = SMP_T_STR,
+ [PAT_MATCH_SUB] = SMP_T_STR,
+ [PAT_MATCH_DIR] = SMP_T_STR,
+ [PAT_MATCH_DOM] = SMP_T_STR,
+ [PAT_MATCH_END] = SMP_T_STR,
+ [PAT_MATCH_REG] = SMP_T_STR,
};
/*
/* Parse a string. It is allocated and duplicated. */
int pat_parse_str(const char *text, struct pattern *pattern, char **err)
{
- pattern->type = SMP_T_CSTR;
- pattern->expect_type = SMP_T_CSTR;
+ pattern->type = SMP_T_STR;
+ pattern->expect_type = SMP_T_STR;
pattern->ptr.str = (char *)text;
pattern->len = strlen(text);
return 1;
{
struct chunk *trash;
- pattern->type = SMP_T_CBIN;
- pattern->expect_type = SMP_T_CBIN;
+ pattern->type = SMP_T_BIN;
+ pattern->expect_type = SMP_T_BIN;
trash = get_trash_chunk();
pattern->len = trash->size;
pattern->ptr.str = trash->str;
pattern->ptr.reg->regstr = (char *)text;
pattern->freeptrbuf = NULL;
- pattern->expect_type = SMP_T_CSTR;
+ pattern->expect_type = SMP_T_STR;
return 1;
}
int ret;
ret = pat_parse_int(text, pattern, err);
- pattern->expect_type = SMP_T_CSTR;
+ pattern->expect_type = SMP_T_STR;
return ret;
}
struct pattern_tree *node;
/* Only string can be indexed */
- if (pat->type != SMP_T_CSTR && pat->type != SMP_T_STR) {
+ if (pat->type != SMP_T_STR) {
memprintf(err, "internal error: string expected, but the type is '%s'",
smp_to_type[pat->type]);
return 0;
if (!eb_is_empty(&expr->pattern_tree) && pattern.type != SMP_T_IPV6) {
/* Check the pattern type */
if (pattern.type != SMP_T_STR &&
- pattern.type != SMP_T_CSTR &&
pattern.type != SMP_T_IPV4) {
memprintf(err, "Unexpected pattern type.");
return 0;
name_len = (data[7] << 8) + data[8];
if (name_type == 0) { /* hostname */
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
smp->data.str.str = (char *)data + 9;
smp->data.str.len = name_len;
- smp->flags = SMP_F_VOLATILE;
+ smp->flags = SMP_F_VOLATILE | SMP_F_CONST;
return 1;
}
}
if (!s || !s->req)
return 0;
- smp->flags = 0;
- smp->type = SMP_T_CSTR;
+ smp->flags = SMP_F_CONST;
+ smp->type = SMP_T_STR;
bleft = s->req->buf->i;
if (bleft <= 11)
goto not_cookie;
smp->data.str.len = (char *)data - smp->data.str.str;
- smp->flags = SMP_F_VOLATILE;
+ smp->flags = SMP_F_VOLATILE | SMP_F_CONST;
return 1;
too_short:
- smp->flags = SMP_F_MAY_CHANGE;
+ smp->flags = SMP_F_MAY_CHANGE | SMP_F_CONST;
not_cookie:
return 0;
}
goto too_short;
/* init chunk as read only */
- smp->type = SMP_T_CBIN;
+ smp->type = SMP_T_BIN;
+ smp->flags = SMP_F_VOLATILE | SMP_F_CONST;
chunk_initlen(&smp->data.str, chn->buf->p + buf_offset, 0, buf_size);
- smp->flags = SMP_F_VOLATILE;
return 1;
too_short:
- smp->flags = SMP_F_MAY_CHANGE;
+ smp->flags = SMP_F_MAY_CHANGE | SMP_F_CONST;
return 0;
}
goto too_short;
/* init chunk as read only */
- smp->type = SMP_T_CBIN;
+ smp->type = SMP_T_BIN;
+ smp->flags = SMP_F_VOLATILE | SMP_F_CONST;
chunk_initlen(&smp->data.str, chn->buf->p + buf_offset, 0, buf_size ? buf_size : (chn->buf->i - buf_offset));
- smp->flags = SMP_F_VOLATILE;
if (!buf_size && !channel_full(chn) && !channel_input_closed(chn))
smp->flags |= SMP_F_MAY_CHANGE;
return 1;
too_short:
- smp->flags = SMP_F_MAY_CHANGE;
+ smp->flags = SMP_F_MAY_CHANGE | SMP_F_CONST;
return 0;
}
* instance IPv4/IPv6 must be declared IPv4.
*/
static struct sample_fetch_kw_list smp_kws = {ILH, {
- { "payload", smp_fetch_payload, ARG2(2,UINT,UINT), NULL, SMP_T_CBIN, SMP_USE_L6REQ|SMP_USE_L6RES },
- { "payload_lv", smp_fetch_payload_lv, ARG3(2,UINT,UINT,SINT), val_payload_lv, SMP_T_CBIN, SMP_USE_L6REQ|SMP_USE_L6RES },
- { "rdp_cookie", smp_fetch_rdp_cookie, ARG1(0,STR), NULL, SMP_T_CSTR, SMP_USE_L6REQ },
+ { "payload", smp_fetch_payload, ARG2(2,UINT,UINT), NULL, SMP_T_BIN, SMP_USE_L6REQ|SMP_USE_L6RES },
+ { "payload_lv", smp_fetch_payload_lv, ARG3(2,UINT,UINT,SINT), val_payload_lv, SMP_T_BIN, SMP_USE_L6REQ|SMP_USE_L6RES },
+ { "rdp_cookie", smp_fetch_rdp_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_L6REQ },
{ "rdp_cookie_cnt", smp_fetch_rdp_cookie_cnt, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_L6REQ },
{ "rep_ssl_hello_type", smp_fetch_ssl_hello_type, 0, NULL, SMP_T_UINT, SMP_USE_L6RES },
{ "req_len", smp_fetch_len, 0, NULL, SMP_T_UINT, SMP_USE_L6REQ },
{ "req_ssl_hello_type", smp_fetch_ssl_hello_type, 0, NULL, SMP_T_UINT, SMP_USE_L6REQ },
- { "req_ssl_sni", smp_fetch_ssl_hello_sni, 0, NULL, SMP_T_CSTR, SMP_USE_L6REQ },
+ { "req_ssl_sni", smp_fetch_ssl_hello_sni, 0, NULL, SMP_T_STR, SMP_USE_L6REQ },
{ "req_ssl_ver", smp_fetch_req_ssl_ver, 0, NULL, SMP_T_UINT, SMP_USE_L6REQ },
{ "req.len", smp_fetch_len, 0, NULL, SMP_T_UINT, SMP_USE_L6REQ },
- { "req.payload", smp_fetch_payload, ARG2(2,UINT,UINT), NULL, SMP_T_CBIN, SMP_USE_L6REQ },
- { "req.payload_lv", smp_fetch_payload_lv, ARG3(2,UINT,UINT,SINT), val_payload_lv, SMP_T_CBIN, SMP_USE_L6REQ },
- { "req.rdp_cookie", smp_fetch_rdp_cookie, ARG1(0,STR), NULL, SMP_T_CSTR, SMP_USE_L6REQ },
+ { "req.payload", smp_fetch_payload, ARG2(2,UINT,UINT), NULL, SMP_T_BIN, SMP_USE_L6REQ },
+ { "req.payload_lv", smp_fetch_payload_lv, ARG3(2,UINT,UINT,SINT), val_payload_lv, SMP_T_BIN, SMP_USE_L6REQ },
+ { "req.rdp_cookie", smp_fetch_rdp_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_L6REQ },
{ "req.rdp_cookie_cnt", smp_fetch_rdp_cookie_cnt, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_L6REQ },
{ "req.ssl_hello_type", smp_fetch_ssl_hello_type, 0, NULL, SMP_T_UINT, SMP_USE_L6REQ },
- { "req.ssl_sni", smp_fetch_ssl_hello_sni, 0, NULL, SMP_T_CSTR, SMP_USE_L6REQ },
+ { "req.ssl_sni", smp_fetch_ssl_hello_sni, 0, NULL, SMP_T_STR, SMP_USE_L6REQ },
{ "req.ssl_ver", smp_fetch_req_ssl_ver, 0, NULL, SMP_T_UINT, SMP_USE_L6REQ },
{ "res.len", smp_fetch_len, 0, NULL, SMP_T_UINT, SMP_USE_L6RES },
- { "res.payload", smp_fetch_payload, ARG2(2,UINT,UINT), NULL, SMP_T_CBIN, SMP_USE_L6RES },
- { "res.payload_lv", smp_fetch_payload_lv, ARG3(2,UINT,UINT,SINT), val_payload_lv, SMP_T_CBIN, SMP_USE_L6RES },
+ { "res.payload", smp_fetch_payload, ARG2(2,UINT,UINT), NULL, SMP_T_BIN, SMP_USE_L6RES },
+ { "res.payload_lv", smp_fetch_payload_lv, ARG3(2,UINT,UINT,SINT), val_payload_lv, SMP_T_BIN, SMP_USE_L6RES },
{ "res.ssl_hello_type", smp_fetch_ssl_hello_type, 0, NULL, SMP_T_UINT, SMP_USE_L6RES },
{ "wait_end", smp_fetch_wait_end, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN },
{ /* END */ },
return 0;
}
pattern->ptr.str = trash->str;
- pattern->expect_type = SMP_T_CSTR;
+ pattern->expect_type = SMP_T_STR;
pattern->len = len;
}
else
CHECK_HTTP_MESSAGE_FIRST_PERM();
meth = txn->meth;
+ smp->flags = 0;
smp->type = SMP_T_UINT;
smp->data.uint = meth;
if (meth == HTTP_METH_OTHER) {
if (txn->rsp.msg_state != HTTP_MSG_RPBEFORE)
/* ensure the indexes are not affected */
return 0;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags |= SMP_F_CONST;
smp->data.str.len = txn->req.sl.rq.m_l;
smp->data.str.str = txn->req.chn->buf->p;
}
- smp->flags = SMP_F_VOL_1ST;
+ smp->flags |= SMP_F_VOL_1ST;
return 1;
}
if (len <= 0)
return 0;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
smp->data.str.str = ptr;
smp->data.str.len = len;
- smp->flags = SMP_F_VOL_1ST;
+ smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
return 1;
}
if (len <= 0)
return 0;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
smp->data.str.str = ptr;
smp->data.str.len = len;
- smp->flags = SMP_F_VOL_1ST;
+ smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
return 1;
}
CHECK_HTTP_MESSAGE_FIRST();
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
smp->data.str.len = txn->req.sl.rq.u_l;
smp->data.str.str = txn->req.chn->buf->p + txn->req.sl.rq.u;
- smp->flags = SMP_F_VOL_1ST;
+ smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
return 1;
}
/* prepare to report multiple occurrences for ACL fetches */
smp->flags |= SMP_F_NOT_LAST;
- smp->type = SMP_T_CSTR;
- smp->flags |= SMP_F_VOL_HDR;
+ smp->type = SMP_T_STR;
+ smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST;
if (http_get_fhdr(msg, name_str, name_len, idx, occ, ctx, &smp->data.str.str, &smp->data.str.len))
return 1;
/* prepare to report multiple occurrences for ACL fetches */
smp->flags |= SMP_F_NOT_LAST;
- smp->type = SMP_T_CSTR;
- smp->flags |= SMP_F_VOL_HDR;
+ smp->type = SMP_T_STR;
+ smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST;
if (http_get_hdr(msg, name_str, name_len, idx, occ, ctx, &smp->data.str.str, &smp->data.str.len))
return 1;
return 0;
/* OK, we got the '/' ! */
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
smp->data.str.str = ptr;
while (ptr < end && *ptr != '?')
ptr++;
smp->data.str.len = ptr - smp->data.str.str;
- smp->flags = SMP_F_VOL_1ST;
+ smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
return 1;
}
/* pat_match_auth() will need the user list */
smp->ctx.a[0] = args->data.usr;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags = SMP_F_CONST;
smp->data.str.str = l4->txn.auth.user;
smp->data.str.len = strlen(l4->txn.auth.user);
if (idx > (fe->nb_req_cap - 1) || txn->req.cap == NULL || txn->req.cap[idx] == NULL)
return 0;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags |= SMP_F_CONST;
smp->data.str.str = txn->req.cap[idx];
smp->data.str.len = strlen(txn->req.cap[idx]);
if (idx > (fe->nb_rsp_cap - 1) || txn->rsp.cap == NULL || txn->rsp.cap[idx] == NULL)
return 0;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags |= SMP_F_CONST;
smp->data.str.str = txn->rsp.cap[idx];
smp->data.str.len = strlen(txn->rsp.cap[idx]);
temp->str = txn->uri;
temp->len = ptr - txn->uri;
smp->data.str = *temp;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags = SMP_F_CONST;
return 1;
smp->data.str = *temp;
smp->data.str.len = ptr - temp->str;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags = SMP_F_CONST;
return 1;
}
smp->ctx.a[1] = smp->ctx.a[0] + ctx->vlen;
}
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags |= SMP_F_CONST;
smp->ctx.a[0] = extract_cookie_value(smp->ctx.a[0], smp->ctx.a[1],
args->data.str.str, args->data.str.len,
(opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ,
val_end = val_beg + ctx.vlen;
}
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags |= SMP_F_CONST;
while ((val_beg = extract_cookie_value(val_beg, val_end,
args->data.str.str, args->data.str.len,
(opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ,
delim))
return 0;
- smp->type = SMP_T_CSTR;
- smp->flags = SMP_F_VOL_1ST;
+ smp->type = SMP_T_STR;
+ smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
return 1;
}
/************************************************************************/
/* Note: must not be declared <const> as its list will be overwritten */
static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
- { "base", smp_fetch_base, 0, NULL, SMP_T_CSTR, SMP_USE_HRQHV },
+ { "base", smp_fetch_base, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
{ "base32", smp_fetch_base32, 0, NULL, SMP_T_UINT, SMP_USE_HRQHV },
{ "base32+src", smp_fetch_base32_src, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
- { "capture.req.uri", smp_fetch_capture_req_uri, 0, NULL, SMP_T_CSTR, SMP_USE_HRQHP },
- { "capture.req.method", smp_fetch_capture_req_method, 0, NULL, SMP_T_CSTR, SMP_USE_HRQHP },
+ { "capture.req.uri", smp_fetch_capture_req_uri, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
+ { "capture.req.method", smp_fetch_capture_req_method, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
/* capture are allocated and are permanent in the session */
- { "capture.req.hdr", smp_fetch_capture_header_req, ARG1(1, UINT), NULL, SMP_T_CSTR, SMP_USE_HRQHP },
- { "capture.res.hdr", smp_fetch_capture_header_res, ARG1(1, UINT), NULL, SMP_T_CSTR, SMP_USE_HRSHP },
+ { "capture.req.hdr", smp_fetch_capture_header_req, ARG1(1, UINT), NULL, SMP_T_STR, SMP_USE_HRQHP },
+ { "capture.res.hdr", smp_fetch_capture_header_res, ARG1(1, UINT), NULL, SMP_T_STR, SMP_USE_HRSHP },
/* cookie is valid in both directions (eg: for "stick ...") but cook*
* are only here to match the ACL's name, are request-only and are used
* for ACL compatibility only.
*/
- { "cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_CSTR, SMP_USE_HRQHV },
- { "cookie", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_CSTR, SMP_USE_HRQHV|SMP_USE_HRSHV },
+ { "cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
+ { "cookie", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV },
{ "cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRQHV },
{ "cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRQHV },
* only here to match the ACL's name, are request-only and are used for
* ACL compatibility only.
*/
- { "hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_CSTR, SMP_USE_HRQHV|SMP_USE_HRSHV },
+ { "hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV },
{ "hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRQHV },
{ "hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRQHV },
{ "hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_UINT, SMP_USE_HRQHV },
{ "http_auth", smp_fetch_http_auth, ARG1(1,USR), NULL, SMP_T_BOOL, SMP_USE_HRQHV },
- { "http_auth_group", smp_fetch_http_auth_grp, ARG1(1,USR), NULL, SMP_T_CSTR, SMP_USE_HRQHV },
+ { "http_auth_group", smp_fetch_http_auth_grp, ARG1(1,USR), NULL, SMP_T_STR, SMP_USE_HRQHV },
{ "http_first_req", smp_fetch_http_first_req, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP },
{ "method", smp_fetch_meth, 0, NULL, SMP_T_UINT, SMP_USE_HRQHP },
- { "path", smp_fetch_path, 0, NULL, SMP_T_CSTR, SMP_USE_HRQHV },
+ { "path", smp_fetch_path, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
/* HTTP protocol on the request path */
{ "req.proto_http", smp_fetch_proto_http, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP },
{ "req_proto_http", smp_fetch_proto_http, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP },
/* HTTP version on the request path */
- { "req.ver", smp_fetch_rqver, 0, NULL, SMP_T_CSTR, SMP_USE_HRQHV },
- { "req_ver", smp_fetch_rqver, 0, NULL, SMP_T_CSTR, SMP_USE_HRQHV },
+ { "req.ver", smp_fetch_rqver, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
+ { "req_ver", smp_fetch_rqver, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
/* HTTP version on the response path */
- { "res.ver", smp_fetch_stver, 0, NULL, SMP_T_CSTR, SMP_USE_HRSHV },
- { "resp_ver", smp_fetch_stver, 0, NULL, SMP_T_CSTR, SMP_USE_HRSHV },
+ { "res.ver", smp_fetch_stver, 0, NULL, SMP_T_STR, SMP_USE_HRSHV },
+ { "resp_ver", smp_fetch_stver, 0, NULL, SMP_T_STR, SMP_USE_HRSHV },
/* explicit req.{cook,hdr} are used to force the fetch direction to be request-only */
- { "req.cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_CSTR, SMP_USE_HRQHV },
+ { "req.cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
{ "req.cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRQHV },
{ "req.cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRQHV },
- { "req.fhdr", smp_fetch_fhdr, ARG2(0,STR,SINT), val_hdr, SMP_T_CSTR, SMP_USE_HRQHV },
+ { "req.fhdr", smp_fetch_fhdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV },
{ "req.fhdr_cnt", smp_fetch_fhdr_cnt, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRQHV },
- { "req.hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_CSTR, SMP_USE_HRQHV },
+ { "req.hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV },
{ "req.hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRQHV },
{ "req.hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRQHV },
{ "req.hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_UINT, SMP_USE_HRQHV },
/* explicit req.{cook,hdr} are used to force the fetch direction to be response-only */
- { "res.cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_CSTR, SMP_USE_HRSHV },
+ { "res.cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV },
{ "res.cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRSHV },
{ "res.cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRSHV },
- { "res.fhdr", smp_fetch_fhdr, ARG2(0,STR,SINT), val_hdr, SMP_T_CSTR, SMP_USE_HRSHV },
+ { "res.fhdr", smp_fetch_fhdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV },
{ "res.fhdr_cnt", smp_fetch_fhdr_cnt, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRSHV },
- { "res.hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_CSTR, SMP_USE_HRSHV },
+ { "res.hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV },
{ "res.hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRSHV },
{ "res.hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRSHV },
{ "res.hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_UINT, SMP_USE_HRSHV },
/* scook is valid only on the response and is used for ACL compatibility */
- { "scook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_CSTR, SMP_USE_HRSHV },
+ { "scook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV },
{ "scook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRSHV },
{ "scook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRSHV },
- { "set-cookie", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_CSTR, SMP_USE_HRSHV }, /* deprecated */
+ { "set-cookie", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV }, /* deprecated */
/* shdr is valid only on the response and is used for ACL compatibility */
- { "shdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_CSTR, SMP_USE_HRSHV },
+ { "shdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV },
{ "shdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_UINT, SMP_USE_HRSHV },
{ "shdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRSHV },
{ "shdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_UINT, SMP_USE_HRSHV },
{ "status", smp_fetch_stcode, 0, NULL, SMP_T_UINT, SMP_USE_HRSHP },
- { "url", smp_fetch_url, 0, NULL, SMP_T_CSTR, SMP_USE_HRQHV },
+ { "url", smp_fetch_url, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
{ "url32", smp_fetch_url32, 0, NULL, SMP_T_UINT, SMP_USE_HRQHV },
{ "url32+src", smp_fetch_url32_src, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
{ "url_ip", smp_fetch_url_ip, 0, NULL, SMP_T_IPV4, SMP_USE_HRQHV },
{ "url_port", smp_fetch_url_port, 0, NULL, SMP_T_UINT, SMP_USE_HRQHV },
- { "url_param", smp_fetch_url_param, ARG2(1,STR,STR), NULL, SMP_T_CSTR, SMP_USE_HRQHV },
- { "urlp" , smp_fetch_url_param, ARG2(1,STR,STR), NULL, SMP_T_CSTR, SMP_USE_HRQHV },
+ { "url_param", smp_fetch_url_param, ARG2(1,STR,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
+ { "urlp" , smp_fetch_url_param, ARG2(1,STR,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
{ "urlp_val", smp_fetch_url_param_val, ARG2(1,STR,STR), NULL, SMP_T_UINT, SMP_USE_HRQHV },
{ /* END */ },
}};
[SMP_T_IPV6] = "ipv6",
[SMP_T_STR] = "str",
[SMP_T_BIN] = "bin",
- [SMP_T_CSTR] = "cstr",
- [SMP_T_CBIN] = "cbin",
};
/* static sample used in sample_process() when <p> is NULL */
trash->len = strlen(trash->str);
smp->data.str = *trash;
smp->type = SMP_T_STR;
+ smp->flags &= ~SMP_F_CONST;
return 1;
}
trash->len = strlen(trash->str);
smp->data.str = *trash;
smp->type = SMP_T_STR;
+ smp->flags &= ~SMP_F_CONST;
return 1;
}
if (!buf2ip6(smp->data.str.str, smp->data.str.len, &smp->data.ipv6))
return 0;
smp->type = SMP_T_IPV6;
+ smp->flags &= ~SMP_F_CONST;
return 1;
}
smp->type = SMP_T_IPV4;
+ smp->flags &= ~SMP_F_CONST;
return 1;
}
if (!buf2ip(smp->data.str.str, smp->data.str.len, &smp->data.ipv4))
return 0;
smp->type = SMP_T_IPV4;
+ smp->flags &= ~SMP_F_CONST;
return 1;
}
if (!buf2ip6(smp->data.str.str, smp->data.str.len, &smp->data.ipv6))
return 0;
smp->type = SMP_T_IPV6;
+ smp->flags &= ~SMP_F_CONST;
return 1;
}
trash->str[ptr] = 0;
smp->data.str = *trash;
smp->type = SMP_T_STR;
+ smp->flags &= ~SMP_F_CONST;
return 1;
}
trash->len = strlen(pos);
smp->data.str = *trash;
smp->type = SMP_T_STR;
+ smp->flags &= ~SMP_F_CONST;
return 1;
}
-static inline void _c_datadup(struct sample *smp)
+/* This function duplicates data and removes the flag "const". */
+int smp_dup(struct sample *smp)
{
- struct chunk *trash = get_trash_chunk();
+ struct chunk *trash;
- trash->len = smp->data.str.len < trash->size ? smp->data.str.len : trash->size;
- memcpy(trash->str, smp->data.str.str, trash->len);
- smp->data.str = *trash;
-}
+ /* If the const flag is not set, we don't need to duplicate the
+ * pattern as it can be modified in place.
+ */
+ if (!(smp->flags & SMP_F_CONST))
+ return 1;
-static int c_datadup(struct sample *smp)
-{
- _c_datadup(smp);
- if (smp->type == SMP_T_CSTR)
- smp->type = SMP_T_STR;
- else
- smp->type = SMP_T_BIN;
- return 1;
-}
+ switch (smp->type) {
+ case SMP_T_BOOL:
+ case SMP_T_UINT:
+ case SMP_T_SINT:
+ case SMP_T_ADDR:
+ case SMP_T_IPV4:
+ case SMP_T_IPV6:
+ /* These type are not const. */
+ break;
+ case SMP_T_STR:
+ case SMP_T_BIN:
+ /* Duplicate data. */
+ trash = get_trash_chunk();
+ trash->len = smp->data.str.len < trash->size ? smp->data.str.len : trash->size;
+ memcpy(trash->str, smp->data.str.str, trash->len);
+ smp->data.str = *trash;
+ break;
+ default:
+ /* Other cases are unexpected. */
+ return 0;
+ }
-static int c_bindup(struct sample *smp)
-{
- _c_datadup(smp);
- smp->type = SMP_T_BIN;
+ /* remove const flag */
+ smp->flags &= ~SMP_F_CONST;
return 1;
}
-
int c_none(struct sample *smp)
{
return 1;
smp->data.uint = ret;
smp->type = SMP_T_UINT;
+ smp->flags &= ~SMP_F_CONST;
return 1;
}
/*****************************************************************/
sample_cast_fct sample_casts[SMP_TYPES][SMP_TYPES] = {
-/* to: BOOL UINT SINT ADDR IPV4 IPV6 STR BIN CSTR CBIN */
-/* from: BOOL */ { c_none, c_none, c_none, NULL, NULL, NULL, c_int2str, NULL, c_int2str, NULL, },
-/* UINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, NULL, c_int2str, NULL, c_int2str, NULL, },
-/* SINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, NULL, c_int2str, NULL, c_int2str, NULL, },
-/* ADDR */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, },
-/* IPV4 */ { NULL, c_ip2int, c_ip2int, c_none, c_none, c_ip2ipv6, c_ip2str, NULL, c_ip2str, NULL, },
-/* IPV6 */ { NULL, NULL, NULL, c_none, NULL, c_none, c_ipv62str, NULL, c_ipv62str, NULL, },
-/* STR */ { c_str2int, c_str2int, c_str2int, c_str2addr, c_str2ip, c_str2ipv6, c_none, c_none, c_none, c_none, },
-/* BIN */ { NULL, NULL, NULL, NULL, NULL, NULL, c_bin2str, c_none, c_bin2str, c_none, },
-/* CSTR */ { c_str2int, c_str2int, c_str2int, c_str2addr, c_str2ip, c_str2ipv6, c_datadup, c_bindup, c_none, c_none, },
-/* CBIN */ { NULL, NULL, NULL, NULL, NULL, NULL, c_bin2str, c_datadup, c_bin2str, c_none, },
+/* to: BOOL UINT SINT ADDR IPV4 IPV6 STR BIN */
+/* from: BOOL */ { c_none, c_none, c_none, NULL, NULL, NULL, c_int2str, NULL, },
+/* UINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, NULL, c_int2str, NULL, },
+/* SINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, NULL, c_int2str, NULL, },
+/* ADDR */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, },
+/* IPV4 */ { NULL, c_ip2int, c_ip2int, c_none, c_none, c_ip2ipv6, c_ip2str, NULL, },
+/* IPV6 */ { NULL, NULL, NULL, c_none, NULL, c_none, c_ipv62str, NULL, },
+/* STR */ { c_str2int, c_str2int, c_str2int, c_str2addr, c_str2ip, c_str2ipv6, c_none, c_none, },
+/* BIN */ { NULL, NULL, NULL, NULL, NULL, NULL, c_bin2str, c_none, },
};
/*
if (!smp)
return NULL;
- if (!sample_casts[smp->type][SMP_T_CSTR])
+ if (!sample_casts[smp->type][SMP_T_STR])
return NULL;
- if (!sample_casts[smp->type][SMP_T_CSTR](smp))
+ if (!sample_casts[smp->type][SMP_T_STR](smp))
return NULL;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
return smp;
}
}
smp->data.str = *trash;
smp->type = SMP_T_STR;
+ smp->flags &= ~SMP_F_CONST;
return 1;
}
{
int i;
+ if (!smp_dup(smp))
+ return 0;
+
if (!smp->data.str.size)
return 0;
if ((smp->data.str.str[i] >= 'A') && (smp->data.str.str[i] <= 'Z'))
smp->data.str.str[i] += 'a' - 'A';
}
- smp->type = SMP_T_STR;
return 1;
}
{
int i;
+ if (!smp_dup(smp))
+ return 0;
+
if (!smp->data.str.size)
return 0;
if ((smp->data.str.str[i] >= 'a') && (smp->data.str.str[i] <= 'z'))
smp->data.str.str[i] += 'A' - 'a';
}
- smp->type = SMP_T_STR;
return 1;
}
if (!env)
return 0;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags = SMP_F_CONST;
smp->data.str.str = env;
smp->data.str.len = strlen(env);
return 1;
static struct sample_fetch_kw_list smp_kws = {ILH, {
{ "always_false", smp_fetch_false, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN },
{ "always_true", smp_fetch_true, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN },
- { "env", smp_fetch_env, ARG1(1,STR), NULL, SMP_T_CSTR, SMP_USE_INTRN },
+ { "env", smp_fetch_env, ARG1(1,STR), NULL, SMP_T_STR, SMP_USE_INTRN },
{ "date", smp_fetch_date, ARG1(0,SINT), NULL, SMP_T_UINT, SMP_USE_INTRN },
{ "rand", smp_fetch_rand, ARG1(0,UINT), NULL, SMP_T_UINT, SMP_USE_INTRN },
{ /* END */ },
return 0;
}
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags |= SMP_F_CONST;
smp->data.str.len = strlen(smp->data.str.str);
X509_free(crt);
return 0;
}
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags |= SMP_F_CONST;
smp->data.str.len = strlen(smp->data.str.str);
X509_free(crt);
if (!smp->data.str.str)
return 0;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags |= SMP_F_CONST;
smp->data.str.len = strlen(smp->data.str.str);
return 1;
if (!smp->data.str.str)
return 0;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags |= SMP_F_CONST;
smp->data.str.len = strlen(smp->data.str.str);
return 1;
if (!smp->data.str.str)
return 0;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags |= SMP_F_CONST;
smp->data.str.len = strlen(smp->data.str.str);
return 1;
{
struct connection *conn;
- smp->flags = 0;
- smp->type = SMP_T_CSTR;
+ smp->flags = SMP_F_CONST;
+ smp->type = SMP_T_STR;
if (!l4)
return 0;
{
struct connection *conn;
- smp->flags = 0;
- smp->type = SMP_T_CSTR;
+ smp->flags = SMP_F_CONST;
+ smp->type = SMP_T_STR;
if (!l4)
return 0;
if (!smp->data.str.str)
return 0;
- smp->type = SMP_T_CSTR;
+ smp->type = SMP_T_STR;
+ smp->flags = SMP_F_CONST;
smp->data.str.len = strlen(smp->data.str.str);
return 1;
SSL_SESSION *sess;
struct connection *conn;
- smp->flags = 0;
- smp->type = SMP_T_CBIN;
+ smp->flags = SMP_F_CONST;
+ smp->type = SMP_T_BIN;
if (!l4)
return 0;
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
struct connection *conn;
- smp->flags = 0;
- smp->type = SMP_T_CSTR;
+ smp->flags = SMP_F_CONST;
+ smp->type = SMP_T_STR;
if (!l4)
return 0;
{ "ssl_f_version", smp_fetch_ssl_f_version, 0, NULL, SMP_T_UINT, SMP_USE_L5CLI },
{ "ssl_fc", smp_fetch_ssl_fc, 0, NULL, SMP_T_BOOL, SMP_USE_L5CLI },
{ "ssl_fc_alg_keysize", smp_fetch_ssl_fc_alg_keysize, 0, NULL, SMP_T_UINT, SMP_USE_L5CLI },
- { "ssl_fc_cipher", smp_fetch_ssl_fc_cipher, 0, NULL, SMP_T_CSTR, SMP_USE_L5CLI },
+ { "ssl_fc_cipher", smp_fetch_ssl_fc_cipher, 0, NULL, SMP_T_STR, SMP_USE_L5CLI },
{ "ssl_fc_has_crt", smp_fetch_ssl_fc_has_crt, 0, NULL, SMP_T_BOOL, SMP_USE_L5CLI },
{ "ssl_fc_has_sni", smp_fetch_ssl_fc_has_sni, 0, NULL, SMP_T_BOOL, SMP_USE_L5CLI },
#ifdef OPENSSL_NPN_NEGOTIATED
- { "ssl_fc_npn", smp_fetch_ssl_fc_npn, 0, NULL, SMP_T_CSTR, SMP_USE_L5CLI },
+ { "ssl_fc_npn", smp_fetch_ssl_fc_npn, 0, NULL, SMP_T_STR, SMP_USE_L5CLI },
#endif
#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
- { "ssl_fc_alpn", smp_fetch_ssl_fc_alpn, 0, NULL, SMP_T_CSTR, SMP_USE_L5CLI },
+ { "ssl_fc_alpn", smp_fetch_ssl_fc_alpn, 0, NULL, SMP_T_STR, SMP_USE_L5CLI },
#endif
- { "ssl_fc_protocol", smp_fetch_ssl_fc_protocol, 0, NULL, SMP_T_CSTR, SMP_USE_L5CLI },
+ { "ssl_fc_protocol", smp_fetch_ssl_fc_protocol, 0, NULL, SMP_T_STR, SMP_USE_L5CLI },
{ "ssl_fc_use_keysize", smp_fetch_ssl_fc_use_keysize, 0, NULL, SMP_T_UINT, SMP_USE_L5CLI },
- { "ssl_fc_session_id", smp_fetch_ssl_fc_session_id, 0, NULL, SMP_T_CBIN, SMP_USE_L5CLI },
- { "ssl_fc_sni", smp_fetch_ssl_fc_sni, 0, NULL, SMP_T_CSTR, SMP_USE_L5CLI },
+ { "ssl_fc_session_id", smp_fetch_ssl_fc_session_id, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI },
+ { "ssl_fc_sni", smp_fetch_ssl_fc_sni, 0, NULL, SMP_T_STR, SMP_USE_L5CLI },
{ NULL, NULL, 0, 0, 0 },
}};
/* IPV6 */ { k_ip2ip, k_ip2ipv6, k_ip2int, k_ip2str, NULL },
/* STR */ { k_str2ip, k_str2ipv6, k_str2int, k_str2str, k_str2str },
/* BIN */ { NULL, NULL, NULL, k_bin2str, k_str2str },
-/* CSTR */ { k_str2ip, k_str2ipv6, k_str2int, k_str2str, k_str2str },
-/* CBIN */ { NULL, NULL, NULL, k_bin2str, k_str2str },
};