summaryrefslogtreecommitdiffstats
path: root/src/uscxml/server
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-03-20 08:00:41 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-03-20 08:00:41 (GMT)
commitc6c1f3e2e333705bf7d54fffd4b18939a56f4ed8 (patch)
tree92af8be33c602a68d1912790cad657c2a012e2c0 /src/uscxml/server
parentccbf595c52fd705ec70abc774a29b153a7281334 (diff)
downloaduscxml-c6c1f3e2e333705bf7d54fffd4b18939a56f4ed8.zip
uscxml-c6c1f3e2e333705bf7d54fffd4b18939a56f4ed8.tar.gz
uscxml-c6c1f3e2e333705bf7d54fffd4b18939a56f4ed8.tar.bz2
Started Syteminvoker
Diffstat (limited to 'src/uscxml/server')
-rw-r--r--src/uscxml/server/HTTPServer.cpp31
-rw-r--r--src/uscxml/server/HTTPServer.h1
2 files changed, 24 insertions, 8 deletions
diff --git a/src/uscxml/server/HTTPServer.cpp b/src/uscxml/server/HTTPServer.cpp
index 8be45e6..dd06ab7 100644
--- a/src/uscxml/server/HTTPServer.cpp
+++ b/src/uscxml/server/HTTPServer.cpp
@@ -56,7 +56,8 @@ HTTPServer::HTTPServer(unsigned short port) {
}
determineAddress();
- evhttp_set_timeout(_http, 5);
+// evhttp_set_timeout(_http, 5);
+
// generic callback
evhttp_set_gencb(_http, HTTPServer::httpRecvReqCallback, NULL);
}
@@ -217,7 +218,7 @@ void HTTPServer::httpRecvReqCallback(struct evhttp_request *req, void *callbackD
request.data.compound["content"] = Data::fromJSON(request.data.compound["content"].atom);
}
}
-
+
if (callbackData == NULL) {
HTTPServer::getInstance()->processByMatchingServlet(request);
} else {
@@ -236,7 +237,7 @@ void HTTPServer::processByMatchingServlet(const Request& request) {
// is the servlet path a prefix of the actual path?
std::string servletPath = "/" + servletIter->first;
if (boost::iequals(actualPath.substr(0, servletPath.length()), servletPath) && // actual path is a prefix
- boost::iequals(actualPath.substr(servletPath.length(), 1), "/")) { // and next character is a '/'
+ boost::iequals(actualPath.substr(servletPath.length(), 1), "/")) { // and next character is a '/'
if (bestPath.length() < servletPath.length()) {
// this servlet is a better match
bestPath = servletPath;
@@ -299,20 +300,34 @@ bool HTTPServer::registerServlet(const std::string& path, HTTPServlet* servlet)
HTTPServer* INSTANCE = getInstance();
tthread::lock_guard<tthread::recursive_mutex> lock(INSTANCE->_mutex);
- if(INSTANCE->_servlets.find(path) != INSTANCE->_servlets.end()) {
- return false;
+ // remove trailing and leading slash
+ std::string actualPath = path;
+ if (boost::ends_with(actualPath, "/"))
+ actualPath = actualPath.substr(0, actualPath.size() - 1);
+ if (boost::starts_with(actualPath, "/"))
+ actualPath = actualPath.substr(1);
+ std::string suffixedPath = actualPath;
+
+ // if this servlet allows to adapt the path, do so
+ int i = 2;
+ while(INSTANCE->_servlets.find(suffixedPath) != INSTANCE->_servlets.end()) {
+ if (!servlet->canAdaptPath())
+ return false;
+ std::stringstream ss;
+ ss << actualPath << i++;
+ suffixedPath = ss.str();
}
std::stringstream servletURL;
- servletURL << "http://" << INSTANCE->_address << ":" << INSTANCE->_port << "/" << path;
+ servletURL << "http://" << INSTANCE->_address << ":" << INSTANCE->_port << "/" << suffixedPath;
servlet->setURL(servletURL.str());
- INSTANCE->_servlets[path] = servlet;
+ INSTANCE->_servlets[suffixedPath] = servlet;
LOG(INFO) << "HTTP Servlet listening at: " << servletURL.str() << std::endl;
// register callback
- evhttp_set_cb(INSTANCE->_http, ("/" + path).c_str(), HTTPServer::httpRecvReqCallback, servlet);
+ evhttp_set_cb(INSTANCE->_http, ("/" + suffixedPath).c_str(), HTTPServer::httpRecvReqCallback, servlet);
return true;
}
diff --git a/src/uscxml/server/HTTPServer.h b/src/uscxml/server/HTTPServer.h
index 319b62f..990d0a7 100644
--- a/src/uscxml/server/HTTPServer.h
+++ b/src/uscxml/server/HTTPServer.h
@@ -83,6 +83,7 @@ private:
class HTTPServlet {
public:
virtual void httpRecvRequest(const HTTPServer::Request& request) = 0;
+ virtual bool canAdaptPath() { return true; }
virtual void setURL(const std::string& url) = 0; /// Called by the server with the actual URL
};