Ctrl: Fix use of ints in cJSON.

This commit is contained in:
Roger A. Light 2020-11-04 13:58:40 +00:00
parent 801e31efda
commit aafb75b6bc
5 changed files with 20 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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

View File

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