}
}
+static TR_CONSTRAINT *tr_cfg_parse_one_constraint (TR_INSTANCE *tr, const char *ctype, json_t *jdc, TR_CFG_RC *rc)
+{
+ if (NULL == (cons = malloc(sizeof(TR_CONSTRAINT)))) {
+ fprintf(stderr, "tr_cfg_parse_one_constraint: Out of memory.\n");
+ *rc = TR_CFG_NOMEM;
+ return NULL;
+ }
+
+ memset(filt, 0, sizeof(TR_FILTER));
+
+
+}
+
static TR_FILTER *tr_cfg_parse_one_filter (TR_INSTANCE *tr, json_t *jfilt, TR_CFG_RC *rc)
{
TR_FILTER *filt = NULL;
json_t *jfspecs = NULL;
json_t *jffield = NULL;
json_t *jfmatch = NULL;
+ json_t *jrc = NULL;
+ json_t *jdc = NULL;
int i = 0, j = 0;
if ((NULL == (jftype = json_object_get(jfilt, "type"))) ||
return NULL;
}
- /* TBD -- optionally parse realm and domain constraints */
-
if (NULL == (filt = malloc(sizeof(TR_FILTER)))) {
fprintf(stderr, "tr_config_parse_one_filter: Out of memory.\n");
*rc = TR_CFG_NOMEM;
return NULL;
}
- /* TBD -- parse constraints */
+ if ((NULL != (jrc = json_object_get(json_array_get(jfls, i), "realm_constraints"))) &&
+ (json_is_array(jrc)) &&
+ (0 != json_array_size(jrc)) &&
+ (TR_MAX_CONST_MATCHES >= json_array_size(jrc))) {
+ if (NULL == (filt->realm_cons = tr_cfg_parse_one_constraint(tr, "realm", jrc, rc)))
+ fprintf(stderr, "tr_cfg_parse_one_filter: Error parsing realm constraint");
+ tr_filter_free(filt);
+ return NULL;
+ }
+
+ if ((NULL != (jdc = json_object_get(json_array_get(jfls, i), "domain_constraints"))) &&
+ (json_is_array(jdc)) &&
+ (0 != json_array_size(jdc)) &&
+ (TR_MAX_CONST_MATCHES >= json_array_size(jdc))) {
+ if (NULL == (filt->realm_cons = tr_cfg_parse_one_constraint(tr, "domain", jdc, rc)))
+ fprintf(stderr, "tr_cfg_parse_one_filter: Error parsing domain constraint");
+ tr_filter_free(filt);
+ return NULL;
+ }
if ((NULL == (jfspecs = json_object_get(json_array_get(jfls, i), "filter_specs"))) ||
(!json_is_array(jfspecs)) ||
--- /dev/null
+/*
+ * Copyright (c) 2012, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <jansson.h>
+
if (filt->lines[i]->specs[j])
free(filt->lines[i]->specs[j]);
}
+ if (filt->lines[i]->realm_cons)
+ free(filt->lines[i]->realm_cons);
+ if (filt->lines[i]->domain_cons)
+ free(filt->lines[i]->domain_cons);
+
free(filt->lines[i]);
}
}
--- /dev/null
+/*
+ * Copyright (c) 2012, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <jansson.h>
+
+#define TR_MAX_CONST_MATCHES 24;
+
+typedef json_t TR_CONSTRAINT_SET;
+
+typedef tr_constraint {
+ TR_NAME type;
+ TR_NAME matches[TR_MAX_CONST_MATCHES];
+} TR_CONSTRAINT;
#define TR_FILTER_H
#include <trust_router/tr_name.h>
+#include <tr_constraint.h>
#include <jansson.h>
#define TR_MAX_FILTERS 5
#define TR_MAX_FILTER_LINES 8
#define TR_MAX_FILTER_SPECS 8
-#define TR_MAX_CONS_VALUES 8
/* Filter actions */
#define TR_FILTER_ACTION_REJECT 0
#define TR_FILTER_TYPE_RP_PERMITTED 0
/* Other types TBD */
-typedef json_t TR_CONSTRAINT_SET;
-
-typedef struct tr_constraint {
- TR_NAME values[TR_MAX_CONS_VALUES];
-} TR_CONSTRAINT;
-
typedef struct tr_fspec {
TR_NAME *field;
TR_NAME *match;
typedef struct tr_fline {
int action;
TR_FSPEC *specs[TR_MAX_FILTER_SPECS];
- TR_CONSTRAINT_SET *constraints;
+ TR_CONSTRAINT realm_cons;
+ TR_CONSTRAINT domain_cons;
} TR_FLINE;
typedef struct tr_filter {