summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-11-26 15:47:19 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-11-26 15:47:19 +0000
commit17b5f19bf1476cb22ccb409145600dac7209f823 (patch)
tree54ddfc6c923517600539a25dbc842fae11a48e20
parent0f907d2b8ba69d80d0f605ecb707efcf1426204a (diff)
Added start of spanning tree system TEST MODULE, tested outbound connections
Outbound connections function OK. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1956 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/modules.h4
-rw-r--r--src/inspircd.cpp1
-rw-r--r--src/modules.cpp12
-rw-r--r--src/modules/m_spanningtree.cpp162
-rw-r--r--src/socket.cpp3
5 files changed, 182 insertions, 0 deletions
diff --git a/include/modules.h b/include/modules.h
index 9c504e62b..a4173060d 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -1099,6 +1099,10 @@ class Server : public classbase
/** Adds a class derived from InspSocket to the server's socket engine.
*/
virtual void AddSocket(InspSocket* sock);
+
+ /** Deletes a class derived from InspSocket from the server's socket engine.
+ */
+ virtual void DelSocket(InspSocket* sock);
};
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 50536099d..b9b9eb33e 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -2342,6 +2342,7 @@ int InspIRCd(char** argv, int argc)
InspSocket* s = (InspSocket*)*a;
if (!s->Poll())
{
+ s->Close();
delete s;
module_sockets.erase(a);
break;
diff --git a/src/modules.cpp b/src/modules.cpp
index 0c2f36f0d..cb0f1e634 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -377,6 +377,18 @@ void Server::AddSocket(InspSocket* sock)
module_sockets.push_back(sock);
}
+void Server::DelSocket(InspSocket* sock)
+{
+ for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
+ {
+ if (*a == sock)
+ {
+ module_sockets.erase(a);
+ return;
+ }
+ }
+}
+
void Server::SendOpers(std::string s)
{
WriteOpers("%s",s.c_str());
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
new file mode 100644
index 000000000..95d4d4398
--- /dev/null
+++ b/src/modules/m_spanningtree.cpp
@@ -0,0 +1,162 @@
+/* +------------------------------------+
+ * | Inspire Internet Relay Chat Daemon |
+ * +------------------------------------+
+ *
+ * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ * 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.
+ *
+ * ---------------------------------------------------
+ */
+
+using namespace std;
+
+#include <stdio.h>
+#include <vector>
+#include "users.h"
+#include "channels.h"
+#include "modules.h"
+#include "socket.h"
+
+/* $ModDesc: Povides a spanning tree server link protocol */
+
+Server *Srv;
+
+class TreeSocket : public InspSocket
+{
+ std::string myhost;
+
+ public:
+
+ TreeSocket(std::string host, int port, bool listening, unsigned long maxtime)
+ : InspSocket(host, port, listening, maxtime)
+ {
+ Srv->Log(DEBUG,"Create new");
+ myhost = host;
+ }
+
+ virtual bool OnConnected()
+ {
+ Srv->Log(DEBUG,"Connected");
+ Srv->SendToModeMask("o",WM_AND,"*** CONNECTED!");
+ this->Write("GET / HTTP/1.1\r\nHost: " + myhost + "\r\nConnection: Close\r\n\r\n");
+ Srv->SendToModeMask("o",WM_AND,"*** DATA WRITTEN ***");
+ Srv->Log(DEBUG,"Wrote");
+ return true;
+ }
+
+ virtual void OnError(InspSocketError e)
+ {
+ char x[1024];
+ Srv->Log(DEBUG,"Error");
+ sprintf(x,"*** ERROR %d",(int)e);
+ Srv->SendToModeMask("o",WM_AND,x);
+ }
+
+ virtual int OnDisconnect()
+ {
+ Srv->Log(DEBUG,"Disconnect");
+ Srv->SendToModeMask("o",WM_AND,"*** DISCONNECTED!");
+ return true;
+ }
+
+ virtual bool OnDataReady()
+ {
+ Srv->Log(DEBUG,"Data");
+ Srv->SendToModeMask("o",WM_AND,"*** DATA ***");
+ char* data = this->Read();
+ if (data)
+ {
+ Srv->SendToModeMask("o",WM_AND,data);
+ }
+ return (data != NULL);
+ }
+
+ virtual void OnTimeout()
+ {
+ Srv->Log(DEBUG,"Timeout");
+ Srv->SendToModeMask("o",WM_AND,"*** TIMED OUT ***");
+ }
+
+ virtual void OnClose()
+ {
+ Srv->SendToModeMask("o",WM_AND,"*** CLOSED ***");
+ }
+
+ virtual int OnIncomingConnection()
+ {
+ Srv->SendToModeMask("o",WM_AND,"*** INCOMING ***");
+ return true;
+ }
+};
+
+void handle_connecttest(char **parameters, int pcnt, userrec *user)
+{
+ // create a new class of type TreeSocket.
+ std::string a = parameters[0];
+ TreeSocket* s = new TreeSocket(a,80,false,10);
+ Srv->Log(DEBUG,"Create TreeSocket");
+ Srv->AddSocket(s);
+ Srv->Log(DEBUG,"Added socket");
+}
+
+class ModuleSpanningTree : public Module
+{
+ public:
+ ModuleSpanningTree()
+ {
+ Srv = new Server;
+ Srv->AddCommand("CONNECTTEST",handle_connecttest,'o',1,"m_spanningtree.so");
+ Srv->Log(DEBUG,"ModCreate");
+ }
+
+ virtual void OnUserJoin(userrec* user, chanrec* channel)
+ {
+ }
+
+ virtual ~ModuleSpanningTree()
+ {
+ delete Srv;
+ }
+
+ virtual Version GetVersion()
+ {
+ return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
+ }
+
+ virtual void OnUserConnect(userrec* user)
+ {
+ }
+
+};
+
+
+class ModuleSpanningTreeFactory : public ModuleFactory
+{
+ public:
+ ModuleSpanningTreeFactory()
+ {
+ }
+
+ ~ModuleSpanningTreeFactory()
+ {
+ }
+
+ virtual Module * CreateModule()
+ {
+ return new ModuleSpanningTree;
+ }
+
+};
+
+
+extern "C" void * init_module( void )
+{
+ return new ModuleSpanningTreeFactory;
+}
+
diff --git a/src/socket.cpp b/src/socket.cpp
index cb019a3c2..48a58db0b 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -115,6 +115,7 @@ char* InspSocket::Read()
}
else
{
+ log(DEBUG,"EOF or error on socket");
return NULL;
}
}
@@ -166,6 +167,7 @@ bool InspSocket::Poll()
switch (this->state)
{
case I_CONNECTING:
+ this->SetState(I_CONNECTED);
return this->OnConnected();
break;
case I_LISTENING:
@@ -184,6 +186,7 @@ bool InspSocket::Poll()
void InspSocket::SetState(InspSocketState s)
{
+ log(DEBUG,"Socket state change");
this->state = s;
}