diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-21 13:26:31 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-21 13:26:31 +0000 |
commit | e2af2347fc035d702e45f12e772223a8d578410d (patch) | |
tree | bfd80aac2858a9f4faedc316794fc1051dbaa72c /src/modules/m_spanningtree | |
parent | 16fc672b685752007e47aed0fb97bc1ee7443c76 (diff) |
Create StreamSocket for IO hooking implementation
Fixes the SSL SendQ bug
Removes duplicate code between User and BufferedSocket
Simplify SSL module API
Simplify EventHandler API (Readable/Writeable moved to SE)
Add hook for culled objects to invoke callbacks prior to destructor
Replace SocketCull with GlobalCull now that sockets can close themselves
Shorten common case of user read/parse/write path:
User::Write is now zero-copy up to syscall/SSL invocation
User::Read has only two copy/scan passes from read() to ProcessCommand
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11752 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_spanningtree')
43 files changed, 222 insertions, 279 deletions
diff --git a/src/modules/m_spanningtree/addline.cpp b/src/modules/m_spanningtree/addline.cpp index 2f7b5132d..3e6d38070 100644 --- a/src/modules/m_spanningtree/addline.cpp +++ b/src/modules/m_spanningtree/addline.cpp @@ -24,7 +24,7 @@ bool TreeSocket::AddLine(const std::string &prefix, parameterlist ¶ms) { if (params.size() < 6) { - this->ServerInstance->SNO->WriteToSnoMask('d',"%s sent me a malformed ADDLINE of type %s.",prefix.c_str(),params[0].c_str()); + ServerInstance->SNO->WriteToSnoMask('d',"%s sent me a malformed ADDLINE of type %s.",prefix.c_str(),params[0].c_str()); return true; } @@ -43,7 +43,7 @@ bool TreeSocket::AddLine(const std::string &prefix, parameterlist ¶ms) if (!xlf) { - this->ServerInstance->SNO->WriteToSnoMask('d',"%s sent me an unknown ADDLINE type (%s).",setter.c_str(),params[0].c_str()); + ServerInstance->SNO->WriteToSnoMask('d',"%s sent me an unknown ADDLINE type (%s).",setter.c_str(),params[0].c_str()); return true; } @@ -54,7 +54,7 @@ bool TreeSocket::AddLine(const std::string &prefix, parameterlist ¶ms) } catch (ModuleException &e) { - this->ServerInstance->SNO->WriteToSnoMask('d',"Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason()); + ServerInstance->SNO->WriteToSnoMask('d',"Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason()); return true; } xl->SetCreateTime(atoi(params[3].c_str())); @@ -62,12 +62,12 @@ bool TreeSocket::AddLine(const std::string &prefix, parameterlist ¶ms) { if (xl->duration) { - this->ServerInstance->SNO->WriteToSnoMask('X',"%s added %s%s on %s to expire on %s: %s",setter.c_str(),params[0].c_str(),params[0].length() == 1 ? "-line" : "", + ServerInstance->SNO->WriteToSnoMask('X',"%s added %s%s on %s to expire on %s: %s",setter.c_str(),params[0].c_str(),params[0].length() == 1 ? "-line" : "", params[1].c_str(),ServerInstance->TimeString(xl->expiry).c_str(),params[5].c_str()); } else { - this->ServerInstance->SNO->WriteToSnoMask('X',"%s added permanent %s%s on %s: %s",setter.c_str(),params[0].c_str(),params[0].length() == 1 ? "-line" : "", + ServerInstance->SNO->WriteToSnoMask('X',"%s added permanent %s%s on %s: %s",setter.c_str(),params[0].c_str(),params[0].length() == 1 ? "-line" : "", params[1].c_str(),params[5].c_str()); } params[5] = ":" + params[5]; diff --git a/src/modules/m_spanningtree/admin.cpp b/src/modules/m_spanningtree/admin.cpp index 133da928b..e47078c7e 100644 --- a/src/modules/m_spanningtree/admin.cpp +++ b/src/modules/m_spanningtree/admin.cpp @@ -25,30 +25,30 @@ bool TreeSocket::Admin(const std::string &prefix, parameterlist ¶ms) { if (params.size() > 0) { - if (InspIRCd::Match(this->ServerInstance->Config->ServerName, params[0])) + if (InspIRCd::Match(ServerInstance->Config->ServerName, params[0])) { /* It's for our server */ string_list results; - User* source = this->ServerInstance->FindNick(prefix); + User* source = ServerInstance->FindNick(prefix); if (source) { parameterlist par; par.push_back(prefix); par.push_back(""); par[1] = std::string("::")+ServerInstance->Config->ServerName+" 256 "+source->nick+" :Administrative info for "+ServerInstance->Config->ServerName; - Utils->DoOneToOne(this->ServerInstance->Config->GetSID(), "PUSH",par, source->server); + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH",par, source->server); par[1] = std::string("::")+ServerInstance->Config->ServerName+" 257 "+source->nick+" :Name - "+ServerInstance->Config->AdminName; - Utils->DoOneToOne(this->ServerInstance->Config->GetSID(), "PUSH",par, source->server); + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH",par, source->server); par[1] = std::string("::")+ServerInstance->Config->ServerName+" 258 "+source->nick+" :Nickname - "+ServerInstance->Config->AdminNick; - Utils->DoOneToOne(this->ServerInstance->Config->GetSID(), "PUSH",par, source->server); + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH",par, source->server); par[1] = std::string("::")+ServerInstance->Config->ServerName+" 258 "+source->nick+" :E-Mail - "+ServerInstance->Config->AdminEmail; - Utils->DoOneToOne(this->ServerInstance->Config->GetSID(), "PUSH",par, source->server); + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH",par, source->server); } } else { /* Pass it on */ - User* source = this->ServerInstance->FindNick(prefix); + User* source = ServerInstance->FindNick(prefix); if (source) Utils->DoOneToOne(prefix, "ADMIN", params, params[0]); } diff --git a/src/modules/m_spanningtree/away.cpp b/src/modules/m_spanningtree/away.cpp index 2aac26bbd..354266554 100644 --- a/src/modules/m_spanningtree/away.cpp +++ b/src/modules/m_spanningtree/away.cpp @@ -20,7 +20,7 @@ bool TreeSocket::Away(const std::string &prefix, parameterlist ¶ms) { - User* u = this->ServerInstance->FindNick(prefix); + User* u = ServerInstance->FindNick(prefix); if (!u) return true; if (params.size()) diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp index 66d448e55..7953468e4 100644 --- a/src/modules/m_spanningtree/capab.cpp +++ b/src/modules/m_spanningtree/capab.cpp @@ -23,7 +23,7 @@ std::string TreeSocket::MyModules(int filter) { - std::vector<std::string> modlist = this->ServerInstance->Modules->GetAllModuleNames(filter); + std::vector<std::string> modlist = ServerInstance->Modules->GetAllModuleNames(filter); if (filter == VF_COMMON && proto_version != ProtocolVersion) CompatAddModules(modlist); @@ -236,13 +236,13 @@ bool TreeSocket::Capab(const parameterlist ¶ms) } } - if(this->CapKeys.find("PREFIX") != this->CapKeys.end() && this->CapKeys.find("PREFIX")->second != this->ServerInstance->Modes->BuildPrefixes()) + if(this->CapKeys.find("PREFIX") != this->CapKeys.end() && this->CapKeys.find("PREFIX")->second != ServerInstance->Modes->BuildPrefixes()) reason = "One or more of the prefixes on the remote server are invalid on this server."; - if(this->CapKeys.find("CHANMODES") != this->CapKeys.end() && this->CapKeys.find("CHANMODES")->second != this->ServerInstance->Modes->GiveModeList(MASK_CHANNEL)) + if(this->CapKeys.find("CHANMODES") != this->CapKeys.end() && this->CapKeys.find("CHANMODES")->second != ServerInstance->Modes->GiveModeList(MASK_CHANNEL)) reason = "One or more of the channel modes on the remote server are invalid on this server."; - if(this->CapKeys.find("USERMODES") != this->CapKeys.end() && this->CapKeys.find("USERMODES")->second != this->ServerInstance->Modes->GiveModeList(MASK_USER)) + if(this->CapKeys.find("USERMODES") != this->CapKeys.end() && this->CapKeys.find("USERMODES")->second != ServerInstance->Modes->GiveModeList(MASK_USER)) reason = "One or more of the user modes on the remote server are invalid on this server."; @@ -255,8 +255,8 @@ bool TreeSocket::Capab(const parameterlist ¶ms) if (!this->GetTheirChallenge().empty() && (this->LinkState == CONNECTING)) { this->SendCapabilities(2); - this->WriteLine(std::string("SERVER ")+this->ServerInstance->Config->ServerName+" "+this->MakePass(OutboundPass, this->GetTheirChallenge())+" 0 "+ - ServerInstance->Config->GetSID()+" :"+this->ServerInstance->Config->ServerDesc); + this->WriteLine(std::string("SERVER ")+ServerInstance->Config->ServerName+" "+this->MakePass(OutboundPass, this->GetTheirChallenge())+" 0 "+ + ServerInstance->Config->GetSID()+" :"+ServerInstance->Config->ServerDesc); } } else @@ -265,7 +265,7 @@ bool TreeSocket::Capab(const parameterlist ¶ms) if (this->LinkState == CONNECTING) { this->SendCapabilities(2); - this->WriteLine(std::string("SERVER ")+this->ServerInstance->Config->ServerName+" "+OutboundPass+" 0 "+ServerInstance->Config->GetSID()+" :"+this->ServerInstance->Config->ServerDesc); + this->WriteLine(std::string("SERVER ")+ServerInstance->Config->ServerName+" "+OutboundPass+" 0 "+ServerInstance->Config->GetSID()+" :"+ServerInstance->Config->ServerDesc); } } diff --git a/src/modules/m_spanningtree/compat.cpp b/src/modules/m_spanningtree/compat.cpp index 8a6e6855f..71272edec 100644 --- a/src/modules/m_spanningtree/compat.cpp +++ b/src/modules/m_spanningtree/compat.cpp @@ -82,7 +82,7 @@ void TreeSocket::WriteLine(std::string line) ServerInstance->Logs->Log("m_spanningtree",DEBUG, "S[%d] O %s", this->GetFd(), line.c_str()); line.append("\r\n"); - this->Write(line); + this->WriteData(line); } diff --git a/src/modules/m_spanningtree/delline.cpp b/src/modules/m_spanningtree/delline.cpp index a1a9089ad..cadcdd14b 100644 --- a/src/modules/m_spanningtree/delline.cpp +++ b/src/modules/m_spanningtree/delline.cpp @@ -42,7 +42,7 @@ bool TreeSocket::DelLine(const std::string &prefix, parameterlist ¶ms) /* NOTE: No check needed on 'user', this function safely handles NULL */ if (ServerInstance->XLines->DelLine(params[1].c_str(), params[0], user)) { - this->ServerInstance->SNO->WriteToSnoMask('X',"%s removed %s%s on %s", setter.c_str(), + ServerInstance->SNO->WriteToSnoMask('X',"%s removed %s%s on %s", setter.c_str(), params[0].c_str(), params[0].length() == 1 ? "-line" : "", params[1].c_str()); Utils->DoOneToAllButSender(prefix,"DELLINE", params, prefix); } diff --git a/src/modules/m_spanningtree/encap.cpp b/src/modules/m_spanningtree/encap.cpp index 7b85a49d0..175257b0a 100644 --- a/src/modules/m_spanningtree/encap.cpp +++ b/src/modules/m_spanningtree/encap.cpp @@ -29,7 +29,7 @@ bool TreeSocket::Encap(const std::string &prefix, parameterlist ¶ms) { if (InspIRCd::Match(ServerInstance->Config->GetSID(), params[0])) { - User* who = this->ServerInstance->FindUUID(prefix); + User* who = ServerInstance->FindUUID(prefix); if (!who) who = Utils->ServerUser; diff --git a/src/modules/m_spanningtree/fhost.cpp b/src/modules/m_spanningtree/fhost.cpp index 1595b98aa..d31cffa39 100644 --- a/src/modules/m_spanningtree/fhost.cpp +++ b/src/modules/m_spanningtree/fhost.cpp @@ -25,7 +25,7 @@ bool TreeSocket::ChangeHost(const std::string &prefix, parameterlist ¶ms) { if (params.size() < 1) return true; - User* u = this->ServerInstance->FindNick(prefix); + User* u = ServerInstance->FindNick(prefix); if (u) { diff --git a/src/modules/m_spanningtree/fident.cpp b/src/modules/m_spanningtree/fident.cpp index 0744d9bf2..8cd3618db 100644 --- a/src/modules/m_spanningtree/fident.cpp +++ b/src/modules/m_spanningtree/fident.cpp @@ -25,7 +25,7 @@ bool TreeSocket::ChangeIdent(const std::string &prefix, parameterlist ¶ms) { if (params.size() < 1) return true; - User* u = this->ServerInstance->FindNick(prefix); + User* u = ServerInstance->FindNick(prefix); if (u) { u->ChangeIdent(params[0].c_str()); diff --git a/src/modules/m_spanningtree/fjoin.cpp b/src/modules/m_spanningtree/fjoin.cpp index 2c3606db1..7f11f40dd 100644 --- a/src/modules/m_spanningtree/fjoin.cpp +++ b/src/modules/m_spanningtree/fjoin.cpp @@ -59,7 +59,7 @@ bool TreeSocket::ForceJoin(const std::string &source, parameterlist ¶ms) time_t TS = atoi(params[1].c_str()); /* Timestamp given to us for remote side */ irc::tokenstream users((params.size() > 3) ? params[params.size() - 1] : ""); /* users from the user list */ bool apply_other_sides_modes = true; /* True if we are accepting the other side's modes */ - Channel* chan = this->ServerInstance->FindChan(channel); /* The channel we're sending joins to */ + Channel* chan = ServerInstance->FindChan(channel); /* The channel we're sending joins to */ bool created = !chan; /* True if the channel doesnt exist here yet */ std::string item; /* One item in the list of nicks */ @@ -123,7 +123,7 @@ bool TreeSocket::ForceJoin(const std::string &source, parameterlist ¶ms) modelist.push_back(params[idx]); } - this->ServerInstance->SendMode(modelist, Utils->ServerUser); + ServerInstance->SendMode(modelist, Utils->ServerUser); } /* Now, process every 'modes,nick' pair */ @@ -156,7 +156,7 @@ bool TreeSocket::ForceJoin(const std::string &source, parameterlist ¶ms) usr++; /* Check the user actually exists */ - who = this->ServerInstance->FindUUID(usr); + who = ServerInstance->FindUUID(usr); if (who) { /* Check that the user's 'direction' is correct */ @@ -168,7 +168,7 @@ bool TreeSocket::ForceJoin(const std::string &source, parameterlist ¶ms) for (std::string::iterator x = modes.begin(); x != modes.end(); ++x) modestack.Push(*x, who->nick); - Channel::JoinUser(this->ServerInstance, who, channel.c_str(), true, "", route_back_again->bursting, TS); + Channel::JoinUser(ServerInstance, who, channel.c_str(), true, "", route_back_again->bursting, TS); } else { diff --git a/src/modules/m_spanningtree/fmode.cpp b/src/modules/m_spanningtree/fmode.cpp index 3421f8045..3bca098d6 100644 --- a/src/modules/m_spanningtree/fmode.cpp +++ b/src/modules/m_spanningtree/fmode.cpp @@ -34,7 +34,7 @@ bool TreeSocket::ForceMode(const std::string &source, parameterlist ¶ms) std::string sourceserv; /* Are we dealing with an FMODE from a user, or from a server? */ - User* who = this->ServerInstance->FindNick(source); + User* who = ServerInstance->FindNick(source); if (who) { /* FMODE from a user, set sourceserv to the users server name */ @@ -66,7 +66,7 @@ bool TreeSocket::ForceMode(const std::string &source, parameterlist ¶ms) } /* Extract the TS value of the object, either User or Channel */ - User* dst = this->ServerInstance->FindNick(params[0]); + User* dst = ServerInstance->FindNick(params[0]); Channel* chan = NULL; time_t ourTS = 0; @@ -76,7 +76,7 @@ bool TreeSocket::ForceMode(const std::string &source, parameterlist ¶ms) } else { - chan = this->ServerInstance->FindChan(params[0]); + chan = ServerInstance->FindChan(params[0]); if (chan) { ourTS = chan->age; diff --git a/src/modules/m_spanningtree/fname.cpp b/src/modules/m_spanningtree/fname.cpp index a83591a4f..cc7625f12 100644 --- a/src/modules/m_spanningtree/fname.cpp +++ b/src/modules/m_spanningtree/fname.cpp @@ -25,7 +25,7 @@ bool TreeSocket::ChangeName(const std::string &prefix, parameterlist ¶ms) { if (params.size() < 1) return true; - User* u = this->ServerInstance->FindNick(prefix); + User* u = ServerInstance->FindNick(prefix); if (u) { u->ChangeName(params[0].c_str()); diff --git a/src/modules/m_spanningtree/ftopic.cpp b/src/modules/m_spanningtree/ftopic.cpp index 34e97dd11..5a6656e3e 100644 --- a/src/modules/m_spanningtree/ftopic.cpp +++ b/src/modules/m_spanningtree/ftopic.cpp @@ -27,14 +27,14 @@ bool TreeSocket::ForceTopic(const std::string &source, parameterlist ¶ms) if (params.size() != 4) return true; time_t ts = atoi(params[1].c_str()); - Channel* c = this->ServerInstance->FindChan(params[0]); + Channel* c = ServerInstance->FindChan(params[0]); if (c) { if ((ts >= c->topicset) || (c->topic.empty())) { if (c->topic != params[3]) { - User* user = this->ServerInstance->FindNick(source); + User* user = ServerInstance->FindNick(source); // Update topic only when it differs from current topic c->topic.assign(params[3], 0, ServerInstance->Config->Limits.MaxTopic); if (!user) diff --git a/src/modules/m_spanningtree/handshaketimer.cpp b/src/modules/m_spanningtree/handshaketimer.cpp index 56f34283b..814aa122c 100644 --- a/src/modules/m_spanningtree/handshaketimer.cpp +++ b/src/modules/m_spanningtree/handshaketimer.cpp @@ -37,15 +37,15 @@ HandshakeTimer::~HandshakeTimer() void HandshakeTimer::Tick(time_t TIME) { - if (!sock->GetHook()) + if (!sock->GetIOHook()) { CancelRepeat(); sock->SendCapabilities(1); } - else if (BufferedSocketHSCompleteRequest(sock, (Module*)Utils->Creator, sock->GetHook()).Send()) + else if (BufferedSocketHSCompleteRequest(sock, Utils->Creator, sock->GetIOHook()).Send()) { CancelRepeat(); - BufferedSocketAttachCertRequest(sock, (Module*)Utils->Creator, sock->GetHook()).Send(); + BufferedSocketAttachCertRequest(sock, Utils->Creator, sock->GetIOHook()).Send(); sock->SendCapabilities(1); } // otherwise, try again later diff --git a/src/modules/m_spanningtree/hmac.cpp b/src/modules/m_spanningtree/hmac.cpp index cc1b33f23..b7cddc47a 100644 --- a/src/modules/m_spanningtree/hmac.cpp +++ b/src/modules/m_spanningtree/hmac.cpp @@ -129,9 +129,9 @@ bool TreeSocket::ComparePass(const Link& link, const std::string &theirs) this->auth_challenge = !ourchallenge.empty() && !theirchallenge.empty(); std::string fp; - if (GetHook()) + if (GetIOHook()) { - BufferedSocketCertificateRequest req(this, Utils->Creator, GetHook()); + BufferedSocketCertificateRequest req(this, Utils->Creator, GetIOHook()); req.Send(); if (req.cert) { diff --git a/src/modules/m_spanningtree/kill.cpp b/src/modules/m_spanningtree/kill.cpp index c2026d0bb..e76fc7f3e 100644 --- a/src/modules/m_spanningtree/kill.cpp +++ b/src/modules/m_spanningtree/kill.cpp @@ -28,7 +28,7 @@ bool TreeSocket::RemoteKill(const std::string &prefix, parameterlist ¶ms) if (params.size() != 2) return true; - User* who = this->ServerInstance->FindNick(params[0]); + User* who = ServerInstance->FindNick(params[0]); if (who) { @@ -46,7 +46,7 @@ bool TreeSocket::RemoteKill(const std::string &prefix, parameterlist ¶ms) // this shouldn't ever be null, but it doesn't hurt to check who->Write(":%s KILL %s :%s (%s)", src->GetName().c_str(), who->nick.c_str(), src->GetName().c_str(), reason.c_str()); } - this->ServerInstance->Users->QuitUser(who, reason); + ServerInstance->Users->QuitUser(who, reason); } return true; } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 1bc3dfe39..230c3109b 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -275,7 +275,7 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y) /* Gave a hook, but it wasnt one we know */ if ((!x->Hook.empty()) && (Utils->hooks.find(x->Hook.c_str()) == Utils->hooks.end())) return; - TreeSocket* newsocket = new TreeSocket(Utils, ServerInstance, x->IPAddr,x->Port, x->Timeout ? x->Timeout : 10,x->Name.c_str(), x->Bind, y, x->Hook.empty() ? NULL : Utils->hooks[x->Hook.c_str()]); + TreeSocket* newsocket = new TreeSocket(Utils, x->IPAddr,x->Port, x->Timeout ? x->Timeout : 10,x->Name.c_str(), x->Bind, y, x->Hook.empty() ? NULL : Utils->hooks[x->Hook.c_str()]); if (newsocket->GetFd() > -1) { /* Handled automatically on success */ @@ -283,8 +283,7 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y) else { ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(),strerror(errno)); - if (ServerInstance->SocketCull.find(newsocket) == ServerInstance->SocketCull.end()) - ServerInstance->SocketCull[newsocket] = newsocket; + ServerInstance->GlobalCulls.AddItem(newsocket); Utils->DoFailOver(y); } } diff --git a/src/modules/m_spanningtree/metadata.cpp b/src/modules/m_spanningtree/metadata.cpp index 40a98d93b..135970a4a 100644 --- a/src/modules/m_spanningtree/metadata.cpp +++ b/src/modules/m_spanningtree/metadata.cpp @@ -33,26 +33,26 @@ bool TreeSocket::MetaData(const std::string &prefix, parameterlist ¶ms) { if (params[0] == "*") { - FOREACH_MOD_I(this->ServerInstance,I_OnDecodeMetaData,OnDecodeMetaData(NULL,params[1],params[2])); + FOREACH_MOD_I(ServerInstance,I_OnDecodeMetaData,OnDecodeMetaData(NULL,params[1],params[2])); } else if (*(params[0].c_str()) == '#') { - Channel* c = this->ServerInstance->FindChan(params[0]); + Channel* c = ServerInstance->FindChan(params[0]); if (c) { if (item) item->unserialize(FORMAT_NETWORK, c, params[2]); - FOREACH_MOD_I(this->ServerInstance,I_OnDecodeMetaData,OnDecodeMetaData(c,params[1],params[2])); + FOREACH_MOD_I(ServerInstance,I_OnDecodeMetaData,OnDecodeMetaData(c,params[1],params[2])); } } else if (*(params[0].c_str()) != '#') { - User* u = this->ServerInstance->FindNick(params[0]); + User* u = ServerInstance->FindNick(params[0]); if (u) { if (item) item->unserialize(FORMAT_NETWORK, u, params[2]); - FOREACH_MOD_I(this->ServerInstance,I_OnDecodeMetaData,OnDecodeMetaData(u,params[1],params[2])); + FOREACH_MOD_I(ServerInstance,I_OnDecodeMetaData,OnDecodeMetaData(u,params[1],params[2])); } } } diff --git a/src/modules/m_spanningtree/modules.cpp b/src/modules/m_spanningtree/modules.cpp index 6c9132794..7a20a98ff 100644 --- a/src/modules/m_spanningtree/modules.cpp +++ b/src/modules/m_spanningtree/modules.cpp @@ -26,7 +26,7 @@ bool TreeSocket::Modules(const std::string &prefix, parameterlist ¶ms) if (params.empty()) return true; - if (!InspIRCd::Match(this->ServerInstance->Config->ServerName, params[0])) + if (!InspIRCd::Match(ServerInstance->Config->ServerName, params[0])) { /* Pass it on, not for us */ Utils->DoOneToOne(prefix, "MODULES", params, params[0]); @@ -38,7 +38,7 @@ bool TreeSocket::Modules(const std::string &prefix, parameterlist ¶ms) par.push_back(prefix); par.push_back(""); - User* source = this->ServerInstance->FindNick(prefix); + User* source = ServerInstance->FindNick(prefix); if (!source) return true; diff --git a/src/modules/m_spanningtree/motd.cpp b/src/modules/m_spanningtree/motd.cpp index e42c53152..0c775d644 100644 --- a/src/modules/m_spanningtree/motd.cpp +++ b/src/modules/m_spanningtree/motd.cpp @@ -27,11 +27,11 @@ bool TreeSocket::Motd(const std::string &prefix, parameterlist ¶ms) { if (params.size() > 0) { - if (InspIRCd::Match(this->ServerInstance->Config->ServerName, params[0])) + if (InspIRCd::Match(ServerInstance->Config->ServerName, params[0])) { /* It's for our server */ string_list results; - User* source = this->ServerInstance->FindNick(prefix); + User* source = ServerInstance->FindNick(prefix); if (source) { @@ -42,27 +42,27 @@ bool TreeSocket::Motd(const std::string &prefix, parameterlist ¶ms) if (!ServerInstance->Config->MOTD.size()) { par[1] = std::string("::")+ServerInstance->Config->ServerName+" 422 "+source->nick+" :Message of the day file is missing."; - Utils->DoOneToOne(this->ServerInstance->Config->GetSID(), "PUSH",par, source->server); + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH",par, source->server); return true; } par[1] = std::string("::")+ServerInstance->Config->ServerName+" 375 "+source->nick+" :"+ServerInstance->Config->ServerName+" message of the day"; - Utils->DoOneToOne(this->ServerInstance->Config->GetSID(), "PUSH",par, source->server); + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH",par, source->server); for (unsigned int i = 0; i < ServerInstance->Config->MOTD.size(); i++) { par[1] = std::string("::")+ServerInstance->Config->ServerName+" 372 "+source->nick+" :- "+ServerInstance->Config->MOTD[i]; - Utils->DoOneToOne(this->ServerInstance->Config->GetSID(), "PUSH",par, source->server); + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH",par, source->server); } par[1] = std::string("::")+ServerInstance->Config->ServerName+" 376 "+source->nick+" :End of message of the day."; - Utils->DoOneToOne(this->ServerInstance->Config->GetSID(), "PUSH",par, source->server); + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH",par, source->server); } } else { /* Pass it on */ - User* source = this->ServerInstance->FindNick(prefix); + User* source = ServerInstance->FindNick(prefix); if (source) Utils->DoOneToOne(prefix, "MOTD", params, params[0]); } diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp index ada10e6a1..3cfad9b63 100644 --- a/src/modules/m_spanningtree/netburst.cpp +++ b/src/modules/m_spanningtree/netburst.cpp @@ -30,16 +30,16 @@ void TreeSocket::DoBurst(TreeServer* s) { std::string name = s->GetName(); - std::string burst = ":" + this->ServerInstance->Config->GetSID() + " BURST " +ConvToStr(ServerInstance->Time()); - std::string endburst = ":" + this->ServerInstance->Config->GetSID() + " ENDBURST"; - this->ServerInstance->SNO->WriteToSnoMask('l',"Bursting to \2%s\2 (Authentication: %s%s).", + std::string burst = ":" + ServerInstance->Config->GetSID() + " BURST " +ConvToStr(ServerInstance->Time()); + std::string endburst = ":" + ServerInstance->Config->GetSID() + " ENDBURST"; + ServerInstance->SNO->WriteToSnoMask('l',"Bursting to \2%s\2 (Authentication: %s%s).", name.c_str(), this->auth_fingerprint ? "SSL Fingerprint and " : "", this->auth_challenge ? "challenge-response" : "plaintext password"); this->CleanNegotiationInfo(); this->WriteLine(burst); /* send our version string */ - this->WriteLine(std::string(":")+this->ServerInstance->Config->GetSID()+" VERSION :"+this->ServerInstance->GetVersionString()); + this->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" VERSION :"+ServerInstance->GetVersionString()); /* Send server tree */ this->SendServers(Utils->TreeRoot,s,1); /* Send users and their oper status */ @@ -47,9 +47,9 @@ void TreeSocket::DoBurst(TreeServer* s) /* Send everything else (channel modes, xlines etc) */ this->SendChannelModes(s); this->SendXLines(s); - FOREACH_MOD_I(this->ServerInstance,I_OnSyncNetwork,OnSyncNetwork(Utils->Creator,(void*)this)); + FOREACH_MOD_I(ServerInstance,I_OnSyncNetwork,OnSyncNetwork(Utils->Creator,(void*)this)); this->WriteLine(endburst); - this->ServerInstance->SNO->WriteToSnoMask('l',"Finished bursting to \2"+name+"\2."); + ServerInstance->SNO->WriteToSnoMask('l',"Finished bursting to \2"+name+"\2."); } /** Recursively send the server tree with distances as hops. @@ -91,7 +91,7 @@ void TreeSocket::SendFJoins(TreeServer* Current, Channel* c) size_t curlen, headlen; curlen = headlen = snprintf(list,MAXBUF,":%s FJOIN %s %lu +%s :", - this->ServerInstance->Config->GetSID().c_str(), c->name.c_str(), (unsigned long)c->age, c->ChanModes(true)); + ServerInstance->Config->GetSID().c_str(), c->name.c_str(), (unsigned long)c->age, c->ChanModes(true)); int numusers = 0; char* ptr = list + curlen; bool looped_once = false; @@ -103,7 +103,7 @@ void TreeSocket::SendFJoins(TreeServer* Current, Channel* c) for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++) { size_t ptrlen = 0; - std::string modestr = this->ServerInstance->Modes->ModeString(i->first, c, false); + std::string modestr = ServerInstance->Modes->ModeString(i->first, c, false); if ((curlen + modestr.length() + i->first->uuid.length() + 4) > 480) { @@ -150,7 +150,7 @@ void TreeSocket::SendFJoins(TreeServer* Current, Channel* c) if ((params.length() >= ServerInstance->Config->Limits.MaxModes) || (currsize > 350)) { /* Wrap at MAXMODES */ - buffer.append(":").append(this->ServerInstance->Config->GetSID()).append(" FMODE ").append(c->name).append(" ").append(ConvToStr(c->age)).append(" +").append(modes).append(params).append("\r\n"); + buffer.append(":").append(ServerInstance->Config->GetSID()).append(" FMODE ").append(c->name).append(" ").append(ConvToStr(c->age)).append(" +").append(modes).append(params).append("\r\n"); modes.clear(); params.clear(); linesize = 1; @@ -159,7 +159,7 @@ void TreeSocket::SendFJoins(TreeServer* Current, Channel* c) /* Only send these if there are any */ if (!modes.empty()) - buffer.append(":").append(this->ServerInstance->Config->GetSID()).append(" FMODE ").append(c->name).append(" ").append(ConvToStr(c->age)).append(" +").append(modes).append(params); + buffer.append(":").append(ServerInstance->Config->GetSID()).append(" FMODE ").append(c->name).append(" ").append(ConvToStr(c->age)).append(" +").append(modes).append(params); this->WriteLine(buffer); } @@ -168,7 +168,7 @@ void TreeSocket::SendFJoins(TreeServer* Current, Channel* c) void TreeSocket::SendXLines(TreeServer* Current) { char data[MAXBUF]; - std::string n = this->ServerInstance->Config->GetSID(); + std::string n = ServerInstance->Config->GetSID(); const char* sn = n.c_str(); std::vector<std::string> types = ServerInstance->XLines->GetAllTypes(); @@ -209,9 +209,9 @@ void TreeSocket::SendChannelModes(TreeServer* Current) { char data[MAXBUF]; std::deque<std::string> list; - std::string n = this->ServerInstance->Config->GetSID(); + std::string n = ServerInstance->Config->GetSID(); const char* sn = n.c_str(); - for (chan_hash::iterator c = this->ServerInstance->chanlist->begin(); c != this->ServerInstance->chanlist->end(); c++) + for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); c++) { SendFJoins(Current, c->second); if (!c->second->topic.empty()) @@ -230,7 +230,7 @@ void TreeSocket::SendChannelModes(TreeServer* Current) Utils->Creator->ProtoSendMetaData(this, c->second, i->first, value); } - FOREACH_MOD_I(this->ServerInstance,I_OnSyncChannel,OnSyncChannel(c->second,Utils->Creator,this)); + FOREACH_MOD_I(ServerInstance,I_OnSyncChannel,OnSyncChannel(c->second,Utils->Creator,this)); } } @@ -239,7 +239,7 @@ void TreeSocket::SendUsers(TreeServer* Current) { char data[MAXBUF]; std::string dataline; - for (user_hash::iterator u = this->ServerInstance->Users->clientlist->begin(); u != this->ServerInstance->Users->clientlist->end(); u++) + for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++) { if (u->second->registered == REG_ALL) { @@ -281,7 +281,7 @@ void TreeSocket::SendUsers(TreeServer* Current) Utils->Creator->ProtoSendMetaData(this, u->second, i->first, value); } - FOREACH_MOD_I(this->ServerInstance,I_OnSyncUser,OnSyncUser(u->second,Utils->Creator,this)); + FOREACH_MOD_I(ServerInstance,I_OnSyncUser,OnSyncUser(u->second,Utils->Creator,this)); } } } diff --git a/src/modules/m_spanningtree/nickcollide.cpp b/src/modules/m_spanningtree/nickcollide.cpp index a723c114f..4481ba35e 100644 --- a/src/modules/m_spanningtree/nickcollide.cpp +++ b/src/modules/m_spanningtree/nickcollide.cpp @@ -114,7 +114,7 @@ int TreeSocket::DoCollision(User *u, time_t remotets, const std::string &remotei } if (bChangeRemote) { - User *remote = this->ServerInstance->FindUUID(remoteuid); + User *remote = ServerInstance->FindUUID(remoteuid); /* * remote side needs to change. If this happens, we will modify * the UID or halt the propagation of the nick change command, diff --git a/src/modules/m_spanningtree/operquit.cpp b/src/modules/m_spanningtree/operquit.cpp index 5cdee3bc6..9128baa0f 100644 --- a/src/modules/m_spanningtree/operquit.cpp +++ b/src/modules/m_spanningtree/operquit.cpp @@ -26,7 +26,7 @@ bool TreeSocket::OperQuit(const std::string &prefix, parameterlist ¶ms) if (params.size() < 1) return true; - User* u = this->ServerInstance->FindNick(prefix); + User* u = ServerInstance->FindNick(prefix); if (u) { diff --git a/src/modules/m_spanningtree/opertype.cpp b/src/modules/m_spanningtree/opertype.cpp index c1105aa71..a1ad88007 100644 --- a/src/modules/m_spanningtree/opertype.cpp +++ b/src/modules/m_spanningtree/opertype.cpp @@ -29,11 +29,11 @@ bool TreeSocket::OperType(const std::string &prefix, parameterlist ¶ms) if (params.size() != 1) return true; std::string opertype = params[0]; - User* u = this->ServerInstance->FindNick(prefix); + User* u = ServerInstance->FindNick(prefix); if (u) { if (!IS_OPER(u)) - this->ServerInstance->Users->all_opers.push_back(u); + ServerInstance->Users->all_opers.push_back(u); u->modes[UM_OPERATOR] = 1; u->oper.assign(opertype, 0, 512); Utils->DoOneToAllButSender(u->uuid, "OPERTYPE", params, u->server); @@ -49,7 +49,7 @@ bool TreeSocket::OperType(const std::string &prefix, parameterlist ¶ms) */ if ( remoteserver->bursting || - this->ServerInstance->SilentULine(this->ServerInstance->FindServerNamePtr(u->server)) + ServerInstance->SilentULine(ServerInstance->FindServerNamePtr(u->server)) ) { dosend = false; @@ -57,7 +57,7 @@ bool TreeSocket::OperType(const std::string &prefix, parameterlist ¶ms) } if (dosend) - this->ServerInstance->SNO->WriteToSnoMask('O',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server, u->nick.c_str(),u->ident.c_str(), u->host.c_str(), irc::Spacify(opertype.c_str())); + ServerInstance->SNO->WriteToSnoMask('O',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server, u->nick.c_str(),u->ident.c_str(), u->host.c_str(), irc::Spacify(opertype.c_str())); } return true; } diff --git a/src/modules/m_spanningtree/override_stats.cpp b/src/modules/m_spanningtree/override_stats.cpp index 9986763d9..5d0239f84 100644 --- a/src/modules/m_spanningtree/override_stats.cpp +++ b/src/modules/m_spanningtree/override_stats.cpp @@ -78,8 +78,8 @@ ModResult ModuleSpanningTree::OnStats(char statschar, User* user, string_list &r ip = "*"; std::string transport("plaintext"); - if (Utils->Bindings[i]->GetIOHook()) - transport = BufferedSocketNameRequest(this, Utils->Bindings[i]->GetIOHook()).Send(); + if (Utils->Bindings[i]->Hook) + transport = BufferedSocketNameRequest(this, Utils->Bindings[i]->Hook).Send(); results.push_back(ConvToStr(ServerInstance->Config->ServerName) + " 249 "+user->nick+" :" + ip + ":" + ConvToStr(Utils->Bindings[i]->GetPort())+ " (server, " + transport + ")"); diff --git a/src/modules/m_spanningtree/ping.cpp b/src/modules/m_spanningtree/ping.cpp index 1318b60a0..c3467c984 100644 --- a/src/modules/m_spanningtree/ping.cpp +++ b/src/modules/m_spanningtree/ping.cpp @@ -31,13 +31,13 @@ bool TreeSocket::LocalPing(const std::string &prefix, parameterlist ¶ms) if (params.size() == 1) { std::string stufftobounce = params[0]; - this->WriteLine(std::string(":")+this->ServerInstance->Config->GetSID()+" PONG "+stufftobounce); + this->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" PONG "+stufftobounce); return true; } else { std::string forwardto = params[1]; - if (forwardto == this->ServerInstance->Config->ServerName || forwardto == this->ServerInstance->Config->GetSID()) + if (forwardto == ServerInstance->Config->ServerName || forwardto == ServerInstance->Config->GetSID()) { // this is a ping for us, send back PONG to the requesting server params[1] = params[0]; diff --git a/src/modules/m_spanningtree/pong.cpp b/src/modules/m_spanningtree/pong.cpp index b551ef6d2..274641897 100644 --- a/src/modules/m_spanningtree/pong.cpp +++ b/src/modules/m_spanningtree/pong.cpp @@ -52,7 +52,7 @@ bool TreeSocket::LocalPong(const std::string &prefix, parameterlist ¶ms) * dump the PONG reply back to their fd. If its a server, do nowt. * Services might want to send these s->s, but we dont need to yet. */ - User* u = this->ServerInstance->FindNick(prefix); + User* u = ServerInstance->FindNick(prefix); if (u) { u->WriteServ("PONG %s %s",params[0].c_str(),params[1].c_str()); diff --git a/src/modules/m_spanningtree/push.cpp b/src/modules/m_spanningtree/push.cpp index 88c6b55bd..778c2291c 100644 --- a/src/modules/m_spanningtree/push.cpp +++ b/src/modules/m_spanningtree/push.cpp @@ -28,7 +28,7 @@ bool TreeSocket::Push(const std::string &prefix, parameterlist ¶ms) { if (params.size() < 2) return true; - User* u = this->ServerInstance->FindNick(params[0]); + User* u = ServerInstance->FindNick(params[0]); if (!u) return true; if (IS_LOCAL(u)) diff --git a/src/modules/m_spanningtree/resolvers.cpp b/src/modules/m_spanningtree/resolvers.cpp index 73e67c4f7..c7c49b348 100644 --- a/src/modules/m_spanningtree/resolvers.cpp +++ b/src/modules/m_spanningtree/resolvers.cpp @@ -49,7 +49,7 @@ void ServernameResolver::OnLookupComplete(const std::string &result, unsigned in if ((!MyLink.Hook.empty()) && (Utils->hooks.find(MyLink.Hook.c_str()) == Utils->hooks.end())) return; - TreeSocket* newsocket = new TreeSocket(this->Utils, ServerInstance, result,MyLink.Port,MyLink.Timeout ? MyLink.Timeout : 10,MyLink.Name.c_str(), + TreeSocket* newsocket = new TreeSocket(this->Utils, result,MyLink.Port,MyLink.Timeout ? MyLink.Timeout : 10,MyLink.Name.c_str(), MyLink.Bind, myautoconnect, MyLink.Hook.empty() ? NULL : Utils->hooks[MyLink.Hook.c_str()]); if (newsocket->GetFd() > -1) { @@ -59,8 +59,7 @@ void ServernameResolver::OnLookupComplete(const std::string &result, unsigned in { /* Something barfed, show the opers */ ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",MyLink.Name.c_str(),strerror(errno)); - if (ServerInstance->SocketCull.find(newsocket) == ServerInstance->SocketCull.end()) - ServerInstance->SocketCull[newsocket] = newsocket; + ServerInstance->GlobalCulls.AddItem(newsocket); Utils->DoFailOver(myautoconnect); } } diff --git a/src/modules/m_spanningtree/save.cpp b/src/modules/m_spanningtree/save.cpp index 9969fdca7..cfa8dc794 100644 --- a/src/modules/m_spanningtree/save.cpp +++ b/src/modules/m_spanningtree/save.cpp @@ -32,7 +32,7 @@ bool TreeSocket::ForceNick(const std::string &prefix, parameterlist ¶ms) if (params.size() < 2) return true; - User* u = this->ServerInstance->FindNick(params[0]); + User* u = ServerInstance->FindNick(params[0]); time_t ts = atol(params[1].c_str()); if (u && u->age == ts) @@ -41,7 +41,7 @@ bool TreeSocket::ForceNick(const std::string &prefix, parameterlist ¶ms) if (!u->ForceNickChange(u->uuid.c_str())) { - this->ServerInstance->Users->QuitUser(u, "Nickname collision"); + ServerInstance->Users->QuitUser(u, "Nickname collision"); } } diff --git a/src/modules/m_spanningtree/server.cpp b/src/modules/m_spanningtree/server.cpp index c275f3490..025675642 100644 --- a/src/modules/m_spanningtree/server.cpp +++ b/src/modules/m_spanningtree/server.cpp @@ -49,7 +49,7 @@ bool TreeSocket::RemoteServer(const std::string &prefix, parameterlist ¶ms) this->SendError("Protocol error - Introduced remote server from unknown server "+ParentOfThis->GetName()); return false; } - if (!this->ServerInstance->IsSID(sid)) + if (!ServerInstance->IsSID(sid)) { this->SendError("Invalid format server ID: "+sid+"!"); return false; @@ -58,26 +58,26 @@ bool TreeSocket::RemoteServer(const std::string &prefix, parameterlist ¶ms) if (CheckDupe) { this->SendError("Server "+servername+" already exists!"); - this->ServerInstance->SNO->WriteToSnoMask('L', "Server \2"+CheckDupe->GetName()+"\2 being introduced from \2" + ParentOfThis->GetName() + "\2 denied, already exists. Closing link with " + ParentOfThis->GetName()); + ServerInstance->SNO->WriteToSnoMask('L', "Server \2"+CheckDupe->GetName()+"\2 being introduced from \2" + ParentOfThis->GetName() + "\2 denied, already exists. Closing link with " + ParentOfThis->GetName()); return false; } CheckDupe = Utils->FindServer(sid); if (CheckDupe) { this->SendError("Server ID "+sid+" already exists! You may want to specify the server ID for the server manually with <server:id> so they do not conflict."); - this->ServerInstance->SNO->WriteToSnoMask('L', "Server \2"+servername+"\2 being introduced from \2" + ParentOfThis->GetName() + "\2 denied, server ID already exists on the network. Closing link with " + ParentOfThis->GetName()); + ServerInstance->SNO->WriteToSnoMask('L', "Server \2"+servername+"\2 being introduced from \2" + ParentOfThis->GetName() + "\2 denied, server ID already exists on the network. Closing link with " + ParentOfThis->GetName()); return false; } Link* lnk = Utils->FindLink(servername); - TreeServer *Node = new TreeServer(this->Utils, this->ServerInstance, servername, description, sid, ParentOfThis,NULL, lnk ? lnk->Hidden : false); + TreeServer *Node = new TreeServer(this->Utils, ServerInstance, servername, description, sid, ParentOfThis,NULL, lnk ? lnk->Hidden : false); ParentOfThis->AddChild(Node); params[4] = ":" + params[4]; Utils->DoOneToAllButSender(prefix,"SERVER",params,prefix); - this->ServerInstance->SNO->WriteToSnoMask('L', "Server \002"+ParentOfThis->GetName()+"\002 introduced server \002"+servername+"\002 ("+description+")"); + ServerInstance->SNO->WriteToSnoMask('L', "Server \002"+ParentOfThis->GetName()+"\002 introduced server \002"+servername+"\002 ("+description+")"); return true; } @@ -110,11 +110,11 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist ¶ms) if (hops) { this->SendError("Server too far away for authentication"); - this->ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication"); + ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication"); return false; } - if (!this->ServerInstance->IsSID(sid)) + if (!ServerInstance->IsSID(sid)) { this->SendError("Invalid format server ID: "+sid+"!"); return false; @@ -127,7 +127,7 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist ¶ms) if (!ComparePass(*x, password)) { - this->ServerInstance->SNO->WriteToSnoMask('l',"Invalid password on link: %s", x->Name.c_str()); + ServerInstance->SNO->WriteToSnoMask('l',"Invalid password on link: %s", x->Name.c_str()); continue; } @@ -135,14 +135,14 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist ¶ms) if (CheckDupe) { this->SendError("Server "+sname+" already exists on server "+CheckDupe->GetParent()->GetName()+"!"); - this->ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName()); + ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName()); return false; } CheckDupe = Utils->FindServer(sid); if (CheckDupe) { this->SendError("Server ID "+sid+" already exists on the network! You may want to specify the server ID for the server manually with <server:id> so they do not conflict."); - this->ServerInstance->SNO->WriteToSnoMask('l',"Server \2"+assign(servername)+"\2 being introduced denied, server ID already exists on the network. Closing link."); + ServerInstance->SNO->WriteToSnoMask('l',"Server \2"+assign(servername)+"\2 being introduced denied, server ID already exists on the network. Closing link."); return false; } @@ -158,7 +158,7 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist ¶ms) Utils->timeoutlist.erase(this); - TreeServer *Node = new TreeServer(this->Utils, this->ServerInstance, sname, description, sid, Utils->TreeRoot, this, x->Hidden); + TreeServer *Node = new TreeServer(this->Utils, ServerInstance, sname, description, sid, Utils->TreeRoot, this, x->Hidden); Utils->TreeRoot->AddChild(Node); params[4] = ":" + params[4]; @@ -173,7 +173,7 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist ¶ms) } this->SendError("Invalid credentials (check the other server's linking snomask for more information)"); - this->ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials"); + ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials"); return false; } @@ -205,11 +205,11 @@ bool TreeSocket::Inbound_Server(parameterlist ¶ms) if (hops) { this->SendError("Server too far away for authentication"); - this->ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication"); + ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication"); return false; } - if (!this->ServerInstance->IsSID(sid)) + if (!ServerInstance->IsSID(sid)) { this->SendError("Invalid format server ID: "+sid+"!"); return false; @@ -222,7 +222,7 @@ bool TreeSocket::Inbound_Server(parameterlist ¶ms) if (!ComparePass(*x, password)) { - this->ServerInstance->SNO->WriteToSnoMask('l',"Invalid password on link: %s", x->Name.c_str()); + ServerInstance->SNO->WriteToSnoMask('l',"Invalid password on link: %s", x->Name.c_str()); continue; } @@ -231,7 +231,7 @@ bool TreeSocket::Inbound_Server(parameterlist ¶ms) if (CheckDupe) { this->SendError("Server "+sname+" already exists on server "+CheckDupe->GetParent()->GetName()+"!"); - this->ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName()); + ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName()); return false; } @@ -242,30 +242,30 @@ bool TreeSocket::Inbound_Server(parameterlist ¶ms) if (CheckDupe) { this->SendError("Server ID "+CheckDupe->GetID()+" already exists on server "+CheckDupe->GetName()+"! You may want to specify the server ID for the server manually with <server:id> so they do not conflict."); - this->ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server ID '"+CheckDupe->GetID()+ + ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server ID '"+CheckDupe->GetID()+ "' already exists on server "+CheckDupe->GetName()); return false; } - this->ServerInstance->SNO->WriteToSnoMask('l',"Verified incoming server connection from \002"+sname+"\002["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] ("+description+")"); - if (this->Hook) + ServerInstance->SNO->WriteToSnoMask('l',"Verified incoming server connection from \002"+sname+"\002["+(x->HiddenFromStats ? "<hidden>" : this->IP)+"] ("+description+")"); + if (this->GetIOHook()) { - std::string name = BufferedSocketNameRequest((Module*)Utils->Creator, this->Hook).Send(); - this->ServerInstance->SNO->WriteToSnoMask('l',"Connection from \2"+sname+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] using transport \2"+name+"\2"); + std::string name = BufferedSocketNameRequest(Utils->Creator, this->GetIOHook()).Send(); + ServerInstance->SNO->WriteToSnoMask('l',"Connection from \2"+sname+"\2["+(x->HiddenFromStats ? "<hidden>" : this->IP)+"] using transport \2"+name+"\2"); } // this is good. Send our details: Our server name and description and hopcount of 0, // along with the sendpass from this block. this->SendCapabilities(2); - this->WriteLine(std::string("SERVER ")+this->ServerInstance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 "+ServerInstance->Config->GetSID()+" :"+this->ServerInstance->Config->ServerDesc); + this->WriteLine(std::string("SERVER ")+ServerInstance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 "+ServerInstance->Config->GetSID()+" :"+ServerInstance->Config->ServerDesc); // move to the next state, we are now waiting for THEM. this->LinkState = WAIT_AUTH_2; return true; } this->SendError("Invalid credentials"); - this->ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials"); + ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials"); return false; } diff --git a/src/modules/m_spanningtree/stats.cpp b/src/modules/m_spanningtree/stats.cpp index d67c5a3af..71f12d50b 100644 --- a/src/modules/m_spanningtree/stats.cpp +++ b/src/modules/m_spanningtree/stats.cpp @@ -32,11 +32,11 @@ bool TreeSocket::Stats(const std::string &prefix, parameterlist ¶ms) */ if (params.size() > 1) { - if (InspIRCd::Match(this->ServerInstance->Config->ServerName, params[1])) + if (InspIRCd::Match(ServerInstance->Config->ServerName, params[1])) { /* It's for our server */ string_list results; - User* source = this->ServerInstance->FindNick(prefix); + User* source = ServerInstance->FindNick(prefix); if (source) { parameterlist par; @@ -46,14 +46,14 @@ bool TreeSocket::Stats(const std::string &prefix, parameterlist ¶ms) for (size_t i = 0; i < results.size(); i++) { par[1] = "::" + results[i]; - Utils->DoOneToOne(this->ServerInstance->Config->GetSID(), "PUSH",par, source->server); + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH",par, source->server); } } } else { /* Pass it on */ - User* source = this->ServerInstance->FindNick(prefix); + User* source = ServerInstance->FindNick(prefix); if (source) Utils->DoOneToOne(source->uuid, "STATS", params, params[1]); } diff --git a/src/modules/m_spanningtree/svsjoin.cpp b/src/modules/m_spanningtree/svsjoin.cpp index b6246e2f4..1664190f8 100644 --- a/src/modules/m_spanningtree/svsjoin.cpp +++ b/src/modules/m_spanningtree/svsjoin.cpp @@ -29,13 +29,13 @@ bool TreeSocket::ServiceJoin(const std::string &prefix, parameterlist ¶ms) if (params.size() < 2) return true; - User* u = this->ServerInstance->FindNick(params[0]); + User* u = ServerInstance->FindNick(params[0]); if (u) { /* only join if it's local, otherwise just pass it on! */ if (IS_LOCAL(u)) - Channel::JoinUser(this->ServerInstance, u, params[1].c_str(), false, "", false, ServerInstance->Time()); + Channel::JoinUser(ServerInstance, u, params[1].c_str(), false, "", false, ServerInstance->Time()); Utils->DoOneToAllButSender(prefix,"SVSJOIN",params,prefix); } return true; diff --git a/src/modules/m_spanningtree/svsnick.cpp b/src/modules/m_spanningtree/svsnick.cpp index 3af6961d0..7a723a36d 100644 --- a/src/modules/m_spanningtree/svsnick.cpp +++ b/src/modules/m_spanningtree/svsnick.cpp @@ -32,7 +32,7 @@ bool TreeSocket::SVSNick(const std::string &prefix, parameterlist ¶ms) if (params.size() < 3) return true; - User* u = this->ServerInstance->FindNick(params[0]); + User* u = ServerInstance->FindNick(params[0]); if (u) { @@ -48,7 +48,7 @@ bool TreeSocket::SVSNick(const std::string &prefix, parameterlist ¶ms) /* buh. UID them */ if (!u->ForceNickChange(u->uuid.c_str())) { - this->ServerInstance->Users->QuitUser(u, "Nickname collision"); + ServerInstance->Users->QuitUser(u, "Nickname collision"); return true; } } diff --git a/src/modules/m_spanningtree/svspart.cpp b/src/modules/m_spanningtree/svspart.cpp index 83e329b4e..1e26c90d9 100644 --- a/src/modules/m_spanningtree/svspart.cpp +++ b/src/modules/m_spanningtree/svspart.cpp @@ -34,8 +34,8 @@ bool TreeSocket::ServicePart(const std::string &prefix, parameterlist ¶ms) if (params.size() == 3) reason = params[2]; - User* u = this->ServerInstance->FindNick(params[0]); - Channel* c = this->ServerInstance->FindChan(params[1]); + User* u = ServerInstance->FindNick(params[0]); + Channel* c = ServerInstance->FindChan(params[1]); if (u) { diff --git a/src/modules/m_spanningtree/time.cpp b/src/modules/m_spanningtree/time.cpp index 82a7fe62e..6fdcf8b53 100644 --- a/src/modules/m_spanningtree/time.cpp +++ b/src/modules/m_spanningtree/time.cpp @@ -31,20 +31,20 @@ bool TreeSocket::Time(const std::string &prefix, parameterlist ¶ms) if (params.size() == 2) { // someone querying our time? - if (this->ServerInstance->Config->ServerName == params[0] || this->ServerInstance->Config->GetSID() == params[0]) + if (ServerInstance->Config->ServerName == params[0] || ServerInstance->Config->GetSID() == params[0]) { - User* u = this->ServerInstance->FindNick(params[1]); + User* u = ServerInstance->FindNick(params[1]); if (u) { params.push_back(ConvToStr(ServerInstance->Time())); params[0] = prefix; - Utils->DoOneToOne(this->ServerInstance->Config->GetSID(),"TIME",params,params[0]); + Utils->DoOneToOne(ServerInstance->Config->GetSID(),"TIME",params,params[0]); } } else { // not us, pass it on - User* u = this->ServerInstance->FindNick(params[1]); + User* u = ServerInstance->FindNick(params[1]); if (u) Utils->DoOneToOne(prefix,"TIME",params,params[0]); } @@ -52,7 +52,7 @@ bool TreeSocket::Time(const std::string &prefix, parameterlist ¶ms) else if (params.size() == 3) { // a response to a previous TIME - User* u = this->ServerInstance->FindNick(params[1]); + User* u = ServerInstance->FindNick(params[1]); if ((u) && (IS_LOCAL(u))) { std::string sourceserv = Utils->FindServer(prefix)->GetName(); diff --git a/src/modules/m_spanningtree/treesocket.h b/src/modules/m_spanningtree/treesocket.h index a26e89f85..3c9484981 100644 --- a/src/modules/m_spanningtree/treesocket.h +++ b/src/modules/m_spanningtree/treesocket.h @@ -71,7 +71,6 @@ class TreeSocket : public BufferedSocket { SpanningTreeUtilities* Utils; /* Utility class */ std::string myhost; /* Canonical hostname */ - std::string in_buffer; /* Input buffer */ ServerState LinkState; /* Link state */ std::string InboundServerName; /* Server name sent to us by other side */ std::string InboundDescription; /* Server description (GECOS) sent to us by the other side */ @@ -80,10 +79,10 @@ class TreeSocket : public BufferedSocket int num_lost_servers; /* Servers lost in split */ time_t NextPing; /* Time when we are due to ping this server */ bool LastPingWasGood; /* Responded to last ping we sent? */ + std::string IP; std::string ModuleList; /* Required module list of other server from CAPAB */ std::string OptModuleList; /* Optional module list of other server from CAPAB */ std::map<std::string,std::string> CapKeys; /* CAPAB keys from other server */ - Module* Hook; /* I/O hooking module that we're attached to for this socket */ std::string ourchallenge; /* Challenge sent for challenge/response */ std::string theirchallenge; /* Challenge recv for challenge/response */ std::string OutboundPass; /* Outbound password */ @@ -101,13 +100,13 @@ class TreeSocket : public BufferedSocket * most of the action, and append a few of our own values * to it. */ - TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string host, int port, unsigned long maxtime, const std::string &ServerName, const std::string &bindto, Autoconnect* myac, Module* HookMod = NULL); + TreeSocket(SpanningTreeUtilities* Util, std::string host, int port, unsigned long maxtime, const std::string &ServerName, const std::string &bindto, Autoconnect* myac, Module* HookMod = NULL); /** When a listening socket gives us a new file descriptor, * we must associate it with a socket without creating a new * connection. This constructor is used for this purpose. */ - TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, int newfd, char* ip, Autoconnect* myac, Module* HookMod = NULL); + TreeSocket(SpanningTreeUtilities* Util, int newfd, char* ip, Autoconnect* myac, Module* HookMod = NULL); /** Get link state */ @@ -137,10 +136,6 @@ class TreeSocket : public BufferedSocket */ void CleanNegotiationInfo(); - /** Return the module which we are hooking to for I/O encapsulation - */ - Module* GetHook(); - /** Destructor */ ~TreeSocket(); @@ -160,7 +155,7 @@ class TreeSocket : public BufferedSocket * to server docs on the inspircd.org site, the other side * will then send back its own server string. */ - virtual bool OnConnected(); + virtual void OnConnected(); /** Handle socket error event */ @@ -171,10 +166,6 @@ class TreeSocket : public BufferedSocket */ void SendError(const std::string &errormessage); - /** Handle socket disconnect event - */ - virtual int OnDisconnect(); - /** Recursively send the server tree with distances as hops. * This is used during network burst to inform the other server * (and any of ITS servers too) of what servers we know about. @@ -258,14 +249,9 @@ class TreeSocket : public BufferedSocket void DoBurst(TreeServer* s); /** This function is called when we receive data from a remote - * server. We buffer the data in a std::string (it doesnt stay - * there for long), reading using BufferedSocket::Read() which can - * read up to 16 kilobytes in one operation. - * - * IF THIS FUNCTION RETURNS FALSE, THE CORE CLOSES AND DELETES - * THE SOCKET OBJECT FOR US. + * server. */ - virtual bool OnDataReady(); + void OnDataReady(); /** Send one or more complete lines down the socket */ @@ -404,10 +390,9 @@ class TreeSocket : public BufferedSocket /** Handle socket timeout from connect() */ virtual void OnTimeout(); - - /** Handle socket close event + /** Handle server quit on close */ - virtual void OnClose(); + virtual void Close(); }; /* Used to validate the value lengths of multiple parameters for a command */ diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp index d59364751..55fbc2c91 100644 --- a/src/modules/m_spanningtree/treesocket1.cpp +++ b/src/modules/m_spanningtree/treesocket1.cpp @@ -34,17 +34,18 @@ * most of the action, and append a few of our own values * to it. */ -TreeSocket::TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string shost, int iport, unsigned long maxtime, const std::string &ServerName, const std::string &bindto, Autoconnect* myac, Module* HookMod) - : BufferedSocket(SI, shost, iport, maxtime, bindto), Utils(Util), Hook(HookMod), myautoconnect(myac) +TreeSocket::TreeSocket(SpanningTreeUtilities* Util, std::string shost, int iport, unsigned long maxtime, const std::string &ServerName, const std::string &bindto, Autoconnect* myac, Module* HookMod) + : Utils(Util), IP(shost), myautoconnect(myac) { - age = SI->Time(); + age = ServerInstance->Time(); myhost = ServerName; capab_phase = 0; proto_version = 0; LinkState = CONNECTING; + DoConnect(shost, iport, maxtime, bindto); Utils->timeoutlist[this] = std::pair<std::string, int>(ServerName, maxtime); - if (Hook) - BufferedSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send(); + if (HookMod) + BufferedSocketHookRequest(this, Utils->Creator, HookMod).Send(); hstimer = NULL; } @@ -52,18 +53,18 @@ TreeSocket::TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string sh * we must associate it with a socket without creating a new * connection. This constructor is used for this purpose. */ -TreeSocket::TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, int newfd, char* ip, Autoconnect* myac, Module* HookMod) - : BufferedSocket(SI, newfd, ip), Utils(Util), Hook(HookMod), myautoconnect(myac) +TreeSocket::TreeSocket(SpanningTreeUtilities* Util, int newfd, char* ip, Autoconnect* myac, Module* HookMod) + : BufferedSocket(newfd), Utils(Util), IP(ip), myautoconnect(myac) { - age = SI->Time(); + age = ServerInstance->Time(); LinkState = WAIT_AUTH_1; capab_phase = 0; proto_version = 0; /* If we have a transport module hooked to the parent, hook the same module to this * socket, and set a timer waiting for handshake before we send CAPAB etc. */ - if (Hook) - BufferedSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send(); + if (HookMod) + BufferedSocketHookRequest(this, Utils->Creator, HookMod).Send(); hstimer = new HandshakeTimer(ServerInstance, this, &(Utils->LinkBlocks[0]), this->Utils, 1); ServerInstance->Timers->AddTimer(hstimer); @@ -77,11 +78,6 @@ ServerState TreeSocket::GetLinkState() return this->LinkState; } -Module* TreeSocket::GetHook() -{ - return this->Hook; -} - void TreeSocket::CleanNegotiationInfo() { ModuleList.clear(); @@ -94,8 +90,8 @@ void TreeSocket::CleanNegotiationInfo() TreeSocket::~TreeSocket() { - if (Hook) - BufferedSocketUnhookRequest(this, (Module*)Utils->Creator, Hook).Send(); + if (GetIOHook()) + BufferedSocketUnhookRequest(this, Utils->Creator, GetIOHook()).Send(); if (hstimer) ServerInstance->Timers->DelTimer(hstimer); Utils->timeoutlist.erase(this); @@ -107,7 +103,7 @@ TreeSocket::~TreeSocket() * to server docs on the inspircd.org site, the other side * will then send back its own server string. */ -bool TreeSocket::OnConnected() +void TreeSocket::OnConnected() { if (this->LinkState == CONNECTING) { @@ -116,25 +112,17 @@ bool TreeSocket::OnConnected() { if (x->Name == this->myhost) { - ServerInstance->SNO->WriteToSnoMask('l', "Connection to \2%s\2[%s] started.", myhost.c_str(), (x->HiddenFromStats ? "<hidden>" : this->GetIP().c_str())); - if (Hook) - { - BufferedSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send(); - ServerInstance->SNO->WriteToSnoMask('l', "Connection to \2%s\2[%s] using transport \2%s\2", myhost.c_str(), (x->HiddenFromStats ? "<hidden>" : this->GetIP().c_str()), - x->Hook.c_str()); - } + ServerInstance->SNO->WriteToSnoMask('l', "Connection to \2%s\2[%s] started.", myhost.c_str(), (x->HiddenFromStats ? "<hidden>" : this->IP.c_str())); this->OutboundPass = x->SendPass; - - /* found who we're supposed to be connecting to, send the neccessary gubbins. */ - if (this->GetHook()) + if (GetIOHook()) { + ServerInstance->SNO->WriteToSnoMask('l', "Connection to \2%s\2[%s] using transport \2%s\2", myhost.c_str(), (x->HiddenFromStats ? "<hidden>" : this->IP.c_str()), x->Hook.c_str()); hstimer = new HandshakeTimer(ServerInstance, this, &(*x), this->Utils, 1); ServerInstance->Timers->AddTimer(hstimer); } else this->SendCapabilities(1); - - return true; + return; } } } @@ -144,7 +132,6 @@ bool TreeSocket::OnConnected() * and rather harmless. */ ServerInstance->SNO->WriteToSnoMask('l', "Connection to \2%s\2 lost link tag(!)", myhost.c_str()); - return true; } void TreeSocket::OnError(BufferedSocketError e) @@ -174,21 +161,11 @@ void TreeSocket::OnError(BufferedSocketError e) } } -int TreeSocket::OnDisconnect() -{ - /* For the same reason as above, we don't - * handle OnDisconnect() - */ - return true; -} - void TreeSocket::SendError(const std::string &errormessage) { /* Display the error locally as well as sending it remotely */ - ServerInstance->SNO->WriteToSnoMask('l', "Sent \2ERROR\2 to %s: %s", (this->InboundServerName.empty() ? this->GetIP().c_str() : this->InboundServerName.c_str()), errormessage.c_str()); - this->WriteLine("ERROR :"+errormessage); - /* One last attempt to make sure the error reaches its target */ - this->FlushWriteBuffer(); + ServerInstance->SNO->WriteToSnoMask('l', "Sent \2ERROR\2 to %s: %s", (this->InboundServerName.empty() ? this->IP.c_str() : this->InboundServerName.c_str()), errormessage.c_str()); + WriteLine("ERROR :"+errormessage); } /** This function forces this server to quit, removing this server @@ -232,12 +209,12 @@ void TreeSocket::Squit(TreeServer* Current, const std::string &reason) Utils->DoOneToAllButSender(Current->GetParent()->GetName(),"SQUIT",params,Current->GetName()); if (Current->GetParent() == Utils->TreeRoot) { - this->ServerInstance->SNO->WriteToSnoMask('l', "Server \002"+Current->GetName()+"\002 split: "+reason); + ServerInstance->SNO->WriteToSnoMask('l', "Server \002"+Current->GetName()+"\002 split: "+reason); LocalSquit = true; } else { - this->ServerInstance->SNO->WriteToSnoMask('L', "Server \002"+Current->GetName()+"\002 split from server \002"+Current->GetParent()->GetName()+"\002 with reason: "+reason); + ServerInstance->SNO->WriteToSnoMask('L', "Server \002"+Current->GetName()+"\002 split from server \002"+Current->GetParent()->GetName()+"\002 with reason: "+reason); } num_lost_servers = 0; num_lost_users = 0; @@ -247,56 +224,41 @@ void TreeSocket::Squit(TreeServer* Current, const std::string &reason) Current->GetParent()->DelChild(Current); delete Current; if (LocalSquit) - this->ServerInstance->SNO->WriteToSnoMask('l', "Netsplit complete, lost \002%d\002 users on \002%d\002 servers.", num_lost_users, num_lost_servers); + ServerInstance->SNO->WriteToSnoMask('l', "Netsplit complete, lost \002%d\002 users on \002%d\002 servers.", num_lost_users, num_lost_servers); else - this->ServerInstance->SNO->WriteToSnoMask('L', "Netsplit complete, lost \002%d\002 users on \002%d\002 servers.", num_lost_users, num_lost_servers); + ServerInstance->SNO->WriteToSnoMask('L', "Netsplit complete, lost \002%d\002 users on \002%d\002 servers.", num_lost_users, num_lost_servers); } else ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Squit from unknown server"); } /** This function is called when we receive data from a remote - * server. We buffer the data in a std::string (it doesnt stay - * there for long), reading using BufferedSocket::Read() which can - * read up to 16 kilobytes in one operation. - * - * IF THIS FUNCTION RETURNS FALSE, THE CORE CLOSES AND DELETES - * THE SOCKET OBJECT FOR US. + * server. */ -bool TreeSocket::OnDataReady() +void TreeSocket::OnDataReady() { - const char* data = this->Read(); - /* Check that the data read is a valid pointer and it has some content */ - if (data && *data) + Utils->Creator->loopCall = true; + /* While there is at least one new line in the buffer, + * do something useful (we hope!) with it. + */ + while (recvq.find("\n") != std::string::npos) { - this->in_buffer.append(data); - Utils->Creator->loopCall = true; - /* While there is at least one new line in the buffer, - * do something useful (we hope!) with it. + std::string ret = recvq.substr(0,recvq.find("\n")-1); + recvq = recvq.substr(recvq.find("\n")+1,recvq.length()-recvq.find("\n")); + /* Use rfind here not find, as theres more + * chance of the \r being near the end of the + * string, not the start. */ - while (in_buffer.find("\n") != std::string::npos) + if (ret.find("\r") != std::string::npos) + ret = recvq.substr(0,recvq.find("\r")-1); + /* Process this one, abort if it + * didnt return true. + */ + if (!this->ProcessLine(ret)) { - std::string ret = in_buffer.substr(0,in_buffer.find("\n")-1); - in_buffer = in_buffer.substr(in_buffer.find("\n")+1,in_buffer.length()-in_buffer.find("\n")); - /* Use rfind here not find, as theres more - * chance of the \r being near the end of the - * string, not the start. - */ - if (ret.find("\r") != std::string::npos) - ret = in_buffer.substr(0,in_buffer.find("\r")-1); - /* Process this one, abort if it - * didnt return true. - */ - if (!this->ProcessLine(ret)) - { - return false; - } + SetError("ProcessLine returned false"); + break; } - Utils->Creator->loopCall = false; - return true; } - /* EAGAIN returns an empty but non-NULL string, so this - * evaluates to TRUE for EAGAIN but to FALSE for EOF. - */ - return (data && !*data); + Utils->Creator->loopCall = false; } diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index 793802781..cf537f05b 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -32,7 +32,7 @@ bool TreeSocket::Error(parameterlist ¶ms) { if (params.size() < 1) return false; - this->ServerInstance->SNO->WriteToSnoMask('l',"ERROR from %s: %s",(!InboundServerName.empty() ? InboundServerName.c_str() : myhost.c_str()),params[0].c_str()); + ServerInstance->SNO->WriteToSnoMask('l',"ERROR from %s: %s",(!InboundServerName.empty() ? InboundServerName.c_str() : myhost.c_str()),params[0].c_str()); /* we will return false to cause the socket to close. */ return false; } @@ -126,9 +126,7 @@ bool TreeSocket::ProcessLine(std::string &line) } else { - // XXX ...wtf. - irc::string error = "Invalid command in negotiation phase: " + command; - this->SendError(assign(error)); + this->SendError(std::string("Invalid command in negotiation phase: ") + command.c_str()); return false; } break; @@ -171,7 +169,7 @@ bool TreeSocket::ProcessLine(std::string &line) Link* lnk = Utils->FindLink(InboundServerName); - Node = new TreeServer(this->Utils, this->ServerInstance, InboundServerName, InboundDescription, InboundSID, Utils->TreeRoot, this, lnk ? lnk->Hidden : false); + Node = new TreeServer(this->Utils, ServerInstance, InboundServerName, InboundDescription, InboundSID, Utils->TreeRoot, this, lnk ? lnk->Hidden : false); Utils->TreeRoot->AddChild(Node); parameterlist sparams; @@ -242,7 +240,7 @@ bool TreeSocket::ProcessLine(std::string &line) */ std::string direction = prefix; - User *t = this->ServerInstance->FindUUID(prefix); + User *t = ServerInstance->FindUUID(prefix); if (t) { /* Find UID */ @@ -316,7 +314,7 @@ bool TreeSocket::ProcessLine(std::string &line) } else if ((command == "NOTICE" || command == "PRIVMSG") && (Utils->IsServer(prefix))) { - return this->ServerMessage(assign(command), prefix, params, sourceserv); + return ServerMessage(assign(command), prefix, params, sourceserv); } else if (command == "STATS") { @@ -487,7 +485,7 @@ bool TreeSocket::ProcessLine(std::string &line) // Set prefix server as bursting if (!ServerSource) { - this->ServerInstance->SNO->WriteToSnoMask('l', "WTF: Got BURST from a nonexistant server(?): %s", (ServerSource ? ServerSource->GetName().c_str() : prefix.c_str())); + ServerInstance->SNO->WriteToSnoMask('l', "WTF: Got BURST from a nonexistant server(?): %s", (ServerSource ? ServerSource->GetName().c_str() : prefix.c_str())); return false; } @@ -498,7 +496,7 @@ bool TreeSocket::ProcessLine(std::string &line) { if (!ServerSource) { - this->ServerInstance->SNO->WriteToSnoMask('l', "WTF: Got ENDBURST from a nonexistant server(?): %s", (ServerSource ? ServerSource->GetName().c_str() : prefix.c_str())); + ServerInstance->SNO->WriteToSnoMask('l', "WTF: Got ENDBURST from a nonexistant server(?): %s", (ServerSource ? ServerSource->GetName().c_str() : prefix.c_str())); return false; } @@ -515,7 +513,7 @@ bool TreeSocket::ProcessLine(std::string &line) * Not a special s2s command. Emulate the user doing it. * This saves us having a huge ugly command parser again. */ - User* who = this->ServerInstance->FindUUID(prefix); + User* who = ServerInstance->FindUUID(prefix); if (ServerSource) { @@ -546,7 +544,7 @@ bool TreeSocket::ProcessLine(std::string &line) * On nick messages, check that the nick doesnt already exist here. * If it does, perform collision logic. */ - User* x = this->ServerInstance->FindNickOnly(params[0]); + User* x = ServerInstance->FindNickOnly(params[0]); if ((x) && (x != who)) { int collideret = 0; @@ -564,7 +562,7 @@ bool TreeSocket::ProcessLine(std::string &line) } } - switch (this->ServerInstance->CallCommandHandler(command.c_str(), params, who)) + switch (ServerInstance->CallCommandHandler(command.c_str(), params, who)) { case CMD_INVALID: /* @@ -607,13 +605,15 @@ void TreeSocket::OnTimeout() { if (this->LinkState == CONNECTING) { - this->ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str()); + ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str()); Utils->DoFailOver(myautoconnect); } } -void TreeSocket::OnClose() +void TreeSocket::Close() { + this->BufferedSocket::Close(); + // Test fix for big fuckup if (this->LinkState != CONNECTED) return; @@ -634,10 +634,10 @@ void TreeSocket::OnClose() if (!quitserver.empty()) { - this->ServerInstance->SNO->WriteToSnoMask('l', "Connection to '\2%s\2' failed.",quitserver.c_str()); + ServerInstance->SNO->WriteToSnoMask('l', "Connection to '\2%s\2' failed.",quitserver.c_str()); time_t server_uptime = ServerInstance->Time() - this->age; if (server_uptime) - this->ServerInstance->SNO->WriteToSnoMask('l', "Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str()); + ServerInstance->SNO->WriteToSnoMask('l', "Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str()); } } diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp index b7c13b5f8..0f0e75a1d 100644 --- a/src/modules/m_spanningtree/uid.cpp +++ b/src/modules/m_spanningtree/uid.cpp @@ -64,9 +64,9 @@ bool TreeSocket::ParseUID(const std::string &source, parameterlist ¶ms) } /* check for collision */ - user_hash::iterator iter = this->ServerInstance->Users->clientlist->find(params[2]); + user_hash::iterator iter = ServerInstance->Users->clientlist->find(params[2]); - if (iter != this->ServerInstance->Users->clientlist->end()) + if (iter != ServerInstance->Users->clientlist->end()) { /* * Nick collision. @@ -87,19 +87,19 @@ bool TreeSocket::ParseUID(const std::string &source, parameterlist ¶ms) User* _new = NULL; try { - _new = new User(this->ServerInstance, params[0]); + _new = new User(ServerInstance, params[0]); } catch (...) { this->SendError("Protocol violation - Duplicate UUID '" + params[0] + "' on introduction of new user"); return false; } - (*(this->ServerInstance->Users->clientlist))[params[2]] = _new; + (*(ServerInstance->Users->clientlist))[params[2]] = _new; _new->SetFd(FD_MAGIC_NUMBER); _new->nick.assign(params[2], 0, MAXBUF); _new->host.assign(params[3], 0, 64); _new->dhost.assign(params[4], 0, 64); - _new->server = this->ServerInstance->FindServerNamePtr(remoteserver->GetName().c_str()); + _new->server = ServerInstance->FindServerNamePtr(remoteserver->GetName().c_str()); _new->ident.assign(params[5], 0, MAXBUF); _new->fullname.assign(params[params.size() - 1], 0, MAXBUF); _new->registered = REG_ALL; @@ -164,11 +164,11 @@ bool TreeSocket::ParseUID(const std::string &source, parameterlist ¶ms) bool dosend = true; - if ((this->Utils->quiet_bursts && remoteserver->bursting) || this->ServerInstance->SilentULine(_new->server)) + if ((this->Utils->quiet_bursts && remoteserver->bursting) || ServerInstance->SilentULine(_new->server)) dosend = false; if (dosend) - this->ServerInstance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s!%s@%s [%s] [%s]", _new->server, _new->nick.c_str(), _new->ident.c_str(), _new->host.c_str(), _new->GetIPString(), _new->fullname.c_str()); + ServerInstance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s!%s@%s [%s] [%s]", _new->server, _new->nick.c_str(), _new->ident.c_str(), _new->host.c_str(), _new->GetIPString(), _new->fullname.c_str()); params[params.size() - 1] = ":" + params[params.size() - 1]; Utils->DoOneToAllButSender(source, "UID", params, source); diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index b37aecc4b..8d3c55758 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -49,19 +49,18 @@ void ServerSocketListener::OnAcceptReady(int newsock) if (!found) { - this->ServerInstance->SNO->WriteToSnoMask('l', "Server connection from %s denied (no link blocks with that IP address)", ip); + ServerInstance->SNO->WriteToSnoMask('l', "Server connection from %s denied (no link blocks with that IP address)", ip); ServerInstance->SE->Close(newsock); return; } } - if (this->GetIOHook()) - { - this->GetIOHook()->OnRawSocketAccept(newsock, &client, &server); - } + /* we don't need to do anything with the pointer, creating it stores it in the necessary places */ + TreeSocket* ts = new TreeSocket(Utils, newsock, ip, NULL, Hook); + + if (Hook) + Hook->OnStreamSocketAccept(ts, &client, &server); - /* we don't need a pointer to this, creating it stores it in the necessary places */ - new TreeSocket(this->Utils, this->ServerInstance, newsock, ip, NULL, this->GetIOHook()); return; } @@ -73,7 +72,7 @@ void ServerSocketListener::OnAcceptReady(int newsock) */ TreeServer* SpanningTreeUtilities::FindServer(const std::string &ServerName) { - if (this->ServerInstance->IsSID(ServerName)) + if (ServerInstance->IsSID(ServerName)) return this->FindServerID(ServerName); server_hash::iterator iter = serverlist.find(ServerName.c_str()); @@ -150,12 +149,10 @@ bool SpanningTreeUtilities::IsServer(const std::string &ServerName) SpanningTreeUtilities::SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* C) : ServerInstance(Instance), Creator(C) { - Bindings.clear(); - ServerInstance->Logs->Log("m_spanningtree",DEBUG,"***** Using SID for hash: %s *****", ServerInstance->Config->GetSID().c_str()); this->TreeRoot = new TreeServer(this, ServerInstance, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc, ServerInstance->Config->GetSID()); - this->ServerUser = new FakeUser(ServerInstance, TreeRoot->GetID()); + ServerUser = new FakeUser(ServerInstance, TreeRoot->GetID()); this->ReadConfiguration(true); } @@ -182,7 +179,6 @@ SpanningTreeUtilities::~SpanningTreeUtilities() ServerUser->uuid = TreeRoot->GetID(); delete TreeRoot; delete ServerUser; - ServerInstance->BufferedSocketCull(); } void SpanningTreeUtilities::AddThisServer(TreeServer* server, TreeServerList &list) @@ -465,7 +461,6 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind) { delete Bindings[i]; } - ServerInstance->BufferedSocketCull(); Bindings.clear(); for (int j = 0; j < Conf->Enumerate("bind"); j++) @@ -498,7 +493,7 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind) } if (!transport.empty()) - listener->AddIOHook(hooks[transport.c_str()]); + listener->Hook = hooks[transport.c_str()]; Bindings.push_back(listener); } @@ -656,7 +651,7 @@ void SpanningTreeUtilities::DoFailOver(Autoconnect* x) { if (x->FailOver == x->Server) { - this->ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Some muppet configured the failover for server \002%s\002 to point at itself. Not following it!", x->Server.c_str()); + ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Some muppet configured the failover for server \002%s\002 to point at itself. Not following it!", x->Server.c_str()); return; } Link* TryThisOne = this->FindLink(x->FailOver.c_str()); @@ -669,13 +664,13 @@ void SpanningTreeUtilities::DoFailOver(Autoconnect* x) } else { - this->ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Server.c_str(), TryThisOne->Name.c_str()); + ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Server.c_str(), TryThisOne->Name.c_str()); Creator->ConnectServer(TryThisOne, NULL); } } else { - this->ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Server.c_str()); + ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Server.c_str()); } } } diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index 09c707131..1bdf127d8 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -47,8 +47,11 @@ class ServerSocketListener : public ListenSocketBase ServerSocketListener(InspIRCd* Instance, SpanningTreeUtilities *u, int port, char* addr) : ListenSocketBase(Instance, port, addr) { this->Utils = u; + Hook = NULL; } + Module* Hook; + virtual void OnAcceptReady(int nfd); }; diff --git a/src/modules/m_spanningtree/whois.cpp b/src/modules/m_spanningtree/whois.cpp index f12a7f109..79e2d7355 100644 --- a/src/modules/m_spanningtree/whois.cpp +++ b/src/modules/m_spanningtree/whois.cpp @@ -28,13 +28,13 @@ bool TreeSocket::Whois(const std::string &prefix, parameterlist ¶ms) { if (params.size() < 1) return true; - User* u = this->ServerInstance->FindNick(prefix); + User* u = ServerInstance->FindNick(prefix); if (u) { // an incoming request if (params.size() == 1) { - User* x = this->ServerInstance->FindNick(params[0]); + User* x = ServerInstance->FindNick(params[0]); if ((x) && (IS_LOCAL(x))) { char signon[MAXBUF]; @@ -58,7 +58,7 @@ bool TreeSocket::Whois(const std::string &prefix, parameterlist ¶ms) else if (params.size() == 3) { std::string who_did_the_whois = params[0]; - User* who_to_send_to = this->ServerInstance->FindNick(who_did_the_whois); + User* who_to_send_to = ServerInstance->FindNick(who_did_the_whois); if ((who_to_send_to) && (IS_LOCAL(who_to_send_to))) { // an incoming reply to a whois we sent out |