2
0
mirror of https://github.com/inspircd/inspircd.git synced 2025-03-22 17:09:03 -04:00

Event class for m_httpd.cpp

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4325 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
brain 2006-07-11 12:55:49 +00:00
parent ecec1067b4
commit 3f80008ba3
2 changed files with 74 additions and 5 deletions

42
src/modules/httpd.h Normal file

@ -0,0 +1,42 @@
#include "base.h"
#ifndef __HTTPD_H__
#define __HTTPD_H__
HTTPRequest : public classbase
{
protected:
std::string type;
std::string document;
std::string ipaddr;
public:
void* opaque;
HTTPRequest(const std::string &request_type, const std::string &uri, void* opaque, const std::string &ip)
: type(request_type), document(uri), ipaddr(ip)
{
}
std::string& GetType()
{
return type;
}
std::string& GetURI()
{
return document;
}
std::string& GetIP()
{
return ipaddr;
}
}
#endif
//httpr(request_type,uri,headers,this,this->GetIP());

@ -22,10 +22,14 @@ using namespace std;
#include "modules.h" #include "modules.h"
#include "inspsocket.h" #include "inspsocket.h"
#include "helperfuncs.h" #include "helperfuncs.h"
#include "httpd.h"
/* $ModDesc: Provides HTTP serving facilities to modules */ /* $ModDesc: Provides HTTP serving facilities to modules */
class ModuleHttp;
static Server *Srv; static Server *Srv;
static ModuleHttp* HttpModule;
extern time_t TIME; extern time_t TIME;
enum HttpState enum HttpState
@ -68,18 +72,20 @@ class HttpSocket : public InspSocket
{ {
} }
void SendHeaders() void SendHeaders(unsigned long size)
{ {
struct tm *timeinfo = localtime(&TIME); struct tm *timeinfo = localtime(&TIME);
this->Write("HTTP/1.1 200 OK\r\nDate: "); this->Write("HTTP/1.1 200 OK\r\nDate: ");
this->Write(asctime(timeinfo)); this->Write(asctime(timeinfo));
this->Write("Server: InspIRCd/m_httpd.so/1.1\r\nContent-Length: "+ConvToStr(index->ContentSize())+ this->Write("Server: InspIRCd/m_httpd.so/1.1\r\nContent-Length: "+ConvToStr(size)+
"\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n"); "\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n");
} }
virtual bool OnDataReady() virtual bool OnDataReady()
{ {
char* data = this->Read(); char* data = this->Read();
std::string request_type;
/* Check that the data read is a valid pointer and it has some content */ /* Check that the data read is a valid pointer and it has some content */
if (data && *data) if (data && *data)
{ {
@ -89,9 +95,20 @@ class HttpSocket : public InspSocket
{ {
/* Headers are complete */ /* Headers are complete */
InternalState = HTTP_SERVE_SEND_DATA; InternalState = HTTP_SERVE_SEND_DATA;
SendHeaders();
headers >> request_type;
headers >> uri;
if ((request_type == "GET") && (uri = "/"))
{
SendHeaders(index->ContentSize());
this->Write(index->Contents()); this->Write(index->Contents());
}
else
{
HttpRequest httpr(request_type,uri,headers,this,this->GetIP());
Event e(uri, HttpModule, "httpd_url");
}
return false; return false;
} }
@ -147,6 +164,15 @@ class ModuleHttp : public Module
CreateListener(); CreateListener();
} }
void OnEvent(Event* event)
{
}
char* OnRequest(Request* request)
{
return NULL;
}
void Implements(char* List) void Implements(char* List)
{ {
List[I_OnEvent] = List[I_OnRequest] = 1; List[I_OnEvent] = List[I_OnRequest] = 1;
@ -177,7 +203,8 @@ class ModuleHttpFactory : public ModuleFactory
virtual Module * CreateModule(Server* Me) virtual Module * CreateModule(Server* Me)
{ {
return new ModuleHttp(Me); ModuleHttp = new ModuleHttp(Me);
return new HttpModule;
} }
}; };