diff --git a/FlowAction.cpp b/FlowAction.cpp new file mode 100644 index 0000000..ccaefef --- /dev/null +++ b/FlowAction.cpp @@ -0,0 +1,21 @@ +#include "FlowAction.h" + +namespace http { + + FlowAction::FlowAction() { + int len = strlen(hex); + for(int ix = 0; ix < sizeof(actionId); ++ix) { + actionId[ix] = hex[random() % len]; + } + } + + bool FlowAction::action(HTTPParameters &p) { + return true; + } + + coreutils::ZString FlowAction::getId() { + return coreutils::ZString(actionId, sizeof(actionId)); + } + + +} diff --git a/FlowAction.h b/FlowAction.h new file mode 100644 index 0000000..dc16c8d --- /dev/null +++ b/FlowAction.h @@ -0,0 +1,26 @@ +#ifndef __FlowAction_h__ +# define __FlowAction_h__ + +#include "HTTPParameters.h" +#include "ZString.h" + +namespace http { + + class FlowAction { + + public: + FlowAction(); + + virtual bool action(HTTPParameters &p); + + coreutils::ZString getId(); + + protected: + char actionId[64]; + const char *hex = "0123456789ABCDEF"; + + }; + +} + +#endif diff --git a/HTTPActionList.cpp b/HTTPActionList.cpp new file mode 100644 index 0000000..0fac1e4 --- /dev/null +++ b/HTTPActionList.cpp @@ -0,0 +1,56 @@ +#include "HTTPActionList.h" +#include "Log.h" +#include "HTTPParameters.h" +#include "FlowAction.h" +#include "Exception.h" + +namespace http { + + bool HTTPActionList::processRequest(HTTPParameters &p) { + + p.httpRequest.response.setProtocol(p.httpRequest.request.getProtocol()); + coreutils::ZString uri = p.httpRequest.request.getURI(); + if(!uri.ifNext("/")) + throw coreutils::Exception("Expecting a /."); + + coreutils::Log(coreutils::LOG_DEBUG_1) << "Requesting action '" << uri << "'."; + + try { + return actions.at(uri)->action(p); + } + catch(...) { + throw coreutils::Exception("Requested resource not found."); + } + + } + + coreutils::ZString HTTPActionList::addAction(FlowAction *action) { + coreutils::Log(coreutils::LOG_DEBUG_1) << "Adding flow action to list..." << action->getId(); + + for(auto [key, actionItem] : actions) { + coreutils::Log(coreutils::LOG_DEBUG_2) << "before: " << key; + } + + coreutils::ZString name(action->getId()); + coreutils::Log(coreutils::LOG_DEBUG_2) << "getid: " << name; + auto ret = actions.insert(std::make_pair(name, action)); + + if(ret.second == false) { + coreutils::Log(coreutils::LOG_DEBUG_2) << "already exists" << action->getId(); + } + + for(auto [key, actionItem] : actions) { + coreutils::Log(coreutils::LOG_DEBUG_2) << "after: " << key; + } + + return action->getId(); + } + +// void HTTPActionList::remove(HTTPPage &page) {} + + void HTTPActionList::matchUri(coreutils::ZString &comparator, coreutils::ZString &uri) { + } + +} + + diff --git a/HTTPActionList.h b/HTTPActionList.h new file mode 100644 index 0000000..d14fe99 --- /dev/null +++ b/HTTPActionList.h @@ -0,0 +1,35 @@ +#ifndef __HTTPActionList_h__ +#define __HTTPActionList_h__ + +//#include "HTTPParameters.h" +//#include "HTTPPage.h" +//#include "FlowAction.h" +#include "ZString.h" +#include + +namespace http { + + class HTTPParameters; + class FlowAction; + + class HTTPActionList { + + public: + HTTPActionList() {} + + bool processRequest(HTTPParameters &p); + + coreutils::ZString addAction(FlowAction *action); + +// void removeAction(HTTPPage &page); + + void matchUri(coreutils::ZString &comparator, coreutils::ZString &uri); + + protected: + std::map actions; + + }; + +} + +#endif diff --git a/HTTPConnection.h b/HTTPConnection.h index b02ed09..7f3ef79 100644 --- a/HTTPConnection.h +++ b/HTTPConnection.h @@ -13,7 +13,6 @@ namespace http { HTTPConnection(core::EPoll &ePoll, core::TCPServer &server) : TCPSession(ePoll, server, "HTTP Connection") {} void onDataReceived(coreutils::ZString &data) override { - coreutils::Log(coreutils::LOG_DEBUG_1) << ":" << data; protocol(data); send(); } diff --git a/HTTPGETHandler.cpp b/HTTPGETHandler.cpp new file mode 100644 index 0000000..0ce8790 --- /dev/null +++ b/HTTPGETHandler.cpp @@ -0,0 +1,38 @@ +#include "HTTPGETHandler.h" +#include "HTTPParameters.h" +#include "HTTPSession.h" +#include "HTTPServer.h" +#include "HTTPRequest.h" +#include "ZString.h" +#include "IMFFormData.h" +#include "Exception.h" +#include "Log.h" + +namespace http { + + int HTTPGETHandler::processCommand(coreutils::ZString &request, core::TCPSession &session) { + + HTTPRequest httpRequest(request); + + HTTPSession *httpSession = static_cast(session.server).httpSessions.findSessionByHeader(httpRequest); + + std::stringstream content; + + HTTPParameters p(httpRequest, session, *httpSession, content, ((HTTPServer &)session.server).actionList); + + try { + static_cast(session.server).pageList.processRequest(p); + httpRequest.response.setCode("200"); + httpRequest.response.setText("OK"); + } + catch(coreutils::Exception e) { + httpRequest.response.setCode("404"); + httpRequest.response.setText("Not Found"); + } + + session.out << httpRequest.response.getResponse(content).str(); +// coreutils::Log(coreutils::LOG_DEBUG_1) << session.out.str(); + return true; + } + +} diff --git a/HTTPHandler.h b/HTTPGETHandler.h similarity index 77% rename from HTTPHandler.h rename to HTTPGETHandler.h index 8c894f2..71a091a 100644 --- a/HTTPHandler.h +++ b/HTTPGETHandler.h @@ -1,5 +1,5 @@ -#ifndef __HTTPHandler_h__ -#define __HTTPHandler_h__ +#ifndef __HTTPGETHandler_h__ +#define __HTTPGETHandler_h__ #include "Command.h" #include "TCPSession.h" @@ -9,7 +9,7 @@ namespace http { - class HTTPHandler : public core::Command { + class HTTPGETHandler : public core::Command { public: int processCommand(coreutils::ZString &request, core::TCPSession &session) override; diff --git a/HTTPHandler.cpp b/HTTPHandler.cpp deleted file mode 100644 index 09a34ee..0000000 --- a/HTTPHandler.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "HTTPHandler.h" -#include "HTTPSession.h" -#include "HTTPServer.h" -#include "HTTPRequest.h" -#include "ZString.h" -#include "IMFFormData.h" -#include "Log.h" - -namespace http { - - int HTTPHandler::processCommand(coreutils::ZString &request, core::TCPSession &session) { - if(!httpRequest) { - httpRequest = new HTTPRequest(request); -// session->server.commands.grabInput(session, *this); - processHTTPRequest(session); - } - else { -// httpRequest->parse(request1); - if(!request.equals("")) { -// session->server.commands.clearGrab(session); - processHTTPRequest(session); - } - } - return true; - } - - bool HTTPHandler::processHTTPRequest(core::TCPSession &session) { - - HTTPSession *httpSession = static_cast(session.server).httpSessions.findSessionByHeader(httpRequest); - - std::stringstream content; - - if(static_cast(session.server).pageList.processRequest(httpRequest, &session, httpSession, content)) { - - coreutils::ZString contentType = httpRequest->getHeader("Content-Type"); - if(contentType.equals("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"); - session.out << httpRequest->response.getResponse(content).str(); - coreutils::Log(coreutils::LOG_DEBUG_1) << "Sending response to client..." << content.str(); - } - else { - httpRequest->response.setCode("404"); - httpRequest->response.setText("Not Found"); - session.out << httpRequest->response.getResponse(content).str(); - } - delete httpRequest; - httpRequest = NULL; - return true; - } - -} diff --git a/HTTPPOSTHandler.cpp b/HTTPPOSTHandler.cpp new file mode 100644 index 0000000..e991da3 --- /dev/null +++ b/HTTPPOSTHandler.cpp @@ -0,0 +1,38 @@ +#include "HTTPPOSTHandler.h" +#include "HTTPParameters.h" +#include "HTTPSession.h" +#include "HTTPServer.h" +#include "HTTPRequest.h" +#include "ZString.h" +#include "IMFFormData.h" +#include "Exception.h" +#include "Log.h" + +namespace http { + + int HTTPPOSTHandler::processCommand(coreutils::ZString &request, core::TCPSession &session) { + + HTTPRequest httpRequest(request); + + HTTPSession *httpSession = ((HTTPServer &)(session.server)).httpSessions.findSessionByHeader(httpRequest); + + std::stringstream content; + + HTTPParameters p(httpRequest, session, *httpSession, content, ((HTTPServer &)(session.server)).actionList); + + try { + ((HTTPServer &)(session.server)).actionList.processRequest(p); + httpRequest.response.setCode("200"); + httpRequest.response.setText("OK"); + } + catch(coreutils::Exception e) { + httpRequest.response.setCode("404"); + httpRequest.response.setText("Not Found"); + } + + session.out << httpRequest.response.getResponse(content).str(); + coreutils::Log(coreutils::LOG_DEBUG_1) << session.out.str(); + return true; + } + +} diff --git a/HTTPPOSTHandler.h b/HTTPPOSTHandler.h new file mode 100644 index 0000000..0a292b4 --- /dev/null +++ b/HTTPPOSTHandler.h @@ -0,0 +1,22 @@ +#ifndef __HTTPPOSTHandler_h__ +#define __HTTPPOSTHandler_h__ + +#include "Command.h" +#include "HTTPRequest.h" + +namespace http { + + class HTTPPOSTHandler : public core::Command { + + public: + int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + + private: + HTTPRequest *httpRequest = NULL; + bool processHTTPRequest(core::TCPSession &session); + + }; + +} + +#endif diff --git a/HTTPPUTHandler.cpp b/HTTPPUTHandler.cpp new file mode 100644 index 0000000..8691726 --- /dev/null +++ b/HTTPPUTHandler.cpp @@ -0,0 +1,32 @@ +#include "HTTPPUTHandler.h" +#include "HTTPSession.h" +#include "HTTPServer.h" +#include "HTTPRequest.h" +#include "ZString.h" +#include "IMFFormData.h" +#include "Log.h" + +namespace http { + + int HTTPPUTHandler::processCommand(coreutils::ZString &request, core::TCPSession &session) { + + HTTPRequest httpRequest(request); + + HTTPSession *httpSession = static_cast(session.server).httpSessions.findSessionByHeader(httpRequest); + + std::stringstream content; + HTTPParameters p(httpRequest, session, *httpSession, content, ((HTTPServer &)session.server).actionList); + + try { + ((HTTPServer &)(session.server)).pageList.processRequest(p); + httpRequest.response.setCode("200"); + httpRequest.response.setText("OK"); + } + catch(...) {} + + session.out << httpRequest.response.getResponse(content).str(); +// coreutils::Log(coreutils::LOG_DEBUG_1) << session.out.str(); + return true; + } + +} diff --git a/HTTPPUTHandler.h b/HTTPPUTHandler.h new file mode 100644 index 0000000..b2da3b2 --- /dev/null +++ b/HTTPPUTHandler.h @@ -0,0 +1,25 @@ +#ifndef __HTTPPUTHandler_h__ +#define __HTTPPUTHandler_h__ + +#include "Command.h" +#include "TCPSession.h" +#include "Log.h" +#include "IMFMessage.h" +#include "HTTPRequest.h" + +namespace http { + + class HTTPPUTHandler : public core::Command { + + public: + int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + + private: + HTTPRequest *httpRequest = NULL; + bool processHTTPRequest(core::TCPSession &session); + + }; + +} + +#endif diff --git a/HTTPPage.cpp b/HTTPPage.cpp new file mode 100644 index 0000000..6b32fac --- /dev/null +++ b/HTTPPage.cpp @@ -0,0 +1,10 @@ +#include "HTTPPage.h" +#include "HTTPParameters.h" + +namespace http { + + int HTTPPage::page(HTTPParameters &p) { + return 0; + } + +} diff --git a/HTTPPage.h b/HTTPPage.h index 8619f03..ff2056e 100644 --- a/HTTPPage.h +++ b/HTTPPage.h @@ -1,23 +1,14 @@ #ifndef __HTTPPage_h__ #define __HTTPPage_h__ -#include "HTTPSession.h" -#include "HTTPRequest.h" -#include "TCPSession.h" -#include "Log.h" +#include "HTTPParameters.h" namespace http { class HTTPPage { public: - - virtual int processCommand(HTTPRequest *httpRequest, - core::TCPSession *session, - HTTPSession *httpSession, - std::stringstream &data) { - return false; - } + virtual int page(HTTPParameters &p); }; diff --git a/HTTPPageList.cpp b/HTTPPageList.cpp index 3e7a5cc..a54fbdf 100644 --- a/HTTPPageList.cpp +++ b/HTTPPageList.cpp @@ -1,16 +1,39 @@ #include "HTTPPageList.h" +#include "Log.h" +#include "Exception.h" +#include namespace http { - bool HTTPPageList::processRequest(HTTPRequest *httpRequest, - core::TCPSession *session, - HTTPSession *httpSession, - std::stringstream &data) { + bool HTTPPageList::processRequest(HTTPParameters &p) { - httpRequest->response.setProtocol(httpRequest->request.getProtocol()); - coreutils::ZString uri = httpRequest->request.getURI(); - HTTPPage *page = pages[uri.str()]; - return page->processCommand(httpRequest, session, httpSession, data); + 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."); } void HTTPPageList::add(HTTPPage &page, std::string name) { @@ -19,6 +42,8 @@ namespace http { void HTTPPageList::remove(HTTPPage &page) {} + void HTTPPageList::matchUri(coreutils::ZString &comparator, coreutils::ZString &uri) {} + } diff --git a/HTTPPageList.h b/HTTPPageList.h index 3e0db77..3fca899 100644 --- a/HTTPPageList.h +++ b/HTTPPageList.h @@ -2,50 +2,50 @@ # define __HTTPPageList_h__ # include "TCPSession.h" -# include "HTTPRequest.h" +# include "ZString.h" # include "__index.h" # include "__script.h" # include "__editview.h" # include "__editview_js.h" # include "__style.h" -# include "__setupadmin.h" +# include "__entrypoints.h" # include "__favicon_ico.h" # include "__welcome.h" -# include "__mainmenu.h" -# include "__configure.h" # include "__viewlist.h" # include "__workflow.h" # include "__workflow_js.h" +# include "__addview.h" # include "_image.h" namespace http { - + class HTTPPageList { - + public: HTTPPageList() { add(index, "/"); add(script, "/script"); - add(editview, "/editview"); + add(editview, "/editview/{view_name}"); add(editview_js, "/__editview_js"); add(style, "/style"); - add(setupadmin, "/setupadmin"); + add(entrypoints, "/entrypoints"); add(favicon_ico, "/favicon.ico"); add(welcome, "/welcome"); - add(mainmenu, "/mainmenu"); - add(configure, "/configure"); add(viewlist, "/viewlist"); add(workflow, "/workflow"); add(workflow_js, "/__workflow_js"); - add(image, "/image/"); + add(image, "/image/{image_name}"); + add(addview, "/addview"); } - bool processRequest(HTTPRequest *httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data); + bool processRequest(HTTPParameters &p); void add(HTTPPage &page, std::string entryURL); void remove(HTTPPage &page); + void matchUri(coreutils::ZString &comparator, coreutils::ZString &uri); + protected: std::map pages; @@ -55,14 +55,13 @@ namespace http { __style style; __editview editview; __editview_js editview_js; - __setupadmin setupadmin; + __entrypoints entrypoints; __favicon_ico favicon_ico; __welcome welcome; - __mainmenu mainmenu; - __configure configure; __viewlist viewlist; __workflow workflow; __workflow_js workflow_js; + __addview addview; _image image; }; diff --git a/HTTPParameters.cpp b/HTTPParameters.cpp new file mode 100644 index 0000000..10a3041 --- /dev/null +++ b/HTTPParameters.cpp @@ -0,0 +1,16 @@ +#include "HTTPParameters.h" + +namespace http { + + HTTPParameters::HTTPParameters(HTTPRequest &httpRequest, + core::TCPSession &session, + HTTPSession &httpSession, + std::stringstream &data, + HTTPActionList &actionList) : + httpRequest(httpRequest), + session(session), + httpSession(httpSession), + data(data), + actionList(actionList) {} + +} diff --git a/HTTPParameters.h b/HTTPParameters.h new file mode 100644 index 0000000..da564b9 --- /dev/null +++ b/HTTPParameters.h @@ -0,0 +1,36 @@ +#ifndef __HTTPParameters_h__ +#define __HTTPParameters_h__ + +#include "HTTPRequest.h" +#include "HTTPSession.h" +#include "HTTPActionList.h" +#include "TCPSession.h" +#include + +namespace http { + + /// + /// HTTPParameters groups the objects needed to access request + /// data and a means to return the content of a response message. + /// + + class HTTPParameters { + + public: + HTTPParameters(HTTPRequest &httpRequest, + core::TCPSession &session, + HTTPSession &httpSession, + std::stringstream &data, + HTTPActionList &actionList); + + HTTPRequest &httpRequest; + core::TCPSession &session; + HTTPSession &httpSession; + std::stringstream &data; + HTTPActionList &actionList; + + }; + +} + +#endif diff --git a/HTTPRequest.cpp b/HTTPRequest.cpp new file mode 100644 index 0000000..6fa8ea6 --- /dev/null +++ b/HTTPRequest.cpp @@ -0,0 +1,7 @@ +#include "HTTPRequest.h" + +namespace http { + + HTTPRequest::HTTPRequest(coreutils::ZString &in) : request(in), message(in) {} + +} diff --git a/HTTPRequest.h b/HTTPRequest.h index db5a5a4..b1d2d2c 100644 --- a/HTTPRequest.h +++ b/HTTPRequest.h @@ -1,21 +1,22 @@ #ifndef __HTTPRequest_h__ #define __HTTPRequest_h__ -#include "ZString.h" #include "IMFMessage.h" #include "IMFRequest.h" #include "IMFResponse.h" -#include "Exception.h" -#include "Log.h" +#include namespace http { - class HTTPRequest : public coreutils::IMFMessage { + class HTTPRequest { public: - HTTPRequest(coreutils::ZString &in) : request(in), IMFMessage(in) {} + HTTPRequest(coreutils::ZString &in); + + std::map uriValues; coreutils::IMFRequest request; + coreutils::IMFMessage message; coreutils::IMFResponse response; }; diff --git a/HTTPServer b/HTTPServer index da5af7c..98a95ed 100755 Binary files a/HTTPServer and b/HTTPServer differ diff --git a/HTTPServer.h b/HTTPServer.h index 655ffe5..35c08e8 100644 --- a/HTTPServer.h +++ b/HTTPServer.h @@ -4,8 +4,11 @@ #include "TCPServer.h" #include "HTTPSessions.h" #include "HTTPPageList.h" +#include "HTTPActionList.h" #include "HTTPConnection.h" -#include "HTTPHandler.h" +#include "HTTPGETHandler.h" +#include "HTTPPOSTHandler.h" +#include "HTTPPUTHandler.h" namespace http { @@ -18,6 +21,7 @@ namespace http { : TCPServer(ePoll, ipAddress), httpSessions(httpSessions) { commands.add(getHandler, "GET"); commands.add(postHandler, "POST"); + commands.add(putHandler, "PUT"); } core::TCPSession * getSocketAccept(core::EPoll &epoll) override { @@ -26,10 +30,12 @@ namespace http { HTTPSessions &httpSessions; HTTPPageList pageList; + HTTPActionList actionList; private: - HTTPHandler getHandler; - HTTPHandler postHandler; + HTTPGETHandler getHandler; + HTTPPOSTHandler postHandler; + HTTPPUTHandler putHandler; }; diff --git a/HTTPSession.cpp b/HTTPSession.cpp index 2edd3de..490dd60 100644 --- a/HTTPSession.cpp +++ b/HTTPSession.cpp @@ -1,18 +1,26 @@ #include "HTTPSession.h" +#include namespace http { HTTPSession::HTTPSession() { - sessionId = ""; - } - - HTTPSession::HTTPSession(std::string sessionId) { - this->sessionId = sessionId; + generateSessionId(); } - std::string HTTPSession::getSessionId() { - return sessionId; + HTTPSession::HTTPSession(coreutils::ZString sessionId) { + strncpy(this->sessionId, sessionId.getData(), 37); } - + + coreutils::ZString HTTPSession::getSessionId() { + return coreutils::ZString(sessionId, 37); + } + + int HTTPSession::generateSessionId() { + uuid_t uuid; + uuid_generate_random(uuid); + uuid_unparse(uuid, sessionId); + return 0; + } + } diff --git a/HTTPSession.h b/HTTPSession.h index 2bbdd70..93829b9 100644 --- a/HTTPSession.h +++ b/HTTPSession.h @@ -1,7 +1,7 @@ #ifndef __HTTPSession_h__ #define __HTTPSession_h__ -#include "includes" +#include "ZString.h" //#include "Variables.h" namespace http { @@ -10,14 +10,17 @@ namespace http { public: HTTPSession(); - HTTPSession(std::string sessionId); - std::string getSessionId(); + HTTPSession(coreutils::ZString sessionId); + + coreutils::ZString getSessionId(); // jet::Variables sessionVariables; // jet::Variables cgiFormVariables; private: - std::string sessionId; + int generateSessionId();; + + char sessionId[37]; }; diff --git a/HTTPSessions.cpp b/HTTPSessions.cpp index fee7d72..e54ffc3 100644 --- a/HTTPSessions.cpp +++ b/HTTPSessions.cpp @@ -1,55 +1,42 @@ #include "HTTPSessions.h" #include "HTTPSession.h" #include "Log.h" -#include namespace http { - HTTPSession * HTTPSessions::findSessionByHeader(HTTPRequest *httpRequest) { - coreutils::ZString sessionId(httpRequest->getHeaderKeyPairValue("Cookie", "sessionId")); - HTTPSession *session = findSessionById(sessionId, httpRequest); - return session; + HTTPSession * HTTPSessions::findSessionByHeader(HTTPRequest &httpRequest) { + coreutils::ZString sessionId(httpRequest.message.getHeaderKeyPairValue("Cookie", "SessionId")); + if(sessionId.str() == "") + return createHTTPSession(httpRequest); + else + return findSessionById(sessionId, httpRequest); } - HTTPSession * HTTPSessions::findSessionById(coreutils::ZString &sessionId, HTTPRequest *httpRequest) { - HTTPSession *httpSession; - if(sessionId.getLength() > 0) { - std::map::iterator ix; - httpSession = sessions[sessionId.str()]; - - if(ix == sessions.end()) { - httpSession = createHTTPSession(); - 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()); + HTTPSession * HTTPSessions::findSessionById(coreutils::ZString &sessionId, HTTPRequest &httpRequest) { + try { + HTTPSession *httpSession = sessions.at(sessionId); + return httpSession; } + catch (...) { + return createHTTPSession(httpRequest); + } + } + + HTTPSession * HTTPSessions::createHTTPSession(HTTPRequest &httpRequest) { + HTTPSession *httpSession = new HTTPSession(); + coreutils::ZString sessionId(httpSession->getSessionId()); + sessions.insert(std::make_pair(sessionId, httpSession)); + std::stringstream temp; + temp << "SessionId=" << httpSession->getSessionId(); + httpRequest.response.addHeader(coreutils::IMFHeader("Set-Cookie", temp.str().c_str())); return httpSession; } - HTTPSession * HTTPSessions::createHTTPSession() { - HTTPSession *httpSession = new HTTPSession(generateSessionId()); - sessions.insert(std::make_pair(httpSession->getSessionId(), httpSession)); - return httpSession; - } - - std::string HTTPSessions::generateSessionId() { - uuid_t uuid; - uuid_generate_random(uuid); - char uuid_s[37]; - uuid_unparse(uuid, uuid_s); - return uuid_s; - } - - int HTTPSessions::processCommand(std::string command, core::TCPSession *session, std::stringstream &data) { + int HTTPSessions::processCommand(std::string command, core::TCPSession *session, std::stringstream &data) { if(sessions.size() > 0) { int seq = 0; for(auto httpSession: sessions) data << "|" << ++seq << "|" << httpSession.second->getSessionId() << "|" << std::endl; - } else data << "There are no sessions active." << std::endl; diff --git a/HTTPSessions.h b/HTTPSessions.h index 08809c4..1585327 100644 --- a/HTTPSessions.h +++ b/HTTPSessions.h @@ -12,16 +12,15 @@ namespace http { class HTTPSessions : public core::Command { public: - HTTPSession * findSessionByHeader(HTTPRequest *httpRequest); - HTTPSession * findSessionById(coreutils::ZString &sessionId, HTTPRequest *httpRequest); + HTTPSession * findSessionByHeader(HTTPRequest &httpRequest); + HTTPSession * findSessionById(coreutils::ZString &sessionId, HTTPRequest &httpRequest); int processCommand(std::string request, core::TCPSession *session, std::stringstream &data); private: - HTTPSession * createHTTPSession(); - std::string generateSessionId(); + HTTPSession * createHTTPSession(HTTPRequest &httpRequest); - std::map sessions; + std::map sessions; }; diff --git a/JETServer_Programmers_Guide.tex b/JETServer_Programmers_Guide.tex index 42e9cb9..ba8994f 100644 --- a/JETServer_Programmers_Guide.tex +++ b/JETServer_Programmers_Guide.tex @@ -84,3 +84,16 @@ type will respond. +XQ +Within the XQ you can request action objects that are used to link +work flow exits. Using buttons and anchors you can progress a work +flow instance through a work flow patterns. + +These links are calls to the server using a uniquely assigned id that +is only active for the duration of the XQ duration on the browser. As +soon as a link is selected all links associated with the XQ are +cancelled. + +The associated work flow unit is moved through the work flow pattern +based upon the link selected in addition to the browser's form data +being passed to the work flow unit for processing. diff --git a/__addview.h b/__addview.h new file mode 100644 index 0000000..b1dfa7e --- /dev/null +++ b/__addview.h @@ -0,0 +1,29 @@ +#ifndef ____addview_h__ +#define ____addview_h__ + +#include "HTTPPage.h" + +namespace http { + + class __addview : public HTTPPage { + + int page(HTTPParameters &p) override { + + p.data << "
" + "

Please enter the name of the new view," + " then press Add View button below:" + "

" + "
View Name:
" + " " + "
" + " " + "
"; + + p.httpRequest.response.addHeader(coreutils::IMFHeader("Content-Type", "text/html")); + + return true; + } + }; +} + +#endif diff --git a/__configure.h b/__configure.h index bdfa4b5..2eeca74 100644 --- a/__configure.h +++ b/__configure.h @@ -5,29 +5,31 @@ namespace http { class __configure : public HTTPPage { - int processCommand(HTTPRequest *httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data) override { + public: + __configure(HTTPParameters &p) { page(p); } - data << "
" << std::endl; - data << "

System Configuration

" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "
Web Domain Name:
" << std::endl; - data << " " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << "
View Directory:
" << std::endl; - data << " " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << "
Image Library Directory:
" << std::endl; - data << " " << std::endl; - data << "
" << std::endl; - data << "

Session Id: " << httpSession->getSessionId() << "" << std::endl; - data << "
The configuration has not yet been established for this web site.

" << std::endl; - data << " " << std::endl; - data << "
" << std::endl; + int page(HTTPParameters &p) override { - httpRequest->response.addHeader("Content-Type", "text/html"); + p.data << "
" + "

System Configuration

" + "
" + "
Web Domain Name:
" + " " + "
" + "
" + "
View Directory:
" + " " + "
" + "
" + "
Image Library Directory:
" + " " + "
" + "

Session Id: " << p.httpSession.getSessionId() << "" + "
The configuration has not yet been established for this web site.

" + " " + "
"; + + p.httpRequest.response.addHeader(coreutils::IMFHeader("Content-Type", "text/html")); return true; } diff --git a/__editview.h b/__editview.h index a82f7b7..7d2cc4d 100644 --- a/__editview.h +++ b/__editview.h @@ -8,76 +8,78 @@ namespace http { class __editview : public HTTPPage { - int processCommand(HTTPRequest *httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data) override { + int page(HTTPParameters &p) override { - data << "
" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << " View Editor" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << " " << std::endl; - data << "" << std::endl; - - coreutils::File workspace("/home/barant/jetserver/views/testview1.view"); + char format[256]; + sprintf(format, "/home/barant/jetserver/views/%s.view", p.httpRequest.uriValues["view_name"].str().c_str()); + coreutils::File workspace(format); workspace.read(); - data << "
"; - data << workspace.asString(); - data << "
" << std::endl; + // coreutils::ZString requestId(putRequest()); - data << "" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << " OPTIONS" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << " Show Grid
" << std::endl; - data << " Snap To Grid
" << std::endl; - data << " Grid Size:
" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "

NO DATA

" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << " Toolbar" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << " " << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " " << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << " - - - - - - -
- -
- - View Editor - -
- - - - - - - - - -
-
- -
-
- -
-
- - This is a text label - - - -
-
- - -
- - OPTIONS - -
- -
- Show Grid
- Snap To Grid
- Grid Size:
-
- -
- -
-

NO DATA

-
- -
-
- - -
- - Toolbar - -
- - -
-
- -
- - - - - - \ No newline at end of file diff --git a/__editview_js.h b/__editview_js.h index 6bea5d8..faa8e59 100644 --- a/__editview_js.h +++ b/__editview_js.h @@ -7,207 +7,209 @@ namespace http { class __editview_js : public HTTPPage { - int processCommand(HTTPRequest *httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data) override { - data << " var mainpage;" << std::endl; - data << " var result;" << std::endl; - data << " var mousedownx;" << std::endl; - data << " var mousedowny;" << std::endl; - data << " var mouseDownWidth;" << std::endl; - data << " var mouseDownHeight;" << std::endl; - data << " var ismousedown = false;" << std::endl; - data << " var dragobject;" << std::endl; - data << " var dragHint = \"move\";" << std::endl; - data << " var data;" << std::endl; - data << " var showGrid = false;" << std::endl; - data << " var snapToGrid = false;" << std::endl; - data << " var gridSize = 10;" << std::endl; - data << " var selected;" << std::endl; - data << " var itemparameters;" << std::endl; - data << "" << std::endl; - data << " mainpage = document.getElementById(\"mainpage\");" << std::endl; - data << " data = document.getElementById(\"data\");" << std::endl; - data << " itemparameters = document.getElementById(\"itemparameters\");" << std::endl; - data << " var gridsize = document.getElementById(\"gridsize\");" << std::endl; - data << " gridsize.value = gridSize;" << std::endl; - data << " drawGrid();" << std::endl; - data << "" << std::endl; - data << " function drawGrid() {" << std::endl; - data << " var grid = document.getElementById(\"grid\");" << std::endl; - data << " var context = grid.getContext(\"2d\");" << std::endl; - data << " if(showGrid == true) {" << std::endl; - data << " context.clearRect(0,0,grid.width,grid.height);" << std::endl; - data << " context.globalAlpha = 0.2;" << std::endl; - data << " context.lineWidth = 0.5; " << std::endl; - data << " for(ix = 0; ix < grid.width; ix += gridSize) {" << std::endl; - data << " context.beginPath();" << std::endl; - data << " context.moveTo(ix, 0);" << std::endl; - data << " context.lineTo(ix, grid.height);" << std::endl; - data << " context.stroke();" << std::endl; - data << " context.beginPath();" << std::endl; - data << " context.moveTo(0, ix);" << std::endl; - data << " context.lineTo(grid.width, ix);" << std::endl; - data << " context.stroke(); " << std::endl; - data << " }" << std::endl; - data << " } else {" << std::endl; - data << " context.clearRect(0,0,grid.width,grid.height);" << std::endl; - data << " }" << std::endl; - data << " }" << std::endl; - data << "" << std::endl; - data << " function setDragHint(hint) {" << std::endl; - data << " dragHint = hint;" << std::endl; - data << " }" << std::endl; - data << " " << std::endl; - data << " function getMouseX(e) {" << std::endl; - data << " return e.clientX - mainpage.offsetLeft - parseFloat(mainpage.style.borderWidth);" << std::endl; - data << " }" << std::endl; - data << " " << std::endl; - data << " function getMouseY(e) {" << std::endl; - data << " return e.clientY - mainpage.offsetTop - parseFloat(mainpage.style.borderWidth);" << std::endl; - data << " }" << std::endl; - data << "" << std::endl; - data << " function mousedown(obj, e) {" << std::endl; - data << " var mouseX = getMouseX(e);" << std::endl; - data << " var mouseY = getMouseY(e);" << std::endl; - data << " mousedownx = mouseX - obj.offsetLeft;" << std::endl; - data << " mousedowny = mouseY - obj.offsetTop;" << std::endl; - data << " mouseDownLeft = parseFloat(obj.style.left);" << std::endl; - data << " mouseDownTop = parseFloat(obj.style.top);" << std::endl; - data << " mouseDownWidth = parseFloat(obj.style.width);" << std::endl; - data << " mouseDownHeight = parseFloat(obj.style.height);" << std::endl; - data << " dragobject = obj;" << std::endl; - data << " selected = obj;" << std::endl; - data << " ismousedown = true;" << std::endl; - data << " displayParameters();" << std::endl; - data << " }" << std::endl; - data << " " << std::endl; - data << " function mouseup() {" << std::endl; - data << " ismousedown = false;" << std::endl; - data << " dragobject = null;" << std::endl; - data << " console.log(mainpage.innerHTML);" << std::endl; - data << " }" << std::endl; - data << "" << std::endl; - data << " function mousemove(e) {" << std::endl; - data << " var mouseX = getMouseX(e);" << std::endl; - data << " var mouseY = getMouseY(e);" << std::endl; - data << " if(ismousedown) {" << std::endl; - data << " " << std::endl; - data << " if(dragHint == \"move\") {" << std::endl; - data << " if(snapToGrid == false) {" << std::endl; - data << " dragobject.style.left = (mouseX - mousedownx) + \"px\";" << std::endl; - data << " dragobject.style.top = (mouseY - mousedowny) + \"px\";" << std::endl; - data << " } else {" << std::endl; - data << " dragobject.style.left = (Math.round((mouseX - mousedownx) / gridSize) * gridSize) + \"px\";" << std::endl; - data << " dragobject.style.top = (Math.round((mouseY - mousedowny) / gridSize) * gridSize) + \"px\";" << std::endl; - data << " }" << std::endl; - data << " if((mouseX - mousedownx) < 0)" << std::endl; - data << " dragobject.style.left = \"0px\";" << std::endl; - data << " if((mouseY - mousedowny) < 0)" << std::endl; - data << " dragobject.style.top = \"0px\";" << std::endl; - data << " if((mouseX - mousedownx + parseFloat(dragobject.style.width)) > parseFloat(mainpage.style.width)) " << std::endl; - data << " dragobject.style.left = (mouseX - mousedownx) + \"px\"; " << std::endl; - data << " } else if(dragHint == \"rightbottomresize\") { " << std::endl; - data << " dragobject.style.width = (mouseX - mouseDownLeft) + \"px\";" << std::endl; - data << " dragobject.style.height = (mouseY - mouseDownTop) + \"px\";" << std::endl; - data << " } else if(dragHint == \"rightresize\") { " << std::endl; - data << " if(snapToGrid == false) {" << std::endl; - data << " dragobject.style.width = (mouseX - mouseDownLeft) + \"px\"; " << std::endl; - data << " } else {" << std::endl; - data << " dragobject.style.width = (Math.round((mouseX - mouseDownLeft) / gridSize) * gridSize) + \"px\"; " << std::endl; - data << " }" << std::endl; - data << " } else if(dragHint == \"bottomresize\") { " << std::endl; - data << " if(snapToGrid == false) {" << std::endl; - data << " dragobject.style.height = (mouseY - mouseDownTop) + \"px\";" << std::endl; - data << " } else {" << std::endl; - data << " dragobject.style.height = (Math.round((mouseY - mouseDownTop) / gridSize) * gridSize) + \"px\";" << std::endl; - data << " }" << std::endl; - data << " } else if(dragHint == \"leftresize\") { " << std::endl; - data << " dragobject.style.left = mouseX + \"px\";" << std::endl; - data << " dragobject.style.width = (mouseDownWidth + (mouseDownLeft - mouseX)) + \"px\";" << std::endl; - data << " } else if(dragHint == \"topresize\") { " << std::endl; - data << " dragobject.style.top = mouseY + \"px\";" << std::endl; - data << " dragobject.style.height = (mouseDownHeight + (mouseDownTop - mouseY)) + \"px\";" << std::endl; - data << " }" << std::endl; - data << " " << std::endl; - data << " data.innerHTML = \"

\" + dragobject.nodeName + \"
\" + " << std::endl; - data << " \"Action: \" + dragHint + \"
\" +" << std::endl; - data << " \"MouseLocation: \" + mouseX + \":\" + mouseY + \"
\" +" << std::endl; - data << " \"MouseOver Location: \" + (mouseX - dragobject.offsetLeft) + \":\" + (mouseY - dragobject.offsetTop) + \"
\" + " << std::endl; - data << " \"Location: \" + dragobject.style.left + \":\" + dragobject.style.top + \"
\" + " << std::endl; - data << " \"Size: \" + dragobject.style.width + \":\" + dragobject.style.height + \"
\" + " << std::endl; - data << " \"

\";" << std::endl; - data << " " << std::endl; - data << "" << std::endl; - data << " } else {" << std::endl; - data << " var mouseabove = document.elementFromPoint(mouseX + mainpage.offsetLeft, mouseY + mainpage.offsetTop);" << std::endl; - data << "" << std::endl; - data << " if((mouseabove.id != \"mainpage\") && (mouseabove.id != \"grid\")) {" << std::endl; - data << " " << std::endl; - data << " data.innerHTML = \"

\" + mouseabove.nodeName + \"
\" + " << std::endl; - data << " \"Action: \" + dragHint + \"
\" +" << std::endl; - data << " \"MouseLocation: \" + mouseX + \":\" + mouseY + \"
\" +" << std::endl; - data << " \"MouseOver Location: \" + (mouseX - mouseabove.offsetLeft) + \":\" + (mouseY - mouseabove.offsetTop) + \"
\" + " << std::endl; - data << " \"Location: \" + mouseabove.style.left + \":\" + mouseabove.style.top + \"
\" + " << std::endl; - data << " \"Size: \" + mouseabove.style.width + \":\" + mouseabove.style.height + \"
\" + " << std::endl; - data << " \"

\";" << std::endl; - data << " " << std::endl; - data << " if((mouseabove.nodeName == \"DIV\") || " << std::endl; - data << " (mouseabove.nodeName == \"IMG\") || " << std::endl; - data << " (mouseabove.nodeName == \"BUTTON\") ||" << std::endl; - data << " (mouseabove.nodeName == \"INPUT\") ||" << std::endl; - data << " (mouseabove.nodeName == \"SPAN\")) {" << std::endl; - data << " " << std::endl; - data << " if((parseFloat(mouseabove.style.width) <= (mouseX - mouseabove.offsetLeft)) && " << std::endl; - data << " (parseFloat(mouseabove.style.height) <= (mouseY - mouseabove.offsetTop))) {" << std::endl; - data << " mouseabove.style.cursor = \"nwse-resize\";" << std::endl; - data << " dragHint = \"rightbottomresize\"; " << std::endl; - data << " } else if((parseFloat(mouseabove.style.left) <= (mouseX - mouseabove.offsetLeft)) && " << std::endl; - data << " ((parseFloat(mouseabove.style.borderWidth) + 2) >= (mouseY - mouseabove.offsetTop))) {" << std::endl; - data << " mouseabove.style.cursor = \"nesw-resize\";" << std::endl; - data << " dragHint = \"righttopresize\"; " << std::endl; - data << " } else if(((parseFloat(mouseabove.style.borderWidth) + 2) >= (mouseX - mouseabove.offsetLeft)) && " << std::endl; - data << " (parseFloat(mouseabove.style.height) <= (mouseY - mouseabove.offsetTop))) {" << std::endl; - data << " mouseabove.style.cursor = \"nesw-resize\";" << std::endl; - data << " dragHint = \"leftbottomresize\"; " << std::endl; - data << " } else if(parseFloat(mouseabove.style.width) <= (mouseX - mouseabove.offsetLeft)) {" << std::endl; - data << " mouseabove.style.cursor = \"ew-resize\";" << std::endl; - data << " dragHint = \"rightresize\";" << std::endl; - data << " } else if(parseFloat(mouseabove.style.height) <= (mouseY - mouseabove.offsetTop)) {" << std::endl; - data << " mouseabove.style.cursor = \"ns-resize\";" << std::endl; - data << " dragHint = \"bottomresize\";" << std::endl; - data << " } else if((parseFloat(mouseabove.style.borderWidth) + 2) >= (mouseX - mouseabove.offsetLeft)) {" << std::endl; - data << " mouseabove.style.cursor = \"ew-resize\";" << std::endl; - data << " dragHint = \"leftresize\";" << std::endl; - data << " } else if((parseFloat(mouseabove.style.borderWidth) + 2) >= (mouseY - mouseabove.offsetTop)) {" << std::endl; - data << " mouseabove.style.cursor = \"ns-resize\";" << std::endl; - data << " dragHint = \"topresize\";" << std::endl; - data << " } else {" << std::endl; - data << " mouseabove.style.cursor = \"move\";" << std::endl; - data << " dragHint = \"move\";" << std::endl; - data << " }" << std::endl; - data << " } else {" << std::endl; - data << " mouseabove.style.cursor = \"default\";" << std::endl; - data << " }" << std::endl; - data << " } else {" << std::endl; - data << " mouseabove.style.cursor = \"default\";" << std::endl; - data << " dragHint = \"\";" << std::endl; - data << " data.innerHTML = \"

\";" << std::endl; - data << " }" << std::endl; - data << " }" << std::endl; - data << " displayParameters();" << std::endl; - data << " }" << std::endl; - data << " " << std::endl; - data << " function displayParameters() {" << std::endl; - data << "" << std::endl; - data << " itemparameters.innerHTML = \"

\" + selected.nodeName + \": \" + selected.id + \"
\" + " << std::endl; - data << " \"Location: \" + selected.style.left + \":\" + selected.style.top + \"
\" + " << std::endl; - data << " \"Size: \" + selected.style.width + \":\" + selected.style.height + \"
\" + " << std::endl; - data << " \"

\";" << std::endl; - data << "" << std::endl; - data << " }" << std::endl; + int page(HTTPParameters &p) override { - httpRequest->response.addHeader("Content-Type", "script/javascript"); + p.data << " var mainpage;" + " var result;" + " var mousedownx;" + " var mousedowny;" + " var mouseDownWidth;" + " var mouseDownHeight;" + " var ismousedown = false;" + " var dragobject;" + " var dragHint = \"move\";" + " var data;" + " var showGrid = false;" + " var snapToGrid = false;" + " var gridSize = 10;" + " var selected;" + " var itemparameters;" + "" + " mainpage = document.getElementById(\"mainpage\");" + " workspace = document.getElementById(\"__workspace__\");" + " data = document.getElementById(\"data\");" + " itemparameters = document.getElementById(\"itemparameters\");" + " var gridsize = document.getElementById(\"gridsize\");" + " gridsize.value = gridSize;" + " drawGrid();" + "" + " function drawGrid() {" + " var grid = document.getElementById(\"grid\");" + " var context = grid.getContext(\"2d\");" + " if(showGrid == true) {" + " context.clearRect(0,0,grid.width,grid.height);" + " context.globalAlpha = 0.2;" + " context.lineWidth = 0.5; " + " for(ix = 0; ix < grid.width; ix += gridSize) {" + " context.beginPath();" + " context.moveTo(ix, 0);" + " context.lineTo(ix, grid.height);" + " context.stroke();" + " context.beginPath();" + " context.moveTo(0, ix);" + " context.lineTo(grid.width, ix);" + " context.stroke(); " + " }" + " } else {" + " context.clearRect(0,0,grid.width,grid.height);" + " }" + " }" + "" + " function setDragHint(hint) {" + " dragHint = hint;" + " }" + " " + " function getMouseX(e) {" + " return e.clientX - mainpage.offsetLeft - parseFloat(mainpage.style.borderWidth);" + " }" + " " + " function getMouseY(e) {" + " return e.clientY - mainpage.offsetTop - parseFloat(mainpage.style.borderWidth);" + " }" + "" + " function mousedown(obj, e) {" + " var mouseX = getMouseX(e);" + " var mouseY = getMouseY(e);" + " mousedownx = mouseX - obj.offsetLeft;" + " mousedowny = mouseY - obj.offsetTop;" + " mouseDownLeft = parseFloat(obj.style.left);" + " mouseDownTop = parseFloat(obj.style.top);" + " mouseDownWidth = parseFloat(obj.style.width);" + " mouseDownHeight = parseFloat(obj.style.height);" + " dragobject = obj;" + " selected = obj;" + " ismousedown = true;" + " displayParameters();" + " }" + " " + " function mouseup() {" + " ismousedown = false;" + " dragobject = null;" + " console.log(workspace.innerHTML);" + " }" + "" + " function mousemove(e) {" + " var mouseX = getMouseX(e);" + " var mouseY = getMouseY(e);" + " if(ismousedown) {" + " " + " if(dragHint == \"move\") {" + " if(snapToGrid == false) {" + " dragobject.style.left = (mouseX - mousedownx) + \"px\";" + " dragobject.style.top = (mouseY - mousedowny) + \"px\";" + " } else {" + " dragobject.style.left = (Math.round((mouseX - mousedownx) / gridSize) * gridSize) + \"px\";" + " dragobject.style.top = (Math.round((mouseY - mousedowny) / gridSize) * gridSize) + \"px\";" + " }" + " if((mouseX - mousedownx) < 0)" + " dragobject.style.left = \"0px\";" + " if((mouseY - mousedowny) < 0)" + " dragobject.style.top = \"0px\";" + " if((mouseX - mousedownx + parseFloat(dragobject.style.width)) > parseFloat(mainpage.style.width)) " + " dragobject.style.left = (mouseX - mousedownx) + \"px\"; " + " } else if(dragHint == \"rightbottomresize\") { " + " dragobject.style.width = (mouseX - mouseDownLeft) + \"px\";" + " dragobject.style.height = (mouseY - mouseDownTop) + \"px\";" + " } else if(dragHint == \"rightresize\") { " + " if(snapToGrid == false) {" + " dragobject.style.width = (mouseX - mouseDownLeft) + \"px\"; " + " } else {" + " dragobject.style.width = (Math.round((mouseX - mouseDownLeft) / gridSize) * gridSize) + \"px\"; " + " }" + " } else if(dragHint == \"bottomresize\") { " + " if(snapToGrid == false) {" + " dragobject.style.height = (mouseY - mouseDownTop) + \"px\";" + " } else {" + " dragobject.style.height = (Math.round((mouseY - mouseDownTop) / gridSize) * gridSize) + \"px\";" + " }" + " } else if(dragHint == \"leftresize\") { " + " dragobject.style.left = mouseX + \"px\";" + " dragobject.style.width = (mouseDownWidth + (mouseDownLeft - mouseX)) + \"px\";" + " } else if(dragHint == \"topresize\") { " + " dragobject.style.top = mouseY + \"px\";" + " dragobject.style.height = (mouseDownHeight + (mouseDownTop - mouseY)) + \"px\";" + " }" + " " + " data.innerHTML = \"

\" + dragobject.nodeName + \"
\" + " + " \"Action: \" + dragHint + \"
\" +" + " \"MouseLocation: \" + mouseX + \":\" + mouseY + \"
\" +" + " \"MouseOver Location: \" + (mouseX - dragobject.offsetLeft) + \":\" + (mouseY - dragobject.offsetTop) + \"
\" + " + " \"Location: \" + dragobject.style.left + \":\" + dragobject.style.top + \"
\" + " + " \"Size: \" + dragobject.style.width + \":\" + dragobject.style.height + \"
\" + " + " \"

\";" + " " + "" + " } else {" + " var mouseabove = document.elementFromPoint(mouseX + mainpage.offsetLeft, mouseY + mainpage.offsetTop);" + "" + " if((mouseabove.id != \"mainpage\") && (mouseabove.id != \"grid\")) {" + " " + " data.innerHTML = \"

\" + mouseabove.nodeName + \"
\" + " + " \"Action: \" + dragHint + \"
\" +" + " \"MouseLocation: \" + mouseX + \":\" + mouseY + \"
\" +" + " \"MouseOver Location: \" + (mouseX - mouseabove.offsetLeft) + \":\" + (mouseY - mouseabove.offsetTop) + \"
\" + " + " \"Location: \" + mouseabove.style.left + \":\" + mouseabove.style.top + \"
\" + " + " \"Size: \" + mouseabove.style.width + \":\" + mouseabove.style.height + \"
\" + " + " \"

\";" + " " + " if((mouseabove.nodeName == \"DIV\") || " + " (mouseabove.nodeName == \"IMG\") || " + " (mouseabove.nodeName == \"BUTTON\") ||" + " (mouseabove.nodeName == \"INPUT\") ||" + " (mouseabove.nodeName == \"SPAN\")) {" + " " + " if((parseFloat(mouseabove.style.width) <= (mouseX - mouseabove.offsetLeft)) && " + " (parseFloat(mouseabove.style.height) <= (mouseY - mouseabove.offsetTop))) {" + " mouseabove.style.cursor = \"nwse-resize\";" + " dragHint = \"rightbottomresize\"; " + " } else if((parseFloat(mouseabove.style.left) <= (mouseX - mouseabove.offsetLeft)) && " + " ((parseFloat(mouseabove.style.borderWidth) + 2) >= (mouseY - mouseabove.offsetTop))) {" + " mouseabove.style.cursor = \"nesw-resize\";" + " dragHint = \"righttopresize\"; " + " } else if(((parseFloat(mouseabove.style.borderWidth) + 2) >= (mouseX - mouseabove.offsetLeft)) && " + " (parseFloat(mouseabove.style.height) <= (mouseY - mouseabove.offsetTop))) {" + " mouseabove.style.cursor = \"nesw-resize\";" + " dragHint = \"leftbottomresize\"; " + " } else if(parseFloat(mouseabove.style.width) <= (mouseX - mouseabove.offsetLeft)) {" + " mouseabove.style.cursor = \"ew-resize\";" + " dragHint = \"rightresize\";" + " } else if(parseFloat(mouseabove.style.height) <= (mouseY - mouseabove.offsetTop)) {" + " mouseabove.style.cursor = \"ns-resize\";" + " dragHint = \"bottomresize\";" + " } else if((parseFloat(mouseabove.style.borderWidth) + 2) >= (mouseX - mouseabove.offsetLeft)) {" + " mouseabove.style.cursor = \"ew-resize\";" + " dragHint = \"leftresize\";" + " } else if((parseFloat(mouseabove.style.borderWidth) + 2) >= (mouseY - mouseabove.offsetTop)) {" + " mouseabove.style.cursor = \"ns-resize\";" + " dragHint = \"topresize\";" + " } else {" + " mouseabove.style.cursor = \"move\";" + " dragHint = \"move\";" + " }" + " } else {" + " mouseabove.style.cursor = \"default\";" + " }" + " } else {" + " data.innerHTML = \"

\";" + " mouseabove.style.cursor = \"default\";" + " dragHint = \"\";" + " }" + " }" + " displayParameters();" + " }" + " " + " function displayParameters() {" + "" + " itemparameters.innerHTML = \"

\" + selected.nodeName + \": \" + selected.id + \"
\" + " + " \"Location: \" + selected.style.left + \":\" + selected.style.top + \"
\" + " + " \"Size: \" + selected.style.width + \":\" + selected.style.height + \"
\" + " + " \"

\";" + "" + " }"; - return 0; + p.httpRequest.response.addHeader(coreutils::IMFHeader("Content-Type", "script/javascript")); + + return 1; } }; diff --git a/__entrypoints.h b/__entrypoints.h new file mode 100644 index 0000000..677f88b --- /dev/null +++ b/__entrypoints.h @@ -0,0 +1,31 @@ +#ifndef ____entrypoints_h__ +#define ____entrypoints_h__ + +namespace http { + + class __entrypoints : public HTTPPage { + + int page(HTTPParameters &p) override { + + p.data << "
" + "

Entry Points

" + "
" + "
Entry Point URL:
" + " " + "
" + "
" + "
Entry Point Flow
" + " " + "
" + "

Session Id: " << p.httpSession.getSessionId() << "" + " " + "
"; + + p.httpRequest.response.addHeader(coreutils::IMFHeader("Content-Type", "text/html")); + + return true; + } + }; +} + +#endif diff --git a/__favicon_ico.h b/__favicon_ico.h index 0df88ac..ada1f7c 100644 --- a/__favicon_ico.h +++ b/__favicon_ico.h @@ -7,15 +7,12 @@ namespace http { class __favicon_ico : public HTTPPage { - int processCommand(HTTPRequest *httpRequest, - core::TCPSession *session, - HTTPSession *httpSession, - std::stringstream &data) override { + int page(HTTPParameters &p) override { - data << std::string(header_data, 806); + p.data << std::string(header_data, 806); - httpRequest->response.addHeader("Content-Type", "image/x-icon"); - return true; + p.httpRequest.response.addHeader(coreutils::IMFHeader("Content-Type", "image/x-icon")); + return 1; } const char *header_data = {"\x00\x00\x01\x00\x01\x00\x20\x20\x00\x00\x01\x00\x08\x00\xA8\x08\x00" diff --git a/__index.h b/__index.h index b7e2c2c..1331fe6 100644 --- a/__index.h +++ b/__index.h @@ -2,29 +2,28 @@ #define ____index_h__ #include "HTTPPage.h" -#include "HTTPRequest.h" +#include "IMFHeader.h" namespace http { class __index : public HTTPPage { - int processCommand(HTTPRequest *httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data) override { + int page(HTTPParameters &p) override { - data << "" << std::endl; - data << " " << std::endl; - data << " " << std::endl; - data << " " << std::endl; - data << " " << std::endl; - data << " " << std::endl; + p.data << "" + " " + " " + " " + " " + " " + " " + "
If you see this then something is wrong.
" + " " + ""; - data << "" << std::endl; - data << "
If you see this then something is wrong.
" << std::endl; - data << " " << std::endl; - data << "" << std::endl; - - httpRequest->response.addHeader("Content-Type", "text/html"); + p.httpRequest.response.addHeader(coreutils::IMFHeader("Content-Type", "text/html")); return true; } }; diff --git a/__mainmenu.h b/__mainmenu.h index e5e483a..9c9f654 100644 --- a/__mainmenu.h +++ b/__mainmenu.h @@ -2,40 +2,41 @@ #define ____mainmenu_h__ #include "HTTPPage.h" +#include "IMFFormData.h" namespace http { class __mainmenu : public HTTPPage { - int processCommand(HTTPRequest *httpRequest, - core::TCPSession *session, - HTTPSession *httpSession, - std::stringstream &data) override { + public: + __mainmenu(HTTPParameters &p) { page(p); } + + int page(HTTPParameters &p) override { - data << "
" << std::endl; - data << "
" << std::endl; - data << " Setup Server Parameters" << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " View and Layout Designer" << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " Entry Points" << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " Data Entity Editor" << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " Work Flow Process Management" << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; + p.data << "
" + "
" + " Setup Server Parameters" + "
" + "
" + " View and Layout Designer" + "
" + "
" + " Entry Points" + "
" + "
" + " Data Entity Editor" + "
" + "
" + " Work Flow Process Management" + "
" + "
"; - httpRequest->response.addHeader("Content-Type", "text/html"); + p.httpRequest.response.addHeader(coreutils::IMFHeader("Content-Type", "text/html")); return true; } diff --git a/__script.h b/__script.h index 325a1e6..888ab7a 100644 --- a/__script.h +++ b/__script.h @@ -7,51 +7,45 @@ namespace http { class __script : public HTTPPage { - int processCommand(HTTPRequest *httpRequest, - core::TCPSession *session, - HTTPSession *httpSession, - std::stringstream &data) override { + int page(HTTPParameters &p) override { - data << "function serverSend(url, type, receiver, formData, callback) {" << std::endl; - data << " var server = new XMLHttpRequest();" << std::endl; - data << " server.onload = function() {" << std::endl; - data << " if(server.readyState == 4 && server.status == 200)" << std::endl; - data << " callback(server.responseText, receiver);" << std::endl; - data << " };" << std::endl; - data << " server.open(type, url, true);" << std::endl; - data << " server.send(formData);" << std::endl; - data << "}" << std::endl; + p.data << "function serverSend(url, type, receiver, formData, callback) {" + " var server = new XMLHttpRequest();" + " server.onload = function() {" + " if(server.readyState == 4 && server.status == 200)" + " callback(server.responseText, receiver);" + " };" + " server.open(type, url, true);" + " server.send(formData);" + "}" + "function getPage(url, receiver) {" + " serverSend(url, \"GET\", receiver, null, function(data, receiver) {" + " insertAndExecute(receiver, data);" + " });" + "}" + "function process(url, formName, receiver) {" + " var formElement = document.querySelector(\"form[name='\" + formName + \"']\");" + " var formData = new FormData(formElement);" + " serverSend(url, \"POST\", receiver, formData, function(data, receiver) {" + " insertAndExecute(receiver, data);" + " });" + "}" + "function insertAndExecute(id, text) {" + " idresolved = document.getElementById(id);" + " idresolved.innerHTML = text;" + " var scriptarr = idresolved.getElementsByTagName(\"script\");" + " if(scriptarr.length > 0) {" + " var script = document.createElement(\"script\");" + " script.type = \"text/javascript\";" + " script.src = scriptarr[0].src;" + " document.getElementsByTagName(\"head\")[0].appendChild(script);" + " }" + "}"; - data << "function getPage(url, receiver) {" << std::endl; - data << " serverSend(url, \"GET\", receiver, null, function(data, receiver) {" << std::endl; - data << " insertAndExecute(receiver, data);" << std::endl; - data << " });" << std::endl; - data << "}" << std::endl; + p.httpRequest.response.addHeader(coreutils::IMFHeader("Content-Type", "text/javascript")); - data << "function process(url, formName, receiver) {" << std::endl; - data << " var formElement = document.querySelector(\"form[name='\" + formName + \"']\");" << std::endl; - data << " var formData = new FormData(formElement);" << std::endl; - data << " serverSend(url, \"POST\", receiver, formData, function(data, receiver) {" << std::endl; - data << " insertAndExecute(receiver, data);" << std::endl; - data << " });" << std::endl; - data << "}" << std::endl; - - data << "function insertAndExecute(id, text) {" << std::endl; - data << " idresolved = document.getElementById(id);" << std::endl; - data << " idresolved.innerHTML = text;" << std::endl; - data << " var scriptarr = idresolved.getElementsByTagName(\"script\");" << std::endl; - data << " if(scriptarr.length > 0) {" << std::endl; - data << " var script = document.createElement(\"script\");" << std::endl; - data << " script.type = \"text/javascript\";" << std::endl; - data << " script.src = scriptarr[0].src;" << std::endl; - data << " document.getElementsByTagName(\"head\")[0].appendChild(script);" << std::endl; - data << " }" << std::endl; - data << "}" << std::endl; - - httpRequest->response.addHeader("Content-Type", "text/javascript"); - return true; - } + } }; } diff --git a/__setupadmin.cpp b/__setupadmin.cpp new file mode 100644 index 0000000..cd4c480 --- /dev/null +++ b/__setupadmin.cpp @@ -0,0 +1,43 @@ +#include "__setupadmin.h" +#include "__mainmenu.h" + +namespace http { + + __setupadmin::__setupadmin(HTTPParameters &p) { page(p); } + + int __setupadmin::page(HTTPParameters &p) { + + button1Click *click = new button1Click(); + coreutils::ZString button1_Click(p.actionList.addAction(click)); + + p.data << "
" + "

Please enter credential information" + " for the security officer, then press Set Admin Profile button below:" + "

" + "
User Name:
" + " " + "
" + "
" + "
Password:
" + " " + "
" + "
" + "
Verify Password:
" + " " + "
" + "

Session Id: " << p.httpSession.getSessionId() << "" + "
The configuration has not yet been established for this web site.

" + " " + "
"; + + p.httpRequest.response.addHeader(coreutils::IMFHeader("Content-Type", "text/html")); + + return 1; + } + + bool __setupadmin::button1Click::action(HTTPParameters &p) { + __mainmenu mainmenu(p); + return true; + } + +} diff --git a/__setupadmin.h b/__setupadmin.h index f949126..c96bd9a 100644 --- a/__setupadmin.h +++ b/__setupadmin.h @@ -1,36 +1,24 @@ #ifndef ____setupadmin_h__ #define ____setupadmin_h__ +#include "HTTPPage.h" +#include "FlowAction.h" + namespace http { class __setupadmin : public HTTPPage { - int processCommand(HTTPRequest *httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data) override { + public: + __setupadmin(HTTPParameters &p); - data << "
" << std::endl; - data << "

Please enter credential information" << std::endl; - data << " for the security officer, then press Set Admin Profile button below:" << std::endl; - data << "

" << std::endl; - data << "
User Name:
" << std::endl; - data << " " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << "
Password:
" << std::endl; - data << " " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << "
Verify Password:
" << std::endl; - data << " " << std::endl; - data << "
" << std::endl; - data << "

Session Id: " << httpSession->getSessionId() << "" << std::endl; - data << "
The configuration has not yet been established for this web site.

" << std::endl; - data << " " << std::endl; - data << "
" << std::endl; + int page(HTTPParameters &p) override; - httpRequest->response.addHeader("Content-Type", "text/html"); + class button1Click : public FlowAction { - return true; - } + public: + bool action(HTTPParameters &p) override; + + }; }; } diff --git a/__style.h b/__style.h index fa1e0f4..49458a0 100644 --- a/__style.h +++ b/__style.h @@ -5,23 +5,42 @@ namespace http { + #include "HTTPPage.h" + #include "HTTPParameters.h" + class __style : public HTTPPage { - int processCommand(HTTPRequest *httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data) override { + int page(HTTPParameters &p) override { - data << "body {background: #006;" << std::endl; - data << " color: #fff;" << std::endl; - data << " }" << std::endl; + p.data << "body {background: #006;" + " color: #fff;" + " }\n" + ".window {background: #668;" + " color: #fff;" + " border: 1pt solid #f00;" + " width: 400px;" + " padding: 3px;" + " }\n" + ".adminheader {background: #000;" + " color: #fff;" + " border: 1pt solid #888;" + " width: 400px;" + " padding: 3px;" + " }\n" + "h1 {background: #223;" + " color: #fff;" + " padding: 5px;" + " margin: 0px 0px 5px 0px;" + " }\n" + "input[type=text] {background: #0000;" + " color: #fff;" + " border: 0px;" + " padding: 5px;" + " margin: 0px 0px 5px 0px;" + " }\n"; - data << ".window {background: #668;" << std::endl; - data << " color: #fff;" << std::endl; - data << " border: 1pt solid #f00;" << std::endl; - data << " width: 400px;" << std::endl; - data << " padding: 15px;" << std::endl; - data << " }" << std::endl; - - httpRequest->response.addHeader("Content-Type", "text/css"); - return true; + p.httpRequest.response.addHeader(coreutils::IMFHeader("Content-Type", "text/css")); + return 1; } }; } diff --git a/__viewlist.h b/__viewlist.h index 799c47b..8fc9ebb 100644 --- a/__viewlist.h +++ b/__viewlist.h @@ -2,25 +2,22 @@ #define ____viewlist_h__ #include "HTTPPage.h" +#include "HTTPParameters.h" #include "Directory.h" namespace http { class __viewlist : public HTTPPage { - int processCommand(HTTPRequest *httpRequest, - core::TCPSession *session, - HTTPSession *httpSession, - std::stringstream &data) override { + int page(HTTPParameters &p) override { coreutils::Directory directory("../../jetserver/views"); - data << "
" << std::endl; - - data << "
" << std::endl; - data << " Create new view" << std::endl; - data << "
" << std::endl; + p.data << "
" + "
" + " Create new view" + "
"; while(!directory.eod()) { @@ -29,16 +26,16 @@ namespace http { continue; } - data << "
" << std::endl; - data << " " << directory.get().getName() << "" << std::endl; - data << "
" << std::endl; + p.data << "
" + " " << directory.get().getName() << "" + "
"; directory.next(); } - data << "
" << std::endl; + p.data << "
"; - httpRequest->response.addHeader("Content-Type", "text/html"); + p.httpRequest.response.addHeader(coreutils::IMFHeader("Content-Type", "text/html")); return true; } diff --git a/__welcome.cpp b/__welcome.cpp new file mode 100644 index 0000000..e5c9e21 --- /dev/null +++ b/__welcome.cpp @@ -0,0 +1,34 @@ +#include "__welcome.h" +#include "__setupadmin.h" + +namespace http { + + int __welcome::page(HTTPParameters &p) { + + p.data << "
" + "Session Id: " << p.httpSession.getSessionId() << "
User: *ADMIN" + "

"; + + button1Click *click = new button1Click(); + coreutils::ZString button1_Click(p.actionList.addAction(click)); + + p.data << "
" + "
" + "

You have successfully set up a JETServer." + "
The configuration has not yet been established for this web site.

" + "" + "

"; + + p.data << "

"; + + p.httpRequest.response.addHeader(coreutils::IMFHeader("Content-Type", "text/html")); + + return 1; + } + + bool __welcome::button1Click::action(HTTPParameters &p) { + __setupadmin setupadmin(p); + return true; + } + +} diff --git a/__welcome.h b/__welcome.h index 414bf93..f408072 100644 --- a/__welcome.h +++ b/__welcome.h @@ -1,28 +1,22 @@ #ifndef ____welcome_h__ #define ____welcome_h__ +#include "FlowAction.h" #include "HTTPPage.h" namespace http { class __welcome : public HTTPPage { - int processCommand(HTTPRequest *httpRequest, - core::TCPSession *session, - HTTPSession *httpSession, - std::stringstream &data) override { + public: + int page(HTTPParameters &p) override; - data << "
\ -

You have successfully set up a JETServer.\ -
Session Id: " << httpSession->getSessionId() << "\ -
The configuration has not yet been established for this web site.

\ - \ -
"; + class button1Click : public FlowAction { - httpRequest->response.addHeader("Content-Type", "text/html"); + public: + bool action(HTTPParameters &p) override; - return true; - } + }; }; } diff --git a/__workflow.h b/__workflow.h index f14e970..6fd7794 100644 --- a/__workflow.h +++ b/__workflow.h @@ -7,91 +7,92 @@ namespace http { class __workflow : public HTTPPage { - int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) { - data << "" << std::endl; - data << " " << std::endl; - data << " " << std::endl; - data << " " << std::endl; - data << " " << std::endl; - data << " " << std::endl; - data << " " << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "[AQ] START" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << " [XQ] FORM Page 1 " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " Cancel " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " Next " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " [XQ] FORM Page 2 " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " Previous " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " Next " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " [XQ] FORM Page 3 " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " Previous " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " Process Form " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " [PQ] Process Form " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " Previous " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << " Process Form " << std::endl; - data << "
" << std::endl; - data << "
" << std::endl; - data << "" << std::endl; - data << "