fixes for building on Centos; mostly -Werror clean at this point
[trust_router.git] / tid / tidc.c
index 352baaf..de40102 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <jansson.h>
-
 #include <gsscon.h>
-#include <tr_dh.h>
-#include <tid.h>
-#include <tr_msg.h>
 
-/* char tmp_key[32] = 
-  {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
-   0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
-   0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
-   0x19, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
-*/
+#include <trust_router/tr_dh.h>
+#include <trust_router/tid.h>
+#include <tr_msg.h>
+#include <gsscon.h>
 
 int tmp_len = 32;
 
@@ -59,15 +53,6 @@ TIDC_INSTANCE *tidc_create ()
   else
     return NULL;
 
-  if (NULL == (tidc->priv_dh = tr_create_dh_params(NULL, 0))) {
-    free (tidc);
-    return NULL;
-  }
-
-  fprintf(stderr, "TIDC DH Parameters:\n");
-  DHparams_print_fp(stdout, tidc->priv_dh);
-  fprintf(stderr, "\n");
-
   return tidc;
 }
 
@@ -87,7 +72,7 @@ int tidc_open_connection (TIDC_INSTANCE *tidc,
   err = gsscon_connect(server, TID_PORT, &conn);
 
   if (!err)
-    err = gsscon_active_authenticate(conn, NULL, "trustquery", gssctx);
+    err = gsscon_active_authenticate(conn, NULL, "trustidentity", gssctx);
 
   if (!err)
     return conn;
@@ -100,18 +85,18 @@ int tidc_send_request (TIDC_INSTANCE *tidc,
                       gss_ctx_id_t gssctx,
                       char *rp_realm,
                       char *realm, 
-                      char *coi,
+                      char *comm,
                       TIDC_RESP_FUNC *resp_handler,
                       void *cookie)
 
 {
-  json_t *jreq;
-  int err;
-  char *req_buf;
-  char *resp_buf;
+  int err = 0;
+  char *req_buf = NULL;
+  char *resp_buf = NULL;
   size_t resp_buflen = 0;
-  TR_MSG *msg;
-  TID_REQ *tid_req;
+  TR_MSG *msg = NULL;
+  TID_REQ *tid_req = NULL;
+  TR_MSG *resp_msg = NULL;
 
   /* Create and populate a TID msg structure */
   if ((!(msg = malloc(sizeof(TR_MSG)))) ||
@@ -125,14 +110,15 @@ int tidc_send_request (TIDC_INSTANCE *tidc,
   msg->tid_req = tid_req;
 
   tid_req->conn = conn;
+  tid_req->gssctx = gssctx;
 
   /* TBD -- error handling */
   tid_req->rp_realm = tr_new_name(rp_realm);
   tid_req->realm = tr_new_name(realm);
-  tid_req->coi = tr_new_name(coi);
+  tid_req->comm = tr_new_name(comm);
+
+  tid_req->tidc_dh = tidc->client_dh;
 
-  tid_req->tidc_dh = tidc->priv_dh;
-  
   tid_req->resp_func = resp_handler;
   tid_req->cookie = cookie;
 
@@ -161,12 +147,23 @@ int tidc_send_request (TIDC_INSTANCE *tidc,
     return -1;
   }
 
-  fprintf(stdout, "Response Received, %d bytes.\n", resp_buflen);
+  fprintf(stdout, "Response Received (%u bytes).\n", (unsigned) resp_buflen);
+  fprintf(stdout, "%s\n", resp_buf);
 
-  /* Parse response -- TBD */
+  if (NULL == (resp_msg = tr_msg_decode(resp_buf, resp_buflen))) {
+    fprintf(stderr, "Error decoding response.\n");
+    return -1;
+  }
 
+  /* TBD -- Check if this is actually a valid response */
+  if (!resp_msg->tid_resp) {
+    fprintf(stderr, "Error: No response in the response!\n");
+    return -1;
+  }
+  
   /* Call the caller's response function */
-  (*resp_handler)(tidc, NULL, cookie);
+  (*tid_req->resp_func)(tidc, tid_req, resp_msg->tid_resp, cookie);
+
 
   if (msg)
     free(msg);
@@ -177,6 +174,8 @@ int tidc_send_request (TIDC_INSTANCE *tidc,
   if (resp_buf)
     free(resp_buf);
 
+  /* TBD -- free the decoded response */
+
   return 0;
 }