projects
/
trust_router.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Change most while loops over TR_LISTs to for loops
[trust_router.git]
/
common
/
tr_filter_encoders.c
diff --git
a/common/tr_filter_encoders.c
b/common/tr_filter_encoders.c
index
d4d925d
..
932be9e
100644
(file)
--- a/
common/tr_filter_encoders.c
+++ b/
common/tr_filter_encoders.c
@@
-58,11
+58,18
@@
do { \
typedef json_t *(ITEM_ENCODER_FUNC)(void *);
typedef json_t *(ITEM_ENCODER_FUNC)(void *);
-enum
type_to_array
{
-
TYPE_TO_ARRAY
_FSPEC,
-
TYPE_TO_ARRAY
_CONSTRAINT
+enum
array_type
{
+
ARRAY_TYPE
_FSPEC,
+
ARRAY_TYPE
_CONSTRAINT
};
};
-static json_t *tr_names_to_json_array(void *obj, enum type_to_array type)
+/**
+ * Make an array of matches from a TR_FSPEC or TR_CONSTRAINT
+ *
+ * @param obj
+ * @param type
+ * @return
+ */
+static json_t *tr_names_to_json_array(void *obj, enum array_type type)
{
json_t *jarray = json_array();
json_t *retval = NULL;
{
json_t *jarray = json_array();
json_t *retval = NULL;
@@
-74,22
+81,22
@@
static json_t *tr_names_to_json_array(void *obj, enum type_to_array type)
goto cleanup;
switch(type) {
goto cleanup;
switch(type) {
- case
TYPE_TO_ARRAY
_FSPEC:
+ case
ARRAY_TYPE
_FSPEC:
this_match = tr_fspec_iter_first(&fspec_iter, (TR_FSPEC *)obj);
break;
this_match = tr_fspec_iter_first(&fspec_iter, (TR_FSPEC *)obj);
break;
- case
TYPE_TO_ARRAY
_CONSTRAINT:
+ case
ARRAY_TYPE
_CONSTRAINT:
this_match = tr_constraint_iter_first(&cons_iter, (TR_CONSTRAINT *)obj);
break;
}
while(this_match) {
ARRAY_APPEND_OR_FAIL(jarray, tr_name_to_json_string(this_match));
switch(type) {
this_match = tr_constraint_iter_first(&cons_iter, (TR_CONSTRAINT *)obj);
break;
}
while(this_match) {
ARRAY_APPEND_OR_FAIL(jarray, tr_name_to_json_string(this_match));
switch(type) {
- case
TYPE_TO_ARRAY
_FSPEC:
+ case
ARRAY_TYPE
_FSPEC:
this_match = tr_fspec_iter_next(&fspec_iter);
break;
this_match = tr_fspec_iter_next(&fspec_iter);
break;
- case
TYPE_TO_ARRAY
_CONSTRAINT:
+ case
ARRAY_TYPE
_CONSTRAINT:
this_match = tr_constraint_iter_next(&cons_iter);
break;
}
this_match = tr_constraint_iter_next(&cons_iter);
break;
}
@@
-117,7
+124,7
@@
static json_t *tr_fspec_to_json(TR_FSPEC *fspec)
OBJECT_SET_OR_FAIL(fspec_json, "field",
tr_name_to_json_string(fspec->field));
OBJECT_SET_OR_FAIL(fspec_json, "matches",
OBJECT_SET_OR_FAIL(fspec_json, "field",
tr_name_to_json_string(fspec->field));
OBJECT_SET_OR_FAIL(fspec_json, "matches",
- tr_names_to_json_array(fspec,
TYPE_TO_ARRAY
_FSPEC));
+ tr_names_to_json_array(fspec,
ARRAY_TYPE
_FSPEC));
/* succeeded - set the return value and increment the reference count */
retval = fspec_json;
/* succeeded - set the return value and increment the reference count */
retval = fspec_json;
@@
-139,10
+146,10
@@
static json_t *tr_fspecs_to_json_array(TR_FLINE *fline)
if ((jarray == NULL) || (iter == NULL))
goto cleanup;
if ((jarray == NULL) || (iter == NULL))
goto cleanup;
- this_fspec = tr_fline_iter_first(iter, fline);
- while(this_fspec) {
+ for (this_fspec = tr_fline_iter_first(iter, fline);
+ this_fspec != NULL;
+ this_fspec = tr_fline_iter_next(iter)) {
ARRAY_APPEND_OR_FAIL(jarray, tr_fspec_to_json(this_fspec));
ARRAY_APPEND_OR_FAIL(jarray, tr_fspec_to_json(this_fspec));
- this_fspec = tr_fline_iter_next(iter);
}
/* success */
retval = jarray;
}
/* success */
retval = jarray;
@@
-172,11
+179,11
@@
static json_t *tr_fline_to_json(TR_FLINE *fline)
tr_fspecs_to_json_array(fline));
if (fline->realm_cons) {
OBJECT_SET_OR_FAIL(fline_json, "realm_constraints",
tr_fspecs_to_json_array(fline));
if (fline->realm_cons) {
OBJECT_SET_OR_FAIL(fline_json, "realm_constraints",
- tr_names_to_json_array(fline->realm_cons,
TYPE_TO_ARRAY
_CONSTRAINT));
+ tr_names_to_json_array(fline->realm_cons,
ARRAY_TYPE
_CONSTRAINT));
}
if (fline->domain_cons) {
OBJECT_SET_OR_FAIL(fline_json, "domain_constraints",
}
if (fline->domain_cons) {
OBJECT_SET_OR_FAIL(fline_json, "domain_constraints",
- tr_names_to_json_array(fline->domain_cons,
TYPE_TO_ARRAY
_CONSTRAINT));
+ tr_names_to_json_array(fline->domain_cons,
ARRAY_TYPE
_CONSTRAINT));
}
/* succeeded - set the return value and increment the reference count */
}
/* succeeded - set the return value and increment the reference count */
@@
-199,10
+206,10
@@
static json_t *tr_flines_to_json_array(TR_FILTER *filt)
if ((jarray == NULL) || (iter == NULL))
goto cleanup;
if ((jarray == NULL) || (iter == NULL))
goto cleanup;
- this_fline = tr_filter_iter_first(iter, filt);
- while(this_fline) {
+ for(this_fline = tr_filter_iter_first(iter, filt);
+ this_fline != NULL;
+ this_fline = tr_filter_iter_next(iter)) {
ARRAY_APPEND_OR_FAIL(jarray, tr_fline_to_json(this_fline));
ARRAY_APPEND_OR_FAIL(jarray, tr_fline_to_json(this_fline));
- this_fline = tr_filter_iter_next(iter);
}
/* success */
retval = jarray;
}
/* success */
retval = jarray;