X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=common%2Ftr_config.c;h=587a47ce52c95c033e86f21348b5d8adabbd8db1;hb=5aeb22471d8d6d4a6c2348af8b221a8ff9b62184;hp=fbd5027bc86ee334013152911bc7638125cf2b98;hpb=7f85143212b8e2e5b11055c97b083119a756a812;p=trust_router.git diff --git a/common/tr_config.c b/common/tr_config.c index fbd5027..587a47c 100644 --- a/common/tr_config.c +++ b/common/tr_config.c @@ -44,9 +44,39 @@ #include #include -void tr_print_config (FILE *stream, TR_CFG *cfg) { - fprintf(stream, "tr_print_config: Not yet implemented."); - return; +void tr_print_config (TR_CFG *cfg) { + tr_notice("tr_print_config: Logging running trust router configuration."); + tr_print_comms(cfg->comms); +} + +void tr_print_comms (TR_COMM *comm_list) { + TR_COMM *comm = NULL; + + for (comm = comm_list; NULL != comm; comm = comm->next) { + tr_notice("tr_print_config: Community %s:", comm->id->buf); + + tr_notice("tr_print_config: - Member IdPs:"); + tr_print_comm_idps(comm->idp_realms); + + tr_notice("tr_print_config: - Member RPs:"); + tr_print_comm_rps(comm->rp_realms); + } +} + +void tr_print_comm_idps (TR_IDP_REALM *idp_list) { + TR_IDP_REALM *idp = NULL; + + for (idp = idp_list; NULL != idp; idp = idp->comm_next) { + tr_notice("tr_print_config: - @%s", idp->realm_id->buf); + } +} + +void tr_print_comm_rps(TR_RP_REALM *rp_list) { + TR_RP_REALM *rp = NULL; + + for (rp = rp_list; NULL != rp; rp = rp->next) { + tr_notice("tr_print_config: - %s", rp->realm_name->buf); + } } void tr_cfg_free (TR_CFG *cfg) { @@ -649,6 +679,7 @@ static TR_CFG_RC tr_cfg_parse_idp_realms (TR_CFG *trc, json_t *jcfg) static TR_IDP_REALM *tr_cfg_parse_comm_idps (TR_CFG *trc, json_t *jidps, TR_CFG_RC *rc) { TR_IDP_REALM *idp = NULL; + TR_IDP_REALM *found_idp = NULL; TR_IDP_REALM *temp_idp = NULL; int i = 0; @@ -661,7 +692,15 @@ static TR_IDP_REALM *tr_cfg_parse_comm_idps (TR_CFG *trc, json_t *jidps, TR_CFG_ } for (i = 0; i < json_array_size(jidps); i++) { - if (NULL == (temp_idp = (tr_cfg_find_idp(trc, + if (NULL == (temp_idp = talloc(trc, TR_IDP_REALM))) { + tr_debug("tr_cfg_parse_comm_idps: Can't allocate memory for IdP Realm."); + if (rc) + *rc = TR_CFG_NOMEM; + return NULL; + } + memset (temp_idp, 0, sizeof(TR_IDP_REALM)); + + if (NULL == (found_idp = (tr_cfg_find_idp(trc, tr_new_name((char *)json_string_value(json_array_get(jidps, i))), rc)))) { tr_debug("tr_cfg_parse_comm_idps: Unknown IDP %s.", @@ -669,6 +708,9 @@ static TR_IDP_REALM *tr_cfg_parse_comm_idps (TR_CFG *trc, json_t *jidps, TR_CFG_ return NULL; } + // We *MUST* do a dereferenced copy here or the second community will corrupt the linked list we create here. + *temp_idp = *found_idp; + temp_idp->comm_next = idp; idp = temp_idp; } @@ -875,6 +917,7 @@ static char *join_paths(const char *p1, const char *p2) { /* Reads configuration files in config_dir ("" or "./" will use the current directory) */ TR_CFG_RC tr_parse_config (TR_INSTANCE *tr, const char *config_dir, int n, struct dirent **cfg_files) { json_t *jcfg; + json_t *jser; json_error_t rc; char *file_with_path; @@ -907,6 +950,15 @@ TR_CFG_RC tr_parse_config (TR_INSTANCE *tr, const char *config_dir, int n, struc } talloc_free(file_with_path); /* done with filename */ + // Look for serial number and log it if it exists + if (NULL != (jser = json_object_get(jcfg, "serial_number"))) { + if (json_is_number(jser)) { + tr_notice("tr_read_config: Attempting to load revision %i of %s.", + (int *) json_integer_value(jser), + cfg_files[n]->d_name); + } + } + if ((TR_CFG_SUCCESS != tr_cfg_parse_internal(tr->new_cfg, jcfg)) || (TR_CFG_SUCCESS != tr_cfg_parse_rp_clients(tr->new_cfg, jcfg)) || (TR_CFG_SUCCESS != tr_cfg_parse_idp_realms(tr->new_cfg, jcfg)) ||