|
|
|
@ -26,11 +26,41 @@ Contributors:
|
|
|
|
|
#include "mqtt_protocol.h"
|
|
|
|
|
#include "persist_sqlite.h"
|
|
|
|
|
|
|
|
|
|
static uint8_t hex2nibble(char c)
|
|
|
|
|
{
|
|
|
|
|
switch(c){
|
|
|
|
|
case '0': return 0;
|
|
|
|
|
case '1': return 1;
|
|
|
|
|
case '2': return 2;
|
|
|
|
|
case '3': return 3;
|
|
|
|
|
case '4': return 4;
|
|
|
|
|
case '5': return 5;
|
|
|
|
|
case '6': return 6;
|
|
|
|
|
case '7': return 7;
|
|
|
|
|
case '8': return 8;
|
|
|
|
|
case '9': return 9;
|
|
|
|
|
case 'A': return 10;
|
|
|
|
|
case 'a': return 10;
|
|
|
|
|
case 'B': return 11;
|
|
|
|
|
case 'b': return 11;
|
|
|
|
|
case 'C': return 12;
|
|
|
|
|
case 'c': return 12;
|
|
|
|
|
case 'D': return 13;
|
|
|
|
|
case 'd': return 13;
|
|
|
|
|
case 'E': return 14;
|
|
|
|
|
case 'e': return 14;
|
|
|
|
|
case 'F': return 15;
|
|
|
|
|
case 'f': return 15;
|
|
|
|
|
default: return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static mosquitto_property *json_to_properties(const char *json)
|
|
|
|
|
{
|
|
|
|
|
mosquitto_property *properties = NULL;
|
|
|
|
|
cJSON *array, *obj, *j_id, *j_value, *j_name;
|
|
|
|
|
int propid, proptype;
|
|
|
|
|
size_t slen;
|
|
|
|
|
|
|
|
|
|
if(!json) return NULL;
|
|
|
|
|
|
|
|
|
@ -70,6 +100,13 @@ static mosquitto_property *json_to_properties(const char *json)
|
|
|
|
|
mosquitto_property_add_varint(&properties, propid, (uint32_t)j_value->valueint);
|
|
|
|
|
break;
|
|
|
|
|
case MQTT_PROP_TYPE_BINARY:
|
|
|
|
|
if(!cJSON_IsString(j_value)) continue;
|
|
|
|
|
slen = strlen(j_value->valuestring);
|
|
|
|
|
if(slen/2 > UINT16_MAX) continue;
|
|
|
|
|
for(size_t i=0; i<slen; i+=2){
|
|
|
|
|
((uint8_t *)j_value->valuestring)[i/2] = (uint8_t)(hex2nibble(j_value->valuestring[i])<<4) + hex2nibble(j_value->valuestring[i+1]);
|
|
|
|
|
}
|
|
|
|
|
mosquitto_property_add_binary(&properties, propid, (uint8_t *)j_value->valuestring, (uint16_t)(slen/2));
|
|
|
|
|
break;
|
|
|
|
|
case MQTT_PROP_TYPE_STRING:
|
|
|
|
|
if(!cJSON_IsString(j_value)) continue;
|
|
|
|
|