diff --git a/config.h b/config.h index 7b9ce3b4b..bd7433023 100644 --- a/config.h +++ b/config.h @@ -99,4 +99,6 @@ typedef SSIZE_T ssize_t; # define BROKER_EXPORT #endif +#define TOPIC_HIERARCHY_LIMIT 200 + #endif diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index ad099c3ad..f116428fd 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -48,7 +48,7 @@ set(C_SRC srv_mosq.c thread_mosq.c tls_mosq.c - util_mosq.c util_topic.c util_mosq.h + util_mosq.c util_mosq.h will_mosq.c will_mosq.h) if (WITH_THREADING AND WIN32) diff --git a/lib/Makefile b/lib/Makefile index 5559b9962..66c05ca26 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -81,7 +81,6 @@ OBJS= \ thread_mosq.o \ tls_mosq.o \ util_mosq.o \ - util_topic.o \ will_mosq.o OBJS_EXTERNAL= \ diff --git a/libcommon/CMakeLists.txt b/libcommon/CMakeLists.txt index 4c0ec2dac..75a9c49d6 100644 --- a/libcommon/CMakeLists.txt +++ b/libcommon/CMakeLists.txt @@ -1,6 +1,7 @@ set(C_SRC strings_common.c time_common.c + topic_common.c utf8_common.c ) diff --git a/libcommon/Makefile b/libcommon/Makefile index 3c6ca1553..d164b973a 100644 --- a/libcommon/Makefile +++ b/libcommon/Makefile @@ -14,6 +14,7 @@ LOCAL_LIBADD+= OBJS= \ strings_common.o \ time_common.o \ + topic_common.o \ utf8_common.o all : libmosquitto_common.a diff --git a/lib/util_topic.c b/libcommon/topic_common.c similarity index 96% rename from lib/util_topic.c rename to libcommon/topic_common.c index 2e20779d9..3fda91825 100644 --- a/lib/util_topic.c +++ b/libcommon/topic_common.c @@ -29,17 +29,7 @@ Contributors: # include #endif - -#ifdef WITH_BROKER -#include "mosquitto_broker_internal.h" -#endif - #include "mosquitto.h" -#include "memory_mosq.h" -#include "net_mosq.h" -#include "send_mosq.h" -#include "tls_mosq.h" -#include "util_mosq.h" /* Check that a topic used for publishing is valid. * Search for + or # in a topic. Return MOSQ_ERR_INVAL if found. @@ -49,9 +39,7 @@ Contributors: BROKER_EXPORT int mosquitto_pub_topic_check(const char *str) { int len = 0; -#ifdef WITH_BROKER int hier_count = 0; -#endif if(str == NULL){ return MOSQ_ERR_INVAL; @@ -60,19 +48,14 @@ BROKER_EXPORT int mosquitto_pub_topic_check(const char *str) while(str && str[0]){ if(str[0] == '+' || str[0] == '#'){ return MOSQ_ERR_INVAL; - } -#ifdef WITH_BROKER - else if(str[0] == '/'){ + }else if(str[0] == '/'){ hier_count++; } -#endif len++; str = &str[1]; } if(len > 65535) return MOSQ_ERR_INVAL; -#ifdef WITH_BROKER if(hier_count > TOPIC_HIERARCHY_LIMIT) return MOSQ_ERR_INVAL; -#endif return MOSQ_ERR_SUCCESS; } @@ -80,9 +63,7 @@ BROKER_EXPORT int mosquitto_pub_topic_check(const char *str) BROKER_EXPORT int mosquitto_pub_topic_check2(const char *str, size_t len) { size_t i; -#ifdef WITH_BROKER int hier_count = 0; -#endif if(str == NULL || len > 65535){ return MOSQ_ERR_INVAL; @@ -91,16 +72,11 @@ BROKER_EXPORT int mosquitto_pub_topic_check2(const char *str, size_t len) for(i=0; i TOPIC_HIERARCHY_LIMIT) return MOSQ_ERR_INVAL; -#endif return MOSQ_ERR_SUCCESS; } @@ -116,9 +92,7 @@ BROKER_EXPORT int mosquitto_sub_topic_check(const char *str) { char c = '\0'; int len = 0; -#ifdef WITH_BROKER int hier_count = 0; -#endif if(str == NULL){ return MOSQ_ERR_INVAL; @@ -133,20 +107,15 @@ BROKER_EXPORT int mosquitto_sub_topic_check(const char *str) if((c != '\0' && c != '/') || str[1] != '\0'){ return MOSQ_ERR_INVAL; } - } -#ifdef WITH_BROKER - else if(str[0] == '/'){ + }else if(str[0] == '/'){ hier_count++; } -#endif len++; c = str[0]; str = &str[1]; } if(len > 65535) return MOSQ_ERR_INVAL; -#ifdef WITH_BROKER if(hier_count > TOPIC_HIERARCHY_LIMIT) return MOSQ_ERR_INVAL; -#endif return MOSQ_ERR_SUCCESS; } @@ -155,9 +124,7 @@ BROKER_EXPORT int mosquitto_sub_topic_check2(const char *str, size_t len) { char c = '\0'; size_t i; -#ifdef WITH_BROKER int hier_count = 0; -#endif if(str == NULL || len > 65535){ return MOSQ_ERR_INVAL; @@ -172,17 +139,12 @@ BROKER_EXPORT int mosquitto_sub_topic_check2(const char *str, size_t len) if((c != '\0' && c != '/') || i TOPIC_HIERARCHY_LIMIT) return MOSQ_ERR_INVAL; -#endif return MOSQ_ERR_SUCCESS; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1e1bb01ca..56eca3889 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -74,7 +74,7 @@ set (MOSQ_SRCS sys_tree.c sys_tree.h ../lib/tls_mosq.c topic_tok.c - ../lib/util_mosq.c ../lib/util_topic.c ../lib/util_mosq.h + ../lib/util_mosq.c ../lib/util_mosq.h websockets.c will_delay.c ../lib/will_mosq.c ../lib/will_mosq.h diff --git a/src/Makefile b/src/Makefile index c98ac4a31..da726c493 100644 --- a/src/Makefile +++ b/src/Makefile @@ -138,7 +138,6 @@ OBJS_EXTERNAL= \ send_unsubscribe.o \ tls_mosq.o \ util_mosq.o \ - util_topic.o \ will_mosq.o ifeq ($(WITH_WEBSOCKETS),yes) @@ -235,9 +234,6 @@ tls_mosq.o : ${R}/lib/tls_mosq.c util_mosq.o : ${R}/lib/util_mosq.c ${R}/lib/util_mosq.h ${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@ -util_topic.o : ${R}/lib/util_topic.c ${R}/lib/util_mosq.h - ${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@ - will_mosq.o : ${R}/lib/will_mosq.c ${R}/lib/will_mosq.h ${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@ diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 64d17dfab..22c8cfe8b 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -61,7 +61,6 @@ Contributors: #define MQTT3_LOG_ALL 0xFF #define CMD_PORT_LIMIT 10 -#define TOPIC_HIERARCHY_LIMIT 200 typedef uint64_t dbid_t; diff --git a/test/unit/broker/CMakeLists.txt b/test/unit/broker/CMakeLists.txt index 23e77fa1e..e2c9dd9a2 100644 --- a/test/unit/broker/CMakeLists.txt +++ b/test/unit/broker/CMakeLists.txt @@ -3,7 +3,6 @@ add_library(bridge-topic-obj OBJECT ../../../src/bridge_topic.c ../../../lib/memory_mosq.c - ../../../lib/util_topic.c ) target_compile_definitions(bridge-topic-obj PRIVATE WITH_BRIDGE WITH_BROKER) target_link_libraries(bridge-topic-obj PUBLIC common-unit-test-header) @@ -13,7 +12,7 @@ add_executable(bridge-topic-test stubs.c ) target_compile_definitions(bridge-topic-test PRIVATE WITH_BRIDGE WITH_BROKER) -target_link_libraries(bridge-topic-test PRIVATE bridge-topic-obj common-unit-test-header) +target_link_libraries(bridge-topic-test PRIVATE bridge-topic-obj common-unit-test-header libmosquitto_common) add_test(NAME unit-bridge-topic-test COMMAND bridge-topic-test) # keepalive-test diff --git a/test/unit/broker/Makefile b/test/unit/broker/Makefile index 92af98222..39c248332 100644 --- a/test/unit/broker/Makefile +++ b/test/unit/broker/Makefile @@ -21,8 +21,7 @@ BRIDGE_TOPIC_OBJS = \ ${R}/src/bridge_topic.o \ ${R}/src/memory_mosq.o \ ${R}/src/packet_datatypes.o \ - ${R}/src/property_mosq.o \ - ${R}/src/util_topic.o + ${R}/src/property_mosq.o KEEPALIVE_TEST_OBJS = \ keepalive_stubs.o \ @@ -170,9 +169,6 @@ ${R}/src/topic_tok.o : ${R}/src/topic_tok.c ${R}/src/util_mosq.o : ${R}/lib/util_mosq.c $(MAKE) -C ${R}/src/ util_mosq.o -${R}/src/util_topic.o : ${R}/lib/util_topic.c - $(MAKE) -C ${R}/src/ util_topic.o - build : bridge_topic_test keepalive_test persist_read_test persist_write_test subs_test test : build diff --git a/test/unit/lib/CMakeLists.txt b/test/unit/lib/CMakeLists.txt index 46880b4e7..a744a8762 100644 --- a/test/unit/lib/CMakeLists.txt +++ b/test/unit/lib/CMakeLists.txt @@ -8,7 +8,6 @@ add_executable(lib-test property_write.c property_value.c stubs.c - util_topic_test.c # main test files test.c ../../../lib/memory_mosq.c @@ -17,7 +16,6 @@ add_executable(lib-test ../../../lib/packet_mosq.c ../../../lib/property_mosq.c ../../../lib/util_mosq.c - ../../../lib/util_topic.c ) target_link_libraries(lib-test PRIVATE common-unit-test-header OpenSSL::SSL libmosquitto_common) diff --git a/test/unit/lib/Makefile b/test/unit/lib/Makefile index 745f93f37..2a6e9f0bf 100644 --- a/test/unit/lib/Makefile +++ b/test/unit/lib/Makefile @@ -23,7 +23,6 @@ TEST_OBJS = \ property_write.o \ property_value.o \ stubs.o \ - util_topic_test.o LIB_OBJS = \ ${R}/lib/memory_mosq.o \ @@ -31,8 +30,7 @@ LIB_OBJS = \ ${R}/lib/packet_datatypes.o \ ${R}/lib/packet_mosq.o \ ${R}/lib/property_mosq.o \ - ${R}/lib/util_mosq.o \ - ${R}/lib/util_topic.o + ${R}/lib/util_mosq.o all : test-compile @@ -66,9 +64,6 @@ ${R}/lib/property_mosq.o : ${R}/lib/property_mosq.c ${R}/lib/util_mosq.o : ${R}/lib/util_mosq.c $(MAKE) -C ${R}/lib/ util_mosq.o -${R}/lib/util_topic.o : ${R}/lib/util_topic.c - $(MAKE) -C ${R}/lib/ util_topic.o - ${R}/lib/utf8_mosq.o : ${R}/common/utf8_mosq.c $(MAKE) -C ${R}/lib/ utf8_mosq.o diff --git a/test/unit/lib/test.c b/test/unit/lib/test.c index 547ca6ed3..cd8c7d501 100644 --- a/test/unit/lib/test.c +++ b/test/unit/lib/test.c @@ -11,7 +11,6 @@ int init_property_read_tests(void); int init_property_user_read_tests(void); int init_property_write_tests(void); int init_property_value_tests(void); -int init_util_topic_tests(void); int init_misc_trim_tests(void); int main(int argc, char *argv[]) @@ -34,7 +33,6 @@ int main(int argc, char *argv[]) || init_property_user_read_tests() || init_property_write_tests() || init_property_value_tests() - || init_util_topic_tests() || init_misc_trim_tests() ){ diff --git a/test/unit/libcommon/CMakeLists.txt b/test/unit/libcommon/CMakeLists.txt index e4230dad2..b5337ea24 100644 --- a/test/unit/libcommon/CMakeLists.txt +++ b/test/unit/libcommon/CMakeLists.txt @@ -1,6 +1,7 @@ add_executable(libcommon-test strings_test.c test.c + topic_test.c utf8.c ) diff --git a/test/unit/libcommon/Makefile b/test/unit/libcommon/Makefile index 9ff07eaa4..4fdda0f93 100644 --- a/test/unit/libcommon/Makefile +++ b/test/unit/libcommon/Makefile @@ -15,6 +15,7 @@ endif TEST_OBJS = \ strings_test.o \ test.o \ + topic_test.o \ utf8.o \ LIB_OBJS = diff --git a/test/unit/libcommon/test.c b/test/unit/libcommon/test.c index 85e47936c..247441a85 100644 --- a/test/unit/libcommon/test.c +++ b/test/unit/libcommon/test.c @@ -5,6 +5,7 @@ #include int init_strings_tests(void); +int init_topic_tests(void); int init_utf8_tests(void); int main(int argc, char *argv[]) @@ -21,6 +22,7 @@ int main(int argc, char *argv[]) if(0 || init_strings_tests() + || init_topic_tests() || init_utf8_tests() ){ diff --git a/test/unit/lib/util_topic_test.c b/test/unit/libcommon/topic_test.c similarity index 99% rename from test/unit/lib/util_topic_test.c rename to test/unit/libcommon/topic_test.c index 55c06c561..95ae6eadd 100644 --- a/test/unit/lib/util_topic_test.c +++ b/test/unit/libcommon/topic_test.c @@ -1458,7 +1458,7 @@ static void TEST_sub_match_acl(void) * TEST SUITE SETUP * ======================================================================== */ -int init_util_topic_tests(void) +int init_topic_tests(void) { CU_pSuite test_suite = NULL;