Reorganize common code (for msgs, names...) to be used across tr components.
authorMargaret Wasserman <mrw@debian.(none)>
Mon, 17 Dec 2012 19:56:05 +0000 (14:56 -0500)
committerMargaret Wasserman <mrw@debian.(none)>
Mon, 17 Dec 2012 19:56:05 +0000 (14:56 -0500)
12 files changed:
Makefile.am
common/tr_config.c
common/tr_msg.c [moved from tpq/tpq_json.c with 89% similarity]
common/tr_name.c [moved from tpq/tpq_common.c with 88% similarity]
include/tpq.h
include/tr.h [moved from include/trust_router.h with 94% similarity]
include/tr_config.h [new file with mode: 0644]
include/tr_msg.h [new file with mode: 0644]
include/tr_name.h [new file with mode: 0644]
tpq/example/tpqs_main.c
tr/tr_config.c [new file with mode: 0644]
tr/tr_main.c

index 9eadb0f..26231dd 100644 (file)
@@ -1,24 +1,27 @@
-bin_PROGRAMS= tr/tr tpq/tpqc tpq/tpqs
+bin_PROGRAMS= tr/tr tpq/example/tpqc tpq/example/tpqs
 AM_CPPFLAGS=-I$(srcdir)/include
 SUBDIRS = gsscon 
 
 tr_tr_SOURCES = tr/tr_main.c \
 tpq/tpqs.c \
-tpq/tpq_common.c \
-common/tr_config.c
+common/tr_name.c \
+common/tr_msg.c \
+common/tr_config.c 
 
 tr_tr_LDADD = gsscon/libgsscon.la
 
-tpq_tpqc_SOURCES = tpq/example/tpqc_main.c \
+tpq_example_tpqc_SOURCES = tpq/example/tpqc_main.c \
 tpq/tpqc.c \
-tpq/tpq_common.c
+common/tr_name.c \
+common/tr_msg.c
 
-tpq_tpqc_LDADD = gsscon/libgsscon.la
+tpq_example_tpqc_LDADD = gsscon/libgsscon.la
 
-tpq_tpqs_SOURCES = tpq/example/tpqs_main.c \
+tpq_example_tpqs_SOURCES = tpq/example/tpqs_main.c \
 tpq/tpqs.c \
-tpq/tpq_common.c
+common/tr_name.c \
+common/tr_msg.c
 
-tpq_tpqs_LDADD = gsscon/libgsscon.la
+tpq_example_tpqs_LDADD = gsscon/libgsscon.la
 
 
index 93e12e1..bd47832 100644 (file)
@@ -1,5 +1,3 @@
-
-
 /*
  * Copyright (c) 2012, JANET(UK)
  * All rights reserved.
  *
  */
 
-#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
-#include <trust_router.h>
+#include <tr_config.h>
 
 int tr_read_config (FILE *cfg_file) {
-  int rc = 0;
 
-  return rc;
+  return 0;
 }
similarity index 89%
rename from tpq/tpq_json.c
rename to common/tr_msg.c
index 6732589..2aa99ea 100644 (file)
 #include <string.h>
 #include <jansson.h>
 
-#include <tpq.h>
+#include <tr_msg.h>
 
-char *tpq_req_encode(TPQ_REQ *req
+char *tr_msg_encode(TR_MSG *msg
 {
   return NULL;
 }
 
-TPQ_REQ *tpq_req_decode(char *jreq)
+TR_MSG *tr_msg_decode(char *jmsg)
 {
   return NULL;
 }
 
-char *tpq_resp_encode(TPQ_REQ *resp) 
-{
-  return NULL;
-}
-
-TPQ_RESP *tpq_resp_decode(char *jresp)
-{
-  return NULL;
-}
 
 
similarity index 88%
rename from tpq/tpq_common.c
rename to common/tr_name.c
index 5c78043..7136f49 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#include <tpq.h>
+#include <tr_name.h>
 
-TPQ_NAME *tpq_new_name (char *name) 
+TR_NAME *tr_new_name (char *name) 
 {
-  TPQ_NAME *new;
+  TR_NAME *new;
 
-  if (new = malloc(sizeof(TPQ_NAME))) { 
+  if (new = malloc(sizeof(TR_NAME))) { 
     new->len = strlen(name);
     if (new->buf = malloc(new->len+1)) {
       strcpy(new->buf, name);
@@ -50,14 +50,14 @@ TPQ_NAME *tpq_new_name (char *name)
   return new;
 }
 
-TPQ_NAME *tpq_dup_name (TPQ_NAME *from) 
+TR_NAME *tr_dup_name (TR_NAME *from) 
 {
-  TPQ_NAME *to;
+  TR_NAME *to;
 
-  if (to = malloc(sizeof(TPQ_NAME))) {
+  if (to = malloc(sizeof(TR_NAME))) {
     to->len = from->len;
     if (to->buf = malloc(to->len+1)) {
-      strncpy(to->buf, from->buf, to->len);
+      strncpy(to->buf, from->buf, from->len);
       to->buf[to->len] = 0;    /* NULL terminate for debugging printf()s */
     }
   }
index c51958d..db1ac42 100644 (file)
 #define TPQ_PORT       12309
 
 #include <gsscon.h>
-typedef struct tpq_name {
-  char *buf;
-  int len;
-} TPQ_NAME;
+#include <tr_name.h>
 
 typedef struct tpq_req {
   struct tpq_req *next_req;
   int conn;
-  TPQ_NAME *realm;
-  TPQ_NAME *coi;
+  TR_NAME *realm;
+  TR_NAME *coi;
   void *resp_func;
   void *cookie;
 } TPQ_REQ;
 
 typedef struct tpq_resp {
-  TPQ_NAME *realm;
-  TPQ_NAME *coi;
+  TR_NAME *realm;
+  TR_NAME *coi;
   /* Address of AAA Server */
   /* Credentials */
   /* Trust Path Used */
@@ -73,14 +70,6 @@ typedef struct tpqs_instance {
 typedef void (TPQC_RESP_FUNC)(TPQC_INSTANCE *, TPQ_RESP *, void *);
 typedef int (TPQS_REQ_FUNC)(TPQS_INSTANCE *, TPQ_REQ *, TPQ_RESP *, void *);
 
-TPQ_NAME *tpq_new_name (char *name);
-TPQ_NAME *tpq_dup_name (TPQ_NAME *from);
-
-char *tpq_req_encode(TPQ_REQ *req);
-TPQ_REQ *tpq_req_decode(char *jreq);
-char *tpq_resp_encode(TPQ_REQ *resp);
-TPQ_RESP *tpq_resp_decode(char *jresp);
-
 TPQC_INSTANCE *tpqc_create (void);
 int tpqc_open_connection (TPQC_INSTANCE *tpqc, char *server, gss_ctx_id_t *gssctx);
 int tpqc_send_request (TPQC_INSTANCE *tpqc, int conn, gss_ctx_id_t gssctx, char *realm, char *coi, TPQC_RESP_FUNC *resp_handler, void *cookie);
similarity index 94%
rename from include/trust_router.h
rename to include/tr.h
index b6a533a..9fee9dd 100644 (file)
  *
  */
 
-#ifndef TRUST_ROUTER_H
-#define TRUST_ROUTER_H
+#ifndef TR_H
+#define TR_H
 
+#include <tr_msg.h>
+#include <tr_name.h>
+#include <tr_config.h>
 #include <tpq.h>
 #include <tidr.h>
 
 #define TRUST_ROUTER_PORT      12308
 
-int tr_read_config (FILE *cfg_file);
-
 #endif
diff --git a/include/tr_config.h b/include/tr_config.h
new file mode 100644 (file)
index 0000000..3b5559e
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef TR_CONFIG_H
+#define TR_CONFIG_H
+
+#include <stdio.h>
+
+int tr_read_config (FILE *cfg_file);
+
+#endif
diff --git a/include/tr_msg.h b/include/tr_msg.h
new file mode 100644 (file)
index 0000000..8943559
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2012, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef TR_MSG_H
+#define TR_MSG_H
+
+#include <tpq.h>
+// #include <tidr.h>
+#include <jansson.h>
+
+enum msg_type {
+  TR_UNKNOWN,
+  TPQ_REQUEST,
+  TPQ_RESPONSE,
+  TIDR_REQUEST,
+  TIDR_RESPONSE
+};
+
+/* Union of TR message types to hold message of any type. */
+typedef struct tr_msg {
+  enum msg_type msg_type;
+  union {
+    TPQ_REQ msg_req;
+    TPQ_RESP msg_resp;
+    // TIDR_REQ tidr_req;
+    // TIDR_RESP tidr_resp;
+  };
+} TR_MSG;
+
+char *tr_msg_encode(TR_MSG *msg);
+TR_MSG *tr_msg_decode(char *jmsg);
+
+#endif
diff --git a/include/tr_name.h b/include/tr_name.h
new file mode 100644 (file)
index 0000000..3f610bb
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef TR_NAME_H
+#define TR_NAME_H
+
+typedef struct tr__name {
+  char *buf;
+  int len;
+} TR_NAME;
+
+TR_NAME *tr_new_name (char *name);
+TR_NAME *tr_dup_name (TR_NAME *from);
+
+#endif
index e9204f6..ec56fc4 100644 (file)
@@ -45,8 +45,8 @@ int tpqs_req_handler (TPQS_INSTANCE * tpqs,
   if (tpqs)
     tpqs->req_count++;
 
-  if ((NULL == (resp->realm = tpq_dup_name(req->realm))) ||
-      (NULL == (resp->coi = tpq_dup_name(req->coi)))) {
+  if ((NULL == (resp->realm = tr_dup_name(req->realm))) ||
+      (NULL == (resp->coi = tr_dup_name(req->coi)))) {
     printf ("Error in tpq_dup_name, not responding.\n");
     return 1;
   }
diff --git a/tr/tr_config.c b/tr/tr_config.c
new file mode 100644 (file)
index 0000000..b4820b3
--- /dev/null
@@ -0,0 +1,45 @@
+
+
+/*
+ * Copyright (c) 2012, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+
+#include <tr_config.h>
+
+int tr_read_config (FILE *cfg_file) {
+  int rc = 0;
+
+  return rc;
+}
index f539ce4..4e4ea7a 100644 (file)
@@ -34,7 +34,7 @@
 
 #include <stdio.h>
 
-#include <trust_router.h>
+#include <tr.h>
 
 int tpqs_req_handler (TPQS_INSTANCE * tpqs,
                      TPQ_REQ *req, 
@@ -45,8 +45,8 @@ int tpqs_req_handler (TPQS_INSTANCE * tpqs,
   if (tpqs)
     tpqs->req_count++;
 
-  if ((NULL == (resp->realm = tpq_dup_name(req->realm))) ||
-      (NULL == (resp->coi = tpq_dup_name(req->coi)))) {
+  if ((NULL == (resp->realm = tr_dup_name(req->realm))) ||
+      (NULL == (resp->coi = tr_dup_name(req->coi)))) {
     printf ("Error in tpq_dup_name, not responding.\n");
     return 1;
   }