diff --git a/include/proto/sample.h b/include/proto/sample.h index 02ccc5206..6a01ed330 100644 --- a/include/proto/sample.h +++ b/include/proto/sample.h @@ -33,9 +33,9 @@ struct sample_conv *find_sample_conv(const char *kw, int len); struct sample *sample_process(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, struct sample_expr *expr, struct sample *p); -struct sample *sample_fetch_string(struct proxy *px, struct session *sess, +struct sample *sample_fetch_as_type(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, - struct sample_expr *expr); + struct sample_expr *expr, int smp_type); void sample_register_fetches(struct sample_fetch_kw_list *psl); void sample_register_convs(struct sample_conv_kw_list *psl); const char *sample_src_names(unsigned int use); diff --git a/src/log.c b/src/log.c index f0db0a829..577618cff 100644 --- a/src/log.c +++ b/src/log.c @@ -980,9 +980,9 @@ int build_logline(struct stream *s, char *dst, size_t maxsize, struct list *list case LOG_FMT_EXPR: // sample expression, may be request or response key = NULL; if (tmp->options & LOG_OPT_REQ_CAP) - key = sample_fetch_string(be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, tmp->expr); + key = sample_fetch_as_type(be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, tmp->expr, SMP_T_STR); if (!key && (tmp->options & LOG_OPT_RES_CAP)) - key = sample_fetch_string(be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, tmp->expr); + key = sample_fetch_as_type(be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, tmp->expr, SMP_T_STR); if (tmp->options & LOG_OPT_HTTP) ret = encode_chunk(tmplog, dst + maxsize, '%', http_encode_map, key ? &key->data.str : &empty); diff --git a/src/proto_http.c b/src/proto_http.c index 1c30b3bf4..c24479240 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -12498,7 +12498,7 @@ int http_action_req_capture(struct http_req_rule *rule, struct proxy *px, struct char **cap = s->req_cap; int len; - key = sample_fetch_string(s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, expr); + key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, expr, SMP_T_STR); if (!key) return 1; @@ -12541,7 +12541,7 @@ int http_action_req_capture_by_id(struct http_req_rule *rule, struct proxy *px, if (!h) return 1; - key = sample_fetch_string(s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, expr); + key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, expr, SMP_T_STR); if (!key) return 1; @@ -12710,7 +12710,7 @@ int http_action_res_capture_by_id(struct http_res_rule *rule, struct proxy *px, if (!h) return 1; - key = sample_fetch_string(s->be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, expr); + key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, expr, SMP_T_STR); if (!key) return 1; diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 6d1ec03a9..9f9de9bae 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -1206,7 +1206,7 @@ int tcp_inspect_request(struct stream *s, struct channel *req, int an_bit) char **cap = s->req_cap; int len; - key = sample_fetch_string(s->be, sess, s, SMP_OPT_DIR_REQ | partial, rule->act_prm.cap.expr); + key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_REQ | partial, rule->act_prm.cap.expr, SMP_T_STR); if (!key) continue; diff --git a/src/sample.c b/src/sample.c index 309ea11a2..330f08a53 100644 --- a/src/sample.c +++ b/src/sample.c @@ -1338,8 +1338,9 @@ int smp_resolve_args(struct proxy *p) /* * Process a fetch + format conversion as defined by the sample expression * on request or response considering the parameter. The output is - * always of type string. If a stable sample can be fetched, or an unstable one - * when contains SMP_OPT_FINAL, the sample is converted to a string and + * not explicitly set to , but shall be compatible with it as + * specified by 'sample_casts' table. If a stable sample can be fetched, or an + * unstable one when contains SMP_OPT_FINAL, the sample is converted and * returned without the SMP_F_MAY_CHANGE flag. If an unstable sample is found * and does not contain SMP_OPT_FINAL, then the sample is returned as-is * with its SMP_F_MAY_CHANGE flag so that the caller can check it and decide to @@ -1355,9 +1356,9 @@ int smp_resolve_args(struct proxy *p) * smp 1 0 Not present yet, may appear later (eg: header) * smp 1 1 never happens (either flag is cleared on output) */ -struct sample *sample_fetch_string(struct proxy *px, struct session *sess, +struct sample *sample_fetch_as_type(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, - struct sample_expr *expr) + struct sample_expr *expr, int smp_type) { struct sample *smp = &temp_smp; @@ -1369,13 +1370,12 @@ struct sample *sample_fetch_string(struct proxy *px, struct session *sess, return NULL; } - if (!sample_casts[smp->type][SMP_T_STR]) + if (!sample_casts[smp->type][smp_type]) return NULL; - if (!sample_casts[smp->type][SMP_T_STR](smp)) + if (!sample_casts[smp->type][smp_type](smp)) return NULL; - smp->type = SMP_T_STR; smp->flags &= ~SMP_F_MAY_CHANGE; return smp; }