sync.
This commit is contained in:
parent
0510ad5dc7
commit
bbab38de3a
@ -10,45 +10,52 @@ namespace http {
|
||||
|
||||
int HTTPHandler::processCommand(std::string request, core::TCPSession *session, std::stringstream &data) {
|
||||
|
||||
coreutils::Log(coreutils::LOG_DEBUG_4) << "DATA[" << request << "]";
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "DATA[" << request << "]";
|
||||
coreutils::PString request1(request);
|
||||
|
||||
if(mode == REQUEST) {
|
||||
switch(mode) {
|
||||
case REQUEST:
|
||||
httpRequest = new HTTPRequest(request1);
|
||||
session->server.commands.grabInput(session, *this);
|
||||
mode = IMF;
|
||||
break;
|
||||
|
||||
coreutils::PString request1(request);
|
||||
HTTPRequest httpRequest(request1);
|
||||
|
||||
HTTPSession *httpSession = static_cast<HTTPServer &>(session->server).httpSessions.findSessionByHeader(httpRequest);
|
||||
|
||||
std::stringstream content;
|
||||
|
||||
if(static_cast<HTTPServer &>(session->server).pageList.processRequest(httpRequest, session, httpSession, content)) {
|
||||
std::string contentType = httpRequest.getHeader("Content-Type");
|
||||
if(contentType == "multipart/form-data") {
|
||||
coreutils::IMFFormData *formdata = (coreutils::IMFFormData *)httpRequest.getBody();
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "username is '" << formdata->getByName("username") << "'";
|
||||
}
|
||||
|
||||
httpRequest.response.setCode("200");
|
||||
httpRequest.response.setText("OK");
|
||||
data << httpRequest.response.getResponse(content.str());
|
||||
case IMF:
|
||||
httpRequest->parse(request1);
|
||||
if(request == "") {
|
||||
session->server.commands.clearGrab(session);
|
||||
mode = REQUEST;
|
||||
processHTTPRequest(session, data);
|
||||
}
|
||||
|
||||
else {
|
||||
httpRequest.response.setCode("404");
|
||||
httpRequest.response.setText("Not Found");
|
||||
data << httpRequest.response.getResponse(content.str());
|
||||
}
|
||||
|
||||
grabInput();
|
||||
mode = IMFHEADER;
|
||||
}
|
||||
else if(mode == IMFHEADER) {
|
||||
HTTPHeader header(content);
|
||||
releaseGrab();
|
||||
mode = REQUEST;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HTTPHandler::processHTTPRequest(core::TCPSession *session, std::stringstream &data) {
|
||||
|
||||
HTTPSession *httpSession = static_cast<HTTPServer &>(session->server).httpSessions.findSessionByHeader(httpRequest);
|
||||
|
||||
std::stringstream content;
|
||||
|
||||
if(static_cast<HTTPServer &>(session->server).pageList.processRequest(httpRequest, session, httpSession, content)) {
|
||||
std::string contentType = httpRequest->getHeader("Content-Type");
|
||||
if(contentType == "multipart/form-data") {
|
||||
coreutils::IMFFormData *formdata = (coreutils::IMFFormData *)httpRequest->getBody();
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "username is '" << formdata->getByName("username") << "'";
|
||||
}
|
||||
|
||||
httpRequest->response.setCode("200");
|
||||
httpRequest->response.setText("OK");
|
||||
data << httpRequest->response.getResponse(content.str());
|
||||
}
|
||||
|
||||
else {
|
||||
httpRequest->response.setCode("404");
|
||||
httpRequest->response.setText("Not Found");
|
||||
data << httpRequest->response.getResponse(content.str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "Command.h"
|
||||
#include "TCPSession.h"
|
||||
#include "Log.h"
|
||||
#include "HTTPRequest.h"
|
||||
|
||||
namespace http {
|
||||
|
||||
@ -13,7 +14,9 @@ namespace http {
|
||||
int processCommand(std::string request, core::TCPSession *session, std::stringstream &data) override;
|
||||
|
||||
private:
|
||||
enum Mode { REQUEST, IMFHEADER };
|
||||
HTTPRequest *httpRequest;
|
||||
bool processHTTPRequest(core::TCPSession *session, std::stringstream &data);
|
||||
enum Mode { REQUEST, IMF };
|
||||
Mode mode = REQUEST;
|
||||
|
||||
};
|
||||
|
@ -25,7 +25,7 @@ namespace http {
|
||||
virtual int processCommand(std::string request,
|
||||
core::TCPSession *session,
|
||||
HTTPSession *httpSession,
|
||||
HTTPRequest &httpRequest,
|
||||
HTTPRequest *httpRequest,
|
||||
std::stringstream &data) {
|
||||
return false;
|
||||
}
|
||||
|
@ -2,12 +2,11 @@
|
||||
|
||||
namespace http {
|
||||
|
||||
bool HTTPPageList::processRequest(HTTPRequest &httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data) {
|
||||
httpRequest.response.setProtocol(httpRequest.request.getProtocol());
|
||||
bool HTTPPageList::processRequest(HTTPRequest *httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data) {
|
||||
httpRequest->response.setProtocol(httpRequest->request.getProtocol());
|
||||
for(auto *page : pages) {
|
||||
if(page->check(httpRequest.request.getURI())) {
|
||||
page->processCommand(httpRequest.request.getURI(), session, httpSession, httpRequest, data);
|
||||
return true;
|
||||
if(page->check(httpRequest->request.getURI())) {
|
||||
return page->processCommand(httpRequest->request.getURI(), session, httpSession, httpRequest, data);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -38,7 +38,7 @@ namespace http {
|
||||
add(workflow_js, "/__workflow_js");
|
||||
}
|
||||
|
||||
bool processRequest(HTTPRequest &httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data);
|
||||
bool processRequest(HTTPRequest *httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data);
|
||||
|
||||
void add(HTTPPage &page, std::string name = "");
|
||||
|
||||
|
@ -5,21 +5,23 @@
|
||||
#include "IMFMessage.h"
|
||||
#include "IMFRequest.h"
|
||||
#include "IMFResponse.h"
|
||||
#include "Exception.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace http {
|
||||
|
||||
class HTTPRequest : public coreutils::IMFMessage {
|
||||
|
||||
public:
|
||||
HTTPRequest();
|
||||
HTTPRequest(coreutils::PString &in) {
|
||||
request = coreutils::IMFRequest(in);
|
||||
parse(in);
|
||||
}
|
||||
HTTPRequest(coreutils::PString &in);
|
||||
|
||||
coreutils::IMFRequest request;
|
||||
coreutils::IMFResponse response;
|
||||
|
||||
private:
|
||||
std::string key;
|
||||
std::string value;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
BIN
HTTPServer
BIN
HTTPServer
Binary file not shown.
@ -5,13 +5,13 @@
|
||||
|
||||
namespace http {
|
||||
|
||||
HTTPSession * HTTPSessions::findSessionByHeader(HTTPRequest &httpRequest) {
|
||||
std::string sessionId = httpRequest.getHeaderKeyPairValue("Cookie", "sessionId");
|
||||
HTTPSession * HTTPSessions::findSessionByHeader(HTTPRequest *httpRequest) {
|
||||
std::string sessionId = httpRequest->getHeaderKeyPairValue("Cookie", "sessionId");
|
||||
HTTPSession *session = findSessionById(sessionId, httpRequest);
|
||||
return session;
|
||||
}
|
||||
|
||||
HTTPSession * HTTPSessions::findSessionById(std::string sessionId, HTTPRequest &httpRequest) {
|
||||
HTTPSession * HTTPSessions::findSessionById(std::string sessionId, HTTPRequest *httpRequest) {
|
||||
HTTPSession *httpSession;
|
||||
if(sessionId.length() > 0) {
|
||||
std::map<std::string, HTTPSession*>::iterator ix;
|
||||
@ -19,13 +19,13 @@ namespace http {
|
||||
httpSession = ix->second;
|
||||
if(ix == sessions.end()) {
|
||||
httpSession = createHTTPSession();
|
||||
httpRequest.response.setCookie("sessionId", httpSession->getSessionId());
|
||||
httpRequest->response.setCookie("sessionId", httpSession->getSessionId());
|
||||
}
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "http session: " << "(" << sessionId << ") " << httpSession;
|
||||
|
||||
} else {
|
||||
httpSession = createHTTPSession();
|
||||
httpRequest.response.setCookie("sessionId", httpSession->getSessionId());
|
||||
httpRequest->response.setCookie("sessionId", httpSession->getSessionId());
|
||||
}
|
||||
return httpSession;
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ namespace http {
|
||||
class HTTPSessions : public core::Command {
|
||||
|
||||
public:
|
||||
HTTPSession * findSessionByHeader(HTTPRequest &httpRequest);
|
||||
HTTPSession * findSessionById(std::string sessionId, HTTPRequest &httpRequest);
|
||||
HTTPSession * findSessionByHeader(HTTPRequest *httpRequest);
|
||||
HTTPSession * findSessionById(std::string sessionId, HTTPRequest *httpRequest);
|
||||
|
||||
int processCommand(std::string request, core::TCPSession *session, std::stringstream &data);
|
||||
|
||||
|
@ -5,7 +5,7 @@ namespace http {
|
||||
|
||||
class __configure : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest *httpRequest, std::stringstream &data) override {
|
||||
|
||||
data << "<form name=\"configure\" action=\"setupadmin\" method=\"POST\">" << std::endl;
|
||||
data << " <div class=\"window\"><h1>System Configuration</h1>" << std::endl;
|
||||
@ -27,7 +27,7 @@ namespace http {
|
||||
data << " <input type=\"button\" onmousedown=\"process('/mainmenu','configure', 'main'); return true;\" name=\"button1\" value=\"Update Configuration\">" << std::endl;
|
||||
data << " </div></form>" << std::endl;
|
||||
|
||||
httpRequest.response.addHeader("Content-Type", "text/html");
|
||||
httpRequest->response.addHeader("Content-Type", "text/html");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace http {
|
||||
|
||||
class __editview : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest *httpRequest, std::stringstream &data) override {
|
||||
|
||||
data << " <div style=\"position: relative;\">" << std::endl;
|
||||
data << "" << std::endl;
|
||||
@ -70,7 +70,7 @@ namespace http {
|
||||
data << "" << std::endl;
|
||||
data << " <script src=\"/__editview_js\" />" << std::endl;
|
||||
|
||||
httpRequest.response.addHeader("Content-Type", "script/javascript");
|
||||
httpRequest->response.addHeader("Content-Type", "script/javascript");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace http {
|
||||
|
||||
class __editview_js : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest *httpRequest, std::stringstream &data) override {
|
||||
data << " var mainpage;" << std::endl;
|
||||
data << " var result;" << std::endl;
|
||||
data << " var mousedownx;" << std::endl;
|
||||
@ -205,7 +205,7 @@ namespace http {
|
||||
data << "" << std::endl;
|
||||
data << " }" << std::endl;
|
||||
|
||||
httpRequest.response.addHeader("Content-Type", "script/javascript");
|
||||
httpRequest->response.addHeader("Content-Type", "script/javascript");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -10,12 +10,12 @@ namespace http {
|
||||
int processCommand(std::string request,
|
||||
core::TCPSession *session,
|
||||
HTTPSession *httpSession,
|
||||
HTTPRequest &httpRequest,
|
||||
HTTPRequest *httpRequest,
|
||||
std::stringstream &data) override {
|
||||
|
||||
data << std::string(header_data, 806);
|
||||
|
||||
httpRequest.response.addHeader("Content-Type", "image/x-icon");
|
||||
httpRequest->response.addHeader("Content-Type", "image/x-icon");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ namespace http {
|
||||
|
||||
class __index : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest *httpRequest, std::stringstream &data) override {
|
||||
|
||||
data << "<html>" << std::endl;
|
||||
data << " <head>" << std::endl;
|
||||
@ -24,7 +24,7 @@ namespace http {
|
||||
data << " </body>" << std::endl;
|
||||
data << "</html>" << std::endl;
|
||||
|
||||
httpRequest.response.addHeader("Content-Type", "text/html");
|
||||
httpRequest->response.addHeader("Content-Type", "text/html");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -10,7 +10,7 @@ namespace http {
|
||||
int processCommand(std::string request,
|
||||
core::TCPSession *session,
|
||||
HTTPSession *httpSession,
|
||||
HTTPRequest &httpRequest,
|
||||
HTTPRequest *httpRequest,
|
||||
std::stringstream &data) override {
|
||||
|
||||
data << "<div>" << std::endl;
|
||||
@ -36,7 +36,7 @@ namespace http {
|
||||
data << " </div>" << std::endl;
|
||||
data << "</div>" << std::endl;
|
||||
|
||||
httpRequest.response.addHeader("Content-Type", "text/html");
|
||||
httpRequest->response.addHeader("Content-Type", "text/html");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace http {
|
||||
|
||||
class __script : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest *httpRequest, std::stringstream &data) override {
|
||||
|
||||
data << "function serverSend(url, type, receiver, formData, callback) {" << std::endl;
|
||||
data << " var server = new XMLHttpRequest();" << std::endl;
|
||||
@ -45,7 +45,7 @@ namespace http {
|
||||
data << " }" << std::endl;
|
||||
data << "}" << std::endl;
|
||||
|
||||
httpRequest.response.addHeader("Content-Type", "text/javascript");
|
||||
httpRequest->response.addHeader("Content-Type", "text/javascript");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ namespace http {
|
||||
|
||||
class __setupadmin : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest *httpRequest, std::stringstream &data) override {
|
||||
|
||||
data << "<form name=\"setupadmin\" action=\"setupadmin\" method=\"POST\">" << std::endl;
|
||||
data << " <div class=\"window\"><p>Please enter credential information" << std::endl;
|
||||
@ -27,7 +27,7 @@ namespace http {
|
||||
data << " <input type=\"button\" onmousedown=\"process('/mainmenu','setupadmin', 'main'); return true;\" name=\"button1\" value=\"Set Admin Profile\">" << std::endl;
|
||||
data << " </div></form>" << std::endl;
|
||||
|
||||
httpRequest.response.addHeader("Content-Type", "text/html");
|
||||
httpRequest->response.addHeader("Content-Type", "text/html");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace http {
|
||||
|
||||
class __style : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest *httpRequest, std::stringstream &data) override {
|
||||
|
||||
data << "body {background: #006;" << std::endl;
|
||||
data << " color: #fff;" << std::endl;
|
||||
@ -20,7 +20,7 @@ namespace http {
|
||||
data << " padding: 15px;" << std::endl;
|
||||
data << " }" << std::endl;
|
||||
|
||||
httpRequest.response.addHeader("Content-Type", "text/css");
|
||||
httpRequest->response.addHeader("Content-Type", "text/css");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ namespace http {
|
||||
int processCommand(std::string request,
|
||||
core::TCPSession *session,
|
||||
HTTPSession *httpSession,
|
||||
HTTPRequest &httpRequest,
|
||||
HTTPRequest *httpRequest,
|
||||
std::stringstream &data) override {
|
||||
|
||||
coreutils::Directory directory("/home/bradarant/jetserver/views");
|
||||
@ -39,7 +39,7 @@ namespace http {
|
||||
|
||||
data << "</div>" << std::endl;
|
||||
|
||||
httpRequest.response.addHeader("Content-Type", "text/html");
|
||||
httpRequest->response.addHeader("Content-Type", "text/html");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace http {
|
||||
int processCommand(std::string request,
|
||||
core::TCPSession *session,
|
||||
HTTPSession *httpSession,
|
||||
HTTPRequest &httpRequest,
|
||||
HTTPRequest *httpRequest,
|
||||
std::stringstream &data) override {
|
||||
|
||||
data << "<div class=\"window\">\
|
||||
@ -20,7 +20,7 @@ namespace http {
|
||||
<input type=\"button\" onmousedown=\"getPage('/setupadmin','main'); return true;\" name=\"button1\" value=\"Configure\">\
|
||||
</div>";
|
||||
|
||||
httpRequest.response.addHeader("Content-Type", "text/html");
|
||||
httpRequest->response.addHeader("Content-Type", "text/html");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user