mosquitto/plugins/common/plugin_common.c
Roger A. Light ffb7661d86 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.
2022-02-09 16:26:10 +00:00

22 lines
593 B
C

#include <cjson/cJSON.h>
#include "plugin_common.h"
void plugin__command_reply(struct plugin_cmd *cmd, const char *error)
{
cJSON *j_response;
j_response = cJSON_CreateObject();
if(j_response == NULL) return;
if(cJSON_AddStringToObject(j_response, "command", cmd->command_name) == NULL
|| (error && cJSON_AddStringToObject(j_response, "error", error) == NULL)
|| (cmd->correlation_data && cJSON_AddStringToObject(j_response, "correlationData", cmd->correlation_data) == NULL)
){
cJSON_Delete(j_response);
return;
}
cJSON_AddItemToArray(cmd->j_responses, j_response);
}