+++ /dev/null
-// Copyright (c) 2013 Intel Corporation. All rights reserved.
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "wrt-upgrade/wrt-upgrade-info.h"
-#include "common/logger.h"
-
-// #include <sstream>
-
-namespace {
-const std::string kSectionPrefix = "_SECT_";
-const std::string kSectionSuffix = "_SECT_";
-
-const std::string kDBPublicSection = "public";
-const std::string kDBPrivateSection = "private";
-
-const std::string kGeolocationPermissionPrefix = "__WRT_GEOPERM_";
-const std::string kNotificationPermissionPrefix = "__WRT_NOTIPERM_";
-const std::string kQuotaPermissionPrefix = "__WRT_QUOTAPERM_";
-const std::string kCertificateAllowPrefix = "__WRT_CERTIPERM_";
-const std::string kUsermediaPermissionPrefix = "__WRT_USERMEDIAPERM_";
-
-const std::string kValueAllow = "allowed";
-const std::string kValueDenied = "denied";
-const std::string kValueUnknown = "unknown";
-
-const std::string kAppDirectoryPrefix = "/opt/usr/home/owner/apps_rw/";
-const std::string kAppSecurityOriginDBFile = "/data/.security_origin.db";
-const std::string kAppCertificateDBFile = "/data/.certificate.db";
-
-enum {
- FEATURE_GEOLOCATION = 0,
- FEATURE_WEB_NOTIFICATION,
- FEATURE_USER_MEDIA,
- FEATURE_FULLSCREEN_MODE,
- FEATURE_WEB_DATABASE,
- FEATURE_CAMERA,
- FEATURE_AUDIO_RECORDER
-};
-enum {
- RESULT_UNKNOWN = 0,
- RESULT_ALLOW_ONCE,
- RESULT_DENY_ONCE,
- RESULT_ALLOW_ALWAYS,
- RESULT_DENY_ALWAYS
-};
-} // namespace
-
-namespace upgrade {
-
-PreferenceInfo::PreferenceInfo(std::string key, std::string value) {
- m_section_ = kDBPublicSection;
- m_key_ = key;
- m_value_ = value;
-}
-SecurityOriginInfo::SecurityOriginInfo(
- int feature,
- std::string scheme,
- std::string host,
- int port,
- int result) {
- m_section_ = kDBPrivateSection;
- m_key_ = translateKey(feature, scheme, host, port);
- m_value_ = translateValue(result);
-}
-std::string SecurityOriginInfo::translateKey(
- int feature,
- std::string scheme,
- std::string host,
- int port) {
-
- std::string key = "";
-
- switch (feature) {
- case FEATURE_GEOLOCATION :
- key += kGeolocationPermissionPrefix;
- break;
- case FEATURE_WEB_NOTIFICATION :
- key += kNotificationPermissionPrefix;
- break;
- case FEATURE_USER_MEDIA :
- key += kUsermediaPermissionPrefix;
- break;
- case FEATURE_WEB_DATABASE :
- key += kQuotaPermissionPrefix;
- break;
- default :
- break;
- }
-
- key += scheme;
- key += "://";
- key += host;
- key += ":";
- key += std::to_string(port);
-
- return key;
-}
-std::string SecurityOriginInfo::translateValue(int result) {
- std::string value = "";
-
- switch (result) {
- case RESULT_ALLOW_ALWAYS :
- value = kValueAllow;
- break;
- case RESULT_DENY_ALWAYS :
- value = kValueDenied;
- break;
- case RESULT_UNKNOWN :
- case RESULT_ALLOW_ONCE :
- case RESULT_DENY_ONCE :
- default :
- value = kValueUnknown;
- break;
- }
- return value;
-}
-CertificateInfo::CertificateInfo(
- std::string pem,
- int result) {
- m_section_ = kDBPrivateSection;
- m_key_ = translateKey(pem);
- m_value_ = translateValue(result);
-}
-std::string CertificateInfo::translateKey(std::string pem) {
- std::string key = "";
- key = kCertificateAllowPrefix + pem;
- return key;
-}
-std::string CertificateInfo::translateValue(int result) {
- std::string value = "";
-
- switch (result) {
- case RESULT_ALLOW_ALWAYS :
- value = kValueAllow;
- break;
- case RESULT_DENY_ALWAYS :
- value = kValueDenied;
- break;
- case RESULT_UNKNOWN :
- case RESULT_ALLOW_ONCE :
- case RESULT_DENY_ONCE :
- default :
- value = kValueUnknown;
- break;
- }
- return value;
-}
-WrtUpgradeInfo::WrtUpgradeInfo(std::string appid) {
- app_id_ = appid;
- pkg_id_ = appid.substr(0, appid.find_first_of('.'));
- app_dir_ = kAppDirectoryPrefix + pkg_id_;
-}
-void WrtUpgradeInfo::addPreferenceInfo(PreferenceInfo preference) {
- preference_info_list_.push_back(preference);
-}
-void WrtUpgradeInfo::addSecurityOriginInfo(SecurityOriginInfo security_origin) {
- security_origin_info_list_.push_back(security_origin);
-}
-void WrtUpgradeInfo::addCertificateInfo(CertificateInfo certificate) {
- certificate_info_list.push_back(certificate);
-}
-
-std::string WrtUpgradeInfo::getSecurityOriginDB() {
- return app_dir_ + kAppSecurityOriginDBFile;
-}
-std::string WrtUpgradeInfo::getCertificateDB() {
- return app_dir_ + kAppCertificateDBFile;
-}
-} // namespace upgrade
+++ /dev/null
-// Copyright (c) 2013 Intel Corporation. All rights reserved.
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef WRT_UPGRADE_INFO_H
-#define WRT_UPGRADE_INFO_H
-
-#include <iostream>
-#include <string>
-#include <vector>
-
-namespace upgrade {
-class PreferenceInfo{
- public:
- PreferenceInfo(std::string key, std::string value);
- std::string getSection() {return m_section_;}
- std::string getKey() {return m_key_;}
- std::string getValue() {return m_value_;}
- private:
- std::string m_section_;
- std::string m_key_;
- std::string m_value_;
-};
-
-class SecurityOriginInfo{
- public:
- SecurityOriginInfo(
- int feature,
- std::string scheme,
- std::string host,
- int port,
- int result);
- std::string getSection() {return m_section_;}
- std::string getKey() {return m_key_;}
- std::string getValue() {return m_value_;}
- private:
- std::string translateKey(
- int feature,
- std::string scheme,
- std::string host,
- int port);
- std::string translateValue(int result);
- std::string m_section_;
- std::string m_key_;
- std::string m_value_;
-};
-
-class CertificateInfo{
- public:
- CertificateInfo(
- std::string pem,
- int result);
- std::string getSection() {return m_section_;}
- std::string getKey() {return m_key_;}
- std::string getValue() {return m_value_;}
- private:
- std::string translateKey(std::string pem);
- std::string translateValue(int result);
- std::string m_section_;
- std::string m_key_;
- std::string m_value_;
-};
-
-class WrtUpgradeInfo{
- public:
- WrtUpgradeInfo() {}
- explicit WrtUpgradeInfo(std::string appid);
-
- std::string getAppid() { return app_id_; }
- std::string getPkgid() { return pkg_id_; }
- std::string getAppDir() { return app_dir_; }
- std::string getSecurityOriginDB();
- std::string getCertificateDB();
-
- void addPreferenceInfo(PreferenceInfo preference);
- void addSecurityOriginInfo(SecurityOriginInfo security_origin);
- void addCertificateInfo(CertificateInfo certificate);
-
- PreferenceInfo getPreferenceInfo(int idx)
- {return preference_info_list_[idx];}
- SecurityOriginInfo getSecurityOriginInfo(int idx)
- {return security_origin_info_list_[idx];}
- CertificateInfo getCertificateInfo(int idx)
- {return certificate_info_list[idx];}
-
- int getPreferenceInfoSize()
- {return static_cast<int>(preference_info_list_.size());}
- int getSecurityOriginInfoSize()
- {return static_cast<int>(security_origin_info_list_.size());}
- int getCertificateInfoSize()
- {return static_cast<int>(certificate_info_list.size());}
-
- private:
- std::string pkg_id_;
- std::string app_id_;
- std::string app_dir_;
- std::vector<PreferenceInfo> preference_info_list_;
- std::vector<SecurityOriginInfo> security_origin_info_list_;
- std::vector<CertificateInfo> certificate_info_list;
-};
-} // namespace upgrade
-#endif // WRT_UPGRADE_INFO_H
+++ /dev/null
-// Copyright (c) 2013 Intel Corporation. All rights reserved.
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "wrt-upgrade/wrt-upgrade.h"
-
-#include <sqlite3.h>
-#include <unistd.h>
-
-#include <iostream>
-#include <fstream>
-#include <utility>
-
-#include "common/picojson.h"
-#include "common/logger.h"
-#include "common/file_utils.h"
-
-namespace {
- const std::string kWRTDbFile = "/opt/dbspace/.wrt.db";
- const std::string kAppDirectoryPrefix = "/opt/usr/home/owner/apps_rw/";
- const std::string kAppMigrationFile = "/data/.runtime.migration";
- const std::string kJournalPostfix = "-journal";
-} // namespace
-
-namespace upgrade {
-WrtUpgrade::WrtUpgrade() {
-}
-WrtUpgrade::~WrtUpgrade() {
-}
-void WrtUpgrade::Run() {
- ParseWrtDatabse();
- ParseSecurityOriginDatabase();
- ParseCertificatenDatabase();
- CreateMigrationFile();
- RemoveDatabases();
-}
-void WrtUpgrade::ParseWrtDatabse() {
- std::cout << "parseWrtDatabse" << std::endl;
- sqlite3 *wrt_db;
- try {
- int ret = sqlite3_open(kWRTDbFile.c_str(), &wrt_db);
- if (ret != SQLITE_OK) {
- throw("error to open wrt database");
- }
-
- // get applist
- std::string query = "select tizen_appid from widgetinfo";
- sqlite3_stmt* stmt = NULL;
-
- ret = sqlite3_prepare_v2(wrt_db, query.c_str() , -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- throw("error for prepare query");
- }
-
- while (SQLITE_ROW == sqlite3_step(stmt)) {
- std::string appid
- = std::string(reinterpret_cast<const char*>(
- sqlite3_column_text(stmt, 0)));
- application_list_.push_back(appid);
- application_map_.insert(
- std::pair<std::string, WrtUpgradeInfo>(appid, WrtUpgradeInfo(appid)));
- }
-
- ret = sqlite3_finalize(stmt);
- if (ret != SQLITE_OK) {
- throw("error for finalize stmt");
- }
-
- // get widget preference
- query = "select tizen_appid,key_name,key_value from widgetpreference";
- stmt = NULL;
-
- ret = sqlite3_prepare_v2(wrt_db, query.c_str() , -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- throw("error for prepare query");
- }
-
- while (SQLITE_ROW == sqlite3_step(stmt)) {
- std::string appid
- = std::string(reinterpret_cast<const char*>(
- sqlite3_column_text(stmt, 0)));
- std::string key
- = std::string(reinterpret_cast<const char*>(
- sqlite3_column_text(stmt, 1)));
- std::string value
- = std::string(reinterpret_cast<const char*>(
- sqlite3_column_text(stmt, 2)));
-
- application_map_[appid].addPreferenceInfo(PreferenceInfo(key, value));
- }
- ret = sqlite3_finalize(stmt);
- if (ret != SQLITE_OK) {
- throw("error for finalize stmt");
- }
- } catch(const char* err) {
- std::cout << err << std::endl;
- }
- sqlite3_close(wrt_db);
-}
-void WrtUpgrade::ParseSecurityOriginDatabase() {
- std::cout << "parseSecurityOriginDatabase" << std::endl;
- for (int i = 0; i < static_cast<int>(application_list_.size()) ; i++) {
- sqlite3 *security_origin_db;
- std::string appid = application_list_[i];
- try {
- std::string db_path = application_map_[appid].getSecurityOriginDB();
-
- if (access(db_path.c_str(), 0) != 0) {
- throw("file is not exist : ["+db_path+"]");
- }
- int ret = sqlite3_open(db_path.c_str(), &security_origin_db);
- if (ret != SQLITE_OK) {
- throw("error to open wrt database");
- }
-
- // get applist
- std::string query = "select * from securityorigininfo";
- sqlite3_stmt* stmt = NULL;
-
- ret = sqlite3_prepare_v2(
- security_origin_db, query.c_str() , -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- throw("error for prepare query");
- }
-
- while (SQLITE_ROW == sqlite3_step(stmt)) {
- int feature = sqlite3_column_int(stmt, 0);
- std::string scheme
- = std::string(reinterpret_cast<const char*>(
- sqlite3_column_text(stmt, 1)));
- std::string host
- = std::string(reinterpret_cast<const char*>(
- sqlite3_column_text(stmt, 2)));
- int port = sqlite3_column_int(stmt, 3);
- int result = sqlite3_column_int(stmt, 4);
- application_map_[appid].addSecurityOriginInfo(
- SecurityOriginInfo(feature, scheme, host, port, result));
- }
-
- ret = sqlite3_finalize(stmt);
- if (ret != SQLITE_OK) {
- throw("error for finalize stmt");
- }
- } catch(...) {
- }
- sqlite3_close(security_origin_db);
- }
-}
-void WrtUpgrade::ParseCertificatenDatabase() {
- std::cout << "parseCertificateDatabase" << std::endl;
- for (int i = 0 ; i < static_cast<int>(application_list_.size()) ; i++) {
- sqlite3 *certificate_db;
- std::string appid = application_list_[i];
- try {
- std::string db_path = application_map_[appid].getCertificateDB();
-
- if (access(db_path.c_str(), 0) != 0) {
- throw("file is not exist : ["+db_path+"]");
- }
- int ret = sqlite3_open(db_path.c_str(), &certificate_db);
- if (ret != SQLITE_OK) {
- throw("error to open wrt database");
- }
-
- // get applist
- std::string query = "select * from certificateinfo";
- sqlite3_stmt* stmt = NULL;
-
- ret = sqlite3_prepare_v2(certificate_db, query.c_str() , -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- throw("error for prepare query");
- }
-
- while (SQLITE_ROW == sqlite3_step(stmt)) {
- std::string certificate
- = std::string(reinterpret_cast<const char*>(
- sqlite3_column_text(stmt, 0)));
- int result = sqlite3_column_int(stmt, 1);
- application_map_[appid].addCertificateInfo(
- CertificateInfo(certificate, result));
- }
-
- ret = sqlite3_finalize(stmt);
- if (ret != SQLITE_OK) {
- throw("error for finalize stmt");
- }
- } catch(...) {
- }
- sqlite3_close(certificate_db);
- }
-}
-void WrtUpgrade::CreateMigrationFile() {
- std::cout << "createMigrationFile" << std::endl;
- for (int i = 0 ; i < static_cast<int>(application_list_.size()) ; i++) {
- std::string appid = application_list_[i];
- std::string json_str = CreateJsonObject(appid);
- if (!json_str.empty()) {
- std::string pkg_id = appid.substr(0, appid.find_first_of('.'));
- std::string output_file_path
- = kAppDirectoryPrefix + pkg_id + kAppMigrationFile;
- std::ofstream output_file(output_file_path);
- output_file << json_str;
- output_file.close();
- }
- }
-}
-void WrtUpgrade::RemoveDatabases() {
- for (int i = 0 ; i < static_cast<int>(application_list_.size()) ; i++) {
- std::string appid = application_list_[i];
- try {
- std::string security_origin_db_path
- = application_map_[appid].getSecurityOriginDB();
- std::string security_origin_journal_db_path
- = security_origin_db_path + kJournalPostfix;
- std::string certificate_db_path
- = application_map_[appid].getCertificateDB();
- std::string certificate_journal_db_path
- = certificate_db_path + kJournalPostfix;
-
- RemoveFile(security_origin_db_path);
- RemoveFile(security_origin_journal_db_path);
- RemoveFile(certificate_db_path);
- RemoveFile(certificate_journal_db_path);
- } catch(...) {
- }
- }
-}
-std::string WrtUpgrade::CreateJsonObject(std::string appid) {
- WrtUpgradeInfo info = application_map_[appid];
-
- if (info.getPreferenceInfoSize() == 0
- && info.getSecurityOriginInfoSize() == 0
- && info.getCertificateInfoSize() == 0) {
- return "";
- }
- std::cout << "createJsonObject for " << appid << std::endl;
-
- // make preference value arr : vector
- picojson::array preference_arr;
- for (int i = 0 ; i < info.getPreferenceInfoSize() ; i++) {
- PreferenceInfo p_info = info.getPreferenceInfo(i);
- picojson::object obj;
- obj["key"] = picojson::value(p_info.getKey());
- obj["value"] = picojson::value(p_info.getValue());
- preference_arr.push_back(picojson::value(obj));
- }
-
- // make security_origin value arr : vector
- picojson::array securityorigin_arr;
- for (int i = 0 ; i < info.getSecurityOriginInfoSize() ; i++) {
- SecurityOriginInfo s_info = info.getSecurityOriginInfo(i);
- picojson::object obj;
- obj["section"] = picojson::value(s_info.getSection());
- obj["key"] = picojson::value(s_info.getKey());
- obj["value"] = picojson::value(s_info.getValue());
- securityorigin_arr.push_back(picojson::value(obj));
- }
-
- // make certificate value arr : vector
- picojson::array certificate_arr;
- for (int i = 0 ; i < info.getCertificateInfoSize() ; i++) {
- CertificateInfo c_info = info.getCertificateInfo(i);
- picojson::object obj;
- obj["section"] = picojson::value(c_info.getSection());
- obj["key"] = picojson::value(c_info.getKey());
- obj["value"] = picojson::value(c_info.getValue());
- certificate_arr.push_back(picojson::value(obj));
- }
-
- // make one json
- picojson::object migration_obj;
- migration_obj["preference"] = picojson::value(preference_arr);
- migration_obj["security_orgin"] = picojson::value(securityorigin_arr);
- migration_obj["certificate"] = picojson::value(certificate_arr);
-
- picojson::value migration_val = picojson::value(migration_obj);
- std::string json_str = migration_val.serialize();
- return json_str;
-}
-bool WrtUpgrade::RemoveFile(const std::string& path) {
- if (!common::utils::Exists(path)) {
- LOGGER(ERROR) << "File is not Exist : " << path;
- return false;
- }
- return (remove(path.c_str()) == 0);
-}
-} // namespace upgrade
-int main() {
- std::cout << "Tizen database migration tool for Webruntime" << std::endl;
- upgrade::WrtUpgrade mt;
- mt.Run();
- return 0;
-}