Diffstat (limited to 'noncore/net/opieirc/ircmessageparser.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp index ad9de2b..939cdae 100644 --- a/noncore/net/opieirc/ircmessageparser.cpp +++ b/noncore/net/opieirc/ircmessageparser.cpp @@ -1,55 +1,60 @@ #include <qtextstream.h> #include <qdatetime.h> +#include <opie2/ofiledialog.h> +#include <opie2/ofileselector.h> +#include <opie2/odebug.h> + #include "ircmessageparser.h" #include "ircversion.h" #include "ircchannelperson.h" -//#include "transferreceiver.h" +#include "dcctransfertab.h" +#include "ircservertab.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) }, { "DCC", FUNC(parseCTCPDCC) }, { 0 , 0 } }; /* Lookup table for numerical commands * According to: * http://www.faqs.org/rfcs/rfc1459.html * http://www.faqs.org/rfcs/rfc2812.html */ IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { { 1, "%1", "1", FUNC(parseNumericalServerName) }, // RPL_WELCOME { 2, "%1", "1", 0 }, // RPL_YOURHOST { 3, "%1", "1", 0 }, // RPL_CREATED { 4, QT_TR_NOOP("Server %1 version %2 supports usermodes '%3' and channelmodes '%4'"), "1:4", FUNC(parseNumericalServerFeatures) }, // RPL_MYINFO { 5, 0, 0, FUNC(parseNumericalServerProtocol) }, // RPL_BOUNCE, RPL_PROTOCTL { 250, "%1", "1", 0 }, // RPL_STATSCONN { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS { 255, "%1", "1", 0 }, // RPL_LUSERME { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN { 265, "%1", "1", 0 }, // RPL_LOCALUSERS { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS @@ -416,102 +421,115 @@ void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { if(message->isCTCPRequest()) { m_session->m_connection->sendCTCPReply(mask.nick(), "VERSION", APP_VERSION " " APP_COPYSTR); output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick()); } else { output.setMessage("Received CTCP VERSION reply from " + mask.nick() + ":" + message->param(0)); } emit outputReady(output); } void IRCMessageParser::parseCTCPAction(IRCMessage *message) { IRCPerson mask(message->prefix()); QString dest = message->ctcpDestination(); if (dest.startsWith("#")) { IRCChannel *channel = m_session->getChannel(dest.lower()); 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"))); } } } void IRCMessageParser::parseCTCPDCC(IRCMessage *message) { QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace()); + + if(params[0] == "SEND") { + QString nickname = IRCPerson(message->prefix()).nick(); if( params.count() != 5) { - emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from ") + IRCPerson(message->prefix()).nick())); + emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from %1").arg(nickname))); return; } + bool accepted = DCCTransferTab::confirm(static_cast<QWidget*>(m_session->parent()), nickname, params[1], params[4].toUInt()); + if(!accepted) + return; + QString filename = Opie::Ui::OFileDialog::getSaveFileName(Opie::Ui::OFileSelector::EXTENDED_ALL, + QString::null, params[1], MimeTypes(), 0, tr("Save As")); + if(filename.isEmpty()) + return; - //TransferReceiver *foo = new TransferReceiver(params[2].toUInt(), params[3].toUInt(), params[1], params[4].toUInt()); + odebug << "Receiving file " << filename << " from " << nickname << oendl; + static_cast<IRCServerTab*>(m_session->parent())->mainwindow()->addDCC(DCCTransfer::Recv, params[2].toUInt(), params[3].toUInt(), + filename, nickname, params[4].toUInt()); + } } void IRCMessageParser::parseLiteralMode(IRCMessage *message) { IRCPerson mask(message->prefix()); if (message->param(0).startsWith("#")) { IRCChannel *channel = m_session->getChannel(message->param(0).lower()); if (channel) { QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); QTextIStream stream(¶meters); bool set = FALSE; while (!stream.atEnd()) { stream >> temp; if (temp.startsWith("+")) { set = TRUE; temp = temp.right(1); } else if (temp.startsWith("-")) { set = FALSE; temp = temp.right(1); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); return; } if (temp == "o") { stream >> temp; IRCChannelPerson *person = channel->getPerson(temp); if (person) { IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set)); output.addParam(channel); output.addParam(person); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); } } else if (temp == "v") { stream >> temp; IRCChannelPerson *person = channel->getPerson(temp); if (person) { IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set)); output.addParam(channel); output.addParam(person); emit outputReady(output); |