Progress towards parsing update messages.
[trust_router.git] / include / trp_internal.h
1 #ifndef TRP_INTERNAL_H
2 #define TRP_INTERNAL_H
3
4 #include <talloc.h>
5
6 #include <gsscon.h>
7 #include <trust_router/tr_dh.h>
8
9 #define TRP_PORT 12310
10 #define TRP_METRIC_INFINITY 0xFFFF
11
12 typedef enum trp_rc {
13   TRP_SUCCESS=0,
14   TRP_ERROR, /* generic error */
15   TRP_NOPARSE, /* parse error */
16   TRP_NOMEM, /* allocation error */
17   TRP_BADTYPE, /* typing error */
18 } TRP_RC;
19
20 /*** Messages ***/
21 typedef enum trp_msg_type {
22   TRP_MSG_TYPE_UNKNOWN=0, /* conveniently, JSON parser returns 0 if a non-integer number is specified */
23   TRP_MSG_TYPE_UPDATE,
24   TRP_MSG_TYPE_ROUTE_REQ
25 } TRP_MSG_TYPE;
26
27 typedef struct trp_msg {
28   TRP_MSG_TYPE type;
29   void *body;
30 } TRP_MSG;
31
32 typedef struct trp_msg_body_update TRP_MSG_BODY_UPDATE;
33 struct trp_msg_body_update {
34   TRP_MSG_BODY_UPDATE *next;
35   TR_NAME *community;
36   TR_NAME *realm;
37   TR_NAME *trust_router;
38   unsigned int metric;
39   unsigned int interval;
40 };
41
42 typedef struct trp_msg_body_route_req {
43   TR_NAME *community;
44   TR_NAME *realm;
45 } TRP_MSG_BODY_ROUTE_REQ;
46
47 TRP_MSG_TYPE trp_msg_type_from_string(const char *s);
48 const char *trp_msg_type_to_string(TRP_MSG_TYPE msgtype);
49
50 TRP_MSG *trp_msg_new(TALLOC_CTX *mem_ctx);
51 void trp_msg_destroy(TRP_MSG *msg);
52
53
54 typedef struct trps_instance TRPS_INSTANCE;
55
56 /* REMOVE THIS!! --jennifer, 2016-06-13 */
57 typedef TRP_MSG TRP_REQ;
58 typedef TRP_MSG TRP_RESP;
59
60
61 typedef int (TRPS_REQ_FUNC)(TRPS_INSTANCE *, TRP_REQ *, TRP_RESP *, void *);
62 typedef void (TRPS_RESP_FUNC)(TRPS_INSTANCE *, TRP_REQ *, TRP_RESP *, void *);
63 typedef int (trps_auth_func)(gss_name_t client_name, TR_NAME *display_name, void *cookie);
64
65
66 /* encapsulate a gss context and its connection file handle */
67 typedef struct trps_connection {
68   int conn;
69   gss_ctx_id_t *gssctx;
70 } TRPS_CONNECTION;
71
72 /* a collection of the above */
73 #define TRPS_CONNECTIONS_MAX 10
74 typedef struct trps_connection_set {
75   TRPS_CONNECTION *conn[TRPS_CONNECTIONS_MAX];
76   unsigned int nconn;
77 } TRPS_CONNECTION_SET;
78
79 /* TRP Client Instance Data */
80 typedef struct trpc_instance {
81   DH *client_dh;                        /* Client's DH struct with priv and pub keys */
82 } TRPC_INSTANCE;
83
84 /* TRP Server Instance Data */
85 struct trps_instance {
86   char *hostname;
87   unsigned int port;
88   TRPS_REQ_FUNC *req_handler;
89   trps_auth_func *auth_handler;
90   void *cookie;
91   struct tr_rp_client *rp_gss;          /* Client matching GSS name, TBD -- FIX ME (??) */
92   TRPS_CONNECTION_SET *connections; /* active GSS connections */
93 };
94
95 typedef enum {
96   TRPS_ERR_OK=0, /* success */
97   TRPS_ERR_NOMEM, /* allocation problem */
98   TRPS_ERR_MAX_CONN, /* out of connections */
99   TRPS_ERR_UNKNOWN /* catch-all */
100 } TRPS_ERR;
101
102 /* prototypes */
103
104 /* these should probably  be static? */
105 TRPS_CONNECTION *trps_connection_new(TALLOC_CTX *mem_ctx);
106 TRPS_CONNECTION_SET *trps_connection_set_new(TALLOC_CTX *mem_ctx);
107 TRPS_ERR trps_connection_set_add(TRPS_CONNECTION_SET *tcs, TRPS_CONNECTION *new_conn);
108 TRPS_ERR trps_connection_set_del(TRPS_CONNECTION_SET *tcs, TRPS_CONNECTION *conn);
109 unsigned int trps_connection_set_len(TRPS_CONNECTION_SET *tcs);
110
111 TRPC_INSTANCE *trpc_create (TALLOC_CTX *mem_ctx);
112 void trpc_destroy (TRPC_INSTANCE *trpc);
113 int trpc_open_connection (TRPC_INSTANCE *trpc, char *server, unsigned int port, gss_ctx_id_t *gssctx);
114 int trpc_send_msg (TRPC_INSTANCE *trpc, int conn, gss_ctx_id_t gssctx, const char *msg_content,
115                    int *resp_handler(), void *cookie);
116
117 TRPS_INSTANCE *trps_create (TALLOC_CTX *mem_ctx);
118 void trps_destroy (TRPS_INSTANCE *trps);
119 int trps_send_msg (TRPS_INSTANCE *trps, int conn, gss_ctx_id_t gssctx, const char *msg_content);
120 int trps_accept(TRPS_INSTANCE *trps, int listen);
121
122 #endif /* TRP_INTERNAL_H */