#include <vector>
#include <algorithm>
-#include "common/utils/clist_helpers.h"
+#include "common/utils/glist_range.h"
#include "common/utils/logging.h"
namespace bf = boost::filesystem;
}
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<char*>(manifest->privileges)) {
+ security_manager_app_inst_req_add_privilege(req, priv);
}
}
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<application_x*>(manifest->application)) {
if (!app->appid) {
return false;
}
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<application_x*>(manifest->application)) {
if (!app->appid) {
return false;
}
#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;
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<application_x*>(
+ 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<icon_x*>(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);
#include <cstdlib>
#include <string>
-#include "common/utils/clist_helpers.h"
+#include "common/utils/glist_range.h"
namespace bf = boost::filesystem;
}
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<char*>(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 {
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;
#include <boost/system/error_code.hpp>
#include <pkgmgr-info.h>
-#include "common/utils/clist_helpers.h"
+#include "common/utils/glist_range.h"
namespace bf = boost::filesystem;
namespace bs = boost::system;
}
}
- 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<application_x*>(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<icon_x*>(app->icon->data);
+ bf::path source = GetIconRoot() / icon->text;
if (bf::exists(source)) {
bf::path destination = icons_directory / app->appid;
if (source.has_extension())
#include <cstring>
#include <string>
-#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;
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<label_x*>(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 <appid.png>
- if (app->icon && app->icon->text) {
+ if (app->icon) {
+ icon_x* iconx = reinterpret_cast<icon_x*>(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") {
} 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();
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<appcontrol_x*>(app->appcontrol)) {
xmlTextWriterStartElement(writer, BAD_CAST "app-control");
if (appc->operation) {
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<datacontrol_x*>(app->datacontrol)) {
xmlTextWriterStartElement(writer, BAD_CAST "datacontrol");
if (datacontrol->access) {
xmlTextWriterWriteAttribute(writer, BAD_CAST "access",
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<metadata_x*>(app->metadata)) {
xmlTextWriterStartElement(writer, BAD_CAST "metadata");
xmlTextWriterWriteAttribute(writer, BAD_CAST "key",
BAD_CAST meta->key);
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<char*>(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);
}
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<label_x*>(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<author_x*>(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<description_x*>(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<application_x*>(context_->manifest_data.get()->application)) {
bool is_service = false;
if (strcmp(app->component_type, "uiapp") == 0) {
xmlTextWriterStartElement(writer, BAD_CAST "ui-application");
}
// 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<char*>(context_->manifest_data.get()->privileges)) {
xmlTextWriterWriteFormatElement(writer, BAD_CAST "privilege",
- "%s", BAD_CAST pv->text);
+ "%s", BAD_CAST priv);
}
xmlTextWriterEndElement(writer);
}
#include <string>
-#include "common/utils/clist_helpers.h"
+#include "common/utils/glist_range.h"
namespace {
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<application_x*>(old_manifest->application)) {
+ (void) KillApp(app->appid);
}
return Status::OK;
}
#include <memory>
#include <string>
-#include "common/utils/clist_helpers.h"
+#include "common/utils/glist_range.h"
namespace {
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<privileges_x*>(calloc(1, sizeof(privileges_x*)));
- if (!m->privileges)
- return false;
- }
- privilege_x* priv =
- reinterpret_cast<privilege_x*>(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 "
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<const char*[]> input_privileges(new const char*[size]);
+ std::unique_ptr<const char*[]> 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<char*>(m->privileges)) {
+ input_privileges[input_size++] = priv;
}
// get mapping
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<char*>(priv->text));
- free(priv);
- }
- free(privileges);
- }
-
// set pkgmgr new list
- m->privileges =
- reinterpret_cast<privileges_x*>(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<privilege_x*>(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);
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.
#include <pkgmgr-info.h>
#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;
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<application_x*>(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<icon_x*>(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);
#include <cstring>
#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 {
}
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<application_x*>(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<icon_x*>(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)) {
+++ /dev/null
-// 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_
--- /dev/null
+// 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 <glib.h>
+
+#include <cstddef>
+#include <iterator>
+
+// Range with mutable forward iterator based on GList
+// supporting language foreach construct
+template<typename T>
+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<const T&>(ptr_->data);
+ }
+ reference& operator*() {
+ return reinterpret_cast<T&>(ptr_->data);
+ }
+ const pointer operator->() const {
+ return reinterpret_cast<pointer>(&ptr_->data);
+ }
+ pointer operator->() {
+ return reinterpret_cast<pointer>(&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_
#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 {
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<application_x*>(m->application)) {
if (!CreateSymLink(app, context_))
return Status::ERROR;
}
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<application_x*>(m->application)) {
if (!CreateSymLink(app, context_))
ret = Status::ERROR;
}
#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 {
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;
}
(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;
}
return true;
std::set<std::string> privileges = perm_info->GetPrivileges();
- if (!privileges.empty()) {
- privileges_x* privileges_x_list =
- reinterpret_cast<privileges_x*>(calloc(1, sizeof(privileges_x)));
- manifest->privileges = privileges_x_list;
- for (const std::string& p : privileges) {
- privilege_x* privilege_x_node =
- reinterpret_cast<privilege_x*>(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;
}
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;
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;
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;
}
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;
}
// 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;
}
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;
}
static_cast<metadata_x*>(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;
}
#include <cstring>
#include <memory>
-#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<privileges_x*>(calloc(1, sizeof(privileges_x*)));
- if (!m->privileges)
- return false;
- }
- privilege_x* priv =
- reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
- if (!priv)
- return false;
-
- priv->text = strdup(priv_str);
- LISTADD(m->privileges->privilege, priv);
- return true;
-}
-
} // namespace
namespace wgt {
}
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;
}
#include <string>
#include "common/utils/file_util.h"
+#include "common/utils/glist_range.h"
namespace wgt {
namespace 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<application_x*>(context_->manifest_data.get()->application)) {
// binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
bf::path exec_path =
context_->pkg_path.get()
}
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<application_x*>(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);
}
#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<metadata_x*>(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
for (auto& application_icon : icons_info->icons()) {
icon_x* icon = reinterpret_cast<icon_x*> (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;
(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<label_x*>(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<application_x*>(manifest->application->data);
label_x* label = reinterpret_cast<label_x*>(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<author_x*>(calloc(1, sizeof(author_x)));
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<const SettingInfo> settings_info =
std::static_pointer_cast<const SettingInfo>(
return false;
}
// application data
- manifest->application = reinterpret_cast<application_x*>
- (calloc (1, sizeof(application_x)));
- manifest->application->component_type = strdup("uiapp");
- manifest->application->icon =
- reinterpret_cast<icon_x*> (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<application_x*>(
+ 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<icon_x*>(manifest->icon->data);
+ icon_x* app_icon = reinterpret_cast<icon_x*>(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;
}
std::static_pointer_cast<const AppControlInfoList>(
parser_->GetManifestData(app_keys::kTizenApplicationAppControlsKey));
+ application_x* app =
+ reinterpret_cast<application_x*>(manifest->application->data);
if (app_info_list) {
for (const auto& control : app_info_list->controls) {
appcontrol_x* app_control =
- static_cast<appcontrol_x*>(calloc(sizeof(appcontrol_x), 1));
+ static_cast<appcontrol_x*>(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;
if (perm_info)
privileges = ExtractPrivileges(perm_info);
- if (!privileges.empty()) {
- privileges_x* privileges_x_list =
- reinterpret_cast<privileges_x*>(calloc(1, sizeof(privileges_x)));
- manifest->privileges = privileges_x_list;
- for (const std::string& p : privileges) {
- privilege_x* privilege_x_node =
- reinterpret_cast<privilege_x*> (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;
}
if (!category_info)
return true;
+ application_x* app =
+ reinterpret_cast<application_x*>(manifest->application->data);
// there is one app atm
for (auto& category : category_info->categories) {
- category_x* c = reinterpret_cast<category_x*>(
- 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;
}
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<application_x*>(manifest->application)) {
+ app->metadata = GenerateMetadataListX(*meta_info);
}
return true;
}
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) {