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;
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);