First stab at a working blocking example.
[radsecproxy.git] / lib / libradsec-base.h
1 /** @file libradsec-base.h
2     @brief Low level API for libradsec.  */
3
4 /* FIXME: License blurb goes here.  */
5
6 #include <unistd.h>
7 #include <stdint.h>
8 #include <sys/socket.h>
9 #include "libradsec.h"
10
11 /* Function prototypes.  */
12
13 /** Establish a connection.
14
15     @param type Connection type.
16     @param addr Network address to connect to.
17     @param cred Credentials, or NULL.
18
19     @return A file descriptor or -1 if an error occurred, in which
20     case errno is set appropriately.  */
21 int rs_connect(const struct rs_config *conf,
22                const struct sockaddr *addr,
23                socklen_t addrlen);
24
25 /** Disconnect.
26
27     @param fd File descriptor to close.
28
29     @return 0 on success or -1 if an error occurred, in which case
30     errno is set appropriately.  */
31 int rs_disconnect(const struct rs_config *conf,
32                   int fd);
33
34 /** Allocate and initialize a packet from a buffer containing a packet
35     as seen on the wire.  Free the packet using @a rs_packet_free().
36
37 FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
38
39     @param buf Buffer with on-the-wire data with packet.
40     @param buflen Number of octets in @a buf.
41
42     @param count Number of octets used in buffer, in case of
43     successful construction of a packet (return !NULL) or number of
44     octets needed for a complete packet (return NULL).
45
46 FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
47
48     @return Packet or NULL on error or not enough data in @a buf.  If
49     return value is NULL and @a count is < 0, an error has occurred
50     and errno is set appropriately.  If return value is NULL and @a
51     count is > 0 it shows the number of bytes needed to complete the
52     packet.  */
53 struct rs_packet *rs_packet_new(const struct rs_config *ctx,
54                                 const uint8_t buf[RS_HEADER_LEN],
55                                 size_t *count);
56
57 /* FIXME: if return NULL, @a packet is freed and the pointer is no longer valid!  */
58 struct rs_packet *rs_packet_parse(const struct rs_config *ctx,
59                                   struct rs_packet **packet,
60                                   const uint8_t *buf,
61                                   size_t buflen);
62
63 /** Free a packet that has been allocated by @a rs_packet_new().
64
65     @param packet Packet to free.
66     FIXME
67 */
68 void rs_packet_free(const struct rs_config *ctx,
69                     struct rs_packet **packet);
70
71 /** Serialize a packet.
72
73     @param packet Packet to serialize.
74     @param buf Buffer to store the serialized packet in.
75     @param buflen Length of buffer.
76
77     @return Number of bytes written to buf or 0 if the buffer wasn't
78     large enough to hold the packet or < 0 in case the packet couldn't
79     be serialized for some other eason (FIXME: elaborate) */
80
81 ssize_t rs_packet_serialize(const struct rs_packet *packet,
82                             uint8_t *buf,
83                             size_t buflen);