diff --git a/apps/mosquitto_ctrl/CMakeLists.txt b/apps/mosquitto_ctrl/CMakeLists.txt index 19d55714..5a748a49 100644 --- a/apps/mosquitto_ctrl/CMakeLists.txt +++ b/apps/mosquitto_ctrl/CMakeLists.txt @@ -13,6 +13,7 @@ if(WITH_TLS AND CJSON_FOUND) ../../lib/memory_mosq.c ../../lib/memory_mosq.h ../../src/memory_public.c options.c + ../../common/json_help.c ../../common/json_help.h ../../common/password_mosq.c ../../common/password_mosq.h ) diff --git a/apps/mosquitto_ctrl/Makefile b/apps/mosquitto_ctrl/Makefile index ea3e48ea..03931f83 100644 --- a/apps/mosquitto_ctrl/Makefile +++ b/apps/mosquitto_ctrl/Makefile @@ -28,6 +28,7 @@ OBJS= mosquitto_ctrl.o \ dynsec_hash.o \ dynsec_role.o \ get_password.o \ + json_help.o \ memory_mosq.o \ memory_public.o \ options.o \ @@ -87,6 +88,9 @@ example.o : example.c mosquitto_ctrl.h get_password.o : ${R}/apps/mosquitto_passwd/get_password.c ${R}/apps/mosquitto_passwd/get_password.h ${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 $@ + memory_mosq.o : ${R}/lib/memory_mosq.c ${CROSS_COMPILE}${CC} $(APP_CPPFLAGS) $(APP_CFLAGS) -c $< -o $@ diff --git a/apps/mosquitto_ctrl/dynsec.c b/apps/mosquitto_ctrl/dynsec.c index df408bd4..a6dc5373 100644 --- a/apps/mosquitto_ctrl/dynsec.c +++ b/apps/mosquitto_ctrl/dynsec.c @@ -92,14 +92,6 @@ void dynsec__print_usage(void) printf(" https://mosquitto.org/documentation/dynamic-security/\n\n"); } -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); -} - /* ################################################################ * # * # Payload callback diff --git a/apps/mosquitto_ctrl/dynsec_client.c b/apps/mosquitto_ctrl/dynsec_client.c index 02ba70d2..887e783c 100644 --- a/apps/mosquitto_ctrl/dynsec_client.c +++ b/apps/mosquitto_ctrl/dynsec_client.c @@ -23,6 +23,7 @@ Contributors: #include "mosquitto.h" #include "mosquitto_ctrl.h" #include "get_password.h" +#include "json_help.h" #include "password_mosq.h" #include "dynamic_security.h" diff --git a/apps/mosquitto_ctrl/dynsec_group.c b/apps/mosquitto_ctrl/dynsec_group.c index cb4b51e5..912e051f 100644 --- a/apps/mosquitto_ctrl/dynsec_group.c +++ b/apps/mosquitto_ctrl/dynsec_group.c @@ -24,6 +24,7 @@ Contributors: #include "mosquitto.h" #include "mosquitto_ctrl.h" +#include "json_help.h" #include "password_mosq.h" int dynsec_group__create(int argc, char *argv[], cJSON *j_command) diff --git a/apps/mosquitto_ctrl/dynsec_role.c b/apps/mosquitto_ctrl/dynsec_role.c index cae3a6fb..55efab52 100644 --- a/apps/mosquitto_ctrl/dynsec_role.c +++ b/apps/mosquitto_ctrl/dynsec_role.c @@ -28,6 +28,7 @@ Contributors: #include "mosquitto.h" #include "mosquitto_ctrl.h" +#include "json_help.h" #include "password_mosq.h" int dynsec_role__create(int argc, char *argv[], cJSON *j_command) diff --git a/apps/mosquitto_ctrl/mosquitto_ctrl.h b/apps/mosquitto_ctrl/mosquitto_ctrl.h index 6ac3160d..dd39da97 100644 --- a/apps/mosquitto_ctrl/mosquitto_ctrl.h +++ b/apps/mosquitto_ctrl/mosquitto_ctrl.h @@ -87,8 +87,6 @@ int client_request_response(struct mosq_ctrl *ctrl); int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg); int client_connect(struct mosquitto *mosq, struct mosq_config *cfg); -cJSON *cJSON_AddIntToObject(cJSON * const object, const char * const name, int number); - void broker__print_usage(void); int broker__main(int argc, char *argv[], struct mosq_ctrl *ctrl); diff --git a/common/json_help.c b/common/json_help.c index 44fdfab2..d90557ad 100644 --- a/common/json_help.c +++ b/common/json_help.c @@ -96,11 +96,11 @@ 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_AddIntToObject(cJSON * const object, const char * const name, long long number) { char buf[30]; - snprintf(buf, sizeof(buf), "%d", number); + 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 07b58c54..2b11e9d2 100644 --- a/common/json_help.h +++ b/common/json_help.h @@ -27,7 +27,7 @@ int json_get_bool(cJSON *json, const char *name, bool *value, bool optional, boo 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_AddIntToObject(cJSON * const object, const char * const name, long long number); cJSON *cJSON_CreateInt(int num); #endif