Fill information related resource package (#11)
author김일호/Tizen Platform Lab(SR)/Engineer/삼성전자 <ilho159.kim@samsung.com>
Thu, 17 Jun 2021 03:53:06 +0000 (12:53 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 17 Jun 2021 03:53:06 +0000 (12:53 +0900)
* Fill information related resource package

- Fill allowed packages
- Fill res_type, res_version

Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/rpk/step/configuration/step_parse_rpk_manifest.cc

index 9588606..abac1b2 100644 (file)
@@ -236,17 +236,13 @@ bool StepParseRpkManifest::FillPackageInfo(manifest_x* manifest) {
   manifest->api_version = strdup(pkg_info->api_version().c_str());
   manifest->installlocation = strdup(kInternalOnly);
   manifest->type = strdup(kRpk);
-/*
-  // TODO: add this code when manifest has variables for these
   manifest->res_type = strdup(pkg_info->res_type().c_str());
   manifest->res_version = strdup(pkg_info->res_version().c_str());
-*/
 
   return true;
 }
 
 bool StepParseRpkManifest::FillAllowedPackageInfo(manifest_x* manifest) {
-  // add allowed-package info
   std::shared_ptr<const rpk::parse::AllowedPackageInfoList> allowed_pkg_info_list =
       std::static_pointer_cast<const rpk::parse::AllowedPackageInfoList>(
           parser_->GetManifestData(kAllowedPackageKey));
@@ -255,18 +251,33 @@ bool StepParseRpkManifest::FillAllowedPackageInfo(manifest_x* manifest) {
     return false;
   }
 
-  auto& allowed_pkg_list = allowed_pkg_info_list->allowed_packages();
+  const auto& allowed_pkg_list = allowed_pkg_info_list->allowed_packages();
   if (allowed_pkg_list.size() == 0)
     return true;
 
-/*
-  // TODO: this should be activated after manifest has variables for these
   for (auto& allowed_pkg : allowed_pkg_list) {
-    // add allowed-package info
-    std::string pkgid = allowed_pkg->get_pkgid();
-    auto& required_privileges = allowed_pkg->get_privileges();
+    res_allowed_package_x* rap =
+        reinterpret_cast<res_allowed_package_x*>(
+            calloc(1, sizeof(res_allowed_package_x)));
+    if (!rap) {
+      LOG(ERROR) << "Out of memory";
+      return false;
+    }
+
+    rap->allowed_package = strdup(allowed_pkg->get_pkgid().c_str());
+    if (!rap->allowed_package) {
+      LOG(ERROR) << "Out of memory";
+      free(rap);
+      return false;
+    }
+
+    for (const auto& priv : allowed_pkg->get_privileges())
+      rap->required_privileges =
+          g_list_prepend(rap->required_privileges, strdup(priv.first.c_str()));
+
+    manifest->res_allowed_packages =
+        g_list_prepend(manifest->res_allowed_packages, rap);
   }
-*/
 
   return true;
 }