X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=trp%2Ftrp_route_encoders.c;h=ad913dac6300032e353f96e580204a2bcbcb62c1;hb=a445d02a6c0b4c8c41276d511111ccf0c5003f43;hp=c954a81353048867fa95d3cf09873abe9e5bad5b;hpb=81a61f8c6064bf52ff2a40a3d28e6ee5b2e478d4;p=trust_router.git diff --git a/trp/trp_route_encoders.c b/trp/trp_route_encoders.c index c954a81..ad913da 100644 --- a/trp/trp_route_encoders.c +++ b/trp/trp_route_encoders.c @@ -44,6 +44,8 @@ #include #include #include +#include +#include /* Pretty print a route table entry to a newly allocated string. If sep is NULL, * returns comma+space separated string. */ @@ -61,13 +63,13 @@ char *trp_route_to_str(TALLOC_CTX *mem_ctx, TRP_ROUTE *entry, const char *sep) sep=", "; result=talloc_asprintf(mem_ctx, - "%s%s%s%s%s%s%u%s%s%s%s%s%u%s%u%s%s%s%u", + "%s%s%s%s%s%s%u%s%s:%d%s%s:%d%s%u%s%u%s%s%s%u", comm, sep, realm, sep, peer, sep, entry->metric, sep, - trust_router, sep, - next_hop, sep, + trust_router, entry->trust_router_port, sep, + next_hop, entry->next_hop_port, sep, entry->selected, sep, entry->local, sep, expiry, sep, @@ -103,25 +105,11 @@ static json_t *expiry_to_json_string(TRP_ROUTE *route) 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) - -#define OBJECT_SET_OR_SKIP(jobj, key, val) \ -do { \ - if (val) \ - json_object_set_new((jobj),(key),(val)); \ -} while (0) - json_t *trp_route_to_json(TRP_ROUTE *route) { json_t *route_json = NULL; json_t *retval = NULL; + TR_NAME *n; route_json = json_object(); if (route_json == NULL) @@ -132,9 +120,25 @@ json_t *trp_route_to_json(TRP_ROUTE *route) if (trp_route_get_peer(route)->len > 0) OBJECT_SET_OR_FAIL(route_json, "peer", tr_name_to_json_string(trp_route_get_peer(route))); OBJECT_SET_OR_FAIL(route_json, "metric", json_integer(trp_route_get_metric(route))); - OBJECT_SET_OR_FAIL(route_json, "trust_router", tr_name_to_json_string(trp_route_get_trust_router(route))); - if (trp_route_get_next_hop(route)->len > 0) - OBJECT_SET_OR_FAIL(route_json, "next_hop", tr_name_to_json_string(trp_route_get_next_hop(route))); + + /* add trust_router as hostname:port */ + n = tr_hostname_and_port_to_name( + trp_route_get_trust_router(route), + trp_route_get_trust_router_port(route)); + if (n == NULL) + goto cleanup; + OBJECT_SET_OR_FAIL(route_json, "trust_router", tr_name_to_json_string(n)); + tr_free_name(n); + + /* add next_hop as hostname:port */ + n = tr_hostname_and_port_to_name( + trp_route_get_next_hop(route), + trp_route_get_next_hop_port(route)); + if (n == NULL) + goto cleanup; + OBJECT_SET_OR_FAIL(route_json, "next_hop", tr_name_to_json_string(n)); + tr_free_name(n); + OBJECT_SET_OR_FAIL(route_json, "selected", json_boolean(trp_route_is_selected(route))); OBJECT_SET_OR_FAIL(route_json, "local", json_boolean(trp_route_is_local(route))); OBJECT_SET_OR_SKIP(route_json, "expires", expiry_to_json_string(route));