]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree.cpp
Converted more stuff to 'Implements' system
[user/henk/code/inspircd.git] / src / modules / m_spanningtree.cpp
index a4b34f689061d50d916236cf078f649cbacea3d2..4487e79a348fb63b20ee06f88226a5028e5ea117 100644 (file)
@@ -73,6 +73,8 @@ using namespace std;
 class ModuleSpanningTree;
 static ModuleSpanningTree* TreeProtocolModule;
 
+extern ServerConfig* Config;
+
 extern std::vector<Module*> modules;
 extern std::vector<ircd_module*> factory;
 extern int MODCOUNT;
@@ -552,6 +554,7 @@ class TreeSocket : public InspSocket
        {
                myhost = host;
                this->LinkState = LISTENER;
+               this->ctx = NULL;
        }
 
        TreeSocket(std::string host, int port, bool listening, unsigned long maxtime, std::string ServerName)
@@ -559,6 +562,7 @@ class TreeSocket : public InspSocket
        {
                myhost = ServerName;
                this->LinkState = CONNECTING;
+               this->ctx = NULL;
        }
 
        /* When a listening socket gives us a new file descriptor,
@@ -569,9 +573,16 @@ class TreeSocket : public InspSocket
                : InspSocket(newfd, ip)
        {
                this->LinkState = WAIT_AUTH_1;
+               this->ctx = NULL;
                this->SendCapabilities();
        }
 
+       ~TreeSocket()
+       {
+               if (ctx)
+                       delete ctx;
+       }
+
        void InitAES(std::string key,std::string SName)
        {
                if (key == "")
@@ -1135,12 +1146,12 @@ class TreeSocket : public InspSocket
                                snprintf(data,MAXBUF,":%s FMODE %s +b %s",Srv->GetServerName().c_str(),c->second->name,b->data);
                                this->WriteLine(data);
                        }
-                       FOREACH_MOD OnSyncChannel(c->second,(Module*)TreeProtocolModule,(void*)this);
+                       FOREACH_MOD(I_OnSyncChannel,OnSyncChannel(c->second,(Module*)TreeProtocolModule,(void*)this));
                        list.clear();
                        c->second->GetExtList(list);
                        for (unsigned int j = 0; j < list.size(); j++)
                        {
-                               FOREACH_MOD OnSyncChannelMetaData(c->second,(Module*)TreeProtocolModule,(void*)this,list[j]);
+                               FOREACH_MOD(I_OnSyncChannelMetaData,OnSyncChannelMetaData(c->second,(Module*)TreeProtocolModule,(void*)this,list[j]));
                        }
                }
        }
@@ -1160,12 +1171,12 @@ class TreeSocket : public InspSocket
                                {
                                        this->WriteLine(":"+std::string(u->second->nick)+" OPERTYPE "+std::string(u->second->oper));
                                }
-                               FOREACH_MOD OnSyncUser(u->second,(Module*)TreeProtocolModule,(void*)this);
+                               FOREACH_MOD(I_OnSyncUser,OnSyncUser(u->second,(Module*)TreeProtocolModule,(void*)this));
                                list.clear();
                                u->second->GetExtList(list);
                                for (unsigned int j = 0; j < list.size(); j++)
                                {
-                                       FOREACH_MOD OnSyncUserMetaData(u->second,(Module*)TreeProtocolModule,(void*)this,list[j]);
+                                       FOREACH_MOD(I_OnSyncUserMetaData,OnSyncUserMetaData(u->second,(Module*)TreeProtocolModule,(void*)this,list[j]));
                                }
                        }
                }
@@ -1229,9 +1240,11 @@ class TreeSocket : public InspSocket
                                {
                                        char out[1024];
                                        char result[1024];
+                                       memset(result,0,1024);
+                                       memset(out,0,1024);
                                        log(DEBUG,"Original string '%s'",ret.c_str());
-                                       /* ERROR is still allowed unencryped */
-                                       if (ret.substr(0,7) != "ERROR :")
+                                       /* ERROR + CAPAB is still allowed unencryped */
+                                       if ((ret.substr(0,7) != "ERROR :") && (ret.substr(0,6) != "CAPAB "))
                                        {
                                                int nbytes = from64tobits(out, ret.c_str(), 1024);
                                                log(DEBUG,"m_spanningtree: decrypt %d bytes",nbytes);
@@ -1256,8 +1269,8 @@ class TreeSocket : public InspSocket
                if (this->ctx)
                {
                        log(DEBUG,"AES context");
-                       char result[1024];
-                       char result64[1024];
+                       char result[10240];
+                       char result64[10240];
                        if (this->keylength)
                        {
                                while (line.length() % this->keylength != 0)
@@ -1266,10 +1279,13 @@ class TreeSocket : public InspSocket
                                        line = line + "\7";
                                }
                        }
-                       ctx->Encrypt(line.c_str(), result, line.length(),0);
+                       unsigned int ll = line.length();
+                       log(DEBUG,"Plaintext line with padding = %d chars",ll);
+                       ctx->Encrypt(line.c_str(), result, ll, 0);
+                       log(DEBUG,"Encrypted.");
                        to64frombits((unsigned char*)result64,
                                        (unsigned char*)result,
-                                       line.length());
+                                       ll);
                        line = result64;
                        log(DEBUG,"Encrypted: %s",line.c_str());
                        //int from64tobits(char *out, const char *in, int maxlen);
@@ -1411,7 +1427,7 @@ class TreeSocket : public InspSocket
                                chanrec* c = Srv->FindChannel(params[0]);
                                if (c)
                                {
-                                       FOREACH_MOD OnDecodeMetaData(TYPE_CHANNEL,c,params[1],params[2]);
+                                       FOREACH_MOD(I_OnDecodeMetaData,OnDecodeMetaData(TYPE_CHANNEL,c,params[1],params[2]));
                                }
                        }
                        else
@@ -1419,7 +1435,7 @@ class TreeSocket : public InspSocket
                                userrec* u = Srv->FindNick(params[0]);
                                if (u)
                                {
-                                       FOREACH_MOD OnDecodeMetaData(TYPE_USER,u,params[1],params[2]);
+                                       FOREACH_MOD(I_OnDecodeMetaData,OnDecodeMetaData(TYPE_USER,u,params[1],params[2]));
                                }
                        }
                }
@@ -2639,7 +2655,7 @@ class ModuleSpanningTree : public Module
        {
                /* If the command doesnt appear to be valid, we dont want to mess with it. */
                if (!validated)
-                       return;
+                       return 0;
 
                if (command == "CONNECT")
                {