X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=tid%2Ftid_req.c;h=a1a7a5a46502fa6e2585af11975a8cc5b20233e4;hb=39c2dec6054da6fb692b40f6b5ac374795b17092;hp=6bb269ba9ca5d7e5be305b89bf65cf78bc3f1cdd;hpb=bc3b722a7f84211da42f309158c42eff0e7b9329;p=trust_router.git diff --git a/tid/tid_req.c b/tid/tid_req.c index 6bb269b..a1a7a5a 100644 --- a/tid/tid_req.c +++ b/tid/tid_req.c @@ -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 @@ -34,8 +34,36 @@ #include #include +#include +#include + +#include +#include + +#include + +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; +} + +TID_REQ *tid_req_new() +{ + TID_REQ *req = talloc_zero(NULL, TID_REQ); + if(!req) + return NULL; + talloc_set_destructor(req, destroy_tid_req); + req->json_references = json_array(); + assert(req->json_references); + req->conn = -1; + return req; +} -#include TID_REQ *tid_req_get_next_req(TID_REQ *req) { return(req->next_req); @@ -151,25 +179,79 @@ TID_REQ *tid_dup_req (TID_REQ *orig_req) TID_REQ *new_req = NULL; if (NULL == (new_req = malloc(sizeof(TID_REQ)))) { - fprintf(stderr, "tid_dup_req: Can't allocated duplicate request.\n"); + tr_crit("tid_dup_req: Can't allocated duplicate request."); return NULL; } /* Memcpy for flat fields, not valid until names are duped. */ memcpy(new_req, orig_req, sizeof(TID_REQ)); + json_incref(new_req->json_references); if ((NULL == (new_req->rp_realm = tr_dup_name(orig_req->rp_realm))) || (NULL == (new_req->realm = tr_dup_name(orig_req->realm))) || (NULL == (new_req->comm = tr_dup_name(orig_req->comm)))) { - fprintf(stderr, "tid_dup_req: Can't duplicate request (names).\n"); + tr_crit("tid_dup_req: Can't duplicate request (names)."); } if (orig_req->orig_coi) { if (NULL == (new_req->orig_coi = tr_dup_name(orig_req->orig_coi))) { - fprintf(stderr, "tid_dup_req: Can't duplicate request (orig_coi).\n"); + tr_crit("tid_dup_req: Can't duplicate request (orig_coi)."); } } return new_req; } + +void tid_req_cleanup_json( TID_REQ *req, json_t *ref) +{ + (void) json_array_append_new(req->json_references, ref); +} + +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; +}