1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-12-04 14:46:31 -05:00

Feature: Added reference counting to httpp parser object

This commit is contained in:
Philipp Schafft 2018-08-09 09:25:26 +00:00
parent aeddcad5df
commit 03659eb096
2 changed files with 34 additions and 10 deletions

View File

@ -118,19 +118,22 @@ httpp_request_info_t httpp_request_info(httpp_request_type_e req)
http_parser_t *httpp_create_parser(void)
{
return (http_parser_t *)malloc(sizeof(http_parser_t));
}
void httpp_initialize(http_parser_t *parser, http_varlist_t *defaults)
{
http_varlist_t *list;
http_parser_t *parser = calloc(1, sizeof(http_parser_t));
parser->refc = 1;
parser->req_type = httpp_req_none;
parser->uri = NULL;
parser->vars = avl_tree_new(_compare_vars, NULL);
parser->queryvars = avl_tree_new(_compare_vars, NULL);
parser->postvars = avl_tree_new(_compare_vars, NULL);
return parser;
}
void httpp_initialize(http_parser_t *parser, http_varlist_t *defaults)
{
http_varlist_t *list;
/* now insert the default variables */
list = defaults;
while (list != NULL) {
@ -732,7 +735,7 @@ const char *httpp_get_param(http_parser_t *parser, const char *name)
return _httpp_get_param(parser->queryvars, name);
}
void httpp_clear(http_parser_t *parser)
static void httpp_clear(http_parser_t *parser)
{
parser->req_type = httpp_req_none;
if (parser->uri)
@ -744,10 +747,29 @@ void httpp_clear(http_parser_t *parser)
parser->vars = NULL;
}
void httpp_destroy(http_parser_t *parser)
int httpp_addref(http_parser_t *parser)
{
if (!parser)
return -1;
parser->refc++;
return 0;
}
int httpp_release(http_parser_t *parser)
{
if (!parser)
return -1;
parser->refc--;
if (parser->refc)
return 0;
httpp_clear(parser);
free(parser);
return 0;
}
static char *_lowercase(char *str)

View File

@ -82,6 +82,7 @@ typedef struct http_varlist_tag {
} http_varlist_t;
typedef struct http_parser_tag {
size_t refc;
httpp_request_type_e req_type;
char *uri;
avl_tree *vars;
@ -125,8 +126,9 @@ void httpp_set_post_param(http_parser_t *parser, const char *name, const char *v
const char *httpp_get_post_param(http_parser_t *parser, const char *name);
const char *httpp_get_param(http_parser_t *parser, const char *name);
const http_var_t *httpp_get_param_var(http_parser_t *parser, const char *name);
void httpp_destroy(http_parser_t *parser);
void httpp_clear(http_parser_t *parser);
int httpp_addref(http_parser_t *parser);
int httpp_release(http_parser_t *parser);
#define httpp_destroy(x) httpp_release((x))
/* util functions */
httpp_request_type_e httpp_str_to_method(const char * method);