修改看板告警

Signed-off-by: li-tiangang4 <litiangang4@huawei.com>
This commit is contained in:
li-tiangang4 2024-11-07 18:48:41 +08:00
parent 21f5e840ac
commit 38427ad3ac
18 changed files with 349 additions and 315 deletions

View File

@ -58,6 +58,7 @@ private:
void ToJson(cJSON *jsonObject, const MetaCapabilityInfo &metaCapInfo); void ToJson(cJSON *jsonObject, const MetaCapabilityInfo &metaCapInfo);
void FromJson(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo); void FromJson(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo);
void FromJsonContinue(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo);
using MetaCapInfoMap = std::map<std::string, std::shared_ptr<MetaCapabilityInfo>>; using MetaCapInfoMap = std::map<std::string, std::shared_ptr<MetaCapabilityInfo>>;
} // namespace DistributedHardware } // namespace DistributedHardware

View File

@ -110,85 +110,108 @@ std::vector<DHType> ComponentLoader::GetAllCompTypes()
int32_t ParseComponent(const cJSON *json, CompConfig &cfg) int32_t ParseComponent(const cJSON *json, CompConfig &cfg)
{ {
if (!IsString(json, COMP_NAME)) { cJSON *nameJson = cJSON_GetObjectItem(json, COMP_NAME.c_str());
if (!IsString(nameJson)) {
DHLOGE("COMP_NAME is invalid!"); DHLOGE("COMP_NAME is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
cfg.name = cJSON_GetObjectItem(json, COMP_NAME.c_str())->valuestring; cfg.name = nameJson->valuestring;
if (!IsString(json, COMP_TYPE)) {
cJSON *typeJson = cJSON_GetObjectItem(json, COMP_TYPE.c_str());
if (!IsString(typeJson)) {
DHLOGE("COMP_TYPE is invalid!"); DHLOGE("COMP_TYPE is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
cfg.type = g_mapDhTypeName[cJSON_GetObjectItem(json, COMP_TYPE.c_str())->valuestring]; cfg.type = g_mapDhTypeName[typeJson->valuestring];
if (!IsString(json, COMP_HANDLER_LOC)) {
cJSON *handlerLocJson = cJSON_GetObjectItem(json, COMP_HANDLER_LOC.c_str());
if (!IsString(handlerLocJson)) {
DHLOGE("COMP_HANDLER_LOC is invalid!"); DHLOGE("COMP_HANDLER_LOC is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
cfg.compHandlerLoc = cJSON_GetObjectItem(json, COMP_HANDLER_LOC.c_str())->valuestring; cfg.compHandlerLoc = handlerLocJson->valuestring;
if (!IsString(json, COMP_HANDLER_VERSION)) {
cJSON *handlerVerJson = cJSON_GetObjectItem(json, COMP_HANDLER_VERSION.c_str());
if (!IsString(handlerVerJson)) {
DHLOGE("COMP_HANDLER_VERSION is invalid!"); DHLOGE("COMP_HANDLER_VERSION is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
cfg.compHandlerVersion = cJSON_GetObjectItem(json, COMP_HANDLER_VERSION.c_str())->valuestring; cfg.compHandlerVersion = handlerVerJson->valuestring;
return DH_FWK_SUCCESS; return DH_FWK_SUCCESS;
} }
int32_t ParseSource(const cJSON *json, CompConfig &cfg) int32_t ParseSource(const cJSON *json, CompConfig &cfg)
{ {
if (!IsString(json, COMP_SOURCE_LOC)) { cJSON *sourceLocJson = cJSON_GetObjectItem(json, COMP_SOURCE_LOC.c_str());
if (!IsString(sourceLocJson)) {
DHLOGE("COMP_SOURCE_LOC is invalid!"); DHLOGE("COMP_SOURCE_LOC is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
cfg.compSourceLoc = cJSON_GetObjectItem(json, COMP_SOURCE_LOC.c_str())->valuestring; cfg.compSourceLoc = sourceLocJson->valuestring;
if (!IsString(json, COMP_SOURCE_VERSION)) {
cJSON *sourceVerJson = cJSON_GetObjectItem(json, COMP_SOURCE_VERSION.c_str());
if (!IsString(sourceVerJson)) {
DHLOGE("COMP_SOURCE_VERSION is invalid!"); DHLOGE("COMP_SOURCE_VERSION is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
cfg.compSourceVersion = cJSON_GetObjectItem(json, COMP_SOURCE_VERSION.c_str())->valuestring; cfg.compSourceVersion = sourceVerJson->valuestring;
if (!IsInt32(json, COMP_SOURCE_SA_ID)) {
cJSON *sourceSaIdJson = cJSON_GetObjectItem(json, COMP_SOURCE_SA_ID.c_str());
if (!IsInt32(sourceSaIdJson)) {
DHLOGE("COMP_SOURCE_SA_ID is invalid!"); DHLOGE("COMP_SOURCE_SA_ID is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
cfg.compSourceSaId = static_cast<int32_t>(cJSON_GetObjectItem(json, COMP_SOURCE_SA_ID.c_str())->valuedouble); cfg.compSourceSaId = static_cast<int32_t>(sourceSaIdJson->valueint);
return DH_FWK_SUCCESS; return DH_FWK_SUCCESS;
} }
int32_t ParseSink(const cJSON *json, CompConfig &cfg) int32_t ParseSink(const cJSON *json, CompConfig &cfg)
{ {
if (!IsString(json, COMP_SINK_LOC)) { cJSON *sinkLocJson = cJSON_GetObjectItem(json, COMP_SINK_LOC.c_str());
if (!IsString(sinkLocJson)) {
DHLOGE("COMP_SINK_LOC is invalid!"); DHLOGE("COMP_SINK_LOC is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
cfg.compSinkLoc = cJSON_GetObjectItem(json, COMP_SINK_LOC.c_str())->valuestring; cfg.compSinkLoc = sinkLocJson->valuestring;
if (!IsString(json, COMP_SINK_VERSION)) {
cJSON *sinkVerJson = cJSON_GetObjectItem(json, COMP_SINK_VERSION.c_str());
if (!IsString(sinkVerJson)) {
DHLOGE("COMP_SINK_VERSION is invalid!"); DHLOGE("COMP_SINK_VERSION is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
cfg.compSinkVersion = cJSON_GetObjectItem(json, COMP_SINK_VERSION.c_str())->valuestring; cfg.compSinkVersion = sinkVerJson->valuestring;
if (!IsInt32(json, COMP_SINK_SA_ID)) {
cJSON *sinkSaIdJson = cJSON_GetObjectItem(json, COMP_SINK_SA_ID.c_str());
if (!IsInt32(sinkSaIdJson)) {
DHLOGE("COMP_SINK_SA_ID is invalid!"); DHLOGE("COMP_SINK_SA_ID is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
cfg.compSinkSaId = static_cast<int32_t>(cJSON_GetObjectItem(json, COMP_SINK_SA_ID.c_str())->valuedouble); cfg.compSinkSaId = static_cast<int32_t>(sinkSaIdJson->valueint);
return DH_FWK_SUCCESS; return DH_FWK_SUCCESS;
} }
int32_t ParseResourceDesc(const cJSON *json, CompConfig &cfg) int32_t ParseResourceDesc(const cJSON *json, CompConfig &cfg)
{ {
if (!IsArray(json, COMP_RESOURCE_DESC)) { cJSON *resouceDescJson = cJSON_GetObjectItem(json, COMP_RESOURCE_DESC.c_str());
if (!IsArray(resouceDescJson)) {
DHLOGE("COMP_RESOURCE_DESC is invalid!"); DHLOGE("COMP_RESOURCE_DESC is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
cJSON *resourceDescArray = cJSON_GetObjectItem(json, COMP_RESOURCE_DESC.c_str());
cJSON *element = nullptr; cJSON *element = nullptr;
cJSON_ArrayForEach(element, resourceDescArray) { cJSON_ArrayForEach(element, resouceDescJson) {
ResourceDesc desc; ResourceDesc desc;
if (!IsString(element, COMP_SUBTYPE)) { cJSON *subtypeJson = cJSON_GetObjectItem(element, COMP_SUBTYPE.c_str());
if (!IsString(subtypeJson)) {
DHLOGE("COMP_SUBTYPE is invalid!"); DHLOGE("COMP_SUBTYPE is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
desc.subtype = cJSON_GetObjectItem(element, COMP_SUBTYPE.c_str())->valuestring; desc.subtype = subtypeJson->valuestring;
cJSON *sensitive = cJSON_GetObjectItem(element, COMP_SENSITIVE.c_str()); cJSON *sensitive = cJSON_GetObjectItem(element, COMP_SENSITIVE.c_str());
if (!IsBool(sensitive)) {
DHLOGE("COMP_SENSITIVE is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
if (cJSON_IsTrue(sensitive)) { if (cJSON_IsTrue(sensitive)) {
desc.sensitiveValue = true; desc.sensitiveValue = true;
} else { } else {
@ -256,12 +279,12 @@ int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std::
DHLOGE("jsonStr parse failed"); DHLOGE("jsonStr parse failed");
return ERR_DH_FWK_JSON_PARSE_FAILED; return ERR_DH_FWK_JSON_PARSE_FAILED;
} }
if (!IsArray(root, COMPONENTSLOAD_DISTRIBUTED_COMPONENTS)) { cJSON *components = cJSON_GetObjectItem(root, COMPONENTSLOAD_DISTRIBUTED_COMPONENTS.c_str());
if (!IsArray(components)) {
DHLOGE("distributed_components is not an array"); DHLOGE("distributed_components is not an array");
cJSON_Delete(root); cJSON_Delete(root);
return ERR_DH_FWK_PARA_INVALID; return ERR_DH_FWK_PARA_INVALID;
} }
cJSON *components = cJSON_GetObjectItem(root, COMPONENTSLOAD_DISTRIBUTED_COMPONENTS.c_str());
size_t compSize = static_cast<size_t>(cJSON_GetArraySize(components)); size_t compSize = static_cast<size_t>(cJSON_GetArraySize(components));
if (compSize == 0 || compSize > MAX_COMP_SIZE) { if (compSize == 0 || compSize > MAX_COMP_SIZE) {
@ -284,40 +307,48 @@ int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std::
void ComponentLoader::ParseCompConfigFromJson(cJSON *component, CompConfig &config) void ComponentLoader::ParseCompConfigFromJson(cJSON *component, CompConfig &config)
{ {
if (IsString(component, COMP_NAME.c_str())) { cJSON *nameJson = cJSON_GetObjectItem(component, COMP_NAME.c_str());
config.name = cJSON_GetObjectItem(component, COMP_NAME.c_str())->valuestring; if (IsString(nameJson)) {
config.name = nameJson->valuestring;
} }
if (IsString(component, COMP_TYPE.c_str())) { cJSON *typeJson = cJSON_GetObjectItem(component, COMP_TYPE.c_str());
config.type = g_mapDhTypeName[cJSON_GetObjectItem(component, COMP_TYPE.c_str())->valuestring]; if (IsString(typeJson)) {
config.type = g_mapDhTypeName[typeJson->valuestring];
} }
if (IsString(component, COMP_HANDLER_LOC.c_str())) { cJSON *handlerLocJson = cJSON_GetObjectItem(component, COMP_HANDLER_LOC.c_str());
config.compHandlerLoc = cJSON_GetObjectItem(component, COMP_HANDLER_LOC.c_str())->valuestring; if (IsString(handlerLocJson)) {
config.compHandlerLoc = handlerLocJson->valuestring;
} }
if (IsString(component, COMP_HANDLER_VERSION.c_str())) { cJSON *handlerVerJson = cJSON_GetObjectItem(component, COMP_HANDLER_VERSION.c_str());
config.compHandlerVersion = cJSON_GetObjectItem(component, COMP_HANDLER_VERSION.c_str())->valuestring; if (IsString(handlerVerJson)) {
config.compHandlerVersion = handlerVerJson->valuestring;
} }
if (IsString(component, COMP_SOURCE_LOC.c_str())) { cJSON *sourceLocJson = cJSON_GetObjectItem(component, COMP_SOURCE_LOC.c_str());
config.compSourceLoc = cJSON_GetObjectItem(component, COMP_SOURCE_LOC.c_str())->valuestring; if (IsString(sourceLocJson)) {
config.compSourceLoc = sourceLocJson->valuestring;
} }
if (IsString(component, COMP_SOURCE_VERSION.c_str())) { cJSON *sourceVerJson = cJSON_GetObjectItem(component, COMP_SOURCE_VERSION.c_str());
config.compSourceVersion = cJSON_GetObjectItem(component, COMP_SOURCE_VERSION.c_str())->valuestring; if (IsString(sourceVerJson)) {
config.compSourceVersion = sourceVerJson->valuestring;
} }
if (IsInt32(component, COMP_SOURCE_SA_ID.c_str())) { cJSON *sourceSaIdJson = cJSON_GetObjectItem(component, COMP_SOURCE_SA_ID.c_str());
config.compSourceSaId = if (IsInt32(sourceSaIdJson)) {
static_cast<int32_t>(cJSON_GetObjectItem(component, COMP_SOURCE_SA_ID.c_str())->valuedouble); config.compSourceSaId = static_cast<int32_t>(sourceSaIdJson->valueint);
} }
if (IsString(component, COMP_SINK_LOC.c_str())) { cJSON *sinkLocJson = cJSON_GetObjectItem(component, COMP_SINK_LOC.c_str());
config.compSinkLoc = cJSON_GetObjectItem(component, COMP_SINK_LOC.c_str())->valuestring; if (IsString(sinkLocJson)) {
config.compSinkLoc = sinkLocJson->valuestring;
} }
if (IsString(component, COMP_SINK_VERSION.c_str())) { cJSON *sinkVerJson = cJSON_GetObjectItem(component, COMP_SINK_VERSION.c_str());
config.compSinkVersion = cJSON_GetObjectItem(component, COMP_SINK_VERSION.c_str())->valuestring; if (IsString(sinkVerJson)) {
config.compSinkVersion = sinkVerJson->valuestring;
} }
if (IsInt32(component, COMP_SINK_SA_ID.c_str())) { cJSON *sinkSaIdJson = cJSON_GetObjectItem(component, COMP_SINK_SA_ID.c_str());
config.compSinkSaId = if (IsInt32(sinkSaIdJson)) {
static_cast<int32_t>(cJSON_GetObjectItem(component, COMP_SINK_SA_ID.c_str())->valuedouble); config.compSinkSaId = static_cast<int32_t>(sinkSaIdJson->valueint);
} }
if (IsArray(component, COMP_RESOURCE_DESC.c_str())) { cJSON *resourceDescs = cJSON_GetObjectItem(component, COMP_RESOURCE_DESC.c_str());
cJSON *resourceDescs = cJSON_GetObjectItem(component, COMP_RESOURCE_DESC.c_str()); if (IsArray(resourceDescs)) {
ParseResourceDescFromJson(resourceDescs, config); ParseResourceDescFromJson(resourceDescs, config);
} }
} }
@ -328,17 +359,22 @@ void ComponentLoader::ParseResourceDescFromJson(cJSON *resourceDescs, CompConfig
cJSON_ArrayForEach(resourceDesc, resourceDescs) { cJSON_ArrayForEach(resourceDesc, resourceDescs) {
bool sensitiveValue; bool sensitiveValue;
cJSON *sensitive = cJSON_GetObjectItem(resourceDesc, COMP_SENSITIVE.c_str()); cJSON *sensitive = cJSON_GetObjectItem(resourceDesc, COMP_SENSITIVE.c_str());
if (!IsBool(sensitive)) {
DHLOGE("COMP_SUBTYPE is invalid!");
return;
}
if (cJSON_IsTrue(sensitive)) { if (cJSON_IsTrue(sensitive)) {
sensitiveValue = true; sensitiveValue = true;
} else { } else {
sensitiveValue = false; sensitiveValue = false;
} }
ResourceDesc resource; ResourceDesc resource;
if (!IsString(resourceDesc, COMP_SUBTYPE)) { cJSON *subtypeJson = cJSON_GetObjectItem(resourceDesc, COMP_SUBTYPE.c_str());
if (!IsString(subtypeJson)) {
DHLOGE("COMP_SUBTYPE is invalid!"); DHLOGE("COMP_SUBTYPE is invalid!");
return; return;
} }
resource.subtype = cJSON_GetObjectItem(resourceDesc, COMP_SUBTYPE.c_str())->valuestring; resource.subtype = subtypeJson->valuestring;
resource.sensitiveValue = sensitiveValue; resource.sensitiveValue = sensitiveValue;
config.compResourceDesc.push_back(resource); config.compResourceDesc.push_back(resource);
} }

View File

@ -295,47 +295,46 @@ ComponentPrivacy::ComponentEventHandler::~ComponentEventHandler()
void ComponentPrivacy::ComponentEventHandler::ProcessStartPage(const AppExecFwk::InnerEvent::Pointer &event) void ComponentPrivacy::ComponentEventHandler::ProcessStartPage(const AppExecFwk::InnerEvent::Pointer &event)
{ {
DHLOGI("ProcessStartPage enter."); DHLOGI("ProcessStartPage enter.");
if (event == nullptr) {
DHLOGE("event is nullptr");
return;
}
std::shared_ptr<cJSON> dataMsg = event->GetSharedObject<cJSON>(); std::shared_ptr<cJSON> dataMsg = event->GetSharedObject<cJSON>();
cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0); cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0);
if (!IsString(innerMsg, PRIVACY_SUBTYPE)) { cJSON *subtypeJson = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str());
if (!IsString(subtypeJson)) {
DHLOGE("PRIVACY_SUBTYPE is invalid!"); DHLOGE("PRIVACY_SUBTYPE is invalid!");
return; return;
} }
std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring; std::string subtype = subtypeJson->valuestring;
if (!IsString(innerMsg, PRIVACY_NETWORKID)) { cJSON *networkIdJson = cJSON_GetObjectItem(innerMsg, PRIVACY_NETWORKID.c_str());
if (!IsString(networkIdJson)) {
DHLOGE("PRIVACY_NETWORKID is invalid!"); DHLOGE("PRIVACY_NETWORKID is invalid!");
return; return;
} }
std::string networkId = networkIdJson->valuestring;
if (comPrivacyObj_ == nullptr) { if (comPrivacyObj_ == nullptr) {
DHLOGE("comPrivacyObj_ is nullptr"); DHLOGE("comPrivacyObj_ is nullptr");
return; return;
} }
std::string networkId = cJSON_GetObjectItem(innerMsg, PRIVACY_NETWORKID.c_str())->valuestring;
comPrivacyObj_->StartPrivacePage(subtype, networkId); comPrivacyObj_->StartPrivacePage(subtype, networkId);
} }
void ComponentPrivacy::ComponentEventHandler::ProcessStopPage(const AppExecFwk::InnerEvent::Pointer &event) void ComponentPrivacy::ComponentEventHandler::ProcessStopPage(const AppExecFwk::InnerEvent::Pointer &event)
{ {
DHLOGI("ProcessStopPage enter."); DHLOGI("ProcessStopPage enter.");
if (event == nullptr) {
DHLOGE("event is nullptr");
return;
}
std::shared_ptr<cJSON> dataMsg = event->GetSharedObject<cJSON>(); std::shared_ptr<cJSON> dataMsg = event->GetSharedObject<cJSON>();
cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0); cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0);
if (!IsString(innerMsg, PRIVACY_SUBTYPE)) { if (innerMsg == NULL) {
DHLOGE("innerMsg is nullptr");
return;
}
cJSON *subtypeJson = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str());
if (!IsString(subtypeJson)) {
DHLOGE("PRIVACY_SUBTYPE is invalid!"); DHLOGE("PRIVACY_SUBTYPE is invalid!");
return; return;
} }
std::string subtype = subtypeJson->valuestring;
if (comPrivacyObj_ == nullptr) { if (comPrivacyObj_ == nullptr) {
DHLOGE("comPrivacyObj_ is nullptr"); DHLOGE("comPrivacyObj_ is nullptr");
return; return;
} }
std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring;
comPrivacyObj_->StopPrivacePage(subtype); comPrivacyObj_->StopPrivacePage(subtype);
} }
} // namespace DistributedHardware } // namespace DistributedHardware

View File

@ -237,12 +237,13 @@ std::string DistributedHardwareService::QueryDhSysSpec(const std::string &target
DHLOGE("attrs json is invalid, attrs: %{public}s", attrs.c_str()); DHLOGE("attrs json is invalid, attrs: %{public}s", attrs.c_str());
return ""; return "";
} }
if (!IsString(attrJson, targetKey)) { cJSON *targetKeyJson = cJSON_GetObjectItem(attrJson, targetKey.c_str());
if (!IsString(targetKeyJson)) {
DHLOGE("Attrs Json not contains key: %{public}s", targetKey.c_str()); DHLOGE("Attrs Json not contains key: %{public}s", targetKey.c_str());
cJSON_Delete(attrJson); cJSON_Delete(attrJson);
return ""; return "";
} }
std::string result = cJSON_GetObjectItem(attrJson, targetKey.c_str())->valuestring; std::string result = targetKeyJson->valuestring;
cJSON_Delete(attrJson); cJSON_Delete(attrJson);
return result; return result;
} }

View File

@ -53,19 +53,21 @@ void LowLatencyListener::OnMessage(const DHTopic topic, const std::string& messa
DHLOGE("jsonStr parse failed"); DHLOGE("jsonStr parse failed");
return; return;
} }
if (!IsUInt32(jsonObj, DH_TYPE)) { cJSON *dhTypeJson = cJSON_GetObjectItem(jsonObj, DH_TYPE.c_str());
if (!IsUInt32(dhTypeJson)) {
DHLOGE("The DH_TYPE key is invalid!"); DHLOGE("The DH_TYPE key is invalid!");
cJSON_Delete(jsonObj); cJSON_Delete(jsonObj);
return; return;
} }
if (!IsBool(jsonObj, LOW_LATENCY_ENABLE)) {
cJSON *enableJson = cJSON_GetObjectItem(jsonObj, LOW_LATENCY_ENABLE.c_str());
if (!IsBool(enableJson)) {
DHLOGE("The LOW_LATENCY_ENABLE key is invalid!"); DHLOGE("The LOW_LATENCY_ENABLE key is invalid!");
cJSON_Delete(jsonObj); cJSON_Delete(jsonObj);
return; return;
} }
DHType dhType = (DHType)cJSON_GetObjectItem(jsonObj, DH_TYPE.c_str())->valuedouble; DHType dhType = (DHType)dhTypeJson->valueint;
cJSON *isEnable = cJSON_GetObjectItem(jsonObj, LOW_LATENCY_ENABLE.c_str()); if (cJSON_IsTrue(enableJson)) {
if (cJSON_IsTrue(isEnable)) {
LowLatency::GetInstance().EnableLowLatency(dhType); LowLatency::GetInstance().EnableLowLatency(dhType);
} else { } else {
LowLatency::GetInstance().DisableLowLatency(dhType); LowLatency::GetInstance().DisableLowLatency(dhType);

View File

@ -207,47 +207,54 @@ void FromJson(const cJSON *jsonObject, CapabilityInfo &capability)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, DH_ID)) { cJSON *dhIdJson = cJSON_GetObjectItem(jsonObject, DH_ID.c_str());
if (!IsString(dhIdJson)) {
DHLOGE("DH_ID is invalid!"); DHLOGE("DH_ID is invalid!");
return; return;
} }
capability.SetDHId(cJSON_GetObjectItem(jsonObject, DH_ID.c_str())->valuestring); capability.SetDHId(dhIdJson->valuestring);
if (!IsString(jsonObject, DEV_ID)) { cJSON *devIdJson = cJSON_GetObjectItem(jsonObject, DEV_ID.c_str());
if (!IsString(devIdJson)) {
DHLOGE("DEV_ID is invalid!"); DHLOGE("DEV_ID is invalid!");
return; return;
} }
capability.SetDeviceId(cJSON_GetObjectItem(jsonObject, DEV_ID.c_str())->valuestring); capability.SetDeviceId(devIdJson->valuestring);
if (!IsString(jsonObject, DEV_NAME)) { cJSON *devNameJson = cJSON_GetObjectItem(jsonObject, DEV_NAME.c_str());
if (!IsString(devNameJson)) {
DHLOGE("DEV_NAME is invalid!"); DHLOGE("DEV_NAME is invalid!");
return; return;
} }
capability.SetDeviceName(cJSON_GetObjectItem(jsonObject, DEV_NAME.c_str())->valuestring); capability.SetDeviceName(devNameJson->valuestring);
if (!IsUInt16(jsonObject, DEV_TYPE)) { cJSON *devTypeJson = cJSON_GetObjectItem(jsonObject, DEV_TYPE.c_str());
if (!IsUInt16(devTypeJson)) {
DHLOGE("DEV_TYPE is invalid!"); DHLOGE("DEV_TYPE is invalid!");
return; return;
} }
capability.SetDeviceType((uint16_t)cJSON_GetObjectItem(jsonObject, DEV_TYPE.c_str())->valuedouble); capability.SetDeviceType(static_cast<uint16_t>(devTypeJson->valueint));
if (!IsUInt32(jsonObject, DH_TYPE)) { cJSON *dhTypeJson = cJSON_GetObjectItem(jsonObject, DH_TYPE.c_str());
if (!IsUInt32(dhTypeJson)) {
DHLOGE("DH_TYPE is invalid!"); DHLOGE("DH_TYPE is invalid!");
return; return;
} }
capability.SetDHType((DHType)cJSON_GetObjectItem(jsonObject, DH_TYPE.c_str())->valuedouble); capability.SetDHType((DHType)dhTypeJson->valueint);
if (!IsString(jsonObject, DH_ATTRS)) { cJSON *dhAttrsJson = cJSON_GetObjectItem(jsonObject, DH_ATTRS.c_str());
if (!IsString(dhAttrsJson)) {
DHLOGE("DH_ATTRS is invalid!"); DHLOGE("DH_ATTRS is invalid!");
return; return;
} }
capability.SetDHAttrs(cJSON_GetObjectItem(jsonObject, DH_ATTRS.c_str())->valuestring); capability.SetDHAttrs(dhAttrsJson->valuestring);
if (!IsString(jsonObject, DH_SUBTYPE)) { cJSON *dhSubtypeJson = cJSON_GetObjectItem(jsonObject, DH_SUBTYPE.c_str());
if (!IsString(dhSubtypeJson)) {
DHLOGE("DH_SUBTYPE is invalid!"); DHLOGE("DH_SUBTYPE is invalid!");
return; return;
} }
capability.SetDHSubtype(cJSON_GetObjectItem(jsonObject, DH_SUBTYPE.c_str())->valuestring); capability.SetDHSubtype(dhSubtypeJson->valuestring);
} }
} // namespace DistributedHardware } // namespace DistributedHardware
} // namespace OHOS } // namespace OHOS

View File

@ -172,8 +172,8 @@ int32_t CapabilityInfoManager::SyncRemoteCapabilityInfos()
DHLOGE("Get capability ptr by value failed"); DHLOGE("Get capability ptr by value failed");
continue; continue;
} }
const std::string &deviceId = capabilityInfo->GetDeviceId(); const std::string deviceId = capabilityInfo->GetDeviceId();
const std::string &localDeviceId = DHContext::GetInstance().GetDeviceInfo().deviceId; const std::string localDeviceId = DHContext::GetInstance().GetDeviceInfo().deviceId;
if (deviceId.compare(localDeviceId) == 0) { if (deviceId.compare(localDeviceId) == 0) {
DHLOGE("local device info not need sync from db"); DHLOGE("local device info not need sync from db");
continue; continue;

View File

@ -163,59 +163,73 @@ void ToJson(cJSON *jsonObject, const MetaCapabilityInfo &metaCapInfo)
void FromJson(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo) void FromJson(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo)
{ {
if (!IsString(jsonObject, DH_ID)) { cJSON *dhIdJson = cJSON_GetObjectItem(jsonObject, DH_ID.c_str());
if (!IsString(dhIdJson)) {
DHLOGE("DH_ID is invalid!"); DHLOGE("DH_ID is invalid!");
return; return;
} }
metaCapInfo.SetDHId(cJSON_GetObjectItem(jsonObject, DH_ID.c_str())->valuestring); metaCapInfo.SetDHId(dhIdJson->valuestring);
if (!IsString(jsonObject, DEV_ID)) { cJSON *devIdJson = cJSON_GetObjectItem(jsonObject, DEV_ID.c_str());
if (!IsString(devIdJson)) {
DHLOGE("DEV_ID is invalid!"); DHLOGE("DEV_ID is invalid!");
return; return;
} }
metaCapInfo.SetDeviceId(cJSON_GetObjectItem(jsonObject, DEV_ID.c_str())->valuestring); metaCapInfo.SetDeviceId(devIdJson->valuestring);
if (!IsString(jsonObject, DEV_NAME)) { cJSON *devNameJson = cJSON_GetObjectItem(jsonObject, DEV_NAME.c_str());
if (!IsString(devNameJson)) {
DHLOGE("DEV_NAME is invalid!"); DHLOGE("DEV_NAME is invalid!");
return; return;
} }
metaCapInfo.SetDeviceName(cJSON_GetObjectItem(jsonObject, DEV_NAME.c_str())->valuestring); metaCapInfo.SetDeviceName(devNameJson->valuestring);
if (!IsUInt16(jsonObject, DEV_TYPE)) { cJSON *devTypeJson = cJSON_GetObjectItem(jsonObject, DEV_TYPE.c_str());
if (!IsUInt16(devTypeJson)) {
DHLOGE("DEV_TYPE is invalid!"); DHLOGE("DEV_TYPE is invalid!");
return; return;
} }
metaCapInfo.SetDeviceType((uint16_t)cJSON_GetObjectItem(jsonObject, DEV_TYPE.c_str())->valuedouble); metaCapInfo.SetDeviceType(static_cast<uint16_t>(devTypeJson->valueint));
if (!IsUInt32(jsonObject, DH_TYPE)) { cJSON *dhTypeJson = cJSON_GetObjectItem(jsonObject, DH_TYPE.c_str());
if (!IsUInt32(dhTypeJson)) {
DHLOGE("DH_TYPE is invalid!"); DHLOGE("DH_TYPE is invalid!");
return; return;
} }
metaCapInfo.SetDHType((DHType)cJSON_GetObjectItem(jsonObject, DH_TYPE.c_str())->valuedouble); metaCapInfo.SetDHType((DHType)dhTypeJson->valueint);
if (!IsString(jsonObject, DH_ATTRS)) { cJSON *dhAttrsObj = cJSON_GetObjectItem(jsonObject, DH_ATTRS.c_str());
if (!IsString(dhAttrsObj)) {
DHLOGE("DH_ATTRS is invalid!"); DHLOGE("DH_ATTRS is invalid!");
return; return;
} }
metaCapInfo.SetDHAttrs(cJSON_GetObjectItem(jsonObject, DH_ATTRS.c_str())->valuestring); metaCapInfo.SetDHAttrs(dhAttrsObj->valuestring);
if (!IsString(jsonObject, DH_SUBTYPE)) { FromJsonContinue(jsonObject, metaCapInfo);
}
void FromJsonContinue(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo)
{
cJSON *dhSubtypeJson = cJSON_GetObjectItem(jsonObject, DH_SUBTYPE.c_str());
if (!IsString(dhSubtypeJson)) {
DHLOGE("DH_SUBTYPE is invalid!"); DHLOGE("DH_SUBTYPE is invalid!");
return; return;
} }
metaCapInfo.SetDHSubtype(cJSON_GetObjectItem(jsonObject, DH_SUBTYPE.c_str())->valuestring); metaCapInfo.SetDHSubtype(dhSubtypeJson->valuestring);
if (!IsString(jsonObject, DEV_UDID_HASH)) { cJSON *udidHashJson = cJSON_GetObjectItem(jsonObject, DEV_UDID_HASH.c_str());
if (!IsString(udidHashJson)) {
DHLOGE("DEV_UDID_HASH is invalid!"); DHLOGE("DEV_UDID_HASH is invalid!");
return; return;
} }
metaCapInfo.SetUdidHash(cJSON_GetObjectItem(jsonObject, DEV_UDID_HASH.c_str())->valuestring); metaCapInfo.SetUdidHash(udidHashJson->valuestring);
if (!IsString(jsonObject, SINK_VER)) { cJSON *sinkVerJson = cJSON_GetObjectItem(jsonObject, SINK_VER.c_str());
if (!IsString(sinkVerJson)) {
DHLOGE("SINK_VER is invalid!"); DHLOGE("SINK_VER is invalid!");
return; return;
} }
metaCapInfo.SetSinkVersion(cJSON_GetObjectItem(jsonObject, SINK_VER.c_str())->valuestring); metaCapInfo.SetSinkVersion(sinkVerJson->valuestring);
} }
} // namespace DistributedHardware } // namespace DistributedHardware
} // namespace OHOS } // namespace OHOS

View File

@ -208,8 +208,8 @@ int32_t MetaInfoManager::SyncRemoteMetaInfos()
DHLOGE("Get Metainfo ptr by value failed"); DHLOGE("Get Metainfo ptr by value failed");
continue; continue;
} }
const std::string &udidHash = metaCapInfo->GetUdidHash(); const std::string udidHash = metaCapInfo->GetUdidHash();
const std::string &localUdidHash = DHContext::GetInstance().GetDeviceInfo().udidHash; const std::string localUdidHash = DHContext::GetInstance().GetDeviceInfo().udidHash;
if (udidHash.compare(localUdidHash) == 0) { if (udidHash.compare(localUdidHash) == 0) {
DHLOGE("device MetaInfo not need sync from db"); DHLOGE("device MetaInfo not need sync from db");
continue; continue;

View File

@ -101,21 +101,25 @@ void FromJson(const cJSON *jsonObject, CompVersion &compVer)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (IsString(jsonObject, NAME)) { cJSON *nameJson = cJSON_GetObjectItem(jsonObject, NAME.c_str());
compVer.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; if (IsString(nameJson)) {
compVer.name = nameJson->valuestring;
} }
if (IsUInt32(jsonObject, TYPE) && cJSON *typeJson = cJSON_GetObjectItem(jsonObject, TYPE.c_str());
(DHType)cJSON_GetObjectItem(jsonObject, TYPE.c_str())->valuedouble <= DHType::MAX_DH) { if (IsUInt32(typeJson) && (DHType)typeJson->valueint <= DHType::MAX_DH) {
compVer.dhType = (DHType)(cJSON_GetObjectItem(jsonObject, TYPE.c_str())->valuedouble); compVer.dhType = (DHType)typeJson->valueint;
} }
if (IsString(jsonObject, HANDLER)) { cJSON *handlerJson = cJSON_GetObjectItem(jsonObject, HANDLER.c_str());
compVer.handlerVersion = cJSON_GetObjectItem(jsonObject, HANDLER.c_str())->valuestring; if (IsString(handlerJson)) {
compVer.handlerVersion = handlerJson->valuestring;
} }
if (IsString(jsonObject, SOURCE_VER)) { cJSON *sourceVerJson = cJSON_GetObjectItem(jsonObject, SOURCE_VER.c_str());
compVer.sourceVersion = cJSON_GetObjectItem(jsonObject, SOURCE_VER.c_str())->valuestring; if (IsString(sourceVerJson)) {
compVer.sourceVersion = sourceVerJson->valuestring;
} }
if (IsString(jsonObject, SINK_VER)) { cJSON *sinkVerJson = cJSON_GetObjectItem(jsonObject, SINK_VER.c_str());
compVer.sinkVersion = cJSON_GetObjectItem(jsonObject, SINK_VER.c_str())->valuestring; if (IsString(sinkVerJson)) {
compVer.sinkVersion = sinkVerJson->valuestring;
} }
} }
@ -125,12 +129,14 @@ void FromJson(const cJSON *jsonObject, VersionInfo &versionInfo)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (IsString(jsonObject, DEV_ID)) { cJSON *devIdJson = cJSON_GetObjectItem(jsonObject, DEV_ID.c_str());
versionInfo.deviceId = cJSON_GetObjectItem(jsonObject, DEV_ID.c_str())->valuestring; if (IsString(devIdJson)) {
versionInfo.deviceId = devIdJson->valuestring;
} }
if (IsString(jsonObject, DH_VER)) { cJSON *dhVerJson = cJSON_GetObjectItem(jsonObject, DH_VER.c_str());
versionInfo.dhVersion = cJSON_GetObjectItem(jsonObject, DH_VER.c_str())->valuestring; if (IsString(dhVerJson)) {
versionInfo.dhVersion = dhVerJson->valuestring;
} }
const cJSON *compVer = cJSON_GetObjectItem(jsonObject, COMP_VER.c_str()); const cJSON *compVer = cJSON_GetObjectItem(jsonObject, COMP_VER.c_str());

View File

@ -243,8 +243,8 @@ int32_t VersionInfoManager::SyncRemoteVersionInfos()
if (versionInfo.FromJsonString(data) != DH_FWK_SUCCESS) { if (versionInfo.FromJsonString(data) != DH_FWK_SUCCESS) {
continue; continue;
} }
const std::string &deviceId = versionInfo.deviceId; const std::string deviceId = versionInfo.deviceId;
const std::string &localDeviceId = DHContext::GetInstance().GetDeviceInfo().deviceId; const std::string localDeviceId = DHContext::GetInstance().GetDeviceInfo().deviceId;
if (deviceId.compare(localDeviceId) == 0) { if (deviceId.compare(localDeviceId) == 0) {
DHLOGE("Local device info not need sync from db"); DHLOGE("Local device info not need sync from db");
continue; continue;

View File

@ -51,16 +51,15 @@ void FromJson(const cJSON *jsonObject, FullCapsRsp &capsRsp)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
std::string keyNetworkId(CAPS_RSP_NETWORKID_KEY); cJSON *capsRspJson = cJSON_GetObjectItem(jsonObject, CAPS_RSP_NETWORKID_KEY);
if (IsString(jsonObject, keyNetworkId)) { if (IsString(capsRspJson)) {
capsRsp.networkId = cJSON_GetObjectItem(jsonObject, CAPS_RSP_NETWORKID_KEY)->valuestring; capsRsp.networkId = capsRspJson->valuestring;
} }
std::string keyCaps(CAPS_RSP_CAPS_KEY); cJSON *capsRspKeyJson = cJSON_GetObjectItem(jsonObject, CAPS_RSP_CAPS_KEY);
if (IsArray(jsonObject, keyCaps)) { if (IsArray(capsRspKeyJson)) {
cJSON *capsArr = cJSON_GetObjectItem(jsonObject, CAPS_RSP_CAPS_KEY); int32_t arrSize = cJSON_GetArraySize(capsRspKeyJson);
int32_t arrSize = cJSON_GetArraySize(capsArr);
for (int32_t i = 0; i < arrSize; i++) { for (int32_t i = 0; i < arrSize; i++) {
cJSON *cap = cJSON_GetArrayItem(capsArr, i); cJSON *cap = cJSON_GetArrayItem(capsRspKeyJson, i);
std::shared_ptr<CapabilityInfo> capPtr = std::make_shared<CapabilityInfo>(); std::shared_ptr<CapabilityInfo> capPtr = std::make_shared<CapabilityInfo>();
FromJson(cap, *capPtr); FromJson(cap, *capPtr);
capsRsp.caps.push_back(capPtr); capsRsp.caps.push_back(capPtr);
@ -85,13 +84,13 @@ void FromJson(const cJSON *jsonObject, CommMsg &commMsg)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
std::string keyCode(COMM_MSG_CODE_KEY); cJSON *commMsgCodeJson = cJSON_GetObjectItem(jsonObject, COMM_MSG_CODE_KEY);
if (IsInt32(jsonObject, keyCode)) { if (IsInt32(commMsgCodeJson)) {
commMsg.code = cJSON_GetObjectItem(jsonObject, COMM_MSG_CODE_KEY)->valueint; commMsg.code = commMsgCodeJson->valueint;
} }
std::string keyMsg(COMM_MSG_MSG_KEY); cJSON *commMsgeJson = cJSON_GetObjectItem(jsonObject, COMM_MSG_MSG_KEY);
if (IsString(jsonObject, keyMsg)) { if (IsString(commMsgeJson)) {
commMsg.msg = cJSON_GetObjectItem(jsonObject, COMM_MSG_MSG_KEY)->valuestring; commMsg.msg = commMsgeJson->valuestring;
} }
} }

View File

@ -324,13 +324,13 @@ void DHContext::DHFWKIsomerismListener::OnMessage(const DHTopic topic, const std
return; return;
} }
cJSON *eventObj = cJSON_GetObjectItemCaseSensitive(messageJson, ISOMERISM_EVENT_KEY.c_str()); cJSON *eventObj = cJSON_GetObjectItemCaseSensitive(messageJson, ISOMERISM_EVENT_KEY.c_str());
if (eventObj == nullptr || !IsString(messageJson, ISOMERISM_EVENT_KEY)) { if (!IsString(eventObj)) {
cJSON_Delete(messageJson); cJSON_Delete(messageJson);
DHLOGE("OnMessage event invaild"); DHLOGE("OnMessage event invaild");
return; return;
} }
cJSON *devObj = cJSON_GetObjectItemCaseSensitive(messageJson, DEV_ID.c_str()); cJSON *devObj = cJSON_GetObjectItemCaseSensitive(messageJson, DEV_ID.c_str());
if (devObj == nullptr || !IsString(messageJson, DEV_ID)) { if (!IsString(devObj)) {
cJSON_Delete(messageJson); cJSON_Delete(messageJson);
DHLOGE("OnMessage deviceId invaild"); DHLOGE("OnMessage deviceId invaild");
return; return;

View File

@ -931,8 +931,7 @@ HWTEST_F(ComponentLoaderTest, from_json_001, TestSize.Level0)
cJSON_AddStringToObject(Json2, COMP_SOURCE_VERSION.c_str(), "1.0"); cJSON_AddStringToObject(Json2, COMP_SOURCE_VERSION.c_str(), "1.0");
cJSON_AddNumberToObject(Json2, COMP_SOURCE_SA_ID.c_str(), 4801); cJSON_AddNumberToObject(Json2, COMP_SOURCE_SA_ID.c_str(), 4801);
cJSON_AddNumberToObject(Json2, COMP_SINK_LOC.c_str(), 100); cJSON_AddNumberToObject(Json2, COMP_SINK_LOC.c_str(), 100);
from_json(Json2, cfg); EXPECT_NO_FATAL_FAILURE(from_json(Json2, cfg));
EXPECT_EQ(4801, static_cast<int32_t>(cJSON_GetObjectItem(Json2, COMP_SOURCE_SA_ID.c_str())->valuedouble));
cJSON_Delete(Json2); cJSON_Delete(Json2);
} }

View File

@ -47,19 +47,19 @@ std::string GetDeviceIdByUUID(const std::string &uuid);
std::string Sha256(const std::string& string); std::string Sha256(const std::string& string);
bool IsUInt8(const cJSON* jsonObj, const std::string& key); bool IsUInt8(const cJSON* jsonObj);
bool IsUInt16(const cJSON* jsonObj, const std::string& key); bool IsUInt16(const cJSON* jsonObj);
bool IsInt32(const cJSON* jsonObj, const std::string& key); bool IsInt32(const cJSON* jsonObj);
bool IsUInt32(const cJSON* jsonObj, const std::string& key); bool IsUInt32(const cJSON* jsonObj);
bool IsBool(const cJSON* jsonObj, const std::string& key); bool IsBool(const cJSON* jsonObj);
bool IsString(const cJSON* jsonObj, const std::string& key); bool IsString(const cJSON* jsonObj);
bool IsArray(const cJSON* jsonObj, const std::string& key); bool IsArray(const cJSON* jsonObj);
std::string Compress(const std::string& data); std::string Compress(const std::string& data);
std::string Decompress(const std::string& data); std::string Decompress(const std::string& data);

View File

@ -163,64 +163,57 @@ std::string GetLocalNetworkId()
return info.networkId; return info.networkId;
} }
bool IsUInt8(const cJSON* jsonObj, const std::string& key) bool IsUInt8(const cJSON* jsonObj)
{ {
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str()); if (jsonObj == NULL || !cJSON_IsNumber(jsonObj)) {
if (value == NULL || !cJSON_IsNumber(value)) {
return false; return false;
} }
return (value->valuedouble >= 0 && value->valuedouble <= UINT8_MAX); return (jsonObj->valueint >= 0 && jsonObj->valueint <= UINT8_MAX);
} }
bool IsUInt16(const cJSON* jsonObj, const std::string& key) bool IsUInt16(const cJSON* jsonObj)
{ {
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str()); if (jsonObj == NULL || !cJSON_IsNumber(jsonObj)) {
if (value == NULL || !cJSON_IsNumber(value)) {
return false; return false;
} }
return (value->valuedouble >= 0 && value->valuedouble <= UINT16_MAX); return (jsonObj->valueint >= 0 && jsonObj->valueint <= UINT16_MAX);
} }
bool IsInt32(const cJSON* jsonObj, const std::string& key) bool IsInt32(const cJSON* jsonObj)
{ {
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str()); if (jsonObj == NULL || !cJSON_IsNumber(jsonObj)) {
if (value == NULL || !cJSON_IsNumber(value)) {
return false; return false;
} }
return (value->valuedouble >= INT32_MIN && value->valuedouble <= INT32_MAX); return (jsonObj->valueint >= INT32_MIN && jsonObj->valueint <= INT32_MAX);
} }
bool IsUInt32(const cJSON* jsonObj, const std::string& key) bool IsUInt32(const cJSON* jsonObj)
{ {
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str()); if (jsonObj == NULL || !cJSON_IsNumber(jsonObj)) {
if (value == NULL || !cJSON_IsNumber(value)) {
return false; return false;
} }
return (value->valuedouble >= 0 && value->valuedouble <= UINT32_MAX); return (jsonObj->valueint >= 0 && jsonObj->valueint <= UINT32_MAX);
} }
bool IsBool(const cJSON* jsonObj, const std::string& key) bool IsBool(const cJSON* jsonObj)
{ {
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str()); return (jsonObj != NULL && cJSON_IsBool(jsonObj));
return (value != NULL && cJSON_IsBool(value));
} }
bool IsString(const cJSON* jsonObj, const std::string& key) bool IsString(const cJSON* jsonObj)
{ {
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str()); if (jsonObj == NULL || !cJSON_IsString(jsonObj)) {
if (value == NULL || !cJSON_IsString(value)) {
return false; return false;
} }
return (strlen(value->valuestring) > MIN_MESSAGE_LEN && strlen(value->valuestring) <= MAX_MESSAGE_LEN); return (strlen(jsonObj->valuestring) > MIN_MESSAGE_LEN && strlen(jsonObj->valuestring) <= MAX_MESSAGE_LEN);
} }
bool IsArray(const cJSON* jsonObj, const std::string& key) bool IsArray(const cJSON* jsonObj)
{ {
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str()); if (jsonObj == NULL || !cJSON_IsArray(jsonObj)) {
if (value == NULL || !cJSON_IsArray(value)) {
return false; return false;
} }
return ((uint32_t)cJSON_GetArraySize(value) >= 0 && (uint32_t)cJSON_GetArraySize(value) <= MAX_ARR_SIZE); return ((uint32_t)cJSON_GetArraySize(jsonObj) >= 0 && (uint32_t)cJSON_GetArraySize(jsonObj) <= MAX_ARR_SIZE);
} }
std::string Compress(const std::string& data) std::string Compress(const std::string& data)

View File

@ -41,18 +41,16 @@ void FromJson(const cJSON *jsonObject, AudioEncoderIn &audioEncoderIn)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, MIME)) { cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
DHLOGE("AudioEncoderIn MIME is invalid!\n"); if (!IsString(mimeJsonObj)) {
return; DHLOGE("AudioEncoderIn MIME is invalid!");
}
audioEncoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
if (!IsArray(jsonObject, SAMPLE_RATE)) {
DHLOGE("AudioEncoderIn SAMPLE_RATE is invalid\n");
return; return;
} }
audioEncoderIn.mime = mimeJsonObj->valuestring;
cJSON *sampleRate = cJSON_GetObjectItem(jsonObject, SAMPLE_RATE.c_str()); cJSON *sampleRate = cJSON_GetObjectItem(jsonObject, SAMPLE_RATE.c_str());
if (sampleRate == NULL) { if (!IsArray(sampleRate)) {
DHLOGE("AudioEncoderIn SAMPLE_RATE is invalid\n"); DHLOGE("AudioEncoderIn SAMPLE_RATE is invalid!");
return; return;
} }
cJSON *sampleRateItem = nullptr; cJSON *sampleRateItem = nullptr;
@ -69,30 +67,33 @@ void FromJson(const cJSON *jsonObject, AudioEncoderOut &audioEncoderOut)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, MIME)) { cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("AudioEncoderOut MIME is invalid!"); DHLOGE("AudioEncoderOut MIME is invalid!");
return; return;
} }
audioEncoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; audioEncoderOut.mime = mimeJsonObj->valuestring;
if (!IsUInt32(jsonObject, AD_MPEG_VER)) {
cJSON *mpegVerJsonObj = cJSON_GetObjectItem(jsonObject, AD_MPEG_VER.c_str());
if (!IsUInt32(mpegVerJsonObj)) {
DHLOGE("AudioEncoderOut AD_MPEG_VER is invalid!"); DHLOGE("AudioEncoderOut AD_MPEG_VER is invalid!");
return; return;
} }
audioEncoderOut.ad_mpeg_ver = (uint32_t)cJSON_GetObjectItem(jsonObject, AD_MPEG_VER.c_str())->valuedouble; audioEncoderOut.ad_mpeg_ver = static_cast<uint32_t>(mpegVerJsonObj->valuedouble);
if (!IsUInt8(jsonObject, AUDIO_AAC_PROFILE)) { cJSON *aacProfileJsonObj = cJSON_GetObjectItem(jsonObject, AUDIO_AAC_PROFILE.c_str());
if (!IsUInt8(aacProfileJsonObj)) {
DHLOGE("AudioEncoderOut AUDIO_AAC_PROFILE is invalid!"); DHLOGE("AudioEncoderOut AUDIO_AAC_PROFILE is invalid!");
return; return;
} }
audioEncoderOut.aac_profile = audioEncoderOut.aac_profile = (AudioAacProfile)aacProfileJsonObj->valuedouble;
(AudioAacProfile)cJSON_GetObjectItem(jsonObject, AUDIO_AAC_PROFILE.c_str())->valuedouble;
if (!IsUInt8(jsonObject, AUDIO_AAC_STREAM_FORMAT)) { cJSON *aacStreamFmtJsonObj = cJSON_GetObjectItem(jsonObject, AUDIO_AAC_STREAM_FORMAT.c_str());
if (!IsUInt8(aacStreamFmtJsonObj)) {
DHLOGE("AudioEncoderOut AUDIO_AAC_STREAM_FORMAT is invalid!"); DHLOGE("AudioEncoderOut AUDIO_AAC_STREAM_FORMAT is invalid!");
return; return;
} }
audioEncoderOut.aac_stm_fmt = audioEncoderOut.aac_stm_fmt = (AudioAacStreamFormat)aacStreamFmtJsonObj->valuedouble;
(AudioAacStreamFormat)cJSON_GetObjectItem(jsonObject, AUDIO_AAC_STREAM_FORMAT.c_str())->valuedouble;
} }
void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder) void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder)
@ -101,17 +102,18 @@ void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, NAME)) { cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME.c_str());
if (!IsString(nameJsonObj)) {
DHLOGE("AudioEncoder NAME is invalid!"); DHLOGE("AudioEncoder NAME is invalid!");
return; return;
} }
audioEncoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; audioEncoder.name = nameJsonObj->valuestring;
if (!IsArray(jsonObject, INS)) { cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
if (!IsArray(insJson)) {
DHLOGE("AudioEncoder INS is invalid!"); DHLOGE("AudioEncoder INS is invalid!");
return; return;
} }
cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
cJSON *inJson = nullptr; cJSON *inJson = nullptr;
cJSON_ArrayForEach(inJson, insJson) { cJSON_ArrayForEach(inJson, insJson) {
AudioEncoderIn in; AudioEncoderIn in;
@ -119,11 +121,11 @@ void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder)
audioEncoder.ins.push_back(in); audioEncoder.ins.push_back(in);
} }
if (!IsArray(jsonObject, OUTS)) { cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
if (!IsArray(outsJson)) {
DHLOGE("AudioEncoder OUTS is invalid!"); DHLOGE("AudioEncoder OUTS is invalid!");
return; return;
} }
cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
cJSON *outJson = nullptr; cJSON *outJson = nullptr;
cJSON_ArrayForEach(outJson, outsJson) { cJSON_ArrayForEach(outJson, outsJson) {
AudioEncoderOut out; AudioEncoderOut out;
@ -138,17 +140,18 @@ void FromJson(const cJSON *jsonObject, AudioDecoderIn &audioDecoderIn)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, MIME)) { cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("AudioDecoderIn MIME is invalid!"); DHLOGE("AudioDecoderIn MIME is invalid!");
return; return;
} }
audioDecoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; audioDecoderIn.mime = mimeJsonObj->valuestring;
if (!IsArray(jsonObject, AUDIO_CHANNEL_LAYOUT)) { cJSON *channelLayoutJson = cJSON_GetObjectItem(jsonObject, AUDIO_CHANNEL_LAYOUT.c_str());
if (!IsArray(channelLayoutJson)) {
DHLOGE("AudioDecoder AUDIO_CHANNEL_LAYOUT is invalid!"); DHLOGE("AudioDecoder AUDIO_CHANNEL_LAYOUT is invalid!");
return; return;
} }
const cJSON *channelLayoutJson = cJSON_GetObjectItem(jsonObject, AUDIO_CHANNEL_LAYOUT.c_str());
const cJSON *layout = nullptr; const cJSON *layout = nullptr;
cJSON_ArrayForEach(layout, channelLayoutJson) { cJSON_ArrayForEach(layout, channelLayoutJson) {
if (layout && layout->type == cJSON_Number) { if (layout && layout->type == cJSON_Number) {
@ -163,16 +166,18 @@ void FromJson(const cJSON *jsonObject, AudioDecoderOut &audioDecoderOut)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, MIME)) { cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("AudioDecoderOut MIME is invalid!"); DHLOGE("AudioDecoderOut MIME is invalid!");
return; return;
} }
audioDecoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; audioDecoderOut.mime = mimeJsonObj->valuestring;
if (!IsArray(jsonObject, AUDIO_SAMPLE_FORMAT)) {
cJSON *sampleFormatJson = cJSON_GetObjectItem(jsonObject, AUDIO_SAMPLE_FORMAT.c_str());
if (!IsArray(sampleFormatJson)) {
DHLOGE("AudioDecoderOut AUDIO_SAMPLE_FORMAT is invalid!"); DHLOGE("AudioDecoderOut AUDIO_SAMPLE_FORMAT is invalid!");
return; return;
} }
cJSON *sampleFormatJson = cJSON_GetObjectItem(jsonObject, AUDIO_SAMPLE_FORMAT.c_str());
cJSON *format = nullptr; cJSON *format = nullptr;
cJSON_ArrayForEach(format, sampleFormatJson) { cJSON_ArrayForEach(format, sampleFormatJson) {
if (format && format->type == cJSON_Number) { if (format && format->type == cJSON_Number) {
@ -187,28 +192,30 @@ void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, NAME)) { cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME.c_str());
if (!IsString(nameJsonObj)) {
DHLOGE("AudioDecoderOut MIME is invalid!"); DHLOGE("AudioDecoderOut MIME is invalid!");
return; return;
} }
audioDecoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; audioDecoder.name = nameJsonObj->valuestring;
if (!IsArray(jsonObject, INS)) { cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
DHLOGE("AudioDecoder OUTS is invalid!"); if (!IsArray(insJson)) {
DHLOGE("AudioDecoder INS is invalid!");
return; return;
} }
const cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
cJSON *inJson = nullptr; cJSON *inJson = nullptr;
cJSON_ArrayForEach(inJson, insJson) { cJSON_ArrayForEach(inJson, insJson) {
AudioDecoderIn in; AudioDecoderIn in;
FromJson(inJson, in); FromJson(inJson, in);
audioDecoder.ins.push_back(in); audioDecoder.ins.push_back(in);
} }
if (!IsArray(jsonObject, OUTS)) {
cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
if (!IsArray(outsJson)) {
DHLOGE("AudioDecoder OUTS is invalid!"); DHLOGE("AudioDecoder OUTS is invalid!");
return; return;
} }
cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
cJSON *outJson = nullptr; cJSON *outJson = nullptr;
cJSON_ArrayForEach(outJson, outsJson) { cJSON_ArrayForEach(outJson, outsJson) {
AudioDecoderOut out; AudioDecoderOut out;
@ -223,17 +230,18 @@ void FromJson(const cJSON *jsonObject, VideoEncoderIn &videoEncoderIn)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, MIME)) { cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("VideoEncoderIn MIME is invalid!"); DHLOGE("VideoEncoderIn MIME is invalid!");
return; return;
} }
videoEncoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; videoEncoderIn.mime = mimeJsonObj->valuestring;
if (!IsArray(jsonObject, VIDEO_PIXEL_FMT)) { cJSON *videoPixelFmt = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str());
if (!IsArray(videoPixelFmt)) {
DHLOGE("VideoEncoderIn VIDEO_PIXEL_FMT is invalid!"); DHLOGE("VideoEncoderIn VIDEO_PIXEL_FMT is invalid!");
return; return;
} }
cJSON *videoPixelFmt = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str());
cJSON *pixelFmt = nullptr; cJSON *pixelFmt = nullptr;
cJSON_ArrayForEach(pixelFmt, videoPixelFmt) { cJSON_ArrayForEach(pixelFmt, videoPixelFmt) {
if (pixelFmt && pixelFmt->type == cJSON_Number) { if (pixelFmt && pixelFmt->type == cJSON_Number) {
@ -248,11 +256,12 @@ void FromJson(const cJSON *jsonObject, VideoEncoderOut &videoEncoderOut)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, MIME)) { cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
DHLOGE("VideoEncoderIn MIME is invalid!"); if (!IsString(mimeJsonObj)) {
DHLOGE("VideoEncoderOut MIME is invalid!");
return; return;
} }
videoEncoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; videoEncoderOut.mime = mimeJsonObj->valuestring;
} }
void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder) void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder)
@ -261,17 +270,18 @@ void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, NAME)) { cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME.c_str());
if (!IsString(nameJsonObj)) {
DHLOGE("VideoEncoder NAME is invalid!"); DHLOGE("VideoEncoder NAME is invalid!");
return; return;
} }
videoEncoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; videoEncoder.name = nameJsonObj->valuestring;
if (!IsArray(jsonObject, INS)) { cJSON *videoEncoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
if (!IsArray(videoEncoderInsJson)) {
DHLOGE("VideoEncoder INS is invalid!"); DHLOGE("VideoEncoder INS is invalid!");
return; return;
} }
cJSON *videoEncoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
cJSON *inJson = nullptr; cJSON *inJson = nullptr;
cJSON_ArrayForEach(inJson, videoEncoderInsJson) { cJSON_ArrayForEach(inJson, videoEncoderInsJson) {
VideoEncoderIn in; VideoEncoderIn in;
@ -279,11 +289,11 @@ void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder)
videoEncoder.ins.push_back(in); videoEncoder.ins.push_back(in);
} }
if (!IsArray(jsonObject, OUTS)) { cJSON *videoEncoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
if (!IsArray(videoEncoderOutsJson)) {
DHLOGE("VideoEncoder OUTS is invalid!"); DHLOGE("VideoEncoder OUTS is invalid!");
return; return;
} }
cJSON *videoEncoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
cJSON *outJson = nullptr; cJSON *outJson = nullptr;
cJSON_ArrayForEach(outJson, videoEncoderOutsJson) { cJSON_ArrayForEach(outJson, videoEncoderOutsJson) {
VideoEncoderOut out; VideoEncoderOut out;
@ -298,17 +308,18 @@ void FromJson(const cJSON *jsonObject, VideoDecoderIn &videoDecoderIn)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, MIME)) { cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("VideoDecoderIn MIME is invalid!"); DHLOGE("VideoDecoderIn MIME is invalid!");
return; return;
} }
videoDecoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; videoDecoderIn.mime = mimeJsonObj->valuestring;
if (!IsArray(jsonObject, VIDEO_BIT_STREAM_FMT)) { cJSON *videoBitStreamFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_BIT_STREAM_FMT.c_str());
if (!IsArray(videoBitStreamFmtJson)) {
DHLOGE("VideoDecoderIn VIDEO_BIT_STREAM_FMT is invalid!"); DHLOGE("VideoDecoderIn VIDEO_BIT_STREAM_FMT is invalid!");
return; return;
} }
cJSON *videoBitStreamFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_BIT_STREAM_FMT.c_str());
cJSON *fmt = nullptr; cJSON *fmt = nullptr;
cJSON_ArrayForEach(fmt, videoBitStreamFmtJson) { cJSON_ArrayForEach(fmt, videoBitStreamFmtJson) {
if (fmt && fmt->type == cJSON_Number) { if (fmt && fmt->type == cJSON_Number) {
@ -323,17 +334,18 @@ void FromJson(const cJSON *jsonObject, VideoDecoderOut &videoDecoderOut)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, MIME)) { cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("VideoDecoderOut MIME is invalid!"); DHLOGE("VideoDecoderOut MIME is invalid!");
return; return;
} }
videoDecoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; videoDecoderOut.mime = mimeJsonObj->valuestring;
if (!IsArray(jsonObject, VIDEO_PIXEL_FMT)) { cJSON *videoPixelFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str());
if (!IsArray(videoPixelFmtJson)) {
DHLOGE("videoDecoderOut VIDEO_PIXEL_FMT is invalid!"); DHLOGE("videoDecoderOut VIDEO_PIXEL_FMT is invalid!");
return; return;
} }
cJSON *videoPixelFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str());
cJSON *fmt = nullptr; cJSON *fmt = nullptr;
cJSON_ArrayForEach(fmt, videoPixelFmtJson) { cJSON_ArrayForEach(fmt, videoPixelFmtJson) {
if (fmt && fmt->type == cJSON_Number) { if (fmt && fmt->type == cJSON_Number) {
@ -348,17 +360,18 @@ void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder)
DHLOGE("Json pointer is nullptr!"); DHLOGE("Json pointer is nullptr!");
return; return;
} }
if (!IsString(jsonObject, NAME)) { cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME.c_str());
if (!IsString(nameJsonObj)) {
DHLOGE("VideoDecoder NAME is invalid!"); DHLOGE("VideoDecoder NAME is invalid!");
return; return;
} }
videoDecoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; videoDecoder.name = nameJsonObj->valuestring;
if (!IsArray(jsonObject, INS)) { cJSON *videoDecoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
if (!IsArray(videoDecoderInsJson)) {
DHLOGE("VideoDecoder INS is invalid!"); DHLOGE("VideoDecoder INS is invalid!");
return; return;
} }
cJSON *videoDecoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
cJSON *inJson = nullptr; cJSON *inJson = nullptr;
cJSON_ArrayForEach(inJson, videoDecoderInsJson) { cJSON_ArrayForEach(inJson, videoDecoderInsJson) {
VideoDecoderIn in; VideoDecoderIn in;
@ -366,11 +379,11 @@ void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder)
videoDecoder.ins.push_back(in); videoDecoder.ins.push_back(in);
} }
if (!IsArray(jsonObject, OUTS)) { cJSON *videoDecoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
if (!IsArray(videoDecoderOutsJson)) {
DHLOGE("VideoDecoder OUTS is invalid!"); DHLOGE("VideoDecoder OUTS is invalid!");
return; return;
} }
cJSON *videoDecoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
cJSON *outJson = nullptr; cJSON *outJson = nullptr;
cJSON_ArrayForEach(outJson, videoDecoderOutsJson) { cJSON_ArrayForEach(outJson, videoDecoderOutsJson) {
VideoDecoderOut out; VideoDecoderOut out;

View File

@ -149,98 +149,62 @@ HWTEST_F(UtilsToolTest, GetDeviceIdByUUID_002, TestSize.Level0)
HWTEST_F(UtilsToolTest, IsUInt8_001, TestSize.Level0) HWTEST_F(UtilsToolTest, IsUInt8_001, TestSize.Level0)
{ {
cJSON* jsonObj = cJSON_CreateObject();
ASSERT_TRUE(jsonObj != nullptr);
const std::string key = "int8_key";
cJSON_AddStringToObject(jsonObj, key.c_str(), "int8_key_test");
std::string inputKey = "key";
auto ret = IsUInt8(jsonObj, key);
cJSON_Delete(jsonObj);
EXPECT_EQ(false, ret);
cJSON* jsonObj1 = cJSON_CreateObject(); cJSON* jsonObj1 = cJSON_CreateObject();
ASSERT_TRUE(jsonObj1 != nullptr); ASSERT_TRUE(jsonObj1 != nullptr);
cJSON_AddStringToObject(jsonObj1, key.c_str(), "int8_key_test");
ret = IsUInt8(jsonObj1, key);
cJSON_Delete(jsonObj1);
EXPECT_EQ(false, ret);
}
HWTEST_F(UtilsToolTest, IsUInt8_002, TestSize.Level0)
{
cJSON* jsonObj = cJSON_CreateObject();
ASSERT_TRUE(jsonObj != nullptr);
const std::string key = "int8_key"; const std::string key = "int8_key";
const uint8_t keyVaule = 1; cJSON_AddStringToObject(jsonObj1, key.c_str(), "int8_key_test");
cJSON_AddNumberToObject(jsonObj, key.c_str(), keyVaule); cJSON *keyJson1 = cJSON_GetObjectItem(jsonObj1, key.c_str());
auto ret = IsUInt8(jsonObj, key); auto ret = IsUInt8(keyJson1);
cJSON_Delete(jsonObj); EXPECT_EQ(false, ret);
cJSON_Delete(jsonObj1);
cJSON* jsonObj2 = cJSON_CreateObject();
ASSERT_TRUE(jsonObj2 != nullptr);
cJSON_AddNumberToObject(jsonObj2, key.c_str(), 1);
cJSON *keyJson2 = cJSON_GetObjectItem(jsonObj2, key.c_str());
ret = IsUInt8(keyJson2);
EXPECT_EQ(true, ret); EXPECT_EQ(true, ret);
cJSON_Delete(jsonObj2);
} }
HWTEST_F(UtilsToolTest, IsUInt16_001, TestSize.Level0) HWTEST_F(UtilsToolTest, IsUInt16_001, TestSize.Level0)
{ {
cJSON* jsonObj = cJSON_CreateObject();
ASSERT_TRUE(jsonObj != nullptr);
const std::string key = "uint16_key";
cJSON_AddStringToObject(jsonObj, key.c_str(), "uint16_key_test");
std::string inputKey = "key";
auto ret = IsUInt16(jsonObj, key);
cJSON_Delete(jsonObj);
EXPECT_EQ(false, ret);
cJSON* jsonObj1 = cJSON_CreateObject(); cJSON* jsonObj1 = cJSON_CreateObject();
ASSERT_TRUE(jsonObj1 != nullptr); ASSERT_TRUE(jsonObj1 != nullptr);
const std::string key = "uint16_key";
cJSON_AddStringToObject(jsonObj1, key.c_str(), "uint16_key_test"); cJSON_AddStringToObject(jsonObj1, key.c_str(), "uint16_key_test");
ret = IsUInt16(jsonObj1, key); cJSON *keyJson1 = cJSON_GetObjectItem(jsonObj1, key.c_str());
auto ret = IsUInt16(keyJson1);
cJSON_Delete(jsonObj1); cJSON_Delete(jsonObj1);
EXPECT_EQ(false, ret); EXPECT_EQ(false, ret);
}
HWTEST_F(UtilsToolTest, IsUInt16_002, TestSize.Level0) cJSON* jsonObj2 = cJSON_CreateObject();
{ ASSERT_TRUE(jsonObj2 != nullptr);
cJSON* jsonObj = cJSON_CreateObject(); cJSON_AddNumberToObject(jsonObj2, key.c_str(), 1);
ASSERT_TRUE(jsonObj != nullptr); cJSON *keyJson2 = cJSON_GetObjectItem(jsonObj2, key.c_str());
const std::string key = "uint16_key"; ret = IsUInt16(keyJson2);
const uint16_t keyVaule = 1;
cJSON_AddNumberToObject(jsonObj, key.c_str(), keyVaule);
auto ret = IsUInt16(jsonObj, key);
cJSON_Delete(jsonObj);
EXPECT_EQ(true, ret); EXPECT_EQ(true, ret);
cJSON_Delete(jsonObj2);
} }
HWTEST_F(UtilsToolTest, IsUInt32_001, TestSize.Level0) HWTEST_F(UtilsToolTest, IsUInt32_001, TestSize.Level0)
{ {
cJSON* jsonObj = cJSON_CreateObject();
ASSERT_TRUE(jsonObj != nullptr);
const std::string key = "uint32_key";
cJSON_AddStringToObject(jsonObj, key.c_str(), "uint32_key_test");
std::string inputKey = "key";
auto ret = IsUInt32(jsonObj, key);
cJSON_Delete(jsonObj);
EXPECT_EQ(false, ret);
cJSON* jsonObj1 = cJSON_CreateObject(); cJSON* jsonObj1 = cJSON_CreateObject();
ASSERT_TRUE(jsonObj1 != nullptr); ASSERT_TRUE(jsonObj1 != nullptr);
cJSON_AddStringToObject(jsonObj1, key.c_str(), "uint32_key_test");
ret = IsUInt32(jsonObj1, key);
cJSON_Delete(jsonObj1);
EXPECT_EQ(false, ret);
}
HWTEST_F(UtilsToolTest, IsUInt32_002, TestSize.Level0)
{
cJSON* jsonObj = cJSON_CreateObject();
ASSERT_TRUE(jsonObj != nullptr);
const std::string key = "uint32_key"; const std::string key = "uint32_key";
const uint32_t keyVaule = 1; cJSON_AddStringToObject(jsonObj1, key.c_str(), "uint32_key_test");
cJSON_AddNumberToObject(jsonObj, key.c_str(), keyVaule); cJSON *keyJson1 = cJSON_GetObjectItem(jsonObj1, key.c_str());
auto ret = IsUInt32(jsonObj, key); auto ret = IsUInt32(keyJson1);
cJSON_Delete(jsonObj); EXPECT_EQ(false, ret);
cJSON_Delete(jsonObj1);
cJSON* jsonObj2 = cJSON_CreateObject();
ASSERT_TRUE(jsonObj2 != nullptr);
cJSON_AddNumberToObject(jsonObj2, key.c_str(), 1);
cJSON *keyJson2 = cJSON_GetObjectItem(jsonObj2, key.c_str());
ret = IsUInt32(keyJson2);
EXPECT_EQ(true, ret); EXPECT_EQ(true, ret);
cJSON_Delete(jsonObj2);
} }
HWTEST_F(UtilsToolTest, GetSysPara_001, TestSize.Level0) HWTEST_F(UtilsToolTest, GetSysPara_001, TestSize.Level0)