INET Framework for OMNeT++/OMNEST
inet::httptools::HttpServer Class Reference

HttpServerDirect module. More...

#include <HttpServer.h>

Inheritance diagram for inet::httptools::HttpServer:
inet::httptools::HttpServerBase inet::TCPSocket::CallbackInterface inet::httptools::HttpNodeBase inet::ILifecycle inet::httptools::HttpServerEvilA inet::httptools::HttpServerEvilB

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void finish () override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void socketEstablished (int connId, void *yourPtr) override
 
virtual void socketDataArrived (int connId, void *yourPtr, cPacket *msg, bool urgent) override
 
virtual void socketPeerClosed (int connId, void *yourPtr) override
 
virtual void socketClosed (int connId, void *yourPtr) override
 
virtual void socketFailure (int connId, void *yourPtr, int code) override
 
- Protected Member Functions inherited from inet::httptools::HttpServerBase
virtual void refreshDisplay () const override
 
HttpReplyMessagegenerateDocument (HttpRequestMessage *request, const char *resource, int size=0)
 
HttpReplyMessagegenerateResourceMessage (HttpRequestMessage *request, std::string resource, HttpContentType category)
 
HttpReplyMessagehandleGetRequest (HttpRequestMessage *request, std::string resource)
 
HttpReplyMessagegenerateErrorReply (HttpRequestMessage *request, int code)
 
virtual std::string generateBody ()
 
cPacket * handleReceivedMessage (cMessage *msg)
 
void registerWithController ()
 
void readSiteDefinition (std::string file)
 
std::string readHtmlBodyFile (std::string file, std::string path)
 
- Protected Member Functions inherited from inet::httptools::HttpNodeBase
void sendDirectToModule (HttpNodeBase *receiver, cPacket *packet, simtime_t constdelay=0.0, rdObject *rd=nullptr)
 
double transmissionDelay (cPacket *packet)
 
void logRequest (const HttpRequestMessage *httpRequest)
 
void logResponse (const HttpReplyMessage *httpResponse)
 
void logEntry (std::string line)
 
std::string formatHttpRequestShort (const HttpRequestMessage *httpRequest)
 
std::string formatHttpResponseShort (const HttpReplyMessage *httpResponse)
 
std::string formatHttpRequestLong (const HttpRequestMessage *httpRequest)
 
std::string formatHttpResponseLong (const HttpReplyMessage *httpResponse)
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 

Protected Attributes

TCPSocket listensocket
 
TCPSocketMap sockCollection
 
unsigned long numBroken = 0
 
unsigned long socketsOpened = 0
 
- Protected Attributes inherited from inet::httptools::HttpServerBase
std::string hostName
 
int port = -1
 
bool scriptedMode = false
 
std::map< std::string, HtmlPageDatahtmlPages
 
std::map< std::string, unsigned int > resources
 
simtime_t activationTime
 
long htmlDocsServed = 0
 
long imgResourcesServed = 0
 
long textResourcesServed = 0
 
long badRequests = 0
 
rdObjectrdReplyDelay = nullptr
 The processing delay of the server. More...
 
rdObjectrdHtmlPageSize = nullptr
 The HTML page size distribution for the site. More...
 
rdObjectrdTextResourceSize = nullptr
 The text resource size distribution for the site. More...
 
rdObjectrdImageResourceSize = nullptr
 The image resource size distribution for the site. More...
 
rdObjectrdNumResources = nullptr
 Number of resources per HTML page. More...
 
rdObjectrdTextImageResourceRatio = nullptr
 The ratio of text resources to images referenced in HTML pages. More...
 
rdObjectrdErrorMsgSize = nullptr
 The size of error messages. More...
 
- Protected Attributes inherited from inet::httptools::HttpNodeBase
unsigned long linkSpeed = 0
 
int httpProtocol = 0
 
std::string logFileName
 
bool enableLogging = true
 
LOG_FORMAT outputFormat = lf_short
 
bool m_bDisplayMessage = true
 
bool m_bDisplayResponseContent = true
 
cModule * host = nullptr
 

Additional Inherited Members

- Public Member Functions inherited from inet::httptools::HttpServerBase
 HttpServerBase ()
 
 ~HttpServerBase ()
 
const std::string & getHostName ()
 
- Public Member Functions inherited from inet::httptools::HttpNodeBase
 HttpNodeBase ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 
- Public Member Functions inherited from inet::TCPSocket::CallbackInterface
virtual ~CallbackInterface ()
 
virtual void socketStatusArrived (int connId, void *yourPtr, TCPStatusInfo *status)
 
virtual void socketDeleted (int connId, void *yourPtr)
 

Detailed Description

HttpServerDirect module.

This module implements a flexible Web server. It is part of the HttpTools project and should be used in conjunction with a number of clients running the HttpBrowserDirect.

See also
HttpBrowserDirect
Author
Kristjan V. Jonsson

Member Function Documentation

void inet::httptools::HttpServer::finish ( )
overrideprotectedvirtual

Reimplemented from inet::httptools::HttpServerBase.

52 {
54 
55  EV_INFO << "Sockets opened: " << socketsOpened << endl;
56  EV_INFO << "Broken connections: " << numBroken << endl;
57 
58  recordScalar("sock.opened", socketsOpened);
59  recordScalar("sock.broken", numBroken);
60 
61  // Clean up sockets and data structures
63 }
unsigned long numBroken
Definition: HttpServer.h:44
virtual void finish() override
Definition: HttpServerBase.cc:164
TCPSocketMap sockCollection
Definition: HttpServer.h:43
void deleteSockets()
Deletes the socket objects.
Definition: TCPSocketMap.cc:50
unsigned long socketsOpened
Definition: HttpServer.h:45
void inet::httptools::HttpServer::handleMessage ( cMessage *  msg)
overrideprotectedvirtual

Implements inet::httptools::HttpServerBase.

66 {
67  if (msg->isSelfMessage()) {
68  // Self messages not used at the moment
69  }
70  else {
71  EV_DEBUG << "Handle inbound message " << msg->getName() << " of kind " << msg->getKind() << endl;
72  TCPSocket *socket = sockCollection.findSocketFor(msg);
73  if (!socket) {
74  EV_DEBUG << "No socket found for the message. Create a new one" << endl;
75  // new connection -- create new socket object and server process
76  socket = new TCPSocket(msg);
77  socket->setOutputGate(gate("tcpOut"));
78  socket->setDataTransferMode(TCP_TRANSFER_OBJECT);
79  socket->setCallbackObject(this, socket);
80  sockCollection.addSocket(socket);
81  }
82  EV_DEBUG << "Process the message " << msg->getName() << endl;
83  socket->processMessage(msg);
84  }
85 }
TCPSocketMap sockCollection
Definition: HttpServer.h:43
void addSocket(TCPSocket *socket)
Registers the given socket.
Definition: TCPSocketMap.cc:36
Definition: TCPCommand_m.h:256
TCPSocket * findSocketFor(cMessage *msg)
Finds the socket (by connId) for the given message.
Definition: TCPSocketMap.cc:24
void inet::httptools::HttpServer::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::httptools::HttpServerBase.

Reimplemented in inet::httptools::HttpServerEvilA, and inet::httptools::HttpServerEvilB.

Referenced by inet::httptools::HttpServerEvilA::initialize(), and inet::httptools::HttpServerEvilB::initialize().

27 {
29 
30  if (stage == INITSTAGE_LOCAL) {
31  numBroken = 0;
32  socketsOpened = 0;
33 
34  WATCH(numBroken);
35  WATCH(socketsOpened);
36  }
37  else if (stage == INITSTAGE_APPLICATION_LAYER) {
38  EV_DEBUG << "Initializing server component (sockets version)" << endl;
39 
40  int port = par("port");
41 
42  TCPSocket listensocket;
43  listensocket.setOutputGate(gate("tcpOut"));
44  listensocket.setDataTransferMode(TCP_TRANSFER_OBJECT);
45  listensocket.bind(port);
46  listensocket.setCallbackObject(this);
47  listensocket.listen();
48  }
49 }
unsigned long numBroken
Definition: HttpServer.h:44
int port
Definition: HttpServerBase.h:64
virtual void initialize(int stage) override
Definition: HttpServerBase.cc:42
Local initializations.
Definition: InitStages.h:35
Definition: TCPCommand_m.h:256
void setOutputGate(cGate *toTcp)
Sets the gate on which to send to TCP.
Definition: TCPSocket.h:228
unsigned long socketsOpened
Definition: HttpServer.h:45
TCPSocket listensocket
Definition: HttpServer.h:42
Initialization of applications.
Definition: InitStages.h:106
virtual int inet::httptools::HttpServer::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::httptools::HttpServerBase.

Reimplemented in inet::httptools::HttpServerEvilA, and inet::httptools::HttpServerEvilB.

48 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::httptools::HttpServer::socketClosed ( int  connId,
void *  yourPtr 
)
overrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

128 {
129  EV_INFO << "connection closed. Connection id " << connId << endl;
130 
131  if (yourPtr == nullptr) {
132  EV_ERROR << "Socket establish failure. Null pointer" << endl;
133  return;
134  }
135  // Cleanup
136  TCPSocket *socket = (TCPSocket *)yourPtr;
138  delete socket;
139 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
TCPSocket * removeSocket(TCPSocket *socket)
Removes the given socket from the data structure.
Definition: TCPSocketMap.cc:42
TCPSocketMap sockCollection
Definition: HttpServer.h:43
void inet::httptools::HttpServer::socketDataArrived ( int  connId,
void *  yourPtr,
cPacket *  msg,
bool  urgent 
)
overrideprotectedvirtual

Implements inet::TCPSocket::CallbackInterface.

94 {
95  if (yourPtr == nullptr) {
96  EV_ERROR << "Socket establish failure. Null pointer" << endl;
97  return;
98  }
99  TCPSocket *socket = (TCPSocket *)yourPtr;
100 
101  // Should be a HttpReplyMessage
102  EV_DEBUG << "Socket data arrived on connection " << connId << ". Message=" << msg->getName() << ", kind=" << msg->getKind() << endl;
103 
104  // call the message handler to process the message.
105  cMessage *reply = handleReceivedMessage(msg);
106  if (reply != nullptr) {
107  socket->send(reply); // Send to socket if the reply is non-zero.
108  }
109  delete msg; // Delete the received message here. Must not be deleted in the handler!
110 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
cPacket * handleReceivedMessage(cMessage *msg)
Definition: HttpServerBase.cc:200
void inet::httptools::HttpServer::socketEstablished ( int  connId,
void *  yourPtr 
)
overrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

88 {
89  EV_INFO << "connected socket with id=" << connId << endl;
90  socketsOpened++;
91 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
unsigned long socketsOpened
Definition: HttpServer.h:45
void inet::httptools::HttpServer::socketFailure ( int  connId,
void *  yourPtr,
int  code 
)
overrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

142 {
143  EV_WARN << "connection broken. Connection id " << connId << endl;
144  numBroken++;
145 
146  EV_INFO << "connection closed. Connection id " << connId << endl;
147 
148  if (yourPtr == nullptr) {
149  EV_ERROR << "Socket establish failure. Null pointer" << endl;
150  return;
151  }
152  TCPSocket *socket = (TCPSocket *)yourPtr;
153 
154  if (code == TCP_I_CONNECTION_RESET)
155  EV_WARN << "Connection reset!\n";
156  else if (code == TCP_I_CONNECTION_REFUSED)
157  EV_WARN << "Connection refused!\n";
158 
159  // Cleanup
161  delete socket;
162 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
unsigned long numBroken
Definition: HttpServer.h:44
Definition: TCPCommand_m.h:104
TCPSocket * removeSocket(TCPSocket *socket)
Removes the given socket from the data structure.
Definition: TCPSocketMap.cc:42
TCPSocketMap sockCollection
Definition: HttpServer.h:43
Definition: TCPCommand_m.h:103
void inet::httptools::HttpServer::socketPeerClosed ( int  connId,
void *  yourPtr 
)
overrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

113 {
114  if (yourPtr == nullptr) {
115  EV_ERROR << "Socket establish failure. Null pointer" << endl;
116  return;
117  }
118  TCPSocket *socket = (TCPSocket *)yourPtr;
119 
120  // close the connection (if not already closed)
121  if (socket->getState() == TCPSocket::PEER_CLOSED) {
122  EV_INFO << "remote TCP closed, closing here as well. Connection id is " << connId << endl;
123  socket->close(); // Call the close method to properly dispose of the socket.
124  }
125 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
Definition: TCPSocket.h:148

Member Data Documentation

TCPSocket inet::httptools::HttpServer::listensocket
protected

Referenced by initialize().

unsigned long inet::httptools::HttpServer::numBroken = 0
protected

Referenced by finish(), initialize(), and socketFailure().

TCPSocketMap inet::httptools::HttpServer::sockCollection
protected
unsigned long inet::httptools::HttpServer::socketsOpened = 0
protected

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