}
-void IrcServerHandler::defaultHandler(QString cmd, QString prefix, QList<QByteArray> rawparams) {
+void IrcServerHandler::defaultHandler(QString cmd, const QString &prefix, const QList<QByteArray> &rawparams) {
// we assume that all this happens in server encoding
QStringList params;
foreach(QByteArray r, rawparams) params << serverDecode(r);
//******************************/
// IRC SERVER HANDLER
//******************************/
-void IrcServerHandler::handleJoin(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handleJoin(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_ASSERT(params.count() == 1);
QString channel = serverDecode(params[0]);
IrcUser *ircuser = network()->updateNickFromMask(prefix);
ircuser->joinChannel(channel);
}
-void IrcServerHandler::handleKick(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handleKick(const QString &prefix, const QList<QByteArray> ¶ms) {
network()->updateNickFromMask(prefix);
IrcUser *victim = network()->ircUser(params[1]);
QString channel = serverDecode(params[0]);
emit displayMsg(Message::Kick, BufferInfo::ChannelBuffer, channel, msg, prefix);
}
-void IrcServerHandler::handleMode(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handleMode(const QString &prefix, const QList<QByteArray> ¶ms) {
if(params.count() < 2) {
emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Received invalid MODE from %s: %s").arg(prefix).arg(serverDecode(params).join(" ")));
return;
// Channel Modes
emit displayMsg(Message::Mode, BufferInfo::ChannelBuffer, serverDecode(params[0]), serverDecode(params).join(" "), prefix);
- IrcChannel *channel = network()->ircChannel(params.takeFirst());
+ IrcChannel *channel = network()->ircChannel(params[0]);
// FIXME: currently the IrcChannels only support PREFIX-Modes for users
// This cannot be fixed unless the SignalProxy() doesn't rely on methodIds anymore
- QString modes = params.takeFirst();
+ QString modes = params[1];
bool add = true;
int modeIndex = 0;
for(int c = 0; c < modes.length(); c++) {
}
}
-void IrcServerHandler::handleNick(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handleNick(const QString &prefix, const QList<QByteArray> ¶ms) {
IrcUser *ircuser = network()->updateNickFromMask(prefix);
Q_ASSERT(ircuser);
QString newnick = serverDecode(params[0]);
ircuser->setNick(newnick);
}
-void IrcServerHandler::handleNotice(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handleNotice(const QString &prefix, const QList<QByteArray> ¶ms) {
if(params.count() < 2) {
qWarning() << "IrcServerHandler::handleNotice(): not enough Parameters:" << prefix << serverDecode(params);
return;
networkConnection()->ctcpHandler()->parse(Message::Notice, sender, target, userDecode(sender, params[1]));
}
-void IrcServerHandler::handlePart(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handlePart(const QString &prefix, const QList<QByteArray> ¶ms) {
IrcUser *ircuser = network()->updateNickFromMask(prefix);
QString channel = serverDecode(params[0]);
Q_ASSERT(ircuser);
emit displayMsg(Message::Part, BufferInfo::ChannelBuffer, channel, msg, prefix);
}
-void IrcServerHandler::handlePing(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handlePing(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix);
putCmd("PONG", params);
}
-void IrcServerHandler::handlePrivmsg(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handlePrivmsg(const QString &prefix, const QList<QByteArray> ¶ms) {
IrcUser *ircuser = network()->updateNickFromMask(prefix);
Q_ASSERT(ircuser);
- if(params.count() < 2)
- params << QByteArray("");
+ if(params.isEmpty()) {
+ qWarning() << "IrcServerHandler::handlePrivmsg(): received PRIVMSG without target or message from:" << prefix;
+ return;
+ }
+
QString target = serverDecode(params[0]);
+ QByteArray msg = params.count() < 2
+ ? QByteArray("")
+ : params[1];
+
// are we the target?
if(network()->isMyNick(target))
target = nickFromMask(ircuser->nick());
// it's possible to pack multiple privmsgs into one param using ctcp
// - > we let the ctcpHandler do the work
- networkConnection()->ctcpHandler()->parse(Message::Plain, prefix, target, userDecode(ircuser->nick(), params[1]));
+ networkConnection()->ctcpHandler()->parse(Message::Plain, prefix, target, userDecode(ircuser->nick(), msg));
}
-void IrcServerHandler::handleQuit(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handleQuit(const QString &prefix, const QList<QByteArray> ¶ms) {
IrcUser *ircuser = network()->updateNickFromMask(prefix);
Q_ASSERT(ircuser);
network()->removeIrcUser(nickFromMask(prefix));
}
-void IrcServerHandler::handleTopic(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handleTopic(const QString &prefix, const QList<QByteArray> ¶ms) {
IrcUser *ircuser = network()->updateNickFromMask(prefix);
QString channel = serverDecode(params[0]);
QString topic = channelDecode(channel, params[1]);
}
/* RPL_WELCOME */
-void IrcServerHandler::handle001(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle001(const QString &prefix, const QList<QByteArray> ¶ms) {
// there should be only one param: "Welcome to the Internet Relay Network <nick>!<user>@<host>"
QString param = serverDecode(params[0]);
QString myhostmask = param.section(' ', -1, -1);
/* RPL_ISUPPORT */
// TODO Complete 005 handling, also use sensible defaults for non-sent stuff
-void IrcServerHandler::handle005(QString prefix, QList<QByteArray> params) {
- Q_UNUSED(prefix)
- QString rpl_isupport_suffix = serverDecode(params.takeLast());
- if(rpl_isupport_suffix.toLower() != QString("are supported by this server")) {
+void IrcServerHandler::handle005(const QString &prefix, const QList<QByteArray> ¶ms) {
+ Q_UNUSED(prefix);
+ const int numParams = params.size();
+ if(numParams < 1) {
+ qWarning() << "IrcServerHandler::handle005(): received RPL_ISUPPORT (005) with too few parameters:" << serverDecode(params);
+ return;
+ }
+
+ QString rpl_isupport_suffix = serverDecode(params.last());
+ if(!rpl_isupport_suffix.toLower().contains("supported")) {
qWarning() << "Received invalid RPL_ISUPPORT! Suffix is:" << rpl_isupport_suffix << "Excpected: are supported by this server";
return;
}
-
- foreach(QString param, serverDecode(params)) {
- QString key = param.section("=", 0, 0);
- QString value = param.section("=", 1);
+
+ QString rawSupport;
+ QString key, value;
+ for(int i = 0; i < numParams - 1; i++) {
+ QString rawSupport = serverDecode(params[i]);
+ QString key = rawSupport.section("=", 0, 0);
+ QString value = rawSupport.section("=", 1);
network()->addSupport(key, value);
}
}
/* RPL_AWAY - "<nick> :<away message>" */
-void IrcServerHandler::handle301(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle301(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix);
QString nickName = serverDecode(params[0]);
QString awayMessage = userDecode(nickName, params.last());
}
/* RPL_WHOISUSER - "<nick> <user> <host> * :<real name>" */
-void IrcServerHandler::handle311(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle311(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix)
_whois = true;
IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
}
/* RPL_WHOISSERVER - "<nick> <server> :<server info>" */
-void IrcServerHandler::handle312(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle312(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix)
IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
if(ircuser) {
}
/* RPL_WHOISOPERATOR - "<nick> :is an IRC operator" */
-void IrcServerHandler::handle313(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle313(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix)
IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
if(ircuser) {
}
/* RPL_WHOWASUSER - "<nick> <user> <host> * :<real name>" */
-void IrcServerHandler::handle314(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle314(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix)
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whowas] %1").arg(serverDecode(params).join(" ")));
}
/* RPL_ENDOFWHO: "<name> :End of WHO list" */
-void IrcServerHandler::handle315(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle315(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix)
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Who] %1").arg(serverDecode(params).join(" ")));
}
/* RPL_WHOISIDLE - "<nick> <integer> :seconds idle"
(real life: "<nick> <integer> <integer> :seconds idle, signon time) */
//TODO: parse real life message
-void IrcServerHandler::handle317(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle317(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix);
QString nick = serverDecode(params[0]);
IrcUser *ircuser = network()->ircUser(nick);
}
/* RPL_ENDOFWHOIS - "<nick> :End of WHOIS list" */
-void IrcServerHandler::handle318(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle318(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix)
_whois = false;
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(serverDecode(params).join(" ")));
}
/* RPL_WHOISCHANNELS - "<nick> :*( ( "@" / "+" ) <channel> " " )" */
-void IrcServerHandler::handle319(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle319(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix)
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(serverDecode(params).join(" ")));
}
/* RPL_NOTOPIC */
-void IrcServerHandler::handle331(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle331(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix);
QString channel = serverDecode(params[0]);
network()->ircChannel(channel)->setTopic(QString());
}
/* RPL_TOPIC */
-void IrcServerHandler::handle332(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle332(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix);
QString channel = serverDecode(params[0]);
QString topic = channelDecode(channel, params[1]);
}
/* Topic set by... */
-void IrcServerHandler::handle333(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle333(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix);
QString channel = serverDecode(params[0]);
emit displayMsg(Message::Server, BufferInfo::ChannelBuffer, channel,
/* RPL_WHOREPLY: "<channel> <user> <host> <server> <nick>
( "H" / "G" > ["*"] [ ( "@" / "+" ) ] :<hopcount> <real name>" */
-void IrcServerHandler::handle352(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle352(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix)
QString channel = serverDecode(params[0]);
IrcUser *ircuser = network()->ircUser(serverDecode(params[4]));
}
/* RPL_NAMREPLY */
-void IrcServerHandler::handle353(QString prefix, QList<QByteArray> params) {
- Q_UNUSED(prefix)
- params.removeFirst(); // either "=", "*" or "@" indicating a public, private or secret channel
- QString channelname = serverDecode(params.takeFirst());
+void IrcServerHandler::handle353(const QString &prefix, const QList<QByteArray> ¶ms) {
+ Q_UNUSED(prefix);
+ const int numParams = params.count();
+ if(numParams < 2) {
+ qWarning() << "IrcServerHandler::handler353() received not enough params:" << serverDecode(params);
+ return;
+ }
+
+ // param[0] is either "=", "*" or "@" indicating a public, private or secret channel
+ // we don't use this information at the time beeing
+ QString channelname = serverDecode(params[1]);
- foreach(QString nick, serverDecode(params.takeFirst()).split(' ')) {
+ foreach(QString nick, serverDecode(params[2]).split(' ')) {
QString mode = QString();
if(network()->prefixes().contains(nick[0])) {
}
/* RPL_ENDOFWHOWAS - "<nick> :End of WHOWAS" */
-void IrcServerHandler::handle369(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle369(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix)
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whowas] %1").arg(serverDecode(params).join(" ")));
}
/* ERR_ERRONEUSNICKNAME */
-void IrcServerHandler::handle432(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle432(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix);
if(params.size() < 2) {
}
/* ERR_NICKNAMEINUSE */
-void IrcServerHandler::handle433(QString prefix, QList<QByteArray> params) {
+void IrcServerHandler::handle433(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix);
QString errnick = serverDecode(params[0]);
void handleServerMsg(QByteArray rawMsg);
public slots:
- void handleJoin(QString, QList<QByteArray>);
- void handleKick(QString, QList<QByteArray>);
- void handleMode(QString, QList<QByteArray>);
- void handleNick(QString, QList<QByteArray>);
- void handleNotice(QString, QList<QByteArray>);
- void handlePart(QString, QList<QByteArray>);
- void handlePing(QString, QList<QByteArray>);
- void handlePrivmsg(QString, QList<QByteArray>);
- void handleQuit(QString, QList<QByteArray>);
- void handleTopic(QString, QList<QByteArray>);
+ void handleJoin(const QString &prefix, const QList<QByteArray> ¶ms);
+ void handleKick(const QString &prefix, const QList<QByteArray> ¶ms);
+ void handleMode(const QString &prefix, const QList<QByteArray> ¶ms);
+ void handleNick(const QString &prefix, const QList<QByteArray> ¶ms);
+ void handleNotice(const QString &prefix, const QList<QByteArray> ¶ms);
+ void handlePart(const QString &prefix, const QList<QByteArray> ¶ms);
+ void handlePing(const QString &prefix, const QList<QByteArray> ¶ms);
+ void handlePrivmsg(const QString &prefix, const QList<QByteArray> ¶ms);
+ void handleQuit(const QString &prefix, const QList<QByteArray> ¶ms);
+ void handleTopic(const QString &prefix, const QList<QByteArray> ¶ms);
- void handle001(QString, QList<QByteArray>); // RPL_WELCOME
- void handle005(QString, QList<QByteArray>); // RPL_ISUPPORT
- void handle301(QString, QList<QByteArray>); // RPL_AWAY
- void handle311(QString, QList<QByteArray>); // RPL_WHOISUSER
- void handle312(QString, QList<QByteArray>); // RPL_WHOISSERVER
- void handle313(QString, QList<QByteArray>); // RPL_WHOISOPERATOR
- void handle314(QString, QList<QByteArray>); // RPL_WHOWASUSER
- void handle315(QString, QList<QByteArray>); // RPL_ENDOFWHO
- void handle317(QString, QList<QByteArray>); // RPL_WHOISIDLE
- void handle318(QString, QList<QByteArray>); // RPL_ENDOFWHOIS
- void handle319(QString, QList<QByteArray>); // RPL_WHOISCHANNELS
- void handle331(QString, QList<QByteArray>); // RPL_NOTOPIC
- void handle332(QString, QList<QByteArray>); // RPL_TOPIC
- void handle333(QString, QList<QByteArray>); // Topic set by...
- void handle352(QString, QList<QByteArray>); // RPL_WHOREPLY
- void handle353(QString, QList<QByteArray>); // RPL_NAMREPLY
- void handle369(QString, QList<QByteArray>); // RPL_ENDOFWHOWAS
- void handle432(QString, QList<QByteArray>); // ERR_ERRONEUSNICKNAME
- void handle433(QString, QList<QByteArray>); // ERR_NICKNAMEINUSE
+ void handle001(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_WELCOME
+ void handle005(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_ISUPPORT
+ void handle301(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_AWAY
+ void handle311(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_WHOISUSER
+ void handle312(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_WHOISSERVER
+ void handle313(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_WHOISOPERATOR
+ void handle314(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_WHOWASUSER
+ void handle315(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_ENDOFWHO
+ void handle317(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_WHOISIDLE
+ void handle318(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_ENDOFWHOIS
+ void handle319(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_WHOISCHANNELS
+ void handle331(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_NOTOPIC
+ void handle332(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_TOPIC
+ void handle333(const QString &prefix, const QList<QByteArray> ¶ms); // Topic set by...
+ void handle352(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_WHOREPLY
+ void handle353(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_NAMREPLY
+ void handle369(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_ENDOFWHOWAS
+ void handle432(const QString &prefix, const QList<QByteArray> ¶ms); // ERR_ERRONEUSNICKNAME
+ void handle433(const QString &prefix, const QList<QByteArray> ¶ms); // ERR_NICKNAMEINUSE
- void defaultHandler(QString cmd, QString prefix, QList<QByteArray> params);
+ void defaultHandler(QString cmd, const QString &prefix, const QList<QByteArray> ¶ms);
private:
void tryNextNick(const QString &errnick);