diff options
author | Adam <Adam@anope.org> | 2016-09-23 15:46:03 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2016-09-23 15:46:03 -0400 |
commit | 2916943316c0d3c53d347fb43abe98a374c75e36 (patch) | |
tree | 45611b5583dca607e9a513b6b2f7d88975c56231 /src | |
parent | a6b14a9fb6afc5e16874ed7e4c0a135a4f5bfa53 (diff) |
Remove rfc1459 message framing everywhere
Diffstat (limited to 'src')
-rw-r--r-- | src/process.cpp | 23 | ||||
-rw-r--r-- | src/protocol.cpp | 68 | ||||
-rw-r--r-- | src/uplink.cpp | 43 |
3 files changed, 72 insertions, 62 deletions
diff --git a/src/process.cpp b/src/process.cpp index c110394fc..356a3b695 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -105,11 +105,26 @@ void IRCDProto::Parse(const Anope::string &buffer, Anope::string &source, Anope: } } -Anope::string IRCDProto::Format(const Anope::string &source, const Anope::string &message) +Anope::string IRCDProto::Format(IRCMessage &message) { + std::stringstream buffer; + + const Anope::string &source = message.GetSource().GetUID(); if (!source.empty()) - return ":" + source + " " + message; - else - return message; + buffer << ":" << source << " "; + + buffer << message.GetCommand(); + + for (unsigned int i = 0; i < message.GetParameters().size(); ++i) + { + buffer << " "; + + if (i + 1 == message.GetParameters().size()) + buffer << ":"; + + buffer << message.GetParameters()[i]; + } + + return buffer.str(); } diff --git a/src/protocol.cpp b/src/protocol.cpp index 057651d3b..c5b555cad 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -104,61 +104,65 @@ Anope::string IRCDProto::SID_Retrieve() void IRCDProto::SendKill(const MessageSource &source, const Anope::string &target, const Anope::string &reason) { - UplinkSocket::Message(source) << "KILL " << target << " :" << reason; + Uplink::Send(source, "KILL", target, reason); } void IRCDProto::SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) { - UplinkSocket::Message(source) << "KILL " << user->GetUID() << " :" << buf; + Uplink::Send(source, "KILL", user->GetUID(), buf); } void IRCDProto::SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) { - UplinkSocket::Message(source) << "MODE " << dest->name << " " << buf; + IRCMessage message(source, "MODE", dest->name); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } void IRCDProto::SendModeInternal(const MessageSource &source, User *dest, const Anope::string &buf) { - UplinkSocket::Message(source) << "MODE " << dest->GetUID() << " " << buf; + IRCMessage message(source, "MODE", dest->GetUID()); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } void IRCDProto::SendKickInternal(const MessageSource &source, const Channel *c, User *u, const Anope::string &r) { if (!r.empty()) - UplinkSocket::Message(source) << "KICK " << c->name << " " << u->GetUID() << " :" << r; + Uplink::Send(source, "KICK", c->name, u->GetUID(), r); else - UplinkSocket::Message(source) << "KICK " << c->name << " " << u->GetUID(); + Uplink::Send(source, "KICK", c->name, u->GetUID()); } void IRCDProto::SendNoticeInternal(const MessageSource &source, const Anope::string &dest, const Anope::string &msg) { - UplinkSocket::Message(source) << "NOTICE " << dest << " :" << msg; + Uplink::Send(source, "NOTICE", dest, msg); } void IRCDProto::SendPrivmsgInternal(const MessageSource &source, const Anope::string &dest, const Anope::string &buf) { - UplinkSocket::Message(source) << "PRIVMSG " << dest << " :" << buf; + Uplink::Send(source, "PRIVMSG", dest, buf); } void IRCDProto::SendQuitInternal(User *u, const Anope::string &buf) { if (!buf.empty()) - UplinkSocket::Message(u) << "QUIT :" << buf; + Uplink::Send(u, "QUIT", buf); else - UplinkSocket::Message(u) << "QUIT"; + Uplink::Send(u, "QUIT"); } void IRCDProto::SendPartInternal(User *u, const Channel *chan, const Anope::string &buf) { if (!buf.empty()) - UplinkSocket::Message(u) << "PART " << chan->name << " :" << buf; + Uplink::Send(u, "PART", chan->name, buf); else - UplinkSocket::Message(u) << "PART " << chan->name; + Uplink::Send(u, "PART", chan->name); } void IRCDProto::SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) { - UplinkSocket::Message(source) << "GLOBOPS :" << buf; + Uplink::Send(source, "GLOBOPS", buf); } void IRCDProto::SendCTCPInternal(const MessageSource &source, const Anope::string &dest, const Anope::string &buf) @@ -174,12 +178,15 @@ void IRCDProto::SendNumericInternal(int numeric, const Anope::string &dest, cons n = "0" + n; if (numeric < 100) n = "0" + n; - UplinkSocket::Message(Me) << n << " " << dest << " " << buf; + + IRCMessage message(Me, n, dest); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } void IRCDProto::SendTopic(const MessageSource &source, Channel *c) { - UplinkSocket::Message(source) << "TOPIC " << c->name << " :" << c->topic; + Uplink::Send(source, "TOPIC", c->name, c->topic); } void IRCDProto::SendSVSKill(const MessageSource &source, User *user, const char *fmt, ...) @@ -272,28 +279,22 @@ void IRCDProto::SendQuit(User *u, const char *fmt, ...) void IRCDProto::SendPing(const Anope::string &servname, const Anope::string &who) { if (servname.empty()) - UplinkSocket::Message(Me) << "PING " << who; + Uplink::Send(Me, "PING", who); else - UplinkSocket::Message(Me) << "PING " << servname << " " << who; + Uplink::Send(Me, "PING", servname, who); } -/** - * Send a PONG reply to a received PING. - * servname should be left NULL to send a one param reply. - * @param servname Daemon or client that is responding to the PING. - * @param who Origin of the PING and destination of the PONG message. - **/ void IRCDProto::SendPong(const Anope::string &servname, const Anope::string &who) { if (servname.empty()) - UplinkSocket::Message(Me) << "PONG " << who; + Uplink::Send(Me, "PONG", who); else - UplinkSocket::Message(Me) << "PONG " << servname << " " << who; + Uplink::Send(Me, "PONG", servname, who); } void IRCDProto::SendInvite(const MessageSource &source, const Channel *c, User *u) { - UplinkSocket::Message(source) << "INVITE " << u->GetUID() << " " << c->name; + Uplink::Send(source, "INVITE", u->GetUID(), c->name); } void IRCDProto::SendPart(User *user, const Channel *chan, const char *fmt, ...) @@ -323,17 +324,17 @@ void IRCDProto::SendGlobops(const MessageSource &source, const char *fmt, ...) void IRCDProto::SendSquit(Server *s, const Anope::string &message) { - UplinkSocket::Message() << "SQUIT " << s->GetSID() << " :" << message; + Uplink::Send("SQUIT", s->GetSID(), message); } void IRCDProto::SendNickChange(User *u, const Anope::string &newnick) { - UplinkSocket::Message(u) << "NICK " << newnick << " " << Anope::CurTime; + Uplink::Send(u, "NICK", newnick, Anope::CurTime); } void IRCDProto::SendForceNickChange(User *u, const Anope::string &newnick, time_t when) { - UplinkSocket::Message() << "SVSNICK " << u->GetUID() << " " << newnick << " " << when; + Uplink::Send(u, "SVSNICK", u->GetUID(), newnick, when); } void IRCDProto::SendCTCP(const MessageSource &source, const Anope::string &dest, const char *fmt, ...) @@ -482,6 +483,15 @@ const Anope::string &MessageSource::GetName() const return this->source; } +const Anope::string &MessageSource::GetUID() const +{ + if (this->s) + return this->s->GetSID(); + if (this->u) + return this->u->GetUID(); + return this->source; +} + const Anope::string &MessageSource::GetSource() const { return this->source; diff --git a/src/uplink.cpp b/src/uplink.cpp index ac262543f..c2b7579c5 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -166,60 +166,45 @@ void UplinkSocket::OnError(const Anope::string &err) error |= !err.empty(); } -UplinkSocket::Message::Message() : source(Me) +void Uplink::SendMessage(IRCMessage &message) { -} + const MessageSource &source = message.GetSource(); + Anope::string buffer = IRCD->Format(message); -UplinkSocket::Message::Message(const MessageSource &src) : source(src) -{ -} - -UplinkSocket::Message::~Message() -{ - Anope::string message_source; - - if (this->source.GetServer() != NULL) + if (source.GetServer() != NULL) { - const Server *s = this->source.GetServer(); + const Server *s = source.GetServer(); if (s != Me && !s->IsJuped()) { - Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << s->GetName() << " who is not from me?"; + Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" from " << s->GetName() << " who is not from me?"; return; } - - message_source = s->GetSID(); } - else if (this->source.GetUser() != NULL) + else if (source.GetUser() != NULL) { - const User *u = this->source.GetUser(); + const User *u = source.GetUser(); if (u->server != Me && !u->server->IsJuped()) { - Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << u->nick << " who is not from me?"; + Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" from " << u->nick << " who is not from me?"; return; } - const ServiceBot *bi = this->source.GetBot(); + const ServiceBot *bi = source.GetBot(); if (bi != NULL && bi->introduced == false) { - Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << bi->nick << " when not introduced"; + Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" from " << bi->nick << " when not introduced"; return; } - - message_source = u->GetUID(); } if (!UplinkSock) { - if (!message_source.empty()) - Log(LOG_DEBUG) << "Attempted to send \"" << message_source << " " << this->buffer.str() << "\" with UplinkSock NULL"; - else - Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" with UplinkSock NULL"; + Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" with UplinkSock NULL"; return; } - Anope::string sent = IRCD->Format(message_source, this->buffer.str()); - UplinkSock->Write(sent); - Log(LOG_RAWIO) << "Sent: " << sent; + UplinkSock->Write(buffer); + Log(LOG_RAWIO) << "Sent: " << buffer; } |