HTTPServer/HTTPPageList.cpp

50 lines
1.5 KiB
C++
Raw Normal View History

2019-05-31 14:25:19 -07:00
#include "HTTPPageList.h"
2022-06-29 11:38:44 -07:00
#include "Log.h"
#include "Exception.h"
#include <utility>
2019-05-31 14:25:19 -07:00
namespace http {
2020-11-07 17:31:08 -08:00
2022-06-29 11:38:44 -07:00
bool HTTPPageList::processRequest(HTTPParameters &p) {
p.httpRequest.response.setProtocol(p.httpRequest.request.getProtocol());
coreutils::ZString uri = p.httpRequest.request.getURI();
coreutils::Log(coreutils::LOG_DEBUG_1) << "Requesting '" << uri << "'.";
for (auto const& [key, val] : pages) {
p.httpRequest.uriValues.clear();
uri.reset();
coreutils::ZString compare(key.c_str());
int match = compare.ifEqualsCount(uri);
if((match > 0) && (!uri.eod())) {
if(compare.ifNext("{")) {
coreutils::ZString varName = compare.getTokenExclude("}");
if(compare.ifNext("}")) {
if(compare.eod()) {
coreutils::ZString value = uri.getTokenExclude(" ");
p.httpRequest.uriValues[varName] = value;
}
} else
throw coreutils::Exception("Syntax error in entrypoint data.");
}
}
if((match > 0) && uri.eod()) {
return val->page(p);
}
}
throw coreutils::Exception("Requested resource not found.");
2019-05-31 14:25:19 -07:00
}
void HTTPPageList::add(HTTPPage &page, std::string name) {
pages.insert(std::make_pair(name, &page));
2019-05-31 14:25:19 -07:00
}
2020-11-07 17:31:08 -08:00
2019-05-31 14:25:19 -07:00
void HTTPPageList::remove(HTTPPage &page) {}
2020-11-07 17:31:08 -08:00
2022-06-29 11:38:44 -07:00
void HTTPPageList::matchUri(coreutils::ZString &comparator, coreutils::ZString &uri) {}
2019-05-31 14:25:19 -07:00
}