CKMLogic will not depend from InitialValues. 91/52491/3
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Mon, 23 Nov 2015 15:59:34 +0000 (16:59 +0100)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Tue, 24 Nov 2015 14:39:41 +0000 (15:39 +0100)
Change-Id: I91ce4dcadd49ae813c1ca59418ea8f730110718b

src/CMakeLists.txt
src/manager/initial-values/initial-value-loader.cpp [new file with mode: 0644]
src/manager/initial-values/initial-value-loader.h [new file with mode: 0644]
src/manager/service/ckm-logic.cpp
src/manager/service/ckm-service.cpp

index 8faf006..fa31106 100644 (file)
@@ -62,6 +62,7 @@ SET(KEY_MANAGER_SOURCES
     ${KEY_MANAGER_PATH}/initial-values/InitialValuesFile.cpp
     ${KEY_MANAGER_PATH}/initial-values/NoCharactersHandler.cpp
     ${KEY_MANAGER_PATH}/initial-values/xml-utils.cpp
+    ${KEY_MANAGER_PATH}/initial-values/initial-value-loader.cpp
     ${KEY_MANAGER_PATH}/dpl/core/src/assert.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/sql_connection.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/naive_synchronization_object.cpp
diff --git a/src/manager/initial-values/initial-value-loader.cpp b/src/manager/initial-values/initial-value-loader.cpp
new file mode 100644 (file)
index 0000000..01bb79c
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ *
+ *
+ * @file        initial-value-loader.cpp
+ * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version     1.0
+ * @brief
+ */
+#include <dirent.h>
+
+#include <initial-value-loader.h>
+
+#include <ckm-logic.h>
+#include <InitialValuesFile.h>
+
+namespace {
+const char * const INIT_VALUES_DIR          = "/opt/data/ckm/initial_values/";
+const char * const INIT_VALUES_XSD          = "/usr/share/ckm/initial_values.xsd";
+const char * const INIT_VALUES_FILE_SUFFIX  = ".xml";
+} // namespace anonymous
+
+namespace CKM {
+namespace InitialValues {
+
+void LoadFiles(CKMLogic &logic) {
+    try {
+        std::vector<std::string> filesToParse;
+        DIR *dp = opendir(INIT_VALUES_DIR);
+        if(dp)
+        {
+            struct dirent *entry;
+            while ((entry = readdir(dp)))
+            {
+                std::string filename = std::string(entry->d_name);
+
+                // check if XML file
+                std::string lowercaseFilename = filename;
+                std::transform(lowercaseFilename.begin(), lowercaseFilename.end(), lowercaseFilename.begin(), ::tolower);
+                if(lowercaseFilename.find(INIT_VALUES_FILE_SUFFIX) == std::string::npos)
+                    continue;
+
+                filesToParse.push_back(std::string(INIT_VALUES_DIR) + filename);
+            }
+            closedir(dp);
+        }
+
+        // parse
+        for(const auto & file : filesToParse)
+        {
+            InitialValues::InitialValuesFile xmlFile(file.c_str(), logic);
+            int rc = xmlFile.Validate(INIT_VALUES_XSD);
+            if(rc == XML::Parser::PARSE_SUCCESS)
+            {
+                rc = xmlFile.Parse();
+                if(rc != XML::Parser::PARSE_SUCCESS)
+                    LogError("invalid initial values file: " << file << ", parsing code: " << rc);
+            }
+            else
+                LogError("invalid initial values file: " << file << ", validation code: " << rc);
+            unlink(file.c_str());
+        }
+    } catch (...) {
+        LogError("The implementation of exception handling in xml parser is broken!");
+    }
+}
+
+} // namespace InitialValues
+} // namespace CKM
+
diff --git a/src/manager/initial-values/initial-value-loader.h b/src/manager/initial-values/initial-value-loader.h
new file mode 100644 (file)
index 0000000..a558e43
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ *
+ *
+ * @file        ckm-logic.cpp
+ * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version     1.0
+ * @brief
+ */
+#pragma once
+
+namespace CKM {
+
+// forward declaration
+class CKMLogic;
+
+namespace InitialValues {
+
+void LoadFiles(CKMLogic &);
+
+} // namespace InitialValues
+} // namespace CKM
+
index 2dc20a7..8a5e396 100644 (file)
 #include <key-aes-impl.h>
 #include <certificate-config.h>
 #include <certificate-store.h>
-#include <dirent.h>
 #include <algorithm>
-#include <InitialValuesFile.h>
 #include <sw-backend/store.h>
 #include <generic-backend/exception.h>
 
 namespace {
 const char * const CERT_SYSTEM_DIR          = "/etc/ssl/certs";
-const char * const INIT_VALUES_DIR          = "/opt/data/ckm/initial_values/";
-const char * const INIT_VALUES_XSD          = "/usr/share/ckm/initial_values.xsd";
-const char * const INIT_VALUES_FILE_SUFFIX  = ".xml";
 const char * const SYSTEM_DB_PASSWD         = "cAtRugU7";
 
 bool isLabelValid(const CKM::Label &label) {
@@ -66,43 +61,6 @@ CKMLogic::CKMLogic()
     CertificateConfig::addSystemCertificateDir(CERT_SYSTEM_DIR);
 
     m_accessControl.updateCCMode();
-
-    // make initial file list
-    std::vector<std::string> filesToParse;
-    DIR *dp = opendir(INIT_VALUES_DIR);
-    if(dp)
-    {
-        struct dirent *entry;
-        while ((entry = readdir(dp)))
-        {
-            std::string filename = std::string(entry->d_name);
-
-            // check if XML file
-            std::string lowercaseFilename = filename;
-            std::transform(lowercaseFilename.begin(), lowercaseFilename.end(), lowercaseFilename.begin(), ::tolower);
-            if(lowercaseFilename.find(INIT_VALUES_FILE_SUFFIX) == std::string::npos)
-                continue;
-
-            filesToParse.push_back(std::string(INIT_VALUES_DIR) + filename);
-        }
-        closedir(dp);
-    }
-
-    // parse
-    for(const auto & file : filesToParse)
-    {
-        InitialValues::InitialValuesFile xmlFile(file.c_str(), *this);
-        int rc = xmlFile.Validate(INIT_VALUES_XSD);
-        if(rc == XML::Parser::PARSE_SUCCESS)
-        {
-            rc = xmlFile.Parse();
-            if(rc != XML::Parser::PARSE_SUCCESS)
-                LogError("invalid initial values file: " << file << ", parsing code: " << rc);
-        }
-        else
-            LogError("invalid initial values file: " << file << ", validation code: " << rc);
-        unlink(file.c_str());
-    }
 }
 
 CKMLogic::~CKMLogic(){}
index 47fef2b..a830cf8 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <ckm-service.h>
 #include <ckm-logic.h>
+#include <initial-value-loader.h>
 
 namespace {
 const CKM::InterfaceID SOCKET_ID_CONTROL = 0;
@@ -37,7 +38,9 @@ namespace CKM {
 
 CKMService::CKMService()
   : m_logic(new CKMLogic)
-{}
+{
+    InitialValues::LoadFiles(*m_logic);
+}
 
 CKMService::~CKMService() {
     delete m_logic;