Request object implementation and bug fixes by Luke Howard.
[radsecproxy.git] / lib / include / radsec / radsec-impl.h
1 /** @file libradsec-impl.h
2     @brief Libraray internal header file for libradsec.  */
3
4 /* See the file COPYING for licensing information.  */
5
6 #include <freeradius/libradius.h>
7 #include <event2/util.h>
8
9 /* Constants.  */
10 #define RS_HEADER_LEN 4
11
12 /* Data types.  */
13 enum rs_cred_type {
14     RS_CRED_NONE = 0,
15     RS_CRED_TLS_PSK_RSA,        /* RFC 4279.  */
16 };
17 typedef unsigned int rs_cred_type_t;
18
19 struct rs_packet;
20
21 struct rs_credentials {
22     enum rs_cred_type type;
23     char *identity;
24     char *secret;
25 };
26
27 struct rs_error {
28     int code;
29     char *msg;
30     char buf[1024];
31 };
32
33 struct rs_peer {
34     struct rs_connection *conn;
35     struct evutil_addrinfo *addr;
36     int fd;                     /* Socket.  */
37     char is_connecting;         /* FIXME: replace with a single state member */
38     char is_connected;          /* FIXME: replace with a single state member */
39     char *secret;
40     int timeout;                /* client only */
41     int tries;                  /* client only */
42     struct rs_peer *next;
43 };
44
45 struct rs_realm {
46     char *name;
47     enum rs_conn_type type;
48     struct rs_peer *peers;
49     struct rs_realm *next;
50 };
51
52 struct rs_context {
53     struct rs_realm *realms;
54     struct rs_alloc_scheme alloc_scheme;
55     struct rs_error *err;
56     fr_randctx fr_randctx;
57 };
58
59 struct rs_connection {
60     struct rs_context *ctx;
61     struct event_base *evb;
62     struct bufferevent *bev;
63     enum rs_conn_type type;
64     struct rs_credentials transport_credentials;
65     struct rs_conn_callbacks callbacks;
66     void *user_data;
67     struct rs_peer *peers;
68     struct rs_peer *active_peer;
69     struct rs_error *err;
70     int nextid;
71     int user_dispatch_flag : 1; /* User does the dispatching.  */
72 };
73
74 struct rs_packet {
75     struct rs_connection *conn;
76     char hdr_read_flag;
77     uint8_t hdr[4];
78     RADIUS_PACKET *rpkt;
79 };
80
81 struct rs_attr {
82     struct rs_packet *pkt;
83     VALUE_PAIR *vp;
84 };
85
86 /* Nonpublic functions.  */
87 struct rs_error *_rs_resolv(struct evutil_addrinfo **addr,
88                             rs_conn_type_t type, const char *hostname,
89                             const char *service);
90 struct rs_peer *_rs_peer_create(struct rs_context *ctx,
91                                 struct rs_peer **rootp);
92 struct rs_error *_rs_err_create(unsigned int code, const char *file,
93                                 int line, const char *fmt, ...);
94 int _rs_err_conn_push_err(struct rs_connection *conn,
95                           struct rs_error *err);
96
97
98 /* Convenience macros.  */
99 #define rs_calloc(h, nmemb, size) \
100     (h->alloc_scheme.calloc ? h->alloc_scheme.calloc : calloc)(nmemb, size)
101 #define rs_malloc(h, size) \
102     (h->alloc_scheme.malloc ? h->alloc_scheme.malloc : malloc)(size)
103 #define rs_free(h, ptr) \
104     (h->alloc_scheme.free ? h->alloc_scheme.free : free)(ptr)
105 #define rs_realloc(h, realloc, ptr, size) \
106     (h->alloc_scheme.realloc ? h->alloc_scheme.realloc : realloc)(ptr, size)
107
108 /* Local Variables: */
109 /* c-file-style: "stroustrup" */
110 /* End: */