#include <trp_rtable.h>
#include <trust_router/trp.h>
#include <tr_util.h>
+#include <tr_json_util.h>
/* Pretty print a route table entry to a newly allocated string. If sep is NULL,
* returns comma+space separated string. */
/* helper */
static json_t *expiry_to_json_string(TRP_ROUTE *route)
{
- 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(trp_route_get_expiry(route), &ts_zero) > 0) {
- s = timespec_to_str(trp_route_get_expiry(route));
+ if (tr_cmp_timespec(trp_route_get_expiry(route), &ts) > 0) {
+ if (trp_route_get_expiry_realtime(route, &ts) == NULL)
+ s = strdup("error");
+ else
+ s = timespec_to_str(&ts);
if (s) {
jstr = json_string(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)
-
-#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;