Make cJSON a hard dependency.

pull/2756/merge
Roger A. Light 3 years ago
parent 3f7dd60daa
commit 53dc3006a2

@ -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)

@ -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

@ -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 <roger@atchoo.org>
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)

@ -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"

@ -3,7 +3,6 @@
build_variants = [
'WITH_ADNS',
'WITH_BRIDGE',
'WITH_CJSON',
'WITH_DOCS',
'WITH_EC',
'WITH_EPOLL',

@ -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}

@ -26,6 +26,7 @@ Contributors:
#endif
#include <assert.h>
#include <cjson/cJSON.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@ -43,9 +44,6 @@ Contributors:
#undef uthash_free
#include <uthash.h>
#ifdef WITH_CJSON
# include <cjson/cJSON.h>
#endif
#ifdef __APPLE__
# include <sys/time.h>
@ -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<payloadlen; i++){
if(payload[i] == '"' || payload[i] == '\\' || (payload[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
}

@ -1,7 +1,5 @@
#include "config.h"
#ifdef WITH_CJSON
#include "control_common.h"
#include "json_help.h"
#include <mqtt_protocol.h>
@ -135,4 +133,3 @@ int control__generic_control_callback(struct mosquitto_evt_control *event_data,
return MOSQ_ERR_SUCCESS;
}
#endif

@ -18,8 +18,6 @@ Contributors:
#include "config.h"
#ifdef WITH_CJSON
#include <cjson/cJSON.h>
#include <stdbool.h>
#include <stdlib.h>
@ -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

@ -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 <cjson/cJSON.h>
#include <stdbool.h>
@ -31,4 +29,3 @@ cJSON *cJSON_AddIntToObject(cJSON * const object, const char * const name, long
cJSON *cJSON_CreateInt(int num);
#endif
#endif

@ -86,10 +86,8 @@ typedef SSIZE_T ssize_t;
# define HAVE_PTHREAD_CANCEL
#endif
#ifdef WITH_CJSON
# include <cjson/cJSON.h>
# define CJSON_VERSION_FULL (CJSON_VERSION_MAJOR*1000000+CJSON_VERSION_MINOR*1000+CJSON_VERSION_PATCH)
#endif
#include <cjson/cJSON.h>
#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

@ -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

@ -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 \

@ -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

@ -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"

@ -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

@ -18,8 +18,6 @@ Contributors:
#include "config.h"
#ifdef WITH_CJSON
#include <cjson/cJSON.h>
#include <errno.h>
#include <stdio.h>
@ -270,4 +268,3 @@ static int broker__handle_control(struct control_cmd *cmd, struct mosquitto *con
}
return rc;
}
#endif

@ -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);

@ -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

@ -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

@ -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

Loading…
Cancel
Save