From 53dc3006a26d842912bf420d5b2d845f15c618e7 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sat, 1 Apr 2023 23:35:03 +0100 Subject: [PATCH] Make cJSON a hard dependency. --- CMakeLists.txt | 10 +------ ChangeLog.txt | 1 + README.md | 8 ++---- apps/mosquitto_ctrl/Makefile | 11 ++------ buildtest.py | 1 - client/Makefile | 2 ++ client/sub_client_output.c | 45 +------------------------------ common/control_common.c | 3 --- common/json_help.c | 3 --- common/json_help.h | 3 --- config.h | 6 ++--- config.mk | 9 ------- docker/local/Dockerfile | 1 - fuzzing/broker/Makefile | 2 +- plugins/dynamic-security/Makefile | 8 +----- src/Makefile | 1 + src/broker_control.c | 3 --- src/mosquitto.c | 4 --- src/mosquitto_broker_internal.h | 2 -- src/signals.c | 2 -- test/broker/Makefile | 2 -- 21 files changed, 14 insertions(+), 113 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10824dc0..26e30271 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,15 +92,7 @@ if(WITH_DLT) pkg_check_modules(DLT "automotive-dlt >= 2.11" REQUIRED) endif() -option(WITH_CJSON "Build with cJSON support (required for dynamic security plugin and useful for mosquitto_sub)?" ON) -if(WITH_CJSON) - FIND_PACKAGE(cJSON) - if(CJSON_FOUND) - target_compile_definitions(cJSON INTERFACE WITH_CJSON) - else() - message(STATUS "Optional dependency cJSON not found. Some features will be disabled.") - endif() -endif() +find_package(cJSON REQUIRED) option(WITH_LTO "Build with link time optimizations (IPO) / interprocedural optimization (IPO) enabled." ON) if(WITH_LTO) diff --git a/ChangeLog.txt b/ChangeLog.txt index 611d6a35..e747689a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -184,6 +184,7 @@ Build: preinstalled SQLite3 find module. - Add an CMake option `WITH_LTO` to enable/disable link time optimization. - Set C99 as the explicit, rather than implicit, build standard. +- cJSON is now a required dependency. 2.0.15 - 2022-08-16 diff --git a/README.md b/README.md index a0d275e8..a7f4ba28 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,8 @@ already be built. Use `make binary` to skip building the man pages, or install ### Build Dependencies * c-ares (libc-ares-dev on Debian based systems) - only when compiled with `make WITH_SRV=yes` -* cJSON - for client JSON output support. Disable with `make WITH_CJSON=no` Auto detected with CMake. -* libwebsockets (libwebsockets-dev) - enable with `make WITH_WEBSOCKETS=yes` +* cJSON - required for dynsec plugin, broker control plugin, and for client JSON output support. +* libwebsockets (libwebsockets-dev) - enable with `make WITH_WEBSOCKETS=lws` * openssl (libssl-dev on Debian based systems) - disable with `make WITH_TLS=no` * pthreads - for client library thread support. This is required to support the `mosquitto_loop_start()` and `mosquitto_loop_stop()` functions. If compiled @@ -82,7 +82,3 @@ Equivalent options for enabling/disabling features are available when using the ## Credits Mosquitto was written by Roger Light - -Master: [![Travis Build Status (master)](https://travis-ci.org/eclipse/mosquitto.svg?branch=master)](https://travis-ci.org/eclipse/mosquitto) -Develop: [![Travis Build Status (develop)](https://travis-ci.org/eclipse/mosquitto.svg?branch=develop)](https://travis-ci.org/eclipse/mosquitto) -Fixes: [![Travis Build Status (fixes)](https://travis-ci.org/eclipse/mosquitto.svg?branch=fixes)](https://travis-ci.org/eclipse/mosquitto) diff --git a/apps/mosquitto_ctrl/Makefile b/apps/mosquitto_ctrl/Makefile index 7bf80f46..0ec60012 100644 --- a/apps/mosquitto_ctrl/Makefile +++ b/apps/mosquitto_ctrl/Makefile @@ -14,7 +14,7 @@ endif endif LOCAL_LDFLAGS:=${LDFLAGS} -LOCAL_CPPFLAGS:=-I${R}/apps/mosquitto_passwd -I${R}/plugins/dynamic-security -DWITH_CJSON -I${R}/plugins/common -I${R}/common +LOCAL_CPPFLAGS:=-I${R}/apps/mosquitto_passwd -I${R}/plugins/dynamic-security -I${R}/plugins/common -I${R}/common ifeq ($(WITH_BUNDLED_DEPS),yes) LOCAL_CPPFLAGS+=-I${R}/deps endif @@ -38,16 +38,11 @@ OBJS= mosquitto_ctrl.o \ EXAMPLE_OBJS= example.o ifeq ($(WITH_TLS),yes) -ifeq ($(WITH_CJSON),yes) TARGET:=mosquitto_ctrl mosquitto_ctrl_example.so else TARGET:= endif -else -TARGET:= -endif - all : ${TARGET} mosquitto_ctrl : ${OBJS} ${LIBMOSQ} @@ -90,7 +85,7 @@ get_password.o : ${R}/apps/mosquitto_passwd/get_password.c ${R}/apps/mosquitto_p ${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@ json_help.o : ${R}/common/json_help.c ${R}/common/json_help.h - ${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -DWITH_CJSON=yes -c $< -o $@ + ${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@ memory_mosq.o : ${R}/lib/memory_mosq.c ${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@ @@ -112,11 +107,9 @@ ${R}/lib/libmosquitto.a : install : all ifeq ($(WITH_TLS),yes) -ifeq ($(WITH_CJSON),yes) $(INSTALL) -d "${DESTDIR}$(prefix)/bin" $(INSTALL) ${STRIP_OPTS} mosquitto_ctrl "${DESTDIR}${prefix}/bin/mosquitto_ctrl" endif -endif uninstall : -rm -f "${DESTDIR}${prefix}/bin/mosquitto_ctrl" diff --git a/buildtest.py b/buildtest.py index 8fc2f688..f38caf94 100755 --- a/buildtest.py +++ b/buildtest.py @@ -3,7 +3,6 @@ build_variants = [ 'WITH_ADNS', 'WITH_BRIDGE', - 'WITH_CJSON', 'WITH_DOCS', 'WITH_EC', 'WITH_EPOLL', diff --git a/client/Makefile b/client/Makefile index 5099f4ed..53e170de 100644 --- a/client/Makefile +++ b/client/Makefile @@ -6,6 +6,8 @@ include ${R}/config.mk CLIENT_CFLAGS:=$(CLIENT_CFLAGS) $(CFLAGS) CLIENT_CPPFLAGS:=$(CLIENT_CPPFLAGS) $(CPPFLAGS) CLIENT_LDFLAGS:=$(CLIENT_LDFLAGS) $(LDFLAGS) +CLIENT_LDADD:=${CLIENT_LDADD} -lcjson +CLIENT_STATIC_LDADD:=${CLIENT_STATIC_LDADD} -lcjson ifeq ($(WITH_SHARED_LIBRARIES),yes) SHARED_DEP:=${R}/lib/libmosquitto.so.${SOVERSION} diff --git a/client/sub_client_output.c b/client/sub_client_output.c index e954e3c0..8e684a82 100644 --- a/client/sub_client_output.c +++ b/client/sub_client_output.c @@ -26,6 +26,7 @@ Contributors: #endif #include +#include #include #include #include @@ -43,9 +44,6 @@ Contributors: #undef uthash_free #include -#ifdef WITH_CJSON -# include -#endif #ifdef __APPLE__ # include @@ -149,23 +147,6 @@ static void write_payload(const unsigned char *payload, int payloadlen, int hex, } -#ifndef WITH_CJSON -static void write_json_payload(const char *payload, int payloadlen) -{ - int i; - - for(i=0; i=0 && payload[i] < 32)){ - printf("\\u%04x", payload[i]); - }else{ - fputc(payload[i], stdout); - } - } -} -#endif - - -#ifdef WITH_CJSON static int json_print_properties(cJSON *root, const mosquitto_property *properties) { int identifier; @@ -266,7 +247,6 @@ static int json_print_properties(cJSON *root, const mosquitto_property *properti } return MOSQ_ERR_SUCCESS; } -#endif static void format_time_8601(const struct tm *ti, int ns, char *buf, size_t len) @@ -282,7 +262,6 @@ static void format_time_8601(const struct tm *ti, int ns, char *buf, size_t len) static int json_print(const struct mosquitto_message *message, const mosquitto_property *properties, const struct tm *ti, int ns, bool escaped, bool pretty) { char buf[100]; -#ifdef WITH_CJSON cJSON *root; cJSON *tmp; char *json_str; @@ -351,28 +330,6 @@ static int json_print(const struct mosquitto_message *message, const mosquitto_p free(json_str); return MOSQ_ERR_SUCCESS; -#else - UNUSED(properties); - UNUSED(pretty); - - format_time_8601(ti, ns, buf, sizeof(buf)); - - printf("{\"tst\":\"%s\",\"topic\":\"%s\",\"qos\":%d,\"retain\":%d,\"payloadlen\":%d,", buf, message->topic, message->qos, message->retain, message->payloadlen); - if(message->qos > 0){ - printf("\"mid\":%d,", message->mid); - } - if(escaped){ - fputs("\"payload\":\"", stdout); - write_json_payload(message->payload, message->payloadlen); - fputs("\"}", stdout); - }else{ - fputs("\"payload\":", stdout); - write_payload(message->payload, message->payloadlen, 0, 0, 0, 0, 0); - fputs("}", stdout); - } - - return MOSQ_ERR_SUCCESS; -#endif } diff --git a/common/control_common.c b/common/control_common.c index 0ccf5134..ec6d2622 100644 --- a/common/control_common.c +++ b/common/control_common.c @@ -1,7 +1,5 @@ #include "config.h" -#ifdef WITH_CJSON - #include "control_common.h" #include "json_help.h" #include @@ -135,4 +133,3 @@ int control__generic_control_callback(struct mosquitto_evt_control *event_data, return MOSQ_ERR_SUCCESS; } -#endif diff --git a/common/json_help.c b/common/json_help.c index d90557ad..944332b5 100644 --- a/common/json_help.c +++ b/common/json_help.c @@ -18,8 +18,6 @@ Contributors: #include "config.h" -#ifdef WITH_CJSON - #include #include #include @@ -103,4 +101,3 @@ cJSON *cJSON_AddIntToObject(cJSON * const object, const char * const name, long snprintf(buf, sizeof(buf), "%lld", number); return cJSON_AddRawToObject(object, name, buf); } -#endif diff --git a/common/json_help.h b/common/json_help.h index 2b11e9d2..86226853 100644 --- a/common/json_help.h +++ b/common/json_help.h @@ -17,8 +17,6 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. */ -#ifdef WITH_CJSON - #include #include @@ -31,4 +29,3 @@ cJSON *cJSON_AddIntToObject(cJSON * const object, const char * const name, long cJSON *cJSON_CreateInt(int num); #endif -#endif diff --git a/config.h b/config.h index 88330035..0d8c6e94 100644 --- a/config.h +++ b/config.h @@ -86,10 +86,8 @@ typedef SSIZE_T ssize_t; # define HAVE_PTHREAD_CANCEL #endif -#ifdef WITH_CJSON -# include -# define CJSON_VERSION_FULL (CJSON_VERSION_MAJOR*1000000+CJSON_VERSION_MINOR*1000+CJSON_VERSION_PATCH) -#endif +#include +#define CJSON_VERSION_FULL (CJSON_VERSION_MAJOR*1000000+CJSON_VERSION_MINOR*1000+CJSON_VERSION_PATCH) #define WS_IS_LWS 1 #define WS_IS_BUILTIN 2 diff --git a/config.mk b/config.mk index bd8dfce4..f94bb6d0 100644 --- a/config.mk +++ b/config.mk @@ -110,10 +110,6 @@ WITH_COVERAGE:=no # Build with unix domain socket support WITH_UNIX_SOCKETS:=yes -# Build mosquitto_sub with cJSON support -# Build mosquitto with broker control support -WITH_CJSON:=yes - # Build mosquitto with support for the $CONTROL topics. WITH_CONTROL:=yes @@ -418,14 +414,9 @@ ifeq ($(WITH_COVERAGE),yes) CLIENT_LDFLAGS:=$(CLIENT_LDFLAGS) -coverage endif -ifeq ($(WITH_CJSON),yes) - CLIENT_CFLAGS:=$(CLIENT_CFLAGS) -DWITH_CJSON CLIENT_LDADD:=$(CLIENT_LDADD) -lcjson CLIENT_STATIC_LDADD:=$(CLIENT_STATIC_LDADD) -lcjson - CLIENT_LDFLAGS:=$(CLIENT_LDFLAGS) - BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_CJSON BROKER_LDADD:=$(BROKER_LDADD) -lcjson -endif ifeq ($(WITH_OLD_KEEPALIVE),yes) BROKER_CPPFLAGS:=$(BROKER_CPPFLAGS) -DWITH_OLD_KEEPALIVE diff --git a/docker/local/Dockerfile b/docker/local/Dockerfile index d59ebca0..6aa5b22c 100644 --- a/docker/local/Dockerfile +++ b/docker/local/Dockerfile @@ -21,7 +21,6 @@ RUN set -x && \ make -C /build/mosq -j "$(nproc)" \ CFLAGS="-Wall -O2 -I/build" \ WITH_ADNS=no \ - WITH_CJSON=yes \ WITH_DOCS=no \ WITH_SHARED_LIBRARIES=yes \ WITH_SRV=no \ diff --git a/fuzzing/broker/Makefile b/fuzzing/broker/Makefile index 26663b91..93ff8aa3 100644 --- a/fuzzing/broker/Makefile +++ b/fuzzing/broker/Makefile @@ -8,7 +8,7 @@ FUZZERS:= \ broker_fuzz_test_config LOCAL_CPPFLAGS:=$(CPPFLAGS) -I${R}/include/ -I${R}/src -I${R}/lib -I${R} -I${R}/common -I${R}/deps \ - -DWITH_BRIDGE -DWITH_BROKER -DWITH_CJSON -DWITH_CONTROL -DWITH_EC -DWITH_EPOLL \ + -DWITH_BRIDGE -DWITH_BROKER -DWITH_CONTROL -DWITH_EC -DWITH_EPOLL \ -DWITH_MEMORY_TRACKING -DWITH_PERSISTENCE -DWITH_SOCKS -DWITH_SYSTEMD \ -DWITH_SYS_TREE -DWITH_TLS -DWITH_TLS_PSK -DWITH_UNIX_SOCKETS -DWITH_WEBSOCKETS=WS_IS_BUILTIN LOCAL_CXXFLAGS:=$(CXXFLAGS) -g -Wall -Werror -pthread diff --git a/plugins/dynamic-security/Makefile b/plugins/dynamic-security/Makefile index 749e4d02..a53bbe9d 100644 --- a/plugins/dynamic-security/Makefile +++ b/plugins/dynamic-security/Makefile @@ -4,7 +4,7 @@ include ${R}/config.mk .PHONY : all binary check clean reallyclean test test-compile install uninstall PLUGIN_NAME=mosquitto_dynamic_security -LOCAL_CPPFLAGS=-I${R}/lib/ -I${R}/src/ -I${R}/plugins/common -DWITH_CJSON -DWITH_TLS +LOCAL_CPPFLAGS=-I${R}/lib/ -I${R}/src/ -I${R}/plugins/common -DWITH_TLS ifeq ($(WITH_BUNDLED_DEPS),yes) LOCAL_CPPFLAGS:=$(LOCAL_CPPFLAGS) -I${R}/deps endif @@ -32,15 +32,11 @@ OBJS= \ rolelist.o \ tick.o -ifeq ($(WITH_CJSON),yes) ifeq ($(WITH_TLS),yes) ALL_DEPS:= binary else ALL_DEPS:= endif -else -ALL_DEPS:= -endif all : ${ALL_DEPS} binary : ${PLUGIN_NAME}.so @@ -121,12 +117,10 @@ check: test test: test-compile install: all -ifeq ($(WITH_CJSON),yes) ifeq ($(WITH_TLS),yes) $(INSTALL) -d "${DESTDIR}$(libdir)" $(INSTALL) ${STRIP_OPTS} ${PLUGIN_NAME}.so "${DESTDIR}${libdir}/${PLUGIN_NAME}.so" endif -endif uninstall : -rm -f "${DESTDIR}${libdir}/${PLUGIN_NAME}.so" diff --git a/src/Makefile b/src/Makefile index 62cedd13..6567a29c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -6,6 +6,7 @@ include ${R}/config.mk BROKER_CFLAGS:=$(BROKER_CFLAGS) $(CFLAGS) BROKER_CPPFLAGS:=$(BROKER_CPPFLAGS) $(CPPFLAGS) BROKER_LDFLAGS:=$(BROKER_LDFLAGS) $(LDFLAGS) +BROKER_LDADD:=$(BROKER_LDADD) -lcjson ifeq ($(WITH_FUZZING),yes) all : mosquitto_broker.a diff --git a/src/broker_control.c b/src/broker_control.c index a37f9e2e..1da142a8 100644 --- a/src/broker_control.c +++ b/src/broker_control.c @@ -18,8 +18,6 @@ Contributors: #include "config.h" -#ifdef WITH_CJSON - #include #include #include @@ -270,4 +268,3 @@ static int broker__handle_control(struct control_cmd *cmd, struct mosquitto *con } return rc; } -#endif diff --git a/src/mosquitto.c b/src/mosquitto.c index cf3006b4..4094cd00 100644 --- a/src/mosquitto.c +++ b/src/mosquitto.c @@ -447,9 +447,7 @@ int main(int argc, char *argv[]) bridge__start_all(); #endif -#ifdef WITH_CJSON broker_control__init(); -#endif log__printf(NULL, MOSQ_LOG_INFO, "mosquitto version %s running", VERSION); #ifdef WITH_SYSTEMD @@ -471,9 +469,7 @@ int main(int argc, char *argv[]) db.shutdown = true; log__printf(NULL, MOSQ_LOG_INFO, "mosquitto version %s terminating", VERSION); -#ifdef WITH_CJSON broker_control__cleanup(); -#endif #ifdef WITH_PERSISTENCE persist__backup(true); diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index c4b9fcad..acb2c05f 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -975,10 +975,8 @@ void will_delay__remove(struct mosquitto *mosq); void xtreport(void); #endif -#ifdef WITH_CJSON void broker_control__init(void); void broker_control__cleanup(void); void broker_control__reload(void); -#endif #endif diff --git a/src/signals.c b/src/signals.c index 0b1ca862..88ea8cd2 100644 --- a/src/signals.c +++ b/src/signals.c @@ -112,9 +112,7 @@ void signal__flag_check(void) log__init(db.config); keepalive__cleanup(); keepalive__init(); -#ifdef WITH_CJSON broker_control__reload(); -#endif #ifdef WITH_BRIDGE bridge__reload(); #endif diff --git a/test/broker/Makefile b/test/broker/Makefile index f366b93a..faaadccf 100644 --- a/test/broker/Makefile +++ b/test/broker/Makefile @@ -245,7 +245,6 @@ endif 14 : ifeq ($(WITH_TLS),yes) -ifeq ($(WITH_CJSON),yes) ./14-dynsec-acl.py ./14-dynsec-allow-wildcard.py ./14-dynsec-anon-group.py @@ -266,7 +265,6 @@ ifeq ($(WITH_CJSON),yes) ./14-dynsec-role-invalid.py ./14-dynsec-role.py endif -endif 15 : ./15-persist-client-msg-in-v3-1-1.py persist_sqlite