mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-07-17 17:21:55 +00:00
refactoring
This commit is contained in:
@@ -177,14 +177,14 @@ int main(int argc, char *argv[]) {
|
||||
# undef OPT_NUMBER
|
||||
# undef OPT_SET
|
||||
|
||||
if (sink_name == NULL || sink_name[0] == '\0') {
|
||||
if (!us_str_is_ok(sink_name)) {
|
||||
puts("Missing option --sink. See --help for details.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
_output_context_s ctx = {0};
|
||||
|
||||
if (out_path && out_path[0] != '\0') {
|
||||
if (us_str_is_ok(out_path)) {
|
||||
if ((ctx.v_out = (void*)us_output_file_init(out_path, out_json)) == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ int us_capture_open(us_capture_s *cap) {
|
||||
}
|
||||
_LOG_DEBUG("Capture device fd=%d opened", run->fd);
|
||||
|
||||
if (cap->dv_timings && cap->media_path[0] != '\0') {
|
||||
if (cap->dv_timings && us_str_is_ok(cap->media_path)) {
|
||||
if (_capture_open_media_pads(cap) < 0) {
|
||||
goto error_no_device;
|
||||
}
|
||||
@@ -232,7 +232,7 @@ int us_capture_open(us_capture_s *cap) {
|
||||
if (cap->dv_timings && _capture_open_dv_timings(cap, true) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (cap->dv_timings && cap->media_path[0] != '\0') {
|
||||
if (cap->dv_timings && us_str_is_ok(cap->media_path)) {
|
||||
US_ARRAY_ITERATE(run->media_pads, 0, pad, {
|
||||
if (pad->fd >= -1 && _capture_open_media_format(cap, pad) < 0) {
|
||||
goto error;
|
||||
|
||||
@@ -100,7 +100,7 @@ INLINE void us_thread_get_name(char *name) { // Always required for logging
|
||||
|| (defined(__OpenBSD__) && defined(OpenBSD) && OpenBSD >= 201905) \
|
||||
|| defined(__DragonFly__)
|
||||
pthread_get_name_np(pthread_self(), name, US_THREAD_NAME_SIZE); // Also null-terminated
|
||||
if (name[0] != '\0') {
|
||||
if (us_str_is_ok(name)) {
|
||||
retval = 0;
|
||||
}
|
||||
# else
|
||||
|
||||
@@ -92,6 +92,10 @@ INLINE char *us_strdup(const char *str) {
|
||||
return new;
|
||||
}
|
||||
|
||||
INLINE bool us_str_is_ok(const char *str) {
|
||||
return (str != NULL && str[0] != '\0');
|
||||
}
|
||||
|
||||
INLINE const char *us_bool_to_string(bool flag) {
|
||||
return (flag ? "true" : "false");
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ int us_server_listen(us_server_s *server) {
|
||||
us_stream_s *const stream = server->stream;
|
||||
|
||||
{
|
||||
if (server->static_path[0] != '\0') {
|
||||
if (us_str_is_ok(server->static_path)) {
|
||||
_LOG_INFO("Enabling the file server: %s", server->static_path);
|
||||
evhttp_set_gencb(run->http, _http_callback_static, (void*)server);
|
||||
} else {
|
||||
@@ -202,7 +202,7 @@ int us_server_listen(us_server_s *server) {
|
||||
|
||||
evhttp_set_timeout(run->http, server->timeout);
|
||||
|
||||
if (server->user[0] != '\0') {
|
||||
if (us_str_is_ok(server->user)) {
|
||||
char *encoded_token = NULL;
|
||||
|
||||
char *raw_token;
|
||||
@@ -216,7 +216,7 @@ int us_server_listen(us_server_s *server) {
|
||||
_LOG_INFO("Using HTTP basic auth");
|
||||
}
|
||||
|
||||
if (server->unix_path[0] != '\0') {
|
||||
if (us_str_is_ok(server->unix_path)) {
|
||||
_LOG_DEBUG("Binding server to UNIX socket '%s' ...", server->unix_path);
|
||||
if ((run->ext_fd = us_evhttp_bind_unix(
|
||||
run->http,
|
||||
@@ -264,7 +264,7 @@ static int _http_preprocess_request(struct evhttp_request *req, us_server_s *ser
|
||||
|
||||
atomic_store(&server->stream->run->http->last_req_ts, us_get_now_monotonic());
|
||||
|
||||
if (server->allow_origin[0] != '\0') {
|
||||
if (us_str_is_ok(server->allow_origin)) {
|
||||
const char *const cors_headers = us_evhttp_get_header(req, "Access-Control-Request-Headers");
|
||||
const char *const cors_method = us_evhttp_get_header(req, "Access-Control-Request-Method");
|
||||
|
||||
@@ -666,7 +666,7 @@ static void _http_callback_stream_write(struct bufferevent *buf_event, void *v_c
|
||||
if (client->need_initial) {
|
||||
_A_EVBUFFER_ADD_PRINTF(buf, "HTTP/1.0 200 OK" RN);
|
||||
|
||||
if (client->server->allow_origin[0] != '\0') {
|
||||
if (us_str_is_ok(client->server->allow_origin)) {
|
||||
const char *const cors_headers = us_evhttp_get_header(client->req, "Access-Control-Request-Headers");
|
||||
const char *const cors_method = us_evhttp_get_header(client->req, "Access-Control-Request-Method");
|
||||
|
||||
@@ -693,8 +693,8 @@ static void _http_callback_stream_write(struct bufferevent *buf_event, void *v_c
|
||||
"Content-Type: multipart/x-mixed-replace;boundary=" BOUNDARY RN
|
||||
RN
|
||||
"--" BOUNDARY RN,
|
||||
(server->instance_id[0] == '\0' ? "" : "_"),
|
||||
server->instance_id,
|
||||
(us_str_is_ok(server->instance_id) ? "_" : ""),
|
||||
(us_str_is_ok(server->instance_id) ? server->instance_id : ""),
|
||||
(client->key != NULL ? client->key : "0"),
|
||||
client->id);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ char *us_find_static_file_path(const char *root_path, const char *req_path) {
|
||||
char *path = NULL;
|
||||
|
||||
char *const simplified_path = us_simplify_request_path(req_path);
|
||||
if (simplified_path[0] == '\0') {
|
||||
if (!us_str_is_ok(simplified_path)) {
|
||||
US_LOG_VERBOSE("HTTP: Invalid request path %s to static", req_path);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -569,7 +569,7 @@ int us_options_parse(
|
||||
US_LOG_INFO("Starting PiKVM uStreamer %s ...", US_VERSION);
|
||||
|
||||
# define ADD_SINK(x_label, x_prefix) { \
|
||||
if (x_prefix##_name && x_prefix##_name[0] != '\0') { \
|
||||
if (us_str_is_ok(x_prefix##_name)) { \
|
||||
opts->x_prefix = us_memsink_init_opened( \
|
||||
x_label, \
|
||||
x_prefix##_name, \
|
||||
|
||||
Reference in New Issue
Block a user