+/**
+ * convert an IDP realm into routing table entries.
+ *
+ * @param mem_ctx talloc context for the result
+ * @param realm IDP realm whose routes should be generated
+ * @param trust_router hostname for TRP connections to us
+ * @param trust_router_port TRP port of our trust router
+ * @param n_routes (output) the number of routes in the returned array
+ * @return Pointer to an array of pointers to routes
+ */
+static TRP_ROUTE **tr_make_local_routes(TALLOC_CTX *mem_ctx,
+ TR_IDP_REALM *realm,
+ const char *trust_router,
+ int trust_router_port,
+ size_t *n_routes)
+{
+ TALLOC_CTX *tmp_ctx=talloc_new(NULL);
+ TR_APC *comm=NULL;
+ TRP_ROUTE *new_entry=NULL;
+ TRP_ROUTE **entries=NULL;
+ size_t n_comms=0, ii=0;
+
+ *n_routes=0;
+
+ if ((realm==NULL) || (realm->origin!=TR_REALM_LOCAL))
+ goto cleanup;
+
+ /* count comms */
+ for (comm=realm->apcs, n_comms=0; comm!=NULL; comm=comm->next,n_comms++) {}
+
+ entries=talloc_array(tmp_ctx, TRP_ROUTE *, n_comms);
+ for (comm=realm->apcs,ii=0; comm!=NULL; comm=comm->next, ii++) {
+ new_entry=trp_route_new(entries);
+ if (new_entry==NULL) {
+ tr_crit("tr_make_local_routes: unable to allocate entry.");
+ talloc_free(entries);
+ goto cleanup;
+ }
+ trp_route_set_comm(new_entry, tr_dup_name(comm->id));
+ trp_route_set_realm(new_entry, tr_dup_name(realm->realm_id));
+ trp_route_set_peer(new_entry, tr_new_name("")); /* no peer, it's us */
+ trp_route_set_metric(new_entry, 0);
+ trp_route_set_trust_router(new_entry, tr_new_name(trust_router));
+ trp_route_set_trust_router_port(new_entry, trust_router_port);
+ trp_route_set_next_hop(new_entry, tr_new_name("")); /* no next hop */
+ trp_route_set_next_hop_port(new_entry, -1); /* no next hop */
+ trp_route_set_local(new_entry, 1);
+ entries[ii]=new_entry;
+ }
+
+ talloc_steal(mem_ctx, entries);
+ *n_routes=n_comms;
+ cleanup:
+ talloc_free(tmp_ctx);
+ return entries;
+}
+
+void tr_peer_status_change(TRP_PEER *peer, void *cookie)
+{
+ TRPS_INSTANCE *trps=talloc_get_type_abort(cookie, TRPS_INSTANCE);
+
+ if (TRP_SUCCESS!=trps_wildcard_route_req(trps, trp_peer_get_servicename(peer)))
+ tr_err("tr_send_wildcard: error sending wildcard route request.");
+}
+