From 22b24d3ea4e5da07cd3c1ad3a12241b5f3cd8ac8 Mon Sep 17 00:00:00 2001 From: Margaret Wasserman Date: Mon, 17 Dec 2012 14:56:05 -0500 Subject: [PATCH] Reorganize common code (for msgs, names...) to be used across tr components. --- Makefile.am | 21 +++++++----- common/tr_config.c | 10 +++--- tpq/tpq_json.c => common/tr_msg.c | 15 ++------- tpq/tpq_common.c => common/tr_name.c | 16 ++++----- include/tpq.h | 21 +++--------- include/{trust_router.h => tr.h} | 9 ++--- include/tr_config.h | 42 +++++++++++++++++++++++ include/tr_msg.h | 64 ++++++++++++++++++++++++++++++++++++ include/tr_name.h | 46 ++++++++++++++++++++++++++ tpq/example/tpqs_main.c | 4 +-- tr/tr_config.c | 45 +++++++++++++++++++++++++ tr/tr_main.c | 6 ++-- 12 files changed, 239 insertions(+), 60 deletions(-) rename tpq/tpq_json.c => common/tr_msg.c (89%) rename tpq/tpq_common.c => common/tr_name.c (88%) rename include/{trust_router.h => tr.h} (94%) create mode 100644 include/tr_config.h create mode 100644 include/tr_msg.h create mode 100644 include/tr_name.h create mode 100644 tr/tr_config.c diff --git a/Makefile.am b/Makefile.am index 9eadb0f..26231dd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/common/tr_config.c b/common/tr_config.c index 93e12e1..bd47832 100644 --- a/common/tr_config.c +++ b/common/tr_config.c @@ -1,5 +1,3 @@ - - /* * Copyright (c) 2012, JANET(UK) * All rights reserved. @@ -34,12 +32,12 @@ * */ -#include +#include +#include -#include +#include int tr_read_config (FILE *cfg_file) { - int rc = 0; - return rc; + return 0; } diff --git a/tpq/tpq_json.c b/common/tr_msg.c similarity index 89% rename from tpq/tpq_json.c rename to common/tr_msg.c index 6732589..2aa99ea 100644 --- a/tpq/tpq_json.c +++ b/common/tr_msg.c @@ -35,26 +35,17 @@ #include #include -#include +#include -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; -} diff --git a/tpq/tpq_common.c b/common/tr_name.c similarity index 88% rename from tpq/tpq_common.c rename to common/tr_name.c index 5c78043..7136f49 100644 --- a/tpq/tpq_common.c +++ b/common/tr_name.c @@ -35,13 +35,13 @@ #include #include -#include +#include -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 */ } } diff --git a/include/tpq.h b/include/tpq.h index c51958d..db1ac42 100644 --- a/include/tpq.h +++ b/include/tpq.h @@ -38,23 +38,20 @@ #define TPQ_PORT 12309 #include -typedef struct tpq_name { - char *buf; - int len; -} TPQ_NAME; +#include 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); diff --git a/include/trust_router.h b/include/tr.h similarity index 94% rename from include/trust_router.h rename to include/tr.h index b6a533a..9fee9dd 100644 --- a/include/trust_router.h +++ b/include/tr.h @@ -32,14 +32,15 @@ * */ -#ifndef TRUST_ROUTER_H -#define TRUST_ROUTER_H +#ifndef TR_H +#define TR_H +#include +#include +#include #include #include #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 index 0000000..3b5559e --- /dev/null +++ b/include/tr_config.h @@ -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 + +int tr_read_config (FILE *cfg_file); + +#endif diff --git a/include/tr_msg.h b/include/tr_msg.h new file mode 100644 index 0000000..8943559 --- /dev/null +++ b/include/tr_msg.h @@ -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 +// #include +#include + +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 index 0000000..3f610bb --- /dev/null +++ b/include/tr_name.h @@ -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 diff --git a/tpq/example/tpqs_main.c b/tpq/example/tpqs_main.c index e9204f6..ec56fc4 100644 --- a/tpq/example/tpqs_main.c +++ b/tpq/example/tpqs_main.c @@ -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 index 0000000..b4820b3 --- /dev/null +++ b/tr/tr_config.c @@ -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 + +#include + +int tr_read_config (FILE *cfg_file) { + int rc = 0; + + return rc; +} diff --git a/tr/tr_main.c b/tr/tr_main.c index f539ce4..4e4ea7a 100644 --- a/tr/tr_main.c +++ b/tr/tr_main.c @@ -34,7 +34,7 @@ #include -#include +#include 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; } -- 2.1.4