forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApacheRequestHandlerFactory.cpp
More file actions
executable file
·116 lines (92 loc) · 2.84 KB
/
ApacheRequestHandlerFactory.cpp
File metadata and controls
executable file
·116 lines (92 loc) · 2.84 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
//
// ApacheRequestHandlerFactory.cpp
//
// $Id: //poco/1.4/ApacheConnector/src/ApacheRequestHandlerFactory.cpp#2 $
//
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "ApacheRequestHandlerFactory.h"
#include "ApacheConnector.h"
#include "Poco/Net/HTTPRequestHandler.h"
#include "Poco/StringTokenizer.h"
#include "Poco/Manifest.h"
#include "Poco/File.h"
#include <vector>
using Poco::StringTokenizer;
using Poco::FastMutex;
ApacheRequestHandlerFactory::ApacheRequestHandlerFactory()
{
}
ApacheRequestHandlerFactory::~ApacheRequestHandlerFactory()
{
}
Poco::Net::HTTPRequestHandler* ApacheRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest& request)
{
FastMutex::ScopedLock lock(_mutex);
// only if the given uri is found in _uris we are
// handling this request.
RequestHandlerFactories::iterator it = _requestHandlers.begin();
RequestHandlerFactories::iterator itEnd = _requestHandlers.end();
std::string uri = request.getURI();
// if any uri in our map is found at the beginning of the given
// uri -> then we handle it!!
for (; it != itEnd; it++)
{
if (uri.find(it->first) == 0 || it->first.find(uri) == 0)
{
return it->second->createRequestHandler(request);
}
}
return 0;
}
void ApacheRequestHandlerFactory::handleURIs(const std::string& uris)
{
FastMutex::ScopedLock lock(_mutex);
StringTokenizer st(uris, " ", StringTokenizer::TOK_TRIM);
StringTokenizer::Iterator it = st.begin();
StringTokenizer::Iterator itEnd = st.end();
std::string factoryName = (*it);
it++;
std::string dllName = (*it);
it++;
for (; it != itEnd; it++)
{
addRequestHandlerFactory(dllName, factoryName, *it);
}
}
void ApacheRequestHandlerFactory::addRequestHandlerFactory(const std::string& dllPath, const std::string& factoryName, const std::string& uri)
{
try
{
_loader.loadLibrary(dllPath);
Poco::Net::HTTPRequestHandlerFactory* pFactory = _loader.classFor(factoryName).create();
_requestHandlers.insert(std::make_pair(uri, pFactory));
}
catch (Poco::Exception& exc)
{
ApacheConnector::log(__FILE__, __LINE__, ApacheConnector::PRIO_ERROR, 0, exc.displayText().c_str());
}
}
bool ApacheRequestHandlerFactory::mustHandle(const std::string& uri)
{
FastMutex::ScopedLock lock(_mutex);
// only if the given uri is found in _uris we are
// handling this request.
RequestHandlerFactories::iterator it = _requestHandlers.begin();
RequestHandlerFactories::iterator itEnd = _requestHandlers.end();
// if any uri in our map is found at the beginning of the given
// uri -> then we handle it!!
for (; it != itEnd; it++)
{
// dealing with both cases:
// handler is registered with: /download
// uri: /download/xyz
// uri: /download
if (uri.find(it->first) == 0 || it->first.find(uri) == 0)
return true;
}
return false;
}