From c5cfe265d4e3e4a39c9dc3122bda8511d4ff919a Mon Sep 17 00:00:00 2001 From: Soyoung Kim Date: Sat, 16 Mar 2013 20:28:56 +0900 Subject: [PATCH] add getting detail information from widget file. [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 | 1 + src/pkg-manager/CMakeLists.txt | 7 ++ src/pkg-manager/backendlib.cpp | 218 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 223 insertions(+), 3 deletions(-) diff --git a/packaging/wrt-installer.spec b/packaging/wrt-installer.spec index 6dbcf08..fb612c3 100644 --- a/packaging/wrt-installer.spec +++ b/packaging/wrt-installer.spec @@ -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) diff --git a/src/pkg-manager/CMakeLists.txt b/src/pkg-manager/CMakeLists.txt index eb754ea..a0efdbb 100755 --- a/src/pkg-manager/CMakeLists.txt +++ b/src/pkg-manager/CMakeLists.txt @@ -16,6 +16,11 @@ 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 diff --git a/src/pkg-manager/backendlib.cpp b/src/pkg-manager/backendlib.cpp index 37952c1..53b2ba6 100644 --- a/src/pkg-manager/backendlib.cpp +++ b/src/pkg-manager/backendlib.cpp @@ -23,6 +23,7 @@ * to package manager */ #include "package-manager-plugin.h" +#include #include #include #include @@ -37,6 +38,16 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#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 zipFile( + new DPL::ZipInput(widgetPath)); + + std::unique_ptr 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(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 zipFile( + new DPL::ZipInput(widgetPath)); + + std::unique_ptr 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 name; + DPL::Optional 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"))) -- 2.7.4