From 530b09259e9747ab85866646f897c11fd9e0f649 Mon Sep 17 00:00:00 2001 From: Tarik2142 <31830530+Tarik2142@users.noreply.github.com> Date: Sun, 26 Jul 2026 12:34:10 +0300 Subject: [PATCH 1/2] Refactor boolean assignments from cJSON --- .../esp_ot_br_server/src/esp_br_web_base.c | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/components/esp_ot_br_server/src/esp_br_web_base.c b/components/esp_ot_br_server/src/esp_br_web_base.c index 0e4a513..05b00fb 100644 --- a/components/esp_ot_br_server/src/esp_br_web_base.c +++ b/components/esp_ot_br_server/src/esp_br_web_base.c @@ -325,7 +325,7 @@ esp_err_t network_formation_param_json_convert2_struct(const cJSON *root, cJSON temp = cJSON_GetObjectItem(root, "defaultRoute"); if (temp && temp->type != cJSON_NULL) - param->default_route = (bool)cJSON_GetNumberValue(temp); + param->default_route = temp->valueint; else param->default_route = false; @@ -883,7 +883,7 @@ esp_err_t Json2Timestamp(const cJSON *jsonTimestamp, otTimestamp *aTimestamp) value = cJSON_GetObjectItemCaseSensitive(jsonTimestamp, "Authoritative"); if (cJSON_IsBool(value)) { - aTimestamp->mAuthoritative = (bool)cJSON_GetNumberValue(value); + aTimestamp->mAuthoritative = value->valueint; } return ESP_OK; @@ -900,47 +900,47 @@ esp_err_t Json2SecurityPolicy(const cJSON *jsonSecurityPolicy, otSecurityPolicy value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "ObtainNetworkKey"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mObtainNetworkKeyEnabled = (bool)cJSON_GetNumberValue(value); + aSecurityPolicy->mObtainNetworkKeyEnabled = value->valueint; } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "NativeCommissioning"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mNativeCommissioningEnabled = (bool)cJSON_GetNumberValue(value); + aSecurityPolicy->mNativeCommissioningEnabled = value->valueint; } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "Routers"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mRoutersEnabled = (bool)cJSON_GetNumberValue(value); + aSecurityPolicy->mRoutersEnabled = value->valueint; } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "ExternalCommissioning"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mExternalCommissioningEnabled = (bool)cJSON_GetNumberValue(value); + aSecurityPolicy->mExternalCommissioningEnabled = value->valueint; } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "CommercialCommissioning"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mCommercialCommissioningEnabled = (bool)cJSON_GetNumberValue(value); + aSecurityPolicy->mCommercialCommissioningEnabled = value->valueint; } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "AutonomousEnrollment"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mAutonomousEnrollmentEnabled = (bool)cJSON_GetNumberValue(value); + aSecurityPolicy->mAutonomousEnrollmentEnabled = value->valueint; } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "NetworkKeyProvisioning"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mNetworkKeyProvisioningEnabled = (bool)cJSON_GetNumberValue(value); + aSecurityPolicy->mNetworkKeyProvisioningEnabled = value->valueint; } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "TobleLink"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mTobleLinkEnabled = (bool)cJSON_GetNumberValue(value); + aSecurityPolicy->mTobleLinkEnabled = value->valueint; } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "NonCcmRouters"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mNonCcmRoutersEnabled = (bool)cJSON_GetNumberValue(value); + aSecurityPolicy->mNonCcmRoutersEnabled = value->valueint; } return ESP_OK; From c477d400ee844fa07b046de6a1b4a66870b5199f Mon Sep 17 00:00:00 2001 From: Tarik2142 Date: Thu, 20 Aug 2026 12:57:04 +0300 Subject: [PATCH 2/2] use cJSON_IsTrue() for bool values keep default_route as number --- .../esp_ot_br_server/src/esp_br_web_base.c | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/components/esp_ot_br_server/src/esp_br_web_base.c b/components/esp_ot_br_server/src/esp_br_web_base.c index 05b00fb..ff46bac 100644 --- a/components/esp_ot_br_server/src/esp_br_web_base.c +++ b/components/esp_ot_br_server/src/esp_br_web_base.c @@ -325,7 +325,7 @@ esp_err_t network_formation_param_json_convert2_struct(const cJSON *root, cJSON temp = cJSON_GetObjectItem(root, "defaultRoute"); if (temp && temp->type != cJSON_NULL) - param->default_route = temp->valueint; + param->default_route = (bool)cJSON_GetNumberValue(temp); else param->default_route = false; @@ -883,7 +883,7 @@ esp_err_t Json2Timestamp(const cJSON *jsonTimestamp, otTimestamp *aTimestamp) value = cJSON_GetObjectItemCaseSensitive(jsonTimestamp, "Authoritative"); if (cJSON_IsBool(value)) { - aTimestamp->mAuthoritative = value->valueint; + aTimestamp->mAuthoritative = cJSON_IsTrue(value); } return ESP_OK; @@ -900,47 +900,47 @@ esp_err_t Json2SecurityPolicy(const cJSON *jsonSecurityPolicy, otSecurityPolicy value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "ObtainNetworkKey"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mObtainNetworkKeyEnabled = value->valueint; + aSecurityPolicy->mObtainNetworkKeyEnabled = cJSON_IsTrue(value); } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "NativeCommissioning"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mNativeCommissioningEnabled = value->valueint; + aSecurityPolicy->mNativeCommissioningEnabled = cJSON_IsTrue(value); } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "Routers"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mRoutersEnabled = value->valueint; + aSecurityPolicy->mRoutersEnabled = cJSON_IsTrue(value); } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "ExternalCommissioning"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mExternalCommissioningEnabled = value->valueint; + aSecurityPolicy->mExternalCommissioningEnabled = cJSON_IsTrue(value); } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "CommercialCommissioning"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mCommercialCommissioningEnabled = value->valueint; + aSecurityPolicy->mCommercialCommissioningEnabled = cJSON_IsTrue(value); } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "AutonomousEnrollment"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mAutonomousEnrollmentEnabled = value->valueint; + aSecurityPolicy->mAutonomousEnrollmentEnabled = cJSON_IsTrue(value); } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "NetworkKeyProvisioning"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mNetworkKeyProvisioningEnabled = value->valueint; + aSecurityPolicy->mNetworkKeyProvisioningEnabled = cJSON_IsTrue(value); } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "TobleLink"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mTobleLinkEnabled = value->valueint; + aSecurityPolicy->mTobleLinkEnabled = cJSON_IsTrue(value); } value = cJSON_GetObjectItemCaseSensitive(jsonSecurityPolicy, "NonCcmRouters"); if (cJSON_IsBool(value)) { - aSecurityPolicy->mNonCcmRoutersEnabled = value->valueint; + aSecurityPolicy->mNonCcmRoutersEnabled = cJSON_IsTrue(value); } return ESP_OK;