From aafb75b6bc188722ae67395c7df97928b0493c63 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 4 Nov 2020 13:58:40 +0000 Subject: [PATCH] Ctrl: Fix use of ints in cJSON. --- apps/mosquitto_ctrl/dynsec.c | 8 ++++++++ apps/mosquitto_ctrl/dynsec_client.c | 6 +++--- apps/mosquitto_ctrl/dynsec_group.c | 8 ++++---- apps/mosquitto_ctrl/dynsec_role.c | 6 +++--- apps/mosquitto_ctrl/mosquitto_ctrl.h | 2 ++ 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/mosquitto_ctrl/dynsec.c b/apps/mosquitto_ctrl/dynsec.c index 885191a3..79855f30 100644 --- a/apps/mosquitto_ctrl/dynsec.c +++ b/apps/mosquitto_ctrl/dynsec.c @@ -76,6 +76,14 @@ void dynsec__print_usage(void) printf(" |unsubscribeLiteral|unsubscribePattern\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 7119a592..0f9695f9 100644 --- a/apps/mosquitto_ctrl/dynsec_client.c +++ b/apps/mosquitto_ctrl/dynsec_client.c @@ -175,7 +175,7 @@ int dynsec_client__add_remove_role(int argc, char *argv[], cJSON *j_command, con if(cJSON_AddStringToObject(j_command, "command", command) == NULL || cJSON_AddStringToObject(j_command, "username", username) == NULL || cJSON_AddStringToObject(j_command, "rolename", rolename) == NULL - || (priority != -1 && cJSON_AddNumberToObject(j_command, "priority", priority) == NULL) + || (priority != -1 && cJSON_AddIntToObject(j_command, "priority", priority) == NULL) ){ return MOSQ_ERR_NOMEM; @@ -200,8 +200,8 @@ int dynsec_client__list_all(int argc, char *argv[], cJSON *j_command) } if(cJSON_AddStringToObject(j_command, "command", "listClients") == NULL - || (count > 0 && cJSON_AddNumberToObject(j_command, "count", count) == NULL) - || (offset > 0 && cJSON_AddNumberToObject(j_command, "offset", offset) == NULL) + || (count > 0 && cJSON_AddIntToObject(j_command, "count", count) == NULL) + || (offset > 0 && cJSON_AddIntToObject(j_command, "offset", offset) == NULL) ){ return MOSQ_ERR_NOMEM; diff --git a/apps/mosquitto_ctrl/dynsec_group.c b/apps/mosquitto_ctrl/dynsec_group.c index cf3a6ce0..29e8393e 100644 --- a/apps/mosquitto_ctrl/dynsec_group.c +++ b/apps/mosquitto_ctrl/dynsec_group.c @@ -132,7 +132,7 @@ int dynsec_group__add_remove_role(int argc, char *argv[], cJSON *j_command, cons if(cJSON_AddStringToObject(j_command, "command", command) == NULL || cJSON_AddStringToObject(j_command, "groupname", groupname) == NULL || cJSON_AddStringToObject(j_command, "rolename", rolename) == NULL - || (priority != -1 && cJSON_AddNumberToObject(j_command, "priority", priority) == NULL) + || (priority != -1 && cJSON_AddIntToObject(j_command, "priority", priority) == NULL) ){ return MOSQ_ERR_NOMEM; @@ -157,8 +157,8 @@ int dynsec_group__list_all(int argc, char *argv[], cJSON *j_command) } if(cJSON_AddStringToObject(j_command, "command", "listGroups") == NULL - || (count > 0 && cJSON_AddNumberToObject(j_command, "count", count) == NULL) - || (offset > 0 && cJSON_AddNumberToObject(j_command, "offset", offset) == NULL) + || (count > 0 && cJSON_AddIntToObject(j_command, "count", count) == NULL) + || (offset > 0 && cJSON_AddIntToObject(j_command, "offset", offset) == NULL) ){ return MOSQ_ERR_NOMEM; @@ -186,7 +186,7 @@ int dynsec_group__add_remove_client(int argc, char *argv[], cJSON *j_command, co if(cJSON_AddStringToObject(j_command, "command", command) == NULL || cJSON_AddStringToObject(j_command, "username", username) == NULL || cJSON_AddStringToObject(j_command, "groupname", groupname) == NULL - || (priority != -1 && cJSON_AddNumberToObject(j_command, "priority", priority) == NULL) + || (priority != -1 && cJSON_AddIntToObject(j_command, "priority", priority) == NULL) ){ return MOSQ_ERR_NOMEM; diff --git a/apps/mosquitto_ctrl/dynsec_role.c b/apps/mosquitto_ctrl/dynsec_role.c index 1da4d832..0886caff 100644 --- a/apps/mosquitto_ctrl/dynsec_role.c +++ b/apps/mosquitto_ctrl/dynsec_role.c @@ -98,8 +98,8 @@ int dynsec_role__list_all(int argc, char *argv[], cJSON *j_command) } if(cJSON_AddStringToObject(j_command, "command", "listRoles") == NULL - || (count > 0 && cJSON_AddNumberToObject(j_command, "count", count) == NULL) - || (offset > 0 && cJSON_AddNumberToObject(j_command, "offset", offset) == NULL) + || (count > 0 && cJSON_AddIntToObject(j_command, "count", count) == NULL) + || (offset > 0 && cJSON_AddIntToObject(j_command, "offset", offset) == NULL) ){ return MOSQ_ERR_NOMEM; @@ -151,7 +151,7 @@ int dynsec_role__add_acl(int argc, char *argv[], cJSON *j_command) || cJSON_AddStringToObject(j_command, "acltype", acltype) == NULL || cJSON_AddStringToObject(j_command, "topic", topic) == NULL || cJSON_AddBoolToObject(j_command, "allow", allow) == NULL - || (priority != -1 && cJSON_AddNumberToObject(j_command, "priority", priority) == NULL) + || (priority != -1 && cJSON_AddIntToObject(j_command, "priority", priority) == NULL) ){ return MOSQ_ERR_NOMEM; diff --git a/apps/mosquitto_ctrl/mosquitto_ctrl.h b/apps/mosquitto_ctrl/mosquitto_ctrl.h index 80bb11c7..248b8401 100644 --- a/apps/mosquitto_ctrl/mosquitto_ctrl.h +++ b/apps/mosquitto_ctrl/mosquitto_ctrl.h @@ -84,6 +84,8 @@ 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 dynsec__print_usage(void); int dynsec__main(int argc, char *argv[], struct mosq_ctrl *ctrl);