summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
77c4587)
The while loop patter (i = first(); while(i){blah; i = next()}) pattern
was error-prone -- too easy to overlook or forget the next() call.
Changed most of these to for loops to make the iteration more apparent.
Added a few comments. No intentional functional changes.
goto cleanup;
/* Iterate over all the memberships for this realm/comm pair that come from different origins */
goto cleanup;
/* Iterate over all the memberships for this realm/comm pair that come from different origins */
- memb = tr_comm_memb_iter_first(iter, first_memb);
- while (memb) {
+ for (memb = tr_comm_memb_iter_first(iter, first_memb);
+ memb != NULL;
+ memb = tr_comm_memb_iter_next(iter)) {
ARRAY_APPEND_OR_FAIL(jarray, tr_comm_memb_to_json(memb));
ARRAY_APPEND_OR_FAIL(jarray, tr_comm_memb_to_json(memb));
- memb = tr_comm_memb_iter_next(iter);
TR_COMM_MEMB *memb = NULL;
iter = tr_comm_iter_new(NULL);
TR_COMM_MEMB *memb = NULL;
iter = tr_comm_iter_new(NULL);
- realm = tr_realm_iter_first(iter, ctable, comm_name);
/* Do not display the full realm json here, only the name and info relevant to the community listing */
/* Do not display the full realm json here, only the name and info relevant to the community listing */
+ for (realm = tr_realm_iter_first(iter, ctable, comm_name);
+ realm != NULL;
+ realm = tr_realm_iter_next(iter)) {
if (realm->role == role) {
realm_json = json_object();
OBJECT_SET_OR_FAIL(realm_json, "realm",
if (realm->role == role) {
realm_json = json_object();
OBJECT_SET_OR_FAIL(realm_json, "realm",
json_array_append_new(jarray, realm_json);
realm_json = NULL; /* so we don't free this twice during cleanup */
}
json_array_append_new(jarray, realm_json);
realm_json = NULL; /* so we don't free this twice during cleanup */
}
- realm = tr_realm_iter_next(iter);
}
/* Success - increment the reference count so return value survives */
}
/* Success - increment the reference count so return value survives */
goto cleanup;
/* Iterate over communities in the table */
goto cleanup;
/* Iterate over communities in the table */
- comm = tr_comm_table_iter_first(iter, ctable);
- while (comm) {
+ for (comm = tr_comm_table_iter_first(iter, ctable);
+ comm != NULL;
+ comm = tr_comm_table_iter_next(iter)) {
comm_json = tr_comm_to_json(ctable, comm);
if (comm_json == NULL)
goto cleanup;
json_array_append_new(ctable_json, comm_json);
comm_json = tr_comm_to_json(ctable, comm);
if (comm_json == NULL)
goto cleanup;
json_array_append_new(ctable_json, comm_json);
- comm = tr_comm_table_iter_next(iter);
}
/* succeeded - set the return value and increment the reference count */
}
/* succeeded - set the return value and increment the reference count */
/* Step through filter lines looking for a match. If a line matches, retval
* will be set to TR_FILTER_MATCH, so stop then. */
/* Step through filter lines looking for a match. If a line matches, retval
* will be set to TR_FILTER_MATCH, so stop then. */
- this_fline = tr_filter_iter_first(filt_iter, filt);
- while(this_fline) {
+ for (this_fline = tr_filter_iter_first(filt_iter, filt);
+ this_fline != NULL;
+ this_fline = tr_filter_iter_next(filt_iter)) {
/* Assume we are going to succeed. If any specs fail to match, we'll set
* this to TR_FILTER_NO_MATCH. */
retval=TR_FILTER_MATCH;
/* Assume we are going to succeed. If any specs fail to match, we'll set
* this to TR_FILTER_NO_MATCH. */
retval=TR_FILTER_MATCH;
- this_fspec = tr_fline_iter_first(fline_iter, this_fline);
- while(this_fspec) {
+ for (this_fspec = tr_fline_iter_first(fline_iter, this_fline);
+ this_fspec != NULL;
+ this_fspec = tr_fline_iter_next(fline_iter)) {
if (!tr_fspec_matches(this_fspec, filt->type, target)) {
retval=TR_FILTER_NO_MATCH; /* set this in case this is the last filter line */
break; /* give up on this filter line */
}
if (!tr_fspec_matches(this_fspec, filt->type, target)) {
retval=TR_FILTER_NO_MATCH; /* set this in case this is the last filter line */
break; /* give up on this filter line */
}
- this_fspec = tr_fline_iter_next(fline_iter);
}
if (retval==TR_FILTER_MATCH)
break;
}
if (retval==TR_FILTER_MATCH)
break;
- this_fline = tr_filter_iter_next(filt_iter);
}
if (retval==TR_FILTER_MATCH) {
}
if (retval==TR_FILTER_MATCH) {
return 0; /* if we get here, either TR_FILTER_TYPE_UNKNOWN or an invalid value was found */
}
return 0; /* if we get here, either TR_FILTER_TYPE_UNKNOWN or an invalid value was found */
}
- this_fline = tr_filter_iter_first(filt_iter, filt);
- while(this_fline) {
+ for (this_fline = tr_filter_iter_first(filt_iter, filt);
+ this_fline != NULL;
+ this_fline = tr_filter_iter_next(filt_iter)) {
/* check that we recognize the action */
switch(this_fline->action) {
case TR_FILTER_ACTION_ACCEPT:
/* check that we recognize the action */
switch(this_fline->action) {
case TR_FILTER_ACTION_ACCEPT:
- this_fspec = tr_fline_iter_first(fline_iter, this_fline);
- while(this_fspec) {
+ for (this_fspec = tr_fline_iter_first(fline_iter, this_fline);
+ this_fspec != NULL;
+ this_fspec = tr_fline_iter_next(fline_iter)) {
if (!tr_filter_validate_spec_field(filt->type, this_fspec)) {
talloc_free(tmp_ctx);
return 0;
if (!tr_filter_validate_spec_field(filt->type, this_fspec)) {
talloc_free(tmp_ctx);
return 0;
talloc_free(tmp_ctx);
return 0;
}
talloc_free(tmp_ctx);
return 0;
}
- this_fspec = tr_fline_iter_next(fline_iter);
- this_fline = tr_filter_iter_next(filt_iter);
}
/* We ran the gauntlet. Success! */
}
/* We ran the gauntlet. Success! */
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;
goto cleanup;
switch(type) {
goto cleanup;
switch(type) {
- case TYPE_TO_ARRAY_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:
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;
}
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;
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;
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 */
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;
talloc_free(tmp_ctx);
return NULL;
}
talloc_free(tmp_ctx);
return NULL;
}
- this = tr_gss_names_iter_first(iter, orig);
- while (this) {
+ for (this = tr_gss_names_iter_first(iter, orig);
+ this != NULL;
+ this = tr_gss_names_iter_next(iter)) {
if (tr_gss_names_add(new, tr_dup_name(this)) != 0) {
talloc_free(tmp_ctx);
return NULL;
}
if (tr_gss_names_add(new, tr_dup_name(this)) != 0) {
talloc_free(tmp_ctx);
return NULL;
}
- this = tr_gss_names_iter_next(iter);
}
/* success */
talloc_steal(mem_ctx, new);
}
/* success */
talloc_steal(mem_ctx, new);
if ((jarray == NULL) || (iter == NULL))
goto cleanup;
if ((jarray == NULL) || (iter == NULL))
goto cleanup;
- apc = tr_apc_iter_first(iter, apcs);
- while (apc) {
+ for (apc = tr_apc_iter_first(iter, apcs);
+ apc != NULL;
+ apc = tr_apc_iter_next(iter)) {
ARRAY_APPEND_OR_FAIL(jarray, tr_name_to_json_string(tr_apc_get_id(apc)));
ARRAY_APPEND_OR_FAIL(jarray, tr_name_to_json_string(tr_apc_get_id(apc)));
- apc = tr_apc_iter_next(iter);
if ((jarray == NULL) || (iter == NULL))
goto cleanup;
if ((jarray == NULL) || (iter == NULL))
goto cleanup;
- aaa = tr_aaa_server_iter_first(iter, aaas);
- while (aaa) {
+ for (aaa = tr_aaa_server_iter_first(iter, aaas);
+ aaa != NULL;
+ aaa = tr_aaa_server_iter_next(iter)) {
ARRAY_APPEND_OR_FAIL(jarray, tr_aaa_server_to_json(aaa));
ARRAY_APPEND_OR_FAIL(jarray, tr_aaa_server_to_json(aaa));
- aaa = tr_aaa_server_iter_next(iter);
if ((jarray == NULL) || (iter == NULL))
goto cleanup;
if ((jarray == NULL) || (iter == NULL))
goto cleanup;
- rp_client = tr_rp_client_iter_first(iter, rp_clients);
- while (rp_client) {
+ for (rp_client = tr_rp_client_iter_first(iter, rp_clients);
+ rp_client != NULL;
+ rp_client = tr_rp_client_iter_next(iter)) {
ARRAY_APPEND_OR_FAIL(jarray, tr_rp_client_to_json(rp_client));
ARRAY_APPEND_OR_FAIL(jarray, tr_rp_client_to_json(rp_client));
- rp_client = tr_rp_client_iter_next(iter);
}
/* succeeded - set the return value and increment the reference count */
}
/* succeeded - set the return value and increment the reference count */
{
TRP_PTABLE_ITER *iter = trp_ptable_iter_new(NULL);
json_t *ptbl_json = json_array();
{
TRP_PTABLE_ITER *iter = trp_ptable_iter_new(NULL);
json_t *ptbl_json = json_array();
- TRP_PEER *peer = trp_ptable_iter_first(iter, ptbl);
- while(peer) {
+ TRP_PEER *peer = NULL;
+
+ for (trp_ptable_iter_first(iter, ptbl);
+ peer != NULL;
+ peer = trp_ptable_iter_next(iter)) {
json_array_append_new(ptbl_json, trp_peer_to_json(peer));
json_array_append_new(ptbl_json, trp_peer_to_json(peer));
- peer = trp_ptable_iter_next(iter);
}
trp_ptable_iter_free(iter);
return ptbl_json;
}
trp_ptable_iter_free(iter);
return ptbl_json;