Skip to content

Commit

Permalink
Merge pull request #174 from ezloteam/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
lomasSE89 authored Sep 4, 2024
2 parents d527c51 + 90da6ed commit 341e2f6
Show file tree
Hide file tree
Showing 38 changed files with 3,095 additions and 2,033 deletions.
5 changes: 1 addition & 4 deletions ezlopi-cloud/ezlopi-cloud-constants/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
file(GLOB_RECURSE src_files "*.c*")
idf_component_register(SRCS


"${src_files}"
idf_component_register(SRCS "ezlopi_cloud_keywords.c" "${src_files}"
INCLUDE_DIRS "."
REQUIRES )
621 changes: 312 additions & 309 deletions ezlopi-cloud/ezlopi-cloud-constants/ezlopi_cloud_keywords.c

Large diffs are not rendered by default.

629 changes: 316 additions & 313 deletions ezlopi-cloud/ezlopi-cloud-constants/ezlopi_cloud_keywords.h

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion ezlopi-cloud/ezlopi-cloud-devices/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
file(GLOB_RECURSE src_files "*.c")
idf_component_register(SRCS "${src_files}"
INCLUDE_DIRS "."
REQUIRES cjext ezlopi-core-factory-info ezlopi-util-trace ezlopi-core-devices ezlopi-cloud-constants
REQUIRES cjext
mbedtls
ezlopi-core-factory-info
ezlopi-util-trace
ezlopi-core-devices
ezlopi-cloud-constants
)
176 changes: 148 additions & 28 deletions ezlopi-cloud/ezlopi-cloud-devices/ezlopi_cloud_devices.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <string.h>
#include "mbedtls/sha1.h"

#include "ezlopi_cloud_devices.h"
#include "ezlopi_util_trace.h"

#include "ezlopi_core_factory_info.h"
Expand All @@ -10,10 +10,58 @@
#include "ezlopi_core_nvs.h"
#include "ezlopi_core_device_group.h"

#include "ezlopi_cloud_devices.h"
#include "ezlopi_cloud_keywords.h"
#include "ezlopi_cloud_methods_str.h"
#include "cjext.h"
#include "ezlopi_cloud_constants.h"
//------------------------------------------------------------------------------------------------------------------
static char *__generate_sha1_of_src(const char *src)
{
char *ret = NULL;
if (src)
{
if (!mbedtls_sha1_self_test(1))
{
unsigned char sha1[20];
mbedtls_sha1_context sha1_ctx;

mbedtls_sha1_init(&sha1_ctx);
if (0 == mbedtls_sha1_starts_ret(&sha1_ctx))
{
if (0 == mbedtls_sha1_update_ret(&sha1_ctx, (const unsigned char *)src, strlen(src)))
{
if (0 == mbedtls_sha1_finish_ret(&sha1_ctx, sha1))
{
size_t len = (4 * sizeof(sha1)) + 1;
ret = (char *)ezlopi_malloc(__FUNCTION__, len);
if (ret)
{
memset(ret, 0, len);
for (int i = 0; i < sizeof(sha1); i++)
{
size_t l = (len - (strlen(ret) + 1));
if (l > 0)
{
((int)sha1[i] / 100 > 0) ? (snprintf(ret + strlen(ret), l, "%u", (uint8_t)sha1[i])) // tripple digit
: ((int)sha1[i] / 10 > 0) ? (snprintf(ret + strlen(ret), l, "0%u", (uint8_t)sha1[i])) // double digit
: (snprintf(ret + strlen(ret), l, "00%u", (uint8_t)sha1[i])); // single digit
}
else
{
break;
}
}
}
}
}
}

mbedtls_sha1_free(&sha1_ctx);
}
}
return ret;
}
//------------------------------------------------------------------------------------------------------------------
void devices_list_v3(cJSON *cj_request, cJSON *cj_response)
{
cJSON *cjson_result = cJSON_AddObjectToObject(__FUNCTION__, cj_response, ezlopi_result_str);
Expand Down Expand Up @@ -72,7 +120,7 @@ void device_name_set(cJSON *cj_request, cJSON *cj_response)
ezlopi_device_name_set_by_device_id(device_id, cj_device_name_str->valuestring);
}
}
}
}
}
}

Expand Down Expand Up @@ -108,10 +156,11 @@ void device_room_set(cJSON *cj_request, cJSON *cj_response)
cJSON *cj_device_id = cJSON_GetObjectItem(__FUNCTION__, cj_params, ezlopi__id_str);
cJSON *cj_room_id = cJSON_GetObjectItem(__FUNCTION__, cj_params, ezlopi_roomId_str);

if (cj_device_id && cj_room_id)
if (cj_device_id && cj_room_id && cj_room_id->valuestring)
{
uint32_t device_id = strtoul(cj_device_id->valuestring, NULL, 16);
ezlopi_device_set_device_room_id(device_id, cJSON_Duplicate(__FUNCTION__, cj_room_id, true));

ezlopi_device_set_device_room_id(device_id, cj_room_id->valuestring, cJSON_GetObjectItem(__FUNCTION__, cj_params, "separateChildDevices"));
}
}
}
Expand Down Expand Up @@ -178,6 +227,10 @@ void device_updated(cJSON *cj_request, cJSON *cj_response)
}
}

if (device_node->cloud_properties.protect_config && (strlen(device_node->cloud_properties.protect_config) > 0))
{
cJSON_AddStringToObject(__FUNCTION__, cj_result, ezlopi_protect_config_str, device_node->cloud_properties.protect_config);
}
break;
}

Expand Down Expand Up @@ -250,12 +303,36 @@ void device_groups_list(cJSON *cj_request, cJSON *cj_response)
cJSON *cj_result = cJSON_AddObjectToObject(__FUNCTION__, cj_response, ezlopi_result_str);
if (cj_result)
{
ezlopi_core_device_group_get_list(cJSON_AddArrayToObject(__FUNCTION__, cj_result, "deviceGroups"));
// cJSON* cj_ver_str = cJSON_GetObjectItem(__FUNCTION__, cj_request, "version");
// if (cj_ver_str && cj_ver_str->valuestring && cj_ver_str->str_value_len)
// {
// cJSON_AddStringToObject(__FUNCTION__, cj_result, "version", cj_ver_str->valuestring);
// }
cJSON *cj_device_groups = cJSON_AddArrayToObject(__FUNCTION__, cj_result, "deviceGroups");
if (cj_device_groups)
{
ezlopi_core_device_group_get_list(cj_device_groups);
}

// check if the version is identical to the ones from request.
char *res_str = cJSON_PrintBuffered(__FUNCTION__, cj_result, 1024, false);
if (res_str)
{
char *hash_str = NULL;
if (NULL != (hash_str = __generate_sha1_of_src(res_str))) // returns malloc ; need to free
{
// TRACE_S("'hash': %s [%d]", hash_str, strlen(hash_str));
cJSON *cj_ver_str = cJSON_GetObjectItem(__FUNCTION__, (cJSON_GetObjectItem(__FUNCTION__, cj_request, "params")), "version");
if (cj_ver_str && cj_ver_str->valuestring && cj_ver_str->str_value_len)
{
// TRACE_D("'req_version': '%s'[%d]", cj_ver_str->valuestring, strlen(cj_ver_str->valuestring));
if (EZPI_STRNCMP_IF_EQUAL(hash_str, cj_ver_str->valuestring, strlen(hash_str), strlen(cj_ver_str->valuestring)))
{
cJSON_DeleteItemFromObject(__FUNCTION__, cj_result, "deviceGroups");
}
}
// now add the 'version_hash' into result.
cJSON_AddStringToObject(__FUNCTION__, cj_result, "version", hash_str);

ezlopi_free(__FUNCTION__, hash_str);
}
ezlopi_free(__FUNCTION__, res_str);
}
}
}
}
Expand Down Expand Up @@ -358,17 +435,36 @@ void device_group_devitem_expand(cJSON *cj_request, cJSON *cj_response)
cJSON *cj_params = cJSON_GetObjectItem(__FUNCTION__, cj_request, ezlopi_params_str);
if (cj_params)
{
// cJSON* cj_show_item = cJSON_GetObjectItem(__FUNCTION__, cj_request, "showItems");
// if (cj_show_item && cJSON_IsBool(cj_show_item) && (cj_show_item->type == cJSON_True))
// {
ezlopi_core_device_group_devitem_expand(cJSON_AddArrayToObject(__FUNCTION__, cj_result, "devices"), cj_params);
// }

// cJSON* cj_ver_str = cJSON_GetObjectItem(__FUNCTION__, cj_request, "version");
// if (cj_ver_str && cj_ver_str->valuestring && cj_ver_str->str_value_len)
// {
// cJSON_AddStringToObject(__FUNCTION__, cj_result, "version", cj_ver_str->valuestring);
// }
cJSON *cj_devices = cJSON_AddArrayToObject(__FUNCTION__, cj_result, "devices");
if (cj_devices)
{
ezlopi_core_device_group_devitem_expand(cj_devices, cj_params);
}

// check if the version is identical to the ones from request.
char *res_str = cJSON_PrintBuffered(__FUNCTION__, cj_result, 1024, false);
if (res_str)
{
char *hash_str = NULL;
if (NULL != (hash_str = __generate_sha1_of_src(res_str))) // returns malloc ; need to free
{
// TRACE_S("'hash': %s [%d]", hash_str, strlen(hash_str));
cJSON *cj_ver_str = cJSON_GetObjectItem(__FUNCTION__, cj_params, "version");
if (cj_ver_str && cj_ver_str->valuestring && cj_ver_str->str_value_len)
{
// TRACE_D("'version': %s [%d]", cj_ver_str->valuestring, cj_ver_str->str_value_len);
if (EZPI_STRNCMP_IF_EQUAL(hash_str, cj_ver_str->valuestring, strlen(hash_str), strlen(cj_ver_str->valuestring)))
{
cJSON_DeleteItemFromObject(__FUNCTION__, cj_result, "devices");
}
}
// now add the 'version_hash' into result.
cJSON_AddStringToObject(__FUNCTION__, cj_result, "version", hash_str);

ezlopi_free(__FUNCTION__, hash_str);
}
ezlopi_free(__FUNCTION__, res_str);
}
}
}
}
Expand Down Expand Up @@ -499,12 +595,36 @@ void item_groups_list(cJSON *cj_request, cJSON *cj_response)
cJSON *cj_result = cJSON_AddObjectToObject(__FUNCTION__, cj_response, ezlopi_result_str);
if (cj_result)
{
ezlopi_core_item_group_get_list(cJSON_AddArrayToObject(__FUNCTION__, cj_result, "itemGroups"));
// cJSON* cj_ver_str = cJSON_GetObjectItem(__FUNCTION__, cj_request, "version");
// if (cj_ver_str && cj_ver_str->valuestring && cj_ver_str->str_value_len)
// {
// cJSON_AddStringToObject(__FUNCTION__, cj_result, "version", cj_ver_str->valuestring);
// }
cJSON *cj_item_groups = cJSON_AddArrayToObject(__FUNCTION__, cj_result, "itemGroups");
if (cj_item_groups)
{
ezlopi_core_item_group_get_list(cj_item_groups);
}

// check if the version is identical to the ones from request.
char *res_str = cJSON_PrintBuffered(__FUNCTION__, cj_result, 1024, false);
if (res_str)
{
char *hash_str = NULL;
if (NULL != (hash_str = __generate_sha1_of_src(res_str))) // returns malloc ; need to free
{
// TRACE_S("'hash': %s [%d]", hash_str, strlen(hash_str));
cJSON *cj_ver_str = cJSON_GetObjectItem(__FUNCTION__, (cJSON_GetObjectItem(__FUNCTION__, cj_request, "params")), "version");
if (cj_ver_str && cj_ver_str->valuestring && cj_ver_str->str_value_len)
{
// TRACE_D("'version': %s [%d]", cj_ver_str->valuestring, cj_ver_str->str_value_len);
if (EZPI_STRNCMP_IF_EQUAL(hash_str, cj_ver_str->valuestring, strlen(hash_str), strlen(cj_ver_str->valuestring)))
{
cJSON_DeleteItemFromObject(__FUNCTION__, cj_result, "itemGroups");
}
}
// now add the 'version_hash' into result.
cJSON_AddStringToObject(__FUNCTION__, cj_result, "version", hash_str);

ezlopi_free(__FUNCTION__, hash_str);
}
ezlopi_free(__FUNCTION__, res_str);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ezlopi-cloud/ezlopi-cloud-items/ezlopi_cloud_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdlib.h>
#include <stdio.h>

#include "cjext.h"
// #include "cjext.h"
#include "ezlopi_util_trace.h"

#include "ezlopi_core_room.h"
Expand Down
Loading

0 comments on commit 341e2f6

Please sign in to comment.