mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-13 02:53:42 +00:00
refactoring
This commit is contained in:
@@ -60,6 +60,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "blank.h"
|
#include "blank.h"
|
||||||
|
#include "uri.h"
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
#include "mime.h"
|
#include "mime.h"
|
||||||
#include "static.h"
|
#include "static.h"
|
||||||
@@ -67,8 +68,6 @@
|
|||||||
#include "data/index_html.h"
|
#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 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);
|
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);
|
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) \
|
#define ADD_HEADER(_key, _value) \
|
||||||
assert(!evhttp_add_header(evhttp_request_get_output_headers(request), _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;
|
client->need_first_frame = true;
|
||||||
|
|
||||||
evhttp_parse_query(evhttp_request_get_uri(request), ¶ms);
|
evhttp_parse_query(evhttp_request_get_uri(request), ¶ms);
|
||||||
client->key = _http_get_param_uri(¶ms, "key");
|
client->key = uri_get_string(¶ms, "key");
|
||||||
client->extra_headers = _http_get_param_true(¶ms, "extra_headers");
|
client->extra_headers = uri_get_true(¶ms, "extra_headers");
|
||||||
client->advance_headers = _http_get_param_true(¶ms, "advance_headers");
|
client->advance_headers = uri_get_true(¶ms, "advance_headers");
|
||||||
client->dual_final_frames = _http_get_param_true(¶ms, "dual_final_frames");
|
client->dual_final_frames = uri_get_true(¶ms, "dual_final_frames");
|
||||||
evhttp_clear_headers(¶ms);
|
evhttp_clear_headers(¶ms);
|
||||||
|
|
||||||
uuid_generate(uuid);
|
uuid_generate(uuid);
|
||||||
|
|||||||
54
src/http/uri.c
Normal file
54
src/http/uri.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
# #
|
||||||
|
# uStreamer - Lightweight and fast MJPG-HTTP streamer. #
|
||||||
|
# #
|
||||||
|
# Copyright (C) 2018 Maxim Devaev <mdevaev@gmail.com> #
|
||||||
|
# #
|
||||||
|
# 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 <https://www.gnu.org/licenses/>. #
|
||||||
|
# #
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#include "uri.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <event2/http.h>
|
||||||
|
#include <event2/util.h>
|
||||||
|
#include <event2/keyvalq_struct.h>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
31
src/http/uri.h
Normal file
31
src/http/uri.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
# #
|
||||||
|
# uStreamer - Lightweight and fast MJPG-HTTP streamer. #
|
||||||
|
# #
|
||||||
|
# Copyright (C) 2018 Maxim Devaev <mdevaev@gmail.com> #
|
||||||
|
# #
|
||||||
|
# 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 <https://www.gnu.org/licenses/>. #
|
||||||
|
# #
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <event2/http.h>
|
||||||
|
|
||||||
|
|
||||||
|
bool uri_get_true(struct evkeyvalq *params, const char *key);
|
||||||
|
char *uri_get_string(struct evkeyvalq *params, const char *key);
|
||||||
Reference in New Issue
Block a user