added support to get client id

This commit is contained in:
Peter Schojer 2008-07-09 10:45:45 +00:00
parent e7ce0a5b52
commit 4e7a55a24b
3 changed files with 21 additions and 4 deletions

View File

@ -52,6 +52,7 @@
namespace Poco {
namespace Net {
class HTMLForm;
class HTTPServerRequest;
}
namespace WebWidgets {
@ -102,7 +103,7 @@ public:
RequestProcessor* getAjaxProcessor(const std::string& id);
/// Returns the AjaxProcessor or null
void attachToThread();
void attachToThread(Poco::Net::HTTPServerRequest& request);
/// Attaches the WebApplication to the current thread, so that a
/// call to WebApplication::instance() within this thread will return
/// exactly this WebApplication instance.
@ -112,6 +113,9 @@ public:
static WebApplication& instance();
/// Returns the singleton for the current thread
static std::string clientHostName();
/// Returns the host name of the caller
private:
WebApplication(const WebApplication&);
WebApplication& operator = (const WebApplication&);
@ -125,6 +129,7 @@ private:
RequestProcessorMap _requestProcessorMap;
RequestProcessorMap _ajaxProcessorMap;
static Poco::ThreadLocal<WebApplication*> _pInstance;
static Poco::ThreadLocal<std::string> _clientMachine;
};

View File

@ -45,6 +45,7 @@
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/URI.h"
#include "Poco/ThreadLocal.h"
#include <sstream>
@ -59,6 +60,7 @@ const std::string RequestHandler::KEY_ID("id");
const std::string RequestHandler::KEY_EVID("evId");
RequestHandler::RequestHandler(WebApplication& app):
_app(app)
{
@ -72,7 +74,7 @@ RequestHandler::~RequestHandler()
void RequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
_app.attachToThread();
_app.attachToThread(request);
Poco::Net::NameValueCollection args;
parseRequest(request, args);

View File

@ -37,6 +37,7 @@
#include "Poco/WebWidgets/WebApplication.h"
#include "Poco/WebWidgets/RequestProcessor.h"
#include "Poco/Net/HTMLForm.h"
#include "Poco/Net/HTTPServerRequest.h"
namespace Poco {
@ -44,6 +45,7 @@ namespace WebWidgets {
Poco::ThreadLocal<WebApplication*> WebApplication::_pInstance;
Poco::ThreadLocal<std::string> WebApplication::_clientMachine;
WebApplication::WebApplication(const Poco::URI& uri,ResourceManager::Ptr pRM):
@ -53,7 +55,8 @@ WebApplication::WebApplication(const Poco::URI& uri,ResourceManager::Ptr pRM):
_uri(uri)
{
poco_check_ptr (pRM);
attachToThread();
*_pInstance = this;
*_clientMachine = "";
}
@ -76,9 +79,10 @@ void WebApplication::setCurrentPage(Page::Ptr pPage)
}
void WebApplication::attachToThread()
void WebApplication::attachToThread(Poco::Net::HTTPServerRequest& request)
{
*_pInstance = this;
*_clientMachine = request.getHost();
}
@ -90,6 +94,12 @@ WebApplication& WebApplication::instance()
}
std::string WebApplication::clientHostName()
{
return *_clientMachine;
}
void WebApplication::registerFormProcessor(const std::string& fieldName, RequestProcessor* pProc)
{
std::pair<RequestProcessorMap::iterator, bool> res = _requestProcessorMap.insert(std::make_pair(fieldName, pProc));