-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathFilterHandler.cpp
More file actions
121 lines (111 loc) · 4.48 KB
/
FilterHandler.cpp
File metadata and controls
121 lines (111 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Copyright 2009-2020, Sumeet Chhetri
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
* FilterHandler.cpp
*
* Created on: Jun 17, 2012
* Author: Sumeet
*/
#include "FilterHandler.h"
bool FilterHandler::hasFilters(std::string_view cntxtName) {
std::map<std::string, std::map<std::string, std::vector<std::string>, std::less<> >, std::less<> >& filterObjectMap = ConfigurationData::getInstance()->filterObjectMap;
return filterObjectMap.find(cntxtName)!=filterObjectMap.end() && filterObjectMap.find(cntxtName)->second.size()>0;
}
bool FilterHandler::getFilterForPath(std::string_view cntxtName, const std::string& actUrl, std::vector<std::string>& filters, const std::string& type)
{
std::map<std::string, std::map<std::string, std::vector<std::string>, std::less<> >, std::less<> >& filterObjectMap = ConfigurationData::getInstance()->filterObjectMap;
std::map<std::string, std::vector<std::string>, std::less<> > filterMap = filterObjectMap.find(cntxtName)->second;
std::map<std::string, std::vector<std::string>, std::less<> >::iterator it;
for (it=filterMap.begin();it!=filterMap.end();++it) {
std::string pathurl = it->first.substr(0, it->first.length()-type.length());
if(StringUtil::endsWith(it->first, type) && ConfigurationData::urlMatchesPath(cntxtName, pathurl, actUrl))
{
filters = it->second;
return true;
}
}
return false;
}
void FilterHandler::handleIn(HttpRequest* req, const std::string& ext, Reflector& reflector)
{
std::vector<std::string> filters;
if(getFilterForPath(req->getCntxt_name(), req->getCurl(), filters, "in"))
{
for (int var = 0; var < (int)filters.size(); ++var)
{
std::string claz = filters.at(var);
void *_temp = ConfigurationData::getInstance()->ffeadContext.getBean(claz, req->getCntxt_name());
args argus;
argus.push_back("HttpRequest*");
vals valus;
ClassInfo* srv = ConfigurationData::getClassInfo(claz, req->getCntxt_name());
Method meth = srv->getMethod("doInputFilter", argus);
if(meth.getMethodName()!="")
{
valus.push_back(req);
reflector.invokeMethodGVP(_temp,meth,valus);
}
ConfigurationData::getInstance()->ffeadContext.release(_temp, claz, req->getCntxt_name());
}
}
}
bool FilterHandler::handle(HttpRequest* req, HttpResponse* res, const std::string& ext, Reflector& reflector)
{
bool continue_proc_request = true;
std::vector<std::string> filters;
if(getFilterForPath(req->getCntxt_name(), req->getCurl(), filters, "handle"))
{
for (int var = 0; var < (int)filters.size(); ++var)
{
std::string claz = filters.at(var);
void *_temp = ConfigurationData::getInstance()->ffeadContext.getBean(claz, req->getCntxt_name());
args argus;
argus.push_back("HttpRequest*");
argus.push_back("HttpResponse*");
vals valus;
ClassInfo* srv = ConfigurationData::getClassInfo(claz, req->getCntxt_name());
Method meth = srv->getMethod("doHandle", argus);
if(meth.getMethodName()!="")
{
valus.push_back(req);
valus.push_back(res);
reflector.invokeMethod<bool>(&continue_proc_request,_temp,meth,valus);
}
ConfigurationData::getInstance()->ffeadContext.release(_temp, claz, req->getCntxt_name());
}
}
return continue_proc_request;
}
void FilterHandler::handleOut(HttpRequest* req, HttpResponse* res, const std::string& ext, Reflector& reflector)
{
std::vector<std::string> filters;
if(getFilterForPath(req->getCntxt_name(), req->getCurl(), filters, "out"))
{
for (int var = 0; var < (int)filters.size(); ++var)
{
std::string claz = filters.at(var);
void *_temp = ConfigurationData::getInstance()->ffeadContext.getBean(claz, req->getCntxt_name());
args argus;
argus.push_back("HttpResponse*");
vals valus;
ClassInfo* srv = ConfigurationData::getClassInfo(claz, req->getCntxt_name());
Method meth = srv->getMethod("doOutputFilter", argus);
if(meth.getMethodName()!="")
{
valus.push_back(res);
reflector.invokeMethodGVP(_temp,meth,valus);
}
ConfigurationData::getInstance()->ffeadContext.release(_temp, claz, req->getCntxt_name());
}
}
}