Add initial values support - values to feed the shared database on first startup.
[platform/core/security/key-manager.git] / src / manager / initial-values / InitialValuesFile.h
1 /*
2  *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  *
16  *
17  * @file        InitialValuesFile.h
18  * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
19  * @version     1.0
20  * @brief       InitialValuesFile class.
21  */
22
23 #ifndef INITIALVALUESFILE_H_
24 #define INITIALVALUESFILE_H_
25
26 #include <parser.h>
27 #include <InitialValueHandler.h>
28 #include <ckm-logic.h>
29
30 namespace CKM {
31 namespace InitialValues {
32
33 class InitialValuesFile
34 {
35 public:
36     InitialValuesFile(const std::string &XML_filename,
37                       CKMLogic & db_logic);
38
39     int Validate(const std::string &XSD_file);
40     int Parse();
41
42 protected:
43     enum ObjectType {
44         KEY,
45         CERT,
46         DATA
47     };
48
49     XML::Parser::ElementHandlerPtr GetObjectHandler(ObjectType type);
50     void ReleaseObjectHandler(ObjectType type);
51
52     XML::Parser::ElementHandlerPtr GetBufferHandler(EncodingType type);
53     void ReleaseBufferHandler(EncodingType type);
54
55     XML::Parser::ElementHandlerPtr GetPermissionHandler();
56     void ReleasePermissionHandler();
57 private:
58     std::string m_filename;
59     XML::Parser m_parser;
60     InitialValueHandler::InitialValueHandlerPtr m_currentHandler;
61     CKMLogic & m_db_logic;
62
63     class HeaderHandler : public XML::Parser::ElementHandler
64     {
65     public:
66         explicit HeaderHandler(InitialValuesFile & parent);
67         virtual void Start(const XML::Parser::Attributes & attr);
68         virtual void Characters(const std::string &) {};
69         virtual void End() {};
70
71         bool isCorrectVersion() const;
72
73     private:
74         int m_version;
75         InitialValuesFile & m_parent;
76     };
77     typedef std::shared_ptr<HeaderHandler> HeaderHandlerPtr;
78     HeaderHandlerPtr m_header;
79
80     void registerElementListeners();
81     static void Error(const XML::Parser::ErrorType errorType,
82                       const std::string & logMsg);
83
84 };
85
86 }
87 }
88 #endif /* INITIALVALUESFILE_H_ */