-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 33 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.h | 3 | ||||
-rw-r--r-- | noncore/net/opieirc/ircoutput.h | 3 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 12 |
4 files changed, 49 insertions, 2 deletions
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp index 5c70753..d1b70a5 100644 --- a/noncore/net/opieirc/ircmessageparser.cpp +++ b/noncore/net/opieirc/ircmessageparser.cpp @@ -1,86 +1,89 @@ #include <qtextstream.h> #include "ircmessageparser.h" #include "ircversion.h" /* Lookup table for literal commands */ IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { { "PING", FUNC(parseLiteralPing) }, { "NOTICE", FUNC(parseLiteralNotice) }, { "JOIN", FUNC(parseLiteralJoin) }, { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, { "NICK", FUNC(parseLiteralNick) }, { "PART", FUNC(parseLiteralPart) }, { "QUIT", FUNC(parseLiteralQuit) }, { "ERROR", FUNC(parseLiteralError) }, { "ERROR:", FUNC(parseLiteralError) }, { "MODE", FUNC(parseLiteralMode) }, { "KICK", FUNC(parseLiteralKick) }, + { "TOPIC", FUNC(parseLiteralTopic) }, { 0 , 0 } }; /* Lookup table for literal commands */ IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { { "PING", FUNC(parseCTCPPing) }, { "VERSION", FUNC(parseCTCPVersion) }, { "ACTION", FUNC(parseCTCPAction) }, { 0 , 0 } }; /* Lookup table for numerical commands */ IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { { 1, FUNC(parseNumerical001) }, // RPL_WELCOME { 2, FUNC(parseNumerical002) }, // RPL_YOURHOST { 3, FUNC(parseNumerical003) }, // RPL_CREATED { 4, FUNC(parseNumerical004) }, // RPL_MYINFO { 5, FUNC(parseNumerical005) }, // RPL_BOUNCE, RPL_PROTOCTL { 251, FUNC(parseNumericalStats) }, // RPL_LUSERCLIENT { 254, FUNC(nullFunc)}, // RPL_LUSERCHANNELS { 255, FUNC(parseNumericalStats) }, // RPL_LUSERNAME + { 332, FUNC(parseNumericalTopic) }, // RPL_TOPIC + { 333, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME { 353, FUNC(parseNumericalNames) }, // RPL_NAMREPLY { 366, FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES { 375, FUNC(parseNumericalStats) }, // RPL_MOTDSTART { 372, FUNC(parseNumericalStats) }, // RPL_MOTD { 376, FUNC(parseNumericalStats) }, // RPL_ENDOFMOTD { 377, FUNC(parseNumericalStats) }, // RPL_MOTD2 { 378, FUNC(parseNumericalStats) }, // RPL_MOTD3 { 401, FUNC(parseNumericalNoSuchNick) }, // ERR_NOSUCHNICK { 406, FUNC(parseNumericalNoSuchNick) }, // ERR_WASNOSUCHNICK { 412, FUNC(parseNumericalStats) }, // ERR_NOTEXTTOSEND { 433, FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE { 0, 0 } }; IRCMessageParser::IRCMessageParser(IRCSession *session) { m_session = session; } void IRCMessageParser::parse(IRCMessage *message) { /* Find out what kind of message we have here and call the appropriate handler using the parser tables. If no handler can be found, print out an error message */ if (message->isNumerical()) { for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { (this->*(numericalParserProcTable[i].proc))(message); return; } } emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command : ")+QString::number(message->commandNumber()))); } else if (message->isCTCP()) { for (int i=0; ctcpParserProcTable[i].commandName; i++) { if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { (this->*(ctcpParserProcTable[i].proc))(message); return; } } emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command : ")+message->ctcpCommand())); } else { for (int i=0; literalParserProcTable[i].commandName; i++) { if (message->command() == literalParserProcTable[i].commandName) { (this->*(literalParserProcTable[i].proc))(message); return; } } emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command : ")+message->command())); } } @@ -146,147 +149,159 @@ void IRCMessageParser::parseLiteralPart(IRCMessage *message) { emit outputReady(output); delete channel; } else { IRCChannelPerson *person = channel->getPerson(mask.nick()); if (person) { channel->removePerson(person); IRCOutput output(OUTPUT_OTHERPART, mask.nick() + tr(" left channel ") + channelName); output.addParam(channel); output.addParam(person); emit outputReady(output); delete person; } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); } } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?"))); } } void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { if (m_session->m_server->nick() == message->param(0)) { /* IRC Query message detected, verify sender and display it */ IRCPerson mask(message->prefix()); IRCPerson *person = m_session->getPerson(mask.nick()); if (!person) { /* Person not yet known, create and add to the current session */ person = new IRCPerson(message->prefix()); m_session->addPerson(person); } IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1)); output.addParam(person); emit outputReady(output); } else if (message->param(0).at(0) == '#') { /* IRC Channel message detected, verify sender, channel and display it */ IRCChannel *channel = m_session->getChannel(message->param(0)); if (channel) { IRCPerson mask(message->prefix()); IRCChannelPerson *person = channel->getPerson(mask.nick()); if (person) { IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); output.addParam(channel); output.addParam(person); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); } } else { - emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel"))); + emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel ") + message->param(0))); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type"))); } } void IRCMessageParser::parseLiteralNick(IRCMessage *message) { IRCPerson mask(message->prefix()); if (mask.nick() == m_session->m_server->nick()) { /* We are changing our nickname */ m_session->m_server->setNick(message->param(0)); IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as ")+message->param(0)); output.addParam(0); emit outputReady(output); } else { /* Someone else is */ IRCPerson *person = m_session->getPerson(mask.nick()); if (person) { IRCOutput output(OUTPUT_NICKCHANGE, mask.nick() + tr(" is now known as ") + message->param(0)); output.addParam(person); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); } } } void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { IRCPerson mask(message->prefix()); IRCPerson *person = m_session->getPerson(mask.nick()); if (person) { QList<IRCChannel> channels; m_session->getChannelsByPerson(person, channels); QListIterator<IRCChannel> it(channels); for (;it.current(); ++it) { IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); it.current()->removePerson(chanperson); delete chanperson; } m_session->removePerson(person); IRCOutput output(OUTPUT_QUIT, mask.nick() + tr(" has quit ") + "(" + message->param(0) + ")"); output.addParam(person); emit outputReady(output); delete person; } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); } } +void IRCMessageParser::parseLiteralTopic(IRCMessage *message) { + IRCPerson mask(message->prefix()); + IRCChannel *channel = m_session->getChannel(message->param(0)); + if (channel) { + IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\""); + output.addParam(channel); + emit outputReady(output); + } else { + emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?"))); + } +} + void IRCMessageParser::parseLiteralError(IRCMessage *message) { emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); } void IRCMessageParser::parseCTCPPing(IRCMessage *message) { IRCPerson mask(message->prefix()); m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters()); emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); } void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { IRCPerson mask(message->prefix()); m_session->m_connection->sendCTCP(mask.nick(), APP_VERSION " " APP_COPYSTR); emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick())); } void IRCMessageParser::parseCTCPAction(IRCMessage *message) { IRCPerson mask(message->prefix()); QString dest = message->ctcpDestination(); if (dest.startsWith("#")) { IRCChannel *channel = m_session->getChannel(dest); if (channel) { IRCChannelPerson *person = channel->getPerson(mask.nick()); if (person) { IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); output.addParam(channel); output.addParam(person); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?"))); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?"))); } } else { if (message->ctcpDestination() == m_session->m_server->nick()) { IRCPerson *person = m_session->getPerson(mask.nick()); if (!person) { /* Person not yet known, create and add to the current session */ person = new IRCPerson(message->prefix()); m_session->addPerson(person); } IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); output.addParam(person); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); } @@ -439,48 +454,64 @@ void IRCMessageParser::parseNumericalNames(IRCMessage *message) { case '@': flag = PERSON_FLAG_OP; break; case '+': flag = PERSON_FLAG_VOICE; break; case '%': flag = PERSON_FLAG_HALFOP; break; default : flag = 0; break; } } else { nick = temp; } IRCChannelPerson *chan_person = new IRCChannelPerson(); IRCPerson *person = m_session->getPerson(nick); if (person == 0) { person = new IRCPerson(); person->setNick(nick); m_session->addPerson(person); } chan_person->person = person; chan_person->flags = flag; channel->addPerson(chan_person); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); } } void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { /* Done syncing to channel */ IRCChannel *channel = m_session->getChannel(message->param(1)); if (channel) { channel->setHasPeople(TRUE); /* Yes, we want the names before anything happens inside the GUI */ IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); output.addParam(channel); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); } } void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); m_session->endSession(); } void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname"))); } + +void IRCMessageParser::parseNumericalTopic(IRCMessage *message) { + IRCChannel *channel = m_session->getChannel(message->param(1)); + if (channel) { + IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\"")); + output.addParam(channel); + emit outputReady(output); + } else { + IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\"")); + output.addParam(0); + emit outputReady(output); + } +} + +void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *message) { +} diff --git a/noncore/net/opieirc/ircmessageparser.h b/noncore/net/opieirc/ircmessageparser.h index f774047..c4dd96c 100644 --- a/noncore/net/opieirc/ircmessageparser.h +++ b/noncore/net/opieirc/ircmessageparser.h @@ -27,70 +27,73 @@ #define FUNC(__proc) &IRCMessageParser::__proc class IRCMessageParser; /* Typedef representing a parser function */ typedef void (IRCMessageParser::*IRCMessageParseProc)(IRCMessage *); /* Struct representing a literal command handler */ typedef struct IRCLiteralMessageParserStruct { char *commandName; IRCMessageParseProc proc; }; /* Struct representing a ctcp command handler */ typedef struct IRCCTCPMessageParserStruct { char *commandName; IRCMessageParseProc proc; }; /* Struct representing a numerical command handler */ typedef struct IRCNumericalMessageParserStruct { unsigned short commandNumber; IRCMessageParseProc proc; }; class IRCMessageParser : public QObject { Q_OBJECT public: /* Create an IRCMessageParser object */ IRCMessageParser(IRCSession *session); /* Parse a server message and take the appropriate actions */ void parse(IRCMessage *message); signals: /* Used to send commands to the UI (such as displaying text etc) */ void outputReady(IRCOutput output); private: /* Parser functions */ void nullFunc(IRCMessage *message); void parseLiteralPing(IRCMessage *message); void parseLiteralNotice(IRCMessage *message); void parseLiteralJoin(IRCMessage *message); void parseLiteralPrivMsg(IRCMessage *message); void parseLiteralNick(IRCMessage *message); void parseLiteralPart(IRCMessage *message); void parseLiteralQuit(IRCMessage *message); void parseLiteralError(IRCMessage *message); void parseLiteralMode(IRCMessage *message); void parseLiteralKick(IRCMessage *message); + void parseLiteralTopic(IRCMessage *message); void parseNumerical001(IRCMessage *message); void parseNumerical002(IRCMessage *message); void parseNumerical003(IRCMessage *message); void parseNumerical004(IRCMessage *message); void parseNumerical005(IRCMessage *message); void parseNumericalStats(IRCMessage *message); void parseNumericalNames(IRCMessage *message); void parseNumericalEndOfNames(IRCMessage *message); void parseNumericalNicknameInUse(IRCMessage *message); void parseNumericalNoSuchNick(IRCMessage *message); + void parseNumericalTopic(IRCMessage *message); + void parseNumericalTopicWhoTime(IRCMessage *message); void parseCTCPPing(IRCMessage *message); void parseCTCPVersion(IRCMessage *message); void parseCTCPAction(IRCMessage *message); protected: IRCSession *m_session; /* Parser tables */ static IRCLiteralMessageParserStruct literalParserProcTable[]; static IRCNumericalMessageParserStruct numericalParserProcTable[]; static IRCCTCPMessageParserStruct ctcpParserProcTable[]; }; #endif /* __IRCMESSAGEPARSER_H */ diff --git a/noncore/net/opieirc/ircoutput.h b/noncore/net/opieirc/ircoutput.h index e8cc524..9c0b8bb 100644 --- a/noncore/net/opieirc/ircoutput.h +++ b/noncore/net/opieirc/ircoutput.h @@ -1,74 +1,75 @@ /* OpieIRC - An embedded IRC client Copyright (C) 2002 Wenzel Jakob This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __IRCOUTPUT_H #define __IRCOUTPUT_H #include <qstring.h> #include <qlist.h> #include "ircchannel.h" /* Types of possible IRC output */ enum IRCOutputType { OUTPUT_ERROR = -1, /* parameters : none */ OUTPUT_SERVERMESSAGE = 0, /* parameters : none */ OUTPUT_CLIENTMESSAGE = 1, /* parameters : none */ OUTPUT_CHANPRIVMSG = 2, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */ OUTPUT_QUERYPRIVMSG = 3, /* parameters : person (IRCPerson) */ OUTPUT_NICKCHANGE = 4, /* parameters : person (IRCPerson) */ OUTPUT_SELFJOIN = 5, /* parameters : channel (IRCChannel) */ OUTPUT_OTHERJOIN = 6, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */ OUTPUT_SELFPART = 7, /* parameters : channel (IRCChannel) */ OUTPUT_OTHERPART = 8, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */ OUTPUT_QUIT = 9, /* parameters : person (IRCPerson) */ OUTPUT_CONNCLOSE = 10, /* parameters : none */ OUTPUT_CTCP = 11, /* parameters : none */ OUTPUT_SELFKICK = 12, /* parameters : channel (IRCChannel) */ OUTPUT_OTHERKICK = 13, /* parameters : channel (IRCChannel) person (IRCChannelPerson) */ OUTPUT_CHANACTION = 14, /* parameters : channel (IRCChannel) person (IRCChannelPerson) */ OUTPUT_QUERYACTION = 15, /* parameters : person (IRCPerson) */ - OUTPUT_CHANPERSONMODE = 16 /* parameters : channel (IRCCHannel) person (IRCChannelPerson) */ + OUTPUT_CHANPERSONMODE = 16, /* parameters : channel (IRCCHannel) person (IRCChannelPerson) */ + OUTPUT_TOPIC = 17 /* parameters : channel (IRCChannel) */ }; /* The IRCOutput class is used as a kind of message which is sent by the IRC parser to inform the GUI of changes. This could for example be a channel message or a nickname change */ class IRCOutput { public: IRCOutput(IRCOutputType type, QString message); /* Used to add a parameter to this IRCOutput. Parameters are dependent on which IRCOutputType we are using (see above) */ void addParam(void *data); IRCOutputType type(); QString message(); /* Return the message with all HTML code escaped (for example < instead of '<') */ QString htmlMessage(); static QString toHTML(QString message); void *getParam(int index); protected: IRCOutputType m_type; QString m_message; QList<void> m_parameters; }; #endif diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp index 4be60ef..aea58a3 100644 --- a/noncore/net/opieirc/ircservertab.cpp +++ b/noncore/net/opieirc/ircservertab.cpp @@ -174,79 +174,91 @@ void IRCServerTab::display(IRCOutput output) { } else { appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() +"</font><br>"); QListIterator<IRCChannelTab> it(m_channelTabs); for (; it.current(); ++it) { it.current()->appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() +"</font><br>"); } } break; case OUTPUT_SELFJOIN: { IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); m_channelTabs.append(channeltab); m_mainWindow->addTab(channeltab); } break; case OUTPUT_CHANPRIVMSG: { IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); channelTab->appendText("<font color=\"" + m_textColor + "\"><</font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(((IRCChannelPerson *)output.getParam(1))->person->nick())+"</font><font color=\"" + m_textColor + "\">> " + output.htmlMessage()+"</font><br>"); } break; case OUTPUT_QUERYACTION: case OUTPUT_QUERYPRIVMSG: { IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0)); if (!queryTab) { queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); m_queryTabs.append(queryTab); m_mainWindow->addTab(queryTab); } queryTab->display(output); } break; case OUTPUT_SELFPART: { IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); if (channelTab) m_mainWindow->killTab(channelTab); } break; case OUTPUT_SELFKICK: { appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>"); IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); if (channelTab) m_mainWindow->killTab(channelTab); } break; case OUTPUT_CHANACTION: { IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); channelTab->appendText("<font color=\"" + m_otherColor + "\">"+output.htmlMessage()+"</font><br>"); } break; + case OUTPUT_TOPIC: { + IRCChannel *channel = (IRCChannel *) output.getParam(0); + if (channel) { + IRCChannelTab *channelTab = getTabForChannel(channel); + if (channelTab) { + channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); + return; + } + } + appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); + } + break; case OUTPUT_QUIT: { QString nick = ((IRCPerson *)output.getParam(0))->nick(); QListIterator<IRCChannelTab> it(m_channelTabs); for (; it.current(); ++it) { if (it.current()->list()->hasPerson(nick)) { it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); it.current()->list()->update(); } } } break; case OUTPUT_OTHERJOIN: case OUTPUT_OTHERKICK: case OUTPUT_CHANPERSONMODE: case OUTPUT_OTHERPART: { IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); channelTab->list()->update(); } break; case OUTPUT_CTCP: appendText("<font color=\"" + m_notificationColor + "\">" + output.htmlMessage() + "</font><br>"); break; case OUTPUT_ERROR: appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>"); break; default: appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() + "</font><br>"); break; } } |