Add RSE_DISCO.
[radsecproxy.git] / lib / include / radsec / radsec.h
1 /** @file libradsec.h
2     @brief Header file for libradsec.  */
3 /* See the file COPYING for licensing information.  */
4
5 #include <unistd.h>
6 #include <sys/time.h>
7
8 enum rs_error_code {
9     RSE_OK = 0,
10     RSE_NOMEM = 1,
11     RSE_NOSYS = 2,
12     RSE_INVALID_CTX = 3,
13     RSE_INVALID_CONN = 4,
14     RSE_CONN_TYPE_MISMATCH = 5,
15     RSE_FR = 6,                 /* FreeRADIUS error.  */
16     RSE_BADADDR = 7,
17     RSE_NOPEER = 8,
18     RSE_EVENT = 9,              /* libevent error.  */
19     RSE_SOCKERR = 10,
20     RSE_CONFIG = 11,
21     RSE_BADAUTH = 12,
22     RSE_INTERNAL = 13,
23     RSE_SSLERR = 14,            /* OpenSSL error.  */
24     RSE_INVALID_PKT = 15,
25     RSE_TIMEOUT_CONN = 16,      /* Connection timeout.  */
26     RSE_INVAL = 17,             /* Invalid argument.  */
27     RSE_TIMEOUT_IO = 18,        /* I/O timeout.  */
28     RSE_TIMEOUT = 19,           /* High level timeout.  */
29     RSE_DISCO = 20,
30 };
31
32 enum rs_conn_type {
33     RS_CONN_TYPE_NONE = 0,
34     RS_CONN_TYPE_UDP,
35     RS_CONN_TYPE_TCP,
36     RS_CONN_TYPE_TLS,
37     RS_CONN_TYPE_DTLS,
38 };
39 typedef unsigned int rs_conn_type_t;
40
41
42 #if defined (__cplusplus)
43 extern "C" {
44 #endif
45
46 /* Data types.  */
47 struct rs_context;              /* radsec-impl.h */
48 struct rs_connection;           /* radsec-impl.h */
49 struct rs_packet;               /* radsec-impl.h */
50 struct rs_conn;                 /* radsec-impl.h */
51 struct rs_attr;                 /* radsec-impl.h */
52 struct rs_error;                /* radsec-impl.h */
53 struct rs_peer;                 /* radsec-impl.h */
54 struct radius_packet;           /* <freeradius/libradius.h> */
55 struct event_base;              /* <event2/event-internal.h> */
56
57 typedef void *(*rs_calloc_fp) (size_t nmemb, size_t size);
58 typedef void *(*rs_malloc_fp) (size_t size);
59 typedef void (*rs_free_fp) (void *ptr);
60 typedef void *(*rs_realloc_fp) (void *ptr, size_t size);
61 struct rs_alloc_scheme {
62     rs_calloc_fp calloc;
63     rs_malloc_fp malloc;
64     rs_free_fp free;
65     rs_realloc_fp realloc;
66 };
67
68 typedef void (*rs_conn_connected_cb) (void *user_data /* FIXME: peer? */ );
69 typedef void (*rs_conn_disconnected_cb) (void *user_data /* FIXME: reason? */ );
70 typedef void (*rs_conn_packet_received_cb) (struct rs_packet *packet,
71                                             void *user_data);
72 typedef void (*rs_conn_packet_sent_cb) (void *user_data);
73 struct rs_conn_callbacks {
74     /** Callback invoked when the connection has been established.  */
75     rs_conn_connected_cb connected_cb;
76     /** Callback invoked when the connection has been torn down.  */
77     rs_conn_disconnected_cb disconnected_cb;
78     /** Callback invoked when a packet was received.  */
79     rs_conn_packet_received_cb received_cb;
80     /** Callback invoked when a packet was successfully sent.  */
81     rs_conn_packet_sent_cb sent_cb;
82 };
83
84
85 /* Function prototypes.  */
86 /* Context.  */
87 int rs_context_create(struct rs_context **ctx, const char *dict);
88 void rs_context_destroy(struct rs_context *ctx);
89 int rs_context_set_alloc_scheme(struct rs_context *ctx,
90                                 struct rs_alloc_scheme *scheme);
91 int rs_context_read_config(struct rs_context *ctx, const char *config_file);
92
93 /* Connection.  */
94 int rs_conn_create(struct rs_context *ctx,
95                    struct rs_connection **conn,
96                    const char *config);
97 void rs_conn_set_type(struct rs_connection *conn, rs_conn_type_t type);
98 int rs_conn_add_listener(struct rs_connection *conn,
99                          rs_conn_type_t type,
100                          const char *hostname,
101                          int port);
102 int rs_conn_disconnect (struct rs_connection *conn);
103 int rs_conn_destroy(struct rs_connection *conn);
104 int rs_conn_set_eventbase(struct rs_connection *conn, struct event_base *eb);
105 void rs_conn_set_callbacks(struct rs_connection *conn,
106                            struct rs_conn_callbacks *cb);
107 void rs_conn_del_callbacks(struct rs_connection *conn);
108 struct rs_conn_callbacks *rs_conn_get_callbacks(struct rs_connection *conn);
109 int rs_conn_select_peer(struct rs_connection *conn, const char *name);
110 int rs_conn_get_current_peer(struct rs_connection *conn,
111                              const char *name,
112                              size_t buflen);
113 int rs_conn_receive_packet(struct rs_connection *conn,
114                            struct rs_packet *request,
115                            struct rs_packet **pkt_out);
116 int rs_conn_fd(struct rs_connection *conn);
117 void rs_conn_set_timeout(struct rs_connection *conn, struct timeval *tv);
118
119 /* Peer -- client and server.  */
120 int rs_peer_create(struct rs_connection *conn, struct rs_peer **peer_out);
121 int rs_peer_set_address(struct rs_peer *peer, const char *hostname,
122                         const char *service);
123 int rs_peer_set_secret(struct rs_peer *peer, const char *secret);
124 void rs_peer_set_timeout(struct rs_peer *peer, int timeout);
125 void rs_peer_set_retries(struct rs_peer *peer, int retries);
126
127 /* Packet.  */
128 int rs_packet_create(struct rs_connection *conn, struct rs_packet **pkt_out);
129 void rs_packet_destroy(struct rs_packet *pkt);
130 void rs_packet_add_attr(struct rs_packet *pkt, struct rs_attr *attr);
131 int rs_packet_send(struct rs_packet *pkt, void *user_data);
132 struct radius_packet *rs_packet_frpkt(struct rs_packet *pkt);
133 int rs_packet_create_authn_request(struct rs_connection *conn,
134                                    struct rs_packet **pkt,
135                                    const char *user_name,
136                                    const char *user_pw);
137
138 /* Attribute.  */
139 /* FIXME: Replace (or complement) with a wrapper for paircreate().  */
140 int rs_attr_create(struct rs_connection *conn,
141                    struct rs_attr **attr,
142                    const char *type,
143                    const char *val);
144 void rs_attr_destroy(struct rs_attr *attr);
145
146 /* Config.  */
147 struct rs_realm *rs_conf_find_realm(struct rs_context *ctx, const char *name);
148
149 /* Error.  */
150 int rs_err_ctx_push(struct rs_context *ctx, int code, const char *fmt, ...);
151 int rs_err_ctx_push_fl(struct rs_context *ctx,
152                        int code,
153                        const char *file,
154                        int line,
155                        const char *fmt,
156                        ...);
157 struct rs_error *rs_err_ctx_pop(struct rs_context *ctx);
158 int rs_err_conn_push(struct rs_connection *conn,
159                      int code,
160                      const char *fmt,
161                      ...);
162 int rs_err_conn_push_fl(struct rs_connection *conn,
163                         int code,
164                         const char *file,
165                         int line,
166                         const char *fmt,
167                         ...);
168 struct rs_error *rs_err_conn_pop(struct rs_connection *conn);
169 int rs_err_conn_peek_code (struct rs_connection *conn);
170 void rs_err_free(struct rs_error *err);
171 char *rs_err_msg(struct rs_error *err);
172 int rs_err_code(struct rs_error *err, int dofree_flag);
173
174 #if defined (__cplusplus)
175 }
176 #endif
177
178 /* Local Variables: */
179 /* c-file-style: "stroustrup" */
180 /* End: */