version 0.3.0
[fms.git] / src / http / httpthread.cpp
index 55f82b9..ceaad4f 100644 (file)
@@ -1,21 +1,11 @@
 #include "../../include/http/httpthread.h"\r
+#include "../../include/http/fmshttprequesthandlerfactory.h"\r
 #include "../../include/option.h"\r
 #include "../../include/stringfunctions.h"\r
-#include "../../include/http/pages/homepage.h"\r
-#include "../../include/http/pages/optionspage.h"\r
-#include "../../include/http/pages/showcaptchapage.h"\r
-#include "../../include/http/pages/createidentitypage.h"\r
-#include "../../include/http/pages/localidentitiespage.h"\r
-#include "../../include/http/pages/announceidentitypage.h"\r
-#include "../../include/http/pages/addpeerpage.h"\r
-#include "../../include/http/pages/peertrustpage.h"\r
-#include "../../include/http/pages/controlboardpage.h"\r
-#include "../../include/http/pages/peerdetailspage.h"\r
-#include "../../include/http/pages/peermaintenancepage.h"\r
-#include "../../include/http/pages/execquerypage.h"\r
-#include "../../include/http/pages/boardspage.h"\r
-#include "../../include/http/pages/insertedfilespage.h"\r
-#include "../../include/http/pages/confirmpage.h"\r
+\r
+#include <Poco/Net/ServerSocket.h>\r
+#include <Poco/Net/HTTPServer.h>\r
+#include <Poco/Net/HTTPServerParams.h>\r
 \r
 #include <iostream>\r
 \r
 \r
 HTTPThread::HTTPThread()\r
 {\r
-       std::string templatestr;\r
-       int port;\r
+       m_listenport=8080;\r
        std::string portstr;\r
        Option::Instance()->Get("HTTPListenPort",portstr);\r
-       StringFunctions::Convert(portstr,port);\r
-\r
-       std::string aclstr;\r
-       Option::Instance()->Get("HTTPAccessControl",aclstr);\r
-\r
-       // set template\r
-       templatestr="<html><head></head><body><a href=\"home.htm\">Home</a><br><h1>Could not find template.htm!  Place in program directory and restart!</h1><br>[CONTENT]</body></html>";\r
-       FILE *infile=fopen("template.htm","r+b");\r
-       if(infile)\r
-       {\r
-               fseek(infile,0,SEEK_END);\r
-               long len=ftell(infile);\r
-               std::vector<char> data(len,0);\r
-               fseek(infile,0,SEEK_SET);\r
-               fread(&data[0],1,len,infile);\r
-               fclose(infile);\r
-               templatestr.assign(data.begin(),data.end());\r
-       }\r
-       else\r
-       {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"HTTPThread::HTTPThread could not open template.htm");\r
-       }\r
+       StringFunctions::Convert(portstr,m_listenport);\r
 \r
        // push back page handlers\r
+       /*\r
        m_pagehandlers.push_back(new ShowCaptchaPage());\r
        m_pagehandlers.push_back(new OptionsPage(templatestr));\r
        m_pagehandlers.push_back(new LocalIdentitiesPage(templatestr));\r
@@ -69,27 +38,11 @@ HTTPThread::HTTPThread()
        m_pagehandlers.push_back(new ConfirmPage(templatestr));\r
        // homepage must be last - catch all page handler\r
        m_pagehandlers.push_back(new HomePage(templatestr));\r
-\r
-       m_ctx=0;\r
-       m_ctx=shttpd_init();\r
-       shttpd_set_option(m_ctx,"ports",portstr.c_str());\r
-       shttpd_set_option(m_ctx,"acl",aclstr.c_str());\r
-\r
-       shttpd_register_uri(m_ctx,"*",HTTPThread::PageCallback,this);\r
-\r
-}\r
-\r
-HTTPThread::~HTTPThread()\r
-{\r
-       shttpd_fini(m_ctx);\r
-\r
-       for(std::vector<IPageHandler *>::iterator i=m_pagehandlers.begin(); i!=m_pagehandlers.end(); i++)\r
-       {\r
-               delete (*i);\r
-       }\r
-\r
+       */\r
+       \r
 }\r
 \r
+/*\r
 void HTTPThread::PageCallback(shttpd_arg *arg)\r
 {\r
 \r
@@ -108,16 +61,26 @@ void HTTPThread::PageCallback(shttpd_arg *arg)
        }\r
 \r
 }\r
-\r
-void HTTPThread::Run()\r
+*/\r
+void HTTPThread::run()\r
 {\r
-       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"HTTPThread::run thread started.");\r
+       m_log->debug("HTTPThread::run thread started.");\r
+\r
+       Poco::Net::ServerSocket sock(m_listenport);\r
+       Poco::Net::HTTPServerParams* pParams = new Poco::Net::HTTPServerParams;\r
+       pParams->setMaxQueued(10);\r
+       pParams->setMaxThreads(5);\r
+       Poco::Net::HTTPServer srv(new FMSHTTPRequestHandlerFactory,sock,pParams);\r
+\r
+       srv.start();\r
 \r
        do\r
        {\r
-               shttpd_poll(m_ctx,1000);\r
+               Poco::Thread::sleep(1000);\r
        }while(!IsCancelled());\r
 \r
-       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"HTTPThread::run thread exiting.");\r
+       srv.stop();\r
+\r
+       m_log->debug("HTTPThread::run thread exiting.");\r
 \r
 }\r