]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: actions: mutualise the action keyword lookup
authorThierry FOURNIER <tfournier@arpalert.org>
Wed, 19 Aug 2015 07:07:47 +0000 (09:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 20 Aug 2015 15:13:47 +0000 (17:13 +0200)
Each (http|tcp)-(request|response) action use the same method
for looking up the action keyword during the cofiguration parsing.

This patch mutualize the code.

include/proto/action.h [new file with mode: 0644]
include/types/action.h
src/proto_http.c
src/proto_tcp.c

diff --git a/include/proto/action.h b/include/proto/action.h
new file mode 100644 (file)
index 0000000..5f71067
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * include/proto/action.h
+ * This file contains actions prototypes.
+ *
+ * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _PROTO_ACTION_H
+#define _PROTO_ACTION_H
+
+#include <types/action.h>
+
+static inline struct action_kw *action_lookup(struct list *keywords, const char *kw)
+{
+       struct action_kw_list *kw_list;
+       int i;
+
+       if (LIST_ISEMPTY(keywords))
+               return NULL;
+
+       list_for_each_entry(kw_list, keywords, list) {
+               for (i = 0; kw_list->kw[i].kw != NULL; i++) {
+                       if (kw_list->kw[i].match_pfx &&
+                           strncmp(kw, kw_list->kw[i].kw, strlen(kw_list->kw[i].kw)) == 0)
+                               return &kw_list->kw[i];
+                       if (!strcmp(kw, kw_list->kw[i].kw))
+                               return &kw_list->kw[i];
+               }
+       }
+       return NULL;
+}
+
+#endif /* _PROTO_ACTION_H */
index 9fb087889d7304dc7fe7fcb8d0799cae97055090..b8b4cd4df941e737e00be978e2972d8066e29021 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * include/types/action.h
- * This file contains TCP protocol definitions.
+ * This file contains actions definitions.
  *
  * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
  *
index 69a1052d10adbbc9516f5db7bab824ef69a81f7d..68158eb233b30cb2d768d469ea267dc487fce2b3 100644 (file)
@@ -42,6 +42,7 @@
 #include <types/global.h>
 
 #include <proto/acl.h>
+#include <proto/action.h>
 #include <proto/arg.h>
 #include <proto/auth.h>
 #include <proto/backend.h>
@@ -12647,21 +12648,7 @@ int parse_http_res_capture(const char **args, int *orig_arg, struct proxy *px, s
  */
 struct action_kw *action_http_req_custom(const char *kw)
 {
-       if (!LIST_ISEMPTY(&http_req_keywords.list)) {
-               struct action_kw_list *kw_list;
-               int i;
-
-               list_for_each_entry(kw_list, &http_req_keywords.list, list) {
-                       for (i = 0; kw_list->kw[i].kw != NULL; i++) {
-                               if (kw_list->kw[i].match_pfx &&
-                                   strncmp(kw, kw_list->kw[i].kw, strlen(kw_list->kw[i].kw)) == 0)
-                                       return &kw_list->kw[i];
-                               if (!strcmp(kw, kw_list->kw[i].kw))
-                                       return &kw_list->kw[i];
-                       }
-               }
-       }
-       return NULL;
+       return action_lookup(&http_req_keywords.list, kw);
 }
 
 /*
@@ -12669,21 +12656,7 @@ struct action_kw *action_http_req_custom(const char *kw)
  */
 struct action_kw *action_http_res_custom(const char *kw)
 {
-       if (!LIST_ISEMPTY(&http_res_keywords.list)) {
-               struct action_kw_list *kw_list;
-               int i;
-
-               list_for_each_entry(kw_list, &http_res_keywords.list, list) {
-                       for (i = 0; kw_list->kw[i].kw != NULL; i++) {
-                               if (kw_list->kw[i].match_pfx &&
-                                   strncmp(kw, kw_list->kw[i].kw, strlen(kw_list->kw[i].kw)) == 0)
-                                       return &kw_list->kw[i];
-                               if (!strcmp(kw, kw_list->kw[i].kw))
-                                       return &kw_list->kw[i];
-                       }
-               }
-       }
-       return NULL;
+       return action_lookup(&http_res_keywords.list, kw);
 }
 
 /************************************************************************/
index 8dd95fd2d7c0df0adcac521c5996595110fc8245..87aeaf0647ebebf274a67f6f75e2123636d6a99c 100644 (file)
@@ -40,6 +40,7 @@
 #include <types/server.h>
 
 #include <proto/acl.h>
+#include <proto/action.h>
 #include <proto/arg.h>
 #include <proto/channel.h>
 #include <proto/connection.h>
@@ -137,62 +138,17 @@ void tcp_res_cont_keywords_register(struct action_kw_list *kw_list)
  */
 static struct action_kw *tcp_req_conn_action(const char *kw)
 {
-       struct action_kw_list *kw_list;
-       int i;
-
-       if (LIST_ISEMPTY(&tcp_req_conn_keywords))
-               return NULL;
-
-       list_for_each_entry(kw_list, &tcp_req_conn_keywords, list) {
-               for (i = 0; kw_list->kw[i].kw != NULL; i++) {
-                       if (kw_list->kw[i].match_pfx &&
-                           strncmp(kw, kw_list->kw[i].kw, strlen(kw_list->kw[i].kw)) == 0)
-                               return &kw_list->kw[i];
-                       if (!strcmp(kw, kw_list->kw[i].kw))
-                               return &kw_list->kw[i];
-               }
-       }
-       return NULL;
+       return action_lookup(&tcp_req_conn_keywords, kw);
 }
 
 static struct action_kw *tcp_req_cont_action(const char *kw)
 {
-       struct action_kw_list *kw_list;
-       int i;
-
-       if (LIST_ISEMPTY(&tcp_req_cont_keywords))
-               return NULL;
-
-       list_for_each_entry(kw_list, &tcp_req_cont_keywords, list) {
-               for (i = 0; kw_list->kw[i].kw != NULL; i++) {
-                       if (kw_list->kw[i].match_pfx &&
-                           strncmp(kw, kw_list->kw[i].kw, strlen(kw_list->kw[i].kw)) == 0)
-                               return &kw_list->kw[i];
-                       if (!strcmp(kw, kw_list->kw[i].kw))
-                               return &kw_list->kw[i];
-               }
-       }
-       return NULL;
+       return action_lookup(&tcp_req_cont_keywords, kw);
 }
 
 static struct action_kw *tcp_res_cont_action(const char *kw)
 {
-       struct action_kw_list *kw_list;
-       int i;
-
-       if (LIST_ISEMPTY(&tcp_res_cont_keywords))
-               return NULL;
-
-       list_for_each_entry(kw_list, &tcp_res_cont_keywords, list) {
-               for (i = 0; kw_list->kw[i].kw != NULL; i++) {
-                       if (kw_list->kw[i].match_pfx &&
-                           strncmp(kw, kw_list->kw[i].kw, strlen(kw_list->kw[i].kw)) == 0)
-                               return &kw_list->kw[i];
-                       if (!strcmp(kw, kw_list->kw[i].kw))
-                               return &kw_list->kw[i];
-               }
-       }
-       return NULL;
+       return action_lookup(&tcp_res_cont_keywords, kw);
 }
 
 /* Binds ipv4/ipv6 address <local> to socket <fd>, unless <flags> is set, in which