]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: action: add a function to dump the list of actions for a ruleset
authorWilly Tarreau <w@1wt.eu>
Wed, 30 Mar 2022 09:19:22 +0000 (11:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Mar 2022 09:19:22 +0000 (11:19 +0200)
The new function dump_act_rules() now dumps the list of actions supported
by a ruleset. These actions are alphanumerically sorted first so that the
produced output is easy to compare.

include/haproxy/action.h
src/action.c

index eed440d8e3214edeb7baeeacde52781a20cfc872..8a35664f408b8e1c0f98da37df7aa842bdedf4ce 100644 (file)
@@ -114,5 +114,6 @@ static inline void release_timeout_action(struct act_rule *rule)
 
 struct act_rule *new_act_rule(enum act_from from, const char *file, int linenum);
 void free_act_rules(struct list *rules);
+void dump_act_rules(const struct list *rules, const char *pfx);
 
 #endif /* _HAPROXY_ACTION_H */
index 74f5387b9c5c8a4fe6962abcc2e22a00ec5958d3..4ee23c5479ccd716352f02890b7f788c81134816 100644 (file)
@@ -321,3 +321,28 @@ void free_act_rules(struct list *rules)
                free_act_rule(rule);
        }
 }
+
+/* dumps all known actions registered in action rules <rules> after prefix
+ * <pfx> to stdout. The actions are alphabetically sorted. Those with the
+ * KWF_MATCH_PREFIX flag have their name suffixed with '*'.
+ */
+void dump_act_rules(const struct list *rules, const char *pfx)
+{
+       const struct action_kw *akwp, *akwn;
+       struct action_kw_list *akwl;
+       int index;
+
+       for (akwn = akwp = NULL;; akwp = akwn) {
+               list_for_each_entry(akwl, rules, list) {
+                       for (index = 0; akwl->kw[index].kw != NULL; index++)
+                               if (strordered(akwp ? akwp->kw : NULL,
+                                              akwl->kw[index].kw,
+                                              akwn != akwp ? akwn->kw : NULL))
+                                       akwn = &akwl->kw[index];
+               }
+               if (akwn == akwp)
+                       break;
+               printf("%s%s%s\n", pfx ? pfx : "", akwn->kw,
+                      (akwn->flags & KWF_MATCH_PREFIX) ? "*" : "");
+       }
+}