Diffstat (limited to 'noncore/net/opieirc/ircmessageparser.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 100 |
1 files changed, 58 insertions, 42 deletions
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp index cfad2c1..9c1492c 100644 --- a/noncore/net/opieirc/ircmessageparser.cpp +++ b/noncore/net/opieirc/ircmessageparser.cpp | |||
@@ -3,6 +3,8 @@ | |||
3 | 3 | ||
4 | #include "ircmessageparser.h" | 4 | #include "ircmessageparser.h" |
5 | #include "ircversion.h" | 5 | #include "ircversion.h" |
6 | #include "ircchannelperson.h" | ||
7 | //#include "transferreceiver.h" | ||
6 | 8 | ||
7 | /* Lookup table for literal commands */ | 9 | /* Lookup table for literal commands */ |
8 | IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { | 10 | IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { |
@@ -26,6 +28,7 @@ IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { | |||
26 | { "PING", FUNC(parseCTCPPing) }, | 28 | { "PING", FUNC(parseCTCPPing) }, |
27 | { "VERSION", FUNC(parseCTCPVersion) }, | 29 | { "VERSION", FUNC(parseCTCPVersion) }, |
28 | { "ACTION", FUNC(parseCTCPAction) }, | 30 | { "ACTION", FUNC(parseCTCPAction) }, |
31 | { "DCC", FUNC(parseCTCPDCC) }, | ||
29 | { 0 , 0 } | 32 | { 0 , 0 } |
30 | }; | 33 | }; |
31 | 34 | ||
@@ -50,10 +53,11 @@ IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { | |||
50 | { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN | 53 | { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN |
51 | { 265, "%1", "1", 0 }, // RPL_LOCALUSERS | 54 | { 265, "%1", "1", 0 }, // RPL_LOCALUSERS |
52 | { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS | 55 | { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS |
53 | { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5" }, // RPL_WHOISUSER | 56 | { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5", 0 }, // RPL_WHOISUSER |
54 | { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER | 57 | { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER |
55 | { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE | 58 | { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE |
56 | { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS | 59 | { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS |
60 | { 319, QT_TR_NOOP("%1 is on channels: %2"), "1,2", 0 }, // RPL_WHOISCHANNELS | ||
57 | { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT | 61 | { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT |
58 | { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC | 62 | { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC |
59 | { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/ | 63 | { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/ |
@@ -67,7 +71,7 @@ IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { | |||
67 | { 378, "%1", "1", 0 }, // RPL_MOTD3 | 71 | { 378, "%1", "1", 0 }, // RPL_MOTD3 |
68 | { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME | 72 | { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME |
69 | { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK | 73 | { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK |
70 | { 406, QT_TR_NOOP("There is no history information for %1"), "1" }, // ERR_WASNOSUCHNICK | 74 | { 406, QT_TR_NOOP("There is no history information for %1"), "1", 0 }, // ERR_WASNOSUCHNICK |
71 | { 409, "%1", "1", 0 }, // ERR_NOORIGIN | 75 | { 409, "%1", "1", 0 }, // ERR_NOORIGIN |
72 | { 411, "%1", "1", 0 }, // ERR_NORECIPIENT | 76 | { 411, "%1", "1", 0 }, // ERR_NORECIPIENT |
73 | { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND | 77 | { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND |
@@ -99,7 +103,7 @@ void IRCMessageParser::parse(IRCMessage *message) { | |||
99 | } else if (message->isCTCP()) { | 103 | } else if (message->isCTCP()) { |
100 | for (int i=0; ctcpParserProcTable[i].commandName; i++) { | 104 | for (int i=0; ctcpParserProcTable[i].commandName; i++) { |
101 | if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { | 105 | if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { |
102 | (this->*(ctcpParserProcTable[i].proc))(message); | 106 | parseCTCP(message, i); |
103 | return; | 107 | return; |
104 | } | 108 | } |
105 | } | 109 | } |
@@ -134,9 +138,16 @@ void IRCMessageParser::parseNumerical(IRCMessage *message, int position) { | |||
134 | (this->*(numericalParserProcTable[position].proc))(message); | 138 | (this->*(numericalParserProcTable[position].proc))(message); |
135 | } | 139 | } |
136 | 140 | ||
141 | void IRCMessageParser::parseCTCP(IRCMessage *message, int position) { | ||
142 | if(ctcpParserProcTable[position].proc) | ||
143 | (this->*(ctcpParserProcTable[position].proc))(message); | ||
144 | } | ||
145 | |||
146 | |||
147 | |||
137 | void IRCMessageParser::parseNumericalServerName(IRCMessage *message) { | 148 | void IRCMessageParser::parseNumericalServerName(IRCMessage *message) { |
138 | emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>")); | 149 | emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>")); |
139 | /* Register EFFECTIVE nickname, some networks (as irc-hispano) uses nick:password | 150 | /* Register EFFECTIVE nickname, some networks (as irc-hispano) use nick:password |
140 | * for authentication and the parser gets confused */ | 151 | * for authentication and the parser gets confused */ |
141 | m_session->m_server->setNick(message->param(0)); | 152 | m_session->m_server->setNick(message->param(0)); |
142 | 153 | ||
@@ -189,14 +200,12 @@ void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { | |||
189 | /* Someone else joined */ | 200 | /* Someone else joined */ |
190 | if (mask.nick() != m_session->m_server->nick()) { | 201 | if (mask.nick() != m_session->m_server->nick()) { |
191 | if (!channel->getPerson(mask.nick())) { | 202 | if (!channel->getPerson(mask.nick())) { |
192 | IRCChannelPerson *chanperson = new IRCChannelPerson(); | ||
193 | IRCPerson *person = m_session->getPerson(mask.nick()); | 203 | IRCPerson *person = m_session->getPerson(mask.nick()); |
194 | if (!person) { | 204 | if (!person) { |
195 | person = new IRCPerson(message->prefix()); | 205 | person = new IRCPerson(message->prefix()); |
196 | m_session->addPerson(person); | 206 | m_session->addPerson(person); |
197 | } | 207 | } |
198 | chanperson->flags = 0; | 208 | IRCChannelPerson *chanperson = new IRCChannelPerson(person); |
199 | chanperson->person = person; | ||
200 | channel->addPerson(chanperson); | 209 | channel->addPerson(chanperson); |
201 | IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName )); | 210 | IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName )); |
202 | output.addParam(channel); | 211 | output.addParam(channel); |
@@ -355,7 +364,7 @@ void IRCMessageParser::parseLiteralError(IRCMessage *message) { | |||
355 | 364 | ||
356 | void IRCMessageParser::parseCTCPPing(IRCMessage *message) { | 365 | void IRCMessageParser::parseCTCPPing(IRCMessage *message) { |
357 | IRCPerson mask(message->prefix()); | 366 | IRCPerson mask(message->prefix()); |
358 | m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters()); | 367 | m_session->m_connection->sendCTCPReply(mask.nick(), "PING", message->allParameters()); |
359 | emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); | 368 | emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); |
360 | 369 | ||
361 | //IRCPerson mask(message->prefix()); | 370 | //IRCPerson mask(message->prefix()); |
@@ -395,8 +404,16 @@ void IRCMessageParser::parseCTCPPing(IRCMessage *message) { | |||
395 | 404 | ||
396 | void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { | 405 | void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { |
397 | IRCPerson mask(message->prefix()); | 406 | IRCPerson mask(message->prefix()); |
398 | m_session->m_connection->sendCTCP(mask.nick(), "VERSION " APP_VERSION " " APP_COPYSTR); | 407 | IRCOutput output(OUTPUT_CTCP); |
399 | emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick())); | 408 | if(message->isCTCPRequest()) { |
409 | m_session->m_connection->sendCTCPReply(mask.nick(), "VERSION", APP_VERSION " " APP_COPYSTR); | ||
410 | output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick()); | ||
411 | } | ||
412 | |||
413 | else { | ||
414 | output.setMessage("Received CTCP VERSION reply from " + mask.nick() + ":" + message->param(0)); | ||
415 | } | ||
416 | emit outputReady(output); | ||
400 | } | 417 | } |
401 | 418 | ||
402 | void IRCMessageParser::parseCTCPAction(IRCMessage *message) { | 419 | void IRCMessageParser::parseCTCPAction(IRCMessage *message) { |
@@ -434,6 +451,16 @@ void IRCMessageParser::parseCTCPAction(IRCMessage *message) { | |||
434 | } | 451 | } |
435 | } | 452 | } |
436 | 453 | ||
454 | void IRCMessageParser::parseCTCPDCC(IRCMessage *message) { | ||
455 | QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace()); | ||
456 | if( params.count() != 5) { | ||
457 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from ") + IRCPerson(message->prefix()).nick())); | ||
458 | return; | ||
459 | } | ||
460 | |||
461 | //TransferReceiver *foo = new TransferReceiver(params[2].toUInt(), params[3].toUInt(), params[1], params[4].toUInt()); | ||
462 | } | ||
463 | |||
437 | void IRCMessageParser::parseLiteralMode(IRCMessage *message) { | 464 | void IRCMessageParser::parseLiteralMode(IRCMessage *message) { |
438 | IRCPerson mask(message->prefix()); | 465 | IRCPerson mask(message->prefix()); |
439 | 466 | ||
@@ -448,10 +475,13 @@ void IRCMessageParser::parseLiteralMode(IRCMessage *message) { | |||
448 | if (temp.startsWith("+")) { | 475 | if (temp.startsWith("+")) { |
449 | set = TRUE; | 476 | set = TRUE; |
450 | temp = temp.right(1); | 477 | temp = temp.right(1); |
451 | } else if (temp.startsWith("-")) { | 478 | } |
479 | else | ||
480 | if (temp.startsWith("-")) { | ||
452 | set = FALSE; | 481 | set = FALSE; |
453 | temp = temp.right(1); | 482 | temp = temp.right(1); |
454 | } else { | 483 | } |
484 | else { | ||
455 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); | 485 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); |
456 | return; | 486 | return; |
457 | } | 487 | } |
@@ -459,43 +489,30 @@ void IRCMessageParser::parseLiteralMode(IRCMessage *message) { | |||
459 | stream >> temp; | 489 | stream >> temp; |
460 | IRCChannelPerson *person = channel->getPerson(temp); | 490 | IRCChannelPerson *person = channel->getPerson(temp); |
461 | if (person) { | 491 | if (person) { |
462 | if (set) { | 492 | IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set)); |
463 | person->flags |= PERSON_FLAG_OP; | ||
464 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives channel operator status to " + person->person->nick())); | ||
465 | output.addParam(channel); | ||
466 | output.addParam(person); | ||
467 | emit outputReady(output); | ||
468 | } else { | ||
469 | person->flags &= 0xFFFF - PERSON_FLAG_OP; | ||
470 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes channel operator status from " + person->person->nick())); | ||
471 | output.addParam(channel); | 493 | output.addParam(channel); |
472 | output.addParam(person); | 494 | output.addParam(person); |
473 | emit outputReady(output); | 495 | emit outputReady(output); |
474 | } | 496 | } |
475 | } else { | 497 | else { |
476 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); | 498 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); |
477 | } | 499 | } |
478 | } else if (temp == "v") { | 500 | } |
501 | else | ||
502 | if (temp == "v") { | ||
479 | stream >> temp; | 503 | stream >> temp; |
480 | IRCChannelPerson *person = channel->getPerson(temp); | 504 | IRCChannelPerson *person = channel->getPerson(temp); |
481 | if (person) { | 505 | if (person) { |
482 | if (set) { | 506 | IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set)); |
483 | person->flags |= PERSON_FLAG_VOICE; | ||
484 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives voice to " + person->person->nick())); | ||
485 | output.addParam(channel); | ||
486 | output.addParam(person); | ||
487 | emit outputReady(output); | ||
488 | } else { | ||
489 | person->flags &= 0xFFFF - PERSON_FLAG_VOICE; | ||
490 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes voice from " + person->person->nick())); | ||
491 | output.addParam(channel); | 507 | output.addParam(channel); |
492 | output.addParam(person); | 508 | output.addParam(person); |
493 | emit outputReady(output); | 509 | emit outputReady(output); |
494 | } | 510 | } |
495 | } else { | 511 | else { |
496 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); | 512 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); |
497 | } | 513 | } |
498 | } else { | 514 | } |
515 | else { | ||
499 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag"))); | 516 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag"))); |
500 | } | 517 | } |
501 | } | 518 | } |
@@ -513,7 +530,7 @@ void IRCMessageParser::parseLiteralKick(IRCMessage *message) { | |||
513 | if (channel) { | 530 | if (channel) { |
514 | IRCChannelPerson *person = channel->getPerson(message->param(1)); | 531 | IRCChannelPerson *person = channel->getPerson(message->param(1)); |
515 | if (person) { | 532 | if (person) { |
516 | if (person->person->nick() == m_session->m_server->nick()) { | 533 | if (person->nick() == m_session->m_server->nick()) { |
517 | m_session->removeChannel(channel); | 534 | m_session->removeChannel(channel); |
518 | IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")"); | 535 | IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")"); |
519 | output.addParam(channel); | 536 | output.addParam(channel); |
@@ -521,7 +538,7 @@ void IRCMessageParser::parseLiteralKick(IRCMessage *message) { | |||
521 | } else { | 538 | } else { |
522 | /* someone else got kicked */ | 539 | /* someone else got kicked */ |
523 | channel->removePerson(person); | 540 | channel->removePerson(person); |
524 | IRCOutput output(OUTPUT_OTHERKICK, person->person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")"); | 541 | IRCOutput output(OUTPUT_OTHERKICK, person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")"); |
525 | output.addParam(channel); | 542 | output.addParam(channel); |
526 | output.addParam(person); | 543 | output.addParam(person); |
527 | emit outputReady(output); | 544 | emit outputReady(output); |
@@ -553,24 +570,23 @@ void IRCMessageParser::parseNumericalNames(IRCMessage *message) { | |||
553 | 570 | ||
554 | nick = temp.right(temp.length()-1); | 571 | nick = temp.right(temp.length()-1); |
555 | switch (flagch) { | 572 | switch (flagch) { |
556 | case '@': flag = PERSON_FLAG_OP; break; | 573 | case '@': flag = IRCChannelPerson::PERSON_FLAG_OP; break; |
557 | case '+': flag = PERSON_FLAG_VOICE; break; | 574 | case '+': flag = IRCChannelPerson::PERSON_FLAG_VOICE; break; |
558 | case '%': flag = PERSON_FLAG_HALFOP; break; | 575 | case '%': flag = IRCChannelPerson::PERSON_FLAG_HALFOP; break; |
559 | default : flag = 0; break; | 576 | default : flag = 0; break; |
560 | } | 577 | } |
561 | } else { | 578 | } else { |
562 | nick = temp; | 579 | nick = temp; |
563 | } | 580 | } |
564 | 581 | ||
565 | IRCChannelPerson *chan_person = new IRCChannelPerson(); | ||
566 | IRCPerson *person = m_session->getPerson(nick); | 582 | IRCPerson *person = m_session->getPerson(nick); |
567 | if (person == 0) { | 583 | if (person == 0) { |
568 | person = new IRCPerson(); | 584 | person = new IRCPerson(); |
569 | person->setNick(nick); | 585 | person->setNick(nick); |
570 | m_session->addPerson(person); | 586 | m_session->addPerson(person); |
571 | } | 587 | } |
572 | chan_person->person = person; | 588 | IRCChannelPerson *chan_person = new IRCChannelPerson(person); |
573 | chan_person->flags = flag; | 589 | chan_person->setFlags(flag); |
574 | channel->addPerson(chan_person); | 590 | channel->addPerson(chan_person); |
575 | } | 591 | } |
576 | } else { | 592 | } else { |