Reimplementing tr_config.c to use new config file format. Not done.
[trust_router.git] / include / tr_filter.h
index 718dca0..da613fd 100644 (file)
 #ifndef TR_FILTER_H
 #define TR_FILTER_H
 
+#include <talloc.h>
+#include <jansson.h>
+
 #include <trust_router/tr_name.h>
 #include <trust_router/tr_constraint.h>
-#include <jansson.h>
 
 #define TR_MAX_FILTERS 5
 #define TR_MAX_FILTER_LINES 8
 #define TR_MAX_FILTER_SPECS 8
 
 /* Filter actions */
-#define TR_FILTER_ACTION_REJECT 0
-#define TR_FILTER_ACTION_ACCEPT 1
+typedef enum {
+  TR_FILTER_ACTION_REJECT=0,
+  TR_FILTER_ACTION_ACCEPT,
+  TR_FILTER_ACTION_UNKNOWN
+} TR_FILTER_ACTION;
 
 /* Match codes */
 #define TR_FILTER_MATCH 0
 #define TR_FILTER_NO_MATCH 1
 
 /* Filter types */
-#define TR_FILTER_TYPE_RP_PERMITTED 0
-/* Other types TBD */
+typedef enum {
+  TR_FILTER_TYPE_TID_INCOMING=0,
+  TR_FILTER_TYPE_UNKNOWN
+} TR_FILTER_TYPE;
+/* #define for backward compatibility, TODO: get rid of this -jlr */
+#define TR_FILTER_TYPE_RP_PERMITTED TR_FILTER_TYPE_TID_INCOMING
+
 
 typedef struct tr_fspec {
   TR_NAME *field;
@@ -61,18 +71,28 @@ typedef struct tr_fspec {
 } TR_FSPEC;
 
 typedef struct tr_fline {
-  int action;
+  TR_FILTER_ACTION action;
   TR_FSPEC *specs[TR_MAX_FILTER_SPECS];
   TR_CONSTRAINT *realm_cons;
   TR_CONSTRAINT *domain_cons;
 } TR_FLINE;
   
 typedef struct tr_filter {
-  int type;
+  TR_FILTER_TYPE type;
   TR_FLINE *lines[TR_MAX_FILTER_LINES];
 } TR_FILTER;
 
-void tr_filter_free (TR_FILTER *filt);
+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_fline_new(TALLOC_CTX *mem_ctx);
+void tr_fline_free(TR_FLINE *fline);
+TR_FSPEC *tr_fspec_new(TALLOC_CTX *mem_ctx);
+void tr_fspec_free(TR_FSPEC *fspec);
+
+
 /*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_process_rp_permitted (TR_NAME *rp_realm, TR_FILTER *rpp_filter, TR_CONSTRAINT_SET *in_constraints, TR_CONSTRAINT_SET **out_constraints, int *out_action);