httpp.h 2.54 KB
Newer Older
Jack Moffitt's avatar
Jack Moffitt committed
1 2 3
/* httpp.h
**
** http parsing library
4 5 6
** 
** This program is distributed under the GNU General Public License, version 2.
** A copy of this license is included with this source.
Jack Moffitt's avatar
Jack Moffitt committed
7 8 9 10 11
*/

#ifndef __HTTPP_H
#define __HTTPP_H

12
#include <avl/avl.h>
Jack Moffitt's avatar
Jack Moffitt committed
13 14 15 16

#define HTTPP_VAR_PROTOCOL "__protocol"
#define HTTPP_VAR_VERSION "__version"
#define HTTPP_VAR_URI "__uri"
17
#define HTTPP_VAR_RAWURI "__rawuri"
Karl Heyes's avatar
Karl Heyes committed
18
#define HTTPP_VAR_QUERYARGS " __queryargs"
Jack Moffitt's avatar
Jack Moffitt committed
19
#define HTTPP_VAR_REQ_TYPE "__req_type"
20
#define HTTPP_VAR_ERROR_MESSAGE "__errormessage"
21
#define HTTPP_VAR_ERROR_CODE "__errorcode"
22
#define HTTPP_VAR_ICYPASSWORD "__icy_password"
Jack Moffitt's avatar
Jack Moffitt committed
23 24

typedef enum httpp_request_type_tag {
25
    httpp_req_none, httpp_req_get, httpp_req_post, httpp_req_put, httpp_req_head,
26
    httpp_req_source, httpp_req_play, httpp_req_stats, httpp_req_unknown
Jack Moffitt's avatar
Jack Moffitt committed
27 28 29
} httpp_request_type_e;

typedef struct http_var_tag {
30 31
    char *name;
    char *value;
Jack Moffitt's avatar
Jack Moffitt committed
32 33 34
} http_var_t;

typedef struct http_varlist_tag {
35 36
    http_var_t var;
    struct http_varlist_tag *next;
Jack Moffitt's avatar
Jack Moffitt committed
37 38 39
} http_varlist_t;

typedef struct http_parser_tag {
40 41 42 43
    httpp_request_type_e req_type;
    char *uri;
    avl_tree *vars;
    avl_tree *queryvars;
Jack Moffitt's avatar
Jack Moffitt committed
44 45
} http_parser_t;

brendan's avatar
brendan committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59
#ifdef _mangle
# define httpp_create_parser _mangle(httpp_create_parser)
# define httpp_initialize _mangle(httpp_initialize)
# define httpp_parse _mangle(httpp_parse)
# define httpp_parse_icy _mangle(httpp_parse_icy)
# define httpp_parse_response _mangle(httpp_parse_response)
# define httpp_setvar _mangle(httpp_setvar)
# define httpp_getvar _mangle(httpp_getvar)
# define httpp_set_query_param _mangle(httpp_set_query_param)
# define httpp_get_query_param _mangle(httpp_get_query_param)
# define httpp_destroy _mangle(httpp_destroy)
# define httpp_clear _mangle(httpp_clear)
#endif

Jack Moffitt's avatar
Jack Moffitt committed
60 61
http_parser_t *httpp_create_parser(void);
void httpp_initialize(http_parser_t *parser, http_varlist_t *defaults);
62 63 64
int httpp_parse(http_parser_t *parser, const char *http_data, unsigned long len);
int httpp_parse_icy(http_parser_t *parser, const char *http_data, unsigned long len);
int httpp_parse_response(http_parser_t *parser, const char *http_data, unsigned long len, const char *uri);
65
void httpp_setvar(http_parser_t *parser, const char *name, const char *value);
Karl Heyes's avatar
Karl Heyes committed
66
void httpp_deletevar(http_parser_t *parser, const char *name);
67 68 69
const char *httpp_getvar(http_parser_t *parser, const char *name);
void httpp_set_query_param(http_parser_t *parser, const char *name, const char *value);
const char *httpp_get_query_param(http_parser_t *parser, const char *name);
Jack Moffitt's avatar
Jack Moffitt committed
70
void httpp_destroy(http_parser_t *parser);
71
void httpp_clear(http_parser_t *parser);
Jack Moffitt's avatar
Jack Moffitt committed
72 73
 
#endif