client.h 4.54 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 23 24
#include "common/httpp/httpp.h"
#include "common/httpp/encoding.h"

25
#include "icecasttypes.h"
26
#include "errors.h"
Michael Smith's avatar
Michael Smith committed
27
#include "refbuf.h"
28
#include "module.h"
Michael Smith's avatar
Michael Smith committed
29

30 31
#define CLIENT_DEFAULT_REPORT_XSL_TRANSFORMED           "report-html.xsl"
#define CLIENT_DEFAULT_REPORT_XSL_PLAINTEXT             "report-plaintext.xsl"
32 33
#define CLIENT_DEFAULT_ERROR_XSL_TRANSFORMED            "error-html.xsl"
#define CLIENT_DEFAULT_ERROR_XSL_PLAINTEXT              "error-plaintext.xsl"
34 35
#define CLIENT_DEFAULT_ADMIN_FORMAT                     ADMIN_FORMAT_TRANSFORMED

36 37 38 39 40
typedef enum _document_domain_tag {
    DOCUMENT_DOMAIN_WEB,
    DOCUMENT_DOMAIN_ADMIN
} document_domain_t;

Philipp Schafft's avatar
Philipp Schafft committed
41 42 43 44 45
typedef enum _protocol_tag {
    ICECAST_PROTOCOL_HTTP = 0,
    ICECAST_PROTOCOL_SHOUTCAST
} protocol_t;

46 47 48 49
typedef enum _reuse_tag {
    /* do not reuse */
    ICECAST_REUSE_CLOSE = 0,
    /* reuse */
50 51 52
    ICECAST_REUSE_KEEPALIVE,
    /* Upgrade to TLS */
    ICECAST_REUSE_UPGRADETLS
53 54
} reuse_t;

55 56 57 58 59 60 61
typedef enum {
    CLIENT_SLURP_ERROR,
    CLIENT_SLURP_NEEDS_MORE_DATA,
    CLIENT_SLURP_BUFFER_TO_SMALL,
    CLIENT_SLURP_SUCCESS
} client_slurp_result_t;

62
struct _client_tag {
63 64 65
    /* mode of operation for this client */
    operation_mode mode;

Michael Smith's avatar
Michael Smith committed
66
    /* the client's connection */
67
    connection_t *con;
68 69 70 71

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

Michael Smith's avatar
Michael Smith committed
72
    /* the client's http headers */
73
    http_parser_t *parser;
Jack Moffitt's avatar
Jack Moffitt committed
74

75 76 77
    /* Transfer Encoding if any */
    httpp_encoding_t *encoding;

Philipp Schafft's avatar
Philipp Schafft committed
78 79 80
    /* protocol client uses */
    protocol_t protocol;

81 82 83 84 85 86 87 88
    /* http request body length
     * -1 for streaming (e.g. chunked), 0 for no body, >0 for NNN bytes
     */
    ssize_t request_body_length;

    /* http request body length read so far */
    size_t request_body_read;

89 90
    /* http response code for this client */
    int respcode;
Jack Moffitt's avatar
Jack Moffitt committed
91

Philipp Schafft's avatar
Philipp Schafft committed
92
    /* admin command if any. ADMIN_COMMAND_ERROR if not an admin command. */
93
    admin_command_id_t admin_command;
Philipp Schafft's avatar
Philipp Schafft committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

    /* 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;
109

110 111 112 113
    /* Handler module and function */
    module_t *handler_module;
    char *handler_function;

114 115
    /* is client getting intro data */
    long intro_offset;
Karl Heyes's avatar
Karl Heyes committed
116

Karl Heyes's avatar
Karl Heyes committed
117 118 119
    /* where in the queue the client is */
    refbuf_t *refbuf;

120
    /* position in first buffer */
121
    unsigned int pos;
122

123
    /* auth used for this client */
124
    auth_t *auth;
125

126 127
    /* Format-handler-specific data for this client */
    void *format_data;
128 129

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

132
    /* write out data associated with client */
133
    int (*write_to_client)(client_t *client);
134

Karl Heyes's avatar
Karl Heyes committed
135
    /* function to check if refbuf needs updating */
136
    int (*check_buffer)(source_t *source, client_t *client);
137
};
Jack Moffitt's avatar
Jack Moffitt committed
138

139
int client_create (client_t **c_ptr, connection_t *con, http_parser_t *parser);
Jack Moffitt's avatar
Jack Moffitt committed
140
void client_destroy(client_t *client);
141
void client_send_error_by_id(client_t *client, icecast_error_id_t id);
142
void client_send_101(client_t *client, reuse_t reuse);
143
void client_send_204(client_t *client);
144
void client_send_426(client_t *client, reuse_t reuse);
145
void client_send_reportxml(client_t *client, reportxml_t *report, document_domain_t domain, const char *xsl, admin_format_t admin_format_hint, int status);
146
admin_format_t client_get_admin_format_by_content_negotiation(client_t *client);
147
int client_send_bytes (client_t *client, const void *buf, unsigned len);
148
int client_read_bytes (client_t *client, void *buf, unsigned len);
Karl Heyes's avatar
Karl Heyes committed
149
void client_set_queue (client_t *client, refbuf_t *refbuf);
150 151
ssize_t client_body_read(client_t *client, void *buf, size_t len);
int client_body_eof(client_t *client);
152 153
client_slurp_result_t client_body_slurp(client_t *client, void *buf, size_t *len);
client_slurp_result_t client_body_skip(client_t *client);
Jack Moffitt's avatar
Jack Moffitt committed
154 155

#endif  /* __CLIENT_H__ */