From 7572febbd8dbb94ad9841a029ff62877c47853ce Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sat, 22 Nov 2014 04:44:47 +0000 Subject: [PATCH] expose converting of method names to enum values as httpp_str_to_method() svn path=/icecast/trunk/httpp/; revision=19348 --- httpp/httpp.c | 38 +++++++++++++++++++++----------------- httpp/httpp.h | 3 +++ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/httpp/httpp.c b/httpp/httpp.c index 10612bc..d65c00a 100644 --- a/httpp/httpp.c +++ b/httpp/httpp.c @@ -337,23 +337,7 @@ int httpp_parse(http_parser_t *parser, const char *http_data, unsigned long len) } } - if (strcasecmp("GET", req_type) == 0) { - parser->req_type = httpp_req_get; - } else if (strcasecmp("POST", req_type) == 0) { - parser->req_type = httpp_req_post; - } else if (strcasecmp("PUT", req_type) == 0) { - parser->req_type = httpp_req_put; - } else if (strcasecmp("HEAD", req_type) == 0) { - parser->req_type = httpp_req_head; - } else if (strcasecmp("SOURCE", req_type) == 0) { - parser->req_type = httpp_req_source; - } else if (strcasecmp("PLAY", req_type) == 0) { - parser->req_type = httpp_req_play; - } else if (strcasecmp("STATS", req_type) == 0) { - parser->req_type = httpp_req_stats; - } else { - parser->req_type = httpp_req_unknown; - } + parser->req_type = httpp_str_to_method(req_type); if (uri != NULL && strlen(uri) > 0) { char *query; @@ -569,3 +553,23 @@ static int _free_vars(void *key) return 1; } +httpp_request_type_e httpp_str_to_method(const char * method) { + if (strcasecmp("GET", method) == 0) { + return httpp_req_get; + } else if (strcasecmp("POST", method) == 0) { + return httpp_req_post; + } else if (strcasecmp("PUT", method) == 0) { + return httpp_req_put; + } else if (strcasecmp("HEAD", method) == 0) { + return httpp_req_head; + } else if (strcasecmp("SOURCE", method) == 0) { + return httpp_req_source; + } else if (strcasecmp("PLAY", method) == 0) { + return httpp_req_play; + } else if (strcasecmp("STATS", method) == 0) { + return httpp_req_stats; + } else { + return httpp_req_unknown; + } +} + diff --git a/httpp/httpp.h b/httpp/httpp.h index 05ed182..10abbd8 100644 --- a/httpp/httpp.h +++ b/httpp/httpp.h @@ -82,5 +82,8 @@ void httpp_set_query_param(http_parser_t *parser, const char *name, const char * const char *httpp_get_query_param(http_parser_t *parser, const char *name); void httpp_destroy(http_parser_t *parser); void httpp_clear(http_parser_t *parser); + +/* util functions */ +httpp_request_type_e httpp_str_to_method(const char * method); #endif