Add next_hop field to route update record, filled in locally.
[trust_router.git] / common / tr_msg.c
index 4faff68..6295068 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;
@@ -790,6 +798,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);