+// 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