From dc6cce5f0cc99d0922ad740971e6ef453e115f5a Mon Sep 17 00:00:00 2001 From: Martin Vierula Date: Tue, 24 Oct 2023 06:36:18 -0700 Subject: [PATCH] refactoring and remove dead code in lmdb --- headers/modsecurity/collection/collection.h | 16 -------- .../backend/in_memory-per_process.h | 16 +++++++- src/collection/backend/lmdb.cc | 37 ------------------- src/collection/backend/lmdb.h | 1 - 4 files changed, 15 insertions(+), 55 deletions(-) diff --git a/headers/modsecurity/collection/collection.h b/headers/modsecurity/collection/collection.h index 4c2ed34f..25d86b9a 100644 --- a/headers/modsecurity/collection/collection.h +++ b/headers/modsecurity/collection/collection.h @@ -45,7 +45,6 @@ class Collection { public: explicit Collection(const std::string &a) : m_name(a) { } virtual ~Collection() { } - virtual void store(std::string key, std::string value) = 0; virtual bool storeOrUpdateFirst(const std::string &key, const std::string &value) = 0; @@ -70,21 +69,6 @@ class Collection { variables::KeyExclusions &ke) = 0; - /* store */ - virtual void store(std::string key, std::string compartment, - std::string value) { - std::string nkey = compartment + "::" + key; - store(nkey, value); - } - - - virtual void store(std::string key, std::string compartment, - std::string compartment2, std::string value) { - std::string nkey = compartment + "::" + compartment2 + "::" + key; - store(nkey, value); - } - - /* storeOrUpdateFirst */ virtual bool storeOrUpdateFirst(const std::string &key, std::string compartment, const std::string &value) { diff --git a/src/collection/backend/in_memory-per_process.h b/src/collection/backend/in_memory-per_process.h index cd5f44e8..43b8de24 100644 --- a/src/collection/backend/in_memory-per_process.h +++ b/src/collection/backend/in_memory-per_process.h @@ -76,7 +76,7 @@ class InMemoryPerProcess : public: explicit InMemoryPerProcess(const std::string &name); ~InMemoryPerProcess(); - void store(std::string key, std::string value) override; + void store(std::string key, std::string value); bool storeOrUpdateFirst(const std::string &key, const std::string &value) override; @@ -101,6 +101,20 @@ class InMemoryPerProcess : std::vector *l, variables::KeyExclusions &ke) override; + /* store */ + virtual void store(std::string key, std::string compartment, + std::string value) { + std::string nkey = compartment + "::" + key; + store(nkey, value); + } + + + virtual void store(std::string key, std::string compartment, + std::string compartment2, std::string value) { + std::string nkey = compartment + "::" + compartment2 + "::" + key; + store(nkey, value); + } + private: pthread_mutex_t m_lock; }; diff --git a/src/collection/backend/lmdb.cc b/src/collection/backend/lmdb.cc index 0fb92964..9197fda8 100644 --- a/src/collection/backend/lmdb.cc +++ b/src/collection/backend/lmdb.cc @@ -397,43 +397,6 @@ end_txn: } -void LMDB::store(std::string key, std::string value) { - MDB_val mdb_key, mdb_data; - MDB_txn *txn = NULL; - int rc; - MDB_stat mst; - - rc = txn_begin(0, &txn); - lmdb_debug(rc, "txn", "store"); - if (rc != 0) { - goto end_txn; - } - - string2val(key, &mdb_key); - string2val(value, &mdb_data); - rc = mdb_put(txn, m_dbi, &mdb_key, &mdb_data, 0); - lmdb_debug(rc, "put", "store"); - if (rc != 0) { - goto end_put; - } - - rc = mdb_txn_commit(txn); - lmdb_debug(rc, "commit", "store"); - if (rc != 0) { - goto end_commit; - } - -end_put: -end_dbi: - if (rc != 0) { - mdb_txn_abort(txn); - } -end_commit: -end_txn: - return; -} - - bool LMDB::updateFirst(const std::string &key, const std::string &value) { int rc; diff --git a/src/collection/backend/lmdb.h b/src/collection/backend/lmdb.h index 11b4760a..fb88b003 100644 --- a/src/collection/backend/lmdb.h +++ b/src/collection/backend/lmdb.h @@ -98,7 +98,6 @@ class LMDB : public Collection { public: explicit LMDB(const std::string &name); - void store(std::string key, std::string value) override; bool storeOrUpdateFirst(const std::string &key, const std::string &value) override;