|
|
|
@ -208,8 +208,9 @@ static int json_print_properties(cJSON *root, const mosquitto_property *properti
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int json_print(const struct mosquitto_message *message, const mosquitto_property *properties, const struct tm *ti, bool escaped, bool pretty)
|
|
|
|
|
static int json_print(const struct mosquitto_message *message, const mosquitto_property *properties, const struct tm *ti, int ns, bool escaped, bool pretty)
|
|
|
|
|
{
|
|
|
|
|
char buf[100];
|
|
|
|
|
#ifdef WITH_CJSON
|
|
|
|
|
cJSON *root;
|
|
|
|
|
cJSON *tmp;
|
|
|
|
@ -221,7 +222,11 @@ static int json_print(const struct mosquitto_message *message, const mosquitto_p
|
|
|
|
|
return MOSQ_ERR_NOMEM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmp = cJSON_CreateNumber(time(NULL));
|
|
|
|
|
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.000000Z%z", ti);
|
|
|
|
|
snprintf(&buf[strlen("2020-05-06T21:48:00.")], 9, "%06d", ns/1000);
|
|
|
|
|
buf[strlen("2020-05-06T21:48:00.000000")] = 'Z';
|
|
|
|
|
|
|
|
|
|
tmp = cJSON_CreateStringReference(buf);
|
|
|
|
|
if(tmp == NULL){
|
|
|
|
|
cJSON_Delete(root);
|
|
|
|
|
return MOSQ_ERR_NOMEM;
|
|
|
|
@ -304,10 +309,12 @@ static int json_print(const struct mosquitto_message *message, const mosquitto_p
|
|
|
|
|
|
|
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
|
|
#else
|
|
|
|
|
char buf[100];
|
|
|
|
|
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.000000Z%z", ti);
|
|
|
|
|
snprintf(&buf[strlen("2020-05-06T21:48:00.")], 9, "%06d", ns/1000);
|
|
|
|
|
buf[strlen("2020-05-06T21:48:00.000000")] = 'Z';
|
|
|
|
|
|
|
|
|
|
strftime(buf, 100, "%s", ti);
|
|
|
|
|
printf("{\"tst\":%s,\"topic\":\"%s\",\"qos\":%d,\"retain\":%d,\"payloadlen\":%d,", buf, message->topic, message->qos, message->retain, message->payloadlen);
|
|
|
|
|
tmp = cJSON_CreateStringReference(buf);
|
|
|
|
|
printf("{\"tst\":\"%s\",\"topic\":\"%s\",\"qos\":%d,\"retain\":%d,\"payloadlen\":%d,", buf, message->topic, message->qos, message->retain, message->payloadlen);
|
|
|
|
|
if(message->qos > 0){
|
|
|
|
|
printf("\"mid\":%d,", message->mid);
|
|
|
|
|
}
|
|
|
|
@ -403,7 +410,7 @@ static void formatted_print(const struct mosq_config *lcfg, const struct mosquit
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(json_print(message, properties, ti, true, lcfg->pretty) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
if(json_print(message, properties, ti, ns, true, lcfg->pretty) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
err_printf(lcfg, "Error: Out of memory.\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -416,7 +423,7 @@ static void formatted_print(const struct mosq_config *lcfg, const struct mosquit
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rc = json_print(message, properties, ti, false, lcfg->pretty);
|
|
|
|
|
rc = json_print(message, properties, ti, ns, false, lcfg->pretty);
|
|
|
|
|
if(rc == MOSQ_ERR_NOMEM){
|
|
|
|
|
err_printf(lcfg, "Error: Out of memory.\n");
|
|
|
|
|
return;
|
|
|
|
|