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) goto cleanup; OBJECT_SET_OR_FAIL(route_json, "community", tr_name_to_json_string(trp_route_get_comm(route))); OBJECT_SET_OR_FAIL(route_json, "realm", tr_name_to_json_string(trp_route_get_realm(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))); /* 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)); /* succeeded - set the return value and increment the reference count */ retval = route_json; json_incref(retval); cleanup: if (route_json) json_decref(route_json); return retval; }
TR_NAME *trp_route_dup_realm(TRP_ROUTE *entry) { return tr_dup_name(trp_route_get_realm(entry)); }