Use the the peer table iterator correctly
[trust_router.git] / trp / trp_ptable_encoders.c
index f584c2b..db2658c 100644 (file)
@@ -55,3 +55,18 @@ char *trp_ptable_to_str(TALLOC_CTX *memctx, TRP_PTABLE *ptbl, const char *sep, c
   talloc_free(tmpctx); /* free detritus */
   return result;
 }
+
+json_t *trp_ptable_to_json(TRP_PTABLE *ptbl)
+{
+  TRP_PTABLE_ITER *iter = trp_ptable_iter_new(NULL);
+  json_t *ptbl_json = json_array();
+  TRP_PEER *peer = NULL;
+
+  for (peer = 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));
+  }
+  trp_ptable_iter_free(iter);
+  return ptbl_json;
+}