Properly set expiry on new community inforecs.
[trust_router.git] / common / tr_config.c
index 0d862dd..b451860 100644 (file)
@@ -51,7 +51,7 @@
 
 void tr_print_config (TR_CFG *cfg) {
   tr_notice("tr_print_config: Logging running trust router configuration.");
-  tr_print_comms(cfg->comms);
+  tr_print_comms(cfg->ctable);
 }
 
 void tr_print_comms (TR_COMM_TABLE *ctab)
@@ -126,13 +126,11 @@ TR_CFG *tr_cfg_new(TALLOC_CTX *mem_ctx)
   TR_CFG *cfg=talloc(mem_ctx, TR_CFG);
   if (cfg!=NULL) {
     cfg->internal=NULL;
-    cfg->idp_realms=NULL;
-    cfg->rp_realms=NULL;
     cfg->rp_clients=NULL;
     cfg->peers=NULL;
     cfg->default_servers=NULL;
-    cfg->comms=tr_comm_table_new(cfg);
-    if (cfg->comms==NULL) {
+    cfg->ctable=tr_comm_table_new(cfg);
+    if (cfg->ctable==NULL) {
       talloc_free(cfg);
       cfg=NULL;
     }
@@ -186,6 +184,9 @@ static TR_CFG_RC tr_cfg_parse_internal(TR_CFG *trc, json_t *jcfg)
   json_t *jcfgsettle = NULL;
   json_t *jroutesweep = NULL;
   json_t *jrouteupdate = NULL;
+  json_t *jtidreq_timeout = NULL;
+  json_t *jtidresp_numer = NULL;
+  json_t *jtidresp_denom = NULL;
   json_t *jrouteconnect = NULL;
 
   if ((!trc) || (!jcfg))
@@ -296,6 +297,42 @@ static TR_CFG_RC tr_cfg_parse_internal(TR_CFG *trc, json_t *jcfg)
       trc->internal->trp_update_interval=TR_DEFAULT_TRP_UPDATE_INTERVAL;
     }
 
+    if (NULL != (jtidreq_timeout = json_object_get(jint, "tid_request_timeout"))) {
+      if (json_is_number(jtidreq_timeout)) {
+        trc->internal->tid_req_timeout = json_integer_value(jtidreq_timeout);
+      } else {
+        tr_debug("tr_cfg_parse_internal: Parsing error, tid_request_timeout is not a number.");
+        return TR_CFG_NOPARSE;
+      }
+    } else {
+      /* if not configured, use the default */
+      trc->internal->tid_req_timeout=TR_DEFAULT_TID_REQ_TIMEOUT;
+    }
+
+    if (NULL != (jtidresp_numer = json_object_get(jint, "tid_response_numerator"))) {
+      if (json_is_number(jtidresp_numer)) {
+        trc->internal->tid_resp_numer = json_integer_value(jtidresp_numer);
+      } else {
+        tr_debug("tr_cfg_parse_internal: Parsing error, tid_response_numerator is not a number.");
+        return TR_CFG_NOPARSE;
+      }
+    } else {
+      /* if not configured, use the default */
+      trc->internal->tid_resp_numer=TR_DEFAULT_TID_RESP_NUMER;
+    }
+
+    if (NULL != (jtidresp_denom = json_object_get(jint, "tid_response_denominator"))) {
+      if (json_is_number(jtidresp_denom)) {
+        trc->internal->tid_resp_denom = json_integer_value(jtidresp_denom);
+      } else {
+        tr_debug("tr_cfg_parse_internal: Parsing error, tid_response_denominator is not a number.");
+        return TR_CFG_NOPARSE;
+      }
+    } else {
+      /* if not configured, use the default */
+      trc->internal->tid_resp_denom=TR_DEFAULT_TID_RESP_DENOM;
+    }
+
     if (NULL != (jlog = json_object_get(jint, "logging"))) {
       if (NULL != (jlogthres = json_object_get(jlog, "log_threshold"))) {
         if (json_is_string(jlogthres)) {
@@ -1456,8 +1493,8 @@ cleanup:
   /* if we succeeded, link things to the configuration and move out of tmp context */
   if (retval==TR_CFG_SUCCESS) {
     if (new_idp_realms!=NULL) {
-      tr_idp_realm_add(trc->idp_realms, new_idp_realms); /* fixes talloc contexts except for head*/
-      talloc_steal(trc, trc->idp_realms); /* make sure the head is in the right context */
+      tr_idp_realm_add(trc->ctable->idp_realms, new_idp_realms); /* fixes talloc contexts except for head*/
+      talloc_steal(trc, trc->ctable->idp_realms); /* make sure the head is in the right context */
     }
 
     if (new_rp_clients!=NULL) {
@@ -1637,7 +1674,7 @@ static void tr_cfg_parse_comm_idps(TR_CFG *trc, json_t *jidps, TR_COMM *comm, TR
       *rc=TR_CFG_ERROR;
       return;
     }
-    tr_comm_add_idp_realm(trc->comms, comm, found_idp, NULL, NULL); /* no provenance, never expires */
+    tr_comm_add_idp_realm(trc->ctable, comm, found_idp, 0, NULL, NULL); /* no provenance, never expires */
   }
 
   *rc=TR_CFG_SUCCESS;
@@ -1677,7 +1714,7 @@ static void tr_cfg_parse_comm_rps(TR_CFG *trc, json_t *jrps, TR_COMM *comm, TR_C
     }
 
     /* see if we already have this RP in this community */
-    found_rp=tr_comm_find_rp(trc->comms, comm, rp_name);
+    found_rp=tr_comm_find_rp(trc->ctable, comm, rp_name);
     if (found_rp!=NULL) {
       tr_notice("tr_cfg_parse_comm_rps: RP %s repeated in community %.*s.",
                 s, tr_comm_get_id(comm)->len, tr_comm_get_id(comm)->buf);
@@ -1686,20 +1723,23 @@ static void tr_cfg_parse_comm_rps(TR_CFG *trc, json_t *jrps, TR_COMM *comm, TR_C
     }
 
     /* Add the RP to the community, first see if we have the RP in any community */
-    found_rp=tr_rp_realm_lookup(trc->rp_realms, rp_name);
-    if (found_rp!=NULL)
+    found_rp=tr_rp_realm_lookup(trc->ctable->rp_realms, rp_name);
+    if (found_rp!=NULL) {
+      tr_debug("tr_cfg_parse_comm_rps: RP realm %s already exists.", s);
       new_rp=found_rp; /* use it rather than creating a new realm record */
-    else {
+    else {
       new_rp=tr_rp_realm_new(NULL);
       if (new_rp==NULL) {
         tr_err("tr_cfg_parse_comm_rps: unable to allocate RP record for %s in community %.*s.",
                s, tr_comm_get_id(comm)->len, tr_comm_get_id(comm)->buf);
       }
+      tr_debug("tr_cfg_parse_comm_rps: setting name to %s", rp_name->buf);
       tr_rp_realm_set_id(new_rp, rp_name);
       rp_name=NULL; /* rp_name no longer belongs to us */
-      tr_rp_realm_add(trc->rp_realms, new_rp);
+      tr_rp_realm_add(trc->ctable->rp_realms, new_rp);
+      talloc_steal(trc->ctable, trc->ctable->rp_realms); /* make sure head is in the right context */
     }
-    tr_comm_add_rp_realm(trc->comms, comm, new_rp, NULL, NULL);
+    tr_comm_add_rp_realm(trc->ctable, comm, new_rp, 0, NULL, NULL);
   }
 }
 
@@ -1832,12 +1872,12 @@ static TR_CFG_RC tr_cfg_parse_comms (TR_CFG *trc, json_t *jcfg)
                                                 trc, 
                                                 json_array_get(jcomms, i), 
                                                &rc))) {
-       return rc;
+        return rc;
       }
       tr_debug("tr_cfg_parse_comms: Community configured: %s.",
                tr_comm_get_id(comm)->buf);
 
-      tr_comm_table_add_comm(trc->comms, comm);
+      tr_comm_table_add_comm(trc->ctable, comm);
     }
   }
   tr_debug("tr_cfg_parse_comms: Finished (rc=%d)", rc);
@@ -1862,12 +1902,12 @@ TR_CFG_RC tr_cfg_validate(TR_CFG *trc)
     rc = TR_CFG_ERROR;
   }
 
-  if (0==tr_comm_table_size(trc->comms)) {
+  if (0==tr_comm_table_size(trc->ctable)) {
     tr_debug("tr_cfg_validate: Error: No Communities configured");
     rc = TR_CFG_ERROR;
   }
 
-  if ((NULL == trc->default_servers) && (NULL == trc->idp_realms)) {
+  if ((NULL == trc->default_servers) && (NULL == trc->ctable->idp_realms)) {
     tr_debug("tr_cfg_validate: Error: No default servers or IDPs configured.");
     rc = TR_CFG_ERROR;
   }
@@ -1990,7 +2030,7 @@ TR_IDP_REALM *tr_cfg_find_idp (TR_CFG *tr_cfg, TR_NAME *idp_id, TR_CFG_RC *rc)
     return NULL;
   }
 
-  for (cfg_idp = tr_cfg->idp_realms; NULL != cfg_idp; cfg_idp = cfg_idp->next) {
+  for (cfg_idp = tr_cfg->ctable->idp_realms; NULL != cfg_idp; cfg_idp = cfg_idp->next) {
     if (!tr_name_cmp (idp_id, cfg_idp->realm_id)) {
       tr_debug("tr_cfg_find_idp: Found %s.", idp_id->buf);
       return cfg_idp;