1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 #include "wrt-upgrade/wrt-upgrade-info.h"
7 #include "common/logger.h"
12 const std::string kSectionPrefix = "_SECT_";
13 const std::string kSectionSuffix = "_SECT_";
15 const std::string kDBPublicSection = "public";
16 const std::string kDBPrivateSection = "private";
18 const std::string kGeolocationPermissionPrefix = "__WRT_GEOPERM_";
19 const std::string kNotificationPermissionPrefix = "__WRT_NOTIPERM_";
20 const std::string kQuotaPermissionPrefix = "__WRT_QUOTAPERM_";
21 const std::string kCertificateAllowPrefix = "__WRT_CERTIPERM_";
22 const std::string kUsermediaPermissionPrefix = "__WRT_USERMEDIAPERM_";
24 const std::string kValueAllow = "allowed";
25 const std::string kValueDenied = "denied";
26 const std::string kValueUnknown = "unknown";
28 const std::string kAppDirectoryPrefix = "/opt/usr/home/owner/apps_rw/";
29 const std::string kAppSecurityOriginDBFile = "/data/.security_origin.db";
30 const std::string kAppCertificateDBFile = "/data/.certificate.db";
33 FEATURE_GEOLOCATION = 0,
34 FEATURE_WEB_NOTIFICATION,
36 FEATURE_FULLSCREEN_MODE,
39 FEATURE_AUDIO_RECORDER
52 PreferenceInfo::PreferenceInfo(std::string key, std::string value) {
53 m_section_ = kDBPublicSection;
57 SecurityOriginInfo::SecurityOriginInfo(
63 m_section_ = kDBPrivateSection;
64 m_key_ = translateKey(feature, scheme, host, port);
65 m_value_ = translateValue(result);
67 std::string SecurityOriginInfo::translateKey(
76 case FEATURE_GEOLOCATION :
77 key += kGeolocationPermissionPrefix;
79 case FEATURE_WEB_NOTIFICATION :
80 key += kNotificationPermissionPrefix;
82 case FEATURE_USER_MEDIA :
83 key += kUsermediaPermissionPrefix;
85 case FEATURE_WEB_DATABASE :
86 key += kQuotaPermissionPrefix;
96 key += std::to_string(port);
100 std::string SecurityOriginInfo::translateValue(int result) {
101 std::string value = "";
104 case RESULT_ALLOW_ALWAYS :
107 case RESULT_DENY_ALWAYS :
108 value = kValueDenied;
110 case RESULT_UNKNOWN :
111 case RESULT_ALLOW_ONCE :
112 case RESULT_DENY_ONCE :
114 value = kValueUnknown;
119 CertificateInfo::CertificateInfo(
122 m_section_ = kDBPrivateSection;
123 m_key_ = translateKey(pem);
124 m_value_ = translateValue(result);
126 std::string CertificateInfo::translateKey(std::string pem) {
127 std::string key = "";
128 key = kCertificateAllowPrefix + pem;
131 std::string CertificateInfo::translateValue(int result) {
132 std::string value = "";
135 case RESULT_ALLOW_ALWAYS :
138 case RESULT_DENY_ALWAYS :
139 value = kValueDenied;
141 case RESULT_UNKNOWN :
142 case RESULT_ALLOW_ONCE :
143 case RESULT_DENY_ONCE :
145 value = kValueUnknown;
150 WrtUpgradeInfo::WrtUpgradeInfo(std::string appid) {
152 pkg_id_ = appid.substr(0, appid.find_first_of('.'));
153 app_dir_ = kAppDirectoryPrefix + pkg_id_;
155 void WrtUpgradeInfo::addPreferenceInfo(PreferenceInfo preference) {
156 preference_info_list_.push_back(preference);
158 void WrtUpgradeInfo::addSecurityOriginInfo(SecurityOriginInfo security_origin) {
159 security_origin_info_list_.push_back(security_origin);
161 void WrtUpgradeInfo::addCertificateInfo(CertificateInfo certificate) {
162 certificate_info_list.push_back(certificate);
165 std::string WrtUpgradeInfo::getSecurityOriginDB() {
166 return app_dir_ + kAppSecurityOriginDBFile;
168 std::string WrtUpgradeInfo::getCertificateDB() {
169 return app_dir_ + kAppCertificateDBFile;
171 } // namespace upgrade