Merge pull request #100 from painless-security/milestone/monitoring
[trust_router.git] / common / tr_idp.c
index 747397b..a3d84a7 100644 (file)
 #include <talloc.h>
 #include <time.h>
 
+#include <tr_aaa_server.h>
 #include <tr_name_internal.h>
 #include <tr_idp.h>
 #include <tr_config.h>
 #include <tr_debug.h>
 
-static int tr_aaa_server_destructor(void *obj)
-{
-  TR_AAA_SERVER *aaa=talloc_get_type_abort(obj, TR_AAA_SERVER);
-  if (aaa->hostname!=NULL)
-    tr_free_name(aaa->hostname);
-  return 0;
-}
-
-TR_AAA_SERVER *tr_aaa_server_new(TALLOC_CTX *mem_ctx, TR_NAME *hostname)
-{
-  TR_AAA_SERVER *aaa=talloc(mem_ctx, TR_AAA_SERVER);
-  if (aaa!=NULL) {
-    aaa->next=NULL;
-    aaa->hostname=hostname;
-    talloc_set_destructor((void *)aaa, tr_aaa_server_destructor);
-  }
-  return aaa;
-}
-
-void tr_aaa_server_free(TR_AAA_SERVER *aaa)
-{
-  talloc_free(aaa);
-}
-
-TR_AAA_SERVER_ITER *tr_aaa_server_iter_new(TALLOC_CTX *mem_ctx)
-{
-  return talloc(mem_ctx, TR_AAA_SERVER_ITER);
-}
-
-void tr_aaa_server_iter_free(TR_AAA_SERVER_ITER *iter)
-{
-  talloc_free(iter);
-}
-
-TR_AAA_SERVER *tr_aaa_server_iter_first(TR_AAA_SERVER_ITER *iter, TR_AAA_SERVER *aaa)
-{
-  iter->this=aaa;
-  return iter->this;
-}
-
-TR_AAA_SERVER *tr_aaa_server_iter_next(TR_AAA_SERVER_ITER *iter)
-{
-  if (iter->this!=NULL) {
-    iter->this=iter->this->next;
-  }
-  return iter->this;
-}
-
-
 /* fills in shared if pointer not null */
 TR_AAA_SERVER *tr_idp_aaa_server_lookup(TR_IDP_REALM *idp_realms, TR_NAME *idp_realm_name, TR_NAME *comm, int *shared_out)
 {
@@ -259,7 +211,7 @@ TR_IDP_REALM *tr_idp_realm_remove_func(TR_IDP_REALM *head, TR_IDP_REALM *remove)
   return head;
 }
 
-static int tr_idp_realm_apc_count(TR_IDP_REALM *idp)
+int tr_idp_realm_apc_count(TR_IDP_REALM *idp)
 {
   int ii=0;
   TR_APC *apc=idp->apcs;
@@ -270,7 +222,7 @@ static int tr_idp_realm_apc_count(TR_IDP_REALM *idp)
   return ii;
 }
 
-static int tr_idp_realm_aaa_server_count(TR_IDP_REALM *idp)
+int tr_idp_realm_aaa_server_count(TR_IDP_REALM *idp)
 {
   int ii=0;
   TR_AAA_SERVER *aaa=idp->aaa_servers;
@@ -281,84 +233,6 @@ static int tr_idp_realm_aaa_server_count(TR_IDP_REALM *idp)
   return ii;
 }
 
-static char *tr_aaa_server_to_str(TALLOC_CTX *mem_ctx, TR_AAA_SERVER *aaa)
-{
-  return talloc_strndup(mem_ctx, aaa->hostname->buf, aaa->hostname->len);
-}
-
-char *tr_idp_realm_to_str(TALLOC_CTX *mem_ctx, TR_IDP_REALM *idp)
-{
-  TALLOC_CTX *tmp_ctx=talloc_new(NULL);
-  char **s_aaa=NULL, *aaa_servers=NULL;
-  char **s_apc=NULL, *apcs=NULL;
-  int ii=0, aaa_servers_strlen=0, apcs_strlen=0;
-  int n_aaa_servers=tr_idp_realm_aaa_server_count(idp);
-  int n_apcs=tr_idp_realm_apc_count(idp);
-  TR_AAA_SERVER *aaa=NULL;
-  TR_APC *apc=NULL;
-  char *result=NULL;
-
-  /* get the AAA servers */
-  if (n_aaa_servers<=0)
-    aaa_servers=talloc_strdup(tmp_ctx, "");
-  else {
-    s_aaa=talloc_array(tmp_ctx, char *, n_aaa_servers);
-    for (aaa=idp->aaa_servers,ii=0; aaa!=NULL; aaa=aaa->next,ii++) {
-      s_aaa[ii]=tr_aaa_server_to_str(s_aaa, aaa);
-      aaa_servers_strlen+=strlen(s_aaa[ii]);
-    }
-
-    /* add space for comma-space separators */
-    aaa_servers_strlen+=2*(n_aaa_servers-1);
-
-    aaa_servers=talloc_array(tmp_ctx, char, aaa_servers_strlen+1);
-    aaa_servers[0]='\0';
-    for (ii=0; ii<n_aaa_servers; ii++) {
-      strcat(aaa_servers, s_aaa[ii]);
-      if (ii<(n_aaa_servers-1))
-        strcat(aaa_servers, ", ");
-    }
-    talloc_free(s_aaa);
-  }
-
-  /* get the APCs */
-  if (n_apcs<=0)
-    apcs=talloc_strdup(tmp_ctx, "");
-  else {
-    s_apc=talloc_array(tmp_ctx, char *, n_apcs);
-    for (apc=idp->apcs,ii=0; apc!=NULL; apc=apc->next,ii++) {
-      s_apc[ii]=tr_apc_to_str(s_apc, apc);
-      apcs_strlen+=strlen(s_apc[ii]);
-    }
-
-    /* add space for comma-space separators */
-    apcs_strlen+=2*(n_apcs-1);
-
-    apcs=talloc_array(tmp_ctx, char, apcs_strlen+1);
-    apcs[0]='\0';
-    for (ii=0; ii<n_apcs; ii++) {
-      strcat(apcs, s_apc[ii]);
-      if (ii<(n_apcs-1))
-        strcat(apcs, ", ");
-    }
-    talloc_free(s_apc);
-  }
-
-  result=talloc_asprintf(mem_ctx,
-                         "IDP realm: \"%.*s\""
-                         "  shared: %s"
-                         "  local: %s"
-                         "  AAA servers: %s"
-                         "  APCs: %s",
-                         idp->realm_id->len, idp->realm_id->buf,
-                         (idp->shared_config)?"yes":"no",
-                         (idp->origin==TR_REALM_LOCAL)?"yes":"no",
-                         aaa_servers,
-                         apcs);
-  talloc_free(tmp_ctx);
-  return result;
-}
-
 void tr_idp_realm_incref(TR_IDP_REALM *realm)
 {
   realm->refcount++;