#include <tr_util.h>
#include <tr_debug.h>
-/**
- * Convert TR_NAME n to a JSON string, returning the empty string if n is null
- */
-static json_t *safe_name_to_json_string(TR_NAME *n)
-{
- if (n)
- return tr_name_to_json_string(n);
- else
- return json_string("");
-}
-
static json_t *expiry_to_json_string(TR_COMM_MEMB *memb)
{
- struct timespec ts_zero = {0, 0};
+ struct timespec ts = {0}; /* initialization to zero is important */
char *s = NULL;
json_t *jstr = NULL;
- if (tr_cmp_timespec(tr_comm_memb_get_expiry(memb), &ts_zero) == 0) {
- s = strdup("");
- } else {
- s = timespec_to_str(tr_comm_memb_get_expiry(memb));
- }
+ if (tr_cmp_timespec(tr_comm_memb_get_expiry(memb), &ts) > 0) {
+ if (tr_comm_memb_get_expiry_realtime(memb, &ts) == NULL)
+ s = strdup("error");
+ else
+ s = timespec_to_str(&ts);
- if (s) {
- jstr = json_string(s);
- free(s);
+ if (s) {
+ jstr = json_string(s);
+ free(s);
+ }
}
return jstr;
OBJECT_SET_OR_FAIL(memb_json, "origin", json_string("file"));
} else {
OBJECT_SET_OR_FAIL(memb_json, "origin",
- safe_name_to_json_string(tr_comm_memb_get_origin(memb)));
+ tr_name_to_json_string(tr_comm_memb_get_origin(memb)));
OBJECT_SET_OR_FAIL(memb_json, "provenance",
provenance_to_json(memb));
OBJECT_SET_OR_FAIL(memb_json, "expires",
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));
- memb = tr_comm_memb_iter_next(iter);
}
/* success */
TR_COMM_MEMB *memb = NULL;
iter = tr_comm_iter_new(NULL);
- realm = tr_realm_iter_first(iter, ctable, comm_name);
+ realm = NULL;
/* Do not display the full realm json here, only the name and info relevant to the community listing */
- while(realm) {
+ 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",
tr_name_to_json_string(tr_realm_get_id(realm)));
- memb = tr_comm_table_find_idp_memb(ctable,
- tr_realm_get_id(realm),
- comm_name);
+ memb = tr_comm_table_find_memb(ctable,
+ tr_realm_get_id(realm),
+ comm_name);
+ if (memb == NULL) {
+ /* This should not happen - there must be a matching membership if we
+ * believed the realm was in the community in the first place! */
+ goto cleanup;
+ }
OBJECT_SET_OR_FAIL(realm_json, "sources",
tr_comm_memb_sources_to_json(memb));
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 */
}
OBJECT_SET_OR_FAIL(comm_json, "name",
tr_name_to_json_string(tr_comm_get_id(comm)));
- OBJECT_SET_OR_FAIL(comm_json, "owner_realm",
- safe_name_to_json_string(tr_comm_get_owner_realm(comm)));
- OBJECT_SET_OR_FAIL(comm_json, "owner_contact",
- safe_name_to_json_string(tr_comm_get_owner_contact(comm)));
-
+ if (tr_comm_get_owner_realm(comm)) {
+ OBJECT_SET_OR_FAIL(comm_json, "owner_realm",
+ tr_name_to_json_string(tr_comm_get_owner_realm(comm)));
+ }
+ if (tr_comm_get_owner_contact(comm)) {
+ OBJECT_SET_OR_FAIL(comm_json, "owner_contact",
+ tr_name_to_json_string(tr_comm_get_owner_contact(comm)));
+ }
OBJECT_SET_OR_FAIL(comm_json, "idp_realms",
tr_comm_realms_to_json(ctable, tr_comm_get_id(comm), TR_ROLE_IDP));
OBJECT_SET_OR_FAIL(comm_json, "rp_realms",
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 = tr_comm_table_iter_next(iter);
}
/* succeeded - set the return value and increment the reference count */