From: Tomasz Iwanek Date: Wed, 7 Oct 2015 08:13:43 +0000 (+0200) Subject: Use GList in manifest_x structures X-Git-Tag: accepted/tizen/mobile/20151027.055537^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4bdf0c07f63b846633578f1fac610feebcd684e0;p=platform%2Fcore%2Fappfw%2Fapp-installers.git Use GList in manifest_x structures This is adjustment to following commit: - https://review.tizen.org/gerrit/#/c/49085/ Changes should be submitted together. Change-Id: I0834960bf882e1335109d9208b4970dbc03ede1e --- diff --git a/src/common/security_registration.cc b/src/common/security_registration.cc index f62481d..924bd54 100644 --- a/src/common/security_registration.cc +++ b/src/common/security_registration.cc @@ -11,7 +11,7 @@ #include #include -#include "common/utils/clist_helpers.h" +#include "common/utils/glist_range.h" #include "common/utils/logging.h" namespace bf = boost::filesystem; @@ -64,14 +64,8 @@ bool PrepareRequest(const std::string& app_id, const std::string& pkg_id, } if (manifest) { - privileges_x *privileges = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(manifest->privileges, privileges); - for (; privileges != nullptr; privileges = privileges->next) { - privilege_x* priv = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(privileges->privilege, priv); - for (; priv != nullptr; priv = priv->next) { - security_manager_app_inst_req_add_privilege(req, priv->text); - } + for (const char* priv : GListRange(manifest->privileges)) { + security_manager_app_inst_req_add_privilege(req, priv); } } @@ -146,8 +140,7 @@ namespace common_installer { bool RegisterSecurityContextForApps( const std::string& pkg_id, const boost::filesystem::path& path, manifest_x* manifest) { - for (application_x* app = manifest->application; - app != nullptr; app = app->next) { + for (application_x* app : GListRange(manifest->application)) { if (!app->appid) { return false; } @@ -161,8 +154,7 @@ bool RegisterSecurityContextForApps( bool UnregisterSecurityContextForApps( const std::string& pkg_id, manifest_x* manifest) { - for (application_x* app = manifest->application; - app != nullptr; app = app->next) { + for (application_x* app : GListRange(manifest->application)) { if (!app->appid) { return false; } diff --git a/src/common/step/step_backup_icons.cc b/src/common/step/step_backup_icons.cc index 284cec7..d7691aa 100755 --- a/src/common/step/step_backup_icons.cc +++ b/src/common/step/step_backup_icons.cc @@ -11,6 +11,7 @@ #include "common/backup_paths.h" #include "common/utils/file_util.h" +#include "common/utils/glist_range.h" namespace bf = boost::filesystem; namespace bs = boost::system; @@ -19,19 +20,21 @@ namespace common_installer { namespace backup { Step::Status StepBackupIcons::process() { - application_x* app = context_->old_manifest_data.get()->application; - // gather icon info - for (; app != nullptr; app = app->next) { + for (application_x* app : + GListRange( + context_->old_manifest_data.get()->application)) { if (strcmp(app->component_type, "uiapp") != 0) continue; bf::path app_icon = bf::path(getIconPath(context_->uid.get())) / bf::path(app->appid); - if (app->icon && app->icon->text) - app_icon += bf::path(app->icon->text).extension(); - else + if (app->icon) { + icon_x* icon = reinterpret_cast(app->icon->data); + app_icon += bf::path(icon->text).extension(); + } else { app_icon += ".png"; + } bf::path icon_backup = GetBackupPathForIconFile(app_icon); if (bf::exists(app_icon)) icons_.emplace_back(app_icon, icon_backup); diff --git a/src/common/step/step_check_signature.cc b/src/common/step/step_check_signature.cc index dca62eb..837e5c6 100644 --- a/src/common/step/step_check_signature.cc +++ b/src/common/step/step_check_signature.cc @@ -16,7 +16,7 @@ #include #include -#include "common/utils/clist_helpers.h" +#include "common/utils/glist_range.h" namespace bf = boost::filesystem; @@ -106,21 +106,9 @@ common_installer::Step::Status ValidateSignatureFile( } bool ValidatePrivilegeLevel(common_installer::PrivilegeLevel level, - bool is_webapp, const char* api_version, privileges_x *privileges) { - GList* list = nullptr; - privileges_x* pvlg = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(privileges, pvlg); - for (; pvlg != nullptr; pvlg = pvlg->next) { - privilege_x* pv = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(pvlg->privilege, pv); - for (; pv != nullptr; pv = pv->next) { - list = g_list_append(list, const_cast(pv->text)); - } - } - + bool is_webapp, const char* api_version, GList* privileges) { if (level == common_installer::PrivilegeLevel::UNTRUSTED) { - if (list) { - g_list_free(list); + if (privileges) { LOG(ERROR) << "Untrusted application cannot declare privileges"; return false; } else { @@ -130,12 +118,11 @@ bool ValidatePrivilegeLevel(common_installer::PrivilegeLevel level, char* error = nullptr; int status = PRVMGR_ERR_NONE; - if (list) { // Do the privilege check only if the package has privileges + // Do the privilege check only if the package has privileges + if (privileges) { status = privilege_manager_verify_privilege(api_version, - is_webapp ? PRVMGR_PACKAGE_TYPE_WRT : PRVMGR_PACKAGE_TYPE_CORE, list, - PrivilegeLevelToVisibility(level), - &error); - g_list_free(list); + is_webapp ? PRVMGR_PACKAGE_TYPE_WRT : PRVMGR_PACKAGE_TYPE_CORE, + privileges, PrivilegeLevelToVisibility(level), &error); } if (status != PRVMGR_ERR_NONE) { LOG(ERROR) << "Error while verifing privilege level: " << error; diff --git a/src/common/step/step_create_icons.cc b/src/common/step/step_create_icons.cc index f321c15..e1c4912 100644 --- a/src/common/step/step_create_icons.cc +++ b/src/common/step/step_create_icons.cc @@ -8,7 +8,7 @@ #include #include -#include "common/utils/clist_helpers.h" +#include "common/utils/glist_range.h" namespace bf = boost::filesystem; namespace bs = boost::system; @@ -27,17 +27,16 @@ Step::Status StepCreateIcons::process() { } } - application_x* app = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(context_->manifest_data.get()->application, - app); - for (; app; app = app->next) { + for (application_x* app : + GListRange(context_->manifest_data.get()->application)) { if (strcmp(app->component_type, "uiapp") != 0) continue; // TODO(t.iwanek): this is ignoring icon locale as well as other steps // icons should be localized - if (app->icon && app->icon->text) { - bf::path source = GetIconRoot() / app->icon->text; + if (app->icon) { + icon_x* icon = reinterpret_cast(app->icon->data); + bf::path source = GetIconRoot() / icon->text; if (bf::exists(source)) { bf::path destination = icons_directory / app->appid; if (source.has_extension()) diff --git a/src/common/step/step_generate_xml.cc b/src/common/step/step_generate_xml.cc index 5529cbd..53f36a2 100755 --- a/src/common/step/step_generate_xml.cc +++ b/src/common/step/step_generate_xml.cc @@ -18,8 +18,8 @@ #include #include -#include "common/utils/clist_helpers.h" #include "common/utils/file_util.h" +#include "common/utils/glist_range.h" namespace bs = boost::system; namespace bf = boost::filesystem; @@ -69,22 +69,20 @@ common_installer::Step::Status StepGenerateXml::GenerateApplicationCommonXml( WriteServiceApplicationAttributes(writer, app); else WriteUIApplicationAttributes(writer, app); - if (app->label) { - label_x* label = nullptr; - LISTHEAD(app->label, label); - for (; label; label = label->next) { - xmlTextWriterStartElement(writer, BAD_CAST "label"); - if (label->lang && strlen(label->lang)) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", - BAD_CAST label->lang); - } - xmlTextWriterWriteString(writer, BAD_CAST label->name); - xmlTextWriterEndElement(writer); + + for (label_x* label : GListRange(app->label)) { + xmlTextWriterStartElement(writer, BAD_CAST "label"); + if (label->lang && strlen(label->lang)) { + xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", + BAD_CAST label->lang); } + xmlTextWriterWriteString(writer, BAD_CAST label->name); + xmlTextWriterEndElement(writer); } // icon is renamed to - if (app->icon && app->icon->text) { + if (app->icon) { + icon_x* iconx = reinterpret_cast(app->icon->data); bf::path app_icon = context_->pkg_path.get(); // TODO(t.iwanek): type should not be used here if (context_->pkg_type.get() == "wgt") { @@ -92,7 +90,7 @@ common_installer::Step::Status StepGenerateXml::GenerateApplicationCommonXml( } else { app_icon /= "shared/res"; } - app_icon /= app->icon->text; + app_icon /= iconx->text; bf::path icon = app->appid; if (app_icon.has_extension()) icon += app_icon.extension(); @@ -108,9 +106,7 @@ common_installer::Step::Status StepGenerateXml::GenerateApplicationCommonXml( LOG(DEBUG) << "Icon was not found in package"; } - appcontrol_x* appc = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(app->appcontrol, appc); - for (; appc != nullptr; appc = appc->next) { + for (appcontrol_x* appc : GListRange(app->appcontrol)) { xmlTextWriterStartElement(writer, BAD_CAST "app-control"); if (appc->operation) { @@ -137,9 +133,8 @@ common_installer::Step::Status StepGenerateXml::GenerateApplicationCommonXml( xmlTextWriterEndElement(writer); } - datacontrol_x* datacontrol = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(app->datacontrol, datacontrol); - for (; datacontrol != nullptr; datacontrol = datacontrol->next) { + for (datacontrol_x* datacontrol : + GListRange(app->datacontrol)) { xmlTextWriterStartElement(writer, BAD_CAST "datacontrol"); if (datacontrol->access) { xmlTextWriterWriteAttribute(writer, BAD_CAST "access", @@ -156,9 +151,7 @@ common_installer::Step::Status StepGenerateXml::GenerateApplicationCommonXml( xmlTextWriterEndElement(writer); } - metadata_x* meta = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(app->metadata, meta); - for (; meta; meta = meta->next) { + for (metadata_x* meta : GListRange(app->metadata)) { xmlTextWriterStartElement(writer, BAD_CAST "metadata"); xmlTextWriterWriteAttribute(writer, BAD_CAST "key", BAD_CAST meta->key); @@ -168,12 +161,9 @@ common_installer::Step::Status StepGenerateXml::GenerateApplicationCommonXml( xmlTextWriterEndElement(writer); } - category_x* category = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(app->category, category); - for (; category; category = category->next) { + for (const char* category : GListRange(app->category)) { xmlTextWriterStartElement(writer, BAD_CAST "category"); - xmlTextWriterWriteAttribute(writer, BAD_CAST "name", - BAD_CAST category->name); + xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST category); xmlTextWriterEndElement(writer); } @@ -239,57 +229,46 @@ common_installer::Step::Status StepGenerateXml::process() { xmlTextWriterWriteAttribute(writer, BAD_CAST "api-version", BAD_CAST context_->manifest_data.get()->api_version); - if (context_->manifest_data.get()->label) { - label_x* label = nullptr; - LISTHEAD(context_->manifest_data.get()->label, label); - for (; label; label = label->next) { - xmlTextWriterStartElement(writer, BAD_CAST "label"); - if (label->lang && strlen(label->lang)) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", - BAD_CAST label->lang); - } - xmlTextWriterWriteString(writer, BAD_CAST label->name); - xmlTextWriterEndElement(writer); + for (label_x* label : + GListRange(context_->manifest_data.get()->label)) { + xmlTextWriterStartElement(writer, BAD_CAST "label"); + if (label->lang && strlen(label->lang)) { + xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", + BAD_CAST label->lang); } + xmlTextWriterWriteString(writer, BAD_CAST label->name); + xmlTextWriterEndElement(writer); } - if (context_->manifest_data.get()->author) { - author_x* author = nullptr; - LISTHEAD(context_->manifest_data.get()->author, author); - for (; author; author = author->next) { - xmlTextWriterStartElement(writer, BAD_CAST "author"); - if (author->email && strlen(author->email)) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "email", - BAD_CAST author->email); - } - if (author->href && strlen(author->href)) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "href", - BAD_CAST author->href); - } - xmlTextWriterWriteString(writer, BAD_CAST author->text); - xmlTextWriterEndElement(writer); + for (author_x* author : + GListRange(context_->manifest_data.get()->author)) { + xmlTextWriterStartElement(writer, BAD_CAST "author"); + if (author->email && strlen(author->email)) { + xmlTextWriterWriteAttribute(writer, BAD_CAST "email", + BAD_CAST author->email); } + if (author->href && strlen(author->href)) { + xmlTextWriterWriteAttribute(writer, BAD_CAST "href", + BAD_CAST author->href); + } + xmlTextWriterWriteString(writer, BAD_CAST author->text); + xmlTextWriterEndElement(writer); } - if (context_->manifest_data.get()->description) { - description_x* description = nullptr; - LISTHEAD(context_->manifest_data.get()->description, description); - for (; description; description = description->next) { - xmlTextWriterStartElement(writer, BAD_CAST "description"); - if (description->lang && strlen(description->lang)) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", - BAD_CAST description->lang); - } - xmlTextWriterWriteString(writer, BAD_CAST description->name); - xmlTextWriterEndElement(writer); + for (description_x* description : + GListRange(context_->manifest_data.get()->description)) { + xmlTextWriterStartElement(writer, BAD_CAST "description"); + if (description->lang && strlen(description->lang)) { + xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", + BAD_CAST description->lang); } + xmlTextWriterWriteString(writer, BAD_CAST description->name); + xmlTextWriterEndElement(writer); } // add application - application_x* app = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(context_->manifest_data.get()->application, - app); - for (; app; app = app->next) { + for (application_x* app : + GListRange(context_->manifest_data.get()->application)) { bool is_service = false; if (strcmp(app->component_type, "uiapp") == 0) { xmlTextWriterStartElement(writer, BAD_CAST "ui-application"); @@ -306,17 +285,12 @@ common_installer::Step::Status StepGenerateXml::process() { } // add privilege element - privileges_x* pvlg = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD( - context_->manifest_data.get()->privileges, - pvlg); - for (; pvlg != nullptr; pvlg = pvlg->next) { + if (context_->manifest_data.get()->privileges) { xmlTextWriterStartElement(writer, BAD_CAST "privileges"); - privilege_x* pv = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(pvlg->privilege, pv); - for (; pv != nullptr; pv = pv->next) { + for (const char* priv : + GListRange(context_->manifest_data.get()->privileges)) { xmlTextWriterWriteFormatElement(writer, BAD_CAST "privilege", - "%s", BAD_CAST pv->text); + "%s", BAD_CAST priv); } xmlTextWriterEndElement(writer); } diff --git a/src/common/step/step_kill_apps.cc b/src/common/step/step_kill_apps.cc index 1981967..a5aec31 100644 --- a/src/common/step/step_kill_apps.cc +++ b/src/common/step/step_kill_apps.cc @@ -9,7 +9,7 @@ #include -#include "common/utils/clist_helpers.h" +#include "common/utils/glist_range.h" namespace { @@ -48,12 +48,9 @@ namespace pkgmgr { Step::Status StepKillApps::process() { manifest_x* old_manifest = context_->old_manifest_data.get() ? context_->old_manifest_data.get() : context_->manifest_data.get(); - application_x* ui = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(old_manifest->application, ui); - for (; ui; ui = ui->next) { - if (!ui->appid) - continue; - (void) KillApp(ui->appid); + for (application_x* app : + GListRange(old_manifest->application)) { + (void) KillApp(app->appid); } return Status::OK; } diff --git a/src/common/step/step_privilege_compatibility.cc b/src/common/step/step_privilege_compatibility.cc index b1eb396..baef0bc 100644 --- a/src/common/step/step_privilege_compatibility.cc +++ b/src/common/step/step_privilege_compatibility.cc @@ -12,7 +12,7 @@ #include #include -#include "common/utils/clist_helpers.h" +#include "common/utils/glist_range.h" namespace { @@ -24,23 +24,6 @@ const char kPrivForPartner[] = const char kPrivForPlatform[] = "http://tizen.org/privilege/internal/default/platform"; -bool AddPrivilegeToList(manifest_x* m, const char* priv_str) { - if (!m->privileges) { - m->privileges = - reinterpret_cast(calloc(1, sizeof(privileges_x*))); - if (!m->privileges) - return false; - } - privilege_x* priv = - reinterpret_cast(calloc(1, sizeof(privilege_x))); - if (!priv) - return false; - - priv->text = strdup(priv_str); - LISTADD(m->privileges->privilege, priv); - return true; -} - bool TranslatePrivilegesForCompatibility(manifest_x* m) { if (!m->api_version) { LOG(WARNING) << "Skipping privileges mapping because api-version " @@ -50,26 +33,17 @@ bool TranslatePrivilegesForCompatibility(manifest_x* m) { if (strcmp(m->api_version, kPlatformVersion) == 0) return true; - // calculate number of privileges - size_t size = 0; - privileges_x *privileges = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(m->privileges, privileges); - for (; privileges; privileges = privileges->next) { - privilege_x* priv = privileges->privilege; - size += PKGMGR_LIST_LEN(priv); + // No privileges to map + if (!m->privileges) { + return true; } // prepare input structure - std::unique_ptr input_privileges(new const char*[size]); + std::unique_ptr input_privileges( + new const char*[g_list_length(m->privileges)]); size_t input_size = 0; - privileges = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(m->privileges, privileges); - for (; privileges; privileges = privileges->next) { - privilege_x* priv = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(privileges->privilege, priv); - for (; priv; priv = priv->next) { - input_privileges[input_size++] = priv->text; - } + for (const char* priv : GListRange(m->privileges)) { + input_privileges[input_size++] = priv; } // get mapping @@ -82,32 +56,11 @@ bool TranslatePrivilegesForCompatibility(manifest_x* m) { return false; } - // delete pkgmgr old list - privileges = nullptr; - privileges_x* privileges_next = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(m->privileges, privileges); - for (; privileges; privileges = privileges_next) { - privileges_next = privileges->next; - privilege_x* priv = nullptr; - privilege_x* next = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(privileges->privilege, priv); - for (; priv; priv = next) { - next = priv->next; - // mark as const but we actually have ownership - free(const_cast(priv->text)); - free(priv); - } - free(privileges); - } - // set pkgmgr new list - m->privileges = - reinterpret_cast(calloc(1, sizeof(privileges_x))); + g_list_free_full(m->privileges, free); + m->privileges = nullptr; for (size_t i = 0; i < output_size; ++i) { - privilege_x* priv = - reinterpret_cast(calloc(1, sizeof(privilege_x))); - priv->text = strdup(output_privileges[i]); - LISTADD(m->privileges->privilege, priv); + m->privileges = g_list_append(m->privileges, strdup(output_privileges[i])); } security_manager_privilege_mapping_free(output_privileges, output_size); @@ -132,16 +85,19 @@ Step::Status StepPrivilegeCompatibility::process() { bool ret = true; switch (context_->privilege_level.get()) { case common_installer::PrivilegeLevel::PUBLIC: - ret = AddPrivilegeToList(context_->manifest_data.get(), - kPrivForPublic); + context_->manifest_data.get()->privileges = + g_list_append(context_->manifest_data.get()->privileges, + strdup(kPrivForPublic)); break; case common_installer::PrivilegeLevel::PARTNER: - ret = AddPrivilegeToList(context_->manifest_data.get(), - kPrivForPartner); + context_->manifest_data.get()->privileges = + g_list_append(context_->manifest_data.get()->privileges, + strdup(kPrivForPartner)); break; case common_installer::PrivilegeLevel::PLATFORM: - ret = AddPrivilegeToList(context_->manifest_data.get(), - kPrivForPlatform); + context_->manifest_data.get()->privileges = + g_list_append(context_->manifest_data.get()->privileges, + strdup(kPrivForPlatform)); break; default: // No default privileges for untrusted application. diff --git a/src/common/step/step_recover_icons.cc b/src/common/step/step_recover_icons.cc index aaf2dfd..37591bb 100644 --- a/src/common/step/step_recover_icons.cc +++ b/src/common/step/step_recover_icons.cc @@ -9,8 +9,8 @@ #include #include "common/backup_paths.h" -#include "common/utils/clist_helpers.h" #include "common/utils/file_util.h" +#include "common/utils/glist_range.h" namespace bf = boost::filesystem; namespace bs = boost::system; @@ -54,19 +54,19 @@ Step::Status StepRecoverIcons::RecoveryUpdate() { bool StepRecoverIcons::TryGatherIcons() { if (!context_->manifest_data.get()) return false; - application_x* app = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(context_->manifest_data.get()->application, - app); - for (; app != nullptr; app = app->next) { + for (application_x* app : + GListRange(context_->manifest_data.get()->application)) { if (strcmp(app->component_type, "uiapp") != 0) continue; bf::path app_icon = bf::path(getIconPath(context_->uid.get())) / bf::path(app->appid); - if (app->icon && app->icon->text) - app_icon += bf::path(app->icon->text).extension(); - else + if (app->icon) { + icon_x* icon = reinterpret_cast(app->icon->data); + app_icon += bf::path(icon->text).extension(); + } else { app_icon += ".png"; + } bf::path icon_backup = GetBackupPathForIconFile(app_icon); if (bf::exists(icon_backup) || bf::exists(app_icon)) icons_.emplace_back(app_icon, icon_backup); diff --git a/src/common/step/step_remove_icons.cc b/src/common/step/step_remove_icons.cc index 6de1de8..ab29c3d 100644 --- a/src/common/step/step_remove_icons.cc +++ b/src/common/step/step_remove_icons.cc @@ -10,8 +10,8 @@ #include #include "common/backup_paths.h" -#include "common/utils/clist_helpers.h" #include "common/utils/file_util.h" +#include "common/utils/glist_range.h" namespace common_installer { namespace filesystem { @@ -29,19 +29,19 @@ Step::Status StepRemoveIcons::precheck() { } Step::Status StepRemoveIcons::process() { - application_x* app = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(context_->manifest_data.get()->application, - app); - for (; app != nullptr; app = app->next) { + for (application_x* app : + GListRange(context_->manifest_data.get()->application)) { if (strcmp(app->component_type, "uiapp") != 0) continue; bf::path app_icon = bf::path(getIconPath(context_->uid.get())) / bf::path(app->appid); - if (app->icon && app->icon->text) - app_icon += bf::path(app->icon->text).extension(); - else + if (app->icon) { + icon_x* icon = reinterpret_cast(app->icon->data); + app_icon += bf::path(icon->text).extension(); + } else { app_icon += ".png"; + } if (bf::exists(app_icon)) { bf::path backup_icon_file = GetBackupPathForIconFile(app_icon); if (!MoveFile(app_icon, backup_icon_file)) { diff --git a/src/common/utils/clist_helpers.h b/src/common/utils/clist_helpers.h deleted file mode 100644 index 045dd7f..0000000 --- a/src/common/utils/clist_helpers.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2015 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. - -#ifndef COMMON_UTILS_CLIST_HELPERS_H_ -#define COMMON_UTILS_CLIST_HELPERS_H_ - -#include "pkgmgr/pkgmgr_parser.h" - -/* NOTE: For *_x list types in pkgmgr-info, like privileges_x or privilege_x, - * this macro moves the current node to the head of the list. - * This LISTHEAD() macro is defined in pkgmgr_parser.h in pkgmgr-info package. - */ -#define PKGMGR_LIST_MOVE_NODE_TO_HEAD(list, node) \ - do { \ - if (list) { \ - LISTHEAD(list, node); \ - } \ - } while (false) \ - -/* - * Calculates size of C style list from any of its point - */ -#define PKGMGR_LIST_LEN(list) \ - [list]() { \ - size_t size = 0; \ - auto node = list; \ - PKGMGR_LIST_MOVE_NODE_TO_HEAD(list, node); \ - while (node) { \ - node = node->next; \ - ++size; \ - } \ - return size; \ - }() \ - -#endif // COMMON_UTILS_CLIST_HELPERS_H_ diff --git a/src/common/utils/glist_range.h b/src/common/utils/glist_range.h new file mode 100644 index 0000000..af4a410 --- /dev/null +++ b/src/common/utils/glist_range.h @@ -0,0 +1,75 @@ +// Copyright (c) 2015 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. + +#ifndef COMMON_UTILS_GLIST_RANGE_H_ +#define COMMON_UTILS_GLIST_RANGE_H_ + +#include + +#include +#include + +// Range with mutable forward iterator based on GList +// supporting language foreach construct +template +class GListRange { + public: + class Iterator { + public: + typedef T value_type; + typedef T& reference; + typedef T* pointer; + typedef std::size_t difference_type; + typedef std::forward_iterator_tag iterator_category; + + explicit Iterator(std::nullptr_t ptr = nullptr) : ptr_(ptr) { } + explicit Iterator(GList* ptr) : ptr_(ptr) { } + explicit operator bool() const { + return ptr_; + } + const reference& operator*() const { + return reinterpret_cast(ptr_->data); + } + reference& operator*() { + return reinterpret_cast(ptr_->data); + } + const pointer operator->() const { + return reinterpret_cast(&ptr_->data); + } + pointer operator->() { + return reinterpret_cast(&ptr_->data); + } + Iterator& operator++() { + ptr_ = g_list_next(ptr_); + return *this; + } + Iterator operator++(int) { + Iterator iter(ptr_); + ptr_ = g_list_next(ptr_); + return iter; + } + bool operator==(const Iterator& other) const { + return ptr_ == other.ptr_; + } + bool operator!=(const Iterator& other) const { + return !this->operator==(other); + } + + private: + GList* ptr_; + }; + + explicit GListRange(GList* list) : list_(list) { } + Iterator begin() { + return Iterator(list_); + } + Iterator end() { + return Iterator(); + } + + private: + GList* list_; +}; + +#endif // COMMON_UTILS_GLIST_RANGE_H_ diff --git a/src/tpk/step/step_create_symbolic_link.cc b/src/tpk/step/step_create_symbolic_link.cc index 559c7dd..47ed02a 100644 --- a/src/tpk/step/step_create_symbolic_link.cc +++ b/src/tpk/step/step_create_symbolic_link.cc @@ -9,8 +9,8 @@ #include "common/step/step.h" #include "common/app_installer.h" #include "common/installer_context.h" -#include "common/utils/clist_helpers.h" #include "common/utils/file_util.h" +#include "common/utils/glist_range.h" #include "common/utils/logging.h" namespace tpk { @@ -83,9 +83,7 @@ Status StepCreateSymbolicLink::precheck() { Status StepCreateSymbolicLink::process() { manifest_x* m = context_->manifest_data.get(); - application_x* app = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(m->application, app); - for (; app; app = app->next) { + for (application_x* app : GListRange(m->application)) { if (!CreateSymLink(app, context_)) return Status::ERROR; } @@ -96,9 +94,7 @@ Status StepCreateSymbolicLink::process() { Status StepCreateSymbolicLink::undo() { manifest_x* m = context_->manifest_data.get(); Step::Status ret = Status::OK; - application_x* app = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(m->application, app); - for (; app; app = app->next) { + for (application_x* app : GListRange(m->application)) { if (!CreateSymLink(app, context_)) ret = Status::ERROR; } diff --git a/src/tpk/step/step_parse.cc b/src/tpk/step/step_parse.cc index e2dc8e8..68ec2c5 100644 --- a/src/tpk/step/step_parse.cc +++ b/src/tpk/step/step_parse.cc @@ -29,7 +29,7 @@ #include "common/app_installer.h" #include "common/installer_context.h" #include "common/step/step.h" -#include "utils/clist_helpers.h" +#include "common/utils/glist_range.h" namespace tpk { namespace parse { @@ -134,7 +134,7 @@ bool StepParse::FillAuthorInfo(manifest_x* manifest) { author->text = strdup(author_info->name().c_str()); author->email = strdup(author_info->email().c_str()); author->href = strdup(author_info->href().c_str()); - LISTADD(manifest->author, author); + manifest->author = g_list_append(manifest->author, author); return true; } @@ -152,7 +152,7 @@ bool StepParse::FillDescription(manifest_x* manifest) { (calloc(1, sizeof(description_x))); description->text = strdup(description_info->description().c_str()); description->lang = strdup(description_info->xml_lang().c_str()); - LISTADD(manifest->description, description); + manifest->description = g_list_append(manifest->description, description); return true; } @@ -164,16 +164,9 @@ bool StepParse::FillPrivileges(manifest_x* manifest) { return true; std::set privileges = perm_info->GetPrivileges(); - if (!privileges.empty()) { - privileges_x* privileges_x_list = - reinterpret_cast(calloc(1, sizeof(privileges_x))); - manifest->privileges = privileges_x_list; - for (const std::string& p : privileges) { - privilege_x* privilege_x_node = - reinterpret_cast(calloc(1, sizeof(privilege_x))); - privilege_x_node->text = strdup(p.c_str()); - LISTADD(manifest->privileges->privilege, privilege_x_node); - } + for (auto& priv : privileges) { + manifest->privileges = g_list_append(manifest->privileges, + strdup(priv.c_str())); } return true; } @@ -195,7 +188,7 @@ bool StepParse::FillServiceApplication(manifest_x* manifest) { service_app->onboot = strdup(application.sa_info.on_boot().c_str()); service_app->type = strdup(application.sa_info.type().c_str()); service_app->component_type = strdup("svcapp"); - LISTADD(manifest->application, service_app); + manifest->application = g_list_append(manifest->application, service_app); if (!FillAppControl(service_app, application.app_control)) return false; @@ -228,7 +221,7 @@ bool StepParse::FillUIApplication(manifest_x* manifest) { ui_app->taskmanage = strdup(application.ui_info.taskmanage().c_str()); ui_app->type = strdup(application.ui_info.type().c_str()); ui_app->component_type = strdup("uiapp"); - LISTADD(manifest->application, ui_app); + manifest->application = g_list_append(manifest->application, ui_app); if (!FillAppControl(ui_app, application.app_control)) return false; @@ -257,7 +250,7 @@ bool StepParse::FillAppControl(application_x* app, const T& app_control_list) { app_control->mime = strdup(control.mime().c_str()); if (!control.uri().empty()) app_control->uri = strdup(control.uri().c_str()); - LISTADD(app->appcontrol, app_control); + app->appcontrol = g_list_append(app->appcontrol, app_control); } return true; } @@ -274,7 +267,7 @@ bool StepParse::FillDataControl(application_x* app, data_control->access = strdup(control.access().c_str()); data_control->providerid = strdup(control.providerid().c_str()); data_control->type = strdup(control.type().c_str()); - LISTADD(app->datacontrol, data_control); + app->datacontrol = g_list_append(app->datacontrol, data_control); } return true; } @@ -289,7 +282,7 @@ bool StepParse::FillApplicationIconPaths(application_x* app, // Current implementation is just for compatibility. icon->text = strdup(application_icon.path().c_str()); icon->name = strdup(application_icon.path().c_str()); - LISTADD(app->icon, icon); + app->icon = g_list_append(app->icon, icon); } return true; } @@ -308,7 +301,7 @@ bool StepParse::FillLabel(application_x* app, const T& label_list) { label->text = strdup(control.text().c_str()); label->name = strdup(control.name().c_str()); label->lang = strdup(control.xml_lang().c_str()); - LISTADD(app->label, label); + app->label = g_list_append(app->label, label); } return true; } @@ -323,7 +316,7 @@ bool StepParse::FillMetadata(application_x* app, const T& meta_data_list) { static_cast(calloc(1, sizeof(metadata_x))); metadata->key = strdup(meta.key().c_str()); metadata->value = strdup(meta.val().c_str()); - LISTADD(app->metadata, metadata); + app->metadata = g_list_append(app->metadata, metadata); } return true; } diff --git a/src/wgt/step/step_add_default_privileges.cc b/src/wgt/step/step_add_default_privileges.cc index 796e990..18eb902 100644 --- a/src/wgt/step/step_add_default_privileges.cc +++ b/src/wgt/step/step_add_default_privileges.cc @@ -10,30 +10,11 @@ #include #include -#include "common/utils/clist_helpers.h" - namespace { const char kPrivForWebApp[] = "http://tizen.org/privilege/internal/webappdefault"; -bool AddPrivilegeToList(manifest_x* m, const char* priv_str) { - if (!m->privileges) { - m->privileges = - reinterpret_cast(calloc(1, sizeof(privileges_x*))); - if (!m->privileges) - return false; - } - privilege_x* priv = - reinterpret_cast(calloc(1, sizeof(privilege_x))); - if (!priv) - return false; - - priv->text = strdup(priv_str); - LISTADD(m->privileges->privilege, priv); - return true; -} - } // namespace namespace wgt { @@ -48,10 +29,8 @@ common_installer::Step::Status StepAddDefaultPrivileges::precheck() { } common_installer::Step::Status StepAddDefaultPrivileges::process() { - if (!AddPrivilegeToList(context_->manifest_data.get(), kPrivForWebApp)) { - LOG(ERROR) << "Error during adding default privileges for webapp."; - return Status::ERROR; - } + manifest_x* m = context_->manifest_data.get(); + m->privileges = g_list_append(m->privileges, strdup(kPrivForWebApp)); return Status::OK; } diff --git a/src/wgt/step/step_create_symbolic_link.cc b/src/wgt/step/step_create_symbolic_link.cc index 8fdfe98..c686382 100644 --- a/src/wgt/step/step_create_symbolic_link.cc +++ b/src/wgt/step/step_create_symbolic_link.cc @@ -15,6 +15,7 @@ #include #include "common/utils/file_util.h" +#include "common/utils/glist_range.h" namespace wgt { namespace filesystem { @@ -24,13 +25,8 @@ namespace bf = boost::filesystem; common_installer::Step::Status StepCreateSymbolicLink::process() { assert(context_->manifest_data.get()); boost::system::error_code error; - application_x* app = context_->manifest_data.get()->application; - if (!app) { - LOG(ERROR) << "There is no application described!"; - return Step::Status::ERROR; - } - // add ui-application element per ui application - for (; app != nullptr; app = app->next) { + for (application_x* app : + GListRange(context_->manifest_data.get()->application)) { // binary is a symbolic link named and is located in / bf::path exec_path = context_->pkg_path.get() @@ -52,10 +48,9 @@ common_installer::Step::Status StepCreateSymbolicLink::process() { } common_installer::Step::Status StepCreateSymbolicLink::undo() { - application_x* app = context_->manifest_data.get()->application; - - for (; app != nullptr; app = app->next) { - bf::path exec_path = context_->pkg_path.get() / bf::path("bin"); + for (application_x* app : + GListRange(context_->manifest_data.get()->application)) { + bf::path exec_path = context_->pkg_path.get() / "bin" / app->appid; if (bf::exists(exec_path)) bf::remove_all(exec_path); } diff --git a/src/wgt/step/step_parse.cc b/src/wgt/step/step_parse.cc index 905ea5b..d9752ca 100755 --- a/src/wgt/step/step_parse.cc +++ b/src/wgt/step/step_parse.cc @@ -30,24 +30,24 @@ #include "common/app_installer.h" #include "common/installer_context.h" #include "common/step/step.h" -#include "utils/clist_helpers.h" +#include "utils/glist_range.h" #include "wgt/wgt_backend_data.h" namespace { const std::string kManifestVersion = "1.0.0"; -metadata_x* GenerateMetadataListX(const wgt::parse::MetaDataInfo& meta_info, - metadata_x* head) { +GList* GenerateMetadataListX(const wgt::parse::MetaDataInfo& meta_info) { + GList* list = nullptr; for (auto& meta : meta_info.metadata()) { metadata_x* new_meta = static_cast(calloc(1, sizeof(metadata_x))); new_meta->key = strdup(meta.first.c_str()); if (!meta.second.empty()) new_meta->value = strdup(meta.second.c_str()); - LISTADD(head, new_meta); + list = g_list_append(list, new_meta); } - return head; + return list; } } // namespace @@ -83,7 +83,7 @@ bool StepParse::FillIconPaths(manifest_x* manifest) { for (auto& application_icon : icons_info->icons()) { icon_x* icon = reinterpret_cast (calloc(1, sizeof(icon_x))); icon->text = strdup(application_icon.path().c_str()); - LISTADD(manifest->icon, icon); + manifest->icon = g_list_append(manifest->icon, icon); } } return true; @@ -107,24 +107,26 @@ bool StepParse::FillWidgetInfo(manifest_x* manifest) { (calloc(1, sizeof(description_x))); description->name = strdup(item.second.c_str()); description->lang = strdup(item.first.c_str()); - LISTADD(manifest->description, description); + manifest->description = g_list_append(manifest->description, description); } for (auto& item : wgt_info->name_set()) { label_x* label = reinterpret_cast(calloc(1, sizeof(label_x))); label->name = strdup(item.second.c_str()); label->lang = strdup(item.first.c_str()); - LISTADD(manifest->label, label); + manifest->label = g_list_append(manifest->label, label); } manifest->type = strdup("wgt"); // For wgt package use the long name for (auto& item : wgt_info->name_set()) { + application_x* app = + reinterpret_cast(manifest->application->data); label_x* label = reinterpret_cast(calloc(1, sizeof(label_x))); label->name = strdup(item.second.c_str()); label->lang = strdup(item.first.c_str()); - LISTADD(manifest->application->label, label); + app->label = g_list_append(app->label, label); } author_x* author = reinterpret_cast(calloc(1, sizeof(author_x))); @@ -134,7 +136,7 @@ bool StepParse::FillWidgetInfo(manifest_x* manifest) { author->email = strdup(wgt_info->author_email().c_str()); if (!wgt_info->author_href().empty()) author->href = strdup(wgt_info->author_href().c_str()); - LISTADD(manifest->author, author); + manifest->author = g_list_append(manifest->author, author); std::shared_ptr settings_info = std::static_pointer_cast( @@ -171,21 +173,21 @@ bool StepParse::FillApplicationInfo(manifest_x* manifest) { return false; } // application data - manifest->application = reinterpret_cast - (calloc (1, sizeof(application_x))); - manifest->application->component_type = strdup("uiapp"); - manifest->application->icon = - reinterpret_cast (calloc(1, sizeof(icon_x))); - manifest->application->appid = strdup(app_info->id().c_str()); - manifest->application->type = strdup("webapp"); - manifest->package = strdup(app_info->package().c_str()); - manifest->mainapp_id = strdup(app_info->id().c_str()); + application_x* application = reinterpret_cast( + calloc(1, sizeof(application_x))); + application->component_type = strdup("uiapp"); + application->appid = strdup(app_info->id().c_str()); + application->type = strdup("webapp"); if (manifest->icon) { - icon_x* icon = nullptr; - LISTHEAD(manifest->icon, icon); - manifest->application->icon->text = strdup(icon->text); + icon_x* icon = reinterpret_cast(manifest->icon->data); + icon_x* app_icon = reinterpret_cast(calloc(1, sizeof(icon_x))); + app_icon->text = strdup(icon->text); + application->icon = g_list_append(application->icon, app_icon); } + manifest->application = g_list_append(manifest->application, application); + manifest->package = strdup(app_info->package().c_str()); + manifest->mainapp_id = strdup(app_info->id().c_str()); return true; } @@ -194,14 +196,16 @@ bool StepParse::FillAppControl(manifest_x* manifest) { std::static_pointer_cast( parser_->GetManifestData(app_keys::kTizenApplicationAppControlsKey)); + application_x* app = + reinterpret_cast(manifest->application->data); if (app_info_list) { for (const auto& control : app_info_list->controls) { appcontrol_x* app_control = - static_cast(calloc(sizeof(appcontrol_x), 1)); + static_cast(calloc(1, sizeof(appcontrol_x))); app_control->operation = strdup(control.operation().c_str()); app_control->mime = strdup(control.mime().c_str()); app_control->uri = strdup(control.uri().c_str()); - LISTADD(manifest->application->appcontrol, app_control); + app->appcontrol = g_list_append(app->appcontrol, app_control); } } return true; @@ -215,16 +219,9 @@ bool StepParse::FillPrivileges(manifest_x* manifest) { if (perm_info) privileges = ExtractPrivileges(perm_info); - if (!privileges.empty()) { - privileges_x* privileges_x_list = - reinterpret_cast(calloc(1, sizeof(privileges_x))); - manifest->privileges = privileges_x_list; - for (const std::string& p : privileges) { - privilege_x* privilege_x_node = - reinterpret_cast (calloc(1, sizeof(privilege_x))); - privilege_x_node->text = strdup(p.c_str()); - LISTADD(manifest->privileges->privilege, privilege_x_node); - } + for (auto& priv : privileges) { + manifest->privileges = + g_list_append(manifest->privileges, strdup(priv.c_str())); } return true; } @@ -236,12 +233,11 @@ bool StepParse::FillCategories(manifest_x* manifest) { if (!category_info) return true; + application_x* app = + reinterpret_cast(manifest->application->data); // there is one app atm for (auto& category : category_info->categories) { - category_x* c = reinterpret_cast( - calloc(1, sizeof(category_x))); - c->name = strdup(category.c_str()); - LISTADD(manifest->application->category, c); + app->category = g_list_append(app->category, strdup(category.c_str())); } return true; } @@ -253,11 +249,8 @@ bool StepParse::FillMetadata(manifest_x* manifest) { if (!meta_info) return true; - application_x* app = nullptr; - PKGMGR_LIST_MOVE_NODE_TO_HEAD(manifest->application, app); - for (; app; app = app->next) { - manifest->application->metadata = - GenerateMetadataListX(*meta_info, manifest->application->metadata); + for (application_x* app : GListRange(manifest->application)) { + app->metadata = GenerateMetadataListX(*meta_info); } return true; } @@ -399,7 +392,6 @@ common_installer::Step::Status StepParse::process() { LOG(DEBUG) << " name = " << name; LOG(DEBUG) << " short_name = " << short_name; LOG(DEBUG) << " aplication version = " << package_version; - LOG(DEBUG) << " icon = " << manifest->application->icon->text; LOG(DEBUG) << " api_version = " << info->required_version(); LOG(DEBUG) << " privileges -["; for (const auto& p : permissions) {