mesh: Fix json-c calling conventions

Fix issue assuming that failed calls to json_object_object_get_ex() will
always NULL the out parameter. Re-coded to always check the returned
boolean for success or failure.
This commit is contained in:
Brian Gix 2019-03-21 13:55:17 -07:00
parent a5958b5ba4
commit b1adefb032

View File

@ -72,16 +72,14 @@ static int get_element_index(json_object *jnode, uint16_t ele_addr)
uint16_t addr, num_ele; uint16_t addr, num_ele;
char *str; char *str;
json_object_object_get_ex(jnode, "unicastAddress", &jvalue); if (!json_object_object_get_ex(jnode, "unicastAddress", &jvalue))
if (!jvalue)
return -1; return -1;
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
if (sscanf(str, "%04hx", &addr) != 1) if (sscanf(str, "%04hx", &addr) != 1)
return -1; return -1;
json_object_object_get_ex(jnode, "elements", &jelements); if (!json_object_object_get_ex(jnode, "elements", &jelements))
if (!jelements)
return -1; return -1;
num_ele = json_object_array_length(jelements); num_ele = json_object_array_length(jelements);
@ -105,16 +103,14 @@ static json_object *get_element_model(json_object *jnode, int ele_idx,
else else
snprintf(buf, 9, "%8.8x", mod_id); snprintf(buf, 9, "%8.8x", mod_id);
json_object_object_get_ex(jnode, "elements", &jelements); if (!json_object_object_get_ex(jnode, "elements", &jelements))
if (!jelements)
return NULL; return NULL;
jelement = json_object_array_get_idx(jelements, ele_idx); jelement = json_object_array_get_idx(jelements, ele_idx);
if (!jelement) if (!jelement)
return NULL; return NULL;
json_object_object_get_ex(jelement, "models", &jmodels); if (!json_object_object_get_ex(jelement, "models", &jmodels))
if (!jmodels)
return NULL; return NULL;
num_mods = json_object_array_length(jmodels); num_mods = json_object_array_length(jmodels);
@ -134,8 +130,7 @@ static json_object *get_element_model(json_object *jnode, int ele_idx,
char *str; char *str;
jmodel = json_object_array_get_idx(jmodels, i); jmodel = json_object_array_get_idx(jmodels, i);
json_object_object_get_ex(jmodel, "modelId", &jvalue); if (!json_object_object_get_ex(jmodel, "modelId", &jvalue))
if (!jvalue)
return NULL; return NULL;
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
@ -270,8 +265,7 @@ bool mesh_db_read_device_key(json_object *jobj, uint8_t key_buf[16])
if (!key_buf) if (!key_buf)
return false; return false;
if (!json_object_object_get_ex(jobj, "deviceKey", &jvalue) || if (!json_object_object_get_ex(jobj, "deviceKey", &jvalue))
!jvalue)
return false; return false;
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
@ -291,8 +285,10 @@ bool mesh_db_read_app_keys(json_object *jobj, mesh_db_app_key_cb cb,
if (!cb) if (!cb)
return true; return true;
json_object_object_get_ex(jobj, "appKeys", &jarray); if (!json_object_object_get_ex(jobj, "appKeys", &jarray))
if (!jarray || (json_object_get_type(jarray) != json_type_array)) return false;
if (json_object_get_type(jarray) != json_type_array)
return false; return false;
len = json_object_array_length(jarray); len = json_object_array_length(jarray);
@ -319,16 +315,14 @@ bool mesh_db_read_app_keys(json_object *jobj, mesh_db_app_key_cb cb,
if (!CHECK_KEY_IDX_RANGE(net_idx)) if (!CHECK_KEY_IDX_RANGE(net_idx))
return false; return false;
json_object_object_get_ex(jtemp, "oldKey", &jvalue); if (json_object_object_get_ex(jtemp, "oldKey", &jvalue)) {
if (jvalue) {
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
if (!str2hex(str, strlen(str), key, 16)) if (!str2hex(str, strlen(str), key, 16))
return false; return false;
key_refresh = true; key_refresh = true;
} }
json_object_object_get_ex(jtemp, "key", &jvalue); if (!json_object_object_get_ex(jtemp, "key", &jvalue))
if (!jvalue)
return false; return false;
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
@ -353,8 +347,10 @@ bool mesh_db_read_net_keys(json_object *jobj, mesh_db_net_key_cb cb,
if (!cb) if (!cb)
return true; return true;
json_object_object_get_ex(jobj, "netKeys", &jarray); if (!json_object_object_get_ex(jobj, "netKeys", &jarray))
if (!jarray || (json_object_get_type(jarray) != json_type_array)) return false;
if (json_object_get_type(jarray) != json_type_array)
return false; return false;
len = json_object_array_length(jarray); len = json_object_array_length(jarray);
@ -376,24 +372,21 @@ bool mesh_db_read_net_keys(json_object *jobj, mesh_db_net_key_cb cb,
if (!CHECK_KEY_IDX_RANGE(idx)) if (!CHECK_KEY_IDX_RANGE(idx))
return false; return false;
json_object_object_get_ex(jtemp, "oldKey", &jvalue); if (json_object_object_get_ex(jtemp, "oldKey", &jvalue)) {
if (jvalue) {
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
if (!str2hex(str, strlen(str), key, 16)) if (!str2hex(str, strlen(str), key, 16))
return false; return false;
key_refresh = true; key_refresh = true;
} }
json_object_object_get_ex(jtemp, "key", &jvalue); if (!json_object_object_get_ex(jtemp, "key", &jvalue))
if (!jvalue)
return false; return false;
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
if (!str2hex(str, strlen(str), key_refresh ? new_key : key, 16)) if (!str2hex(str, strlen(str), key_refresh ? new_key : key, 16))
return false; return false;
json_object_object_get_ex(jtemp, "keyRefresh", &jvalue); if (!json_object_object_get_ex(jtemp, "keyRefresh", &jvalue))
if (!jvalue)
phase = KEY_REFRESH_PHASE_NONE; phase = KEY_REFRESH_PHASE_NONE;
else else
phase = json_object_get_int(jvalue); phase = json_object_get_int(jvalue);
@ -410,11 +403,10 @@ bool mesh_db_read_net_keys(json_object *jobj, mesh_db_net_key_cb cb,
bool mesh_db_net_key_add(json_object *jobj, uint16_t idx, bool mesh_db_net_key_add(json_object *jobj, uint16_t idx,
const uint8_t key[16]) const uint8_t key[16])
{ {
json_object *jarray, *jentry = NULL, *jstring; json_object *jarray = NULL, *jentry = NULL, *jstring;
char buf[5]; char buf[5];
json_object_object_get_ex(jobj, "netKeys", &jarray); json_object_object_get_ex(jobj, "netKeys", &jarray);
if (jarray) if (jarray)
jentry = get_key_object(jarray, idx); jentry = get_key_object(jarray, idx);
@ -462,9 +454,7 @@ bool mesh_db_net_key_update(json_object *jobj, uint16_t idx,
json_object *jarray, *jentry, *jstring; json_object *jarray, *jentry, *jstring;
const char *str; const char *str;
json_object_object_get_ex(jobj, "netKeys", &jarray); if (!json_object_object_get_ex(jobj, "netKeys", &jarray))
if (!jarray)
return false; return false;
jentry = get_key_object(jarray, idx); jentry = get_key_object(jarray, idx);
@ -493,8 +483,7 @@ bool mesh_db_net_key_del(json_object *jobj, uint16_t idx)
{ {
json_object *jarray, *jarray_new; json_object *jarray, *jarray_new;
json_object_object_get_ex(jobj, "netKeys", &jarray); if (!json_object_object_get_ex(jobj, "netKeys", &jarray))
if (!jarray)
return true; return true;
/* Check if matching entry exists */ /* Check if matching entry exists */
@ -529,11 +518,10 @@ bool mesh_db_write_device_key(json_object *jnode, uint8_t *key)
bool mesh_db_app_key_add(json_object *jobj, uint16_t net_idx, uint16_t app_idx, bool mesh_db_app_key_add(json_object *jobj, uint16_t net_idx, uint16_t app_idx,
const uint8_t key[16]) const uint8_t key[16])
{ {
json_object *jarray, *jentry = NULL, *jstring = NULL; json_object *jarray = NULL, *jentry = NULL, *jstring = NULL;
char buf[5]; char buf[5];
json_object_object_get_ex(jobj, "appKeys", &jarray); json_object_object_get_ex(jobj, "appKeys", &jarray);
if (jarray) if (jarray)
jentry = get_key_object(jarray, app_idx); jentry = get_key_object(jarray, app_idx);
@ -586,8 +574,7 @@ bool mesh_db_app_key_update(json_object *jobj, uint16_t app_idx,
json_object *jarray, *jentry = NULL, *jstring = NULL; json_object *jarray, *jentry = NULL, *jstring = NULL;
const char *str; const char *str;
json_object_object_get_ex(jobj, "appKeys", &jarray); if (!json_object_object_get_ex(jobj, "appKeys", &jarray))
if (!jarray)
return false; return false;
/* The key entry should exist if the key is updated */ /* The key entry should exist if the key is updated */
@ -610,8 +597,7 @@ bool mesh_db_app_key_del(json_object *jobj, uint16_t net_idx, uint16_t idx)
{ {
json_object *jarray, *jarray_new; json_object *jarray, *jarray_new;
json_object_object_get_ex(jobj, "appKeys", &jarray); if (!json_object_object_get_ex(jobj, "appKeys", &jarray))
if (!jarray)
return true; return true;
/* Check if matching entry exists */ /* Check if matching entry exists */
@ -641,17 +627,16 @@ bool mesh_db_app_key_del(json_object *jobj, uint16_t net_idx, uint16_t idx)
bool mesh_db_model_binding_add(json_object *jnode, uint8_t ele_idx, bool vendor, bool mesh_db_model_binding_add(json_object *jnode, uint8_t ele_idx, bool vendor,
uint32_t mod_id, uint16_t app_idx) uint32_t mod_id, uint16_t app_idx)
{ {
json_object *jmodel, *jstring, *jarray; json_object *jmodel, *jstring, *jarray = NULL;
char buf[5]; char buf[5];
jmodel = get_element_model(jnode, ele_idx, mod_id, vendor); jmodel = get_element_model(jnode, ele_idx, mod_id, vendor);
if (!jmodel) if (!jmodel)
return false; return false;
json_object_object_get_ex(jmodel, "bind", &jarray);
snprintf(buf, 5, "%4.4x", app_idx); snprintf(buf, 5, "%4.4x", app_idx);
json_object_object_get_ex(jmodel, "bind", &jarray);
if (jarray && jarray_has_string(jarray, buf, 4)) if (jarray && jarray_has_string(jarray, buf, 4))
return true; return true;
@ -683,11 +668,12 @@ bool mesh_db_model_binding_del(json_object *jnode, uint8_t ele_idx, bool vendor,
if (!jmodel) if (!jmodel)
return false; return false;
json_object_object_get_ex(jmodel, "bind", &jarray); if (!json_object_object_get_ex(jmodel, "bind", &jarray))
return true;
snprintf(buf, 5, "%4.4x", app_idx); snprintf(buf, 5, "%4.4x", app_idx);
if (!jarray || !jarray_has_string(jarray, buf, 4)) if (!jarray_has_string(jarray, buf, 4))
return true; return true;
if (json_object_array_length(jarray) == 1) { if (json_object_array_length(jarray) == 1) {
@ -787,13 +773,12 @@ static struct mesh_db_pub *parse_model_publication(json_object *jpub)
int len, value; int len, value;
char *str; char *str;
pub = l_new(struct mesh_db_pub, 1); if (!json_object_object_get_ex(jpub, "address", &jvalue))
if (!pub)
return NULL; return NULL;
json_object_object_get_ex(jpub, "address", &jvalue);
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
len = strlen(str); len = strlen(str);
pub = l_new(struct mesh_db_pub, 1);
switch (len) { switch (len) {
case 4: case 4:
@ -824,8 +809,7 @@ static struct mesh_db_pub *parse_model_publication(json_object *jpub)
goto fail; goto fail;
pub->credential = (uint8_t) value; pub->credential = (uint8_t) value;
json_object_object_get_ex(jpub, "retransmit", &jvalue); if (!json_object_object_get_ex(jpub, "retransmit", &jvalue))
if (!jvalue)
goto fail; goto fail;
if (!get_int(jvalue, "count", &value)) if (!get_int(jvalue, "count", &value))
@ -917,10 +901,10 @@ static bool parse_models(json_object *jmodels, struct mesh_db_element *ele)
goto fail; goto fail;
mod = l_new(struct mesh_db_model, 1); mod = l_new(struct mesh_db_model, 1);
if (!ele)
if (!json_object_object_get_ex(jmodel, "modelId", &jvalue))
goto fail; goto fail;
json_object_object_get_ex(jmodel, "modelId", &jvalue);
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
len = strlen(str); len = strlen(str);
@ -944,23 +928,22 @@ static bool parse_models(json_object *jmodels, struct mesh_db_element *ele)
if (len == 8) if (len == 8)
mod->vendor = true; mod->vendor = true;
json_object_object_get_ex(jmodel, "bind", &jarray); if (json_object_object_get_ex(jmodel, "bind", &jarray)) {
if (json_object_get_type(jarray) != json_type_array ||
!parse_bindings(jarray, mod))
goto fail;
}
if (jarray && (json_object_get_type(jarray) != json_type_array if (json_object_object_get_ex(jmodel, "publish", &jvalue)) {
|| !parse_bindings(jarray, mod)))
goto fail;
json_object_object_get_ex(jmodel, "publish", &jvalue);
if (jvalue) {
mod->pub = parse_model_publication(jvalue); mod->pub = parse_model_publication(jvalue);
if (!mod->pub) if (!mod->pub)
goto fail; goto fail;
} }
json_object_object_get_ex(jmodel, "subscribe", &jarray); if (json_object_object_get_ex(jmodel, "subscribe", &jarray)) {
if (!parse_model_subscriptions(jarray, mod))
if (jarray && !parse_model_subscriptions(jarray, mod)) goto fail;
goto fail; }
l_queue_push_tail(ele->models, mod); l_queue_push_tail(ele->models, mod);
} }
@ -1002,24 +985,23 @@ static bool parse_elements(json_object *jelements, struct mesh_db_node *node)
goto fail; goto fail;
ele = l_new(struct mesh_db_element, 1); ele = l_new(struct mesh_db_element, 1);
if (!ele)
goto fail;
ele->index = index; ele->index = index;
ele->models = l_queue_new(); ele->models = l_queue_new();
if (!ele->models) if (!ele->models)
goto fail; goto fail;
json_object_object_get_ex(jelement, "location", &jvalue); if (!json_object_object_get_ex(jelement, "location", &jvalue))
goto fail;
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
if (sscanf(str, "%04hx", &(ele->location)) != 1) if (sscanf(str, "%04hx", &(ele->location)) != 1)
goto fail; goto fail;
json_object_object_get_ex(jelement, "models", &jmodels); if (json_object_object_get_ex(jelement, "models", &jmodels)) {
if (json_object_get_type(jmodels) != json_type_array ||
if (jmodels && (json_object_get_type(jmodels) != json_type_array !parse_models(jmodels, ele))
|| !parse_models(jmodels, ele))) goto fail;
goto fail; }
l_queue_push_tail(node->elements, ele); l_queue_push_tail(node->elements, ele);
} }
@ -1059,40 +1041,34 @@ static void parse_features(json_object *jconfig, struct mesh_db_node *node)
int mode, count; int mode, count;
uint16_t interval; uint16_t interval;
json_object_object_get_ex(jconfig, "proxy", &jvalue); if (json_object_object_get_ex(jconfig, "proxy", &jvalue)) {
if (jvalue) {
mode = get_mode(jvalue); mode = get_mode(jvalue);
if (mode <= MESH_MODE_UNSUPPORTED) if (mode <= MESH_MODE_UNSUPPORTED)
node->modes.proxy = mode; node->modes.proxy = mode;
} }
json_object_object_get_ex(jconfig, "friend", &jvalue); if (json_object_object_get_ex(jconfig, "friend", &jvalue)) {
if (jvalue) {
mode = get_mode(jvalue); mode = get_mode(jvalue);
if (mode <= MESH_MODE_UNSUPPORTED) if (mode <= MESH_MODE_UNSUPPORTED)
node->modes.friend = mode; node->modes.friend = mode;
} }
json_object_object_get_ex(jconfig, "lowPower", &jvalue); if (json_object_object_get_ex(jconfig, "lowPower", &jvalue)) {
if (jvalue) {
mode = get_mode(jvalue); mode = get_mode(jvalue);
if (mode <= MESH_MODE_UNSUPPORTED) if (mode <= MESH_MODE_UNSUPPORTED)
node->modes.friend = mode; node->modes.friend = mode;
} }
json_object_object_get_ex(jconfig, "beacon", &jvalue); if (json_object_object_get_ex(jconfig, "beacon", &jvalue)) {
if (jvalue) {
mode = get_mode(jvalue); mode = get_mode(jvalue);
if (mode <= MESH_MODE_ENABLED) if (mode <= MESH_MODE_UNSUPPORTED)
node->modes.beacon = mode; node->modes.beacon = mode;
} }
json_object_object_get_ex(jconfig, "relay", &jrelay); if (!json_object_object_get_ex(jconfig, "relay", &jrelay))
if (!jrelay)
return; return;
json_object_object_get_ex(jrelay, "mode", &jvalue); if (json_object_object_get_ex(jrelay, "mode", &jvalue)) {
if (jvalue) {
mode = get_mode(jvalue); mode = get_mode(jvalue);
if (mode <= MESH_MODE_UNSUPPORTED) if (mode <= MESH_MODE_UNSUPPORTED)
node->modes.relay.state = mode; node->modes.relay.state = mode;
@ -1101,16 +1077,14 @@ static void parse_features(json_object *jconfig, struct mesh_db_node *node)
} else } else
return; return;
json_object_object_get_ex(jrelay, "count", &jvalue); if (!json_object_object_get_ex(jrelay, "count", &jvalue))
if (!jvalue)
return; return;
/* TODO: check range */ /* TODO: check range */
count = json_object_get_int(jvalue); count = json_object_get_int(jvalue);
node->modes.relay.cnt = count; node->modes.relay.cnt = count;
json_object_object_get_ex(jrelay, "interval", &jvalue); if (!json_object_object_get_ex(jrelay, "interval", &jvalue))
if (!jvalue)
return; return;
/* TODO: check range */ /* TODO: check range */
@ -1124,32 +1098,28 @@ static bool parse_composition(json_object *jcomp, struct mesh_db_node *node)
char *str; char *str;
/* All the fields in node composition are mandatory */ /* All the fields in node composition are mandatory */
json_object_object_get_ex(jcomp, "cid", &jvalue); if (!json_object_object_get_ex(jcomp, "cid", &jvalue))
if (!jvalue)
return false; return false;
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
if (sscanf(str, "%04hx", &node->cid) != 1) if (sscanf(str, "%04hx", &node->cid) != 1)
return false; return false;
json_object_object_get_ex(jcomp, "pid", &jvalue); if (!json_object_object_get_ex(jcomp, "pid", &jvalue))
if (!jvalue)
return false; return false;
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
if (sscanf(str, "%04hx", &node->pid) != 1) if (sscanf(str, "%04hx", &node->pid) != 1)
return false; return false;
json_object_object_get_ex(jcomp, "vid", &jvalue); if (!json_object_object_get_ex(jcomp, "vid", &jvalue))
if (!jvalue)
return false; return false;
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
if (sscanf(str, "%04hx", &node->vid) != 1) if (sscanf(str, "%04hx", &node->vid) != 1)
return false; return false;
json_object_object_get_ex(jcomp, "crpl", &jvalue); if (!json_object_object_get_ex(jcomp, "crpl", &jvalue))
if (!jvalue)
return false; return false;
str = (char *)json_object_get_string(jvalue); str = (char *)json_object_get_string(jvalue);
@ -1182,8 +1152,7 @@ bool mesh_db_read_node(json_object *jnode, mesh_db_node_cb cb, void *user_data)
parse_features(jnode, &node); parse_features(jnode, &node);
json_object_object_get_ex(jnode, "unicastAddress", &jvalue); if (!json_object_object_get_ex(jnode, "unicastAddress", &jvalue)) {
if (!jvalue) {
l_info("Bad config: Unicast address must be present"); l_info("Bad config: Unicast address must be present");
return false; return false;
} }
@ -1192,8 +1161,7 @@ bool mesh_db_read_node(json_object *jnode, mesh_db_node_cb cb, void *user_data)
if (sscanf(str, "%04hx", &node.unicast) != 1) if (sscanf(str, "%04hx", &node.unicast) != 1)
return false; return false;
json_object_object_get_ex(jnode, "defaultTTL", &jvalue); if (json_object_object_get_ex(jnode, "defaultTTL", &jvalue)) {
if (jvalue) {
int ttl = json_object_get_int(jvalue); int ttl = json_object_get_int(jvalue);
if (ttl < 0 || ttl == 1 || ttl > DEFAULT_TTL) if (ttl < 0 || ttl == 1 || ttl > DEFAULT_TTL)
@ -1201,14 +1169,14 @@ bool mesh_db_read_node(json_object *jnode, mesh_db_node_cb cb, void *user_data)
node.ttl = (uint8_t) ttl; node.ttl = (uint8_t) ttl;
} }
json_object_object_get_ex(jnode, "sequenceNumber", &jvalue); if (json_object_object_get_ex(jnode, "sequenceNumber", &jvalue))
if (jvalue)
node.seq_number = json_object_get_int(jvalue); node.seq_number = json_object_get_int(jvalue);
json_object_object_get_ex(jnode, "elements", &jvalue); if (json_object_object_get_ex(jnode, "elements", &jvalue)) {
if (jvalue && json_object_get_type(jvalue) == json_type_array) { if (json_object_get_type(jvalue) == json_type_array) {
if (!parse_elements(jvalue, &node)) if (!parse_elements(jvalue, &node))
return false; return false;
}
} }
return cb(&node, user_data); return cb(&node, user_data);
@ -1352,18 +1320,15 @@ bool mesh_db_read_net_transmit(json_object *jobj, uint8_t *cnt,
if (!jobj) if (!jobj)
return false; return false;
json_object_object_get_ex(jobj, "retransmit", &jretransmit); if (!json_object_object_get_ex(jobj, "retransmit", &jretransmit))
if (!jretransmit)
return false; return false;
json_object_object_get_ex(jretransmit, "count", &jvalue); if (!json_object_object_get_ex(jretransmit, "count", &jvalue))
if (!jvalue)
return false; return false;
*cnt = (uint8_t) json_object_get_int(jvalue); *cnt = (uint8_t) json_object_get_int(jvalue);
json_object_object_get_ex(jretransmit, "interval", &jvalue); if (!json_object_object_get_ex(jretransmit, "interval", &jvalue))
if (!jvalue)
return false; return false;
*interval = (uint16_t) json_object_get_int(jvalue); *interval = (uint16_t) json_object_get_int(jvalue);
@ -1541,8 +1506,7 @@ static void finish_key_refresh(json_object *jobj, uint16_t net_idx)
int i, len; int i, len;
/* Clean up all the bound appkeys */ /* Clean up all the bound appkeys */
json_object_object_get_ex(jobj, "appKeys", &jarray); if (!json_object_object_get_ex(jobj, "appKeys", &jarray))
if (!jarray)
return; return;
len = json_object_array_length(jarray); len = json_object_array_length(jarray);
@ -1574,9 +1538,7 @@ bool mesh_db_net_key_set_phase(json_object *jobj, uint16_t idx, uint8_t phase)
if (!jobj) if (!jobj)
return false; return false;
json_object_object_get_ex(jobj, "netKeys", &jarray); if (json_object_object_get_ex(jobj, "netKeys", &jarray))
if (jarray)
jentry = get_key_object(jarray, idx); jentry = get_key_object(jarray, idx);
if (!jentry) if (!jentry)
@ -1688,7 +1650,7 @@ bool mesh_db_model_pub_del(json_object *jnode, uint16_t addr, uint32_t mod_id,
bool mesh_db_model_sub_add(json_object *jnode, uint16_t addr, uint32_t mod_id, bool mesh_db_model_sub_add(json_object *jnode, uint16_t addr, uint32_t mod_id,
bool vendor, struct mesh_db_sub *sub) bool vendor, struct mesh_db_sub *sub)
{ {
json_object *jmodel, *jstring, *jarray; json_object *jmodel, *jstring, *jarray = NULL;
int ele_idx, len; int ele_idx, len;
char buf[33]; char buf[33];
@ -1703,8 +1665,6 @@ bool mesh_db_model_sub_add(json_object *jnode, uint16_t addr, uint32_t mod_id,
if (!jmodel) if (!jmodel)
return false; return false;
json_object_object_get_ex(jmodel, "subscribe", &jarray);
if (!sub->virt) { if (!sub->virt) {
snprintf(buf, 5, "%4.4x", sub->src.addr); snprintf(buf, 5, "%4.4x", sub->src.addr);
len = 4; len = 4;
@ -1713,6 +1673,7 @@ bool mesh_db_model_sub_add(json_object *jnode, uint16_t addr, uint32_t mod_id,
len = 32; len = 32;
} }
json_object_object_get_ex(jmodel, "subscribe", &jarray);
if (jarray && jarray_has_string(jarray, buf, len)) if (jarray && jarray_has_string(jarray, buf, len))
return true; return true;
@ -1752,8 +1713,7 @@ bool mesh_db_model_sub_del(json_object *jnode, uint16_t addr,
if (!jmodel) if (!jmodel)
return false; return false;
json_object_object_get_ex(jmodel, "subscribe", &jarray); if (!json_object_object_get_ex(jmodel, "subscribe", &jarray))
if (!jarray)
return true; return true;
if (!sub->virt) { if (!sub->virt) {