summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonrad Lipinski <k.lipinski2@samsung.com>2020-03-17 17:31:45 +0100
committerKonrad Lipinski <k.lipinski2@samsung.com>2020-03-17 17:31:45 +0100
commitefb2e30c43358527ec47579b6306ca1becd46e04 (patch)
tree57cba7b05c6a77b2de1ec8cc7a066a00b378d4ca
parent684af762f87eff9526ac82683e71ce9db3bc1369 (diff)
downloadkey-manager-efb2e30c43358527ec47579b6306ca1becd46e04.tar.gz
key-manager-efb2e30c43358527ec47579b6306ca1becd46e04.tar.bz2
key-manager-efb2e30c43358527ec47579b6306ca1becd46e04.zip
Store DB::Crypto::m_connection as unique_ptr
Change-Id: I289c8c7c62af72ae34ac1692f89af1d2bfd813f6
-rw-r--r--src/manager/service/db-crypto.cpp49
-rw-r--r--src/manager/service/db-crypto.h8
2 files changed, 24 insertions, 33 deletions
diff --git a/src/manager/service/db-crypto.cpp b/src/manager/service/db-crypto.cpp
index d7acb0fc..1121d669 100644
--- a/src/manager/service/db-crypto.cpp
+++ b/src/manager/service/db-crypto.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2020 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.
@@ -150,10 +150,10 @@ const char *DB_CMD_NAME_SELECT_BY_TYPE_AND_PERMISSION =
namespace CKM {
namespace DB {
Crypto::Crypto(const std::string &path, const RawBuffer &rawPass) :
- m_connection(nullptr), m_inUserTransaction(false)
+ m_inUserTransaction(false)
{
try {
- m_connection = new SqlConnection(path, SqlConnection::Flag::Option::CRW);
+ m_connection.reset(new SqlConnection(path, SqlConnection::Flag::Option::CRW));
m_connection->SetKey(rawPass);
initDatabase();
m_connection->ExecCommand("VACUUM;");
@@ -173,27 +173,18 @@ Crypto::Crypto(const std::string &path, const RawBuffer &rawPass) :
}
Crypto::Crypto(Crypto &&other) :
- m_connection(other.m_connection),
+ m_connection(std::move(other.m_connection)),
m_inUserTransaction(other.m_inUserTransaction)
{
- other.m_connection = NULL;
other.m_inUserTransaction = false;
}
-Crypto::~Crypto()
-{
- delete m_connection;
-}
-
Crypto &Crypto::operator=(Crypto &&other)
{
if (this == &other)
return *this;
- delete m_connection;
-
- m_connection = other.m_connection;
- other.m_connection = NULL;
+ m_connection = std::move(other.m_connection);
m_inUserTransaction = other.m_inUserTransaction;
other.m_inUserTransaction = false;
@@ -232,7 +223,7 @@ bool Crypto::getDBVersion(int &schemaVersion)
Transaction transaction(this);
if (m_connection->CheckTableExist("SCHEMA_INFO")) {
- SchemaInfo SchemaInfo(m_connection);
+ SchemaInfo SchemaInfo(m_connection.get());
if (SchemaInfo.getVersionInfo(schemaVersion)) {
LogDebug("Current DB version: " << schemaVersion);
return true;
@@ -285,7 +276,7 @@ void Crypto::initDatabase()
}
// update DB version info
- SchemaInfo SchemaInfo(m_connection);
+ SchemaInfo SchemaInfo(m_connection.get());
SchemaInfo.setVersionInfo();
transaction.commit();
}
@@ -323,7 +314,7 @@ void Crypto::createDBSchema()
"Can not create the database schema: no initialization script");
m_connection->ExecCommand((*script).c_str());
- SchemaInfo SchemaInfo(m_connection);
+ SchemaInfo SchemaInfo(m_connection.get());
SchemaInfo.setVersionInfo();
transaction.commit();
}
@@ -344,7 +335,7 @@ void Crypto::resetDB()
bool Crypto::isNameOwnerPresent(const Name &name, const ClientId &owner) const
{
try {
- NameTable nameTable(this->m_connection);
+ NameTable nameTable(m_connection.get());
return nameTable.isPresent(name, owner);
} catch (const SqlConnection::Exception::SyntaxError &) {
LogError("Couldn't prepare insert statement");
@@ -361,9 +352,9 @@ void Crypto::saveRows(const Name &name, const ClientId &owner,
{
try {
// transaction is present in the layer above
- NameTable nameTable(this->m_connection);
- ObjectTable objectTable(this->m_connection);
- PermissionTable permissionTable(this->m_connection);
+ NameTable nameTable(m_connection.get());
+ ObjectTable objectTable(m_connection.get());
+ PermissionTable permissionTable(m_connection.get());
nameTable.addRow(name, owner);
for (const auto &i : rows)
@@ -389,9 +380,9 @@ void Crypto::saveRow(const Row &row)
{
try {
// transaction is present in the layer above
- NameTable nameTable(this->m_connection);
- ObjectTable objectTable(this->m_connection);
- PermissionTable permissionTable(this->m_connection);
+ NameTable nameTable(m_connection.get());
+ ObjectTable objectTable(m_connection.get());
+ PermissionTable permissionTable(m_connection.get());
nameTable.addRow(row.name, row.owner);
objectTable.addRow(row);
permissionTable.setPermission(row.name,
@@ -412,7 +403,7 @@ void Crypto::updateRow(const Row &row)
{
try {
// transaction is present in the layer above
- ObjectTable objectTable(this->m_connection);
+ ObjectTable objectTable(m_connection.get());
objectTable.updateRow(row);
return;
} catch (const SqlConnection::Exception::SyntaxError &) {
@@ -430,7 +421,7 @@ bool Crypto::deleteRow(
{
try {
// transaction is present in the layer above
- NameTable nameTable(this->m_connection);
+ NameTable nameTable(m_connection.get());
if (nameTable.isPresent(name, owner)) {
nameTable.deleteRow(name, owner);
@@ -473,7 +464,7 @@ PermissionMaskOptional Crypto::getPermissionRow(
const ClientId &accessor) const
{
try {
- PermissionTable permissionTable(this->m_connection);
+ PermissionTable permissionTable(m_connection.get());
return permissionTable.getPermissionRow(name, owner, accessor);
} catch (const SqlConnection::Exception::InvalidColumn &) {
LogError("Select statement invalid column error");
@@ -679,7 +670,7 @@ void Crypto::deleteKey(const ClientId &owner)
deleteCommand->BindString(1, owner.c_str());
deleteCommand->Step();
- NameTable nameTable(this->m_connection);
+ NameTable nameTable(m_connection.get());
nameTable.deleteAllRows(owner);
transaction.commit();
@@ -700,7 +691,7 @@ void Crypto::setPermission(
const PermissionMask permissionMask)
{
try {
- PermissionTable permissionTable(this->m_connection);
+ PermissionTable permissionTable(m_connection.get());
permissionTable.setPermission(name, owner, accessor, permissionMask);
return;
} catch (const SqlConnection::Exception::SyntaxError &) {
diff --git a/src/manager/service/db-crypto.h b/src/manager/service/db-crypto.h
index 4642b749..a9153078 100644
--- a/src/manager/service/db-crypto.h
+++ b/src/manager/service/db-crypto.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Samsung Electronics Co., Ltd. All rights reserved
+ * Copyright (c) 2014-2020 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.
@@ -43,7 +43,7 @@ public:
using RowOptional = boost::optional<Row>;
using RawBufferOptional = boost::optional<RawBuffer>;
- Crypto() : m_connection(nullptr), m_inUserTransaction(false) {}
+ Crypto() : m_inUserTransaction(false) {}
// user name instead of path?
Crypto(const std::string &path, const RawBuffer &rawPass);
@@ -53,7 +53,7 @@ public:
Crypto &operator=(const Crypto &) = delete;
Crypto &operator=(Crypto &&other);
- virtual ~Crypto();
+ virtual ~Crypto() = default;
void saveRow(
const Row &row);
@@ -198,7 +198,7 @@ public:
};
protected:
- SqlConnection *m_connection;
+ std::unique_ptr<SqlConnection> m_connection;
Row getRow(
const SqlConnection::DataCommandUniquePtr &selectCommand) const;