httpp.h 3.81 KB
Newer Older
Jack Moffitt's avatar
Jack Moffitt committed
1 2 3
/* httpp.h
**
** http parsing library
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
**
** Copyright (C) 2014 Michael Smith <msmith@icecast.org>,
**                    Ralph Giles <giles@xiph.org>,
**                    Karl Heyes <karl@xiph.org>,
**                    Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Library General Public
** License as published by the Free Software Foundation; either
** version 2 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
** Library General Public License for more details.
**
** You should have received a copy of the GNU Library General Public
** License along with this library; if not, write to the
** Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
** Boston, MA  02110-1301, USA.
**
Jack Moffitt's avatar
Jack Moffitt committed
25 26 27 28 29
*/

#ifndef __HTTPP_H
#define __HTTPP_H

30
#include <avl/avl.h>
Jack Moffitt's avatar
Jack Moffitt committed
31 32 33 34

#define HTTPP_VAR_PROTOCOL "__protocol"
#define HTTPP_VAR_VERSION "__version"
#define HTTPP_VAR_URI "__uri"
35
#define HTTPP_VAR_RAWURI "__rawuri"
Karl Heyes's avatar
Karl Heyes committed
36
#define HTTPP_VAR_QUERYARGS " __queryargs"
Jack Moffitt's avatar
Jack Moffitt committed
37
#define HTTPP_VAR_REQ_TYPE "__req_type"
38
#define HTTPP_VAR_ERROR_MESSAGE "__errormessage"
39
#define HTTPP_VAR_ERROR_CODE "__errorcode"
40
#define HTTPP_VAR_ICYPASSWORD "__icy_password"
Jack Moffitt's avatar
Jack Moffitt committed
41 42

typedef enum httpp_request_type_tag {
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    /* Initial and internally used state of the engine */
    httpp_req_none = 0,
    /* Part of HTTP standard: GET, POST, PUT and HEAD */
    httpp_req_get,
    httpp_req_post,
    httpp_req_put,
    httpp_req_head,
    /* Icecast SOURCE, to be replaced with PUT some day */
    httpp_req_source,
    /* XXX: ??? */
    httpp_req_play,
    /* Icecast 2.x STATS, to request a live stream of stats events */
    httpp_req_stats,
    /* Used if request method is unknown. MUST BE LAST ONE IN LIST. */
    httpp_req_unknown
Jack Moffitt's avatar
Jack Moffitt committed
58 59 60
} httpp_request_type_e;

typedef struct http_var_tag {
61 62
    char *name;
    char *value;
Jack Moffitt's avatar
Jack Moffitt committed
63 64 65
} http_var_t;

typedef struct http_varlist_tag {
66 67
    http_var_t var;
    struct http_varlist_tag *next;
Jack Moffitt's avatar
Jack Moffitt committed
68 69 70
} http_varlist_t;

typedef struct http_parser_tag {
71 72 73 74
    httpp_request_type_e req_type;
    char *uri;
    avl_tree *vars;
    avl_tree *queryvars;
Jack Moffitt's avatar
Jack Moffitt committed
75 76
} http_parser_t;

brendan's avatar
brendan committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90
#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
91 92
http_parser_t *httpp_create_parser(void);
void httpp_initialize(http_parser_t *parser, http_varlist_t *defaults);
93 94 95
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);
96
void httpp_setvar(http_parser_t *parser, const char *name, const char *value);
Karl Heyes's avatar
Karl Heyes committed
97
void httpp_deletevar(http_parser_t *parser, const char *name);
98 99 100
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
101
void httpp_destroy(http_parser_t *parser);
102
void httpp_clear(http_parser_t *parser);
103 104 105

/* util functions */
httpp_request_type_e httpp_str_to_method(const char * method);
Jack Moffitt's avatar
Jack Moffitt committed
106 107
 
#endif