namespace pkgmgr_common {
namespace database {
-AbstractDBHandler::AbstractDBHandler(uid_t uid) { uid_ = uid; }
+AbstractDBHandler::AbstractDBHandler(uid_t uid, int pid) {
+ uid_ = uid;
+ pid_ = pid;
+}
AbstractDBHandler::~AbstractDBHandler() {
// Is this necessary?
std::vector<std::string> AbstractDBHandler::GetDBPath() {
std::vector<std::string> db_path;
if (db_type_ == DB_TYPE_FILE_PKGDB) {
- db_path = DBHandleProvider::GetInst(uid_).GetParserDBPath();
+ db_path = DBHandleProvider::GetInst(uid_).GetParserDBPath(pid_);
} else if (db_type_ == DB_TYPE_FILE_CERTDB) {
- db_path.emplace_back(DBHandleProvider::GetInst(uid_).GetCertDBPath());
+ db_path.emplace_back(DBHandleProvider::GetInst(uid_).GetCertDBPath(pid_));
}
return db_path;
std::string AbstractDBHandler::GetLocale() { return locale_; }
+int AbstractDBHandler::GetPID() { return pid_; }
+
void AbstractDBHandler::SetLocale(const std::string& locale) {
locale_ = locale;
}
OPERATION_TYPE_WRITE
};
- AbstractDBHandler(uid_t uid);
+ AbstractDBHandler(uid_t uid, pid_t pid);
virtual ~AbstractDBHandler();
virtual int Execute() = 0;
void SetLocale(const std::string& locale);
protected:
bool Connect();
+ int GetPID();
std::vector<sqlite3*> GetConnection();
std::string GetLocale();
DBType db_type_ = DB_TYPE_NONE;
OperationType op_type_ = OPERATION_TYPE_NONE;
uid_t uid_;
+ pid_t pid_;
std::string locale_;
std::vector<sqlite3*> db_handle_list_;
};
namespace pkgmgr_common {
namespace database {
-AppInfoDBHandler::AppInfoDBHandler(uid_t uid)
- : AbstractDBHandler(uid), uid_(uid) {}
+AppInfoDBHandler::AppInfoDBHandler(uid_t uid, int pid)
+ : AbstractDBHandler(uid, pid), uid_(uid) {}
AppInfoDBHandler::~AppInfoDBHandler() {}
class EXPORT_API AppInfoDBHandler : public AbstractDBHandler{
public:
- AppInfoDBHandler(uid_t uid);
+ AppInfoDBHandler(uid_t uid, int pid);
~AppInfoDBHandler();
std::vector<application_x*> GetAppHandle();
void SetFilter(pkgmgrinfo_filter_x* filter);
namespace pkgmgr_common {
namespace database {
-CertGetDBHandler::CertGetDBHandler(uid_t uid)
- : AbstractDBHandler(uid), uid_(uid) {}
+CertGetDBHandler::CertGetDBHandler(uid_t uid, int pid)
+ : AbstractDBHandler(uid, pid), uid_(uid) {}
CertGetDBHandler::~CertGetDBHandler() {}
class EXPORT_API CertGetDBHandler : public AbstractDBHandler{
public:
- CertGetDBHandler(uid_t uid);
+ CertGetDBHandler(uid_t uid, int pid);
~CertGetDBHandler();
pkgmgr_certinfo_x* GetCertHandle();
void SetPkgID (std::string pkgid);
namespace pkgmgr_common {
namespace database {
-CertSetDBHandler::CertSetDBHandler(uid_t uid)
- : AbstractDBHandler(uid), uid_(uid) {}
+CertSetDBHandler::CertSetDBHandler(uid_t uid, int pid)
+ : AbstractDBHandler(uid, pid), uid_(uid) {}
CertSetDBHandler::~CertSetDBHandler() {}
if (!Connect())
return PMINFO_R_ERROR;
- DBHandleProvider::GetInst(uid_).SetMemoryMode(true);
+ DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID(), true);
sqlite3 *conn = GetConnection().front();
int ret = certinfo_internal_set(conn, handle_->pkgid, handle_, uid_);
class EXPORT_API CertSetDBHandler : public AbstractDBHandler{
public:
- CertSetDBHandler(uid_t uid);
+ CertSetDBHandler(uid_t uid, int pid);
~CertSetDBHandler();
void SetCertHandle (pkgmgr_certinfo_x* cert_info);
int Execute() override;
* limitations under the License.
*/
+#include <sys/types.h>
+
#include <tzplatform_config.h>
#include "db_handle_provider.hh"
#include "pkgmgr-info.h"
#include "pkgmgrinfo_debug.h"
+#include <algorithm>
#include <vector>
#ifdef LOG_TAG
std::unordered_map<uid_t, std::unique_ptr<DBHandleProvider>>
DBHandleProvider::provider_;
bool DBHandleProvider::is_memory_ = false;
+std::vector<pid_t> DBHandleProvider::pid_list_;
DBHandleProvider::DBHandleProvider(uid_t uid) : uid_(uid),
global_parser_memory_db_handle_(nullptr, sqlite3_close_v2),
return *prov;
}
-std::vector<std::string> DBHandleProvider::GetParserDBPath() {
+std::vector<std::string> DBHandleProvider::GetParserDBPath(pid_t pid) {
std::unique_lock<std::mutex> u(lock_);
std::vector<std::string> db_path_list;
- if (is_memory_) {
+ bool is_file_access = is_memory_;
+ std::vector<pid_t>::iterator it = std::find(pid_list_.begin(),
+ pid_list_.end(), pid);
+ if (it == pid_list_.end())
+ is_file_access = true;
+
+ if (!is_file_access) {
db_path_list.emplace_back(parser_memory_db_path_);
if (IsUserRequest(uid_))
db_path_list.emplace_back(global_parser_memory_db_path_);
return db_path_list;
}
-std::string DBHandleProvider::GetCertDBPath() {
+std::string DBHandleProvider::GetCertDBPath(pid_t pid) {
std::unique_lock<std::mutex> u(lock_);
- if (is_memory_)
+ bool is_file_access = is_memory_;
+ std::vector<pid_t>::iterator it = std::find(pid_list_.begin(),
+ pid_list_.end(), pid);
+ if (it == pid_list_.end())
+ is_file_access = true;
+
+ if (!is_file_access)
return cert_memory_db_path_;
else
return cert_file_db_path_;
return memorydb;
}
-void DBHandleProvider::SetMemoryMode(bool flag) {
+void DBHandleProvider::SetMemoryMode(pid_t pid, bool flag) {
std::unique_lock<std::mutex> u(lock_);
if (is_memory_ == flag)
return;
cert_memory_db_path_);
if (cert_db != nullptr)
cert_memory_db_handle_.reset(cert_db);
+ std::vector<pid_t>::iterator it =
+ std::find(pid_list_.begin(), pid_list_.end(), pid);
+
+ if (it == pid_list_.end())
+ pid_list_.emplace_back(pid);
} else {
parser_memory_db_handle_.reset(nullptr);
cert_memory_db_handle_.reset(nullptr);
global_parser_memory_db_handle_.reset(nullptr);
+ std::vector<pid_t>::iterator it =
+ std::find(pid_list_.begin(), pid_list_.end(), pid);
+ if (it != pid_list_.end())
+ pid_list_.erase(it);
+ else
+ LOGE("Given pid is not exists in pid list : %d", pid);
}
LOGD("Set Memory mode : %s", flag ? "Memory" : "File");
#include <sqlite3.h>
#include <stdlib.h>
+#include <sys/types.h>
#include <string>
#include <memory>
public:
~DBHandleProvider() = default;
static DBHandleProvider& GetInst(uid_t uid);
- std::vector<std::string> GetParserDBPath();
- std::string GetCertDBPath();
- void SetMemoryMode(bool flag);
+ std::vector<std::string> GetParserDBPath(int pid);
+ std::string GetCertDBPath(int pid);
+ void SetMemoryMode(int pid, bool flag);
private:
DBHandleProvider(uid_t uid);
std::string cert_memory_db_path_;
std::string cert_file_db_path_;
static bool is_memory_;
+ static std::vector<pid_t> pid_list_;
std::mutex lock_;
};
namespace pkgmgr_common {
namespace database {
-DepInfoGetDBHandler::DepInfoGetDBHandler(uid_t uid)
- : AbstractDBHandler(uid), uid_(uid) {}
+DepInfoGetDBHandler::DepInfoGetDBHandler(uid_t uid, int pid)
+ : AbstractDBHandler(uid, pid), uid_(uid) {}
DepInfoGetDBHandler::~DepInfoGetDBHandler() {}
class EXPORT_API DepInfoGetDBHandler : public AbstractDBHandler{
public:
- DepInfoGetDBHandler(uid_t uid);
+ DepInfoGetDBHandler(uid_t uid, int pid);
~DepInfoGetDBHandler();
std::vector<dependency_x*> GetDependencyList();
void SetPkgID(const std::string& pkgid);
namespace pkgmgr_common {
namespace database {
-PkgGetDBHandler::PkgGetDBHandler(uid_t uid)
- : AbstractDBHandler(uid), uid_(uid) {}
+PkgGetDBHandler::PkgGetDBHandler(uid_t uid, int pid)
+ : AbstractDBHandler(uid, pid), uid_(uid) {}
PkgGetDBHandler::~PkgGetDBHandler() {}
class EXPORT_API PkgGetDBHandler : public AbstractDBHandler{
public:
- PkgGetDBHandler(uid_t uid);
+ PkgGetDBHandler(uid_t uid, int pid);
~PkgGetDBHandler();
std::vector<package_x*> GetPkgHandle();
void SetFilter(pkgmgrinfo_filter_x* filter);
namespace pkgmgr_common {
namespace database {
-PkgSetDBHandler::PkgSetDBHandler(uid_t uid)
- : AbstractDBHandler(uid), uid_(uid) {}
+PkgSetDBHandler::PkgSetDBHandler(uid_t uid, int pid)
+ : AbstractDBHandler(uid, pid), uid_(uid) {}
PkgSetDBHandler::~PkgSetDBHandler() {}
int ret = 0;
- DBHandleProvider::GetInst(uid_).SetMemoryMode(true);
+ DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID(), true);
std::vector<sqlite3*> conn_list = GetConnection();
sqlite3* conn = conn_list.front();
if (write_type_ == Insert) {
class EXPORT_API PkgSetDBHandler : public AbstractDBHandler{
public:
- PkgSetDBHandler(uid_t uid);
+ PkgSetDBHandler(uid_t uid, int pid);
~PkgSetDBHandler();
void SetPkgInfo(package_x* package);
void SetPkgID(std::string pkgid);
namespace pkgmgr_common {
namespace database {
-QueryHandler::QueryHandler(uid_t uid) : AbstractDBHandler(uid), uid_(uid) {}
+QueryHandler::QueryHandler(uid_t uid, int pid)
+ : AbstractDBHandler(uid, pid), uid_(uid) {}
QueryHandler::~QueryHandler() {}
_LOGE("Failed to execute query");
return ret;
}
-
+
result_.clear();
result_.resize(row);
GList* tmp = list;
class EXPORT_API QueryHandler : public AbstractDBHandler{
public:
- QueryHandler(uid_t uid);
+ QueryHandler(uid_t uid, int pid);
~QueryHandler();
void SetQuery(std::vector<std::string> query);
bool BindString(std::string value);
--- /dev/null
+// 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 "abstract_request_handler.hh"
+
+#include "pkgmgrinfo_debug.h"
+
+#include <string>
+
+namespace pkgmgr_server {
+namespace request_handler {
+
+void AbstractRequestHandler::SetPID(pid_t pid) {
+ pid_ = pid;
+}
+
+pid_t AbstractRequestHandler::GetPID() {
+ return pid_;
+}
+
+} // namespace request_handler
+} // namespace pkgmgr_server
#define SERVER_ABSTRACT_REQUEST_HANDLER_HH_
#include <string>
+
+#include <sys/types.h>
+
#include <parcel.hh>
namespace pkgmgr_server {
virtual bool HandleRequest(unsigned char* data, int size, std::string locale) = 0;
virtual std::vector<uint8_t> GetResult() = 0;
+ void SetPID(pid_t pid);
+
+ protected:
+ pid_t GetPID();
+
+ private:
+ pid_t pid_;
};
} // namespace request_handler
}
if (parcel->GetCmd() == CommandType::RemoveCache) {
- pkgmgr_common::DBHandleProvider::GetInst(parcel->GetUid()).SetMemoryMode(false);
+ pkgmgr_common::DBHandleProvider::GetInst(parcel->GetUid()).SetMemoryMode(GetPID(), false);
result_.WriteInt32(0);
}
return false;
}
- AppInfoDBHandler db(parcel->GetUid());
+ AppInfoDBHandler db(parcel->GetUid(), GetPID());
db.SetLocale(locale);
db.SetFilter(const_cast<pkgmgrinfo_filter_x*>(parcel->GetFilter()));
int ret = db.Execute();
return false;
}
- CertGetDBHandler db(parcel->GetUid());
+ CertGetDBHandler db(parcel->GetUid(), GetPID());
db.SetLocale(locale);
db.SetPkgID(parcel->GetPkgId());
return false;
}
- DepInfoGetDBHandler db(parcel->GetUid());
+ DepInfoGetDBHandler db(parcel->GetUid(), GetPID());
db.SetPkgID(parcel->GetPkgID());
int ret = db.Execute();
return false;
}
- PkgGetDBHandler db(parcel->GetUid());
+ PkgGetDBHandler db(parcel->GetUid(), GetPID());
db.SetLocale(locale);
db.SetFilter(const_cast<pkgmgrinfo_filter_x*>(parcel->GetFilter()));
int ret = db.Execute();
return false;
}
- QueryHandler db(parcel->GetUid());
+ QueryHandler db(parcel->GetUid(), GetPID());
db.SetLocale(locale);
db.SetQuery(parcel->GetQueries());
db.SetDBType(parcel->GetDBType());
return false;
}
- CertSetDBHandler db(parcel->GetUid());
+ CertSetDBHandler db(parcel->GetUid(), GetPID());
db.SetLocale(locale);
db.SetCertHandle(const_cast<pkgmgr_certinfo_x*>(parcel->GetCertInfo()));
return false;
}
- PkgSetDBHandler db(parcel->GetUid());
+ PkgSetDBHandler db(parcel->GetUid(), GetPID());
db.SetLocale(locale);
db.SetWriteType(parcel->GetWriteType());
std::string AbstractSocket::GetPath() { return path_; }
-int AbstractSocket::GetPID() {
+pid_t AbstractSocket::GetPID() {
int r;
struct ucred cred;
socklen_t len;
#define COMMON_ABSTRACT_SOCKET_HH_
#include <sys/un.h>
+#include <sys/types.h>
#include <string>
int GetFd();
std::string GetPath();
- int GetPID();
+ pid_t GetPID();
protected:
void SetOption();
int PkgRequest::GetSize() { return data_size_; }
-int PkgRequest::GetSenderPID() {
+pid_t PkgRequest::GetSenderPID() {
return socket_->GetPID();
}
#define SERVER_PKG_REQUEST_HH_
#include <memory>
+
+#include <sys/types.h>
+
#include "data_socket.hh"
#include "request_type.hh"
~PkgRequest();
unsigned char* GetData();
int GetSize();
- int GetSenderPID();
+ pid_t GetSenderPID();
pkgmgr_common::ReqType GetRequestType();
bool ReceiveData();
bool SendData(unsigned char* data, int size);
}
try {
+ handler[type]->SetPID(req->GetSenderPID());
if (!handler[type]->HandleRequest(req->GetData(), req->GetSize(),
locale_.GetObject()))
LOGE("Failed to handle request");
};
TEST_F(DatabaseTest, AppInfoDBHandler) {
- pd::AppInfoDBHandler db_handler(0);
+ pd::AppInfoDBHandler db_handler(0, 0);
EXPECT_NE(db_handler.Execute(), PMINFO_R_OK);
}