Skip to content

Commit

Permalink
treat product key of permit join command as optional parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhao.tyh|taoyuhao authored and yusheng committed Mar 19, 2019
1 parent c30ac19 commit 102301c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/sdk-impl/impl_linkkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,28 +764,32 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *paylo
}
break;
case IOTX_DM_EVENT_GATEWAY_PERMIT: {
char *product_key = NULL;
char *product_key = "";

if (payload == NULL || lite_item_pk.type != cJSON_String || lite_item_time.type != cJSON_Number) {
if (payload == NULL || lite_item_time.type != cJSON_Number) {
return;
}
sdk_debug("Current Product Key: %.*s", lite_item_pk.value_length, lite_item_pk.value);
sdk_debug("Current Time: %d", lite_item_time.value_int);

product_key = IMPL_LINKKIT_MALLOC(lite_item_pk.value_length + 1);
if (product_key == NULL) {
sdk_err("Not Enough Memory");
return;
if (lite_item_pk.type == cJSON_String) {
sdk_debug("Current Product Key: %.*s", lite_item_pk.value_length, lite_item_pk.value);
product_key = IMPL_LINKKIT_MALLOC(lite_item_pk.value_length + 1);
if (product_key == NULL) {
sdk_err("Not Enough Memory");
return;
}
memset(product_key, 0, lite_item_pk.value_length + 1);
memcpy(product_key, lite_item_pk.value, lite_item_pk.value_length);
}
memset(product_key, 0, lite_item_pk.value_length + 1);
memcpy(product_key, lite_item_pk.value, lite_item_pk.value_length);

callback = iotx_event_callback(ITE_PERMIT_JOIN);
if (callback) {
((int (*)(const char *, int))callback)((const char *)product_key, (const int)lite_item_time.value_int);
}

IMPL_LINKKIT_FREE(product_key);
if (lite_item_pk.type == cJSON_String) {
IMPL_LINKKIT_FREE(product_key);
}
}
break;
#endif
Expand Down

0 comments on commit 102301c

Please sign in to comment.