client.h 3.33 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).
11
 * Copyright 2011-2018, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
12 13
 */

Jack Moffitt's avatar
Jack Moffitt committed
14
/* client.h
15 16 17 18
 **
 ** client data structions and function definitions
 **
 */
Jack Moffitt's avatar
Jack Moffitt committed
19 20 21
#ifndef __CLIENT_H__
#define __CLIENT_H__

22
#include "icecasttypes.h"
23
#include "errors.h"
Michael Smith's avatar
Michael Smith committed
24
#include "connection.h"
Michael Smith's avatar
Michael Smith committed
25
#include "refbuf.h"
Philipp Schafft's avatar
Philipp Schafft committed
26
#include "acl.h"
27
#include "cfgfile.h"
28
#include "admin.h"
Marvin Scholz's avatar
Marvin Scholz committed
29
#include "common/httpp/httpp.h"
30
#include "common/httpp/encoding.h"
Michael Smith's avatar
Michael Smith committed
31

32 33
#define CLIENT_DEFAULT_ADMIN_FORMAT                     ADMIN_FORMAT_TRANSFORMED

Philipp Schafft's avatar
Philipp Schafft committed
34 35 36 37 38
typedef enum _protocol_tag {
    ICECAST_PROTOCOL_HTTP = 0,
    ICECAST_PROTOCOL_SHOUTCAST
} protocol_t;

39 40 41 42
typedef enum _reuse_tag {
    /* do not reuse */
    ICECAST_REUSE_CLOSE = 0,
    /* reuse */
43 44 45
    ICECAST_REUSE_KEEPALIVE,
    /* Upgrade to TLS */
    ICECAST_REUSE_UPGRADETLS
46 47
} reuse_t;

48
struct _client_tag {
49 50 51
    /* mode of operation for this client */
    operation_mode mode;

Michael Smith's avatar
Michael Smith committed
52
    /* the client's connection */
53
    connection_t *con;
54 55 56 57

    /* Reuse this connection ... */
    reuse_t reuse;

Michael Smith's avatar
Michael Smith committed
58
    /* the client's http headers */
59
    http_parser_t *parser;
Jack Moffitt's avatar
Jack Moffitt committed
60

61 62 63
    /* Transfer Encoding if any */
    httpp_encoding_t *encoding;

Philipp Schafft's avatar
Philipp Schafft committed
64 65 66
    /* protocol client uses */
    protocol_t protocol;

67 68
    /* http response code for this client */
    int respcode;
Jack Moffitt's avatar
Jack Moffitt committed
69

Philipp Schafft's avatar
Philipp Schafft committed
70
    /* admin command if any. ADMIN_COMMAND_ERROR if not an admin command. */
71
    admin_command_id_t admin_command;
Philipp Schafft's avatar
Philipp Schafft committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

    /* authentication instances we still need to go thru */
    struct auth_stack_tag *authstack;

    /* Client username */
    char *username;

    /* Client password */
    char *password;

    /* Client role */
    char *role;

    /* active ACL, set as soon as the client is authenticated */
    acl_t *acl;
87

88 89
    /* is client getting intro data */
    long intro_offset;
Karl Heyes's avatar
Karl Heyes committed
90

Karl Heyes's avatar
Karl Heyes committed
91 92 93
    /* where in the queue the client is */
    refbuf_t *refbuf;

94
    /* position in first buffer */
95
    unsigned int pos;
96

97
    /* auth used for this client */
98
    auth_t *auth;
99

100 101
    /* Format-handler-specific data for this client */
    void *format_data;
102 103

    /* function to call to release format specific resources */
104
    void (*free_client_data)(client_t *client);
Karl Heyes's avatar
Karl Heyes committed
105

106
    /* write out data associated with client */
107
    int (*write_to_client)(client_t *client);
108

Karl Heyes's avatar
Karl Heyes committed
109
    /* function to check if refbuf needs updating */
110
    int (*check_buffer)(source_t *source, client_t *client);
111
};
Jack Moffitt's avatar
Jack Moffitt committed
112

113
int client_create (client_t **c_ptr, connection_t *con, http_parser_t *parser);
Jack Moffitt's avatar
Jack Moffitt committed
114
void client_destroy(client_t *client);
115
void client_send_error_by_id(client_t *client, icecast_error_id_t id);
116
void client_send_101(client_t *client, reuse_t reuse);
117
void client_send_204(client_t *client);
118
void client_send_426(client_t *client, reuse_t reuse);
119
admin_format_t client_get_admin_format_by_content_negotiation(client_t *client);
120
int client_send_bytes (client_t *client, const void *buf, unsigned len);
121
int client_read_bytes (client_t *client, void *buf, unsigned len);
Karl Heyes's avatar
Karl Heyes committed
122
void client_set_queue (client_t *client, refbuf_t *refbuf);
Jack Moffitt's avatar
Jack Moffitt committed
123 124

#endif  /* __CLIENT_H__ */