aboutsummaryrefslogtreecommitdiff
path: root/include/connect.h
blob: d733c5ef20cd85e893de2d678a0c6b32408e5fb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef _CONNECT_H_
#define _CONNECT_H_

#include <openssl/ssl.h>

#include "config.h"
#include "url.h"

/* Error codes */
enum ConnectError {
  ERR_GETADDRINFO = -1,
  ERR_SOCKET = -2,
  ERR_CONNECT = -3,
  ERR_SSL_CTX = -4,
  ERR_SSL_SSL = -5,
};

/**
 * Holds all needed information to manage an open TLS connection.
 */
struct connection {
  SSL *ssl;
  int sockfd;
  bool used;
};

/**
 * Connect to molerat server.
 *
 * Sets `*ssl` in `struct config *conf` to the current active connection.
 */
int tls_connect(struct config *conf, struct url url);

/**
 * Disconnect and free open connection
 */
void tls_cleanup(struct connection *conn);

/**
 * Allocate a new instance of a `struct connection`
 */
struct connection *init_connection(void);

#endif