mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-23 00:24:47 +08:00
Move shared code to common directory
This is currently limited to "utility" type functions and does not include code common to the library and broker that are protocol related.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
R=../..
|
||||
include ${R}/config.mk
|
||||
|
||||
CFLAGS_FINAL=${CFLAGS} -I${R}/include -I${R}/ -I${R}/lib -I${R}/src -I${R}/deps -DWITH_BROKER -DWITH_PERSISTENCE
|
||||
CFLAGS_FINAL=${CFLAGS} -I${R}/include -I${R}/ -I${R}/lib -I${R}/src -I${R}/deps -I${R}/common -DWITH_BROKER -DWITH_PERSISTENCE
|
||||
|
||||
OBJS = \
|
||||
db_dump.o \
|
||||
@@ -70,7 +70,7 @@ stubs.o : stubs.c
|
||||
send_disconnect.o : ${R}/lib/send_disconnect.c
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
time_mosq.o : ${R}/lib/time_mosq.c
|
||||
time_mosq.o : ${R}/common/time_mosq.c ${R}/common/time_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
|
||||
|
||||
topic_tok.o : ${R}/src/topic_tok.c
|
||||
|
||||
@@ -5,7 +5,7 @@ if(WITH_TLS AND CJSON_FOUND)
|
||||
|
||||
add_executable(mosquitto_ctrl
|
||||
mosquitto_ctrl.c mosquitto_ctrl.h
|
||||
../../lib/base64_mosq.c ../../lib/base64_mosq.h
|
||||
../../common/base64_mosq.c ../../common/base64_mosq.h
|
||||
broker.c
|
||||
client.c
|
||||
dynsec.c
|
||||
@@ -17,7 +17,7 @@ if(WITH_TLS AND CJSON_FOUND)
|
||||
../../lib/memory_mosq.c ../../lib/memory_mosq.h
|
||||
../../src/memory_public.c
|
||||
options.c
|
||||
../../src/password_mosq.c ../../src/password_mosq.h
|
||||
../../common/password_mosq.c ../../common/password_mosq.h
|
||||
)
|
||||
|
||||
target_include_directories(mosquitto_ctrl PRIVATE
|
||||
@@ -27,10 +27,11 @@ if(WITH_TLS AND CJSON_FOUND)
|
||||
"${STDINT_H_PATH}"
|
||||
"${mosquitto_SOURCE_DIR}"
|
||||
"${mosquitto_SOURCE_DIR}/apps/mosquitto_passwd"
|
||||
"${mosquitto_SOURCE_DIR}/common"
|
||||
"${mosquitto_SOURCE_DIR}/include"
|
||||
"${mosquitto_SOURCE_DIR}/lib"
|
||||
"${mosquitto_SOURCE_DIR}/plugins/common"
|
||||
"${mosquitto_SOURCE_DIR}/plugins/dynamic-security"
|
||||
"${mosquitto_SOURCE_DIR}/plugins/shared"
|
||||
"${mosquitto_SOURCE_DIR}/src"
|
||||
)
|
||||
if(WITH_BUNDLED_DEPS)
|
||||
|
||||
@@ -13,7 +13,7 @@ LIBMOSQ:=${R}/lib/libmosquitto.a
|
||||
endif
|
||||
endif
|
||||
|
||||
LOCAL_CPPFLAGS:=-I${R}/apps/mosquitto_passwd -I${R}/plugins/dynamic-security -DWITH_CJSON -I${R}/plugins/shared
|
||||
LOCAL_CPPFLAGS:=-I${R}/apps/mosquitto_passwd -I${R}/plugins/dynamic-security -DWITH_CJSON -I${R}/plugins/common -I${R}/common
|
||||
ifeq ($(WITH_BUNDLED_DEPS),yes)
|
||||
LOCAL_CPPFLAGS+=-I${R}/deps
|
||||
endif
|
||||
@@ -57,7 +57,7 @@ mosquitto_ctrl_example.so : ${EXAMPLE_OBJS}
|
||||
mosquitto_ctrl.o : mosquitto_ctrl.c mosquitto_ctrl.h
|
||||
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@
|
||||
|
||||
base64_mosq.o : ${R}/lib/base64_mosq.c ${R}/lib/base64_mosq.h
|
||||
base64_mosq.o : ${R}/common/base64_mosq.c ${R}/common/base64_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@
|
||||
|
||||
broker.o : broker.c mosquitto_ctrl.h
|
||||
@@ -99,7 +99,7 @@ options.o : options.c mosquitto_ctrl.h
|
||||
misc_mosq.o : ${R}/lib/misc_mosq.c ${R}/lib/misc_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@
|
||||
|
||||
password_mosq.o : ${R}/src/password_mosq.c ${R}/src/password_mosq.h
|
||||
password_mosq.o : ${R}/common/password_mosq.c ${R}/common/password_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@
|
||||
|
||||
${R}/lib/libmosquitto.so.${SOVERSION} :
|
||||
|
||||
@@ -2,11 +2,11 @@ if(WITH_TLS)
|
||||
add_executable(mosquitto_passwd
|
||||
mosquitto_passwd.c
|
||||
get_password.c get_password.h
|
||||
../../lib/base64_mosq.c ../../lib/base64_mosq.h
|
||||
../../common/base64_mosq.c ../../common/base64_mosq.h
|
||||
../../lib/memory_mosq.c ../../lib/memory_mosq.h
|
||||
../../src/memory_public.c
|
||||
../../lib/misc_mosq.c
|
||||
../../src/password_mosq.c ../../src/password_mosq.h
|
||||
../../common/misc_mosq.c ../../common/misc_mosq.h
|
||||
../../common/password_mosq.c ../../common/password_mosq.h
|
||||
)
|
||||
|
||||
target_include_directories(mosquitto_passwd PRIVATE
|
||||
@@ -14,6 +14,7 @@ if(WITH_TLS)
|
||||
"${STDBOOL_H_PATH}"
|
||||
"${STDINT_H_PATH}"
|
||||
"${mosquitto_SOURCE_DIR}"
|
||||
"${mosquitto_SOURCE_DIR}/common"
|
||||
"${mosquitto_SOURCE_DIR}/include"
|
||||
"${mosquitto_SOURCE_DIR}/lib"
|
||||
"${mosquitto_SOURCE_DIR}/src"
|
||||
|
||||
@@ -26,7 +26,7 @@ mosquitto_passwd.o : mosquitto_passwd.c
|
||||
get_password.o : get_password.c
|
||||
${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@
|
||||
|
||||
base64_mosq.o : ${R}/lib/base64_mosq.c ${R}/lib/base64_mosq.h
|
||||
base64_mosq.o : ${R}/common/base64_mosq.c ${R}/common/base64_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@
|
||||
|
||||
memory_mosq.o : ${R}/lib/memory_mosq.c
|
||||
@@ -35,10 +35,10 @@ memory_mosq.o : ${R}/lib/memory_mosq.c
|
||||
memory_public.o : ${R}/src/memory_public.c
|
||||
${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@
|
||||
|
||||
misc_mosq.o : ${R}/lib/misc_mosq.c ${R}/lib/misc_mosq.h
|
||||
misc_mosq.o : ${R}/common/misc_mosq.c ${R}/common/misc_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@
|
||||
|
||||
password_mosq.o : ${R}/src/password_mosq.c ${R}/src/password_mosq.h
|
||||
password_mosq.o : ${R}/common/password_mosq.c ${R}/common/password_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@
|
||||
|
||||
install : all
|
||||
|
||||
@@ -169,17 +169,17 @@ endif
|
||||
|
||||
STATIC_LIB_DEPS:=
|
||||
|
||||
APP_CPPFLAGS=$(CPPFLAGS) -I. -I../../ -I../../include -I../../src -I../../lib
|
||||
APP_CPPFLAGS=$(CPPFLAGS) -I. -I${R}/ -I${R}/include -I${R}/common -I${R}/lib
|
||||
APP_CFLAGS=$(CFLAGS) -DVERSION=\""${VERSION}\""
|
||||
APP_LDFLAGS:=$(LDFLAGS)
|
||||
|
||||
LIB_CPPFLAGS=$(CPPFLAGS) -I. -I.. -I../include -I../../include
|
||||
LIB_CPPFLAGS=$(CPPFLAGS) -I${R}/ -I. -I${R}/common -I${R}/include -I${R}/lib
|
||||
LIB_CFLAGS:=$(CFLAGS)
|
||||
LIB_CXXFLAGS:=$(CXXFLAGS)
|
||||
LIB_LDFLAGS:=$(LDFLAGS)
|
||||
LIB_LIBADD:=$(LIBADD)
|
||||
|
||||
BROKER_CPPFLAGS:=$(LIB_CPPFLAGS) -I../lib
|
||||
BROKER_CPPFLAGS:=$(LIB_CPPFLAGS) -I../lib -I../common
|
||||
BROKER_CFLAGS:=${CFLAGS} -DVERSION="\"${VERSION}\"" -DWITH_BROKER
|
||||
BROKER_LDFLAGS:=${LDFLAGS}
|
||||
BROKER_LDADD:=
|
||||
@@ -191,7 +191,7 @@ CLIENT_LDADD:=
|
||||
|
||||
PASSWD_LDADD:=
|
||||
|
||||
PLUGIN_CPPFLAGS:=$(CPPFLAGS) -I../.. -I../../include
|
||||
PLUGIN_CPPFLAGS:=$(CPPFLAGS) -I${R} -I${R}/include -I${R}/common -I${R}/plugins/common
|
||||
PLUGIN_CFLAGS:=$(CFLAGS) -fPIC
|
||||
PLUGIN_LDFLAGS:=$(LDFLAGS)
|
||||
|
||||
|
||||
+5
-4
@@ -26,7 +26,7 @@ set(C_SRC
|
||||
loop.c
|
||||
memory_mosq.c memory_mosq.h
|
||||
messages_mosq.c messages_mosq.h
|
||||
misc_mosq.c misc_mosq.h
|
||||
../common/misc_mosq.c ../common/misc_mosq.h
|
||||
mosquitto.c ../include/mosquitto.h
|
||||
mosquitto_internal.h
|
||||
../include/mqtt_protocol.h
|
||||
@@ -48,14 +48,14 @@ set(C_SRC
|
||||
srv_mosq.c
|
||||
strings_mosq.c
|
||||
thread_mosq.c
|
||||
time_mosq.c
|
||||
../common/time_mosq.c ../common/time_mosq.h
|
||||
tls_mosq.c
|
||||
utf8_mosq.c
|
||||
util_mosq.c util_topic.c util_mosq.h
|
||||
will_mosq.c will_mosq.h)
|
||||
|
||||
if (WIN32)
|
||||
list(APPEND C_SRC "winthread_mosq.c" "winthread_mosq.h")
|
||||
list(APPEND C_SRC "../common/winthread_mosq.c" "../common/winthread_mosq.h")
|
||||
endif()
|
||||
|
||||
set (LIBRARIES ${OPENSSL_LIBRARIES} ${PTHREAD_LIBRARIES})
|
||||
@@ -86,7 +86,7 @@ if(WITH_WEBSOCKETS AND WITH_WEBSOCKETS_BUILTIN)
|
||||
add_definitions("-DWITH_WEBSOCKETS=WS_IS_BUILTIN")
|
||||
set(C_SRC ${C_SRC}
|
||||
../deps/picohttpparser/picohttpparser.c
|
||||
base64_mosq.c base64_mosq.h
|
||||
../common/base64_mosq.c ../common/base64_mosq.h
|
||||
http_client.c http_client.h
|
||||
net_ws.c
|
||||
)
|
||||
@@ -107,6 +107,7 @@ target_include_directories(libmosquitto PRIVATE
|
||||
"${STDBOOL_H_PATH}"
|
||||
"${STDINT_H_PATH}"
|
||||
"${mosquitto_SOURCE_DIR}"
|
||||
"${mosquitto_SOURCE_DIR}/common"
|
||||
"${mosquitto_SOURCE_DIR}/include"
|
||||
"${mosquitto_SOURCE_DIR}/lib"
|
||||
)
|
||||
|
||||
+4
-4
@@ -128,7 +128,7 @@ alias_mosq.o : alias_mosq.c alias_mosq.h ${R}/include/mosquitto.h mosquitto_inte
|
||||
callbacks.o : callbacks.c ${R}/include/mosquitto.h mosquitto_internal.h
|
||||
${CROSS_COMPILE}$(CC) $(LIB_CPPFLAGS) $(LIB_CFLAGS) -c $< -o $@
|
||||
|
||||
base64_mosq.o : base64_mosq.c base64_mosq.h
|
||||
base64_mosq.o : ${R}/common/base64_mosq.c ${R}/common/base64_mosq.h
|
||||
${CROSS_COMPILE}$(CC) $(LIB_CPPFLAGS) $(LIB_CFLAGS) -c $< -o $@
|
||||
|
||||
connect.o : connect.c ${R}/include/mosquitto.h mosquitto_internal.h
|
||||
@@ -182,7 +182,7 @@ messages_mosq.o : messages_mosq.c messages_mosq.h
|
||||
memory_mosq.o : memory_mosq.c memory_mosq.h
|
||||
${CROSS_COMPILE}$(CC) $(LIB_CPPFLAGS) $(LIB_CFLAGS) -c $< -o $@
|
||||
|
||||
misc_mosq.o : misc_mosq.c misc_mosq.h
|
||||
misc_mosq.o : ${R}/common/misc_mosq.c ${R}/common/misc_mosq.h
|
||||
${CROSS_COMPILE}$(CC) $(LIB_CPPFLAGS) $(LIB_CFLAGS) -c $< -o $@
|
||||
|
||||
net_mosq_ocsp.o : net_mosq_ocsp.c net_mosq.h
|
||||
@@ -191,7 +191,7 @@ net_mosq_ocsp.o : net_mosq_ocsp.c net_mosq.h
|
||||
net_mosq.o : net_mosq.c net_mosq.h
|
||||
${CROSS_COMPILE}$(CC) $(LIB_CPPFLAGS) $(LIB_CFLAGS) -c $< -o $@
|
||||
|
||||
password_mosq.o : ${R}/src/password_mosq.c net_mosq.h
|
||||
password_mosq.o : ${R}/common/password_mosq.c net_mosq.h
|
||||
${CROSS_COMPILE}$(CC) $(LIB_CPPFLAGS) $(LIB_CFLAGS) -c $< -o $@
|
||||
|
||||
picohttpparser.o : ${R}/deps/picohttpparser/picohttpparser.c ${R}/deps/picohttpparser/picohttpparser.h
|
||||
@@ -245,7 +245,7 @@ strings_mosq.o : strings_mosq.c
|
||||
thread_mosq.o : thread_mosq.c
|
||||
${CROSS_COMPILE}$(CC) $(LIB_CPPFLAGS) $(LIB_CFLAGS) -c $< -o $@
|
||||
|
||||
time_mosq.o : time_mosq.c
|
||||
time_mosq.o : ${R}/common/time_mosq.c ${R}/common/time_mosq.h
|
||||
${CROSS_COMPILE}$(CC) $(LIB_CPPFLAGS) $(LIB_CFLAGS) -c $< -o $@
|
||||
|
||||
tls_mosq.o : tls_mosq.c
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <cjson/cJSON.h>
|
||||
#include "plugin_shared.h"
|
||||
#include "plugin_common.h"
|
||||
|
||||
void plugin__command_reply(struct plugin_cmd *cmd, const char *error)
|
||||
{
|
||||
@@ -8,10 +8,11 @@ if(CJSON_FOUND AND WITH_TLS)
|
||||
"${STDBOOL_H_PATH}"
|
||||
"${STDINT_H_PATH}"
|
||||
"${mosquitto_SOURCE_DIR}"
|
||||
"${mosquitto_SOURCE_DIR}/common"
|
||||
"${mosquitto_SOURCE_DIR}/deps"
|
||||
"${mosquitto_SOURCE_DIR}/include"
|
||||
"${mosquitto_SOURCE_DIR}/lib"
|
||||
"${mosquitto_SOURCE_DIR}/plugins/shared"
|
||||
"${mosquitto_SOURCE_DIR}/plugins/common"
|
||||
"${mosquitto_SOURCE_DIR}/src"
|
||||
)
|
||||
|
||||
@@ -20,7 +21,7 @@ if(CJSON_FOUND AND WITH_TLS)
|
||||
add_library(mosquitto_dynamic_security MODULE
|
||||
acl.c
|
||||
auth.c
|
||||
../../lib/base64_mosq.c ../../lib/base64_mosq.h
|
||||
../../common/base64_mosq.c ../../common/base64_mosq.h
|
||||
clients.c
|
||||
clientlist.c
|
||||
config.c
|
||||
@@ -31,11 +32,11 @@ if(CJSON_FOUND AND WITH_TLS)
|
||||
groups.c
|
||||
grouplist.c
|
||||
hash.c
|
||||
../shared/json_help.c ../shared/json_help.h
|
||||
../../lib/misc_mosq.c ../../lib/misc_mosq.h
|
||||
../../src/password_mosq.c ../../src/password_mosq.h
|
||||
../../common/json_help.c ../../common/json_help.h
|
||||
../../common/misc_mosq.c ../../common/misc_mosq.h
|
||||
../../common/password_mosq.c ../../common/password_mosq.h
|
||||
plugin.c
|
||||
../shared/plugin_shared.c ../shared/plugin_shared.h
|
||||
../common/plugin_common.c ../common/plugin_common.h
|
||||
roles.c
|
||||
rolelist.c
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@ include ${R}/config.mk
|
||||
.PHONY : all binary check clean reallyclean test install uninstall
|
||||
|
||||
PLUGIN_NAME=mosquitto_dynamic_security
|
||||
LOCAL_CPPFLAGS=-I${R}/lib/ -I${R}/src/ -I${R}/plugins/shared -DWITH_CJSON -DWITH_TLS
|
||||
LOCAL_CPPFLAGS=-I${R}/lib/ -I${R}/src/ -I${R}/plugins/common -DWITH_CJSON -DWITH_TLS
|
||||
ifeq ($(WITH_BUNDLED_DEPS),yes)
|
||||
LOCAL_CPPFLAGS:=$(LOCAL_CPPFLAGS) -I${R}/deps
|
||||
endif
|
||||
@@ -26,7 +26,7 @@ OBJS= \
|
||||
misc_mosq.o \
|
||||
password_mosq.o \
|
||||
plugin.o \
|
||||
plugin_shared.o \
|
||||
plugin_common.o \
|
||||
roles.o \
|
||||
rolelist.o
|
||||
|
||||
@@ -52,7 +52,7 @@ acl.o : acl.c dynamic_security.h
|
||||
auth.o : auth.c dynamic_security.h
|
||||
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(PLUGIN_CPPFLAGS) $(PLUGIN_CFLAGS) -c $< -o $@
|
||||
|
||||
base64_mosq.o : ${R}/lib/base64_mosq.c ${R}/lib/base64_mosq.h
|
||||
base64_mosq.o : ${R}/common/base64_mosq.c ${R}/common/base64_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(PLUGIN_CPPFLAGS) $(PLUGIN_CFLAGS) -c $< -o $@
|
||||
|
||||
clients.o : clients.c dynamic_security.h
|
||||
@@ -82,19 +82,19 @@ grouplist.o : grouplist.c dynamic_security.h
|
||||
hash.o : hash.c dynamic_security.h
|
||||
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(PLUGIN_CPPFLAGS) $(PLUGIN_CFLAGS) -c $< -o $@
|
||||
|
||||
json_help.o : ${R}/plugins/shared/json_help.c ${R}/plugins/shared/json_help.h
|
||||
json_help.o : ${R}/common/json_help.c ${R}/common/json_help.h
|
||||
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(PLUGIN_CPPFLAGS) $(PLUGIN_CFLAGS) -c $< -o $@
|
||||
|
||||
misc_mosq.o : ${R}/lib/misc_mosq.c dynamic_security.h
|
||||
misc_mosq.o : ${R}/common/misc_mosq.c ${R}/common/misc_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(PLUGIN_CPPFLAGS) $(PLUGIN_CFLAGS) -c $< -o $@
|
||||
|
||||
password_mosq.o : ${R}/src/password_mosq.c dynamic_security.h
|
||||
password_mosq.o : ${R}/common/password_mosq.c ${R}/common/password_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(PLUGIN_CPPFLAGS) $(PLUGIN_CFLAGS) -c $< -o $@
|
||||
|
||||
plugin.o : plugin.c dynamic_security.h
|
||||
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(PLUGIN_CPPFLAGS) $(PLUGIN_CFLAGS) -c $< -o $@
|
||||
|
||||
plugin_shared.o : ${R}/plugins/shared/plugin_shared.c dynamic_security.h
|
||||
plugin_common.o : ${R}/plugins/common/plugin_common.c dynamic_security.h
|
||||
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(PLUGIN_CPPFLAGS) $(PLUGIN_CFLAGS) -c $< -o $@
|
||||
|
||||
roles.o : roles.c dynamic_security.h
|
||||
|
||||
@@ -30,7 +30,7 @@ Contributors:
|
||||
#include "mosquitto_broker.h"
|
||||
#include "mosquitto_plugin.h"
|
||||
#include "mqtt_protocol.h"
|
||||
#include "plugin_shared.h"
|
||||
#include "plugin_common.h"
|
||||
|
||||
#include "dynamic_security.h"
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ Contributors:
|
||||
#include "mosquitto.h"
|
||||
#include "password_mosq.h"
|
||||
#include "base64_mosq.h"
|
||||
#include "plugin_shared.h"
|
||||
#include "plugin_common.h"
|
||||
|
||||
/* ################################################################
|
||||
* #
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020-2021 Roger Light <roger@atchoo.org>
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License 2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
|
||||
Contributors:
|
||||
Roger Light - initial implementation and documentation.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <cjson/cJSON.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "json_help.h"
|
||||
#include "mosquitto.h"
|
||||
|
||||
|
||||
int json_get_bool(cJSON *json, const char *name, bool *value, bool optional, bool default_value)
|
||||
{
|
||||
cJSON *jtmp;
|
||||
|
||||
if(optional == true){
|
||||
*value = default_value;
|
||||
}
|
||||
|
||||
jtmp = cJSON_GetObjectItem(json, name);
|
||||
if(jtmp){
|
||||
if(cJSON_IsBool(jtmp) == false){
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
*value = cJSON_IsTrue(jtmp);
|
||||
}else{
|
||||
if(optional == false){
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
}
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int json_get_int(cJSON *json, const char *name, int *value, bool optional, int default_value)
|
||||
{
|
||||
cJSON *jtmp;
|
||||
|
||||
if(optional == true){
|
||||
*value = default_value;
|
||||
}
|
||||
|
||||
jtmp = cJSON_GetObjectItem(json, name);
|
||||
if(jtmp){
|
||||
if(cJSON_IsNumber(jtmp) == false){
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
*value = jtmp->valueint;
|
||||
}else{
|
||||
if(optional == false){
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
}
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int json_get_string(cJSON *json, const char *name, char **value, bool optional)
|
||||
{
|
||||
cJSON *jtmp;
|
||||
|
||||
*value = NULL;
|
||||
|
||||
jtmp = cJSON_GetObjectItem(json, name);
|
||||
if(jtmp){
|
||||
if(cJSON_IsString(jtmp) == false){
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
*value = jtmp->valuestring;
|
||||
}else{
|
||||
if(optional == false){
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
}
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
cJSON *cJSON_AddIntToObject(cJSON * const object, const char * const name, int number)
|
||||
{
|
||||
char buf[30];
|
||||
|
||||
snprintf(buf, sizeof(buf), "%d", number);
|
||||
return cJSON_AddRawToObject(object, name, buf);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef JSON_HELP_H
|
||||
#define JSON_HELP_H
|
||||
/*
|
||||
Copyright (c) 2020-2021 Roger Light <roger@atchoo.org>
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License 2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
|
||||
Contributors:
|
||||
Roger Light - initial implementation and documentation.
|
||||
*/
|
||||
#include <cjson/cJSON.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* "optional==false" can also be taken to mean "only return success if the key exists and is valid" */
|
||||
int json_get_bool(cJSON *json, const char *name, bool *value, bool optional, bool default_value);
|
||||
int json_get_int(cJSON *json, const char *name, int *value, bool optional, int default_value);
|
||||
int json_get_string(cJSON *json, const char *name, char **value, bool optional);
|
||||
|
||||
cJSON *cJSON_AddIntToObject(cJSON * const object, const char * const name, int number);
|
||||
cJSON *cJSON_CreateInt(int num);
|
||||
|
||||
#endif
|
||||
+7
-6
@@ -1,6 +1,6 @@
|
||||
set (MOSQ_SRCS
|
||||
../lib/alias_mosq.c ../lib/alias_mosq.h
|
||||
../lib/base64_mosq.c
|
||||
../common/base64_mosq.c ../common/base64_mosq.h
|
||||
bridge.c bridge_topic.c
|
||||
broker_control.c
|
||||
conf.c
|
||||
@@ -22,9 +22,9 @@ set (MOSQ_SRCS
|
||||
../lib/handle_unsuback.c
|
||||
handle_unsubscribe.c
|
||||
http_serv.c
|
||||
json_help.c json_help.h
|
||||
../common/json_help.c ../common/json_help.h
|
||||
keepalive.c
|
||||
lib_load.h
|
||||
../common/lib_load.h
|
||||
listeners.c
|
||||
logging.c
|
||||
loop.c
|
||||
@@ -32,14 +32,14 @@ set (MOSQ_SRCS
|
||||
memory_public.c
|
||||
mosquitto.c
|
||||
../include/mosquitto_broker.h mosquitto_broker_internal.h
|
||||
../lib/misc_mosq.c ../lib/misc_mosq.h
|
||||
../common/misc_mosq.c ../common/misc_mosq.h
|
||||
mux.c mux.h mux_epoll.c mux_kqueue.c mux_poll.c
|
||||
net.c
|
||||
../lib/net_mosq_ocsp.c ../lib/net_mosq.c ../lib/net_mosq.h
|
||||
../lib/net_ws.c
|
||||
../lib/packet_datatypes.c
|
||||
../lib/packet_mosq.c ../lib/packet_mosq.h
|
||||
password_mosq.c password_mosq.h
|
||||
../common/password_mosq.c ../common/password_mosq.h
|
||||
persist_read_v234.c persist_read_v5.c persist_read.c
|
||||
persist_write_v5.c persist_write.c
|
||||
persist.h
|
||||
@@ -69,7 +69,7 @@ set (MOSQ_SRCS
|
||||
../lib/strings_mosq.c
|
||||
subs.c
|
||||
sys_tree.c sys_tree.h
|
||||
../lib/time_mosq.c
|
||||
../common/time_mosq.c ../common/time_mosq.h
|
||||
../lib/tls_mosq.c
|
||||
topic_tok.c
|
||||
../lib/util_mosq.c ../lib/util_topic.c ../lib/util_mosq.h
|
||||
@@ -225,6 +225,7 @@ target_include_directories(mosquitto PRIVATE
|
||||
"${STDBOOL_H_PATH}"
|
||||
"${STDINT_H_PATH}"
|
||||
"${mosquitto_SOURCE_DIR}"
|
||||
"${mosquitto_SOURCE_DIR}/common"
|
||||
"${mosquitto_SOURCE_DIR}/include"
|
||||
"${mosquitto_SOURCE_DIR}/lib"
|
||||
"${mosquitto_SOURCE_DIR}/src"
|
||||
|
||||
+5
-5
@@ -116,7 +116,7 @@ mosquitto.o : mosquitto.c mosquitto_broker_internal.h
|
||||
alias_mosq.o : ${R}/lib/alias_mosq.c ${R}/lib/alias_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
base64_mosq.o : ${R}/lib/base64_mosq.c ${R}/lib/base64_mosq.h
|
||||
base64_mosq.o : ${R}/common/base64_mosq.c ${R}/common/base64_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
bridge.o : bridge.c mosquitto_broker_internal.h
|
||||
@@ -185,7 +185,7 @@ handle_unsubscribe.o : handle_unsubscribe.c mosquitto_broker_internal.h
|
||||
http_serv.o : http_serv.c mosquitto_broker_internal.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
json_help.o : json_help.c json_help.h
|
||||
json_help.o : ${R}/common/json_help.c ${R}/common/json_help.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
keepalive.o : keepalive.c mosquitto_broker_internal.h
|
||||
@@ -206,7 +206,7 @@ memory_mosq.o : ${R}/lib/memory_mosq.c ${R}/lib/memory_mosq.h
|
||||
memory_public.o : memory_public.c mosquitto_broker_internal.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
misc_mosq.o : ${R}/lib/misc_mosq.c ${R}/lib/misc_mosq.h
|
||||
misc_mosq.o : ${R}/common/misc_mosq.c ${R}/common/misc_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
mux.o : mux.c mosquitto_broker_internal.h
|
||||
@@ -233,7 +233,7 @@ net_mosq.o : ${R}/lib/net_mosq.c ${R}/lib/net_mosq.h
|
||||
net_ws.o : ${R}/lib/net_ws.c ${R}/lib/net_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
password_mosq.o : password_mosq.c password_mosq.h mosquitto_broker_internal.h
|
||||
password_mosq.o : ${R}/common/password_mosq.c ${R}/common/password_mosq.h mosquitto_broker_internal.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
persist_read.o : persist_read.c persist.h mosquitto_broker_internal.h
|
||||
@@ -374,7 +374,7 @@ subs.o : subs.c mosquitto_broker_internal.h
|
||||
sys_tree.o : sys_tree.c mosquitto_broker_internal.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
time_mosq.o : ${R}/lib/time_mosq.c ${R}/lib/time_mosq.h
|
||||
time_mosq.o : ${R}/common/time_mosq.c ${R}/common/time_mosq.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
tls_mosq.o : ${R}/lib/tls_mosq.c
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@ include ${R}/config.mk
|
||||
|
||||
.PHONY: all check test test-broker test-lib clean coverage
|
||||
|
||||
CPPFLAGS:=$(CPPFLAGS) -I${R} -I${R}/include -I${R}/lib -I${R}/src
|
||||
CPPFLAGS:=$(CPPFLAGS) -I${R} -I${R}/include -I${R}/lib -I${R}/src -I${R}/common
|
||||
ifeq ($(WITH_BUNDLED_DEPS),yes)
|
||||
CPPFLAGS:=$(CPPFLAGS) -I${R}/deps
|
||||
endif
|
||||
@@ -138,8 +138,8 @@ memory_mosq.o : ${R}/lib/memory_mosq.c
|
||||
memory_public.o : ${R}/src/memory_public.c
|
||||
$(CROSS_COMPILE)$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^
|
||||
|
||||
misc_mosq.o : ${R}/lib/misc_mosq.c
|
||||
$(CROSS_COMPILE)$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^
|
||||
misc_mosq.o : ${R}/common/misc_mosq.c ${R}/common/misc_mosq.h
|
||||
$(CROSS_COMPILE)$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
packet_datatypes.o : ${R}/lib/packet_datatypes.c
|
||||
$(CROSS_COMPILE)$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^
|
||||
|
||||
Reference in New Issue
Block a user