#include <string>
#include "parcelable_factory.hh"
-
-#include "get_appinfo_request_handler.hh"
-#include "get_cert_request_handler.hh"
-#include "get_depinfo_request_handler.hh"
-#include "get_pkginfo_request_handler.hh"
-#include "query_request_handler.hh"
-#include "set_cert_request_handler.hh"
-#include "set_pkginfo_request_handler.hh"
+ #include "system_locale.hh"
+ #include "ready_checker.hh"
#include "pkgmgrinfo_debug.h"
+#include "pkgmgrinfo_private.h"
+
+#define LIBPKGMGR_INFO "/usr/lib/libpkgmgr-info-server.so.0"
+#define DIRECT_ACCESS_FUNC "_request_handler_direct_access"
namespace pkgmgr_client {
return false;
}
+ // CREATE_DB request type need to be executed directly by the caller
+ if (req_type_ == pkgmgr_common::ReqType::CREATE_DB) {
+ is_offline_ = true;
+ return RequestHandlerDirectAccess();
+ }
+
+ if (!check_server.IsReady()) {
+ LOGW("Server is not ready, try to direct access");
+ is_offline_ = true;
+ return RequestHandlerDirectAccess();
+ }
if (!socket_->Connect()) {
LOGE("Failed to connect client socket, try to direct access");
is_offline_ = true;
tizen_base::Parcel p;
p.WriteParcelable(*parcel_.get());
std::vector<uint8_t> raw = p.GetRaw();
- std::unique_ptr<char, decltype(std::free)*> locale(
- _get_system_locale(), std::free);
- if (locale.get() == nullptr)
- return false;
- handler->HandleRequest(&raw[0], raw.size(),
- pkgmgr_common::SystemLocale::GetInst().Get());
- auto result = handler->ExtractResult();
- if (result.size() == 0)
- return true;
+ static void* handle = nullptr;
+ static void* (*dl_func)(int, unsigned char*, int, const char *);
+
+ if (handle == nullptr) {
+ handle = dlopen(LIBPKGMGR_INFO, RTLD_LOCAL | RTLD_LAZY);
+ if (!handle) {
+ LOGE("Failed to open library: %s (%s)", LIBPKGMGR_INFO, dlerror());
+ return false;
+ }
+ dl_func = reinterpret_cast<void* (*)(int, unsigned char*, int, const char *)>(
+ dlsym(handle, DIRECT_ACCESS_FUNC));
+ if (dl_func == nullptr) {
+ LOGE("cannot find %s symbol in (%s)", DIRECT_ACCESS_FUNC, LIBPKGMGR_INFO);
+ dlclose(handle);
+ handle = nullptr;
+ return false;
+ }
+ }
- result_parcel_.reset(pkgmgr_common::parcel::ParcelableFactory::GetInst()
- .CreateParcel(&result[0], result.size())
- .release());
+ result_parcel_.reset(
+ reinterpret_cast<pkgmgr_common::parcel::AbstractParcelable *>(
- dl_func(req_type_, &raw[0], raw.size(), locale.get())));
++ dl_func(req_type_, &raw[0], raw.size(),
++ pkgmgr_common::SystemLocale::GetInst().Get().c_str())));
return true;
}
pkgmgrinfo_pkginfo_filter_prop_range _pminfo_pkginfo_convert_to_prop_range(const char *property);
- char *_get_system_locale(void);
+ void _pkgmgrinfo_node_destroy(pkgmgrinfo_node_x *node);
+
+ int _check_create_cert_db(void);
-void _save_column_int(sqlite3_stmt *stmt, int idx, int *i);
-void _save_column_str(sqlite3_stmt *stmt, int idx, char **str);
int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **param);
int __get_metadata_filter_condition(gpointer data, char **condition, GList **param);
int _add_icon_info_into_list(const char *locale, char *value, GList **icon);
--- /dev/null
- for (auto db_handle : db_handle_list_)
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "abstract_db_handler.hh"
+
+#include <gio/gio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <sys/types.h>
+#include <tzplatform_config.h>
+
+#include <string>
+#include <vector>
+
+#include "db_handle_provider.hh"
+#include "pkgmgr-info.h"
+#include "pkgmgrinfo_debug.h"
+#include "pkgmgrinfo_private.h"
+
+namespace {
+
+constexpr useconds_t BUSY_WAITING_USEC = (1000000 / 10 / 2); /* 0.05 sec */
+constexpr int BUSY_WAITING_MAX = 100; /* wait for max 5 sec */
+
+int __readdb_busy_handler(void *data, int count) {
+ if (count < BUSY_WAITING_MAX) {
+ usleep(BUSY_WAITING_USEC);
+ return 1;
+ } else {
+ /* sqlite3_prepare_v2 will return SQLITE_BUSY */
+ return 0;
+ }
+}
+
+int __open_read_db(const char *path, sqlite3 **db, int flags) {
+ int ret;
+
+ ret = sqlite3_open_v2(path, db, flags, NULL);
+ if (ret != SQLITE_OK) {
+ sqlite3_close_v2(*db);
+ return ret;
+ }
+
+ ret = sqlite3_busy_handler(*db, __readdb_busy_handler, NULL);
+ if (ret != SQLITE_OK) {
+ _LOGE("failed to register busy handler: %s",
+ sqlite3_errmsg(*db));
+ sqlite3_close_v2(*db);
+ return ret;
+ }
+
+ return ret;
+}
+
+constexpr const char RESOURCED_BUS_NAME[] = "org.tizen.resourced";
+constexpr const char RESOURCED_PROC_PATH[] = "/Org/Tizen/ResourceD/Process";
+constexpr const char RESOURCED_PROC_INTERFACE[] = "org.tizen.resourced.process";
+constexpr const char RESOURCED_PROC_METHOD[] = "ProcExclude";
+
+// This should be removed when the client server structure is complete
+void __send_wakeup_signal_to_resourced(pid_t pid) {
+ GError *error = NULL;
+ GDBusConnection *conn;
+ GDBusProxy *proxy;
+ GVariant *reply;
+
+ conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (conn == NULL) {
+ _LOGE("Failed to connect to dbus: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ proxy = g_dbus_proxy_new_sync(conn,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL, RESOURCED_BUS_NAME,
+ RESOURCED_PROC_PATH, RESOURCED_PROC_INTERFACE,
+ NULL, &error);
+ if (proxy == NULL) {
+ _LOGE("failed to get proxy object: %s", error->message);
+ g_error_free(error);
+ g_object_unref(conn);
+ return;
+ }
+
+ reply = g_dbus_proxy_call_sync(proxy, RESOURCED_PROC_METHOD,
+ g_variant_new("(si)", "wakeup", pid),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (reply == NULL)
+ _LOGE("failed to get reply from resourced");
+ if (error) {
+ _LOGE("failed to send request: %s", error->message);
+ g_error_free(error);
+ }
+
+ g_object_unref(proxy);
+ g_object_unref(conn);
+}
+
+void __check_db_lock(const char *dbpath) {
+ FILE *fp;
+ FILE *fp_cmdline;
+ struct stat sb;
+ char type[BUFSIZE];
+ int pid;
+ unsigned int maj;
+ unsigned int min;
+ unsigned long long ino;
+ char cmdline[BUFSIZE];
+ char name[BUFSIZE];
+ size_t len;
+
+ if (stat(dbpath, &sb) == -1) {
+ _LOGE("get db file(%s) status failed: %d", dbpath, errno);
+ return;
+ }
+
+ fp = fopen("/proc/locks", "r");
+ if (fp == NULL) {
+ _LOGE("Failed to open lock info: %d", errno);
+ return;
+ }
+
+ while (fscanf(fp, "%*s %*s %*s %5s %d %x:%x:%llu %*s %*s",
+ type, &pid, &maj, &min, &ino) != EOF) {
+ if (maj != major(sb.st_dev) || min != minor(sb.st_dev) ||
+ ino != sb.st_ino || pid == getpid() ||
+ strcasecmp(type, "WRITE"))
+ continue;
+
+ snprintf(cmdline, sizeof(cmdline), "/proc/%d/cmdline", pid);
+ fp_cmdline = fopen(cmdline, "r");
+ name[0] = '\0';
+ if (fp_cmdline != NULL) {
+ len = fread(name, sizeof(char), sizeof(name) - 1,
+ fp_cmdline);
+ if (len > 0) {
+ if (name[len - 1] == '\n')
+ name[len - 1] = '\0';
+ else
+ name[len] = '\0';
+ }
+ fclose(fp_cmdline);
+ }
+
+ _LOGE("%s (%d) has lock on pkgmgr db(%s)!", name, pid, dbpath);
+ __send_wakeup_signal_to_resourced(pid);
+ }
+
+ fclose(fp);
+}
+
+int __writedb_busy_handler(void *data, int count) {
+ if (count < (BUSY_WAITING_MAX / 2)) {
+ usleep(BUSY_WAITING_USEC);
+ return 1;
+ } else if (count == (BUSY_WAITING_MAX / 2)) {
+ __check_db_lock((const char *)data);
+ usleep(BUSY_WAITING_USEC);
+ return 1;
+ } else if (count < BUSY_WAITING_MAX) {
+ usleep(BUSY_WAITING_USEC);
+ return 1;
+ } else {
+ /* sqlite3_prepare_v2 will return SQLITE_BUSY */
+ return 0;
+ }
+}
+
+int __open_write_db(uid_t uid, const char* path,
+ sqlite3** db, int flags) {
+ int ret;
+
+ ret = sqlite3_open_v2(path, db, flags, NULL);
+ if (ret != SQLITE_OK) {
+ sqlite3_close_v2(*db);
+ return ret;
+ }
+
+ ret = sqlite3_busy_handler(*db, __writedb_busy_handler,
+ reinterpret_cast<void*>(const_cast<char*>(path)));
+ if (ret != SQLITE_OK) {
+ _LOGE("failed to register busy handler: %s",
+ sqlite3_errmsg(*db));
+ sqlite3_close_v2(*db);
+ return ret;
+ }
+
+ ret = sqlite3_exec(*db, "PRAGMA foreign_keys=ON", NULL, NULL, NULL);
+ if (ret != SQLITE_OK) {
+ _LOGE("failed to enable foreign key support: %s",
+ sqlite3_errmsg(*db));
+ sqlite3_close_v2(*db);
+ return ret;
+ }
+
+ return ret;
+}
+
+int __open_create_db(uid_t uid, const char* path,
+ sqlite3** db, int flags) {
+ int ret;
+
+ ret = sqlite3_open_v2(path, db, flags, NULL);
+ if (ret != SQLITE_OK) {
+ sqlite3_close_v2(*db);
+ return ret;
+ }
+
+ ret = sqlite3_busy_handler(*db, __writedb_busy_handler,
+ reinterpret_cast<void*>(const_cast<char*>(path)));
+ if (ret != SQLITE_OK) {
+ _LOGE("failed to register busy handler: %s",
+ sqlite3_errmsg(*db));
+ sqlite3_close_v2(*db);
+ return ret;
+ }
+
+ return ret;
+}
+
+uid_t ConvertUID(uid_t uid) {
+ if (uid < REGULAR_USER)
+ return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+ else
+ return uid;
+}
+
+} // namespace
+
+namespace pkgmgr_server {
+namespace database {
+
+std::shared_timed_mutex AbstractDBHandler::lock_;
+
+AbstractDBHandler::AbstractDBHandler(uid_t uid, int pid) {
+ uid_ = uid;
+ pid_ = pid;
+}
+
+AbstractDBHandler::~AbstractDBHandler() {
- for (auto dbpath : dbpath_list) {
++ for (auto& db_handle : db_handle_list_)
+ sqlite3_close_v2(db_handle.first);
+}
+
+std::vector<std::pair<std::string, uid_t>> AbstractDBHandler::GetDBPath() {
+ std::vector<std::pair<std::string, uid_t>> db_path;
+ if (db_type_ == pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB)
+ db_path = DBHandleProvider::GetInst(uid_).GetParserDBPath(pid_,
+ op_type_ == pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE);
+ else if (db_type_ == pkgmgr_common::DBType::DB_TYPE_FILE_CERTDB)
+ db_path.emplace_back(
+ std::make_pair(DBHandleProvider::GetInst(uid_).GetCertDBPath(pid_,
+ op_type_ == pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE), uid_));
+
+ return db_path;
+}
+
+bool AbstractDBHandler::Connect() {
+ if (db_type_ == pkgmgr_common::DBType::DB_TYPE_NONE || op_type_ == pkgmgr_common::DBOperationType::OPERATION_TYPE_NONE) {
+ // error log
+ return false;
+ }
+ auto dbpath_list = GetDBPath();
+ int ret = 0;
+ sqlite3* db;
- std::string AbstractDBHandler::GetLocale() { return locale_; }
++ for (auto& dbpath : dbpath_list) {
+ if (op_type_ == pkgmgr_common::DBOperationType::OPERATION_TYPE_READ) {
+ ret = __open_read_db(dbpath.first.c_str(), &db, SQLITE_OPEN_READONLY |
+ SQLITE_OPEN_URI);
+ } else if (op_type_ == pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE) {
+ if (ConvertUID(dbpath.second) != ConvertUID(uid_))
+ continue;
+ ret = __open_write_db(uid_, dbpath.first.c_str(), &db,
+ SQLITE_OPEN_READWRITE);
+ } else {
+ if (ConvertUID(dbpath.second) != ConvertUID(uid_))
+ continue;
+
+ if (access(dbpath.first.c_str(), F_OK) != -1) {
+ _LOGE("Database for user %d is already exists", uid_);
+ return false;
+ }
+ ret = __open_create_db(uid_, dbpath.first.c_str(), &db,
+ SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
+ }
+
+ if (ret != SQLITE_OK)
+ return false;
+
+ db_handle_list_.emplace_back(std::make_pair(db, dbpath.second));
+ }
+
+ return true;
+}
+
+void AbstractDBHandler::ClearDBHandle() {
+ for (auto db_handle : db_handle_list_)
+ sqlite3_close_v2(db_handle.first);
+
+ db_handle_list_.clear();
+}
+
+std::vector<std::pair<sqlite3*, uid_t>> AbstractDBHandler::GetConnection() {
+ return db_handle_list_;
+}
+
+void AbstractDBHandler::SetOpType(pkgmgr_common::DBOperationType type) {
+ op_type_ = type;
+}
+
- void AbstractDBHandler::SetLocale(const std::string& locale) {
- locale_ = locale;
++const std::string& AbstractDBHandler::GetLocale() { return locale_; }
+
+int AbstractDBHandler::GetPID() { return pid_; }
+
+uid_t AbstractDBHandler::GetUID() { return uid_; }
+
++void AbstractDBHandler::SetLocale(std::string locale) {
++ locale_ = std::move(locale);
+}
+
+void AbstractDBHandler::SetDBType(pkgmgr_common::DBType type) { db_type_ = type; }
+
+pkgmgr_common::DBOperationType AbstractDBHandler::GetOpType() {
+ return op_type_;
+}
+
+} // namespace database
+} // namespace pkgmgr_server
--- /dev/null
- #include "query_parcelable.hh"
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ABSTRACT_DB_HANDLER_HH_
+#define ABSTRACT_DB_HANDLER_HH_
+
+#include <shared_mutex>
+#include <string>
+#include <vector>
+
+#include <sys/types.h>
+#include <sqlite3.h>
+
- void SetLocale(const std::string& locale);
+#include "db_type.hh"
++#include "query_parcelable.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API AbstractDBHandler {
+ public:
+ AbstractDBHandler(uid_t uid, pid_t pid);
+ virtual ~AbstractDBHandler();
+ virtual int Execute() = 0;
- std::string GetLocale();
++ void SetLocale(std::string locale);
+ void SetDBType(pkgmgr_common::DBType type);
+ void SetOpType(pkgmgr_common::DBOperationType type);
+ pkgmgr_common::DBOperationType GetOpType();
+
+ protected:
+ virtual bool Connect();
+ int GetPID();
+ uid_t GetUID();
+ virtual std::vector<std::pair<sqlite3*, uid_t>> GetConnection();
+ void ClearDBHandle();
++ const std::string& GetLocale();
+ static std::shared_timed_mutex lock_;
+ private:
+ std::vector<std::pair<std::string, uid_t>> GetDBPath();
+ pkgmgr_common::DBType db_type_ = pkgmgr_common::DBType::DB_TYPE_NONE;
+ pkgmgr_common::DBOperationType op_type_ =
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_NONE;
+ uid_t uid_;
+ pid_t pid_;
+ std::string locale_;
+ std::vector<std::pair<sqlite3*, uid_t>> db_handle_list_;
+};
+
+} // namespace database
+} // namespace pkgmgr_server
+
+#endif // ABSTRACT_DB_HANDLER_HH_
+
--- /dev/null
- for (auto conn : conn_list) {
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "appinfo_db_handler.hh"
+
+#include <vector>
+#include <shared_mutex>
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_internal.h"
+#include "pkgmgrinfo_debug.h"
+
+namespace {
+
+gboolean _move_func(gpointer key, gpointer value, gpointer user_data) {
+ application_x* appinfo = static_cast<application_x*>(value);
+ std::vector<application_x*>* app_list =
+ static_cast<std::vector<application_x*>*>(user_data);
+ app_list->emplace_back(appinfo);
+ return true;
+}
+
+void __free_applications(gpointer data) {
+ pkgmgrinfo_basic_free_application(reinterpret_cast<application_x*>(data));
+}
+
+} // namespace
+
+namespace pkgmgr_server {
+namespace database {
+
+AppInfoDBHandler::AppInfoDBHandler(uid_t uid, int pid)
+ : AbstractDBHandler(uid, pid), uid_(uid) {}
+
+AppInfoDBHandler::~AppInfoDBHandler() {}
+
+std::vector<application_x*> AppInfoDBHandler::GetAppHandle() {
+ return std::move(handle_list_);
+}
+
+void AppInfoDBHandler::SetFilter(pkgmgrinfo_filter_x* filter) {
+ filter_ = filter;
+}
+
+int AppInfoDBHandler::Execute() {
+ std::shared_lock<std::shared_timed_mutex> s(lock_);
+ SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
+ SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
+ if (!Connect())
+ return PMINFO_R_ERROR;
+
+ GHashTable* list = g_hash_table_new_full(g_str_hash, g_str_equal,
+ NULL, __free_applications);
+ std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
+ int ret = PMINFO_R_OK;
++ for (auto& conn : conn_list) {
+ ret = appinfo_internal_filter_get_list(conn.first, filter_, conn.second,
+ uid_, GetLocale().c_str(), list);
+ if (ret == PMINFO_R_ERROR) {
+ _LOGD("Failed to appinfo_internal_filter_get_list (%d)", ret);
+ break;
+ }
+ }
+
+ if (g_hash_table_size(list) == 0)
+ ret = PMINFO_R_ENOENT;
+
+ if (ret == PMINFO_R_OK)
+ g_hash_table_foreach_steal(list, _move_func, &handle_list_);
+
+ g_hash_table_destroy(list);
+ return ret;
+}
+
+} // namespace database
+} // namespace pkgmgr_server
--- /dev/null
- GList *list = nullptr;
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "depinfo_db_handler.hh"
+
+#include <shared_mutex>
+#include <vector>
+
+#include "pkgmgrinfo_debug.h"
+#include "pkgmgrinfo_internal.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+DepInfoGetDBHandler::DepInfoGetDBHandler(uid_t uid, int pid)
+ : AbstractDBHandler(uid, pid), uid_(uid) {}
+
+DepInfoGetDBHandler::~DepInfoGetDBHandler() {}
+
+std::vector<dependency_x*> DepInfoGetDBHandler::GetDependencyList() {
+ return std::move(dependency_list_);
+}
+
+void DepInfoGetDBHandler::SetPkgID(const std::string& pkgid) {
+ pkgid_ = pkgid;
+}
+
+int DepInfoGetDBHandler::Execute() {
+ std::shared_lock<std::shared_timed_mutex> s(lock_);
+ SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
+ SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
+
+ if (!Connect()) {
+ _LOGE("Failed to connect database");
+ return PMINFO_R_ERROR;
+ }
- for (GList *tmp = list; tmp; tmp = tmp->next)
++ GList* list = nullptr;
+ std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
+ int ret = PMINFO_R_OK;
+ for (auto& conn : conn_list) {
+ ret = pkginfo_internal_filter_get_depends_on(
+ conn.first, pkgid_.c_str(), &list);
+ if (ret == PMINFO_R_ERROR)
+ break;
+ }
+
++ for (GList* tmp = list; tmp; tmp = tmp->next)
+ dependency_list_.emplace_back(reinterpret_cast<dependency_x *>(tmp->data));
+
+ g_list_free(list);
+
+ return ret;
+}
+
+} // namespace database
+} // namespace pkgmgr_server
--- /dev/null
- void __free_argument(gpointer data, gpointer user_data) {
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "query_handler.hh"
+
+#include <shared_mutex>
+#include <vector>
+
+#include "pkgmgrinfo_debug.h"
+#include "pkgmgrinfo_internal.h"
+#include "pkgmgr_query_index.h"
+
+namespace {
+
+constexpr const char query_appinfo_get_localed_label[] =
+ "SELECT COALESCE((SELECT app_label FROM package_app_localized_info "
+ "WHERE app_id=? AND app_locale=?),"
+ "(SELECT app_label FROM package_app_localized_info WHERE "
+ "app_id=? AND app_locale='No Locale'))";
+
+constexpr const char query_appinfo_get_datacontrol_info[] =
+ "SELECT app_id, access FROM "
+ "package_app_data_control WHERE "
+ "providerid=? AND type=?";
+
+constexpr const char query_appinfo_get_datacontrol_appid[] =
+ "SELECT app_id FROM package_app_data_control "
+ "WHERE providerid=?";
+
+constexpr const char query_appinfo_get_datacontrol_trusted_info[] =
+ "SELECT app_id, trusted FROM package_app_data_control "
+ "WHERE providerid=? AND type=?";
+
+constexpr const char query_appinfo_get_datacontrol_privileges[] =
+ "SELECT privilege FROM package_app_data_control_privilege "
+ "WHERE providerid=? AND type=?";
+
+constexpr const char query_appinfo_get_appcontrol_privileges[] =
+ "SELECT app_control, privilege FROM package_app_app_control_privilege "
+ "WHERE app_id=?";
+
+constexpr const char query_plugininfo_get_appids[] =
+ "SELECT appid FROM "
+ "package_plugin_info WHERE pkgid=? AND "
+ "plugin_type=? AND plugin_name=?";
+
+constexpr const char query_get_pkg_updateinfo_1[] =
+ "SELECT package, update_version, update_type "
+ "FROM package_update_info";
+constexpr const char query_get_pkg_updateinfo_2[] =
+ "SELECT package, update_version, update_type "
+ "FROM package_update_info WHERE package=?";
+
+constexpr const char query_pkginfo_set_usr_installed_storage_1[] =
+ "UPDATE package_info SET installed_storage=?, external_path=? "
+ "WHERE package=?";
+constexpr const char query_pkginfo_set_usr_installed_storage_2[] =
+ "UPDATE package_app_info SET app_installed_storage=?, "
+ "app_external_path=? WHERE package=?";
+
+constexpr const char query_certinfo_compare_pkg_certinfo[] =
+ "SELECT package, "
+ "COALESCE(author_signer_cert, -1) FROM package_cert_info WHERE "
+ "package IN (?, ?)";
+
+constexpr const char query_certinfo_compare_app_certinfo[] =
+ "SELECT app_id, package FROM "
+ "package_app_info WHERE app_id IN (?, ?)";
+
+constexpr const char query_pkginfo_delete_certinfo[] =
+ "UPDATE package_cert_info SET "
+ "package_count = package_count - 1 WHERE package=?";
+
+// For pkgmgr_parser
+constexpr const char query_insert_package_plugin_execution_info[] =
+ "INSERT INTO package_plugin_info "
+ "(pkgid, appid, plugin_type, plugin_name) "
+ "VALUES (?, ?, ?, ?)";
+
+constexpr const char query_delete_package_plugin_execution_info[] =
+ "DELETE FROM package_plugin_info WHERE pkgid=?";
+
+constexpr const char query_update_global_app_disable[] =
+ "INSERT OR REPLACE INTO package_app_info_for_uid ("
+ " app_id, uid, is_disabled, is_splash_screen_enabled) "
+ "VALUES (?, ?, ?,"
+ " (SELECT app_splash_screen_display FROM package_app_info"
+ " WHERE app_id=?))";
+
+constexpr const char query_update_app_disable_info[] =
+ "UPDATE package_app_info SET app_disable=? "
+ "WHERE app_id=?";
+
+constexpr const char query_update_pkg_disable_info[] =
+ "UPDATE package_info SET package_disable=? "
+ "WHERE package=?";
+
+constexpr const char query_update_global_app_splash_screen_display_info[] =
+ "INSERT OR REPLACE INTO package_app_info_for_uid("
+ " app_id, uid, is_splash_screen_enabled) "
+ "VALUES (?, ?, ?)";
+
+constexpr const char query_update_app_splash_screen_display_info[] =
+ "UPDATE package_app_info SET app_splash_screen_display=? "
+ "WHERE app_id=?";
+
+constexpr const char query_update_app_label_info[] =
+ "UPDATE package_app_localized_info SET app_label=? "
+ "WHERE app_id=? AND app_label IS NOT NULL";
+
+constexpr const char query_update_app_icon_info[] =
+ "UPDATE package_app_localized_info SET app_icon=? "
+ "WHERE app_id=? AND app_icon IS NOT NULL";
+
+constexpr const char query_update_tep_info[] =
+ "UPDATE package_info SET package_tep_name=? "
+ "WHERE package=?";
+
+constexpr const char query_register_pkg_update_info[] =
+ "UPDATE package_update_info "
+ "SET update_version=?, update_type=? "
+ "WHERE package=?";
+
+constexpr const char query_unregister_pkg_update_info[] =
+ "UPDATE package_update_info "
+ "SET update_type='none' WHERE package=?";
+
+constexpr const char query_unregister_all_pkg_update_info[] =
+ "UPDATE package_update_info "
+ "SET update_type='none'";
+
+class QueryMaker {
+ public:
+ std::vector<const char*> query_raw_ = {
+ query_appinfo_get_localed_label,
+ query_appinfo_get_datacontrol_info,
+ query_appinfo_get_datacontrol_appid,
+ query_appinfo_get_datacontrol_trusted_info,
+ query_appinfo_get_datacontrol_privileges,
+ query_appinfo_get_appcontrol_privileges,
+ query_plugininfo_get_appids,
+ query_get_pkg_updateinfo_1,
+ query_get_pkg_updateinfo_2,
+ query_pkginfo_set_usr_installed_storage_1,
+ query_pkginfo_set_usr_installed_storage_2,
+ query_certinfo_compare_pkg_certinfo,
+ query_certinfo_compare_app_certinfo,
+ query_pkginfo_delete_certinfo,
+
+ query_insert_package_plugin_execution_info,
+ query_delete_package_plugin_execution_info,
+ query_update_global_app_disable,
+ query_update_app_disable_info,
+ query_update_pkg_disable_info,
+ query_update_global_app_splash_screen_display_info,
+ query_update_app_splash_screen_display_info,
+ query_update_app_label_info,
+ query_update_app_icon_info,
+ query_update_tep_info,
+ query_register_pkg_update_info,
+ query_unregister_pkg_update_info,
+ query_unregister_all_pkg_update_info,
+ };
+
+ const char* GetQuery(int index) {
+ return query_raw_[index];
+ }
+};
+
+QueryMaker __query_maker;
+
- g_list_foreach(args_list, __free_argument, NULL);
++void __free_argument(gpointer data) {
+ query_args* args = (query_args*)data;
+ g_list_free(args->argument);
+ free(args);
+}
+
+void __free_query_list(GList* queries, GList* args_list) {
+ g_list_free(queries);
++ g_list_free_full(args_list, __free_argument);
+}
+
+} // namespace
+
+namespace pkgmgr_server {
+namespace database {
+
+QueryHandler::QueryHandler(uid_t uid, int pid)
+ : AbstractDBHandler(uid, pid), uid_(uid) {}
+
+QueryHandler::~QueryHandler() {}
+
+void QueryHandler::SetQueryArgs(
+ std::vector<std::pair<int, std::vector<std::string>>> query_args) {
+ query_args_ = std::move(query_args);
+}
+
+std::string QueryHandler::GetString() { return std::string(); }
+int QueryHandler::GetInt() { return 0; }
+int QueryHandler::GetRecordCount() { return 0; }
+
+std::vector<std::vector<std::string>> QueryHandler::GetResult() {
+ return std::move(result_);
+}
+
+int QueryHandler::Execute() {
+ std::shared_lock<std::shared_timed_mutex> s(lock_);
+ if (!Connect()) {
+ _LOGE("Failed to connect database");
+ return PMINFO_R_ERROR;
+ }
+
+ GList* queries = nullptr;
+ GList* args_list = nullptr;
+ for (auto& i : query_args_) {
+ const char* query = __query_maker.GetQuery(i.first);
+ if (query == nullptr) {
+ _LOGE("Failed to get query");
+ __free_query_list(queries, args_list);
+ return PMINFO_R_ERROR;
+ }
+
+ queries = g_list_append(queries, (gpointer)query);
+ query_args* arg = (query_args*)calloc(1, sizeof(query_args));
+ if (arg == nullptr) {
+ _LOGE("Out of memory");
+ __free_query_list(queries, args_list);
+ return PMINFO_R_ERROR;
+ }
+ arg->len = i.second.size();
+ for (auto& argument : i.second)
+ arg->argument = g_list_append(arg->argument, (gpointer)argument.c_str());
+
+ args_list = g_list_append(args_list, arg);
+ }
+
+ std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
+ int ret;
+ if (GetOpType() == pkgmgr_common::DBOperationType::OPERATION_TYPE_READ) {
+ for (auto& conn : conn_list) {
+ GList* list = nullptr;
+ int row = 0;
+ int col = 0;
+
+ query_args* params = (query_args*)args_list->data;
+ ret = get_query_result(conn.first, (const char *)queries->data,
+ params->argument, &list, &row, &col);
+ if (ret == PMINFO_R_ERROR) {
+ _LOGE("Failed to execute query");
+ __free_query_list(queries, args_list);
+ return ret;
+ }
+
+ GList* tmp = list;
+ for (int i = 0; i < row; ++i) {
+ std::vector<std::string> vt;
+ for (int j = 0; j < col; ++j) {
+ vt.emplace_back(reinterpret_cast<char *>(tmp->data));
+ tmp = tmp->next;
+ }
+ result_.emplace_back(std::move(vt));
+ }
++
++ g_list_free_full(list, free);
+ }
+ __free_query_list(queries, args_list);
+
+ return ret;
+ } else {
+ for (auto& conn : conn_list) {
+ ret = execute_write_queries(conn.first, queries, args_list);
+ if (ret != PMINFO_R_OK) {
+ _LOGE("Failed to execute");
+ break;
+ }
+ }
+ __free_query_list(queries, args_list);
+ return ret;
+
+ }
+ return ret;
+}
+
+} // namespace database
+} // namespace pkgmgr_server
--- /dev/null
- virtual bool HandleRequest(unsigned char* data, int size, std::string locale) = 0;
+// Copyright (c) 2021 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 SERVER_ABSTRACT_REQUEST_HANDLER_HH_
+#define SERVER_ABSTRACT_REQUEST_HANDLER_HH_
+
+#include <string>
+
+#include <sys/types.h>
+
+#include <parcel.hh>
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API AbstractRequestHandler {
+ public:
+ virtual ~AbstractRequestHandler() = default;
++ virtual bool HandleRequest(unsigned char* data, int size,
++ const std::string& locale) = 0;
+
+ virtual std::vector<uint8_t> ExtractResult() = 0;
+
+ void SetPID(pid_t pid);
+
+ protected:
+ pid_t GetPID();
+
+ private:
+ pid_t pid_;
+};
+
+} // namespace request_handler
+} // namespace pkgmgr_server
+
+#endif // SERVER_ABSTRACT_REQUEST_HANDLER_HH_
--- /dev/null
- std::string locale) {
+// Copyright (c) 2021 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.
+
+#include "command_request_handler.hh"
+
+#include <string>
+
+#include "db_handle_provider.hh"
+#include "parcelable_factory.hh"
+#include "pkginfo_parcelable.hh"
+
+#include "pkgmgrinfo_debug.h"
+#include "pkgmgrinfo_type.h"
+
+namespace pcp = pkgmgr_common::parcel;
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+bool CommandRequestHandler::HandleRequest(unsigned char* data, int size,
++ const std::string& locale) {
+ auto abstract_parcel =
+ pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
+
+ if (abstract_parcel == nullptr ||
+ abstract_parcel->GetType() != pcp::ParcelableType::Command) {
+ _LOGE("Invalid parcel or type");
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ PMINFO_R_ERROR, std::vector<std::vector<std::string>>{});
+ return false;
+ }
+
+ auto* parcel = dynamic_cast<pcp::CommandParcelable*>(abstract_parcel.get());
+ if (parcel == nullptr) {
+ _LOGE("Parcel is empty");
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ PMINFO_R_ERROR, std::vector<std::vector<std::string>>{});
+ return false;
+ }
+
+ if (parcel->GetCmd() == CommandType::RemoveCache) {
+ database::DBHandleProvider::GetInst(
+ parcel->GetUid()).SetMemoryMode(GetPID(), false);
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ PMINFO_R_OK, std::vector<std::vector<std::string>>{});
+ return true;
+ }
+
+ return true;
+}
+
+std::vector<uint8_t> CommandRequestHandler::ExtractResult() {
+ tizen_base::Parcel parcel;
+
+ parcel.WriteParcelable(*result_);
+ std::vector<uint8_t> raw = parcel.GetRaw();
+ result_.reset();
+
+ return raw;
+}
+
+} // namespace request_handler
+} // namespace pkgmgr_server
--- /dev/null
- bool HandleRequest(unsigned char* data, int size, std::string locale) override;
+// Copyright (c) 2021 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 COMMAND_REQUEST_HANDLER_HH_
+#define COMMAND_REQUEST_HANDLER_HH_
+
+#include "abstract_request_handler.hh"
+#include "command_parcelable.hh"
+#include "result_parcelable.hh"
+
+#include <string>
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API CommandRequestHandler : public AbstractRequestHandler {
+ public:
++ bool HandleRequest(unsigned char* data, int size,
++ const std::string& locale) override;
+
+ std::vector<uint8_t> ExtractResult() override;
+
+ private:
+ std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> result_;
+};
+
+} // namespace request_handler
+} // namespace pkgmgr_server
+
+#endif // COMMAND_REQUEST_HANDLER_HH_
--- /dev/null
- std::string locale) {
+// Copyright (c) 2021 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.
+
+#include "create_db_request_handler.hh"
+
+#include <string>
+
+#include "parcelable_factory.hh"
+#include "create_db_parcelable.hh"
+#include "create_db_handler.hh"
+#include "db_type.hh"
+
+#include "pkgmgr_parser.h"
+
+#include "pkgmgrinfo_debug.h"
+
+namespace pcp = pkgmgr_common::parcel;
+namespace psd = pkgmgr_server::database;
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+bool CreateDBRequestHandler::HandleRequest(unsigned char* data, int size,
++ const std::string& locale) {
+ auto abstract_parcel =
+ pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
+
+ if (abstract_parcel == nullptr ||
+ abstract_parcel->GetType() != pcp::ParcelableType::CreateDB) {
+ _LOGE("Invalid parcel or type");
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ PM_PARSER_R_ERROR, std::vector<std::vector<std::string>>{});
+ return false;
+ }
+
+ auto* parcel = dynamic_cast<pcp::CreateDBParcelable*>(abstract_parcel.get());
+ if (parcel == nullptr) {
+ _LOGE("Parcel is empty");
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ PM_PARSER_R_ERROR, std::vector<std::vector<std::string>>{});
+ return false;
+ }
+
+ psd::CreateDBHandler db(parcel->GetUid(), GetPID());
+ db.SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_CREATE);
+
+ int ret = PM_PARSER_R_ERROR;
+
+ ret = db.Execute();
+
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ ret, std::vector<std::vector<std::string>>{});
+
+ return true;
+}
+
+std::vector<uint8_t> CreateDBRequestHandler::ExtractResult() {
+ tizen_base::Parcel parcel;
+
+ parcel.WriteParcelable(*result_);
+ std::vector<uint8_t> raw = parcel.GetRaw();
+
+ result_.reset();
+
+ return raw;
+}
+
+} // namespace request_handler
+} // namespace pkgmgr_server
--- /dev/null
- bool HandleRequest(unsigned char* data, int size, std::string locale) override;
+// Copyright (c) 2021 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 SERVER_CREATE_DB_REQUEST_HANDLER_HH_
+#define SERVER_CREATE_DB_REQUEST_HANDLER_HH_
+
+#include "abstract_request_handler.hh"
+#include "result_parcelable.hh"
+
+#include <string>
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API CreateDBRequestHandler : public AbstractRequestHandler {
+ public:
++ bool HandleRequest(unsigned char* data, int size,
++ const std::string& locale) override;
+
+ std::vector<uint8_t> ExtractResult() override;
+
+ private:
+ std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> result_;
+};
+
+} // namespace request_handler
+} // namespace pkgmgr_server
+
+#endif // SERVER_CREATE_DB_REQUEST_HANDLER_HH_
--- /dev/null
- std::string locale) {
+// Copyright (c) 2021 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.
+
+#include "get_appinfo_request_handler.hh"
+
+#include <string>
+
+#include "parcelable_factory.hh"
+#include "filter_parcelable.hh"
+#include "appinfo_db_handler.hh"
+
+#include "pkgmgrinfo_debug.h"
+
+namespace pcp = pkgmgr_common::parcel;
+namespace psd = pkgmgr_server::database;
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+bool GetAppinfoRequestHandler::HandleRequest(unsigned char* data, int size,
++ const std::string& locale) {
+ auto abstract_parcel =
+ pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
+
+ if (abstract_parcel == nullptr ||
+ abstract_parcel->GetType() != pcp::ParcelableType::Filter) {
+ _LOGE("Invalid parcel or type");
+ result_ = std::make_shared<pcp::AppInfoParcelable>(
+ PMINFO_R_ERROR, std::vector<application_x*>{});
+ return false;
+ }
+
+ auto* parcel = dynamic_cast<pcp::FilterParcelable*>(abstract_parcel.get());
+ if (parcel == nullptr) {
+ _LOGE("Parcel is empty");
+ result_ = std::make_shared<pcp::AppInfoParcelable>(
+ PMINFO_R_ERROR, std::vector<application_x*>{});
+ return false;
+ }
+
+ psd::AppInfoDBHandler db(parcel->GetUid(), GetPID());
+ db.SetLocale(locale);
+ db.SetFilter(const_cast<pkgmgrinfo_filter_x*>(parcel->GetFilter()));
+ int ret = db.Execute();
+
+ result_ = std::make_shared<pcp::AppInfoParcelable>(ret, db.GetAppHandle());
+
+ return true;
+}
+
+std::vector<uint8_t> GetAppinfoRequestHandler::ExtractResult() {
+ tizen_base::Parcel parcel;
+
+ parcel.WriteParcelable(*result_);
+ std::vector<uint8_t> raw = parcel.GetRaw();
+
+ result_.reset();
+
+ return raw;
+}
+
+} // namespace request_handler
+} // namespace pkgmgr_server
--- /dev/null
- bool HandleRequest(unsigned char* data, int size, std::string locale) override;
+// Copyright (c) 2021 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 SERVER_GET_APPINFO_REQUEST_HANDLER_HH_
+#define SERVER_GET_APPINFO_REQUEST_HANDLER_HH_
+
+#include "abstract_request_handler.hh"
+#include "appinfo_parcelable.hh"
+
+#include <string>
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API GetAppinfoRequestHandler : public AbstractRequestHandler {
+ public:
++ bool HandleRequest(unsigned char* data, int size,
++ const std::string& locale) override;
+
+ std::vector<uint8_t> ExtractResult() override;
+
+ private:
+ std::shared_ptr<pkgmgr_common::parcel::AppInfoParcelable> result_;
+};
+
+} // namespace request_handler
+} // namespace pkgmgr_server
+
+#endif // SERVER_GET_APPINFO_REQUEST_HANDLER_HH_
--- /dev/null
- std::string locale) {
+// Copyright (c) 2021 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.
+
+#include "get_cert_request_handler.hh"
+
+#include <string>
+
+#include "database/cert_get_db_handler.hh"
+#include "parcelable_factory.hh"
+
+#include "pkgmgrinfo_debug.h"
+
+namespace pcp = pkgmgr_common::parcel;
+namespace psd = pkgmgr_server::database;
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+bool GetCertRequestHandler::HandleRequest(unsigned char* data, int size,
++ const std::string& locale) {
+ auto abstract_parcel =
+ pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
+
+ if (abstract_parcel == nullptr ||
+ abstract_parcel->GetType() != pcp::ParcelableType::CertInfo) {
+ _LOGE("Invalid parcel or type");
+ result_ = std::make_shared<pcp::CertInfoParcelable>(
+ PMINFO_R_ERROR, nullptr);
+ return false;
+ }
+
+ auto* parcel = dynamic_cast<pcp::CertInfoParcelable*>(abstract_parcel.get());
+ if (parcel == nullptr) {
+ _LOGE("Parcel is empty");
+ result_ = std::make_shared<pcp::CertInfoParcelable>(
+ PMINFO_R_ERROR, nullptr);
+ return false;
+ }
+
+ psd::CertGetDBHandler db(parcel->GetUid(), GetPID());
+ db.SetLocale(locale);
+ db.SetPkgID(parcel->GetPkgId());
+
+ int ret = db.Execute();
+
+ result_ = std::make_shared<pcp::CertInfoParcelable>(ret, db.GetCertHandle());
+
+ return true;
+}
+
+std::vector<uint8_t> GetCertRequestHandler::ExtractResult() {
+ tizen_base::Parcel parcel;
+
+ parcel.WriteParcelable(*result_);
+ std::vector<uint8_t> raw = parcel.GetRaw();
+
+ result_.reset();
+
+ return raw;
+}
+
+} // namespace request_handler
+} // namespace pkgmgr_server
--- /dev/null
- bool HandleRequest(unsigned char* data, int size, std::string locale) override;
+// Copyright (c) 2021 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 SERVER_GET_CERT_REQUEST_HANDLER_HH_
+#define SERVER_GET_CERT_REQUEST_HANDLER_HH_
+
+#include "abstract_request_handler.hh"
+#include "certinfo_parcelable.hh"
+
+#include <string>
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API GetCertRequestHandler : public AbstractRequestHandler {
+ public:
++ bool HandleRequest(unsigned char* data, int size,
++ const std::string& locale) override;
+
+ std::vector<uint8_t> ExtractResult() override;
+
+ private:
+ std::shared_ptr<pkgmgr_common::parcel::CertInfoParcelable> result_;
+};
+
+} // namespace request_handler
+} // namespace pkgmgr_server
+
+#endif // SERVER_GET_CERT_REQUEST_HANDLER_HH_
--- /dev/null
- std::string locale) {
+// Copyright (c) 2021 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.
+
+#include "get_depinfo_request_handler.hh"
+
+#include <string>
+
+#include "depinfo_db_handler.hh"
+#include "depinfo_parcelable.hh"
+#include "parcelable_factory.hh"
+
+#include "pkgmgrinfo_debug.h"
+
+namespace pcp = pkgmgr_common::parcel;
+namespace psd = pkgmgr_server::database;
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+bool GetDepinfoRequestHandler::HandleRequest(unsigned char* data, int size,
++ const std::string& locale) {
+ auto abstract_parcel =
+ pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
+
+ if (abstract_parcel == nullptr ||
+ abstract_parcel->GetType() != pcp::ParcelableType::DepInfo) {
+ _LOGE("Invalid parcel or type");
+ result_ = std::make_shared<pcp::DepInfoParcelable>(
+ PMINFO_R_ERROR, std::vector<dependency_x*>{});
+ return false;
+ }
+
+ auto* parcel = dynamic_cast<pcp::DepInfoParcelable*>(abstract_parcel.get());
+ if (parcel == nullptr) {
+ _LOGE("Parcel is empty");
+ result_ = std::make_shared<pcp::DepInfoParcelable>(
+ PMINFO_R_ERROR, std::vector<dependency_x*>{});
+ return false;
+ }
+
+ psd::DepInfoGetDBHandler db(parcel->GetUid(), GetPID());
+ db.SetPkgID(parcel->GetPkgID());
+ int ret = db.Execute();
+
+ result_ = std::make_shared<pcp::DepInfoParcelable>(
+ ret, db.GetDependencyList());
+ return true;
+}
+
+std::vector<uint8_t> GetDepinfoRequestHandler::ExtractResult() {
+ tizen_base::Parcel parcel;
+
+ parcel.WriteParcelable(*result_);
+ std::vector<uint8_t> raw = parcel.GetRaw();
+
+ result_.reset();
+
+ return raw;
+}
+
+} // namespace request_handler
+} // namespace pkgmgr_server
--- /dev/null
- bool HandleRequest(unsigned char* data, int size, std::string locale) override;
+// Copyright (c) 2021 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 SERVER_GET_DEPINFO_REQUEST_HANDLER_HH_
+#define SERVER_GET_DEPINFO_REQUEST_HANDLER_HH_
+
+#include "abstract_request_handler.hh"
+#include "depinfo_parcelable.hh"
+
+#include <string>
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API GetDepinfoRequestHandler : public AbstractRequestHandler {
+ public:
++ bool HandleRequest(unsigned char* data, int size,
++ const std::string& locale) override;
+
+ std::vector<uint8_t> ExtractResult() override;
+
+ private:
+ std::shared_ptr<pkgmgr_common::parcel::DepInfoParcelable> result_;
+
+};
+
+} // namespace request_handler
+} // namespace pkgmgr_server
+
+#endif // SERVER_GET_DEPINFO_REQUEST_HANDLER_HH_
--- /dev/null
- std::string locale) {
+// Copyright (c) 2021 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.
+
+#include "get_pkginfo_request_handler.hh"
+
+#include <string>
+
+#include "parcelable_factory.hh"
+#include "pkg_get_db_handler.hh"
+#include "filter_parcelable.hh"
+
+#include "pkgmgrinfo_debug.h"
+
+
+namespace pcp = pkgmgr_common::parcel;
+namespace psd = pkgmgr_server::database;
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+bool GetPkginfoRequestHandler::HandleRequest(unsigned char* data, int size,
++ const std::string& locale) {
+ auto abstract_parcel =
+ pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
+
+ if (abstract_parcel == nullptr ||
+ abstract_parcel->GetType() != pcp::ParcelableType::Filter) {
+ _LOGE("Invalid parcel or type");
+ result_ = std::make_shared<pcp::PkgInfoParcelable>(
+ PMINFO_R_ERROR, std::vector<package_x*>{});
+ return false;
+ }
+
+ auto* parcel = dynamic_cast<pcp::FilterParcelable*>(abstract_parcel.get());
+ if (parcel == nullptr) {
+ _LOGE("Parcel is empty");
+ result_ = std::make_shared<pcp::PkgInfoParcelable>(
+ PMINFO_R_ERROR, std::vector<package_x*>{});
+ return false;
+ }
+
+ psd::PkgGetDBHandler db(parcel->GetUid(), GetPID());
+ db.SetLocale(locale);
+ db.SetFilter(const_cast<pkgmgrinfo_filter_x*>(parcel->GetFilter()));
+ int ret = db.Execute();
+
+ result_ = std::make_shared<pcp::PkgInfoParcelable>(ret, db.GetPkgHandle());
+
+ return true;
+}
+
+std::vector<uint8_t> GetPkginfoRequestHandler::ExtractResult() {
+ tizen_base::Parcel parcel;
+
+ parcel.WriteParcelable(*result_);
+ std::vector<uint8_t> raw = parcel.GetRaw();
+
+ result_.reset();
+
+ return raw;
+}
+
+} // namespace request_handler
+} // namespace pkgmgr_server
--- /dev/null
- bool HandleRequest(unsigned char* data, int size, std::string locale) override;
+// Copyright (c) 2021 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 SERVER_GET_PKGINFO_REQUEST_HANDLER_HH_
+#define SERVER_GET_PKGINFO_REQUEST_HANDLER_HH_
+
+#include "abstract_request_handler.hh"
+#include "pkginfo_parcelable.hh"
+
+#include <string>
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API GetPkginfoRequestHandler : public AbstractRequestHandler {
+ public:
++ bool HandleRequest(unsigned char* data, int size,
++ const std::string& locale) override;
+
+ std::vector<uint8_t> ExtractResult() override;
+
+ private:
+ std::shared_ptr<pkgmgr_common::parcel::PkgInfoParcelable> result_;
+};
+
+} // namespace request_handler
+} // namespace pkgmgr_server
+
+#endif // SERVER_GET_PKGINFO_REQUEST_HANDLER_HH_
--- /dev/null
- std::string locale) {
+// Copyright (c) 2021 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.
+
+#include "query_request_handler.hh"
+
+#include <string>
+
+#include "parcelable_factory.hh"
+#include "query_handler.hh"
+#include "query_parcelable.hh"
+
+#include "pkgmgrinfo_debug.h"
+
+namespace pcp = pkgmgr_common::parcel;
+namespace psd = pkgmgr_server::database;
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+bool QueryRequestHandler::HandleRequest(unsigned char* data, int size,
++ const std::string& locale) {
+ auto abstract_parcel =
+ pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
+
+ if (abstract_parcel == nullptr ||
+ abstract_parcel->GetType() != pcp::ParcelableType::Query) {
+ _LOGE("Invalid parcel or type");
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ PMINFO_R_ERROR, std::vector<std::vector<std::string>>{});
+ return false;
+ }
+
+ auto* parcel = dynamic_cast<pcp::QueryParcelable*>(abstract_parcel.get());
+ if (parcel == nullptr) {
+ _LOGE("Parcel is empty");
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ PMINFO_R_ERROR, std::vector<std::vector<std::string>>{});
+ return false;
+ }
+
+ psd::QueryHandler db(parcel->GetUid(), GetPID());
+ db.SetLocale(locale);
+ db.SetQueryArgs(parcel->GetQueryArgs());
+ db.SetDBType(parcel->GetDBType());
+ db.SetOpType(parcel->GetOpType());
+ int ret = db.Execute();
+
+ result_ = std::make_shared<pcp::ResultParcelable>(ret, db.GetResult());
+
+ return true;
+}
+
+std::vector<uint8_t> QueryRequestHandler::ExtractResult() {
+ tizen_base::Parcel parcel;
+
+ parcel.WriteParcelable(*result_);
+ std::vector<uint8_t> raw = parcel.GetRaw();
+
+ result_.reset();
+
+ return raw;
+}
+
+} // namespace request_handler
+} // namespace pkgmgr_server
--- /dev/null
- bool HandleRequest(unsigned char* data, int size, std::string locale) override;
+// Copyright (c) 2021 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 SERVER_QUERY_REQUEST_HANDLER_HH_
+#define SERVER_QUERY_REQUEST_HANDLER_HH_
+
+#include "abstract_request_handler.hh"
+#include "result_parcelable.hh"
+
+
+#include <string>
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API QueryRequestHandler : public AbstractRequestHandler {
+ public:
++ bool HandleRequest(unsigned char* data, int size,
++ const std::string& locale) override;
+
+ std::vector<uint8_t> ExtractResult() override;
+
+private:
+ std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> result_;
+
+};
+
+} // namespace request_handler
+} // namespace pkgmgr_server
+
+#endif // SERVER_QUERY_REQUEST_HANDLER_HH_
--- /dev/null
- std::string locale) {
+// Copyright (c) 2021 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.
+
+#include "set_cert_request_handler.hh"
+
+#include <string>
+
+#include "certinfo_parcelable.hh"
+#include "cert_set_db_handler.hh"
+#include "parcelable_factory.hh"
+
+#include "pkgmgrinfo_debug.h"
+
+namespace pcp = pkgmgr_common::parcel;
+namespace psd = pkgmgr_server::database;
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+bool SetCertRequestHandler::HandleRequest(unsigned char* data, int size,
++ const std::string& locale) {
+ auto abstract_parcel =
+ pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
+
+ if (abstract_parcel == nullptr ||
+ abstract_parcel->GetType() != pcp::ParcelableType::CertInfo) {
+ _LOGE("Invalid parcel");
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ PMINFO_R_ERROR, std::vector<std::vector<std::string>>{});
+ return false;
+ }
+
+ auto* parcel = dynamic_cast<pcp::CertInfoParcelable*>(abstract_parcel.get());
+ if (parcel == nullptr) {
+ _LOGE("Parcel is empty");
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ PMINFO_R_ERROR, std::vector<std::vector<std::string>>{});
+ return false;
+ }
+
+ psd::CertSetDBHandler db(parcel->GetUid(), GetPID());
+ db.SetLocale(locale);
+ db.SetCertHandle(const_cast<pkgmgr_certinfo_x*>(parcel->GetCertInfo()));
+
+ int ret = db.Execute();
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ ret, std::vector<std::vector<std::string>>{});
+
+ return true;
+}
+
+std::vector<uint8_t> SetCertRequestHandler::ExtractResult() {
+ tizen_base::Parcel parcel;
+
+ parcel.WriteParcelable(*result_);
+ std::vector<uint8_t> raw = parcel.GetRaw();
+
+ result_.reset();
+
+ return raw;
+}
+
+} // namespace request_handler
+} // namespace pkgmgr_server
--- /dev/null
- bool HandleRequest(unsigned char* data, int size, std::string locale) override;
+// Copyright (c) 2021 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 SERVER_SET_CERT_REQUEST_HANDLER_HH_
+#define SERVER_SET_CERT_REQUEST_HANDLER_HH_
+
+#include "abstract_request_handler.hh"
+#include "result_parcelable.hh"
+
+#include <string>
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API SetCertRequestHandler : public AbstractRequestHandler {
+ public:
++ bool HandleRequest(unsigned char* data, int size,
++ const std::string& locale) override;
+
+ std::vector<uint8_t> ExtractResult() override;
+
+ private:
+ std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> result_;
+};
+
+} // namespace request_handler
+} // namespace pkgmgr_server
+
+#endif // SERVER_SET_CERT_REQUEST_HANDLER_HH_
--- /dev/null
- std::string locale) {
+// Copyright (c) 2021 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.
+
+#include "set_pkginfo_request_handler.hh"
+
+#include <string>
+
+#include "parcelable_factory.hh"
+#include "pkginfo_parcelable.hh"
+#include "pkg_set_db_handler.hh"
+
+#include "pkgmgr_parser.h"
+
+#include "pkgmgrinfo_debug.h"
+
+namespace pcp = pkgmgr_common::parcel;
+namespace psd = pkgmgr_server::database;
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+bool SetPkginfoRequestHandler::HandleRequest(unsigned char* data, int size,
++ const std::string& locale) {
+ auto abstract_parcel =
+ pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
+
+ if (abstract_parcel == nullptr ||
+ abstract_parcel->GetType() != pcp::ParcelableType::PkgInfo) {
+ _LOGE("Invalid parcel or type");
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ PM_PARSER_R_ERROR, std::vector<std::vector<std::string>>{});
+ return false;
+ }
+
+ auto* parcel = dynamic_cast<pcp::PkgInfoParcelable*>(abstract_parcel.get());
+ if (parcel == nullptr) {
+ _LOGE("Parcel is empty");
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ PM_PARSER_R_ERROR, std::vector<std::vector<std::string>>{});
+ return false;
+ }
+
+ psd::PkgSetDBHandler db(parcel->GetUid(), GetPID());
+ db.SetLocale(locale);
+ db.SetWriteType(parcel->GetWriteType());
+
+ int ret = PM_PARSER_R_ERROR;
+
+ for (auto& i : parcel->GetPkgInfo()) {
+ db.SetPkgInfo(i);
+ ret = db.Execute();
+ if (ret != PM_PARSER_R_OK) {
+ _LOGE("Failed to set pkginfo");
+ break;
+ }
+ }
+
+ result_ = std::make_shared<pcp::ResultParcelable>(
+ ret, std::vector<std::vector<std::string>>{});
+
+ return true;
+}
+
+std::vector<uint8_t> SetPkginfoRequestHandler::ExtractResult() {
+ tizen_base::Parcel parcel;
+
+ parcel.WriteParcelable(*result_);
+ std::vector<uint8_t> raw = parcel.GetRaw();
+
+ result_.reset();
+
+ return raw;
+}
+
+} // namespace request_handler
+} // namespace pkgmgr_server
--- /dev/null
- bool HandleRequest(unsigned char* data, int size, std::string locale) override;
+// Copyright (c) 2021 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 SERVER_SET_PKGINFO_REQUEST_HANDLER_HH_
+#define SERVER_SET_PKGINFO_REQUEST_HANDLER_HH_
+
+#include "abstract_request_handler.hh"
+#include "result_parcelable.hh"
+
+#include <string>
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API SetPkginfoRequestHandler : public AbstractRequestHandler {
+ public:
++ bool HandleRequest(unsigned char* data, int size,
++ const std::string& locale) override;
+
+ std::vector<uint8_t> ExtractResult() override;
+
+ private:
+ std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> result_;
+};
+
+} // namespace request_handler
+} // namespace pkgmgr_server
+
+#endif // SERVER_SET_PKGINFO_REQUEST_HANDLER_HH_
Runner::~Runner() {
g_source_remove(sid_);
- vconf_ignore_key_changed(VCONFKEY_LANGSET, OnLanguageChange);
+ CynaraChecker::GetInst().Fini();
+ pkgmgr_common::SystemLocale::GetInst().UnRegisterEvent();
}
int Runner::OnReceiveRequest(int fd, GIOCondition cond, void* user_data) {
return G_SOURCE_CONTINUE;
}
- void Runner::OnLanguageChange(keynode_t* key, void* user_data) {
- auto runner = static_cast<Runner*>(user_data);
- std::unique_ptr<char, decltype(std::free)*> locale(
- _get_system_locale(), std::free);
- if (locale.get() == nullptr)
- return;
-
- runner->thread_pool_->SetLocale(locale.get());
+ void Runner::OnChanged(const std::string& locale) {
+ thread_pool_->SetLocale(locale);
}
-bool Runner::QueueRequest(int client_fd) {
- auto req = std::make_shared<PkgRequest>(client_fd);
- thread_pool_->PushQueue(req);
+bool Runner::QueueRequest(std::shared_ptr<PkgRequest> req) {
+ thread_pool_->PushQueue(std::move(req));
return true;
}
public:
Runner(unsigned int thread_num);
~Runner();
+ bool QueueRequest(std::shared_ptr<PkgRequest> req);
+ void OnChanged(const std::string& locale) override;
+
private:
static int OnReceiveRequest(int fd, GIOCondition cond, void* user_data);
- static void OnLanguageChange(keynode_t* key, void* user_data);
+ bool QueueRequest(int client_fd);
private:
int sid_;
return dependency;
}
-bool IsEqualDepInfo(const std::vector<dependency_x *>& depA,
- const std::vector<dependency_x *>& depB) {
+bool IsEqualDepInfo(const std::vector<dependency_x*>& depA,
+ const std::vector<dependency_x*>& depB) {
INT_EQ(depA.size(), depB.size());
- for (int i = 0; i < static_cast<int>(depA.size()); ++i) {
- dependency_x* A = depA[0];
- dependency_x* B = depB[0];
+ for (unsigned int i = 0; i < depA.size(); ++i) {
+ dependency_x *A = depA[0];
+ dependency_x *B = depB[0];
STR_EQ(A->depends_on, B->depends_on);
STR_EQ(A->pkgid, B->pkgid);
STR_EQ(A->required_version, B->required_version);