From ef380650f9c35120091c36b44c974c3d3712e91d Mon Sep 17 00:00:00 2001 From: Minji Park Date: Fri, 23 Jan 2015 11:05:32 +0900 Subject: [PATCH] [SSM] Fix issue about initializing SSM with invalid parameter (IOT-260) Modify SoftSensorManager to return error code when initialized with invalid parameter Change-Id: Ia0a54cd6e71321cbe2b4fd18352a2a609c20fabd Signed-off-by: Minji Park Reviewed-on: https://gerrit.iotivity.org/gerrit/229 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../SSMCore/src/SSMInterface/SoftSensorManager.cpp | 100 ++++++++++++--------- 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/service/soft-sensor-manager/SSMCore/src/SSMInterface/SoftSensorManager.cpp b/service/soft-sensor-manager/SSMCore/src/SSMInterface/SoftSensorManager.cpp index aaf04a7..4b9c023 100644 --- a/service/soft-sensor-manager/SSMCore/src/SSMInterface/SoftSensorManager.cpp +++ b/service/soft-sensor-manager/SSMCore/src/SSMInterface/SoftSensorManager.cpp @@ -58,65 +58,77 @@ SSMRESULT CSoftSensorManager::initializeCore(IN std::string xmlDescription) std::string pathSoftSensors; std::string pathDescription; - xmlDoc.parse<0>((char *)xmlDescription.c_str()); + try + { + xmlDoc.parse<0>((char *)xmlDescription.c_str()); - root = xmlDoc.first_node(); + root = xmlDoc.first_node(); - strKey = root->name(); + if (!root) + { + throw rapidxml::parse_error("No Root Element", 0); + } - if (strKey != "SSMCore") - { - return SSM_E_FAIL; - } + strKey = root->name(); - for (itemSSMCore = root->first_node(); itemSSMCore; itemSSMCore = itemSSMCore->next_sibling()) - { - strKey = itemSSMCore->name(); + if (strKey != "SSMCore") + { + throw rapidxml::parse_error("Invalid root tag name", 0); + } - if (strKey == "Device") + for (itemSSMCore = root->first_node(); itemSSMCore; itemSSMCore = itemSSMCore->next_sibling()) { - for (itemDevice = itemSSMCore->first_node(); itemDevice; itemDevice = itemDevice->next_sibling()) - { - strKey = itemDevice->name(); + strKey = itemSSMCore->name(); - if (strKey == "Name") - { - name = itemDevice->value(); - } - else if (strKey == "Type") - { - type = itemDevice->value(); - } - else + if (strKey == "Device") + { + for (itemDevice = itemSSMCore->first_node(); itemDevice; itemDevice = itemDevice->next_sibling()) { - ;/*NULL*/ + strKey = itemDevice->name(); + + if (strKey == "Name") + { + name = itemDevice->value(); + } + else if (strKey == "Type") + { + type = itemDevice->value(); + } + else + { + ;/*NULL*/ + } } } - } - else if (strKey == "Config") - { - for (itemDevice = itemSSMCore->first_node(); itemDevice; itemDevice = itemDevice->next_sibling()) + else if (strKey == "Config") { - strKey = itemDevice->name(); - - if (strKey == "SoftSensorRepository") - { - pathSoftSensors = itemDevice->value(); - } - else if (strKey == "SoftSensorDescription") - { - pathDescription = itemDevice->value(); - } - else + for (itemDevice = itemSSMCore->first_node(); itemDevice; itemDevice = itemDevice->next_sibling()) { - ;/*NULL*/ + strKey = itemDevice->name(); + + if (strKey == "SoftSensorRepository") + { + pathSoftSensors = itemDevice->value(); + } + else if (strKey == "SoftSensorDescription") + { + pathDescription = itemDevice->value(); + } + else + { + ;/*NULL*/ + } } } + else + { + ;/*NULL*/ + } } - else - { - ;/*NULL*/ - } + } + catch (rapidxml::parse_error &e) + { + SSM_CLEANUP_ASSERT(SSM_E_INVALIDXML); } SSM_CLEANUP_ASSERT(CreateGlobalInstance(OID_ISensingEngine, (IBase **)&m_pSensingEngine)); -- 2.7.4