Full support for rp_permitted filters using new filter structures, etc.
[trust_router.git] / include / tr_filter.h
1 /*
2  * Copyright (c) 2012, 2013, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31  * OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34
35 #ifndef TR_FILTER_H
36 #define TR_FILTER_H
37
38 #include <trust_router/tr_name.h>
39 #include <jansson.h>
40
41 #define TR_MAX_FILTERS  5
42 #define TR_MAX_FILTER_LINES 8
43 #define TR_MAX_FILTER_SPECS 8
44 #define TR_MAX_CONS_VALUES  8
45
46 /* Filter actions */
47 #define TR_FILTER_ACTION_REJECT 0
48 #define TR_FILTER_ACTION_ACCEPT 1
49
50 /* Match codes */
51 #define TR_FILTER_MATCH 0
52 #define TR_FILTER_NO_MATCH 1
53
54 /* Filter types */
55 #define TR_FILTER_TYPE_RP_PERMITTED 0
56 /* Other types TBD */
57
58 typedef json_t TR_CONSTRAINT_SET;
59
60 typedef struct tr_constraint {
61   TR_NAME values[TR_MAX_CONS_VALUES];
62 } TR_CONSTRAINT;
63
64 typedef struct tr_fspec {
65   TR_NAME *field;
66   TR_NAME *match;
67 } TR_FSPEC;
68
69 typedef struct tr_fline {
70   int action;
71   TR_FSPEC *specs[TR_MAX_FILTER_SPECS];
72   TR_CONSTRAINT_SET *constraints;
73 } TR_FLINE;
74   
75 typedef struct tr_filter {
76   int type;
77   TR_FLINE *lines[TR_MAX_FILTER_LINES];
78 } TR_FILTER;
79
80 void tr_filter_free (TR_FILTER *filt);
81 int tr_prefix_wildcard_match (char *str, char *wc_str);
82 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);
83 #endif