From bc873e31d023b3e0a652e9e39597b7935b4ddac8 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Tue, 17 Sep 2019 10:21:33 +0300 Subject: [PATCH] refactoring --- src/http/server.c | 36 +++++-------------------------- src/http/uri.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ src/http/uri.h | 31 +++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 31 deletions(-) create mode 100644 src/http/uri.c create mode 100644 src/http/uri.h diff --git a/src/http/server.c b/src/http/server.c index 3c674c0..20c696e 100644 --- a/src/http/server.c +++ b/src/http/server.c @@ -60,6 +60,7 @@ #endif #include "blank.h" +#include "uri.h" #include "base64.h" #include "mime.h" #include "static.h" @@ -67,8 +68,6 @@ #include "data/index_html.h" -static bool _http_get_param_true(struct evkeyvalq *params, const char *key); -static char *_http_get_param_uri(struct evkeyvalq *params, const char *key); static int _http_preprocess_request(struct evhttp_request *request, struct http_server_t *server); static void _http_callback_root(struct evhttp_request *request, void *v_server); @@ -283,31 +282,6 @@ void http_server_loop_break(struct http_server_t *server) { event_base_loopbreak(server->run->base); } - -static bool _http_get_param_true(struct evkeyvalq *params, const char *key) { - const char *value_str; - - if ((value_str = evhttp_find_header(params, key)) != NULL) { - if ( - value_str[0] == '1' - || !evutil_ascii_strcasecmp(value_str, "true") - || !evutil_ascii_strcasecmp(value_str, "yes") - ) { - return true; - } - } - return false; -} - -static char *_http_get_param_uri(struct evkeyvalq *params, const char *key) { - const char *value_str; - - if ((value_str = evhttp_find_header(params, key)) != NULL) { - return evhttp_encode_uri(value_str); - } - return NULL; -} - #define ADD_HEADER(_key, _value) \ assert(!evhttp_add_header(evhttp_request_get_output_headers(request), _key, _value)) @@ -559,10 +533,10 @@ static void _http_callback_stream(struct evhttp_request *request, void *v_server client->need_first_frame = true; evhttp_parse_query(evhttp_request_get_uri(request), ¶ms); - client->key = _http_get_param_uri(¶ms, "key"); - client->extra_headers = _http_get_param_true(¶ms, "extra_headers"); - client->advance_headers = _http_get_param_true(¶ms, "advance_headers"); - client->dual_final_frames = _http_get_param_true(¶ms, "dual_final_frames"); + client->key = uri_get_string(¶ms, "key"); + client->extra_headers = uri_get_true(¶ms, "extra_headers"); + client->advance_headers = uri_get_true(¶ms, "advance_headers"); + client->dual_final_frames = uri_get_true(¶ms, "dual_final_frames"); evhttp_clear_headers(¶ms); uuid_generate(uuid); diff --git a/src/http/uri.c b/src/http/uri.c new file mode 100644 index 0000000..5628eb0 --- /dev/null +++ b/src/http/uri.c @@ -0,0 +1,54 @@ +/***************************************************************************** +# # +# uStreamer - Lightweight and fast MJPG-HTTP streamer. # +# # +# Copyright (C) 2018 Maxim Devaev # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program 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 General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +*****************************************************************************/ + + +#include "uri.h" + +#include + +#include +#include +#include + + +bool uri_get_true(struct evkeyvalq *params, const char *key) { + const char *value_str; + + if ((value_str = evhttp_find_header(params, key)) != NULL) { + if ( + value_str[0] == '1' + || !evutil_ascii_strcasecmp(value_str, "true") + || !evutil_ascii_strcasecmp(value_str, "yes") + ) { + return true; + } + } + return false; +} + +char *uri_get_string(struct evkeyvalq *params, const char *key) { + const char *value_str; + + if ((value_str = evhttp_find_header(params, key)) != NULL) { + return evhttp_encode_uri(value_str); + } + return NULL; +} diff --git a/src/http/uri.h b/src/http/uri.h new file mode 100644 index 0000000..0b44b10 --- /dev/null +++ b/src/http/uri.h @@ -0,0 +1,31 @@ +/***************************************************************************** +# # +# uStreamer - Lightweight and fast MJPG-HTTP streamer. # +# # +# Copyright (C) 2018 Maxim Devaev # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program 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 General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +*****************************************************************************/ + + +#pragma once + +#include + +#include + + +bool uri_get_true(struct evkeyvalq *params, const char *key); +char *uri_get_string(struct evkeyvalq *params, const char *key);