Normalize port naming (tids_, trps_, and mons_port) and use signed int
[trust_router.git] / trp / trp_peer_encoders.c
index 4e8d57e..48f74c5 100644 (file)
@@ -38,6 +38,7 @@
 #include <tr_gss_names.h>
 #include <trp_peer.h>
 #include <tr_util.h>
+#include <tr_json_util.h>
 
 char *trp_peer_to_str(TALLOC_CTX *memctx, TRP_PEER *peer, const char *sep)
 {
@@ -50,7 +51,7 @@ char *trp_peer_to_str(TALLOC_CTX *memctx, TRP_PEER *peer, const char *sep)
 }
 
 /* helper for encoding to json */
-static json_t *server_to_json_string(const char *server, unsigned int port)
+static json_t *server_to_json_string(const char *server, int port)
 {
   char *s = talloc_asprintf(NULL, "%s:%u", server, port);
   json_t *jstr = json_string(s);
@@ -64,29 +65,18 @@ static json_t *last_attempt_to_json_string(TRP_PEER *peer)
   char *s = NULL;
   json_t *jstr = NULL;
 
-  if (tr_cmp_timespec(trp_peer_get_last_conn_attempt(peer), &ts_zero) == 0) {
-    s = strdup("");
-  } else {
+  if (tr_cmp_timespec(trp_peer_get_last_conn_attempt(peer), &ts_zero) > 0) {
     s = timespec_to_str(trp_peer_get_last_conn_attempt(peer));
-  }
 
-  if (s) {
-    jstr = json_string(s);
-    free(s);
+    if (s) {
+      jstr = json_string(s);
+      free(s);
+    }
   }
 
   return jstr;
 }
 
-/* helper for below */
-#define OBJECT_SET_OR_FAIL(jobj, key, val)     \
-do {                                           \
-  if (val)                                     \
-    json_object_set_new((jobj),(key),(val));   \
-  else                                         \
-    goto cleanup;                              \
-} while (0)
-
 json_t *trp_peer_to_json(TRP_PEER *peer)
 {
   json_t *peer_json = NULL;
@@ -112,6 +102,8 @@ json_t *trp_peer_to_json(TRP_PEER *peer)
                      last_attempt_to_json_string(peer));
   OBJECT_SET_OR_FAIL(peer_json, "allowed_credentials",
                      tr_gss_names_to_json_array(trp_peer_get_gss_names(peer)));
+  OBJECT_SET_OR_FAIL(peer_json, "filters",
+                     tr_filter_set_to_json(peer->filters));
 
   /* succeeded - set the return value and increment the reference count */
   retval = peer_json;