[SSM] Fix issue about initializing SSM with invalid parameter (IOT-260)
authorMinji Park <minjii.park@samsung.com>
Fri, 23 Jan 2015 02:05:32 +0000 (11:05 +0900)
committerUze Choi <uzchoi@samsung.com>
Fri, 23 Jan 2015 04:16:00 +0000 (04:16 +0000)
Modify SoftSensorManager to return error code when initialized with invalid parameter

Change-Id: Ia0a54cd6e71321cbe2b4fd18352a2a609c20fabd
Signed-off-by: Minji Park <minjii.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/229
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/soft-sensor-manager/SSMCore/src/SSMInterface/SoftSensorManager.cpp

index aaf04a7..4b9c023 100644 (file)
@@ -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));