Add next_hop field to route update record, filled in locally.
[trust_router.git] / trp / trp_req.c
1 #include <jansson.h>
2 #include <talloc.h>
3
4 #include <trust_router/tr_name.h>
5 #include <trp_internal.h>
6 #include <tr_debug.h>
7
8 static int trp_req_destructor(void *object)
9 {
10   TRP_REQ *req=talloc_get_type_abort(object, TRP_REQ);
11   
12   /* clean up TR_NAME data, which are not managed by talloc */
13   if (req->comm != NULL) {
14     tr_free_name(req->comm);
15     req->comm=NULL;
16     tr_debug("trp_req_destructor: freed community");
17   }
18   if (req->realm != NULL) {
19     tr_free_name(req->realm);
20     req->realm=NULL;
21     tr_debug("trp_req_destructor: freed realm");
22   }
23   return 0;
24 }
25
26 TRP_REQ *trp_req_new(TALLOC_CTX *mem_ctx)
27 {
28   TRP_REQ *new_req=talloc(mem_ctx, TRP_REQ);
29
30   if (new_req != NULL) {
31     new_req->comm=NULL;
32     new_req->realm=NULL;
33   }
34
35   talloc_set_destructor((void *)new_req, trp_req_destructor);
36   return new_req;
37 }
38
39 void trp_req_free(TRP_REQ *req)
40 {
41   if (req!=NULL)
42     talloc_free(req);
43 }
44
45 TR_NAME *trp_req_get_comm(TRP_REQ *req)
46 {
47   if (req!=NULL)
48     return req->comm;
49   else
50     return NULL;
51 }
52
53 void trp_req_set_comm(TRP_REQ *req, TR_NAME *comm)
54 {
55   if (req)
56     req->comm=comm;
57 }
58
59 TR_NAME *trp_req_get_realm(TRP_REQ *req)
60 {
61   if (req!=NULL)
62     return req->realm;
63   else
64     return NULL;
65 }
66
67
68 void trp_req_set_realm(TRP_REQ *req, TR_NAME *realm)
69 {
70   if (req)
71     req->realm=realm;
72 }