X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=trp%2Ftrp_rtable.c;fp=trp%2Ftrp_rtable.c;h=2926309f12472d73c2b64f587ca898812ee6eebd;hb=58b2b02987b9258df50b95f9741140bf382a703a;hp=7f793512296760c5beb0ff9a4be4e576b42b8eec;hpb=32112416992e9619622b5e9b7a6a7fe4eda992c2;p=trust_router.git diff --git a/trp/trp_rtable.c b/trp/trp_rtable.c index 7f79351..2926309 100644 --- a/trp/trp_rtable.c +++ b/trp/trp_rtable.c @@ -229,9 +229,9 @@ size_t trp_rtable_realm_size(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm) } /* Returns an array of pointers to TRP_ROUTE, length of array in n_out. - * Caller must free the array (in the talloc NULL context), but must + * Caller must free the array (in the mem_ctx context), but must * not free its contents. */ -TRP_ROUTE **trp_rtable_get_entries(TRP_RTABLE *rtbl, size_t *n_out) +TRP_ROUTE **trp_rtable_get_entries(TALLOC_CTX *mem_ctx, TRP_RTABLE *rtbl, size_t *n_out) { TRP_ROUTE **ret=NULL; TR_NAME **comm=NULL; @@ -244,7 +244,7 @@ TRP_ROUTE **trp_rtable_get_entries(TRP_RTABLE *rtbl, size_t *n_out) if (*n_out==0) return NULL; - ret=talloc_array(NULL, TRP_ROUTE *, *n_out); + ret=talloc_array(mem_ctx, TRP_ROUTE *, *n_out); if (ret==NULL) { tr_crit("trp_rtable_get_entries: unable to allocate return array."); *n_out=0; @@ -457,7 +457,7 @@ TRP_ROUTE *trp_rtable_get_selected_entry(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAM void trp_rtable_clear_triggered(TRP_RTABLE *rtbl) { size_t n_entries=0; - TRP_ROUTE **entries=trp_rtable_get_entries(rtbl, &n_entries); + TRP_ROUTE **entries= trp_rtable_get_entries(NULL, rtbl, &n_entries); size_t ii=0; if (entries!=NULL) { @@ -466,84 +466,3 @@ void trp_rtable_clear_triggered(TRP_RTABLE *rtbl) talloc_free(entries); } } - -static int sort_tr_names_cmp(const void *a, const void *b) -{ - TR_NAME **n1=(TR_NAME **)a; - TR_NAME **n2=(TR_NAME **)b; - return tr_name_cmp(*n1, *n2); -} - -static void sort_tr_names(TR_NAME **names, size_t n_names) -{ - qsort(names, n_names, sizeof(TR_NAME *), sort_tr_names_cmp); -} - -char *trp_rtable_to_str(TALLOC_CTX *mem_ctx, TRP_RTABLE *rtbl, const char *sep, const char *lineterm) -{ - TALLOC_CTX *tmp_ctx=talloc_new(NULL); - TR_NAME **comms=NULL; - size_t n_comms=0; - TR_NAME **realms=NULL; - size_t n_realms=0; - TRP_ROUTE **entries=NULL; - size_t n_entries=0; - char **tbl_strings=NULL; - size_t ii_tbl=0; /* counts tbl_strings */ - size_t tbl_size=0; - size_t len=0; - size_t ii=0, jj=0, kk=0; - char *p=NULL; - char *result=NULL; - - if (lineterm==NULL) - lineterm="\n"; - - tbl_size=trp_rtable_size(rtbl); - if (tbl_size==0) { - result=talloc_strdup(mem_ctx, lineterm); - goto cleanup; - } - - tbl_strings=talloc_array(tmp_ctx, char *, tbl_size); - if (tbl_strings==NULL) { - result=talloc_strdup(mem_ctx, "error"); - goto cleanup; - } - - comms=trp_rtable_get_comms(rtbl, &n_comms); - talloc_steal(tmp_ctx, comms); - sort_tr_names(comms, n_comms); - ii_tbl=0; - len=0; - for (ii=0; ii