+ return ret;
+}
+
+/* Get all entries in an apc. Returns an array of pointers in NULL talloc context.
+ * Caller must free this list with talloc_free, but must not free the entries in the
+ * list.. */
+TRP_RENTRY **trp_rtable_get_apc_entries(TRP_RTABLE *rtbl, TR_NAME *apc, size_t *n_out)
+{
+ size_t ii=0, jj=0;
+ TR_NAME **realm=NULL;
+ size_t n_realms=0;
+ TRP_RENTRY **realm_entries=NULL;
+ size_t n_entries=0;
+ TRP_RENTRY **ret=NULL;
+ size_t ii_ret=0;
+
+ *n_out=trp_rtable_apc_size(rtbl, apc);
+ if (*n_out==0)
+ return NULL;
+
+ ret=talloc_array(NULL, TRP_RENTRY *, *n_out);
+ if (ret==NULL) {
+ tr_crit("trp_rtable_get_apc_entries: could not allocate return array.");
+ *n_out=0;
+ return NULL;
+ }
+
+ ii_ret=0; /* counts entries in the output array */
+ realm=trp_rtable_get_apc_realms(rtbl, apc, &n_realms);
+ for (ii=0; ii<n_realms; ii++) {
+ realm_entries=trp_rtable_get_realm_entries(rtbl, apc, realm[ii], &n_entries);
+ for (jj=0; jj<n_entries; jj++)
+ ret[ii_ret++]=realm_entries[jj];
+ talloc_free(realm_entries);
+ }
+ talloc_free(realm);
+
+ if (ii_ret!=*n_out) {
+ tr_crit("trp_rtable_get_apc_entries: found incorrect number of entries.");
+ talloc_free(ret);
+ *n_out=0;
+ return NULL;
+ }
+
+ return ret;
+}
+
+/* Get all entries in an apc/realm. Returns an array of pointers in NULL talloc context.
+ * Caller must free this list with talloc_free, but must not free the entries in the
+ * list.. */
+TRP_RENTRY **trp_rtable_get_realm_entries(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, size_t *n_out)
+{
+ size_t ii=0;
+ TRP_RENTRY **ret=NULL;
+ TR_NAME **peer=NULL;
+
+ peer=trp_rtable_get_apc_realm_peers(rtbl, apc, realm, n_out);
+ ret=talloc_array(NULL, TRP_RENTRY *, *n_out);
+ if (ret==NULL) {
+ tr_crit("trp_rtable_get_realm_entries: could not allocate return array.");
+ talloc_free(peer);
+ n_out=0;
+ return NULL;
+ }
+ for (ii=0; ii<*n_out; ii++)
+ ret[ii]=trp_rtable_get_entry(rtbl, apc, realm, peer[ii]);
+ talloc_free(peer);
+ return ret;
+}
+
+TR_NAME **trp_rtable_get_apc_realm_peers(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, size_t *n_out)
+{
+ TR_NAME **ret=NULL;
+ GHashTable *realm_tbl=NULL;
+ GList *keys=NULL;
+ GList *p=NULL;
+ size_t ii=0;
+
+ *n_out=trp_rtable_realm_size(rtbl, apc, realm);
+ if (*n_out==0)
+ return NULL;
+ realm_tbl=trp_rtable_get_realm_table(rtbl, apc, realm);
+ ret=talloc_array(NULL, TR_NAME *, *n_out);
+ if (ret==NULL) {
+ tr_crit("trp_rtable_get_apc_realm_peers: could not allocate return array.");
+ *n_out=0;
+ return NULL;
+ }
+ keys=g_hash_table_get_keys(realm_tbl);
+ for (ii=0,p=keys; p!=NULL; ii++,p=g_list_next(p))
+ ret[ii]=(TR_NAME *)p->data;
+ g_list_free(keys);
+ return ret;