Add step-parse 74/33374/6
authorMaciej Piotrowski <m.piotrowski@samsung.com>
Thu, 8 Jan 2015 13:37:55 +0000 (14:37 +0100)
committerDominik Duda <d.duda@samsung.com>
Tue, 13 Jan 2015 14:37:17 +0000 (15:37 +0100)
- compile successfully
- widget-manifest-parser library added
- widget-manifest-parser library works correct
- storing data from widget-manifest-parser proposed

Change-Id: I317554abbf19c72c6c1a77b28218c7008d58cb44

CMakeLists.txt
packaging/app-installers.spec
src/common/app_installer.cc
src/common/context_installer.cc
src/common/context_installer.h
src/wgt/CMakeLists.txt
src/wgt/step/step_parse.cc [new file with mode: 0644]
src/wgt/step/step_parse.h [new file with mode: 0644]
src/wgt/step_parse.cc [deleted file]
src/wgt/wgt_backend.cc

index e04193c..fbf07a6 100644 (file)
@@ -48,6 +48,7 @@ PKG_CHECK_MODULES(OPENSSL_DEPS REQUIRED openssl)
 PKG_CHECK_MODULES(TZPLATFORM_CONFIG_DEPS REQUIRED libtzplatform-config)
 PKG_CHECK_MODULES(LIBXML_DEPS REQUIRED libxml-2.0)
 PKG_CHECK_MODULES(XMLSEC1_DEPS REQUIRED xmlsec1)
+PKG_CHECK_MODULES(WIDGET_MANIFEST_PARSER_DEPS REQUIRED widget-manifest-parser)
 
 FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem)
 
index 2c42d0b..a4f00af 100644 (file)
@@ -20,6 +20,7 @@ BuildRequires:  pkgconfig(minizip)
 BuildRequires:  pkgconfig(libzip)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(xmlsec1)
+BuildRequires:  pkgconfig(widget-manifest-parser)
 
 Requires: ca-certificates-tizen
 Requires: libtzplatform-config
index d9262d0..7851bc0 100644 (file)
@@ -15,7 +15,7 @@ AppInstaller::AppInstaller(int request, const char* file, const char* pkgid) {
   ctx_->set_file_path(file);
 }
 
-AppInstaller::~AppInstaller() {  delete ctx_; }
+AppInstaller::~AppInstaller() { delete ctx_; }
 
 
 int AppInstaller::AddStep(Step *step) {
@@ -41,7 +41,7 @@ int AppInstaller::Run() {
     }
   }
   if (it != itEnd) {
-    std::cout << "Faillure occurs" << std::endl;
+    std::cout << "Failure occurs" << std::endl;
     do {
       if ((*it)->undo(ctx_) != APPINST_R_OK) {
         std::cout << "Error during undo operation" << std::endl;
index 9c123bb..630d194 100644 (file)
@@ -2,12 +2,22 @@
 
 #include "common/context_installer.h"
 
+#include <pkgmgr_installer.h>
 #include <tzplatform_config.h>
 #include <unistd.h>
 
 namespace common_installer {
 
-ContextInstaller::ContextInstaller() : uid_(getuid()) {}
+ContextInstaller::ContextInstaller() : req_(PKGMGR_REQ_INVALID),
+                                       uid_(getuid()),
+                                       manifest_(new manifest_x()),
+                                       config_data_(new ConfigData()) {
+}
+
+ContextInstaller::~ContextInstaller() {
+  if (manifest_)
+    pkgmgr_parser_free_manifest_xml(manifest_);
+}
 
 const char* ContextInstaller::GetApplicationPath() {
   return uid_ != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
index 2feb0e2..b97432f 100644 (file)
@@ -8,6 +8,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 
+#include <memory>
 #include <string>
 
 namespace common_installer {
@@ -18,62 +19,89 @@ enum {
   APPINST_R_OK = 0      /**< General success */
 };
 
-class ContextInstaller {
- private :
-  // request type: Install, Reinstall, Uninstall, Update.
-  int req_;
-
-  //  manifest information used to generate xml file
-  manifest_x* manifest_;
-
-  // pkgid used for update or uninstallation processing
-  std::string pkgid_;
-
-  // uid of the user that request the operation
-  uid_t uid_;
+class ConfigData;
+using ConfigDataPtr = std::unique_ptr<ConfigData>;
 
-  // package directory path containing app data
-  std::string pkg_path_;
+class ConfigData {
+ public:
+  ConfigData() {}
 
-  // file path used for installation or reinstallation process
-  std::string file_path_;
+  std::string application_name() const { return application_name_; }
+  void set_application_name(const std::string& app_name) {
+    application_name_ = app_name;
+  }
+  std::string required_version() const { return required_version_; }
+  void set_required_version(const std::string& required_version) {
+    required_version_ = required_version;
+  }
 
-  // directory path where app data are temporarily extracted
-  std::string unpack_directory_;
+ private:
+  std::string application_name_;
+  std::string required_version_;
+};
 
+class ContextInstaller {
  public:
   ContextInstaller();
+  ~ContextInstaller();
 
   int request_type() const { return req_; }
   void set_request_type(int req) {
-    req_ = req;
+   req_ = req;
   }
 
   manifest_x* manifest_data() const { return manifest_; }
 
   std::string pkgid() const { return pkgid_; }
   void set_pkgid(const std::string& pkgid) {
-    pkgid_ = pkgid;
+   pkgid_ = pkgid;
   }
 
   std::string pkg_path() const { return pkg_path_; }
   void set_pkg_path(const std::string& package_path) {
-    pkg_path_ = package_path;
+   pkg_path_ = package_path;
   }
 
   std::string file_path() const { return file_path_; }
   void set_file_path(const std::string& file_path) {
-    file_path_ = file_path;
+   file_path_ = file_path;
   }
 
   uid_t uid() const { return uid_; }
 
   std::string unpack_directory() const { return unpack_directory_; }
   void set_unpack_directory(const std::string& unpack_dir) {
-    unpack_directory_ = unpack_dir;
+   unpack_directory_ = unpack_dir;
   }
 
+  ConfigData* config_data() { return config_data_.get(); }
+
   const char* GetApplicationPath();
+
+ private :
+  // request type: Install, Reinstall, Uninstall, Update.
+  int req_;
+
+  //  manifest information used to generate xml file
+  manifest_x* manifest_;
+
+  // pkgid used for update or uninstallation processing
+  std::string pkgid_;
+
+  // uid of the user that request the operation
+  uid_t uid_;
+
+  // package directory path containing app data
+  std::string pkg_path_;
+
+  // file path used for installation or reinstallation process
+  std::string file_path_;
+
+  // directory path where app data are temporarily extracted
+  std::string unpack_directory_;
+
+  // data from config.xml
+  ConfigDataPtr config_data_;
 };
 
 }  // namespace common_installer
index 067de56..c9dcfe4 100644 (file)
@@ -1,6 +1,7 @@
 # Target - sources
 SET(SRCS
   wgt_backend.cc
+  step/step_parse.cc
 )
 # Target - definition
 ADD_EXECUTABLE(${TARGET_WGT_BACKEND} ${SRCS})
@@ -9,7 +10,9 @@ TARGET_INCLUDE_DIRECTORIES(${TARGET_WGT_BACKEND} PUBLIC "${CMAKE_CURRENT_SOURCE_
 # Target - deps
 APPLY_PKG_CONFIG(${TARGET_WGT_BACKEND} PUBLIC
   PKGMGR_INSTALLER_DEPS
+  WIDGET_MANIFEST_PARSER_DEPS
 )
+
 # Target - in-package deps
 TARGET_LINK_LIBRARIES(${TARGET_WGT_BACKEND} ${TARGET_LIBNAME_COMMON})
 
diff --git a/src/wgt/step/step_parse.cc b/src/wgt/step/step_parse.cc
new file mode 100644 (file)
index 0000000..176c1e6
--- /dev/null
@@ -0,0 +1,113 @@
+/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
+
+#include "wgt/step/step_parse.h"
+
+#include <string.h>
+
+#include <pkgmgr/pkgmgr_parser.h>
+#include <widget-manifest-parser/widget-manifest-parser.h>
+
+#include <cstdio>
+#include <cstdlib>
+#include <iostream>
+
+#include "common/app_installer.h"
+#include "common/context_installer.h"
+#include "common/step/step.h"
+
+namespace wgt {
+namespace parse {
+
+//TODO MAYBE fill later
+//ConfigFileParser::ConfigFileParser(char * file) {
+//}
+
+int StepParse::process(common_installer::ContextInstaller* context) {
+  if (!StepParse::Check(context->unpack_directory())) {
+    std::cout << "[Parse] No config.xml" << std::endl;
+    return common_installer::APPINST_R_ERROR;
+  }
+
+  const ManifestData* data = nullptr;
+  const char* error = nullptr;
+  if (!ParseManifest(config_.c_str(), &data, &error)) {
+    std::cout << "[Parse] Parse failed. " <<  error << std::endl;
+    if (!ReleaseData(data, error))
+      std::cout << "[Parse] Release data failed." << std::endl;
+    return common_installer::APPINST_R_ERROR;
+  }
+
+  // Copy data from ManifestData to ContextInstaller
+  context->config_data()->set_application_name(
+      std::string(data->name));
+  context->config_data()->set_required_version(
+      std::string(data->api_version));
+  unsigned int privilege_len;
+  privileges_x *ctx_privileges = context->manifest_data()->privileges;
+
+  if(!ctx_privileges) {
+    privileges_x *privileges = reinterpret_cast<privileges_x*>(
+        malloc(sizeof(privileges_x)));
+    if(!privileges)
+      return common_installer::APPINST_R_ERROR;
+
+    memset(privileges, '\0', sizeof(privileges_x));
+    LISTADD(ctx_privileges, privileges);
+    context->manifest_data()->privileges = ctx_privileges;
+  }
+  for (unsigned int i = 0; i < data->privilege_count; ++i) {
+    privilege_x *privilege = reinterpret_cast<privilege_x*>(
+        malloc(sizeof(privilege_x)));
+    if(!privilege)
+      return common_installer::APPINST_R_ERROR;
+
+    privilege_len = strlen(data->privilege_list[i]);
+    char* tmp = reinterpret_cast<char*>(malloc(privilege_len + 1));
+    if(!tmp)
+      return common_installer::APPINST_R_ERROR;
+
+    strcpy(tmp, data->privilege_list[i]);
+    memset(privilege, '\0', sizeof(privilege_x));
+    privilege->text = const_cast<const char*>(tmp);
+    LISTADD(ctx_privileges->privilege, privilege);
+  }
+
+  //--- Test ---
+  std::cout << "[Parse] Read data -[ " << std::endl;
+  std::cout << "  package     = " <<  data->package << std::endl;
+  std::cout << "  id          = " <<  data->id << std::endl;
+  std::cout << "  name        = " <<  data->name << std::endl;
+  std::cout << "  short_name  = " <<  data->short_name << std::endl;
+  std::cout << "  version     = " <<  data->version << std::endl;
+  std::cout << "  icon        = " <<  data->icon << std::endl;
+  std::cout << "  api_version = " <<  data->api_version << std::endl;
+  std::cout << "  privileges -[" << std::endl;
+  for (unsigned int i = 0; i < data->privilege_count; ++i)
+    std::cout << "    " << data->privilege_list[i] << std::endl;
+  std::cout << "  ]-" << std::endl;
+  std::cout << "]-" << std::endl;
+  //--- End Test ---
+
+  if (!ReleaseData(data, error)) {
+    std::cout << "[Parse] Release data failed." << std::endl;
+    return common_installer::APPINST_R_ERROR;
+  }
+
+  return common_installer::APPINST_R_OK;
+}
+
+bool StepParse::Check(const boost::filesystem::path& widget_path) {
+  boost::filesystem::path config = widget_path;
+  config /= "config.xml";
+
+  std::cout << "[Parse] config.xml path: " << config << std::endl;
+
+  if(!boost::filesystem::exists(config))
+    return false;
+
+  config_ = config;
+  return true;
+}
+
+}  // namespace parse
+}  // namespace wgt
diff --git a/src/wgt/step/step_parse.h b/src/wgt/step/step_parse.h
new file mode 100644 (file)
index 0000000..8e3c588
--- /dev/null
@@ -0,0 +1,37 @@
+/* 2014, Copyright © Samsung, license APACHE-2.0, see LICENSE file */
+
+#ifndef WGT_STEP_STEP_PARSE_H_
+#define WGT_STEP_STEP_PARSE_H_
+
+#include <boost/filesystem.hpp>
+
+#include "common/app_installer.h"
+#include "common/context_installer.h"
+#include "common/step/step.h"
+
+namespace wgt {
+namespace parse {
+
+//TODO MAYBE fill later
+//class ConfigFileParser {
+// public:
+//  ConfigFileParser(char * file);
+//};
+
+class StepParse: public common_installer::Step {
+ public:
+  StepParse() {}
+
+  int process(common_installer::ContextInstaller* context) override;
+  int clean(common_installer::ContextInstaller*) override { return 0; }
+  int undo(common_installer::ContextInstaller*) override { return 0; }
+
+ private:
+  boost::filesystem::path config_;
+  bool Check(const boost::filesystem::path& widget_path);
+};
+
+}  // namespace parse
+}  // namespace wgt
+
+#endif  // WGT_STEP_STEP_PARSE_H_
diff --git a/src/wgt/step_parse.cc b/src/wgt/step_parse.cc
deleted file mode 100644 (file)
index d8b7c2e..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
-
-#include <iostream>
-#include <cstdio>
-#include <cstdlib>
-
-#include "common/app_installer.h"
-#include "common/step.h"
-
-namespace {
-
-API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest) {
-  _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
-  xmlTextReaderPtr reader;
-  manifest_x *mfx = NULL;
-
-  reader = xmlReaderForFile(manifest, NULL, 0);
-  if (reader) {
-    mfx = malloc(sizeof(manifest_x));
-    if (mfx) {
-      memset(mfx, '\0', sizeof(manifest_x));
-      if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
-        _LOGD("Parsing Failed\n");
-        pkgmgr_parser_free_manifest_xml(mfx);
-        mfx = NULL;
-      } else {
-        _LOGD("Parsing Success\n");
-      }
-    } else {
-      _LOGD("Memory allocation error\n");
-    }
-    xmlFreeTextReader(reader);
-  } else {
-    _LOGD("Unable to create xml reader\n");
-  }
-  return mfx;
-}
-
-}  // namespace
-
-namespace wgt {
-namespace parse {
-
-Class ConfigFileParser {
-ConfigFileParser(char * file) {
-}
-}
-
-class Step {
-// process
-
-// clean
-
-// undo
-};
-
-}  // namespace parse
-}  // namespace wgt
index 745c7e6..e407dcf 100644 (file)
@@ -16,6 +16,7 @@
 #include "common/step/step_unzip.h"
 #include "common/step/step_signature.h"
 #include "common/step/step_copy.h"
+#include "wgt/step/step_parse.h"
 
 int main(int argc, char **argv) {
   /* get request data */
@@ -46,6 +47,10 @@ int main(int argc, char **argv) {
               new common_installer::signature::StepSignature);
       installer->AddStep(step_signature.get());
 
+      wgt::parse::StepParse* step_parse = new
+              wgt::parse::StepParse();
+      installer->AddStep(step_parse);
+
       common_installer::copy::StepCopy* step_copy =
           new common_installer::copy::StepCopy();
       installer->AddStep(step_copy);
@@ -53,7 +58,9 @@ int main(int argc, char **argv) {
       installer->Run();
 
       delete step_unpack;
+      delete step_parse;
       delete step_copy;
+      delete installer;
       break;
     }
     case PKGMGR_REQ_UNINSTALL: {