connection.h 2.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/* Icecast
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
 * Copyright 2000-2004, Jack Moffitt <jack@xiph.org, 
 *                      Michael Smith <msmith@xiph.org>,
 *                      oddsock <oddsock@xiph.org>,
 *                      Karl Heyes <karl@xiph.org>
 *                      and others (see AUTHORS for details).
Philipp Schafft's avatar
Philipp Schafft committed
11
 * Copyright 2014,      Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
12 13
 */

Jack Moffitt's avatar
Jack Moffitt committed
14 15 16
#ifndef __CONNECTION_H__
#define __CONNECTION_H__

17
#include <sys/types.h>
Michael Smith's avatar
Michael Smith committed
18
#include <time.h>
19 20

#include "tls.h"
21

22
#include "compat.h"
Marvin Scholz's avatar
Marvin Scholz committed
23 24 25
#include "common/httpp/httpp.h"
#include "common/thread/thread.h"
#include "common/net/sock.h"
26

27
struct _client_tag;
28
struct source_tag;
29
struct ice_config_tag;
30

31 32 33 34 35
typedef enum _tlsmode_tag {
    /* no TLS is used at all */
    ICECAST_TLSMODE_DISABLED = 0,
    /* TLS mode is to be detected */
    ICECAST_TLSMODE_AUTO,
36 37
    /* Like ICECAST_TLSMODE_AUTO but enforces TLS */
    ICECAST_TLSMODE_AUTO_NO_PLAIN,
38 39 40 41 42 43
    /* TLS via HTTP Upgrade:-header [RFC2817] */
    ICECAST_TLSMODE_RFC2817,
    /* TLS for transport layer like HTTPS [RFC2818] does */
    ICECAST_TLSMODE_RFC2818
} tlsmode_t;

Jack Moffitt's avatar
Jack Moffitt committed
44 45
typedef struct connection_tag
{
46
    unsigned long id;
Jack Moffitt's avatar
Jack Moffitt committed
47

48
    time_t con_time;
49
    time_t discon_time;
50
    uint64_t sent_bytes;
Jack Moffitt's avatar
Jack Moffitt committed
51

52 53
    sock_t sock;
    sock_t serversock;
54
    int error;
Jack Moffitt's avatar
Jack Moffitt committed
55

56
    tlsmode_t tlsmode;
57
    tls_t *tls;
58 59 60
    int (*send)(struct connection_tag *handle, const void *buf, size_t len);
    int (*read)(struct connection_tag *handle, void *buf, size_t len);

61
    char *ip;
Jack Moffitt's avatar
Jack Moffitt committed
62 63 64 65
} connection_t;

void connection_initialize(void);
void connection_shutdown(void);
66
void connection_reread_config(struct ice_config_tag *config);
Jack Moffitt's avatar
Jack Moffitt committed
67
void connection_accept_loop(void);
68
int connection_setup_sockets(struct ice_config_tag *config);
Jack Moffitt's avatar
Jack Moffitt committed
69
void connection_close(connection_t *con);
70 71
connection_t *connection_create(sock_t sock, sock_t serversock, char *ip);
int connection_complete_source(struct source_tag *source, int response);
72
void connection_queue(connection_t *con);
73
void connection_uses_tls(connection_t *con);
74

75 76
ssize_t connection_read_bytes(connection_t *con, void *buf, size_t len);

77
extern rwlock_t _source_shutdown_rwlock;
Jack Moffitt's avatar
Jack Moffitt committed
78 79

#endif  /* __CONNECTION_H__ */