1 #include "../../include/http/httpthread.h"
\r
2 #include "../../include/option.h"
\r
3 #include "../../include/stringfunctions.h"
\r
4 #include "../../include/http/pages/homepage.h"
\r
5 #include "../../include/http/pages/optionspage.h"
\r
6 #include "../../include/http/pages/showcaptchapage.h"
\r
7 #include "../../include/http/pages/createidentitypage.h"
\r
8 #include "../../include/http/pages/localidentitiespage.h"
\r
9 #include "../../include/http/pages/announceidentitypage.h"
\r
10 #include "../../include/http/pages/addpeerpage.h"
\r
11 #include "../../include/http/pages/peertrustpage.h"
\r
12 #include "../../include/http/pages/controlboardpage.h"
\r
13 #include "../../include/http/pages/peerdetailspage.h"
\r
14 #include "../../include/http/pages/peermaintenancepage.h"
\r
15 #include "../../include/http/pages/execquerypage.h"
\r
16 #include "../../include/http/pages/boardspage.h"
\r
17 #include "../../include/http/pages/insertedfilespage.h"
\r
25 HTTPThread::HTTPThread()
\r
27 std::string templatestr;
\r
29 std::string portstr;
\r
30 Option::Instance()->Get("HTTPListenPort",portstr);
\r
31 StringFunctions::Convert(portstr,port);
\r
34 Option::Instance()->Get("HTTPAccessControl",aclstr);
\r
37 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
38 FILE *infile=fopen("template.htm","r+b");
\r
41 fseek(infile,0,SEEK_END);
\r
42 long len=ftell(infile);
\r
43 std::vector<char> data(len,0);
\r
44 fseek(infile,0,SEEK_SET);
\r
45 fread(&data[0],1,len,infile);
\r
47 templatestr.assign(data.begin(),data.end());
\r
51 m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"HTTPThread::HTTPThread could not open template.htm");
\r
54 // push back page handlers
\r
55 m_pagehandlers.push_back(new ShowCaptchaPage());
\r
56 m_pagehandlers.push_back(new OptionsPage(templatestr));
\r
57 m_pagehandlers.push_back(new LocalIdentitiesPage(templatestr));
\r
58 m_pagehandlers.push_back(new CreateIdentityPage(templatestr));
\r
59 m_pagehandlers.push_back(new AnnounceIdentityPage(templatestr));
\r
60 m_pagehandlers.push_back(new AddPeerPage(templatestr));
\r
61 m_pagehandlers.push_back(new PeerTrustPage(templatestr));
\r
62 m_pagehandlers.push_back(new ControlBoardPage(templatestr));
\r
63 m_pagehandlers.push_back(new PeerDetailsPage(templatestr));
\r
64 m_pagehandlers.push_back(new PeerMaintenancePage(templatestr));
\r
65 m_pagehandlers.push_back(new ExecQueryPage(templatestr));
\r
66 m_pagehandlers.push_back(new BoardsPage(templatestr));
\r
67 m_pagehandlers.push_back(new InsertedFilesPage(templatestr));
\r
68 // homepage must be last - catch all page handler
\r
69 m_pagehandlers.push_back(new HomePage(templatestr));
\r
72 m_ctx=shttpd_init();
\r
73 shttpd_set_option(m_ctx,"ports",portstr.c_str());
\r
74 shttpd_set_option(m_ctx,"acl",aclstr.c_str());
\r
76 shttpd_register_uri(m_ctx,"*",HTTPThread::PageCallback,this);
\r
80 HTTPThread::~HTTPThread()
\r
84 for(std::vector<IPageHandler *>::iterator i=m_pagehandlers.begin(); i!=m_pagehandlers.end(); i++)
\r
91 void HTTPThread::PageCallback(shttpd_arg *arg)
\r
94 HTTPThread *thread=(HTTPThread *)arg->user_data;
\r
96 for(std::vector<IPageHandler *>::iterator i=thread->m_pagehandlers.begin(); i!=thread->m_pagehandlers.end(); )
\r
98 if((*i)->Handle(arg)==true)
\r
100 i=thread->m_pagehandlers.end();
\r
110 void HTTPThread::Run()
\r
112 m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"HTTPThread::run thread started.");
\r
116 shttpd_poll(m_ctx,1000);
\r
117 }while(!IsCancelled());
\r
119 m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"HTTPThread::run thread exiting.");
\r