MEDIUM: sample: Remove types SMP_T_CSTR and SMP_T_CBIN, replace it by SMP_F_CONST flags

The operations applied on types SMP_T_CSTR and SMP_T_STR are the same,
but the check code and the declarations are double, because it must
declare action for SMP_T_C* and SMP_T_*. The declared actions and checks
are the same. this complexify the code. Only the "conv" functions can
change from "C*" to "*"

Now, if a function needs to modify input string, it can call the new
function smp_dup(). This one duplicate data in a trash buffer.
diff --git a/include/proto/sample.h b/include/proto/sample.h
index db703ef..d78e82d 100644
--- a/include/proto/sample.h
+++ b/include/proto/sample.h
@@ -43,6 +43,7 @@
 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
diff --git a/include/types/sample.h b/include/types/sample.h
index 46bc75b..0f189fd 100644
--- a/include/types/sample.h
+++ b/include/types/sample.h
@@ -40,8 +40,6 @@
 	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 */
 };
 
@@ -203,6 +201,7 @@
 	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 */
diff --git a/src/compression.c b/src/compression.c
index f42f771..3c53a07 100644
--- a/src/compression.c
+++ b/src/compression.c
@@ -628,7 +628,8 @@
 	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;
diff --git a/src/dumpstats.c b/src/dumpstats.c
index 31b59f4..0b30585 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -4845,7 +4845,8 @@
 			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;
@@ -4935,8 +4936,8 @@
 			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
diff --git a/src/map.c b/src/map.c
index 52f077d..e48408a 100644
--- a/src/map.c
+++ b/src/map.c
@@ -61,15 +61,16 @@
 
 /* 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;
 }
 
@@ -472,6 +473,7 @@
 
 	/* copy new data */
 	smp->type = sample->type;
+	smp->flags |= SMP_F_CONST;
 	memcpy(&smp->data, &sample->data, sizeof(smp->data));
 	return 1;
 }
diff --git a/src/pattern.c b/src/pattern.c
index fa3b7c5..d41e086 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -94,15 +94,15 @@
 	[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,
 };
 
 /*
@@ -202,8 +202,8 @@
 /* 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;
@@ -214,8 +214,8 @@
 {
 	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;
@@ -238,7 +238,7 @@
 	pattern->ptr.reg->regstr = (char *)text;
 	pattern->freeptrbuf = NULL;
 
-	pattern->expect_type = SMP_T_CSTR;
+	pattern->expect_type = SMP_T_STR;
 	return 1;
 }
 
@@ -328,7 +328,7 @@
 	int ret;
 
 	ret = pat_parse_int(text, pattern, err);
-	pattern->expect_type = SMP_T_CSTR;
+	pattern->expect_type = SMP_T_STR;
 	return ret;
 }
 
@@ -933,7 +933,7 @@
 	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;
@@ -1149,7 +1149,6 @@
 	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;
diff --git a/src/payload.c b/src/payload.c
index d9d66f9..4bfd277 100644
--- a/src/payload.c
+++ b/src/payload.c
@@ -375,10 +375,10 @@
 			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;
 			}
 		}
@@ -410,8 +410,8 @@
 	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)
@@ -478,11 +478,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;
 }
@@ -566,13 +566,13 @@
 		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;
 }
 
@@ -603,16 +603,16 @@
 		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;
 }
 
@@ -650,27 +650,27 @@
  * 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 */ },
diff --git a/src/proto_http.c b/src/proto_http.c
index 7c0c915..eca5a33 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -8990,7 +8990,7 @@
 			return 0;
 		}
 		pattern->ptr.str = trash->str;
-		pattern->expect_type = SMP_T_CSTR;
+		pattern->expect_type = SMP_T_STR;
 		pattern->len = len;
 	}
 	else
@@ -9016,17 +9016,19 @@
 	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;
 }
 
@@ -9075,11 +9077,11 @@
 	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;
 }
 
@@ -9103,11 +9105,11 @@
 	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;
 }
 
@@ -9143,10 +9145,10 @@
 
 	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;
 }
 
@@ -9238,8 +9240,8 @@
 		/* 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;
 
@@ -9326,8 +9328,8 @@
 		/* 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;
 
@@ -9434,14 +9436,14 @@
 		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;
 }
 
@@ -9652,7 +9654,8 @@
 	/* 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);
 
@@ -9773,7 +9776,8 @@
 	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]);
 
@@ -9799,7 +9803,8 @@
 	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]);
 
@@ -9827,7 +9832,8 @@
 	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;
 
@@ -9864,7 +9870,8 @@
 
 	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;
 }
@@ -9948,7 +9955,8 @@
 			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,
@@ -10024,7 +10032,8 @@
 			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,
@@ -10171,8 +10180,8 @@
                                  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;
 }
 
@@ -10424,23 +10433,23 @@
 /************************************************************************/
 /* 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 },
 
@@ -10448,73 +10457,73 @@
 	 * 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 */ },
 }};
diff --git a/src/sample.c b/src/sample.c
index 7568d27..e6653fa 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -38,8 +38,6 @@
 	[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 */
@@ -425,6 +423,7 @@
 	trash->len = strlen(trash->str);
 	smp->data.str = *trash;
 	smp->type = SMP_T_STR;
+	smp->flags &= ~SMP_F_CONST;
 
 	return 1;
 }
@@ -446,6 +445,7 @@
 	trash->len = strlen(trash->str);
 	smp->data.str = *trash;
 	smp->type = SMP_T_STR;
+	smp->flags &= ~SMP_F_CONST;
 	return 1;
 }
 
@@ -469,9 +469,11 @@
 		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;
 }
 
@@ -480,6 +482,7 @@
 	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;
 }
 
@@ -488,6 +491,7 @@
 	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;
 }
 
@@ -511,6 +515,7 @@
 	trash->str[ptr] = 0;
 	smp->data.str = *trash;
 	smp->type = SMP_T_STR;
+	smp->flags &= ~SMP_F_CONST;
 	return 1;
 }
 
@@ -529,36 +534,48 @@
 	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;
@@ -586,6 +603,7 @@
 
 	smp->data.uint = ret;
 	smp->type = SMP_T_UINT;
+	smp->flags &= ~SMP_F_CONST;
 	return 1;
 }
 
@@ -596,17 +614,15 @@
 /*****************************************************************/
 
 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, },
 };
 
 /*
@@ -1094,13 +1110,13 @@
 	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;
 }
 
@@ -1123,6 +1139,7 @@
 	}
 	smp->data.str = *trash;
 	smp->type = SMP_T_STR;
+	smp->flags &= ~SMP_F_CONST;
 	return 1;
 }
 
@@ -1130,6 +1147,9 @@
 {
 	int i;
 
+	if (!smp_dup(smp))
+		return 0;
+
 	if (!smp->data.str.size)
 		return 0;
 
@@ -1137,7 +1157,6 @@
 		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;
 }
 
@@ -1145,6 +1164,9 @@
 {
 	int i;
 
+	if (!smp_dup(smp))
+		return 0;
+
 	if (!smp->data.str.size)
 		return 0;
 
@@ -1152,7 +1174,6 @@
 		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;
 }
 
@@ -1202,7 +1223,8 @@
 	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;
@@ -1252,7 +1274,7 @@
 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 */ },
diff --git a/src/ssl_sock.c b/src/ssl_sock.c
index 188c1e3..e6a341e 100644
--- a/src/ssl_sock.c
+++ b/src/ssl_sock.c
@@ -2192,7 +2192,8 @@
 		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);
 
@@ -2233,7 +2234,8 @@
 		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);
 
@@ -2442,7 +2444,8 @@
 	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;
@@ -2479,7 +2482,8 @@
 	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;
@@ -2610,7 +2614,8 @@
 	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;
@@ -2670,8 +2675,8 @@
 {
 	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;
@@ -2698,8 +2703,8 @@
 {
 	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;
@@ -2738,7 +2743,8 @@
 	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;
@@ -2752,8 +2758,8 @@
 	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;
@@ -2783,8 +2789,8 @@
 #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;
@@ -3520,19 +3526,19 @@
 	{ "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 },
 }};
 
diff --git a/src/stick_table.c b/src/stick_table.c
index 92c4dd4..c6463ec 100644
--- a/src/stick_table.c
+++ b/src/stick_table.c
@@ -594,8 +594,6 @@
 /*             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 },
 };