Config file changes and small API changes.
[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 #if defined(RS_ENABLE_TLS)
9 #include <openssl/ssl.h>
10 #endif
11
12 /* Constants.  */
13 #define RS_HEADER_LEN 4
14
15 /* Data types.  */
16 enum rs_cred_type {
17     RS_CRED_NONE = 0,
18     RS_CRED_TLS_PSK_RSA,        /* RFC 4279.  */
19 };
20 typedef unsigned int rs_cred_type_t;
21
22 #if defined (__cplusplus)
23 extern "C" {
24 #endif
25
26 struct rs_credentials {
27     enum rs_cred_type type;
28     char *identity;
29     char *secret;
30 };
31
32 struct rs_error {
33     int code;
34     char *msg;
35     char buf[1024];
36 };
37
38 struct rs_peer {                /* Config object for a connection.  */
39     struct rs_connection *conn;
40     struct rs_realm *realm;
41     struct evutil_addrinfo *addr;
42     char *secret;
43     struct rs_peer *next;
44 };
45
46 struct rs_realm {             /* Config object for a RADIUS realm.  */
47     char *name;
48     enum rs_conn_type type;
49     int timeout;
50     int retries;
51     char *cacertfile;
52     char *cacertpath;
53     char *certfile;
54     char *certkeyfile;
55     struct rs_peer *peers;
56     struct rs_realm *next;
57 };
58
59 struct rs_context {
60     struct rs_realm *realms;
61     struct rs_alloc_scheme alloc_scheme;
62     struct rs_error *err;
63     fr_randctx fr_randctx;
64 };
65
66 struct rs_connection {
67     struct rs_context *ctx;
68     struct rs_realm *realm;     /* Owned by ctx.  */
69     struct event_base *evb;     /* Event base.  */
70     struct bufferevent *bev;    /* Buffer event.  */
71     struct event *tev;          /* Timeout event.  */
72     struct rs_credentials transport_credentials;
73     struct rs_conn_callbacks callbacks;
74     void *user_data;
75     struct rs_peer *peers;
76     struct rs_peer *active_peer;
77     struct rs_error *err;
78     char is_connecting;         /* FIXME: replace with a single state member */
79     char is_connected;          /* FIXME: replace with a single state member */
80     int fd;                     /* Socket.  */
81     int tryagain;
82     int nextid;
83     int user_dispatch_flag : 1; /* User does the dispatching.  */
84 #if defined(RS_ENABLE_TLS)
85     SSL_CTX *tls_ctx;
86     SSL *tls_ssl;
87 #endif
88 };
89
90 struct rs_packet {
91     struct rs_connection *conn;
92     char hdr_read_flag;
93     uint8_t hdr[4];
94     RADIUS_PACKET *rpkt;
95     struct rs_packet *original;
96 };
97
98 struct rs_attr {
99     struct rs_packet *pkt;
100     VALUE_PAIR *vp;
101 };
102
103 /* Nonpublic functions.  */
104 struct rs_error *_rs_resolv(struct evutil_addrinfo **addr,
105                             rs_conn_type_t type, const char *hostname,
106                             const char *service);
107 struct rs_peer *_rs_peer_create(struct rs_context *ctx,
108                                 struct rs_peer **rootp);
109 struct rs_error *_rs_err_create(unsigned int code, const char *file,
110                                 int line, const char *fmt, ...);
111 int _rs_err_conn_push_err(struct rs_connection *conn,
112                           struct rs_error *err);
113
114
115 #if defined (__cplusplus)
116 }
117 #endif
118
119 /* Convenience macros.  */
120 #define rs_calloc(h, nmemb, size) \
121     (h->alloc_scheme.calloc ? h->alloc_scheme.calloc : calloc)(nmemb, size)
122 #define rs_malloc(h, size) \
123     (h->alloc_scheme.malloc ? h->alloc_scheme.malloc : malloc)(size)
124 #define rs_free(h, ptr) \
125     (h->alloc_scheme.free ? h->alloc_scheme.free : free)(ptr)
126 #define rs_realloc(h, realloc, ptr, size) \
127     (h->alloc_scheme.realloc ? h->alloc_scheme.realloc : realloc)(ptr, size)
128 #define min(a, b) ((a) < (b) ? (a) : (b))
129 #define max(a, b) ((a) > (b) ? (a) : (b))
130
131 /* Local Variables: */
132 /* c-file-style: "stroustrup" */
133 /* End: */