]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: pattern: get rid of arg_i in all functions making use of arguments
authorWilly Tarreau <w@1wt.eu>
Fri, 20 Apr 2012 12:03:29 +0000 (14:03 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 May 2012 18:57:12 +0000 (20:57 +0200)
arg_i was almost unused, and since we migrated to use struct arg everywhere,
the rare cases where arg_i was needed could be replaced by switching to
arg->type = ARGT_STOP.

include/proto/pattern.h
include/types/pattern.h
src/haproxy.c
src/pattern.c
src/proto_http.c
src/proto_tcp.c

index bb1181cd6272271c490a630b3f5baf06d8f39ede..ef2c5480cefc6971afd79c8a2cd3d2adc5102882 100644 (file)
@@ -34,6 +34,6 @@ struct pattern *pattern_process(struct proxy *px, struct session *l4,
 void pattern_register_fetches(struct pattern_fetch_kw_list *psl);
 void pattern_register_convs(struct pattern_conv_kw_list *psl);
 
-int pattern_arg_ipmask(const char *arg_str, struct arg **arg_p, int *arg_i);
-int pattern_arg_str(const char *arg_str, struct arg **arg_p, int *arg_i);
+int pattern_arg_ipmask(const char *arg_str, struct arg **arg_p);
+int pattern_arg_str(const char *arg_str, struct arg **arg_p);
 #endif
index e948264ba02d468e37fbd9ce887fb4afd195f89a..101485660943cacc4763fc8c780b2471a8c7dca3 100644 (file)
@@ -63,11 +63,9 @@ struct pattern {
 struct pattern_conv {
        const char *kw;                           /* configuration keyword  */
        int (*process)(const struct arg *arg_p,
-                      int arg_i,
-                      union pattern_data *data); /* process function */
+                      union pattern_data *data); /* process function */
        int (*parse_args)(const char *arg_str,
-                         struct arg **arg_p,
-                         int *arg_i);            /* argument parser. Can be NULL. */
+                         struct arg **arg_p);    /* argument parser. May be NULL. */
        unsigned int in_type;                     /* input needed pattern type */
        unsigned int out_type;                    /* output pattern type */
 };
@@ -77,7 +75,6 @@ struct pattern_conv_expr {
        struct list list;                         /* member of a pattern expression */
        struct pattern_conv *conv;                /* pattern conversion */
        struct arg *arg_p;                        /* pointer on args */
-       int arg_i;                                /* number of args */
 };
 
 /* pattern fetch */
@@ -87,11 +84,9 @@ struct pattern_fetch {
                       struct session *l4,
                       void *l7,
                       int dir, const struct arg *arg_p,
-                      int arg_i,
                       union pattern_data *data); /* fetch processing function */
        int (*parse_args)(const char *arg_str,
-                         struct arg **arg_p,
-                         int *arg_i);            /* argument parser. Can be NULL. */
+                         struct arg **arg_p);    /* argument parser. Can be NULL. */
        unsigned long out_type;                   /* output pattern type */
        int dir;                                  /* usable directions */
 };
@@ -101,7 +96,6 @@ struct pattern_expr {
        struct list list;                         /* member of list of pattern, currently not used */
        struct pattern_fetch *fetch;              /* pattern fetch */
        struct arg *arg_p;                        /* pointer on args */
-       int arg_i;                                /* number of args */
        struct list conv_exprs;                   /* list of conversion expression to apply */
 };
 
index f606ee2bf50ea453b25ad6ad802179790144d620..decfede860a2378cd6346a4be0f07f5544530df5 100644 (file)
@@ -758,21 +758,24 @@ static void deinit_tcp_rules(struct list *rules)
        }
 }
 
-static void deinit_pattern_arg(struct arg *p, int i)
+static void deinit_pattern_arg(struct arg *p)
 {
+       struct arg *p_back = p;
+
        if (!p)
                return;
 
-       while (i--) {
-               if (p[i].type == ARGT_FE || p[i].type == ARGT_BE ||
-                   p[i].type == ARGT_TAB || p[i].type == ARGT_SRV ||
-                   p[i].type == ARGT_USR || p[i].type == ARGT_STR) {
-                       free(p[i].data.str.str);
-                       p[i].data.str.str = NULL;
+       while (p->type != ARGT_STOP) {
+               if (p->type == ARGT_FE || p->type == ARGT_BE ||
+                   p->type == ARGT_TAB || p->type == ARGT_SRV ||
+                   p->type == ARGT_USR || p->type == ARGT_STR) {
+                       free(p->data.str.str);
+                       p->data.str.str = NULL;
                }
+               p++;
        }
 
-       free(p);
+       free(p_back);
 }
 
 static void deinit_stick_rules(struct list *rules)
@@ -785,8 +788,8 @@ static void deinit_stick_rules(struct list *rules)
                if (rule->expr) {
                        struct pattern_conv_expr *conv_expr, *conv_exprb;
                        list_for_each_entry_safe(conv_expr, conv_exprb, &rule->expr->conv_exprs, list)
-                               deinit_pattern_arg(conv_expr->arg_p, conv_expr->arg_i);
-                       deinit_pattern_arg(rule->expr->arg_p, rule->expr->arg_i);
+                               deinit_pattern_arg(conv_expr->arg_p);
+                       deinit_pattern_arg(rule->expr->arg_p);
                        free(rule->expr);
                }
                free(rule);
index cae85a873a9ef885a9e1273c03f342296769f2b4..72c0b34594051dfbcbb29f50f3433dfc9c60f21c 100644 (file)
@@ -328,7 +328,7 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
                p = my_strndup(endw + 1, i);
                if (!p)
                        goto out_error;
-               i = fetch->parse_args(p, &expr->arg_p, &expr->arg_i);
+               i = fetch->parse_args(p, &expr->arg_p);
                free(p);
                if (!i) {
                        p = my_strndup(str[*idx], endw - str[*idx]);
@@ -413,7 +413,7 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
                        p = my_strndup(endw + 1, i);
                        if (!p)
                                goto out_error;
-                       i = conv->parse_args(p, &conv_expr->arg_p, &conv_expr->arg_i);
+                       i = conv->parse_args(p, &conv_expr->arg_p);
                        free(p);
                        if (!i) {
                                p = my_strndup(str[*idx], endw - str[*idx]);
@@ -458,7 +458,7 @@ struct pattern *pattern_process(struct proxy *px, struct session *l4, void *l7,
        if (p == NULL)
                p = &temp_pattern;
 
-       if (!expr->fetch->process(px, l4, l7, dir, expr->arg_p, expr->arg_i, &p->data))
+       if (!expr->fetch->process(px, l4, l7, dir, expr->arg_p, &p->data))
                return NULL;
 
        p->type = expr->fetch->out_type;
@@ -468,7 +468,7 @@ struct pattern *pattern_process(struct proxy *px, struct session *l4, void *l7,
                        return NULL;
 
                p->type = conv_expr->conv->in_type;
-               if (!conv_expr->conv->process(conv_expr->arg_p, conv_expr->arg_i, &p->data))
+               if (!conv_expr->conv->process(conv_expr->arg_p, &p->data))
                        return NULL;
 
                p->type = conv_expr->conv->out_type;
@@ -479,11 +479,11 @@ struct pattern *pattern_process(struct proxy *px, struct session *l4, void *l7,
 /* Converts an argument string mask to a arg type IP.
  * Returns non-zero in case of success, 0 on error.
  */
-int pattern_arg_ipmask(const char *arg_str, struct arg **arg_p, int *arg_i)
+int pattern_arg_ipmask(const char *arg_str, struct arg **arg_p)
 {
-       *arg_i = 1;
-       *arg_p = calloc(1, *arg_i*sizeof(struct arg));
+       *arg_p = calloc(2, sizeof(struct arg));
        (*arg_p)->type = ARGT_IPV4;
+       arg_p[1]->type = ARGT_STOP;
 
        if (!str2mask(arg_str, &(*arg_p)->data.ipv4))
                return 0;
@@ -495,14 +495,13 @@ int pattern_arg_ipmask(const char *arg_str, struct arg **arg_p, int *arg_i)
 /* Converts an argument string to a arg type STRING.
  * Returns non-zero in case of success, 0 on error.
  */
-int pattern_arg_str(const char *arg_str, struct arg **arg_p, int *arg_i)
+int pattern_arg_str(const char *arg_str, struct arg **arg_p)
 {
-       *arg_i = 1;
-       *arg_p = calloc(1, *arg_i*sizeof(struct arg));
+       *arg_p = calloc(2, sizeof(struct arg));
        (*arg_p)->type = ARGT_STR;
        (*arg_p)->data.str.str = strdup(arg_str);
        (*arg_p)->data.str.len = strlen(arg_str);
-
+       arg_p[1]->type = ARGT_STOP;
 
        return 1;
 }
@@ -512,7 +511,7 @@ int pattern_arg_str(const char *arg_str, struct arg **arg_p, int *arg_i)
 /*    Pattern format convert functions                           */
 /*****************************************************************/
 
-static int pattern_conv_str2lower(const struct arg *arg_p, int arg_i, union pattern_data *data)
+static int pattern_conv_str2lower(const struct arg *arg_p, union pattern_data *data)
 {
        int i;
 
@@ -526,7 +525,7 @@ static int pattern_conv_str2lower(const struct arg *arg_p, int arg_i, union patt
        return 1;
 }
 
-static int pattern_conv_str2upper(const struct arg *arg_p, int arg_i, union pattern_data *data)
+static int pattern_conv_str2upper(const struct arg *arg_p, union pattern_data *data)
 {
        int i;
 
@@ -540,8 +539,8 @@ static int pattern_conv_str2upper(const struct arg *arg_p, int arg_i, union patt
        return 1;
 }
 
-/* takes the netmask in arg_i */
-static int pattern_conv_ipmask(const struct arg *arg_p, int arg_i, union pattern_data *data)
+/* takes the netmask in arg_p */
+static int pattern_conv_ipmask(const struct arg *arg_p, union pattern_data *data)
 {
        data->ip.s_addr &= arg_p->data.ipv4.s_addr;
        return 1;
index 6dcb5ffe7424b32f6fc2de5f2b92d12e107ec24a..da7fa339ba442d75f7b3a125f308386fefa8bb74 100644 (file)
@@ -8344,7 +8344,7 @@ static struct acl_kw_list acl_kws = {{ },{
 /* Returns the last occurrence of specified header. */
 static int
 pattern_fetch_hdr(struct proxy *px, struct session *l4, void *l7, int dir,
-                 const struct arg *arg_p, int arg_i, union pattern_data *data)
+                 const struct arg *arg_p, union pattern_data *data)
 {
        struct http_txn *txn = l7;
 
@@ -8439,7 +8439,7 @@ find_url_param_value(char* path, size_t path_l,
 
 static int
 pattern_fetch_url_param(struct proxy *px, struct session *l4, void *l7, int dir,
-                     const struct arg *arg_p, int arg_i, union pattern_data *data)
+                     const struct arg *arg_p, union pattern_data *data)
 {
        struct http_txn *txn = l7;
        struct http_msg *msg = &txn->req;
@@ -8492,7 +8492,7 @@ find_cookie_value(struct http_msg *msg, struct http_txn *txn,
 
 static int
 pattern_fetch_cookie(struct proxy *px, struct session *l4, void *l7, int dir,
-                     const struct arg *arg_p, int arg_i, union pattern_data *data)
+                     const struct arg *arg_p, union pattern_data *data)
 {
        struct http_txn *txn = l7;
        struct http_msg *msg = &txn->req;
@@ -8514,7 +8514,7 @@ pattern_fetch_cookie(struct proxy *px, struct session *l4, void *l7, int dir,
 
 static int
 pattern_fetch_set_cookie(struct proxy *px, struct session *l4, void *l7, int dir,
-                        const struct arg *arg_p, int arg_i, union pattern_data *data)
+                        const struct arg *arg_p, union pattern_data *data)
 {
        struct http_txn *txn = l7;
        struct http_msg *msg = &txn->rsp;
index 59d0d5516f0ff730ce8d9f7e19a3a95ef7d7d65c..a0e315ddc532473fa869f88edd24a16f5632154e 100644 (file)
@@ -1275,7 +1275,7 @@ acl_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir,
 /* extract the connection's source ipv4 address */
 static int
 pattern_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir,
-                  const struct arg *arg_p, int arg_i, union pattern_data *data)
+                  const struct arg *arg_p, union pattern_data *data)
 {
        if (l4->si[0].addr.from.ss_family != AF_INET )
                return 0;
@@ -1287,7 +1287,7 @@ pattern_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir,
 /* extract the connection's source ipv6 address */
 static int
 pattern_fetch_src6(struct proxy *px, struct session *l4, void *l7, int dir,
-                  const struct arg *arg_p, int arg_i, union pattern_data *data)
+                  const struct arg *arg_p, union pattern_data *data)
 {
        if (l4->si[0].addr.from.ss_family != AF_INET6)
                return 0;
@@ -1337,7 +1337,7 @@ acl_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir,
 /* extract the connection's destination ipv4 address */
 static int
 pattern_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir,
-                  const struct arg *arg_p, int arg_i, union pattern_data *data)
+                  const struct arg *arg_p, union pattern_data *data)
 {
        stream_sock_get_to_addr(&l4->si[0]);
 
@@ -1351,7 +1351,7 @@ pattern_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir,
 /* extract the connection's destination ipv6 address */
 static int
 pattern_fetch_dst6(struct proxy *px, struct session *l4, void *l7, int dir,
-                  const struct arg *arg_p, int arg_i, union pattern_data *data)
+                  const struct arg *arg_p, union pattern_data *data)
 {
        stream_sock_get_to_addr(&l4->si[0]);
 
@@ -1378,7 +1378,7 @@ acl_fetch_dport(struct proxy *px, struct session *l4, void *l7, int dir,
 
 static int
 pattern_fetch_dport(struct proxy *px, struct session *l4, void *l7, int dir,
-                    const struct arg *arg, int i, union pattern_data *data)
+                    const struct arg *arg, union pattern_data *data)
 {
        stream_sock_get_to_addr(&l4->si[0]);
 
@@ -1389,7 +1389,7 @@ pattern_fetch_dport(struct proxy *px, struct session *l4, void *l7, int dir,
 }
 
 static int
-pattern_arg_fetch_payloadlv(const char *arg, struct arg **arg_p, int *arg_i)
+pattern_arg_fetch_payloadlv(const char *arg, struct arg **arg_p)
 {
        int member = 0;
        int len_offset = 0;
@@ -1445,21 +1445,21 @@ pattern_arg_fetch_payloadlv(const char *arg, struct arg **arg_p, int *arg_i)
                buf_offset = len_offset + len_size - buf_offset;
        }
 
-       *arg_i = 3;
-       *arg_p = calloc(1, *arg_i*sizeof(struct arg));
+       *arg_p = calloc(4, sizeof(struct arg));
        (*arg_p)[0].type = ARGT_UINT;
        (*arg_p)[0].data.uint = len_offset;
        (*arg_p)[1].type = ARGT_UINT;
        (*arg_p)[1].data.uint = len_size;
        (*arg_p)[2].type = ARGT_UINT;
        (*arg_p)[2].data.uint = buf_offset;
+       (*arg_p)[3].type = ARGT_STOP;
 
        return 1;
 }
 
 static int
 pattern_fetch_payloadlv(struct proxy *px, struct session *l4, void *l7, int dir,
-                        const struct arg *arg_p, int arg_i, union pattern_data *data)
+                        const struct arg *arg_p, union pattern_data *data)
 {
        int len_offset = arg_p[0].data.uint;
        int len_size = arg_p[1].data.uint;
@@ -1500,7 +1500,7 @@ pattern_fetch_payloadlv(struct proxy *px, struct session *l4, void *l7, int dir,
 }
 
 static int
-pattern_arg_fetch_payload (const char *arg, struct arg **arg_p, int *arg_i)
+pattern_arg_fetch_payload (const char *arg, struct arg **arg_p)
 {
        int member = 0;
        int buf_offset = 0;
@@ -1527,19 +1527,19 @@ pattern_arg_fetch_payload (const char *arg, struct arg **arg_p, int *arg_i)
        if (!buf_size)
                return 0;
 
-       *arg_i = 2;
-       *arg_p = calloc(1, *arg_i*sizeof(struct arg));
+       *arg_p = calloc(3, sizeof(struct arg));
        (*arg_p)[0].type = ARGT_UINT;
        (*arg_p)[0].data.uint = buf_offset;
        (*arg_p)[1].type = ARGT_UINT;
        (*arg_p)[1].data.uint = buf_size;
+       (*arg_p)[2].type = ARGT_STOP;
 
        return 1;
 }
 
 static int
 pattern_fetch_payload(struct proxy *px, struct session *l4, void *l7, int dir,
-                      const struct arg *arg_p, int arg_i, union pattern_data *data)
+                      const struct arg *arg_p, union pattern_data *data)
 {
        int buf_offset = arg_p[0].data.uint;
        int buf_size = arg_p[1].data.uint;
@@ -1564,7 +1564,7 @@ pattern_fetch_payload(struct proxy *px, struct session *l4, void *l7, int dir,
 
 static int
 pattern_fetch_rdp_cookie(struct proxy *px, struct session *l4, void *l7, int dir,
-                         const struct arg *arg_p, int arg_i, union pattern_data *data)
+                         const struct arg *arg_p, union pattern_data *data)
 {
        int ret;
        struct acl_expr  expr;