]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: sample: move code to release a sample expression in sample.c
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 26 Oct 2016 09:34:47 +0000 (11:34 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 9 Nov 2016 21:57:00 +0000 (22:57 +0100)
This code has been moved from haproxy.c to sample.c and the function
release_sample_expr can now be called from anywhere to release a sample
expression. This function will be used by the stream processing offload engine
(SPOE).

include/proto/sample.h
src/haproxy.c
src/sample.c

index ecb2eb49770a3b2476cd8fbeb8394e6fc7d0c82d..4319278a9c0192589401d1b1d61736b1f72f87dd 100644 (file)
@@ -36,6 +36,7 @@ struct sample *sample_process(struct proxy *px, struct session *sess,
 struct sample *sample_fetch_as_type(struct proxy *px, struct session *sess,
                                    struct stream *strm, unsigned int opt,
                                    struct sample_expr *expr, int smp_type);
+void release_sample_expr(struct sample_expr *expr);
 void sample_register_fetches(struct sample_fetch_kw_list *psl);
 void sample_register_convs(struct sample_conv_kw_list *psl);
 const char *sample_src_names(unsigned int use);
index b899c76e43df8569d357b78dd8defa1a954bb0af..c40813b246a42bef3f4205678e4b692fdc6b5df9 100644 (file)
@@ -1342,33 +1342,6 @@ static void deinit_tcp_rules(struct list *rules)
        }
 }
 
-static void deinit_sample_arg(struct arg *p)
-{
-       struct arg *p_back = p;
-
-       if (!p)
-               return;
-
-       while (p->type != ARGT_STOP) {
-               if (p->type == ARGT_STR || p->unresolved) {
-                       free(p->data.str.str);
-                       p->data.str.str = NULL;
-                       p->unresolved = 0;
-               }
-               else if (p->type == ARGT_REG) {
-                       if (p->data.reg) {
-                               regex_free(p->data.reg);
-                               free(p->data.reg);
-                               p->data.reg = NULL;
-                       }
-               }
-               p++;
-       }
-
-       if (p_back != empty_arg_list)
-               free(p_back);
-}
-
 static void deinit_stick_rules(struct list *rules)
 {
        struct sticking_rule *rule, *ruleb;
@@ -1376,13 +1349,7 @@ static void deinit_stick_rules(struct list *rules)
        list_for_each_entry_safe(rule, ruleb, rules, list) {
                LIST_DEL(&rule->list);
                deinit_acl_cond(rule->cond);
-               if (rule->expr) {
-                       struct sample_conv_expr *conv_expr, *conv_exprb;
-                       list_for_each_entry_safe(conv_expr, conv_exprb, &rule->expr->conv_exprs, list)
-                               deinit_sample_arg(conv_expr->arg_p);
-                       deinit_sample_arg(rule->expr->arg_p);
-                       free(rule->expr);
-               }
+               release_sample_expr(rule->expr);
                free(rule);
        }
 }
index 1438ca1146b94275adabac5ddc59e4d3d0b1f9ff..35b5913bed58fae72cbdfd3f50be4da4572fbbfc 100644 (file)
@@ -1382,6 +1382,46 @@ struct sample *sample_fetch_as_type(struct proxy *px, struct session *sess,
        return smp;
 }
 
+static void release_sample_arg(struct arg *p)
+{
+       struct arg *p_back = p;
+
+       if (!p)
+               return;
+
+       while (p->type != ARGT_STOP) {
+               if (p->type == ARGT_STR || p->unresolved) {
+                       free(p->data.str.str);
+                       p->data.str.str = NULL;
+                       p->unresolved = 0;
+               }
+               else if (p->type == ARGT_REG) {
+                       if (p->data.reg) {
+                               regex_free(p->data.reg);
+                               free(p->data.reg);
+                               p->data.reg = NULL;
+                       }
+               }
+               p++;
+       }
+
+       if (p_back != empty_arg_list)
+               free(p_back);
+}
+
+void release_sample_expr(struct sample_expr *expr)
+{
+       struct sample_conv_expr *conv_expr, *conv_exprb;
+
+       if (!expr)
+               return;
+
+       list_for_each_entry_safe(conv_expr, conv_exprb, &expr->conv_exprs, list)
+               release_sample_arg(conv_expr->arg_p);
+       release_sample_arg(expr->arg_p);
+       free(expr);
+}
+
 /*****************************************************************/
 /*    Sample format convert functions                            */
 /*    These functions set the data type on return.               */