tizen 2.3 release
[framework/web/wearable/wrt-security.git] / ace / engine / ConfigurationManager.cpp
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 #include <dpl/assert.h>
17 #include <dpl/log/log.h>
18 #include <fcntl.h>
19 #include <errno.h>
20 #include <error.h>
21 #include <malloc.h>
22 #include <sys/stat.h>
23 #include <ace/ConfigurationManager.h>
24 #include <unistd.h>
25
26 using namespace std;
27
28 namespace {
29 const string currentXMLSchema("bondixml.xsd");
30 }
31
32 ConfigurationManager * ConfigurationManager::instance = NULL;
33
34
35 string ConfigurationManager::getCurrentPolicyFile(void) const
36 {
37     LogError("ConfigurationManager::getCurrentPolicyFile is DEPRECATED");
38     return "";
39 }
40
41 string ConfigurationManager::getFullPathToCurrentPolicyFile(void) const
42 {
43     LogError("ConfigurationManager::getFullPathToCurrentPolicyFile"
44              "is DEPRECATED");
45     return "";
46 }
47
48 string ConfigurationManager::getFullPathToCurrentPolicyXMLSchema(void) const
49 {
50     LogError("ConfigurationManager::getFullPathToCurrentPolicyXMLSchema"
51              "is DEPRECATED");
52     return "";
53 }
54
55 int ConfigurationManager::addPolicyFile(const string &)
56 {
57     LogError("ConfigurationManager::addPolicyFile is DEPRECATED");
58     return CM_GENERAL_ERROR;
59 }
60
61 int ConfigurationManager::removePolicyFile(const string&)
62 {
63     LogError("ConfigurationManager::removePolicyFile is DEPRECATED");
64     return CM_GENERAL_ERROR;
65 }
66
67 int ConfigurationManager::changeCurrentPolicyFile(const string&)
68 {
69     LogError("ConfigurationManager::changeCurrentPolicyFile is DEPRECATED");
70     return CM_GENERAL_ERROR;
71 }
72
73 string ConfigurationManager::extractFilename(const string&) const
74 {
75     LogError("ConfigurationManager::extractFilename is DEPRECATED");
76     return "";
77 }
78
79
80 int ConfigurationManager::parse(const string&)
81 {
82     LogError("ConfigurationManager::parse is DEPRECATED");
83     return CM_GENERAL_ERROR;
84 }
85
86 bool ConfigurationManager::copyFile(FILE*, FILE*, int) const
87 {
88     LogError("ConfigurationManager::copyFile is DEPRECATED");
89     return false;
90 }
91
92 bool ConfigurationManager::checkIfFileExistst(const string&) const
93 {
94     LogError("ConfigurationManager::checkIfFileExistst is DEPRECATED");
95     return false;
96 }
97
98 const list<string> & ConfigurationManager::getPolicyFiles() const
99 {
100     LogError("ConfigurationManager::getPolicyFiles is DEPRECATED");
101     static list<string> aList;
102     return aList;
103 }
104
105 const string & ConfigurationManager::getConfigFile() const
106 {
107     LogError("ConfigurationManager::getConfigFile is DEPRECATED");
108     static string returnString("");
109     return returnString;
110 }
111
112 string ConfigurationManager::getFullPathToPolicyFile(PolicyType policy) const
113 {
114     string cscStoragePath = getCscStoragePath();
115     string storagePath = getStoragePath();
116     string fileName;
117
118     switch (policy) {
119     case PolicyType::WAC2_0: {
120         fileName = ACE_WAC_POLICY_FILE_NAME;
121         break; }
122     case PolicyType::Tizen: {
123         fileName = ACE_TIZEN_POLICY_FILE_NAME;
124         break; }
125     default: {
126         LogError("Invalid policy file requested");
127         return ""; }
128     }
129     string cscPolicyFilePath = cscStoragePath + fileName;
130     if ( access(cscPolicyFilePath.c_str(), R_OK) == -1)
131         return storagePath + fileName;
132
133     return cscPolicyFilePath;
134 }
135
136 string ConfigurationManager::getFullPathToPolicyXMLSchema() const
137 {
138     string storagePath = getStoragePath();
139     if (*(storagePath.rbegin()) == '/')
140     {
141         return storagePath + currentXMLSchema;
142     }
143     return storagePath + "/" + currentXMLSchema;
144 }
145
146 string ConfigurationManager::getStoragePath(void) const
147 {
148     return ACE_MAIN_STORAGE;
149 }
150
151 string ConfigurationManager::getCscStoragePath(void) const
152 {
153     return ACE_CSC_STORAGE;
154 }