BUG/MEDIUM: stick-tables: fix breakage in table converters

Baptiste reported that the table_conn_rate() converter would always
return zero in 1.6.5. In fact, commit bc8c404 ("MAJOR: stick-tables:
use sample types in place of dedicated types") broke all stick-table
converters because smp_to_stkey() now returns a pointer to the sample
instead of holding a copy of the key, and the converters used to
reinitialize the sample prior to performing the lookup. Only
"in_table()" continued to work.

The construct is still fragile, so some comments were added to a few
function to clarify their impacts. It's also worth noting that there
is no point anymore in forcing these converters to take a string on
input, but that will be changed in another commit.

The bug was introduced in 1.6-dev4, this fix must be backported to 1.6.
diff --git a/src/stick_table.c b/src/stick_table.c
index 0d15490..10559f0 100644
--- a/src/stick_table.c
+++ b/src/stick_table.c
@@ -461,6 +461,8 @@
 }
 
 /* Prepares a stktable_key from a sample <smp> to search into table <t>.
+ * Note that the sample *is* modified and that the returned key may point
+ * to it, so the sample must not be modified afterwards before the lookup.
  * Returns NULL if the sample could not be converted (eg: no matching type),
  * otherwise a pointer to the static stktable_key filled with what is needed
  * for the lookup.
@@ -700,11 +702,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -736,11 +739,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -771,11 +775,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -806,11 +811,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -842,11 +848,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -878,11 +885,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -913,11 +921,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -948,11 +957,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -984,11 +994,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -1019,11 +1030,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -1055,11 +1067,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -1090,11 +1103,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -1126,11 +1140,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -1161,11 +1176,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -1196,11 +1212,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -1231,11 +1248,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -1266,11 +1284,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (!ts) /* key not present */
 		return 1;
 
@@ -1301,11 +1320,12 @@
 	if (!key)
 		return 0;
 
+	ts = stktable_lookup_key(t, key);
+
 	smp->flags = SMP_F_VOL_TEST;
 	smp->data.type = SMP_T_SINT;
 	smp->data.u.sint = 0;
 
-	ts = stktable_lookup_key(t, key);
 	if (ts)
 		smp->data.u.sint = ts->ref_cnt;