summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-10 21:23:21 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-10 21:23:21 +0000
commit184b6220255ec89c221bff152a62450f1a137340 (patch)
tree42e093e301b7c376623d2c2286f70a7540b9c25a
parent02d9fc3279bf5b09256f535d9c2c873526a619fd (diff)
Try to make this serve some static content
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4308 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/modules.h116
-rw-r--r--src/modules/m_http.cpp73
2 files changed, 123 insertions, 66 deletions
diff --git a/include/modules.h b/include/modules.h
index 3aab093e5..e326f6d97 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -3,13 +3,13 @@
* +------------------------------------+
*
* InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- * E-mail:
- * <brain@chatspike.net>
- * <Craig@chatspike.net>
+ * E-mail:
+ * <brain@chatspike.net>
+ * <Craig@chatspike.net>
*
* Written by Craig Edwards, Craig McLure, and others.
* This program is free but copyrighted software; see
- * the file COPYING for details.
+ * the file COPYING for details.
*
* ---------------------------------------------------
*/
@@ -461,15 +461,15 @@ class Module : public Extensible
virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname);
/** Called whenever a user is about to be kicked.
- * Returning a value of 1 from this function stops the process immediately, causing no
- * output to be sent to the user by the core. If you do this you must produce your own numerics,
- * notices etc.
+ * Returning a value of 1 from this function stops the process immediately, causing no
+ * output to be sent to the user by the core. If you do this you must produce your own numerics,
+ * notices etc.
* @param source The user issuing the kick
* @param user The user being kicked
* @param chan The channel the user is being kicked from
* @param reason The kick reason
* @return 1 to prevent the kick, 0 to continue normally, -1 to explicitly allow the kick regardless of normal operation
- */
+ */
virtual int OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason);
/** Called whenever a user is kicked.
@@ -768,72 +768,72 @@ class Module : public Extensible
/** Called whenever a zline is added by a local user.
* This method is triggered after the line is added.
- * @param duration The duration of the line in seconds
- * @param source The sender of the line
- * @param reason The reason text to be displayed
- * @param ipmask The hostmask to add
+ * @param duration The duration of the line in seconds
+ * @param source The sender of the line
+ * @param reason The reason text to be displayed
+ * @param ipmask The hostmask to add
*/
virtual void OnAddZLine(long duration, userrec* source, const std::string &reason, const std::string &ipmask);
/** Called whenever a kline is added by a local user.
* This method is triggered after the line is added.
- * @param duration The duration of the line in seconds
- * @param source The sender of the line
- * @param reason The reason text to be displayed
- * @param hostmask The hostmask to add
+ * @param duration The duration of the line in seconds
+ * @param source The sender of the line
+ * @param reason The reason text to be displayed
+ * @param hostmask The hostmask to add
*/
virtual void OnAddKLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask);
/** Called whenever a qline is added by a local user.
* This method is triggered after the line is added.
- * @param duration The duration of the line in seconds
- * @param source The sender of the line
- * @param reason The reason text to be displayed
- * @param nickmask The hostmask to add
+ * @param duration The duration of the line in seconds
+ * @param source The sender of the line
+ * @param reason The reason text to be displayed
+ * @param nickmask The hostmask to add
*/
virtual void OnAddQLine(long duration, userrec* source, const std::string &reason, const std::string &nickmask);
/** Called whenever a eline is added by a local user.
* This method is triggered after the line is added.
- * @param duration The duration of the line in seconds
- * @param source The sender of the line
- * @param reason The reason text to be displayed
- * @param hostmask The hostmask to add
+ * @param duration The duration of the line in seconds
+ * @param source The sender of the line
+ * @param reason The reason text to be displayed
+ * @param hostmask The hostmask to add
*/
virtual void OnAddELine(long duration, userrec* source, const std::string &reason, const std::string &hostmask);
/** Called whenever a gline is deleted.
* This method is triggered after the line is deleted.
- * @param source The user removing the line
- * @param hostmask The hostmask to delete
+ * @param source The user removing the line
+ * @param hostmask The hostmask to delete
*/
virtual void OnDelGLine(userrec* source, const std::string &hostmask);
/** Called whenever a zline is deleted.
* This method is triggered after the line is deleted.
- * @param source The user removing the line
- * @param hostmask The hostmask to delete
+ * @param source The user removing the line
+ * @param hostmask The hostmask to delete
*/
virtual void OnDelZLine(userrec* source, const std::string &ipmask);
/** Called whenever a kline is deleted.
* This method is triggered after the line is deleted.
- * @param source The user removing the line
- * @param hostmask The hostmask to delete
+ * @param source The user removing the line
+ * @param hostmask The hostmask to delete
*/
virtual void OnDelKLine(userrec* source, const std::string &hostmask);
/** Called whenever a qline is deleted.
* This method is triggered after the line is deleted.
- * @param source The user removing the line
- * @param hostmask The hostmask to delete
+ * @param source The user removing the line
+ * @param hostmask The hostmask to delete
*/
virtual void OnDelQLine(userrec* source, const std::string &nickmask);
/** Called whenever a eline is deleted.
* This method is triggered after the line is deleted.
- * @param source The user removing the line
- * @param hostmask The hostmask to delete
+ * @param source The user removing the line
+ * @param hostmask The hostmask to delete
*/
virtual void OnDelELine(userrec* source, const std::string &hostmask);
@@ -850,13 +850,13 @@ class Module : public Extensible
/** Called after any nickchange, local or remote. This can be used to track users after nickchanges
* have been applied. Please note that although you can see remote nickchanges through this function, you should
- * NOT make any changes to the userrec if the user is a remote user as this may cause a desnyc.
- * check user->server before taking any action (including returning nonzero from the method).
+ * NOT make any changes to the userrec if the user is a remote user as this may cause a desnyc.
+ * check user->server before taking any action (including returning nonzero from the method).
* Because this method is called after the nickchange is taken place, no return values are possible
* to indicate forbidding of the nick change. Use OnUserPreNick for this.
* @param user The user changing their nick
* @param oldnick The old nickname of the user before the nickchange
- */
+ */
virtual void OnUserPostNick(userrec* user, const std::string &oldnick);
/** Called before an action which requires a channel privilage check.
@@ -929,17 +929,17 @@ class Module : public Extensible
virtual void OnLoadModule(Module* mod,const std::string &name);
/** Called whenever a module is unloaded.
- * mod will contain a pointer to the module, and string will contain its name,
- * for example m_widgets.so. This function is primary for dependency checking,
- * your module may decide to enable some extra features if it sees that you have
- * for example loaded "m_killwidgets.so" with "m_makewidgets.so". It is highly
- * recommended that modules do *NOT* bail if they cannot satisfy dependencies,
- * but instead operate under reduced functionality, unless the dependency is
- * absolutely neccessary (e.g. a module that extends the features of another
- * module).
+ * mod will contain a pointer to the module, and string will contain its name,
+ * for example m_widgets.so. This function is primary for dependency checking,
+ * your module may decide to enable some extra features if it sees that you have
+ * for example loaded "m_killwidgets.so" with "m_makewidgets.so". It is highly
+ * recommended that modules do *NOT* bail if they cannot satisfy dependencies,
+ * but instead operate under reduced functionality, unless the dependency is
+ * absolutely neccessary (e.g. a module that extends the features of another
+ * module).
* @param mod Pointer to the module being unloaded (still valid)
* @param name The filename of the module being unloaded
- */
+ */
virtual void OnUnloadModule(Module* mod,const std::string &name);
/** Called once every five seconds for background processing.
@@ -1015,34 +1015,34 @@ class Module : public Extensible
virtual int OnCheckInvite(userrec* user, chanrec* chan);
/** Called whenever a user joins a channel, to determine if key checks should go ahead or not.
- * This method will always be called for each join, wether or not the channel is actually +k, and
- * determines the outcome of an if statement around the whole section of key checking code.
+ * This method will always be called for each join, wether or not the channel is actually +k, and
+ * determines the outcome of an if statement around the whole section of key checking code.
* if the user specified no key, the keygiven string will be a valid but empty value.
- * return 1 to explicitly allow the join to go ahead or 0 to ignore the event.
+ * return 1 to explicitly allow the join to go ahead or 0 to ignore the event.
* @param user The user joining the channel
* @param chan The channel being joined
* @return 1 to explicitly allow the join, 0 to proceed as normal
- */
+ */
virtual int OnCheckKey(userrec* user, chanrec* chan, const std::string &keygiven);
/** Called whenever a user joins a channel, to determine if channel limit checks should go ahead or not.
- * This method will always be called for each join, wether or not the channel is actually +l, and
- * determines the outcome of an if statement around the whole section of channel limit checking code.
- * return 1 to explicitly allow the join to go ahead or 0 to ignore the event.
+ * This method will always be called for each join, wether or not the channel is actually +l, and
+ * determines the outcome of an if statement around the whole section of channel limit checking code.
+ * return 1 to explicitly allow the join to go ahead or 0 to ignore the event.
* @param user The user joining the channel
* @param chan The channel being joined
* @return 1 to explicitly allow the join, 0 to proceed as normal
- */
+ */
virtual int OnCheckLimit(userrec* user, chanrec* chan);
/** Called whenever a user joins a channel, to determine if banlist checks should go ahead or not.
- * This method will always be called for each join, wether or not the user actually matches a channel ban, and
- * determines the outcome of an if statement around the whole section of ban checking code.
- * return 1 to explicitly allow the join to go ahead or 0 to ignore the event.
+ * This method will always be called for each join, wether or not the user actually matches a channel ban, and
+ * determines the outcome of an if statement around the whole section of ban checking code.
+ * return 1 to explicitly allow the join to go ahead or 0 to ignore the event.
* @param user The user joining the channel
* @param chan The channel being joined
* @return 1 to explicitly allow the join, 0 to proceed as normal
- */
+ */
virtual int OnCheckBan(userrec* user, chanrec* chan);
/** Called on all /STATS commands
diff --git a/src/modules/m_http.cpp b/src/modules/m_http.cpp
index b4f77903a..59293e7a9 100644
--- a/src/modules/m_http.cpp
+++ b/src/modules/m_http.cpp
@@ -21,42 +21,100 @@ using namespace std;
#include "channels.h"
#include "modules.h"
-/* $ModDesc: Povides a proof-of-concept test /WOOT command */
+/* $ModDesc: Provides HTTP serving facilities to modules */
static Server *Srv;
enum HttpState
{
HTTP_LISTEN = 0,
- HTTP_SERVE = 1
+ HTTP_SERVE_WAIT_REQUEST = 1,
+ HTTP_SERVE_SEND_DATA = 2
};
class HttpSocket : public InspSocket
{
+ FileReader* index;
+ HttpState InternalState;
+ std::stringstream headers;
+
public:
- HttpSocket(std::string host, int port, bool listening, unsigned long maxtime) : InspSocket(host, port, listening, maxtime)
+ HttpSocket(std::string host, int port, bool listening, unsigned long maxtime, FileReader* index_page) : InspSocket(host, port, listening, maxtime), index(index_page)
{
+ InternalState = HTTP_LISTEN;
}
HttpSocket(int newfd, char* ip) : InspSocket(newfd, ip)
{
+ InternalState = HTTP_SERVE_WAIT_REQUEST;
+ }
+
+ virtual int OnIncomingConnection(int newsock, char* ip)
+ {
+ if (InternalState == HTTP_LISTEN)
+ {
+ HttpSocket* s = new HttpSocket(newsock, ip);
+ Srv->AddSocket(s);
+ }
+ }
+
+ virtual void OnClose()
+ {
+ }
+
+ virtual bool OnDataReady()
+ {
+ char* data = this->Read();
+ /* Check that the data read is a valid pointer and it has some content */
+ if (data && *data)
+ {
+ headers << data;
+
+ if (headers.str().find("\r\n\r\n"))
+ {
+ /* Headers are complete */
+ InternalState = HTTP_SERVE_SEND_DATA;
+ this->Write("<HTML><H1>COWS.</H1></HTML>");
+ }
+ }
}
};
class ModuleHttp : public Module
{
+ int port;
+ std::string host;
+ std::string bindip;
+ std::string indexfile;
+
+ FileReader index;
+
+ HttpSocket* http;
+
public:
void ReadConfig()
{
ConfigReader c;
+ this->host = c.ReadValue("http", "host", 0);
+ this->bindip = c.ReadValue("http", "ip", 0);
+ this->port = c.ReadInteger("http", "port", 0, true);
+ this->indexfile = c.ReadValue("http", "index", 0);
+
+ index.LoadFile(this->indexfile);
+ }
+
+ void CreateListener()
+ {
+ http = new HttpSocket(this->host, this->port, true, 0, &index);
+ Srv->AddSocket(http);
}
- ModuleHttp(Server* Me)
- : Module::Module(Me)
+ ModuleHttp(Server* Me) : Module::Module(Me)
{
ReadConfig();
+ CreateListener();
}
void Implements(char* List)
@@ -66,8 +124,9 @@ class ModuleHttp : public Module
virtual ~ModuleHttp()
{
+ Srv->DelSocket(http);
}
-
+
virtual Version GetVersion()
{
return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
@@ -90,7 +149,6 @@ class ModuleHttpFactory : public ModuleFactory
{
return new ModuleHttp(Me);
}
-
};
@@ -98,4 +156,3 @@ extern "C" void * init_module( void )
{
return new ModuleHttpFactory;
}
-