2001-09-09 22:24:39 -04:00
|
|
|
/* httpp.h
|
|
|
|
**
|
|
|
|
** http parsing library
|
2014-12-05 04:31:08 -05:00
|
|
|
**
|
2018-10-12 06:28:09 -04:00
|
|
|
** Copyright (C) 2014 Michael Smith <msmith@icecast.org>,
|
|
|
|
** Ralph Giles <giles@xiph.org>,
|
|
|
|
** Karl Heyes <karl@xiph.org>,
|
|
|
|
** Copyright (C) 2012-2018 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
|
|
|
*/
|
|
|
|
|
2018-10-12 06:16:06 -04:00
|
|
|
#ifndef _LIBIGLOO__HTTPP_H_
|
|
|
|
#define _LIBIGLOO__HTTPP_H_
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2018-10-26 10:20:20 -04:00
|
|
|
#include "avl.h"
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2018-10-12 07:27:17 -04:00
|
|
|
#define igloo_HTTPP_VAR_PROTOCOL "__protocol"
|
|
|
|
#define igloo_HTTPP_VAR_VERSION "__version"
|
|
|
|
#define igloo_HTTPP_VAR_URI "__uri"
|
|
|
|
#define igloo_HTTPP_VAR_RAWURI "__rawuri"
|
|
|
|
#define igloo_HTTPP_VAR_QUERYARGS "__queryargs"
|
|
|
|
#define igloo_HTTPP_VAR_REQ_TYPE "__req_type"
|
|
|
|
#define igloo_HTTPP_VAR_ERROR_MESSAGE "__errormessage"
|
|
|
|
#define igloo_HTTPP_VAR_ERROR_CODE "__errorcode"
|
|
|
|
#define igloo_HTTPP_VAR_ICYPASSWORD "__icy_password"
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2018-08-09 07:17:38 -04:00
|
|
|
typedef enum {
|
2018-10-31 07:29:07 -04:00
|
|
|
igloo_HTTPP_NS_VAR,
|
|
|
|
igloo_HTTPP_NS_HEADER,
|
|
|
|
igloo_HTTPP_NS_QUERY_STRING,
|
|
|
|
igloo_HTTPP_NS_POST_BODY
|
2018-10-12 07:27:17 -04:00
|
|
|
} igloo_httpp_ns_t;
|
2018-08-09 07:17:38 -04:00
|
|
|
|
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 */
|
2018-10-31 07:29:07 -04:00
|
|
|
igloo_httpp_req_none = 0,
|
2014-11-21 23:06:26 -05:00
|
|
|
/* Part of HTTP standard: GET, POST, PUT and HEAD */
|
2018-10-31 07:29:07 -04:00
|
|
|
igloo_httpp_req_get,
|
|
|
|
igloo_httpp_req_post,
|
|
|
|
igloo_httpp_req_put,
|
|
|
|
igloo_httpp_req_head,
|
|
|
|
igloo_httpp_req_options,
|
|
|
|
igloo_httpp_req_delete,
|
|
|
|
igloo_httpp_req_trace,
|
|
|
|
igloo_httpp_req_connect,
|
2014-11-21 23:06:26 -05:00
|
|
|
/* Icecast SOURCE, to be replaced with PUT some day */
|
2018-10-31 07:29:07 -04:00
|
|
|
igloo_httpp_req_source,
|
2014-11-21 23:06:26 -05:00
|
|
|
/* XXX: ??? */
|
2018-10-31 07:29:07 -04:00
|
|
|
igloo_httpp_req_play,
|
2014-11-21 23:06:26 -05:00
|
|
|
/* Icecast 2.x STATS, to request a live stream of stats events */
|
2018-10-31 07:29:07 -04:00
|
|
|
igloo_httpp_req_stats,
|
2014-11-21 23:06:26 -05:00
|
|
|
/* Used if request method is unknown. MUST BE LAST ONE IN LIST. */
|
2018-10-31 07:29:07 -04:00
|
|
|
igloo_httpp_req_unknown
|
2018-10-12 07:27:17 -04:00
|
|
|
} igloo_httpp_request_type_e;
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2018-10-12 07:27:17 -04:00
|
|
|
typedef unsigned int igloo_httpp_request_info_t;
|
|
|
|
#define igloo_HTTPP_REQUEST_IS_SAFE ((igloo_httpp_request_info_t)0x0001U)
|
|
|
|
#define igloo_HTTPP_REQUEST_IS_IDEMPOTENT ((igloo_httpp_request_info_t)0x0002U)
|
|
|
|
#define igloo_HTTPP_REQUEST_IS_CACHEABLE ((igloo_httpp_request_info_t)0x0004U)
|
|
|
|
#define igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY ((igloo_httpp_request_info_t)0x0010U)
|
|
|
|
#define igloo_HTTPP_REQUEST_HAS_REQUEST_BODY ((igloo_httpp_request_info_t)0x0100U)
|
|
|
|
#define igloo_HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY ((igloo_httpp_request_info_t)0x0200U)
|
2018-08-02 05:00:32 -04:00
|
|
|
|
2018-10-12 07:27:17 -04:00
|
|
|
typedef struct igloo_http_var_tag igloo_http_var_t;
|
|
|
|
struct igloo_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
|
|
|
|
2018-10-12 07:27:17 -04:00
|
|
|
typedef struct igloo_http_varlist_tag {
|
|
|
|
igloo_http_var_t var;
|
|
|
|
struct igloo_http_varlist_tag *next;
|
|
|
|
} igloo_http_varlist_t;
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2018-10-12 07:27:17 -04:00
|
|
|
typedef struct igloo_http_parser_tag {
|
2018-08-09 05:25:26 -04:00
|
|
|
size_t refc;
|
2018-10-12 07:27:17 -04:00
|
|
|
igloo_httpp_request_type_e req_type;
|
2003-03-14 21:10:19 -05:00
|
|
|
char *uri;
|
2018-10-12 07:27:17 -04:00
|
|
|
igloo_avl_tree *vars;
|
|
|
|
igloo_avl_tree *queryvars;
|
|
|
|
igloo_avl_tree *postvars;
|
|
|
|
} igloo_http_parser_t;
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2018-10-12 07:27:17 -04:00
|
|
|
igloo_httpp_request_info_t igloo_httpp_request_info(igloo_httpp_request_type_e req);
|
2018-08-02 05:00:32 -04:00
|
|
|
|
2018-10-12 07:27:17 -04:00
|
|
|
igloo_http_parser_t *igloo_httpp_create_parser(void);
|
|
|
|
void igloo_httpp_initialize(igloo_http_parser_t *parser, igloo_http_varlist_t *defaults);
|
|
|
|
int igloo_httpp_parse(igloo_http_parser_t *parser, const char *http_data, unsigned long len);
|
|
|
|
int httpp_parse_icy(igloo_http_parser_t *parser, const char *http_data, unsigned long len);
|
|
|
|
int igloo_httpp_parse_response(igloo_http_parser_t *parser, const char *http_data, unsigned long len, const char *uri);
|
|
|
|
int igloo_httpp_parse_postdata(igloo_http_parser_t *parser, const char *body_data, size_t len);
|
|
|
|
void igloo_httpp_setvar(igloo_http_parser_t *parser, const char *name, const char *value);
|
|
|
|
void igloo_httpp_deletevar(igloo_http_parser_t *parser, const char *name);
|
|
|
|
const char *igloo_httpp_getvar(igloo_http_parser_t *parser, const char *name);
|
|
|
|
void igloo_httpp_set_query_param(igloo_http_parser_t *parser, const char *name, const char *value);
|
|
|
|
const char *igloo_httpp_get_query_param(igloo_http_parser_t *parser, const char *name);
|
|
|
|
void igloo_httpp_set_post_param(igloo_http_parser_t *parser, const char *name, const char *value);
|
|
|
|
const char *igloo_httpp_get_post_param(igloo_http_parser_t *parser, const char *name);
|
|
|
|
const char *igloo_httpp_get_param(igloo_http_parser_t *parser, const char *name);
|
|
|
|
const igloo_http_var_t *igloo_httpp_get_param_var(igloo_http_parser_t *parser, const char *name);
|
|
|
|
const igloo_http_var_t *igloo_httpp_get_any_var(igloo_http_parser_t *parser, igloo_httpp_ns_t ns, const char *name);
|
|
|
|
char ** igloo_httpp_get_any_key(igloo_http_parser_t *parser, igloo_httpp_ns_t ns);
|
2018-10-12 06:55:24 -04:00
|
|
|
void igloo_httpp_free_any_key(char **keys);
|
2018-10-12 07:27:17 -04:00
|
|
|
int igloo_httpp_addref(igloo_http_parser_t *parser);
|
|
|
|
int igloo_httpp_release(igloo_http_parser_t *parser);
|
2018-10-12 06:55:24 -04:00
|
|
|
#define httpp_destroy(x) igloo_httpp_release((x))
|
2014-11-21 23:44:47 -05:00
|
|
|
|
|
|
|
/* util functions */
|
2018-10-12 07:27:17 -04:00
|
|
|
igloo_httpp_request_type_e igloo_httpp_str_to_method(const char * method);
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
#endif
|