MAJOR: pattern/map: Extends the map edition system in the patterns
This patch add the following socket command line options:
show acl [<id>]
clear acl <id>
get acl <id> <pattern>
del acl <id> <pattern>
add acl <id> <pattern>
The system used for maps is backported in the pattern functions.
diff --git a/include/proto/pattern.h b/include/proto/pattern.h
index ba428af..a019730 100644
--- a/include/proto/pattern.h
+++ b/include/proto/pattern.h
@@ -40,7 +40,8 @@
* The function returns 1 if the processing is ok, return 0
* if the parser fails, with <err> message filled.
*/
-int pattern_register(struct pattern_expr *expr, const char *arg, struct sample_storage *smp, int patflags, char **err);
+int pattern_register(struct pattern_head *head, char *reference, int refflags, const char *arg, struct sample_storage *smp, int patflags, char **err);
+void pattern_finalize_config(void);
/* return the PAT_MATCH_* index for match name "name", or < 0 if not found */
static inline int pat_find_match_name(const char *name)
@@ -59,7 +60,7 @@
* function returns the matched pattern. In many cases, this pattern can be a
* static buffer.
*/
-struct pattern *pattern_exec_match(struct pattern_expr *expr, struct sample *smp, int fill);
+struct pattern *pattern_exec_match(struct pattern_head *head, struct sample *smp, int fill);
/*
*
@@ -195,11 +196,33 @@
*/
struct pattern *pat_match_reg(struct sample *smp, struct pattern_expr *expr, int fill);
-int pattern_read_from_file(struct pattern_expr *expr, const char *filename, int patflags, char **err);
+/*
+ * pattern_ref manipulation.
+ */
+struct pat_ref *pat_ref_lookup(const char *reference);
+struct pat_ref *pat_ref_new(const char *reference, unsigned int flags);
+int pat_ref_append(struct pat_ref *ref, char *pattern, char *sample, int line);
+int pat_ref_add(struct pat_ref *ref, const char *pattern, const char *sample, char **err);
+int pat_ref_set(struct pat_ref *ref, const char *pattern, const char *sample);
+int pat_ref_delete(struct pat_ref *ref, const char *key);
+void pat_ref_prune(struct pat_ref *ref);
+int pat_ref_load(struct pat_ref *ref, struct pattern_expr *expr, int patflags, int soe, char **err);
+
+/*
+ * pattern_head manipulation.
+ */
+void pattern_init_head(struct pattern_head *head);
+void pattern_prune(struct pattern_head *head);
+int pattern_read_from_file(struct pattern_head *head, unsigned int refflags, const char *filename, int patflags, char **err);
+
+/*
+ * pattern_expr manipulation.
+ */
void pattern_init_expr(struct pattern_expr *expr);
+struct pattern_expr *pattern_lookup_expr(struct pattern_head *head, struct pat_ref *ref);
+struct pattern_expr *pattern_new_expr(struct pattern_head *head, struct pat_ref *ref, char **err);
struct sample_storage **pattern_find_smp(const char *key, struct pattern_expr *expr, char **err);
int pattern_delete(const char *key, struct pattern_expr *expr, char **err);
-void pattern_prune(struct pattern_expr *expr);
#endif
diff --git a/include/types/acl.h b/include/types/acl.h
index 2221761..c0b5ace 100644
--- a/include/types/acl.h
+++ b/include/types/acl.h
@@ -122,7 +122,7 @@
*/
struct acl_expr {
struct sample_expr *smp; /* the sample expression we depend on */
- struct pattern_expr pat; /* the pattern matching expression */
+ struct pattern_head pat; /* the pattern matching expression */
struct list list; /* chaining */
const char *kw; /* points to the ACL kw's name or fetch's name (must not free) */
};
diff --git a/include/types/map.h b/include/types/map.h
index 59c1a22..f274e27 100644
--- a/include/types/map.h
+++ b/include/types/map.h
@@ -22,7 +22,8 @@
#ifndef _TYPES_MAP_H
#define _TYPES_MAP_H
-#include <types/acl.h>
+#include <types/pattern.h>
+#include <types/sample.h>
/* These structs contains a string representation of the map. These struct is
* sorted by file. Permit to hot-add and hot-remove entries.
@@ -31,33 +32,10 @@
*/
extern struct list maps;
-struct map_reference {
- struct list list; /* used for listing */
- char *reference; /* contain the unique identifier used as map identifier.
- in many cases this identifier is the filename that contain
- the patterns */
- struct list entries; /* the list of all the entries of the map. This
- is a list of "struct map_entry" */
- struct list maps; /* the list of all maps associated with the file
- name identifier. This is a list of struct map_descriptor */
-};
-
-struct map_entry {
- struct list list; /* used for listing */
- int line; /* The original line into the file. It is used for log reference.
- If the line is '> 0', this entry is from the original load,
- If the line is '< 0', this entry is modify by dynamux process (CLI) */
- char *key; /* The string containing the key before conversion
- and indexation */
- char *value; /* The string containing the value */
-};
-
-struct sample_storage;
struct map_descriptor {
struct list list; /* used for listing */
- struct map_reference *ref; /* the reference used for unindexed entries */
struct sample_conv *conv; /* original converter descriptor */
- struct pattern_expr *pat; /* the pattern matching associated to the map */
+ struct pattern_head pat; /* the pattern matching associated to the map */
int do_free; /* set if <pat> is the orignal pat and must be freed */
char *default_value; /* a copy of default value. This copy is
useful if the type is str */
diff --git a/include/types/pattern.h b/include/types/pattern.h
index 72022e3..d19bcc1 100644
--- a/include/types/pattern.h
+++ b/include/types/pattern.h
@@ -87,6 +87,30 @@
PAT_MATCH_NUM
};
+#define PAT_REF_MAP 0x1 /* Set if the reference is used by at least one map. */
+#define PAT_REF_ACL 0x2 /* Set if the reference is used by at least one acl. */
+
+/* This struct contain a list of reference strings for dunamically
+ * updatable patterns.
+ */
+struct pat_ref {
+ struct list list; /* Used to chain refs. */
+ unsigned int flags; /* flags PAT_REF_*. */
+ char *reference; /* The reference name. */
+ struct list head; /* The head of the list of struct pat_ref_elt. */
+ struct list pat; /* The head of the list of struct pattern_expr. */
+};
+
+/* This is a part of struct pat_ref. Each entry contain one
+ * pattern and one associated value as original string.
+ */
+struct pat_ref_elt {
+ struct list list; /* Used to chain elements. */
+ char *pattern;
+ char *sample;
+ int line;
+};
+
/* How to store a time range and the valid days in 29 bits */
struct pat_time {
int dow:7; /* 1 bit per day of week: 0-6 */
@@ -154,6 +178,17 @@
* are grouped together in order to optimize caching.
*/
struct pattern_expr {
+ struct list listh; /* Used for chaining pattern_expr in pattern_head. */
+ struct list listr; /* Used for chaining pattern_expr in pat_ref. */
+ struct pat_ref *ref; /* The pattern reference if exists. */
+ struct pattern_head *pat_head; /* Point to the pattern_head that contain manipulation functions. */
+ struct list patterns; /* list of acl_patterns */
+ struct eb_root pattern_tree; /* may be used for lookup in large datasets */
+ struct eb_root pattern_tree_2; /* may be used for different types */
+};
+
+/* This struct contain a list of pattern expr */
+struct pattern_head {
int (*parse)(const char *text, struct pattern *pattern, char **err);
int (*parse_smp)(const char *text, struct sample_storage *smp);
int (*index)(struct pattern_expr *, struct pattern *, char **);
@@ -161,9 +196,8 @@
struct sample_storage **(*find_smp)(struct pattern_expr *, struct pattern *);
void (*prune)(struct pattern_expr *);
struct pattern *(*match)(struct sample *, struct pattern_expr *, int);
- struct list patterns; /* list of acl_patterns */
- struct eb_root pattern_tree; /* may be used for lookup in large datasets */
- struct eb_root pattern_tree_2; /* may be used for different types */
+
+ struct list head;
};
extern char *pat_match_names[PAT_MATCH_NUM];
@@ -175,4 +209,7 @@
extern struct pattern *(*pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern_expr *, int);
extern int pat_match_types[PAT_MATCH_NUM];
+/* This is the root of the list of all pattern_ref avalaibles. */
+extern struct list pattern_reference;
+
#endif /* _TYPES_PATTERN_H */
diff --git a/include/types/stream_interface.h b/include/types/stream_interface.h
index 16c127d..8049fcc 100644
--- a/include/types/stream_interface.h
+++ b/include/types/stream_interface.h
@@ -142,9 +142,11 @@
void *ptr; /* multi-purpose pointer for peers */
} peers;
struct {
- struct map_reference *ref;
- struct map_entry *ent;
+ unsigned int display_flags;
+ struct pat_ref *ref;
+ struct pat_ref_elt *elt;
struct map_descriptor *desc;
+ struct pattern_expr *expr;
struct chunk chunk;
} map;
} ctx; /* used by stats I/O handlers to dump the stats */