The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

HttpServerSocket Class Reference

A socket used for HTTP transport. More...

Inheritance diagram for HttpServerSocket:

Inheritance graph
[legend]
Collaboration diagram for HttpServerSocket:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 HttpServerSocket (InspIRCd *SI, std::string shost, int iport, bool listening, unsigned long maxtime, FileReader *index_page)
 HttpServerSocket (InspIRCd *SI, int newfd, char *ip, FileReader *ind)
FileReaderGetIndex ()
 ~HttpServerSocket ()
virtual int OnIncomingConnection (int newsock, char *ip)
 If your socket is a listening socket, when a new connection comes in on the socket this method will be called.
virtual void OnClose ()
 Whenever close() is called, OnClose() will be called first.
std::string Response (int response)
void SendHTTPError (int response)
void SendHeaders (unsigned long size, int response, HTTPHeaders &rheaders)
virtual bool OnDataReady ()
 When there is data waiting to be read on a socket, the OnDataReady() method is called.
void CheckRequestBuffer ()
void ServeData ()
bool OnWriteReady ()
 When it is ok to write to the socket, and a write event was requested, this method is triggered.
void Page (std::stringstream *n, int response, HTTPHeaders *hheaders)
void SetWrite ()

Private Attributes

FileReaderindex
HttpState InternalState
HTTPHeaders headers
std::string reqbuffer
std::string postdata
unsigned int postsize
std::string request_type
std::string uri
std::string http_version

Detailed Description

A socket used for HTTP transport.

Definition at line 37 of file m_httpd.cpp.


Constructor & Destructor Documentation

HttpServerSocket::HttpServerSocket InspIRCd SI,
std::string  shost,
int  iport,
bool  listening,
unsigned long  maxtime,
FileReader index_page
[inline]
 

Definition at line 52 of file m_httpd.cpp.

References HTTP_LISTEN, and InternalState.

Referenced by OnIncomingConnection().

HttpServerSocket::HttpServerSocket InspIRCd SI,
int  newfd,
char *  ip,
FileReader ind
[inline]
 

Definition at line 57 of file m_httpd.cpp.

References HTTP_SERVE_WAIT_REQUEST, and InternalState.

HttpServerSocket::~HttpServerSocket  )  [inline]
 

Definition at line 67 of file m_httpd.cpp.


Member Function Documentation

void HttpServerSocket::CheckRequestBuffer  )  [inline]
 

Definition at line 246 of file m_httpd.cpp.

References HTTPHeaders::GetHeader(), headers, HTTP_SERVE_RECV_POSTDATA, http_version, InternalState, HTTPHeaders::IsSet(), postdata, postsize, reqbuffer, request_type, SendHTTPError(), ServeData(), HTTPHeaders::SetHeader(), SetWrite(), and uri.

Referenced by OnDataReady().

FileReader* HttpServerSocket::GetIndex  )  [inline]
 

Definition at line 62 of file m_httpd.cpp.

References index.

virtual void HttpServerSocket::OnClose  )  [inline, virtual]
 

Whenever close() is called, OnClose() will be called first.

Please note that this means OnClose will be called alongside OnError(), OnTimeout(), and Close(), and also when cancelling a listening socket by calling the destructor indirectly.

Reimplemented from BufferedSocket.

Definition at line 80 of file m_httpd.cpp.

virtual bool HttpServerSocket::OnDataReady  )  [inline, virtual]
 

When there is data waiting to be read on a socket, the OnDataReady() method is called.

Within this method, you *MUST* call the Read() method to read any pending data. At its lowest level, this event is signalled by the core via the socket engine. If you return false from this function, the core removes your socket from its list and erases it from the socket engine, then calls BufferedSocket::Close() and deletes it.

Returns:
false to close the socket

Reimplemented from BufferedSocket.

Definition at line 214 of file m_httpd.cpp.

References CheckRequestBuffer(), DEBUG, HTTP_SERVE_RECV_POSTDATA, HTTP_SERVE_WAIT_REQUEST, BufferedSocket::Instance, InternalState, LogManager::Log(), InspIRCd::Logs, postdata, postsize, BufferedSocket::Read(), reqbuffer, and ServeData().

virtual int HttpServerSocket::OnIncomingConnection int  newsock,
char *  ip
[inline, virtual]
 

If your socket is a listening socket, when a new connection comes in on the socket this method will be called.

Given the new file descriptor in the parameters, and the IP, it is recommended you copy them to a new instance of your socket class, e.g.:

MySocket* newsocket = new MySocket(newfd,ip);

Once you have done this, you can then associate the new socket with the core using Server::AddSocket().

Reimplemented from BufferedSocket.

Definition at line 71 of file m_httpd.cpp.

References HTTP_LISTEN, HttpServerSocket(), index, and InternalState.

bool HttpServerSocket::OnWriteReady  )  [inline, virtual]
 

When it is ok to write to the socket, and a write event was requested, this method is triggered.

Within this method you should call write() or send() etc, to send data to the other end of the socket. Further write events will not be triggered unless you call WantWrite().

Returns:
false to close the socket

Reimplemented from BufferedSocket.

Definition at line 360 of file m_httpd.cpp.

References DEBUG, BufferedSocket::Instance, LogManager::Log(), and InspIRCd::Logs.

void HttpServerSocket::Page std::stringstream *  n,
int  response,
HTTPHeaders hheaders
[inline]
 

Definition at line 366 of file m_httpd.cpp.

References BufferedSocket::FlushWriteBuffer(), SendHeaders(), SetWrite(), and BufferedSocket::Write().

Referenced by ModuleHttpServer::OnRequest().

std::string HttpServerSocket::Response int  response  )  [inline]
 

Definition at line 84 of file m_httpd.cpp.

Referenced by SendHeaders(), and SendHTTPError().

void HttpServerSocket::SendHeaders unsigned long  size,
int  response,
HTTPHeaders rheaders
[inline]
 

Definition at line 186 of file m_httpd.cpp.

References ConvToStr(), HTTPHeaders::CreateHeader(), HTTPHeaders::GetFormattedHeaders(), http_version, BufferedSocket::Instance, HTTPHeaders::RemoveHeader(), Response(), HTTPHeaders::SetHeader(), InspIRCd::Time(), and BufferedSocket::Write().

Referenced by Page(), SendHTTPError(), and ServeData().

void HttpServerSocket::SendHTTPError int  response  )  [inline]
 

Definition at line 175 of file m_httpd.cpp.

References ConvToStr(), BufferedSocket::FlushWriteBuffer(), Response(), SendHeaders(), and BufferedSocket::Write().

Referenced by CheckRequestBuffer(), and ServeData().

void HttpServerSocket::ServeData  )  [inline]
 

Definition at line 328 of file m_httpd.cpp.

References claimed, FileReader::Contents(), FileReader::ContentSize(), BufferedSocket::FlushWriteBuffer(), headers, HTTP_SERVE_SEND_DATA, index, InternalState, postdata, request_type, Event::Send(), SendHeaders(), SendHTTPError(), SetWrite(), uri, and BufferedSocket::Write().

Referenced by CheckRequestBuffer(), and OnDataReady().

void HttpServerSocket::SetWrite  )  [inline]
 

Definition at line 374 of file m_httpd.cpp.

References DEBUG, BufferedSocket::Instance, LogManager::Log(), InspIRCd::Logs, InspIRCd::SE, BufferedSocket::WaitingForWriteEvent, and SocketEngine::WantWrite().

Referenced by CheckRequestBuffer(), Page(), and ServeData().


Member Data Documentation

HTTPHeaders HttpServerSocket::headers [private]
 

Definition at line 42 of file m_httpd.cpp.

Referenced by CheckRequestBuffer(), and ServeData().

std::string HttpServerSocket::http_version [private]
 

Definition at line 48 of file m_httpd.cpp.

Referenced by CheckRequestBuffer(), and SendHeaders().

FileReader* HttpServerSocket::index [private]
 

Definition at line 39 of file m_httpd.cpp.

Referenced by GetIndex(), OnIncomingConnection(), and ServeData().

HttpState HttpServerSocket::InternalState [private]
 

Definition at line 40 of file m_httpd.cpp.

Referenced by CheckRequestBuffer(), HttpServerSocket(), OnDataReady(), OnIncomingConnection(), and ServeData().

std::string HttpServerSocket::postdata [private]
 

Definition at line 44 of file m_httpd.cpp.

Referenced by CheckRequestBuffer(), OnDataReady(), and ServeData().

unsigned int HttpServerSocket::postsize [private]
 

Definition at line 45 of file m_httpd.cpp.

Referenced by CheckRequestBuffer(), and OnDataReady().

std::string HttpServerSocket::reqbuffer [private]
 

Definition at line 43 of file m_httpd.cpp.

Referenced by CheckRequestBuffer(), and OnDataReady().

std::string HttpServerSocket::request_type [private]
 

Definition at line 46 of file m_httpd.cpp.

Referenced by CheckRequestBuffer(), and ServeData().

std::string HttpServerSocket::uri [private]
 

Definition at line 47 of file m_httpd.cpp.

Referenced by CheckRequestBuffer(), and ServeData().


The documentation for this class was generated from the following file: