Move TRP messaging to tr_msg.c. Fix old bug.
[trust_router.git] / tid / tid_resp.c
index 6cfbb87..44a866a 100644 (file)
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <assert.h>
+#include <talloc.h>
 
-#include <trust_router/tid.h>
+#include <tid_internal.h>
 
-TR_EXPORT TID_RC tid_resp_get_result(TID_RESP *resp)
+TID_RESP *tid_resp_new(TALLOC_CTX *mem_ctx)
+{
+  return talloc(mem_ctx, TID_RESP);
+}
+
+void tid_resp_free(TID_RESP *resp)
+{
+  if (resp)
+    talloc_free(resp);
+}
+
+TR_EXPORT int tid_resp_get_result(TID_RESP *resp)
 {
   return(resp->result);
 }
 
-void tid_resp_set_result(TID_RESP *resp, TID_RC result)
+void tid_resp_set_result(TID_RESP *resp, int result)
 {
   resp->result = result;
 }
@@ -97,12 +110,50 @@ void tid_resp_set_orig_coi(TID_RESP *resp, TR_NAME *orig_coi)
   resp->orig_coi = orig_coi;
 }
 
-TR_EXPORT TID_SRVR_BLK *tid_resp_get_servers(TID_RESP *resp)
+TR_EXPORT TID_SRVR_BLK *tid_resp_get_server(TID_RESP *resp,
+                                           size_t index)
+{
+  assert(resp);
+  assert(index < resp->num_servers);
+  return(&(resp->servers[index]));
+}
+
+size_t tid_resp_get_num_servers(const TID_RESP *resp)
+{
+  assert(resp);
+  return resp->num_servers;
+}
+
+
+const TID_PATH *tid_srvr_get_path( const TID_SRVR_BLK *block)
+{
+  if (!block)
+    return NULL;
+  return (const TID_PATH *) block->path;
+}
+
+const TID_PATH *tid_resp_get_error_path( const TID_RESP *resp)
 {
-  return(resp->servers);
+  if (!resp)
+    return NULL;
+  return (const TID_PATH *) resp->error_path;
 }
 
-void tid_resp_set_servers(TID_RESP *resp, TID_SRVR_BLK *servers)
+const TID_PATH *tid_resp_get_a_path( const TID_RESP *const_resp)
 {
-  resp->servers = servers;
+  size_t index;
+  TID_SRVR_BLK *server;
+  TID_RESP *resp = (TID_RESP *) const_resp;
+  if (!resp)
+    return NULL;
+
+
+  if (resp->error_path)
+    return (const TID_PATH *) resp->error_path;
+  tid_resp_servers_foreach( resp, server, index) {
+    if (server->path)
+      return (const TID_PATH *) server->path;
+  }
+  return NULL;
+  
 }