tid_req: Store json references
[trust_router.git] / tid / tid_req.c
1 /*
2  * Copyright (c) 2012, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31  * OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <assert.h>
38
39 #include <trust_router/tid.h>
40 #include <jansson.h>
41
42 TID_REQ *tid_req_new()
43 {
44   TID_REQ *req = calloc(sizeof(TID_REQ), 1);
45   if(!req)
46     return NULL;
47   req->json_references = json_array();
48   assert(req->json_references);
49   req->conn = -1;
50   return req;
51 }
52
53 TID_REQ *tid_req_get_next_req(TID_REQ *req)
54 {
55   return(req->next_req);
56 }
57
58 void tid_req_set_next_req(TID_REQ *req, TID_REQ *next_req)
59 {
60   req->next_req = next_req;
61 }
62
63 int tid_req_get_resp_sent(TID_REQ *req)
64 {
65   return(req->resp_sent);
66 }
67
68 void tid_req_set_resp_sent(TID_REQ *req, int resp_sent)
69 {
70   req->resp_sent = resp_sent;
71 }
72
73 int tid_req_get_conn(TID_REQ *req)
74 {
75   return(req->conn);
76 }
77
78 void tid_req_set_conn(TID_REQ *req, int conn)
79 {
80   req->conn = conn;
81 }
82
83 gss_ctx_id_t tid_req_get_gssctx(TID_REQ *req)
84 {
85   return(req->gssctx);
86 }
87
88 void tid_req_set_gssctx(TID_REQ *req, gss_ctx_id_t gssctx)
89 {
90   req->gssctx = gssctx;
91 }
92
93 int tid_req_get_resp_rcvd(TID_REQ *req)
94 {
95   return(req->resp_rcvd);
96 }
97
98 void tid_req_set_resp_rcvd(TID_REQ *req, int resp_rcvd)
99 {
100   req->resp_rcvd = resp_rcvd;
101 }
102
103 TR_NAME *tid_req_get_rp_realm(TID_REQ *req)
104 {
105   return(req->rp_realm);
106 }
107
108 void tid_req_set_rp_realm(TID_REQ *req, TR_NAME *rp_realm)
109 {
110   req->rp_realm = rp_realm;
111 }
112
113 TR_NAME *tid_req_get_realm(TID_REQ *req)
114 {
115   return(req->realm);
116 }
117
118 void tid_req_set_realm(TID_REQ *req, TR_NAME *realm)
119 {
120   req->realm = realm;
121 }
122
123 TR_NAME *tid_req_get_comm(TID_REQ *req)
124 {
125   return(req->comm);
126 }
127
128 void tid_req_set_comm(TID_REQ *req, TR_NAME *comm)
129 {
130   req->comm = comm;
131 }
132
133 TR_NAME *tid_req_get_orig_coi(TID_REQ *req)
134 {
135   return(req->orig_coi);
136 }
137
138 void tid_req_set_rp_orig_coi(TID_REQ *req, TR_NAME *orig_coi)
139 {
140   req->orig_coi = orig_coi;
141 }
142
143 TIDC_RESP_FUNC *tid_req_get_resp_func(TID_REQ *req)
144 {
145   return(req->resp_func);
146 }
147
148 void tid_req_set_resp_func(TID_REQ *req, TIDC_RESP_FUNC *resp_func)
149 {
150   req->resp_func = resp_func;
151 }
152
153 void *tid_req_get_cookie(TID_REQ *req)
154 {
155   return(req->cookie);
156 }
157
158 void tid_req_set_cookie(TID_REQ *req, void *cookie)
159 {
160   req->cookie = cookie;
161 }
162
163 TID_REQ *tid_dup_req (TID_REQ *orig_req) 
164 {
165   TID_REQ *new_req = NULL;
166
167   if (NULL == (new_req = malloc(sizeof(TID_REQ)))) {
168     fprintf(stderr, "tid_dup_req: Can't allocated duplicate request.\n");
169     return NULL;
170   }
171
172   /* Memcpy for flat fields, not valid until names are duped. */
173   memcpy(new_req, orig_req, sizeof(TID_REQ));
174   json_incref(new_req->json_references);
175   
176   if ((NULL == (new_req->rp_realm = tr_dup_name(orig_req->rp_realm))) ||
177       (NULL == (new_req->realm = tr_dup_name(orig_req->realm))) ||
178       (NULL == (new_req->comm = tr_dup_name(orig_req->comm)))) {
179         fprintf(stderr, "tid_dup_req: Can't duplicate request (names).\n");
180   }
181
182   if (orig_req->orig_coi) {
183     if (NULL == (new_req->orig_coi = tr_dup_name(orig_req->orig_coi))) {
184       fprintf(stderr, "tid_dup_req: Can't duplicate request (orig_coi).\n");
185     }
186   }
187   
188   return new_req;
189 }
190
191
192 void tid_req_cleanup_json( TID_REQ *req, json_t *ref)
193 {
194   (void) json_array_append_new(req->json_references, ref);
195 }