]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: change url_decode to return the size of the decoded string.
authorThierry FOURNIER <tfournier@exceliance.fr>
Fri, 4 Oct 2013 14:27:27 +0000 (16:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 23 Oct 2013 10:26:50 +0000 (12:26 +0200)
Currently url_decode returns 1 or 0 depending on whether it could decode
the string or not. For some future use cases, it will be needed to get the
decoded string length after a successful decoding, so let's make it return
that value, and fall back to a negative one in case of error.

src/proto_http.c
src/standard.c

index 0e9e429c57a51bde73200528fcdefe948220e35d..831eeeb7bd7c031f79b112e49dffc56ebff34533 100644 (file)
@@ -2861,7 +2861,7 @@ int http_process_req_stat_post(struct stream_interface *si, struct http_txn *txn
                                *value++ = '\0';
                        }
 
-                       if (!url_decode(key) || !url_decode(value))
+                       if (url_decode(key) < 0 || url_decode(value) < 0)
                                break;
 
                        /* Now we can check the key to see what to do */
index cd60a94ed1fdb74721b436f141fb8b3259e2f41d..b519f5716c0226ab729ad2abd4350f3e17b23a72 100644 (file)
@@ -1047,13 +1047,13 @@ char *encode_string(char *start, char *stop,
 
 /* Decode an URL-encoded string in-place. The resulting string might
  * be shorter. If some forbidden characters are found, the conversion is
- * aborted, the string is truncated before the issue and non-zero is returned,
- * otherwise the operation returns non-zero indicating success.
+ * aborted, the string is truncated before the issue and a negative value is
+ * returned, otherwise the operation returns the length of the decoded string.
  */
 int url_decode(char *string)
 {
        char *in, *out;
-       int ret = 0;
+       int ret = -1;
 
        in = string;
        out = string;
@@ -1074,7 +1074,7 @@ int url_decode(char *string)
                }
                in++;
        }
-       ret = 1; /* success */
+       ret = out - string; /* success */
  end:
        *out = 0;
        return ret;