Separate TRP from main trust router code.
[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
11 typedef struct trp_req {
12   int msg;
13 } TRP_REQ;
14
15 typedef struct trp_resp {
16   int msg;
17 } TRP_RESP;
18
19 typedef struct trps_instance TRPS_INSTANCE;
20
21 typedef int (TRPS_REQ_FUNC)(TRPS_INSTANCE *, TRP_REQ *, TRP_RESP *, void *);
22 typedef void (TRPS_RESP_FUNC)(TRPS_INSTANCE *, TRP_REQ *, TRP_RESP *, void *);
23 typedef int (trps_auth_func)(gss_name_t client_name, TR_NAME *display_name, void *cookie);
24
25
26 /* encapsulate a gss context and its connection file handle */
27 typedef struct trps_connection {
28   int conn;
29   gss_ctx_id_t *gssctx;
30 } TRPS_CONNECTION;
31
32 /* a collection of the above */
33 #define TRPS_CONNECTIONS_MAX 10;
34 typedef struct trps_connection_set {
35   TRPS_CONNECTION *conn[TRPS_CONNECTIONS_MAX];
36   unsigned int nconn;
37 } TRPS_CONNECTION_SET;
38
39 /* TRP Client Instance Data */
40 typedef struct trpc_instance {
41   DH *client_dh;                        /* Client's DH struct with priv and pub keys */
42 } TRPC_INSTANCE;
43
44 /* TRP Server Instance Data */
45 struct trps_instance {
46   char *hostname;
47   unsigned int port;
48   TRPS_REQ_FUNC *req_handler;
49   trps_auth_func *auth_handler;
50   void *cookie;
51   struct tr_rp_client *rp_gss;          /* Client matching GSS name, TBD -- FIX ME (??) */
52   TRPS_CONNECTION_SET *connections; /* active GSS connections */
53 };
54
55 typedef enum {
56   TRPS_ERR_OK=0, /* success */
57   TRPS_ERR_NOMEM, /* allocation problem */
58   TRPS_ERR_MAX_CONN, /* out of connections */
59   TRPS_ERR_UNKNOWN /* catch-all */
60 } TRPS_ERR;
61
62 /* prototypes */
63
64 /* these should probably  be static? */
65 TRPS_CONNECTION *trps_connection_new(TALLOC_CTX *mem_ctx);
66 TRPS_CONNECTION_SET *trps_connection_set_new(TALLOC_CTX *mem_ctx);
67 TRPS_ERR trps_connection_set_add(TRPS_CONNECTION_SET *tcs, TRPS_CONNECTION *new_conn);
68 TRPS_ERR trps_connection_set_del(TRPS_CONNECTION_SET *tcs, TRPS_CONNECTION *conn);
69 unsigned int trps_connection_set_len(TRPS_CONNECTION_SET *tcs);
70
71 TRPC_INSTANCE *trpc_create (TALLOC_CTX *mem_ctx);
72 void trpc_destroy (TRPC_INSTANCE *trpc);
73 int trpc_open_connection (TRPC_INSTANCE *trpc, char *server, unsigned int port, gss_ctx_id_t *gssctx);
74 int trpc_send_msg (TRPC_INSTANCE *trpc, int conn, gss_ctx_id_t gssctx, const char *msg_content,
75                    int *resp_handler(), void *cookie);
76
77 TRPS_INSTANCE *trps_create (TALLOC_CTX *mem_ctx);
78 void trps_destroy (TRPS_INSTANCE *trps);
79 int trps_send_msg (TRPS_INSTANCE *trps, int conn, gss_ctx_id_t gssctx, const char *msg_content);
80 int trps_accept(TRPS_INSTANCE *trps, int listen);
81
82 #endif /* TRP_INTERNAL_H */