mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-13 17:59:35 -04:00
added resource_api and rs-nogui-webui (requires libmicrohttpd, Html files are not included)
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8047 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
97831d0667
commit
ad1bc7f3b8
38 changed files with 5547 additions and 2 deletions
libresapi/src/api
57
libresapi/src/api/ResourceRouter.cpp
Normal file
57
libresapi/src/api/ResourceRouter.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include "ResourceRouter.h"
|
||||
|
||||
|
||||
|
||||
namespace resource_api
|
||||
{
|
||||
|
||||
class TestResource: public ResourceRouter
|
||||
{
|
||||
public:
|
||||
TestResource()
|
||||
{
|
||||
addResourceHandler("eins", this, &TestResource::eins);
|
||||
}
|
||||
ResponseTask* eins(Request& req, Response& resp)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
ResourceRouter::~ResourceRouter()
|
||||
{
|
||||
std::vector<std::pair<std::string, HandlerBase*> >::iterator vit;
|
||||
for(vit = mHandlers.begin(); vit != mHandlers.end(); vit++)
|
||||
{
|
||||
delete vit->second;
|
||||
}
|
||||
}
|
||||
|
||||
ResponseTask* ResourceRouter::handleRequest(Request& req, Response& resp)
|
||||
{
|
||||
std::vector<std::pair<std::string, HandlerBase*> >::iterator vit;
|
||||
if(!req.mPath.empty())
|
||||
{
|
||||
for(vit = mHandlers.begin(); vit != mHandlers.end(); vit++)
|
||||
{
|
||||
if(vit->first == req.mPath.top())
|
||||
{
|
||||
req.mPath.pop();
|
||||
return vit->second->handleRequest(req, resp);
|
||||
}
|
||||
}
|
||||
}
|
||||
// not found, search for wildcard handler
|
||||
for(vit = mHandlers.begin(); vit != mHandlers.end(); vit++)
|
||||
{
|
||||
if(vit->first == "*")
|
||||
{
|
||||
// don't pop the path component, because it may contain usefull info for the wildcard handler
|
||||
//req.mPath.pop();
|
||||
return vit->second->handleRequest(req, resp);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace resource_api
|
Loading…
Add table
Add a link
Reference in a new issue