e15d3437f2bf1513d8900c90008106c89e864e10
[framework/security/security-server.git] / ace / include / ace / ConfigurationManager.h
1 /*
2  * Copyright (c) 2011 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 #ifndef _CONFIGURATIONMANAGER_H_
17 #define _CONFIGURATIONMANAGER_H_
18
19 #include <list>
20 #include <string.h>
21 #include <string>
22 #include "Constants.h"
23 #include <iostream>
24 #include <dpl/log/log.h>
25
26 enum class PolicyType {
27     WAC2_0,
28     Tizen
29 };
30
31 #define POLICY_NAME_WAC2_0                  "WAC2.0"
32 #define POLICY_NAME_TIZEN                   "Tizen"
33 #define POLICY_WIDGET_TYPE_ATTRIBUTE_NAME   "WrtSecurity.WidgetPolicyType"
34
35 #pragma message "ATTR_ACTIVE_POLICY BAD_CAST, PARSER_ERROR, PARSER_SUCCESS\
36  macros are DEPRECATED"
37 #define ATTR_ACTIVE_POLICY BAD_CAST("active") // !! DEPRECATED !!
38 #define PARSER_ERROR     1 // !! DEPRECATED !!
39 #define PARSER_SUCCESS   0 // !! DEPRECATED !!
40
41 class ConfigurationManager
42 {
43   public:
44     // !! DEPRECATED !!
45     enum ConfigurationManagerResult
46     {
47         CM_OPERATION_SUCCESS = 0,
48         CM_GENERAL_ERROR = -1,
49         CM_FILE_EXISTS = -2,
50         CM_REMOVE_ERROR = -3,
51         CM_REMOVE_CURRENT = -4,
52         CM_REMOVE_NOT_EXISTING = -5
53     };
54
55     // !! DEPRECATED !!
56     std::string getCurrentPolicyFile(void) const;
57     std::string getFullPathToCurrentPolicyFile(void) const;
58     std::string getFullPathToCurrentPolicyXMLSchema(void) const;
59     int addPolicyFile(const std::string & filePath);
60     int removePolicyFile(const std::string& fileName);
61     int changeCurrentPolicyFile(const std::string& filePath);
62     std::string extractFilename(const std::string& path) const;
63
64     /**
65      * ACE policy file path getter
66      * @return Full path to policy file
67      */
68     std::string getFullPathToPolicyFile(PolicyType policy) const;
69
70     /**
71      * ACE policy dtd file path getter
72      * @return Full path to ACE current policy file
73      */
74     std::string getFullPathToPolicyXMLSchema(void) const;
75
76     /**
77      * ACE policy storage path getter
78      * @return Full path to ACE policy file storage
79      */
80     std::string getStoragePath(void) const;
81
82     /**
83      * Method to obtain instance of configuration manager
84      * @return retuns pointer to configuration manager or NULL in case of error
85      */
86     static ConfigurationManager * getInstance()
87     {
88         if (!instance) {
89             instance = new ConfigurationManager();
90         }
91         return instance;
92     }
93
94   protected:
95
96     // !! DEPRECATED !!
97     int parse(const std::string&);
98     bool copyFile(FILE*, FILE*, int lenght = 1024) const;
99     bool checkIfFileExistst(const std::string&) const;
100     const std::list<std::string> & getPolicyFiles() const;
101     const std::string & getConfigFile() const;
102
103     ConfigurationManager()
104     {
105     }
106     virtual ~ConfigurationManager()
107     {
108     }
109
110 private:
111
112     static ConfigurationManager * instance;
113 };
114
115 #endif
116