Initial path and expiration utilities
[trust_router.git] / tid / tid_req.c
index 6f14be9..159451d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012, 2014-2015, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include <assert.h>
 #include <talloc.h>
 
-#include <trust_router/tid.h>
+#include <tid_internal.h>
 #include <jansson.h>
 
 static int destroy_tid_req(TID_REQ *req)
 {
+  OM_uint32 minor;
   if (req->json_references)
     json_decref(req->json_references);
+  if (req->gssctx)
+    gss_delete_sec_context( &minor, &req->gssctx, NULL);
   return 0;
 }
 
@@ -207,3 +210,46 @@ void tid_req_free(TID_REQ *req)
 {
   talloc_free(req);
 }
+
+int tid_req_add_path(TID_REQ *req,
+                    const char *this_system, unsigned port)
+{
+  char *path_element = talloc_asprintf(req, "%s:%u",
+                                      this_system, port);
+  if (!req->path) {
+    req->path = json_array();
+    if (!req->path)
+      return -1;
+    tid_req_cleanup_json(req, req->path);
+  }
+  return json_array_append( req->path, json_string(path_element));
+}
+
+
+
+void tid_srvr_get_address(const TID_SRVR_BLK *blk,
+                         const struct sockaddr **out_addr,
+                         size_t *out_len)
+{
+  struct sockaddr_in *sa = NULL;
+    assert(blk);
+    sa = talloc_zero(blk, struct sockaddr_in);
+    sa->sin_family = AF_INET;
+    sa->sin_addr = blk->aaa_server_addr;
+    sa->sin_port = htons(2083);
+    *out_addr = (struct sockaddr *) sa;
+    *out_len = sizeof( struct sockaddr_in);
+}
+
+DH *tid_srvr_get_dh( TID_SRVR_BLK *blk)
+{
+  assert(blk);
+  return blk->aaa_server_dh;
+}
+
+const TR_NAME *tid_srvr_get_key_name(
+                                   const TID_SRVR_BLK *blk)
+{
+  assert(blk);
+  return blk->key_name;
+}