2001-09-09 22:24:39 -04:00
|
|
|
/* httpp.h
|
|
|
|
**
|
|
|
|
** http parsing library
|
2014-12-05 04:31:08 -05:00
|
|
|
**
|
|
|
|
** Copyright (C) 2014 Michael Smith <msmith@icecast.org>,
|
|
|
|
** Ralph Giles <giles@xiph.org>,
|
|
|
|
** Karl Heyes <karl@xiph.org>,
|
2019-04-28 05:40:47 -04:00
|
|
|
** Copyright (C) 2012-2019 by Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>
|
2014-12-05 04:31:08 -05:00
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**
|
2001-09-09 22:24:39 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __HTTPP_H
|
|
|
|
#define __HTTPP_H
|
|
|
|
|
2003-03-09 17:56:46 -05:00
|
|
|
#include <avl/avl.h>
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
#define HTTPP_VAR_PROTOCOL "__protocol"
|
|
|
|
#define HTTPP_VAR_VERSION "__version"
|
|
|
|
#define HTTPP_VAR_URI "__uri"
|
2005-06-14 22:32:26 -04:00
|
|
|
#define HTTPP_VAR_RAWURI "__rawuri"
|
2018-08-09 07:13:10 -04:00
|
|
|
#define HTTPP_VAR_QUERYARGS "__queryargs"
|
2001-09-09 22:24:39 -04:00
|
|
|
#define HTTPP_VAR_REQ_TYPE "__req_type"
|
2002-08-05 10:48:04 -04:00
|
|
|
#define HTTPP_VAR_ERROR_MESSAGE "__errormessage"
|
2002-08-16 10:22:44 -04:00
|
|
|
#define HTTPP_VAR_ERROR_CODE "__errorcode"
|
2003-03-07 23:57:02 -05:00
|
|
|
#define HTTPP_VAR_ICYPASSWORD "__icy_password"
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2018-08-09 07:17:38 -04:00
|
|
|
typedef enum {
|
|
|
|
HTTPP_NS_VAR,
|
|
|
|
HTTPP_NS_HEADER,
|
|
|
|
HTTPP_NS_QUERY_STRING,
|
|
|
|
HTTPP_NS_POST_BODY
|
|
|
|
} httpp_ns_t;
|
|
|
|
|
2001-09-09 22:24:39 -04:00
|
|
|
typedef enum httpp_request_type_tag {
|
2014-11-21 23:06:26 -05:00
|
|
|
/* 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,
|
2015-02-10 03:33:30 -05:00
|
|
|
httpp_req_options,
|
|
|
|
httpp_req_delete,
|
|
|
|
httpp_req_trace,
|
|
|
|
httpp_req_connect,
|
2014-11-21 23:06:26 -05:00
|
|
|
/* 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
|
2001-09-09 22:24:39 -04:00
|
|
|
} httpp_request_type_e;
|
|
|
|
|
2018-08-02 05:00:32 -04:00
|
|
|
typedef unsigned int httpp_request_info_t;
|
|
|
|
#define HTTPP_REQUEST_IS_SAFE ((httpp_request_info_t)0x0001U)
|
|
|
|
#define HTTPP_REQUEST_IS_IDEMPOTENT ((httpp_request_info_t)0x0002U)
|
|
|
|
#define HTTPP_REQUEST_IS_CACHEABLE ((httpp_request_info_t)0x0004U)
|
|
|
|
#define HTTPP_REQUEST_HAS_RESPONSE_BODY ((httpp_request_info_t)0x0010U)
|
|
|
|
#define HTTPP_REQUEST_HAS_REQUEST_BODY ((httpp_request_info_t)0x0100U)
|
|
|
|
#define HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY ((httpp_request_info_t)0x0200U)
|
|
|
|
|
2018-07-26 07:57:44 -04:00
|
|
|
typedef struct http_var_tag http_var_t;
|
|
|
|
struct http_var_tag {
|
2003-03-14 21:10:19 -05:00
|
|
|
char *name;
|
2018-07-26 08:55:10 -04:00
|
|
|
size_t values;
|
|
|
|
char **value;
|
2018-07-26 07:57:44 -04:00
|
|
|
};
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
typedef struct http_varlist_tag {
|
2003-03-14 21:10:19 -05:00
|
|
|
http_var_t var;
|
|
|
|
struct http_varlist_tag *next;
|
2001-09-09 22:24:39 -04:00
|
|
|
} http_varlist_t;
|
|
|
|
|
|
|
|
typedef struct http_parser_tag {
|
2018-08-09 05:25:26 -04:00
|
|
|
size_t refc;
|
2003-03-14 21:10:19 -05:00
|
|
|
httpp_request_type_e req_type;
|
|
|
|
char *uri;
|
|
|
|
avl_tree *vars;
|
|
|
|
avl_tree *queryvars;
|
2018-06-18 10:39:03 -04:00
|
|
|
avl_tree *postvars;
|
2001-09-09 22:24:39 -04:00
|
|
|
} http_parser_t;
|
|
|
|
|
2003-07-06 21:49:27 -04:00
|
|
|
#ifdef _mangle
|
2018-08-02 05:00:32 -04:00
|
|
|
# define httpp_request_info _mangle(httpp_request_info)
|
2003-07-06 21:49:27 -04:00
|
|
|
# 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)
|
2018-06-18 17:39:13 -04:00
|
|
|
# define httpp_parse_postdata _mangle(httpp_parse_postdata)
|
2003-07-06 21:49:27 -04:00
|
|
|
# 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)
|
2018-06-18 17:39:13 -04:00
|
|
|
# define httpp_set_post_param _mangle(httpp_set_post_param)
|
|
|
|
# define httpp_get_post_param _mangle(httpp_get_post_param)
|
|
|
|
# define httpp_get_param _mangle(httpp_get_param)
|
2003-07-06 21:49:27 -04:00
|
|
|
# define httpp_destroy _mangle(httpp_destroy)
|
|
|
|
# define httpp_clear _mangle(httpp_clear)
|
|
|
|
#endif
|
|
|
|
|
2018-08-02 05:00:32 -04:00
|
|
|
httpp_request_info_t httpp_request_info(httpp_request_type_e req);
|
|
|
|
|
2001-09-09 22:24:39 -04:00
|
|
|
http_parser_t *httpp_create_parser(void);
|
|
|
|
void httpp_initialize(http_parser_t *parser, http_varlist_t *defaults);
|
2007-08-16 18:52:24 -04:00
|
|
|
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);
|
2018-06-18 10:39:03 -04:00
|
|
|
int httpp_parse_postdata(http_parser_t *parser, const char *body_data, size_t len);
|
2005-06-14 22:32:26 -04:00
|
|
|
void httpp_setvar(http_parser_t *parser, const char *name, const char *value);
|
2009-07-07 12:37:31 -04:00
|
|
|
void httpp_deletevar(http_parser_t *parser, const char *name);
|
2007-08-16 18:52:24 -04:00
|
|
|
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);
|
2018-06-18 10:39:03 -04:00
|
|
|
void httpp_set_post_param(http_parser_t *parser, const char *name, const char *value);
|
|
|
|
const char *httpp_get_post_param(http_parser_t *parser, const char *name);
|
2018-06-18 17:36:19 -04:00
|
|
|
const char *httpp_get_param(http_parser_t *parser, const char *name);
|
2018-07-26 08:59:23 -04:00
|
|
|
const http_var_t *httpp_get_param_var(http_parser_t *parser, const char *name);
|
2018-08-09 07:17:38 -04:00
|
|
|
const http_var_t *httpp_get_any_var(http_parser_t *parser, httpp_ns_t ns, const char *name);
|
|
|
|
char ** httpp_get_any_key(http_parser_t *parser, httpp_ns_t ns);
|
|
|
|
void httpp_free_any_key(char **keys);
|
2018-08-09 05:25:26 -04:00
|
|
|
int httpp_addref(http_parser_t *parser);
|
|
|
|
int httpp_release(http_parser_t *parser);
|
|
|
|
#define httpp_destroy(x) httpp_release((x))
|
2014-11-21 23:44:47 -05:00
|
|
|
|
|
|
|
/* util functions */
|
|
|
|
httpp_request_type_e httpp_str_to_method(const char * method);
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
#endif
|