Refactor TR_FILTER using a GPtrArray of filter lines
[trust_router.git] / include / tr_filter.h
index bbee2dc..caabe5d 100644 (file)
 
 #include <talloc.h>
 #include <jansson.h>
+#include <glib.h>
 
-#include <trust_router/tr_name.h>
+#include <tr_name_internal.h>
 #include <trust_router/tr_constraint.h>
 #include <trust_router/tid.h>
 #include <trust_router/trp.h>
 
-#define TR_MAX_FILTERS  5
-#define TR_MAX_FILTER_LINES 8
 #define TR_MAX_FILTER_SPECS 8
-#define TR_MAX_FILTER_SPEC_MATCHES 8
+#define TR_MAX_FILTER_SPEC_MATCHES 64
 
 /* Filter actions */
-typedef enum {
+typedef enum tr_filter_action {
   TR_FILTER_ACTION_REJECT = 0,
   TR_FILTER_ACTION_ACCEPT,
   TR_FILTER_ACTION_UNKNOWN
@@ -81,9 +80,13 @@ typedef struct tr_fline {
 
 typedef struct tr_filter {
   TR_FILTER_TYPE type;
-  TR_FLINE *lines[TR_MAX_FILTER_LINES];
+  GPtrArray *lines;
 } TR_FILTER;
 
+typedef struct tr_filter_iter {
+  TR_FILTER *filter;
+  guint ii;
+} TR_FILTER_ITER;
 
 typedef struct tr_filter_set TR_FILTER_SET;
 struct tr_filter_set {
@@ -91,18 +94,29 @@ struct tr_filter_set {
   TR_FILTER_SET *next;
 };
 
+/**
+ * Structure to hold information needed to filter different targets.
+ */
+typedef struct tr_filter_target {
+  /* An inforec also needs realm and community information */
+  TRP_INFOREC *trp_inforec;
+  TRP_UPD *trp_upd;
+
+  /* a TID request has all the data it needs to be filtered */
+  TID_REQ *tid_req;
+} TR_FILTER_TARGET;
+
 TR_FILTER_SET *tr_filter_set_new(TALLOC_CTX *mem_ctx);
 void tr_filter_set_free(TR_FILTER_SET *fs);
 int tr_filter_set_add(TR_FILTER_SET *set, TR_FILTER *new);
 TR_FILTER *tr_filter_set_get(TR_FILTER_SET *set, TR_FILTER_TYPE type);
 
 TR_FILTER *tr_filter_new(TALLOC_CTX *mem_ctx);
-
 void tr_filter_free(TR_FILTER *filt);
 
 void tr_filter_set_type(TR_FILTER *filt, TR_FILTER_TYPE type);
-
 TR_FILTER_TYPE tr_filter_get_type(TR_FILTER *filt);
+TR_FLINE *tr_filter_add_line(TR_FILTER *filt, TR_FLINE *line);
 
 TR_FLINE *tr_fline_new(TALLOC_CTX *mem_ctx);
 
@@ -114,13 +128,20 @@ void tr_fspec_free(TR_FSPEC *fspec);
 
 void tr_fspec_add_match(TR_FSPEC *fspec, TR_NAME *match);
 
-int tr_fspec_matches(TR_FSPEC *fspec, TR_FILTER_TYPE ftype, void *target);
+int tr_fspec_matches(TR_FSPEC *fspec, TR_FILTER_TYPE ftype, TR_FILTER_TARGET *target);
 
+TR_FILTER_ITER *tr_filter_iter_new(TALLOC_CTX *mem_ctx);
+void tr_filter_iter_free(TR_FILTER_ITER *iter);
+TR_FLINE *tr_filter_iter_first(TR_FILTER_ITER *iter, TR_FILTER *filter);
+TR_FLINE *tr_filter_iter_next(TR_FILTER_ITER *iter);
 
 /*In tr_constraint.c and exported, but not really a public symbol; needed by tr_filter.c and by tr_constraint.c*/
 int TR_EXPORT tr_prefix_wildcard_match(const char *str, const char *wc_str);
 
-int tr_filter_apply(void *target, TR_FILTER *filt, TR_CONSTRAINT_SET **constraints, TR_FILTER_ACTION *out_action);
+int tr_filter_apply(TR_FILTER_TARGET *target, TR_FILTER *filt, TR_CONSTRAINT_SET **constraints, TR_FILTER_ACTION *out_action);
+void tr_filter_target_free(TR_FILTER_TARGET *target);
+TR_FILTER_TARGET *tr_filter_target_tid_req(TALLOC_CTX *mem_ctx, TID_REQ *req);
+TR_FILTER_TARGET *tr_filter_target_trp_inforec(TALLOC_CTX *mem_ctx, TRP_UPD *upd, TRP_INFOREC *inforec);
 
 TR_CONSTRAINT_SET *tr_constraint_set_from_fline(TR_FLINE *fline);
 
@@ -129,4 +150,7 @@ int tr_filter_validate_spec_field(TR_FILTER_TYPE ftype, TR_FSPEC *fspec);
 const char *tr_filter_type_to_string(TR_FILTER_TYPE ftype);
 TR_FILTER_TYPE tr_filter_type_from_string(const char *s);
 
+/* tr_filter_encoders.c */
+json_t *tr_filter_set_to_json(TR_FILTER_SET *filter_set);
+
 #endif