// privileges
const char kPrivilegesKey[] = "manifest.privileges";
+// provides appdefined privileges
+const char kProvidesAppDefinedPrivilegesKey[] =
+ "manifest.provides-appdefined-privileges";
+
// service-application
const char kServiceApplicationKey[] = "manifest.service-application";
// privileges
extern const char kPrivilegesKey[];
+// provides appdefined privileges
+extern const char kProvidesAppDefinedPrivilegesKey[];
+
// service-application
extern const char kServiceApplicationKey[];
--- /dev/null
+// Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "tpk_manifest_handlers/common/appdefined_privilege_handler.h"
+
+#include <utility>
+
+#include "manifest_parser/manifest_util.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/logging.h"
+#include "manifest_parser/values.h"
+#include "tpk_manifest_handlers/application_manifest_constants.h"
+#include "tpk_manifest_handlers/package_handler.h"
+
+namespace {
+
+const char kAppDefinedPrivilegeKey[] = "appdefined-privilege";
+const char kPrivilegeTextKey[] = "#text";
+const char kPrivilegeTypeKey[] = "@type";
+const char kPrivilegeLicenseKey[] = "@license";
+const char kPrivilegeTypeDefault[] = "tpk";
+const unsigned int kMaxAppDefinedLength = 512;
+
+} // namespace
+
+namespace tpk {
+namespace parse {
+
+bool ParseAppDefinedPrivilege(const parser::DictionaryValue* value,
+ std::shared_ptr<AppDefinedPrivilegeInfo> info, std::string*) {
+ std::string privilege;
+ std::string type = kPrivilegeTypeDefault;
+ std::string license;
+ if (!value->GetString(kPrivilegeTextKey, &privilege) ||
+ privilege.empty())
+ return true;
+ value->GetString(kPrivilegeTypeKey, &type);
+ value->GetString(kPrivilegeLicenseKey, &license);
+ AppDefinedPrivilegeSingleEntry appdef_entry;
+ appdef_entry.privilege = privilege;
+ appdef_entry.type = type;
+ appdef_entry.license = license;
+ info->SetAppDefinedPrivilege(appdef_entry);
+ return true;
+}
+
+bool AppDefinedPrivilegeValidation(const AppDefinedPrivilegeInfo& info,
+ std::string package_name, std::string* error) {
+ auto priv = info.GetAppDefinedPrivilege();
+ if (priv.privilege.length() > kMaxAppDefinedLength ||
+ priv.license.length() > kMaxAppDefinedLength) {
+ *error = "The length is not valid.";
+ return false;
+ }
+ if (!parser::utils::IsValidIRI(priv.privilege)) {
+ *error = "The privilege is not valid IRI.";
+ return false;
+ }
+ std::string tmpstr("http://" + package_name + "/appdefined/");
+ std::size_t found = priv.privilege.find(tmpstr);
+ if (found == std::string::npos || found != 0) {
+ *error = "The privilege is not valid prefix.";
+ LOG(ERROR) << "Invalid prefix, pos(" << found << ")";
+ return false;
+ }
+ return true;
+}
+
+} // namespace parse
+} // namespace tpk
--- /dev/null
+// Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef TPK_MANIFEST_HANDLERS_COMMON_APPDEFINED_PRIVILEGE_HANDLER_H_
+#define TPK_MANIFEST_HANDLERS_COMMON_APPDEFINED_PRIVILEGE_HANDLER_H_
+
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/values.h"
+
+namespace tpk {
+namespace parse {
+
+struct AppDefinedPrivilegeSingleEntry {
+ std::string privilege;
+ std::string type;
+ std::string license; // path of license
+};
+
+class AppDefinedPrivilegeInfo : public parser::ManifestData {
+ public:
+ /**
+ * @brief GetAppDefinedPrivilege
+ * @return AppDefinedPrivilegeSingleEntry
+ */
+ const AppDefinedPrivilegeSingleEntry& GetAppDefinedPrivilege() const {
+ return appdefined_privilege_;
+ }
+
+ /**
+ * @brief AddAppDefinedPrivilege add appdefined privilege
+ * @param AppDefinedPrivilegeSingleEntry
+ */
+ void SetAppDefinedPrivilege(AppDefinedPrivilegeSingleEntry appdef_entry) {
+ appdefined_privilege_ = appdef_entry;
+ }
+
+ private:
+ AppDefinedPrivilegeSingleEntry appdefined_privilege_;
+};
+
+bool ParseAppDefinedPrivilege(const parser::DictionaryValue* value,
+ std::shared_ptr<AppDefinedPrivilegeInfo> info, std::string* error);
+
+bool AppDefinedPrivilegeValidation(const AppDefinedPrivilegeInfo& info,
+ std::string package_name, std::string* error);
+
+} // namespace parse
+} // namespace tpk
+
+#endif // TPK_MANIFEST_HANDLERS_COMMON_APPDEFINED_PRIVILEGE_HANDLER_H_
#include "manifest_parser/utils/logging.h"
#include "manifest_parser/values.h"
#include "tpk_manifest_handlers/application_manifest_constants.h"
+#include "tpk_manifest_handlers/package_handler.h"
namespace tpk {
namespace parse {
const char kPrivilegesKey[] = "manifest.privileges";
const char kPrivilegeKey[] = "privilege";
+const char kAppDefinedPrivilegeKey[] = "appdefined-privilege";
const char kPrivilegeTextKey[] = "#text";
const char kPrivilegeTypeKey[] = "@type";
item->GetString(kPrivilegeTypeKey, &type);
privileges_info->AddPrivilege(privilege, type);
}
+ for (auto& item : parser::GetOneOrMany(privileges_dict,
+ kAppDefinedPrivilegeKey, "")) {
+ std::shared_ptr<AppDefinedPrivilegeInfo> appdef_info(
+ new AppDefinedPrivilegeInfo());
+ if (!ParseAppDefinedPrivilege(item, appdef_info, error))
+ return false;
+ privileges_info->AddAppDefinedPrivilegeInfo(*appdef_info.get());
+ }
+
*output = std::static_pointer_cast<parser::ManifestData>(privileges_info);
return true;
}
+bool PrivilegesHandler::Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const {
+ std::shared_ptr<const PackageInfo> package_info =
+ std::static_pointer_cast<const PackageInfo>(
+ handlers_output.find(PackageInfo::key())->second);
+ const PrivilegesInfo& privileges_info =
+ static_cast<const PrivilegesInfo&>(data);
+ auto appdef_privileges = privileges_info.GetAppDefinedPrivilegeInfoList();
+ for (auto priv : appdef_privileges) {
+ const AppDefinedPrivilegeInfo& info =
+ static_cast<const AppDefinedPrivilegeInfo&>(priv);
+ if (!AppDefinedPrivilegeValidation(info, package_info->package(), error))
+ return false;
+ }
+
+ return true;
+}
+
std::string PrivilegesInfo::key() {
return kPrivilegesKey;
}
#include "manifest_parser/permission_types.h"
#include "manifest_parser/values.h"
#include "tpk_manifest_handlers/application_manifest_constants.h"
+#include "tpk_manifest_handlers/common/appdefined_privilege_handler.h"
namespace tpk {
namespace parse {
void AddPrivilege(const std::string& privilege, const std::string& type) {
privileges_.insert(std::make_pair(privilege, type));
}
+ /**
+ * @brief GetAppDefinedPrivilegeInfoList
+ * @return std::vector<AppDefinedPrivilegeInfo>
+ */
+ const std::vector<AppDefinedPrivilegeInfo> GetAppDefinedPrivilegeInfoList()
+ const {
+ return appdefined_info_list_;
+ }
+ /**
+ * @brief AddAppDefinedPrivilegeInfo
+ * @param AppDefinedPrivilegeInfo
+ */
+ void AddAppDefinedPrivilegeInfo(AppDefinedPrivilegeInfo info) {
+ appdefined_info_list_.push_back(std::move(info));
+ }
private:
PrivilegesSet privileges_;
+ std::vector<AppDefinedPrivilegeInfo> appdefined_info_list_;
};
/**
* Handler of tizen-manifest.xml for xml elements:
* <privileges>
* \_ <privilege>
+ * \_ <appdefined-privilege>
*/
class PrivilegesHandler : public parser::ManifestHandler {
public:
const parser::Manifest& manifest,
std::shared_ptr<parser::ManifestData>* output,
std::string* error) override;
+ bool Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
std::string Key() const override;
};
--- /dev/null
+// Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "tpk_manifest_handlers/provides_appdefined_privileges_handler.h"
+
+#include <utility>
+
+#include "manifest_parser/manifest_util.h"
+#include "manifest_parser/utils/logging.h"
+#include "manifest_parser/values.h"
+#include "tpk_manifest_handlers/application_manifest_constants.h"
+#include "tpk_manifest_handlers/package_handler.h"
+
+namespace {
+
+const char kProvidesAppDefinedPrivilegesKey[] =
+ "manifest.provides-appdefined-privileges";
+const char kAppDefinedPrivilegeKey[] = "appdefined-privilege";
+
+} // namespace
+
+namespace tpk {
+namespace parse {
+
+bool ProvidesAppDefinedPrivilegesHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) {
+ parser::Value* value = nullptr;
+ if (!manifest.Get(kProvidesAppDefinedPrivilegesKey, &value))
+ return true;
+ parser::DictionaryValue* dict = nullptr;
+ if (!value->GetAsDictionary(&dict)) {
+ *error = "Failed to parse <provides-appdefined-privileges> tag";
+ return false;
+ }
+ std::shared_ptr<ProvidesAppDefinedPrivilegesInfo> privileges_info(
+ new ProvidesAppDefinedPrivilegesInfo());
+ for (auto& item : parser::GetOneOrMany(dict, kAppDefinedPrivilegeKey, "")) {
+ std::shared_ptr<AppDefinedPrivilegeInfo> appdef_info(
+ new AppDefinedPrivilegeInfo());
+ if (!ParseAppDefinedPrivilege(item, appdef_info, error))
+ return false;
+ privileges_info->AddAppDefinedPrivilegeInfo(*appdef_info.get());
+ }
+
+ *output = std::static_pointer_cast<parser::ManifestData>(privileges_info);
+ return true;
+}
+
+bool ProvidesAppDefinedPrivilegesHandler::Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const {
+ std::shared_ptr<const PackageInfo> package_info =
+ std::static_pointer_cast<const PackageInfo>(
+ handlers_output.find(PackageInfo::key())->second);
+ const ProvidesAppDefinedPrivilegesInfo& privileges_info =
+ static_cast<const ProvidesAppDefinedPrivilegesInfo&>(data);
+ auto appdef_privileges = privileges_info.GetAppDefinedPrivilegeInfoList();
+ for (auto priv : appdef_privileges) {
+ const AppDefinedPrivilegeInfo& info =
+ static_cast<const AppDefinedPrivilegeInfo&>(priv);
+ if (!AppDefinedPrivilegeValidation(info, package_info->package(), error))
+ return false;
+ }
+
+ return true;
+}
+
+std::string ProvidesAppDefinedPrivilegesInfo::key() {
+ return kProvidesAppDefinedPrivilegesKey;
+}
+
+std::string ProvidesAppDefinedPrivilegesHandler::Key() const {
+ return kProvidesAppDefinedPrivilegesKey;
+}
+
+} // namespace parse
+} // namespace tpk
--- /dev/null
+// Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef TPK_MANIFEST_HANDLERS_PROVIDES_APPDEFINED_PRIVILEGES_HANDLER_H_
+#define TPK_MANIFEST_HANDLERS_PROVIDES_APPDEFINED_PRIVILEGES_HANDLER_H_
+
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/values.h"
+#include "tpk_manifest_handlers/application_manifest_constants.h"
+#include "tpk_manifest_handlers/common/appdefined_privilege_handler.h"
+
+namespace tpk {
+namespace parse {
+
+class ProvidesAppDefinedPrivilegesInfo : public parser::ManifestData {
+ public:
+ /**
+ * @brief key
+ * @param key string
+ */
+ static std::string key();
+ /**
+ * @brief GetAppDefinedPrivilegeInfoList
+ * @return std::vector<AppDefinedPrivilegeInfo>
+ */
+ const std::vector<AppDefinedPrivilegeInfo> GetAppDefinedPrivilegeInfoList()
+ const {
+ return appdefined_info_list_;
+ }
+ /**
+ * @brief AddAppDefinedPrivilegeInfo
+ * @param AppDefinedPrivilegeInfo
+ */
+ void AddAppDefinedPrivilegeInfo(AppDefinedPrivilegeInfo info) {
+ appdefined_info_list_.push_back(std::move(info));
+ }
+
+ private:
+ std::vector<AppDefinedPrivilegeInfo> appdefined_info_list_;
+};
+
+/**
+ * @brief The ProvidesAppDefinedPrivilegesHandler class
+ *
+ * Handler of tizen-manifest.xml for xml elements:
+ * <provides-appdefined-privileges>
+ * \_ <appdefined-privilege>
+ */
+class ProvidesAppDefinedPrivilegesHandler : public parser::ManifestHandler {
+ public:
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+ std::string Key() const override;
+};
+
+} // namespace parse
+} // namespace tpk
+
+#endif // TPK_MANIFEST_HANDLERS_PROVIDES_APPDEFINED_PRIVILEGES_HANDLER_H_
#include "tpk_manifest_handlers/package_handler.h"
#include "tpk_manifest_handlers/privileges_handler.h"
#include "tpk_manifest_handlers/profile_handler.h"
+#include "tpk_manifest_handlers/provides_appdefined_privileges_handler.h"
#include "tpk_manifest_handlers/service_application_handler.h"
#include "tpk_manifest_handlers/shortcut_handler.h"
#include "tpk_manifest_handlers/ui_application_handler.h"
std::make_shared<DescriptionHandler>(),
std::make_shared<PackageHandler>(),
std::make_shared<PrivilegesHandler>(),
+ std::make_shared<ProvidesAppDefinedPrivilegesHandler>(),
std::make_shared<ProfileHandler>(),
std::make_shared<WidgetApplicationHandler>(),
std::make_shared<WatchApplicationHandler>(),