@@ -31,7 +31,12 @@ namespace modsecurity {
3131namespace transaction {
3232
3333
34- Collections::Collections () {
34+ Collections::Collections (transaction::GlobalVariables *global,
35+ transaction::GlobalVariables *ip)
36+ : m_global_collection_key(" " ),
37+ m_ip_collection_key (" " ),
38+ m_global_collection(global),
39+ m_ip_collection(ip) {
3540 /* Create collection TX */
3641 this ->emplace (" TX" , new Collection (" TX" , " " ));
3742}
@@ -53,6 +58,20 @@ void Collections::init(const std::string& name, const std::string& key) {
5358void Collections::storeOrUpdateFirst (const std::string& collectionName,
5459 const std::string& variableName,
5560 const std::string& targetValue) {
61+ if (tolower (collectionName) == " ip"
62+ && !m_ip_collection_key.empty ()) {
63+ m_ip_collection->storeOrUpdateFirst (collectionName + " :"
64+ + variableName, m_ip_collection_key, targetValue);
65+ return ;
66+ }
67+
68+ if (tolower (collectionName) == " global"
69+ && !m_global_collection_key.empty ()) {
70+ m_global_collection->storeOrUpdateFirst (collectionName + " :"
71+ + variableName, m_global_collection_key, targetValue);
72+ return ;
73+ }
74+
5675 try {
5776 transaction::Variables *collection;
5877 collection = this ->at (collectionName);
@@ -99,7 +118,7 @@ std::string* Collections::resolveFirst(const std::string& var) {
99118 for (auto &a : *this ) {
100119 auto range = a.second ->equal_range (var);
101120 for (auto it = range.first ; it != range.second ; ++it) {
102- return &it->second ;
121+ return & it->second ;
103122 }
104123 }
105124
@@ -109,6 +128,19 @@ std::string* Collections::resolveFirst(const std::string& var) {
109128
110129std::string* Collections::resolveFirst (const std::string& collectionName,
111130 const std::string& var) {
131+
132+ if (tolower (collectionName) == " ip"
133+ && !m_ip_collection_key.empty ()) {
134+ return m_ip_collection->resolveFirst (toupper (collectionName)
135+ + " :" + var, m_ip_collection_key);
136+ }
137+
138+ if (tolower (collectionName) == " global"
139+ && !m_global_collection_key.empty ()) {
140+ return m_global_collection->resolveFirst (toupper (collectionName)
141+ + " :" + var, m_global_collection_key);
142+ }
143+
112144 for (auto &a : *this ) {
113145 if (tolower (a.first ) == tolower (collectionName)) {
114146 transaction::Variables *t = a.second ;
@@ -135,6 +167,18 @@ void Collections::resolveSingleMatch(const std::string& var,
135167 const std::string& collection,
136168 std::vector<const transaction::Variable *> *l) {
137169
170+ if (tolower (collection) == " ip"
171+ && !m_ip_collection_key.empty ()) {
172+ m_ip_collection->resolveSingleMatch (var, m_ip_collection_key, l);
173+ return ;
174+ }
175+
176+ if (tolower (collection) == " global"
177+ && !m_global_collection_key.empty ()) {
178+ m_global_collection->resolveSingleMatch (var, m_global_collection_key, l);
179+ return ;
180+ }
181+
138182 try {
139183 this ->at (collection)->resolveSingleMatch (var, l);
140184 } catch (...) { }
@@ -150,6 +194,18 @@ void Collections::resolveMultiMatches(const std::string& var,
150194void Collections::resolveMultiMatches (const std::string& var,
151195 const std::string& collection,
152196 std::vector<const transaction::Variable *> *l) {
197+ if (tolower (collection) == " ip"
198+ && !m_ip_collection_key.empty ()) {
199+ m_ip_collection->resolveMultiMatches (var, m_ip_collection_key, l);
200+ return ;
201+ }
202+
203+ if (tolower (collection) == " global"
204+ && !m_global_collection_key.empty ()) {
205+ m_global_collection->resolveMultiMatches (var, m_global_collection_key, l);
206+ return ;
207+ }
208+
153209 try {
154210 this ->at (collection)->resolveMultiMatches (var, l);
155211 } catch (...) { }
@@ -164,6 +220,19 @@ void Collections::resolveRegularExpression(const std::string& var,
164220void Collections::resolveRegularExpression (const std::string& var,
165221 const std::string& collection,
166222 std::vector<const transaction::Variable *> *l) {
223+ if (tolower (collection) == " ip"
224+ && !m_ip_collection_key.empty ()) {
225+ m_ip_collection->resolveRegularExpression (toupper (collection)
226+ + " :" + var, m_ip_collection_key, l);
227+ return ;
228+ }
229+
230+ if (tolower (collection) == " global"
231+ && !m_global_collection_key.empty ()) {
232+ m_global_collection->resolveRegularExpression (toupper (collection)
233+ + " :" + var, m_global_collection_key, l);
234+ return ;
235+ }
167236
168237 try {
169238 this ->at (collection)->resolveRegularExpression (var, l);
0 commit comments