add getting detail information from widget file.
authorSoyoung Kim <sy037.kim@samsung.com>
Sat, 16 Mar 2013 11:28:56 +0000 (20:28 +0900)
committerGerrit Code Review <gerrit2@kim11>
Mon, 18 Mar 2013 11:15:10 +0000 (20:15 +0900)
[Issue#] DCM-335
[Problem] N/A
[Cause] N/A
[Solution] provide wgt plugin API for pkgmgr.
this function need for getting information from widget package.
[SCMRequest] N/A

Change-Id: If23a281624d05bfc1dd90c7f04aed4f33a401682

packaging/wrt-installer.spec
src/pkg-manager/CMakeLists.txt
src/pkg-manager/backendlib.cpp

index 6dbcf08..fb612c3 100644 (file)
@@ -28,6 +28,7 @@ BuildRequires:  pkgconfig(libpcrecpp)
 BuildRequires:  pkgconfig(pkgmgr-installer)
 BuildRequires:  pkgconfig(pkgmgr-parser)
 BuildRequires:  pkgconfig(pkgmgr-types)
+BuildRequires:  pkgconfig(pkgmgr)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(cert-svc)
 BuildRequires:  pkgconfig(utilX)
index eb754ea..a0efdbb 100755 (executable)
 
 SET(BACKLIB_SRCS
     backendlib.cpp
+    ${PROJECT_SOURCE_DIR}/src/configuration_parser/widget_parser.cpp
+    ${PROJECT_SOURCE_DIR}/src/configuration_parser/parser_runner.cpp
+    ${PROJECT_SOURCE_DIR}/src/configuration_parser/ignoring_parser.cpp
+    ${PROJECT_SOURCE_DIR}/src/configuration_parser/deny_all_parser.cpp
+    ${PROJECT_SOURCE_DIR}/src/configuration_parser/libiriwrapper.cpp
 )
 
 PKG_CHECK_MODULES(WRT_BACKLIB_PKGS
@@ -25,11 +30,13 @@ PKG_CHECK_MODULES(WRT_BACKLIB_PKGS
     dpl-utils-efl
     pkgmgr-installer
     pkgmgr-types
+    pkgmgr
     dlog
     REQUIRED)
 
 INCLUDE_DIRECTORIES(
     ${WRT_BACKLIB_PKGS_INCLUDE_DIRS}
+    ${PROJECT_SOURCE_DIR}/src/configuration_parser
 )
 
 ADD_LIBRARY(${TARGET_BACKEND_LIB} SHARED
index 37952c1..53b2ba6 100644 (file)
@@ -23,6 +23,7 @@
  *             to package manager
  */
 #include "package-manager-plugin.h"
+#include <package-manager.h>
 #include <regex.h>
 #include <dlog.h>
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <dpl/foreach.h>
 #include <dpl/utils/folder_size.h>
 #include <dpl/wrt-dao-ro/wrt_db_types.h>
+#include <dpl/copy.h>
+#include <dpl/abstract_waitable_input_adapter.h>
+#include <dpl/abstract_waitable_output_adapter.h>
+#include <dpl/zip_input.h>
+#include <dpl/binary_queue.h>
+#include <dpl/file_input.h>
+#include <dpl/wrt-dao-ro/config_parser_data.h>
+#include "root_parser.h"
+#include "widget_parser.h"
+#include "parser_runner.h"
 
 using namespace WrtDB;
 
@@ -66,6 +77,8 @@ static int pkg_plugin_get_app_detail_info_from_package(
     package_manager_pkg_detail_info_t
     *pkg_detail_info);
 
+pkgmgr_info *pkgmgr_client_check_pkginfo_from_file(const char *pkg_path);
+
 static void pkg_native_plugin_on_unload()
 {
     LogDebug("pkg_native_plugin_unload() is called");
@@ -221,13 +234,212 @@ static int pkg_plugin_get_app_detail_info(
     return TRUE;
 }
 
+int getConfigParserData(const std::string &widgetPath, ConfigParserData& configInfo)
+{
+    const char* CONFIG_XML = "config.xml";
+    const char* WITH_OSP_XML = "res/wgt/config.xml";
+
+    Try {
+        ParserRunner parser;
+
+        std::unique_ptr<DPL::ZipInput> zipFile(
+                new DPL::ZipInput(widgetPath));
+
+        std::unique_ptr<DPL::ZipInput::File> configFile;
+
+        // Open config.xml file
+        Try {
+            configFile.reset(zipFile->OpenFile(CONFIG_XML));
+        }
+        Catch(DPL::ZipInput::Exception::OpenFileFailed)
+        {
+            configFile.reset(zipFile->OpenFile(WITH_OSP_XML));
+        }
+
+        // Extract config
+        DPL::BinaryQueue buffer;
+        DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
+        DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
+        DPL::Copy(&inputAdapter, &outputAdapter);
+        parser.Parse(&buffer,
+                ElementParserPtr(
+                    new RootParser<WidgetParser>(configInfo,
+                        DPL::
+                        FromUTF32String(
+                            L"widget"))));
+    }
+    Catch(DPL::ZipInput::Exception::OpenFailed)
+    {
+        LogError("Failed to open widget package");
+        return FALSE;
+    }
+    Catch(DPL::ZipInput::Exception::OpenFileFailed)
+    {
+        LogError("Failed to open config.xml file");
+        return FALSE;
+    }
+    Catch(DPL::CopyFailed)
+    {
+        LogError("Failed to extract config.xml file");
+        return FALSE;
+    }
+    Catch(DPL::FileInput::Exception::OpenFailed)
+    {
+        LogError("Failed to open config.xml file");
+        return FALSE;
+    }
+    Catch(ElementParser::Exception::ParseError)
+    {
+        LogError("Failed to parse config.xml file");
+        return FALSE;
+    }
+    Catch(DPL::ZipInput::Exception::SeekFileFailed)
+    {
+        LogError("Failed to seek widget archive - corrupted package?");
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+char* getIconInfo(const std::string widgetPath,
+        const std::string icon_name, int &icon_size)
+{
+    Try {
+        std::unique_ptr<DPL::ZipInput> zipFile(
+                new DPL::ZipInput(widgetPath));
+
+        std::unique_ptr<DPL::ZipInput::File> iconFile;
+
+        iconFile.reset(zipFile->OpenFile(icon_name));
+
+        DPL::BinaryQueue buffer;
+        DPL::AbstractWaitableInputAdapter inputAdapter(iconFile.get());
+        DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
+        DPL::Copy(&inputAdapter, &outputAdapter);
+        icon_size = buffer.Size();
+        char *getBuffer = (char*) calloc(1, (sizeof(char) * icon_size) + 1);
+        buffer.Flatten(getBuffer, buffer.Size());
+        return getBuffer;
+    }
+    Catch(DPL::ZipInput::Exception::OpenFailed)
+    {
+        LogError("Failed to open widget package");
+        return NULL;
+    }
+    Catch(DPL::ZipInput::Exception::OpenFileFailed)
+    {
+        LogError("Failed to open icon file");
+        return NULL;
+    }
+}
+
+int getWidgetDetailInfoFromPackage(const char* pkgPath,
+        package_manager_pkg_detail_info_t* pkg_detail_info)
+{
+    const std::string widget_path(pkgPath);
+    ConfigParserData configInfo;
+
+    if (FALSE == getConfigParserData(widget_path, configInfo)) {
+        return FALSE;
+    }
+
+    strncpy(pkg_detail_info->pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX);
+    if (!configInfo.tizenPkgId.IsNull()) {
+        strncpy(pkg_detail_info->pkgid,
+                DPL::ToUTF8String(*configInfo.tizenPkgId).c_str(), PKG_TYPE_STRING_LEN_MAX);
+    }
+    if (!configInfo.version.IsNull()) {
+        strncpy(pkg_detail_info->version,
+                DPL::ToUTF8String(*configInfo.version).c_str(),
+                PKG_VERSION_STRING_LEN_MAX);
+    }
+
+    DPL::Optional<DPL::String> name;
+    DPL::Optional<DPL::String> desc;
+    DPL::OptionalString defaultLocale = configInfo.defaultlocale;
+
+    FOREACH(localizedData, configInfo.localizedDataSet)
+    {
+        Locale i = localizedData->first;
+        if (!!defaultLocale) {
+            if (defaultLocale == i) {
+                name = localizedData->second.name;
+                desc = localizedData->second.description;
+                break;
+            }
+        } else {
+            name = localizedData->second.name;
+            desc = localizedData->second.description;
+            break;
+        }
+    }
+
+    if( !name.IsNull()) {
+        strncpy(pkg_detail_info->pkg_name, DPL::ToUTF8String(*name).c_str(), PKG_NAME_STRING_LEN_MAX);
+    }
+
+    if (!desc.IsNull()) {
+        strncpy(pkg_detail_info->pkg_description,
+                DPL::ToUTF8String(*desc).c_str(),
+                PKG_VALUE_STRING_LEN_MAX - 1);
+    }
+
+    if (!configInfo.tizenMinVersionRequired.IsNull()) {
+        strncpy(pkg_detail_info->min_platform_version,
+                DPL::ToUTF8String(*configInfo.tizenMinVersionRequired).c_str(),
+                PKG_VERSION_STRING_LEN_MAX);
+    }
+
+    if (!configInfo.authorName.IsNull()) {
+        strncpy(pkg_detail_info->author,
+                DPL::ToUTF8String(*configInfo.authorName).c_str(),
+                PKG_VALUE_STRING_LEN_MAX);
+    }
+
+    std::string icon_name;
+
+    FOREACH(i, configInfo.iconsList) {
+        LogDebug("icon name: " << i->src);
+        icon_name = DPL::ToUTF8String(i->src);
+        break;
+    }
+    pkg_detail_info->icon_buf = getIconInfo(widget_path, icon_name,
+            pkg_detail_info->icon_size);
+    LogDebug("icon size : " << pkg_detail_info->icon_size);
+
+    GList *privilege_list = NULL;
+    FOREACH(it, configInfo.featuresList) {
+        LogDebug("privilege : " << it->name);
+        int length = DPL::ToUTF8String(it->name).length();
+        char *privilege = (char*) calloc(1, (sizeof(char) * length) + 1);
+        snprintf(privilege, length + 1, "%s",
+                DPL::ToUTF8String(it->name).c_str());
+        privilege_list = g_list_append(privilege_list, privilege);
+    }
+    pkg_detail_info->privilege_list = privilege_list;
+
+    return TRUE;
+}
+
 static int pkg_plugin_get_app_detail_info_from_package(
-    const char * /*pkg_path*/,
-    package_manager_pkg_detail_info_t * /*pkg_detail_info*/)
+    const char * pkg_path,
+    package_manager_pkg_detail_info_t * pkg_detail_info)
 {
     LogDebug("pkg_plugin_get_app_detail_info_from_package() is called");
+    return getWidgetDetailInfoFromPackage(pkg_path, pkg_detail_info);
+}
 
-    return TRUE;
+pkgmgr_info *pkgmgr_client_check_pkginfo_from_file(const char *pkg_path)
+{
+    LogDebug("pkgmgr_client_check_pkginfo_from_file() is called");
+    package_manager_pkg_detail_info_t pkg_detail_info;
+    int ret = getWidgetDetailInfoFromPackage(pkg_path, &pkg_detail_info);
+    if (FALSE == ret) {
+        LogError("Failed to get package detail info ");
+        return NULL;
+    }
+    return &pkg_detail_info;
 }
 
 __attribute__ ((visibility("default")))