connection.h 2.83 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>
18
#include <time.h>
19 20

#include "tls.h"
21

22
#include "icecasttypes.h"
23
#include "compat.h"
24 25
#include "common/thread/thread.h"
#include "common/net/sock.h"
26

27 28
typedef unsigned long connection_id_t;

29
struct connection_tag {
30 31 32
    /* Connection ID.
     * This is uniq until it overflows (typically at least 2^32 clients).
     */
33
    connection_id_t id;
Jack Moffitt's avatar
Jack Moffitt committed
34

35
    /* Timestamp of client connecting */
36
    time_t con_time;
37
    /* Timestamp of when the client must be disconnected (reached listentime limit) OR 0 for no limit. */
38
    time_t discon_time;
39
    /* Bytes sent on this connection */
40
    uint64_t sent_bytes;
Jack Moffitt's avatar
Jack Moffitt committed
41

42
    /* Physical socket the client is connected on */
43
    sock_t sock;
44
    /* real and effective listen socket the connect used to connect. */
45 46
    listensocket_t *listensocket_real;
    listensocket_t *listensocket_effective;
47 48

    /* Is the connection in an error condition? */
49
    int error;
Jack Moffitt's avatar
Jack Moffitt committed
50

51
    /* Current TLS mode and state of the client. */
52
    tlsmode_t tlsmode;
53
    tls_t *tls;
54 55 56 57

    /* I/O Callbacks. Should never be called directly.
     * Use connection_*_bytes() for I/O operations.
     */
58 59
    int (*send)(connection_t *handle, const void *buf, size_t len);
    int (*read)(connection_t *handle, void *buf, size_t len);
60

61
    /* Buffers for putback of data into the connection's read queue. */
62 63 64
    void *readbuffer;
    size_t readbufferlen;

65
    /* IP Address of the client as seen by the server */
66
    char *ip;
67
};
Jack Moffitt's avatar
Jack Moffitt committed
68 69 70

void connection_initialize(void);
void connection_shutdown(void);
71
void connection_reread_config(ice_config_t *config);
Jack Moffitt's avatar
Jack Moffitt committed
72
void connection_accept_loop(void);
73
void connection_setup_sockets(ice_config_t *config);
Jack Moffitt's avatar
Jack Moffitt committed
74
void connection_close(connection_t *con);
75
connection_t *connection_create(sock_t sock, listensocket_t *listensocket_real, listensocket_t* listensocket_effective, char *ip);
76
int connection_complete_source(source_t *source, int response);
77
void connection_queue(connection_t *con);
78
void connection_queue_client(client_t *client);
79
void connection_uses_tls(connection_t *con);
80

81
ssize_t connection_send_bytes(connection_t *con, const void *buf, size_t len);
82
ssize_t connection_read_bytes(connection_t *con, void *buf, size_t len);
83
int connection_read_put_back(connection_t *con, const void *buf, size_t len);
84

85
extern rwlock_t _source_shutdown_rwlock;
Jack Moffitt's avatar
Jack Moffitt committed
86 87

#endif  /* __CONNECTION_H__ */