#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);
auto dbpath_list = GetDBPath();
int ret = 0;
sqlite3* db;
- for (auto dbpath : dbpath_list) {
+ for (auto& dbpath : dbpath_list) {
- if (op_type_ == OPERATION_TYPE_READ) {
+ 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 {
+ } 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,
int AbstractDBHandler::GetPID() { return pid_; }
- void AbstractDBHandler::SetLocale(const std::string& locale) {
- locale_ = locale;
+uid_t AbstractDBHandler::GetUID() { return uid_; }
+
+ void AbstractDBHandler::SetLocale(std::string locale) {
+ locale_ = std::move(locale);
}
-void AbstractDBHandler::SetDBType(DBType type) { db_type_ = type; }
+void AbstractDBHandler::SetDBType(pkgmgr_common::DBType type) { db_type_ = type; }
-AbstractDBHandler::OperationType AbstractDBHandler::GetOpType() {
+pkgmgr_common::DBOperationType AbstractDBHandler::GetOpType() {
return op_type_;
}
#include <sys/types.h>
#include <sqlite3.h>
- #include "query_parcelable.hh"
-namespace pkgmgr_common {
+#include "db_type.hh"
++#include "query_parcelable.hh"
+
+namespace pkgmgr_server {
namespace database {
#ifndef EXPORT_API
AbstractDBHandler(uid_t uid, pid_t pid);
virtual ~AbstractDBHandler();
virtual int Execute() = 0;
- void SetLocale(const std::string& locale);
+ void SetLocale(std::string locale);
- void SetDBType(DBType type);
- void SetOpType(OperationType type);
- OperationType GetOpType();
+ void SetDBType(pkgmgr_common::DBType type);
+ void SetOpType(pkgmgr_common::DBOperationType type);
+ pkgmgr_common::DBOperationType GetOpType();
protected:
- bool Connect();
+ virtual bool Connect();
int GetPID();
- std::vector<std::pair<sqlite3*, uid_t>> GetConnection();
+ uid_t GetUID();
+ virtual std::vector<std::pair<sqlite3*, uid_t>> GetConnection();
+ void ClearDBHandle();
- std::string GetLocale();
+ const std::string& GetLocale();
static std::shared_timed_mutex lock_;
private:
std::vector<std::pair<std::string, uid_t>> GetDBPath();
--- /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_
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);