Connect to hard-coded peer and exchange route info. Buggy and incomplete.
[trust_router.git] / common / tr_msg.c
index 4faff68..b2964b6 100644 (file)
@@ -543,6 +543,12 @@ static TRP_RC tr_msg_encode_inforec_route(json_t *jrec, TRP_INFOREC *rec )
   if (rec==NULL)
     return TRP_BADTYPE;
 
+  if ((trp_inforec_get_comm(rec)==NULL)
+     || (trp_inforec_get_realm(rec)==NULL)
+     || (trp_inforec_get_trust_router(rec)==NULL)) {
+    return TRP_ERROR;
+  }
+
   s=tr_name_strdup(trp_inforec_get_comm(rec));
   if (s==NULL)
     return TRP_NOMEM;
@@ -667,6 +673,8 @@ static TRP_INFOREC *tr_msg_decode_trp_inforec(TALLOC_CTX *mem_ctx, json_t *jreco
     goto cleanup;
   talloc_free(s); s=NULL;
 
+  trp_inforec_set_next_hop(rec, NULL); /* make sure this is null (filled in later) */
+
   rc=tr_msg_get_json_integer(jrecord, "metric", &num);
   if ((rc != TRP_SUCCESS) || (TRP_SUCCESS!=trp_inforec_set_metric(rec,num)))
     goto cleanup;
@@ -709,6 +717,7 @@ static json_t *tr_msg_encode_trp_upd(TRP_UPD *update)
   }
   json_object_set_new(jupdate, "records", jrecords); /* jrecords now a "borrowed" reference */
   for (rec=trp_upd_get_inforec(update); rec!=NULL; rec=trp_inforec_get_next(rec)) {
+    tr_debug("tr_msg_encode_trp_upd: encoding inforec.");
     jrec=tr_msg_encode_inforec(rec);
     if (jrec==NULL) {
       json_decref(jupdate); /* also decs jrecords and any elements */
@@ -790,6 +799,12 @@ static json_t *tr_msg_encode_trp_req(TRP_REQ *req)
   if (jbody==NULL)
     return NULL;
 
+  if ((NULL==trp_req_get_comm(req))
+     || (NULL==trp_req_get_realm(req))) {
+    json_decref(jbody);
+    return NULL;
+  }
+
   s=tr_name_strdup(trp_req_get_comm(req)); /* ensures null termination */
   if (s==NULL) {
     json_decref(jbody);