client.h 3.13 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 2011-2014, 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__

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

Philipp Schafft's avatar
Philipp Schafft committed
29 30 31 32 33
typedef enum _protocol_tag {
    ICECAST_PROTOCOL_HTTP = 0,
    ICECAST_PROTOCOL_SHOUTCAST
} protocol_t;

34 35 36 37
typedef enum _reuse_tag {
    /* do not reuse */
    ICECAST_REUSE_CLOSE = 0,
    /* reuse */
38 39 40
    ICECAST_REUSE_KEEPALIVE,
    /* Upgrade to TLS */
    ICECAST_REUSE_UPGRADETLS
41 42
} reuse_t;

Jack Moffitt's avatar
Jack Moffitt committed
43 44
typedef struct _client_tag
{
45 46 47
    /* mode of operation for this client */
    operation_mode mode;

Michael Smith's avatar
Michael Smith committed
48
    /* the client's connection */
49
    connection_t *con;
50 51 52 53

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

Michael Smith's avatar
Michael Smith committed
54
    /* the client's http headers */
55
    http_parser_t *parser;
Jack Moffitt's avatar
Jack Moffitt committed
56

57 58 59
    /* Transfer Encoding if any */
    httpp_encoding_t *encoding;

Philipp Schafft's avatar
Philipp Schafft committed
60 61 62
    /* protocol client uses */
    protocol_t protocol;

63 64
    /* http response code for this client */
    int respcode;
Jack Moffitt's avatar
Jack Moffitt committed
65

Philipp Schafft's avatar
Philipp Schafft committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    /* admin command if any. ADMIN_COMMAND_ERROR if not an admin command. */
    int admin_command;

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

84 85
    /* is client getting intro data */
    long intro_offset;
Karl Heyes's avatar
Karl Heyes committed
86

Karl Heyes's avatar
Karl Heyes committed
87 88 89
    /* where in the queue the client is */
    refbuf_t *refbuf;

90
    /* position in first buffer */
91
    unsigned int pos;
92

93 94 95
    /* auth used for this client */
    struct auth_tag *auth;

96 97
    /* Format-handler-specific data for this client */
    void *format_data;
98 99 100

    /* function to call to release format specific resources */
    void (*free_client_data)(struct _client_tag *client);
Karl Heyes's avatar
Karl Heyes committed
101

102 103 104
    /* write out data associated with client */
    int (*write_to_client)(struct _client_tag *client);

Karl Heyes's avatar
Karl Heyes committed
105 106 107
    /* function to check if refbuf needs updating */
    int (*check_buffer)(struct source_tag *source, struct _client_tag *client);

Jack Moffitt's avatar
Jack Moffitt committed
108 109
} client_t;

110
int client_create (client_t **c_ptr, connection_t *con, http_parser_t *parser);
Jack Moffitt's avatar
Jack Moffitt committed
111
void client_destroy(client_t *client);
112
void client_send_error(client_t *client, int status, int plain, const char *message);
113 114
void client_send_101(client_t *client, reuse_t reuse);
void client_send_426(client_t *client, reuse_t reuse);
115
int client_send_bytes (client_t *client, const void *buf, unsigned len);
116
int client_read_bytes (client_t *client, void *buf, unsigned len);
Karl Heyes's avatar
Karl Heyes committed
117
void client_set_queue (client_t *client, refbuf_t *refbuf);
Jack Moffitt's avatar
Jack Moffitt committed
118 119

#endif  /* __CLIENT_H__ */