]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http_fetch: add case insensitive support for smp_fetch_url_param
authorMartin DOLEZ <martin@dolez.fr>
Tue, 28 Mar 2023 13:06:05 +0000 (09:06 -0400)
committerWilly Tarreau <w@1wt.eu>
Thu, 30 Mar 2023 12:11:10 +0000 (14:11 +0200)
This commit adds a new argument to smp_fetch_url_param
that makes the parameter key comparison case-insensitive.
Several levels of callers were modified to pass this info.

include/haproxy/http.h
src/http.c
src/http_fetch.c

index f597ee4cd1dc13ab9062120ab941104a6641c510..73941336b77438c620d2e2161aebd6e2d445640f 100644 (file)
@@ -54,10 +54,10 @@ char *http_extract_cookie_value(char *hdr, const char *hdr_end,
 int http_parse_qvalue(const char *qvalue, const char **end);
 const char *http_find_url_param_pos(const char **chunks,
                                     const char* url_param_name,
-                                    size_t url_param_name_l, char delim);
+                                    size_t url_param_name_l, char delim, char insensitive);
 int http_find_next_url_param(const char **chunks,
                              const char* url_param_name, size_t url_param_name_l,
-                             const char **vstart, const char **vend, char delim);
+                             const char **vstart, const char **vend, char delim, char insensitive);
 
 int http_parse_header(const struct ist hdr, struct ist *name, struct ist *value);
 int http_parse_stline(const struct ist line, struct ist *p1, struct ist *p2, struct ist *p3);
index f55b6969359bec04a7d8277c5cd5f5b08f804008..8aef755fd202d0bf633dfe846cb336579ceee73b 100644 (file)
@@ -995,7 +995,7 @@ int http_parse_qvalue(const char *qvalue, const char **end)
  */
 const char *http_find_url_param_pos(const char **chunks,
                                     const char* url_param_name, size_t url_param_name_l,
-                                    char delim)
+                                    char delim, char insensitive)
 {
        const char *pos, *last, *equal;
        const char **bufs = chunks;
@@ -1032,9 +1032,16 @@ const char *http_find_url_param_pos(const char **chunks,
                                if (bufs[2] + l2 > bufs[3])
                                        return NULL;
 
-                               if (memcmp(pos,     url_param_name,    l1) == 0 &&
-                                   memcmp(bufs[2], url_param_name+l1, l2) == 0)
-                                       return pos;
+                               if (insensitive) {
+                                       if (strncasecmp(pos,     url_param_name,    l1) == 0 &&
+                                               strncasecmp(bufs[2], url_param_name+l1, l2) == 0)
+                                               return pos;
+                               }
+                               else {
+                                       if (memcmp(pos,     url_param_name,    l1) == 0 &&
+                                               memcmp(bufs[2], url_param_name+l1, l2) == 0)
+                                               return pos;
+                               }
 
                                /* Perform wrapping and jump the string who fail the comparison. */
                                bufs += 2;
@@ -1042,9 +1049,14 @@ const char *http_find_url_param_pos(const char **chunks,
                                last = bufs[1];
 
                        } else {
-                               /* process a simple comparison. */
-                               if (memcmp(pos, url_param_name, url_param_name_l) == 0)
-                                       return pos;
+                                       /* process a simple comparison.*/
+                               if (insensitive) {
+                                       if (strncasecmp(pos, url_param_name, url_param_name_l) == 0)
+                                               return pos;
+                               } else {
+                                       if (memcmp(pos, url_param_name, url_param_name_l) == 0)
+                                               return pos;
+                               }
                                pos += url_param_name_l + 1;
                                if (fix_pointer_if_wrap(chunks, &pos))
                                        last = bufs[2];
@@ -1078,7 +1090,7 @@ const char *http_find_url_param_pos(const char **chunks,
  */
 int http_find_next_url_param(const char **chunks,
                              const char* url_param_name, size_t url_param_name_l,
-                             const char **vstart, const char **vend, char delim)
+                             const char **vstart, const char **vend, char delim, char insensitive)
 {
        const char *arg_start, *qs_end;
        const char *value_start, *value_end;
@@ -1089,7 +1101,7 @@ int http_find_next_url_param(const char **chunks,
                /* Looks for an argument name. */
                arg_start = http_find_url_param_pos(chunks,
                                                    url_param_name, url_param_name_l,
-                                                   delim);
+                                                   delim, insensitive);
                /* Check for wrapping. */
                if (arg_start >= qs_end)
                        qs_end = chunks[3];
index 732cfbbb14e8ff49b886a74d3cf46192def55ad7..270ef97d28f1c2130451d5a99ee082a8afd00f26 100644 (file)
@@ -1833,14 +1833,14 @@ static int smp_fetch_cookie_val(const struct arg *args, struct sample *smp, cons
  * in ctx->a[1], and the optional second part in (ctx->a[2]..ctx->a[3]). The
  * pointers are updated for next iteration before leaving.
  */
-static int smp_fetch_param(char delim, const char *name, int name_len, const struct arg *args, struct sample *smp, const char *kw, void *private)
+static int smp_fetch_param(char delim, const char *name, int name_len, const struct arg *args, struct sample *smp, const char *kw, void *private, char insensitive)
 {
        const char *vstart, *vend;
        struct buffer *temp;
        const char **chunks = (const char **)smp->ctx.a;
 
        if (!http_find_next_url_param(chunks, name, name_len,
-                                &vstart, &vend, delim))
+                                &vstart, &vend, delim, insensitive))
                return 0;
 
        /* Create sample. If the value is contiguous, return the pointer as CONST,
@@ -1926,7 +1926,7 @@ static int smp_fetch_url_param(const struct arg *args, struct sample *smp, const
                 */
        }
 
-       return smp_fetch_param(delim, name, name_len, args, smp, kw, private);
+       return smp_fetch_param(delim, name, name_len, args, smp, kw, private, 0);
 }
 
 /* This function iterates over each parameter of the body. This requires
@@ -1984,7 +1984,7 @@ static int smp_fetch_body_param(const struct arg *args, struct sample *smp, cons
 
        }
 
-       return smp_fetch_param('&', name, name_len, args, smp, kw, private);
+       return smp_fetch_param('&', name, name_len, args, smp, kw, private, 0);
 }
 
 /* Return the signed integer value for the specified url parameter (see url_param