Skip to content

Commit 3062ff2

Browse files
committed
Using Collection instead of GlobalCollection
Both has the same methods and characteristics except for the fact that one is global and the other not. That can be handled by the backend.
1 parent 64c4f23 commit 3062ff2

File tree

14 files changed

+135
-649
lines changed

14 files changed

+135
-649
lines changed

headers/modsecurity/collection/collection.h

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
#include "modsecurity/collection/variable.h"
2828

29-
#ifndef HEADERS_MODSECURITY_TRANSACTION_COLLECTION_H_
30-
#define HEADERS_MODSECURITY_TRANSACTION_COLLECTION_H_
29+
#ifndef HEADERS_MODSECURITY_COLLECTION_COLLECTION_H_
30+
#define HEADERS_MODSECURITY_COLLECTION_COLLECTION_H_
3131

3232
#ifndef __cplusplus
3333
typedef struct Variable_t Variables;
@@ -44,7 +44,8 @@ class Collection {
4444
virtual bool storeOrUpdateFirst(const std::string &key,
4545
const std::string &value) = 0;
4646

47-
virtual bool updateFirst(const std::string &key, const std::string &value) = 0;
47+
virtual bool updateFirst(const std::string &key,
48+
const std::string &value) = 0;
4849

4950
virtual void del(const std::string& key) = 0;
5051

@@ -56,11 +57,33 @@ class Collection {
5657
std::vector<const Variable *> *l) = 0;
5758
virtual void resolveRegularExpression(const std::string& var,
5859
std::vector<const Variable *> *l) = 0;
60+
61+
62+
virtual void store(std::string key, std::string compartment,
63+
std::string value) = 0;
64+
65+
virtual bool storeOrUpdateFirst(const std::string &key,
66+
std::string compartment, const std::string &value) = 0;
67+
68+
virtual bool updateFirst(const std::string &key, std::string compartment,
69+
const std::string &value) = 0;
70+
71+
virtual void del(const std::string& key, std::string compartment) = 0;
72+
73+
virtual std::string* resolveFirst(const std::string& var,
74+
std::string compartment) = 0;
75+
virtual void resolveSingleMatch(const std::string& var,
76+
std::string compartment, std::vector<const Variable *> *l) = 0;
77+
virtual void resolveMultiMatches(const std::string& var,
78+
std::string compartment, std::vector<const Variable *> *l) = 0;
79+
virtual void resolveRegularExpression(const std::string& var,
80+
std::string compartment,
81+
std::vector<const Variable *> *l) = 0;
5982
};
6083

6184
} // namespace collection
6285
} // namespace modsecurity
6386
#endif
6487

6588

66-
#endif // HEADERS_MODSECURITY_TRANSACTION_COLLECTION_H_
89+
#endif // HEADERS_MODSECURITY_COLLECTION_COLLECTION_H_

headers/modsecurity/collection/collections.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@
2727
#include <list>
2828
#endif
2929

30-
#include "modsecurity/collection/global_collection.h"
3130
#include "modsecurity/collection/collection.h"
3231
#include "modsecurity/collection/variable.h"
3332

34-
#ifndef HEADERS_MODSECURITY_TRANSACTION_COLLECTIONS_H_
35-
#define HEADERS_MODSECURITY_TRANSACTION_COLLECTIONS_H_
33+
#ifndef HEADERS_MODSECURITY_COLLECTION_COLLECTIONS_H_
34+
#define HEADERS_MODSECURITY_COLLECTION_COLLECTIONS_H_
3635

3736
#ifndef __cplusplus
3837
typedef struct Collections_t Collections;
@@ -46,7 +45,7 @@ namespace collection {
4645
class Collections :
4746
public std::unordered_map<std::string, Collection *> {
4847
public:
49-
Collections(GlobalCollection *global, GlobalCollection *ip);
48+
Collections(Collection *global, Collection *ip);
5049
~Collections();
5150

5251
void store(std::string key, std::string value);
@@ -88,15 +87,15 @@ class Collections :
8887
std::string m_global_collection_key;
8988
std::string m_ip_collection_key;
9089

91-
GlobalCollection *m_global_collection;
92-
GlobalCollection *m_ip_collection;
90+
Collection *m_global_collection;
91+
Collection *m_ip_collection;
9392
};
9493

9594
} // namespace collection
9695
} // namespace modsecurity
9796
#endif
9897

9998

100-
#endif // HEADERS_MODSECURITY_TRANSACTION_COLLECTIONS_H_
99+
#endif // HEADERS_MODSECURITY_COLLECTION_COLLECTIONS_H_
101100

102101

headers/modsecurity/collection/global_collection.h

Lines changed: 0 additions & 119 deletions
This file was deleted.

headers/modsecurity/collection/variable.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#endif
2020

2121

22-
#ifndef HEADERS_MODSECURITY_TRANSACTION_VARIABLE_H_
23-
#define HEADERS_MODSECURITY_TRANSACTION_VARIABLE_H_
22+
#ifndef HEADERS_MODSECURITY_COLLECTION_VARIABLE_H_
23+
#define HEADERS_MODSECURITY_COLLECTION_VARIABLE_H_
2424

2525

2626
#ifndef __cplusplus
@@ -44,4 +44,4 @@ class Variable {
4444
} // namespace modsecurity
4545
#endif
4646

47-
#endif // HEADERS_MODSECURITY_TRANSACTION_VARIABLE_H_
47+
#endif // HEADERS_MODSECURITY_COLLECTION_VARIABLE_H_

headers/modsecurity/modsecurity.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ typedef struct ModSecurity_t modsecurity;
9393
#include "modsecurity/transaction.h"
9494
#include "modsecurity/debug_log.h"
9595
#include "modsecurity/rules.h"
96-
#include "modsecurity/collection/global_collection.h"
9796

9897
/**
9998
* TAG_NUM:
@@ -223,8 +222,9 @@ class ModSecurity {
223222
NUMBER_OF_PHASES,
224223
};
225224

226-
collection::GlobalCollection m_global_collection;
227-
collection::GlobalCollection m_ip_collection;
225+
collection::Collection *m_global_collection;
226+
collection::Collection *m_ip_collection;
227+
228228
private:
229229
std::string m_connector;
230230
LogCb m_logCb;

src/Makefile.am

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pkginclude_HEADERS = \
3434
libmodsecurity_includesub_HEADERS = \
3535
../headers/modsecurity/collection/collection.h \
3636
../headers/modsecurity/collection/collections.h \
37-
../headers/modsecurity/collection/global_collection.h \
3837
../headers/modsecurity/collection/variable.h
3938

4039

@@ -175,7 +174,6 @@ UTILS = \
175174

176175
COLLECTION = \
177176
collection/collections.cc \
178-
collection/global_collections.cc \
179177
collection/backend/in_memory-per_process.cc
180178

181179

src/collection/backend/in_memory-per_process.cc

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ bool InMemoryPerProcess::storeOrUpdateFirst(const std::string &key,
5353
}
5454

5555

56-
bool InMemoryPerProcess::updateFirst(const std::string &key, const std::string &value) {
56+
bool InMemoryPerProcess::updateFirst(const std::string &key,
57+
const std::string &value) {
5758
auto range = this->equal_range(key);
5859

5960
for (auto it = range.first; it != range.second; ++it) {
@@ -121,6 +122,63 @@ std::string* InMemoryPerProcess::resolveFirst(const std::string& var) {
121122
return NULL;
122123
}
123124

125+
126+
void InMemoryPerProcess::store(std::string key, std::string compartment,
127+
std::string value) {
128+
std::string nkey = key + "::" + compartment;
129+
store(nkey, value);
130+
}
131+
132+
133+
bool InMemoryPerProcess::storeOrUpdateFirst(const std::string &key,
134+
std::string compartment, const std::string &value) {
135+
std::string nkey = key + "::" + compartment;
136+
return storeOrUpdateFirst(nkey, value);
137+
}
138+
139+
140+
bool InMemoryPerProcess::updateFirst(const std::string &key,
141+
std::string compartment, const std::string &value) {
142+
std::string nkey = key + "::" + compartment;
143+
return updateFirst(nkey, value);
144+
}
145+
146+
147+
void InMemoryPerProcess::del(const std::string& key,
148+
std::string compartment) {
149+
std::string nkey = key + "::" + compartment;
150+
del(nkey);
151+
}
152+
153+
154+
std::string* InMemoryPerProcess::resolveFirst(const std::string& var,
155+
std::string compartment) {
156+
std::string nkey = var + "::" + compartment;
157+
return resolveFirst(nkey);
158+
}
159+
160+
161+
void InMemoryPerProcess::resolveSingleMatch(const std::string& var,
162+
std::string compartment, std::vector<const Variable *> *l) {
163+
std::string nkey = var + "::" + compartment;
164+
resolveSingleMatch(nkey, l);
165+
}
166+
167+
168+
void InMemoryPerProcess::resolveMultiMatches(const std::string& var,
169+
std::string compartment, std::vector<const Variable *> *l) {
170+
std::string nkey = var + "::" + compartment;
171+
resolveMultiMatches(nkey, l);
172+
}
173+
174+
175+
void InMemoryPerProcess::resolveRegularExpression(const std::string& var,
176+
std::string compartment, std::vector<const Variable *> *l) {
177+
std::string nkey = var + "::" + compartment;
178+
resolveRegularExpression(nkey, l);
179+
}
180+
181+
124182
} // namespace backend
125183
} // namespace collection
126184
} // namespace modsecurity

0 commit comments

Comments
 (0)