Add extern "C" guards to all header files.
[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_packet;
27
28 struct rs_credentials {
29     enum rs_cred_type type;
30     char *identity;
31     char *secret;
32 };
33
34 struct rs_error {
35     int code;
36     char *msg;
37     char buf[1024];
38 };
39
40 struct rs_peer {
41     struct rs_connection *conn;
42     struct rs_realm *realm;
43     struct evutil_addrinfo *addr;
44     int fd;                     /* Socket.  */
45     char is_connecting;         /* FIXME: replace with a single state member */
46     char is_connected;          /* FIXME: replace with a single state member */
47     char *secret;
48     int timeout;                /* client only */
49     int tries;                  /* client only */
50     struct rs_peer *next;
51 };
52
53 struct rs_realm {
54     char *name;
55     enum rs_conn_type type;
56     char *cacertfile;
57     char *cacertpath;
58     char *certfile;
59     char *certkeyfile;
60     struct rs_peer *peers;
61     struct rs_realm *next;
62 };
63
64 struct rs_context {
65     struct rs_realm *realms;
66     struct rs_alloc_scheme alloc_scheme;
67     struct rs_error *err;
68     fr_randctx fr_randctx;
69 };
70
71 struct rs_connection {
72     struct rs_context *ctx;
73     struct event_base *evb;
74     struct bufferevent *bev;
75     enum rs_conn_type type;
76     struct rs_credentials transport_credentials;
77     struct rs_conn_callbacks callbacks;
78     void *user_data;
79     struct rs_peer *peers;
80     struct rs_peer *active_peer;
81     struct rs_error *err;
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
129 /* Local Variables: */
130 /* c-file-style: "stroustrup" */
131 /* End: */