author | skyhusker <skyhusker> | 2005-02-03 21:47:50 (UTC) |
---|---|---|
committer | skyhusker <skyhusker> | 2005-02-03 21:47:50 (UTC) |
commit | 8aaae9e3eca7853e9c693d2401f721d75209acf7 (patch) (unidiff) | |
tree | 6f700d154fac8510b322242496604d0ad7589377 /noncore/net/opieirc/ircmessageparser.cpp | |
parent | 875b3b63624308f4e50f82e17db27edeb9609d6c (diff) | |
download | opie-8aaae9e3eca7853e9c693d2401f721d75209acf7.zip opie-8aaae9e3eca7853e9c693d2401f721d75209acf7.tar.gz opie-8aaae9e3eca7853e9c693d2401f721d75209acf7.tar.bz2 |
Added DCC receive support
Diffstat (limited to 'noncore/net/opieirc/ircmessageparser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 30 |
1 files changed, 24 insertions, 6 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 @@ | |||
1 | #include <qtextstream.h> | 1 | #include <qtextstream.h> |
2 | #include <qdatetime.h> | 2 | #include <qdatetime.h> |
3 | 3 | ||
4 | #include <opie2/ofiledialog.h> | ||
5 | #include <opie2/ofileselector.h> | ||
6 | #include <opie2/odebug.h> | ||
7 | |||
4 | #include "ircmessageparser.h" | 8 | #include "ircmessageparser.h" |
5 | #include "ircversion.h" | 9 | #include "ircversion.h" |
6 | #include "ircchannelperson.h" | 10 | #include "ircchannelperson.h" |
7 | //#include "transferreceiver.h" | 11 | #include "dcctransfertab.h" |
12 | #include "ircservertab.h" | ||
8 | 13 | ||
9 | /* Lookup table for literal commands */ | 14 | /* Lookup table for literal commands */ |
10 | IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { | 15 | IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { |
11 | { "PING", FUNC(parseLiteralPing) }, | 16 | { "PING", FUNC(parseLiteralPing) }, |
12 | { "NOTICE", FUNC(parseLiteralNotice) }, | 17 | { "NOTICE", FUNC(parseLiteralNotice) }, |
13 | { "JOIN", FUNC(parseLiteralJoin) }, | 18 | { "JOIN", FUNC(parseLiteralJoin) }, |
14 | { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, | 19 | { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, |
15 | { "NICK", FUNC(parseLiteralNick) }, | 20 | { "NICK", FUNC(parseLiteralNick) }, |
16 | { "PART", FUNC(parseLiteralPart) }, | 21 | { "PART", FUNC(parseLiteralPart) }, |
17 | { "QUIT", FUNC(parseLiteralQuit) }, | 22 | { "QUIT", FUNC(parseLiteralQuit) }, |
18 | { "ERROR", FUNC(parseLiteralError) }, | 23 | { "ERROR", FUNC(parseLiteralError) }, |
19 | { "ERROR:", FUNC(parseLiteralError) }, | 24 | { "ERROR:", FUNC(parseLiteralError) }, |
20 | { "MODE", FUNC(parseLiteralMode) }, | 25 | { "MODE", FUNC(parseLiteralMode) }, |
21 | { "KICK", FUNC(parseLiteralKick) }, | 26 | { "KICK", FUNC(parseLiteralKick) }, |
22 | { "TOPIC", FUNC(parseLiteralTopic) }, | 27 | { "TOPIC", FUNC(parseLiteralTopic) }, |
23 | { 0 , 0 } | 28 | { 0 , 0 } |
24 | }; | 29 | }; |
25 | 30 | ||
26 | /* Lookup table for literal commands */ | 31 | /* Lookup table for literal commands */ |
27 | IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { | 32 | IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { |
28 | { "PING", FUNC(parseCTCPPing) }, | 33 | { "PING", FUNC(parseCTCPPing) }, |
29 | { "VERSION", FUNC(parseCTCPVersion) }, | 34 | { "VERSION", FUNC(parseCTCPVersion) }, |
30 | { "ACTION", FUNC(parseCTCPAction) }, | 35 | { "ACTION", FUNC(parseCTCPAction) }, |
31 | { "DCC", FUNC(parseCTCPDCC) }, | 36 | { "DCC", FUNC(parseCTCPDCC) }, |
32 | { 0 , 0 } | 37 | { 0 , 0 } |
33 | }; | 38 | }; |
34 | 39 | ||
35 | /* Lookup table for numerical commands | 40 | /* Lookup table for numerical commands |
36 | * According to: | 41 | * According to: |
37 | * http://www.faqs.org/rfcs/rfc1459.html | 42 | * http://www.faqs.org/rfcs/rfc1459.html |
38 | * http://www.faqs.org/rfcs/rfc2812.html | 43 | * http://www.faqs.org/rfcs/rfc2812.html |
39 | */ | 44 | */ |
40 | 45 | ||
41 | IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { | 46 | IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { |
42 | { 1, "%1", "1", FUNC(parseNumericalServerName) }, // RPL_WELCOME | 47 | { 1, "%1", "1", FUNC(parseNumericalServerName) }, // RPL_WELCOME |
43 | { 2, "%1", "1", 0 }, // RPL_YOURHOST | 48 | { 2, "%1", "1", 0 }, // RPL_YOURHOST |
44 | { 3, "%1", "1", 0 }, // RPL_CREATED | 49 | { 3, "%1", "1", 0 }, // RPL_CREATED |
45 | { 4, QT_TR_NOOP("Server %1 version %2 supports usermodes '%3' and channelmodes '%4'"), "1:4", FUNC(parseNumericalServerFeatures) }, // RPL_MYINFO | 50 | { 4, QT_TR_NOOP("Server %1 version %2 supports usermodes '%3' and channelmodes '%4'"), "1:4", FUNC(parseNumericalServerFeatures) }, // RPL_MYINFO |
46 | { 5, 0, 0, FUNC(parseNumericalServerProtocol) }, // RPL_BOUNCE, RPL_PROTOCTL | 51 | { 5, 0, 0, FUNC(parseNumericalServerProtocol) }, // RPL_BOUNCE, RPL_PROTOCTL |
47 | { 250, "%1", "1", 0 }, // RPL_STATSCONN | 52 | { 250, "%1", "1", 0 }, // RPL_STATSCONN |
48 | { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT | 53 | { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT |
49 | { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP | 54 | { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP |
50 | { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN | 55 | { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN |
51 | { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS | 56 | { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS |
52 | { 255, "%1", "1", 0 }, // RPL_LUSERME | 57 | { 255, "%1", "1", 0 }, // RPL_LUSERME |
53 | { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN | 58 | { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN |
54 | { 265, "%1", "1", 0 }, // RPL_LOCALUSERS | 59 | { 265, "%1", "1", 0 }, // RPL_LOCALUSERS |
55 | { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS | 60 | { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS |
@@ -416,102 +421,115 @@ void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { | |||
416 | if(message->isCTCPRequest()) { | 421 | if(message->isCTCPRequest()) { |
417 | m_session->m_connection->sendCTCPReply(mask.nick(), "VERSION", APP_VERSION " " APP_COPYSTR); | 422 | m_session->m_connection->sendCTCPReply(mask.nick(), "VERSION", APP_VERSION " " APP_COPYSTR); |
418 | output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick()); | 423 | output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick()); |
419 | } | 424 | } |
420 | 425 | ||
421 | else { | 426 | else { |
422 | output.setMessage("Received CTCP VERSION reply from " + mask.nick() + ":" + message->param(0)); | 427 | output.setMessage("Received CTCP VERSION reply from " + mask.nick() + ":" + message->param(0)); |
423 | } | 428 | } |
424 | emit outputReady(output); | 429 | emit outputReady(output); |
425 | } | 430 | } |
426 | 431 | ||
427 | void IRCMessageParser::parseCTCPAction(IRCMessage *message) { | 432 | void IRCMessageParser::parseCTCPAction(IRCMessage *message) { |
428 | IRCPerson mask(message->prefix()); | 433 | IRCPerson mask(message->prefix()); |
429 | QString dest = message->ctcpDestination(); | 434 | QString dest = message->ctcpDestination(); |
430 | if (dest.startsWith("#")) { | 435 | if (dest.startsWith("#")) { |
431 | IRCChannel *channel = m_session->getChannel(dest.lower()); | 436 | IRCChannel *channel = m_session->getChannel(dest.lower()); |
432 | if (channel) { | 437 | if (channel) { |
433 | IRCChannelPerson *person = channel->getPerson(mask.nick()); | 438 | IRCChannelPerson *person = channel->getPerson(mask.nick()); |
434 | if (person) { | 439 | if (person) { |
435 | IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); | 440 | IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); |
436 | output.addParam(channel); | 441 | output.addParam(channel); |
437 | output.addParam(person); | 442 | output.addParam(person); |
438 | emit outputReady(output); | 443 | emit outputReady(output); |
439 | } else { | 444 | } else { |
440 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?"))); | 445 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?"))); |
441 | } | 446 | } |
442 | } else { | 447 | } else { |
443 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?"))); | 448 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?"))); |
444 | } | 449 | } |
445 | } else { | 450 | } else { |
446 | if (message->ctcpDestination() == m_session->m_server->nick()) { | 451 | if (message->ctcpDestination() == m_session->m_server->nick()) { |
447 | IRCPerson *person = m_session->getPerson(mask.nick()); | 452 | IRCPerson *person = m_session->getPerson(mask.nick()); |
448 | if (!person) { | 453 | if (!person) { |
449 | /* Person not yet known, create and add to the current session */ | 454 | /* Person not yet known, create and add to the current session */ |
450 | person = new IRCPerson(message->prefix()); | 455 | person = new IRCPerson(message->prefix()); |
451 | m_session->addPerson(person); | 456 | m_session->addPerson(person); |
452 | } | 457 | } |
453 | IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); | 458 | IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); |
454 | output.addParam(person); | 459 | output.addParam(person); |
455 | emit outputReady(output); | 460 | emit outputReady(output); |
456 | } else { | 461 | } else { |
457 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); | 462 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); |
458 | } | 463 | } |
459 | } | 464 | } |
460 | } | 465 | } |
461 | 466 | ||
462 | void IRCMessageParser::parseCTCPDCC(IRCMessage *message) { | 467 | void IRCMessageParser::parseCTCPDCC(IRCMessage *message) { |
463 | QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace()); | 468 | QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace()); |
464 | if( params.count() != 5) { | 469 | |
465 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from ") + IRCPerson(message->prefix()).nick())); | 470 | if(params[0] == "SEND") { |
466 | return; | 471 | QString nickname = IRCPerson(message->prefix()).nick(); |
472 | if( params.count() != 5) { | ||
473 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from %1").arg(nickname))); | ||
474 | return; | ||
475 | } | ||
476 | bool accepted = DCCTransferTab::confirm(static_cast<QWidget*>(m_session->parent()), nickname, params[1], params[4].toUInt()); | ||
477 | if(!accepted) | ||
478 | return; | ||
479 | QString filename = Opie::Ui::OFileDialog::getSaveFileName(Opie::Ui::OFileSelector::EXTENDED_ALL, | ||
480 | QString::null, params[1], MimeTypes(), 0, tr("Save As")); | ||
481 | if(filename.isEmpty()) | ||
482 | return; | ||
483 | |||
484 | odebug << "Receiving file " << filename << " from " << nickname << oendl; | ||
485 | static_cast<IRCServerTab*>(m_session->parent())->mainwindow()->addDCC(DCCTransfer::Recv, params[2].toUInt(), params[3].toUInt(), | ||
486 | filename, nickname, params[4].toUInt()); | ||
467 | } | 487 | } |
468 | |||
469 | //TransferReceiver *foo = new TransferReceiver(params[2].toUInt(), params[3].toUInt(), params[1], params[4].toUInt()); | ||
470 | } | 488 | } |
471 | 489 | ||
472 | void IRCMessageParser::parseLiteralMode(IRCMessage *message) { | 490 | void IRCMessageParser::parseLiteralMode(IRCMessage *message) { |
473 | IRCPerson mask(message->prefix()); | 491 | IRCPerson mask(message->prefix()); |
474 | 492 | ||
475 | if (message->param(0).startsWith("#")) { | 493 | if (message->param(0).startsWith("#")) { |
476 | IRCChannel *channel = m_session->getChannel(message->param(0).lower()); | 494 | IRCChannel *channel = m_session->getChannel(message->param(0).lower()); |
477 | if (channel) { | 495 | if (channel) { |
478 | QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); | 496 | QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); |
479 | QTextIStream stream(¶meters); | 497 | QTextIStream stream(¶meters); |
480 | bool set = FALSE; | 498 | bool set = FALSE; |
481 | while (!stream.atEnd()) { | 499 | while (!stream.atEnd()) { |
482 | stream >> temp; | 500 | stream >> temp; |
483 | if (temp.startsWith("+")) { | 501 | if (temp.startsWith("+")) { |
484 | set = TRUE; | 502 | set = TRUE; |
485 | temp = temp.right(1); | 503 | temp = temp.right(1); |
486 | } | 504 | } |
487 | else | 505 | else |
488 | if (temp.startsWith("-")) { | 506 | if (temp.startsWith("-")) { |
489 | set = FALSE; | 507 | set = FALSE; |
490 | temp = temp.right(1); | 508 | temp = temp.right(1); |
491 | } | 509 | } |
492 | else { | 510 | else { |
493 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); | 511 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); |
494 | return; | 512 | return; |
495 | } | 513 | } |
496 | if (temp == "o") { | 514 | if (temp == "o") { |
497 | stream >> temp; | 515 | stream >> temp; |
498 | IRCChannelPerson *person = channel->getPerson(temp); | 516 | IRCChannelPerson *person = channel->getPerson(temp); |
499 | if (person) { | 517 | if (person) { |
500 | IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set)); | 518 | IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set)); |
501 | output.addParam(channel); | 519 | output.addParam(channel); |
502 | output.addParam(person); | 520 | output.addParam(person); |
503 | emit outputReady(output); | 521 | emit outputReady(output); |
504 | } | 522 | } |
505 | else { | 523 | else { |
506 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); | 524 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); |
507 | } | 525 | } |
508 | } | 526 | } |
509 | else | 527 | else |
510 | if (temp == "v") { | 528 | if (temp == "v") { |
511 | stream >> temp; | 529 | stream >> temp; |
512 | IRCChannelPerson *person = channel->getPerson(temp); | 530 | IRCChannelPerson *person = channel->getPerson(temp); |
513 | if (person) { | 531 | if (person) { |
514 | IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set)); | 532 | IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set)); |
515 | output.addParam(channel); | 533 | output.addParam(channel); |
516 | output.addParam(person); | 534 | output.addParam(person); |
517 | emit outputReady(output); | 535 | emit outputReady(output); |