/* Common code for handling SqlConnection exceptions */
template <class F>
-auto try_catch_db(F &&f) {
+auto try_catch_db(std::mutex &m, F &&f) {
try {
+ std::lock_guard<std::mutex> lock(m);
return std::forward<F>(f)();
} catch (DB::SqlConnection::Exception::SyntaxError &e) {
LogError("Syntax error in command: " << e.DumpToString());
void PrivilegeDb::BeginTransaction(void)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
mSqlConnection.BeginTransaction();
});
}
void PrivilegeDb::CommitTransaction(void)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
mSqlConnection.CommitTransaction();
});
}
void PrivilegeDb::RollbackTransaction(void)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
mSqlConnection.RollbackTransaction();
});
}
bool PrivilegeDb::PkgNameExists(const std::string &pkgName)
{
- return try_catch_db([&] {
+ return try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EPkgNameExists);
int cnt = 0;
bool PrivilegeDb::AppNameExists(const std::string &appName)
{
- return try_catch_db([&] {
+ return try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EAppNameExists);
int cnt = 0;
void PrivilegeDb::GetAppPkgName(const std::string &appName, std::string &pkgName)
{
- return try_catch_db([&] {
+ return try_catch_db(m_api_mutex, [&] {
pkgName.clear();
auto command = getStatement(StmtType::EGetAppPkgName);
bool PrivilegeDb::GetAppPkgInfo(const std::string &appName, std::string &pkgName, bool &isHybrid, bool &isSharedRO)
{
- return try_catch_db([&] {
+ return try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetAppPkgInfo);
command->BindString(1, appName);
void PrivilegeDb::GetAppVersion(const std::string &appName, std::string &tizenVer)
{
- return try_catch_db([&] {
+ return try_catch_db(m_api_mutex, [&] {
tizenVer.clear();
auto command = getStatement(StmtType::EGetAppVersion);
const std::string &authorName,
bool isHybrid)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EAddApplication);
command->BindString(1, appName);
command->BindString(2, pkgName);
bool &pkgNameIsNoMore,
bool &authorNameIsNoMore)
{
- try_catch_db([&] {
- if (!AppNameExists(appName))
- return;
+ if (!AppNameExists(appName))
+ return;
+ std::string pkgName;
+ GetAppPkgName(appName, pkgName);
- std::string pkgName;
- GetAppPkgName(appName, pkgName);
-
- std::string authorHash;
- GetPkgAuthorHash(pkgName, authorHash);
+ std::string authorHash;
+ GetPkgAuthorHash(pkgName, authorHash);
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::ERemoveApplication);
command->BindString(1, appName);
command->BindInteger(2, static_cast<unsigned int>(uid));
};
LogDebug("Removed appName: " << appName);
-
- appNameIsNoMore = !(AppNameExists(appName));
- pkgNameIsNoMore = !(PkgNameExists(pkgName));
- authorNameIsNoMore = !(AuthorExists(authorHash));
});
+
+ appNameIsNoMore = !(AppNameExists(appName));
+ pkgNameIsNoMore = !(PkgNameExists(pkgName));
+ authorNameIsNoMore = !(AuthorExists(authorHash));
}
void PrivilegeDb::GetPathSharingCount(const std::string &path, int &count)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetPathSharedCount);
command->BindString(1, path);
void PrivilegeDb::GetOwnerTargetSharingCount(const std::string &ownerAppName,
const std::string &targetAppName, int &count)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetOwnerTargetSharedCount);
command->BindString(1, ownerAppName);
command->BindString(2, targetAppName);
void PrivilegeDb::GetTargetPathSharingCount(const std::string &targetAppName,
const std::string &path, int &count)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetTargetPathSharedCount);
command->BindString(1, targetAppName);
command->BindString(2, path);
const std::string &targetAppName, const std::string &path,
const std::string &pathLabel)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EAddPrivatePathSharing);
command->BindString(1, ownerAppName);
command->BindString(2, targetAppName);
void PrivilegeDb::DropPrivateSharing(const std::string &ownerAppName,
const std::string &targetAppName, const std::string &path)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::ERemovePrivatePathSharing);
command->BindString(1, ownerAppName);
command->BindString(2, targetAppName);
}
void PrivilegeDb::GetAllPrivateSharing(std::map<std::string, std::vector<std::string>> &appPathMap) {
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetAllSharedPaths);
while (command->Step()) {
std::string appName = command->GetColumnString(0);
void PrivilegeDb::GetPrivateSharingForOwner(const std::string &ownerAppName,
std::map<std::string, std::vector<std::string>> &ownerSharing)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetSharingForOwner);
command->BindString(1, ownerAppName);
while (command->Step()) {
void PrivilegeDb::GetPrivateSharingForTarget(const std::string &targetAppName,
std::map<std::string, std::vector<std::string>> &targetSharing)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetSharingForTarget);
command->BindString(1, targetAppName);
while (command->Step()) {
}
void PrivilegeDb::SquashSharing(const std::string &targetAppName, const std::string &path) {
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::ESquashSharing);
command->BindString(1, targetAppName);
command->BindString(2, path);
}
void PrivilegeDb::ClearPrivateSharing() {
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
{
auto command = getStatement(StmtType::EClearSharing);
command->Step();
void PrivilegeDb::GetUserApps(uid_t uid, std::vector<std::string> &apps)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetUserApps);
command->BindInteger(1, static_cast<unsigned int>(uid));
apps.clear();
void PrivilegeDb::GetUserAppsFromPkg(uid_t uid, const std::string &pkgName, std::vector<std::string> &apps)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetUserAppsFromPkg);
command->BindInteger(1, static_cast<unsigned int>(uid));
command->BindString(2, pkgName);
void PrivilegeDb::GetUserPkgs(uid_t uid, std::vector<std::string> &pkgs)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetUserPkgs);
command->BindInteger(1, static_cast<unsigned int>(uid));
pkgs.clear();
void PrivilegeDb::GetAllPackages(std::vector<std::string> &packages)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetAllPackages);
packages.clear();
while (command->Step()) {
void PrivilegeDb::GetPkgApps(const std::string &pkgName,
std::vector<std::string> &appNames)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetAppsInPkg);
command->BindString(1, pkgName);
void PrivilegeDb::GetPkgAuthorHash(const std::string &pkgName, std::string &authorHash)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetPkgAuthor);
command->BindString(1, pkgName);
bool PrivilegeDb::AuthorExists(const std::string &authorHash)
{
- return try_catch_db([&]() -> bool {
+ return try_catch_db(m_api_mutex, [&]() -> bool {
auto command = getStatement(StmtType::EAuthorExists);
int cnt = 0;
void PrivilegeDb::GetGroupsRelatedPrivileges(std::vector<std::pair<std::string, std::string>> &privileges)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EGetGroupsRelatedPrivileges);
while (command->Step()) {
void PrivilegeDb::SetSharedROPackage(const std::string &pkgName, bool isSharedRO)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::ESetPackageSharedRO);
command->BindInteger(1, isSharedRO);
command->BindString(2, pkgName);
bool PrivilegeDb::IsPackageHybrid(const std::string& pkgName)
{
- return try_catch_db([&]() -> bool {
+ return try_catch_db(m_api_mutex, [&]() -> bool {
auto command = getStatement(StmtType::EIsPackageHybrid);
command->BindString(1, pkgName);
int isHybrid = 0;
void PrivilegeDb::AddAppDefinedPrivilege(const std::string &appName, uid_t uid,
const AppDefinedPrivilege &privilege)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EAddAppDefinedPrivilege);
command->BindString(1, appName);
command->BindInteger(2, uid);
void PrivilegeDb::AddClientPrivilege(const std::string &appName, uid_t uid, const std::string &privilege,
const std::string &license)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::EAddClientPrivilege);
command->BindString(1, appName);
command->BindInteger(2, uid);
void PrivilegeDb::RemoveAppDefinedPrivileges(const std::string &appName, uid_t uid)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::ERemoveAppDefinedPrivileges);
command->BindString(1, appName);
command->BindInteger(2, uid);
void PrivilegeDb::RemoveClientPrivileges(const std::string &appName, uid_t uid)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
auto command = getStatement(StmtType::ERemoveClientPrivileges);
command->BindString(1, appName);
command->BindInteger(2, uid);
void PrivilegeDb::GetAppDefinedPrivileges(const std::string &appName, uid_t uid,
AppDefinedPrivilegesVector &privileges)
{
- try_catch_db([&] {
+ try_catch_db(m_api_mutex, [&] {
privileges.clear();
auto command = getStatement(StmtType::EGetAppDefinedPrivileges);
std::string &pkgName,
std::string &license)
{
- return try_catch_db([&] {
+ return try_catch_db(m_api_mutex, [&] {
appName.clear();
pkgName.clear();
license.clear();
const std::string &privilege,
std::string &license)
{
- return try_catch_db([&] {
+ return try_catch_db(m_api_mutex, [&] {
license.clear();
auto command = getStatement(StmtType::EGetLicenseForClientPrivilegeAndApp);
const std::string &privilege,
std::string &license)
{
- return try_catch_db([&] {
+ return try_catch_db(m_api_mutex, [&] {
license.clear();
auto command = getStatement(StmtType::EGetLicenseForClientPrivilegeAndPkg);
bool PrivilegeDb::IsUserPkgInstalled(const std::string& pkgName, uid_t uid)
{
- return try_catch_db([&]() -> bool {
+ return try_catch_db(m_api_mutex, [&]() -> bool {
auto command = getStatement(StmtType::EIsUserPkgInstalled);
command->BindString(1, pkgName);
command->BindInteger(2, uid);