--- /dev/null
+// Copyright (c) 2020 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 "common/archive_info.h"
+
+#include <glib.h>
+#include <manifest_parser/utils/logging.h>
+#include <package-manager-plugin.h>
+
+#include <algorithm>
+#include <cstdio>
+#include <cstring>
+#include <utility>
+#include <vector>
+
+namespace common_installer {
+
+bool ArchiveInfo::GetPkgDetailInfo(package_manager_pkg_detail_info_t* info) {
+ if (!info)
+ return false;
+ if (pkgid_.empty())
+ return false;
+
+ snprintf(info->pkg_type, sizeof(info->pkg_type), "%s", type_.c_str());
+ snprintf(info->pkg_name, sizeof(info->pkg_name), "%s", pkgid_.c_str());
+ snprintf(info->pkgid, sizeof(info->pkgid), "%s", pkgid_.c_str());
+ snprintf(info->version, sizeof(info->version), "%s", version_.c_str());
+ snprintf(info->api_version, sizeof(info->api_version), "%s",
+ api_version_.c_str());
+ snprintf(info->author, sizeof(info->author), "%s", author_.c_str());
+ snprintf(info->label, sizeof(info->label), "%s", label_.c_str());
+ snprintf(info->pkg_description, sizeof(info->pkg_description), "%s",
+ description_.c_str());
+
+ for (const auto& priv : privileges_) {
+ char* pirv_str = strdup(priv.first.c_str());
+ if (!priv_str) {
+ LOG(ERROR) << "Out of memory";
+ g_list_free_full(info->dependency_list, free);
+ return false;
+ }
+ info->privilege_list = g_list_append(info->privilege_list, priv_str);
+ }
+
+ for (const auto& dependency : dependencies_) {
+ pkg_dependency_info_t* dep =
+ static_cast<pkg_dependency_info_t*>
+ (calloc(1, sizeof(pkg_dependency_info_t)));
+ if (!dep) {
+ LOG(ERROR) << "Out of memory";
+ g_list_free_full(info->dependency_list, free);
+ return false;
+ }
+ snprintf(dep->pkgid, sizeof(dep->pkgid), "%s",
+ std::get<0>(dependency).c_str());
+ snprintf(dep->type, sizeof(dep->type), "%s",
+ std::get<1>(dependency).c_str());
+ snprintf(dep->required_version, sizeof(dep->required_version), "%s",
+ std::get<2>(dependency).c_str());
+ info->dependency_list = g_list_append(info->dependency_list, dep);
+ }
+
+ info->icon_buf =
+ reinterpret_cast<char*>(malloc(sizeof(char) * icon_buf_.size()));
+ if (!info->icon_buf) {
+ LOG(ERROR) << "Out of memory";
+ g_list_free_full(info->dependency_list, free);
+ return false;
+ }
+
+ std::copy(icon_buf_.begin(), icon_buf_.end(), info->icon_buf);
+ info->icon_size = icon_buf_.size();
+
+ return true;
+}
+
+} // namespace common_installer
--- /dev/null
+// Copyright (c) 2020 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 COMMON_ARCHIVE_INFO_H_
+#define COMMON_ARCHIVE_INFO_H_
+
+#include <package-manager-plugin.h>
+
+#include <string>
+#include <tuple>
+#include <utility>
+#include <vector>
+
+namespace common_installer {
+
+class ArchiveInfo {
+ public:
+ using Privilege = std::pair<std::string, std::string>;
+ using Dependency = std::tuple<std::string, std::string, std::string>;
+
+ explicit ArchiveInfo(std::string path) : path_(std::move(path)) { }
+ virtual bool LoadArchiveInfo() = 0;
+ bool GetPkgDetailInfo(package_manager_pkg_detail_info_t* info);
+
+ std::string type() const { return type_; }
+ std::string name() const { return name_; }
+ std::string pkgid() const { return pkgid_; }
+ std::string author() const { return author_; }
+ std::string description() const { return description_; }
+ std::string version() const { return version_; }
+ std::string api_version() const { return api_version_; }
+ std::string label() const { return label_; }
+ std::string icon() const { return icon_; }
+ std::vector<unsigned char> icon_buf() const { return icon_buf_; }
+ std::vector<Privilege> privileges() const { return privileges_; }
+ std::vector<Dependency> dependencies() const { return dependencies_; }
+
+ protected:
+ std::string path_;
+ std::string type_;
+ std::string name_;
+ std::string pkgid_;
+ std::string author_;
+ std::string description_;
+ std::string version_;
+ std::string api_version_;
+ std::string label_;
+ std::string icon_;
+ std::vector<unsigned char> icon_buf_;
+ std::vector<Privilege> privileges_;
+ std::vector<Dependency> dependencies_;
+};
+
+} // namespace common_installer
+
+#endif // COMMON_ARCHIVE_INFO_H_