Skip to content

Commit 624b162

Browse files
committed
Check pt
1 parent 2285387 commit 624b162

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ set(SOURCES
247247
${WEB_SOURCES}
248248
${ROOT_SOURCES}
249249
"${INIH_INCLUDE_DIR}/ini.c"
250+
include/utils/strings.h
250251
)
251252

252253
# Add go2rtc sources if enabled

include/utils/strings.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
#ifndef STRINGS_H
4+
#define STRINGS_H
5+
6+
#include <stdbool.h>
7+
8+
/**
9+
* Check if a string ends with a given suffix
10+
*
11+
* @param str The string to check
12+
* @param suffix The suffix to look for
13+
* @return true if the string ends with the suffix, false otherwise
14+
*/
15+
bool ends_with(const char *str, const char *suffix);
16+
17+
#endif //STRINGS_H

src/utils/strings.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <string.h>
2+
#include <stdbool.h>
3+
4+
5+
bool ends_with(const char *str, const char *suffix) {
6+
if (!str || !suffix)
7+
return false;
8+
9+
size_t str_len = strlen(str);
10+
size_t suffix_len = strlen(suffix);
11+
12+
if (suffix_len > str_len)
13+
return false;
14+
15+
return strcmp(str + str_len - suffix_len, suffix) == 0;
16+
}

src/video/detection_model.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "core/config.h"
1616
#include "core/shutdown_coordinator.h"
1717
#include "utils/memory.h" // For get_total_memory_allocated
18+
#include "utils/strings.h"
1819
#include "video/detection_model.h"
1920
#include "video/sod_detection.h"
2021
#include "video/sod_realnet.h"
@@ -310,9 +311,7 @@ detection_model_t load_detection_model(const char *model_path, float threshold)
310311
}
311312

312313
// Check if this is an API URL (starts with http:// or https://) or the special "api-detection" string
313-
bool is_api_url = (strncmp(model_path, "http://", 7) == 0 ||
314-
strncmp(model_path, "https://", 8) == 0 ||
315-
strcmp(model_path, "api-detection") == 0);
314+
bool is_api_url = ends_with(model_path, "api-detection");
316315

317316
// Only check file existence if it's not an API URL
318317
if (!is_api_url) {

src/video/detection_stream_thread.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "core/logger.h"
1919
#include "core/config.h"
2020
#include "core/shutdown_coordinator.h"
21+
#include "utils/strings.h"
2122
#include "video/detection_stream_thread.h"
2223
#include "video/detection_model.h"
2324
#include "video/sod_integration.h"
@@ -949,9 +950,7 @@ static void *stream_detection_thread_func(void *arg) {
949950
log_info("[Stream %s] Loading detection model: %s", thread->stream_name, thread->model_path);
950951

951952
// Check if this is an API URL or the special "api-detection" string
952-
bool is_api_detection = (strncmp(thread->model_path, "http://", 7) == 0 ||
953-
strncmp(thread->model_path, "https://", 8) == 0 ||
954-
strcmp(thread->model_path, "api-detection") == 0);
953+
bool is_api_detection = ends_with(thread->model_path, "api-detection");
955954

956955
// Only check file existence if it's not an API detection
957956
if (!is_api_detection) {

tests/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ set(DETECTION_SOURCES
5151
${CMAKE_CURRENT_SOURCE_DIR}/../external/inih/ini.c
5252
${CMAKE_CURRENT_SOURCE_DIR}/../external/cjson/cJSON.c
5353
${CMAKE_CURRENT_SOURCE_DIR}/../external/mongoose/mongoose.c
54+
${CMAKE_CURRENT_SOURCE_DIR}/../src/utils/strings.c
5455
)
5556

5657
# Define motion detection sources
@@ -215,6 +216,7 @@ set(STREAM_DETECTION_SOURCES
215216
${CMAKE_CURRENT_SOURCE_DIR}/../src/core/shutdown_coordinator.c
216217
${CMAKE_CURRENT_SOURCE_DIR}/../src/web/logger_websocket.c
217218
${CMAKE_CURRENT_SOURCE_DIR}/../src/utils/memory.c
219+
${CMAKE_CURRENT_SOURCE_DIR}/../src/utils/strings.c
218220
${CMAKE_CURRENT_SOURCE_DIR}/../external/inih/ini.c
219221
${CMAKE_CURRENT_SOURCE_DIR}/../external/cjson/cJSON.c
220222
)

0 commit comments

Comments
 (0)