tr_constraint_set_get_match_strings
[trust_router.git] / include / trust_router / tr_constraint.h
1 /*
2  * Copyright (c) 2012, 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_CONSTRAINT_H
36 #define TR_CONSTRAINT_H
37 #include <trust_router/tr_name.h>
38 #include <trust_router/tid.h>
39
40
41 #define TR_MAX_CONST_MATCHES 24
42
43
44 typedef struct tr_constraint {
45   TR_NAME *type;
46   TR_NAME *matches[TR_MAX_CONST_MATCHES];
47 } TR_CONSTRAINT;
48
49 void TR_EXPORT tr_constraint_add_to_set (TR_CONSTRAINT_SET **cs, TR_CONSTRAINT *c);
50
51 int TR_EXPORT tr_constraint_set_validate( TR_CONSTRAINT_SET *);
52 /**
53  * Create a new constraint set containing all constraints from #orig
54  * with constraint_type #constraint_type and no others.  This constraint set is
55  * live until #request is freed.
56  */
57 TR_EXPORT TR_CONSTRAINT_SET *tr_constraint_set_filter(TID_REQ *request,
58                                    TR_CONSTRAINT_SET *orig,
59                                    const char * constraint_type);
60
61 TR_EXPORT TR_CONSTRAINT_SET
62 *tr_constraint_set_intersect(TID_REQ *request,
63                              TR_CONSTRAINT_SET *input);
64
65 /** Get the set of wildcard strings that matches a fully intersected
66  * constraint set.  Requires that the constraint set only have one
67  * constraint in it, but the constraint may have multiple matches for
68  * a given type.  Returns true on success false on failure.  The
69  * output is live as long as the request is live.
70  */
71 int TR_EXPORT tr_constraint_set_get_match_strings(TID_REQ *,
72                                             TR_CONSTRAINT_SET *,
73                                                   const char * constraint_type,
74                                                   tr_const_string **output,
75                                             size_t *output_len);
76
77  
78 #endif