summaryrefslogtreecommitdiff
authorerik <erik>2007-07-09 22:06:00 (UTC)
committer erik <erik>2007-07-09 22:06:00 (UTC)
commita91bbaee9eb419dc985d9f5c3689831c8aa75c1e (patch) (unidiff)
treeba0da224a93f7af1a80a4bef3186edff8dc9483f
parent1ec355e1cc016edd2e322ff7d57469feaa46474b (diff)
downloadopie-a91bbaee9eb419dc985d9f5c3689831c8aa75c1e.zip
opie-a91bbaee9eb419dc985d9f5c3689831c8aa75c1e.tar.gz
opie-a91bbaee9eb419dc985d9f5c3689831c8aa75c1e.tar.bz2
Fix for opie bug 1719. This should make opie-irc play nicer with utf-8.
Patches were culled from OE. Thanks to whoever the original patch author was.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircconnection.cpp5
-rw-r--r--noncore/net/opieirc/ircmessageparser.cpp4
2 files changed, 5 insertions, 4 deletions
diff --git a/noncore/net/opieirc/ircconnection.cpp b/noncore/net/opieirc/ircconnection.cpp
index 88e63f7..fb7e168 100644
--- a/noncore/net/opieirc/ircconnection.cpp
+++ b/noncore/net/opieirc/ircconnection.cpp
@@ -1,122 +1,123 @@
1#include <unistd.h> 1#include <unistd.h>
2#include <string.h> 2#include <string.h>
3 3
4#include <qstringlist.h> 4#include <qstringlist.h>
5#include <qdatetime.h> 5#include <qdatetime.h>
6 6
7#include "ircconnection.h" 7#include "ircconnection.h"
8 8
9IRCConnection::IRCConnection(IRCServer *server) { 9IRCConnection::IRCConnection(IRCServer *server) {
10 m_server = server; 10 m_server = server;
11 m_socket = new QSocket(this); 11 m_socket = new QSocket(this);
12 m_connected = FALSE; 12 m_connected = FALSE;
13 m_loggedIn = FALSE; 13 m_loggedIn = FALSE;
14 connect(m_socket, SIGNAL(connected()), this, SLOT(login())); 14 connect(m_socket, SIGNAL(connected()), this, SLOT(login()));
15 connect(m_socket, SIGNAL(readyRead()), this, SLOT(dataReady())); 15 connect(m_socket, SIGNAL(readyRead()), this, SLOT(dataReady()));
16 connect(m_socket, SIGNAL(error(int)), this, SLOT(error(int))); 16 connect(m_socket, SIGNAL(error(int)), this, SLOT(error(int)));
17 connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(disconnect())); 17 connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(disconnect()));
18 connect(m_socket, SIGNAL(delayedCloseFinished()), this, SLOT(disconnect())); 18 connect(m_socket, SIGNAL(delayedCloseFinished()), this, SLOT(disconnect()));
19} 19}
20 20
21/* Connect to the IRC server */ 21/* Connect to the IRC server */
22void IRCConnection::doConnect() { 22void IRCConnection::doConnect() {
23 ASSERT(!m_connected); 23 ASSERT(!m_connected);
24 m_socket->connectToHost(m_server->hostname(), m_server->port()); 24 m_socket->connectToHost(m_server->hostname(), m_server->port());
25} 25}
26 26
27/* Send commands to the IRC server */ 27/* Send commands to the IRC server */
28void IRCConnection::sendLine(QString line) { 28void IRCConnection::sendLine(QString line) {
29 while((line.right(1) == "\n") || (line.right(1) == "\r")) 29 while((line.right(1) == "\n") || (line.right(1) == "\r"))
30 line = line.left(line.length() - 1); 30 line = line.left(line.length() - 1);
31 line.append("\r\n"); 31 line.append("\r\n");
32 m_socket->writeBlock(line, line.length()); 32 QCString uline = line.utf8();
33 m_socket->writeBlock(uline, uline.length());
33} 34}
34 35
35void IRCConnection::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) { 36void IRCConnection::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) {
36 sendLine("NOTICE " + nickname + " :\001" + type + " " + args + "\001"); 37 sendLine("NOTICE " + nickname + " :\001" + type + " " + args + "\001");
37} 38}
38 39
39void IRCConnection::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) { 40void IRCConnection::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) {
40 sendLine("PRIVMSG " + nickname + " :\001" + type + " " + args + "\001"); 41 sendLine("PRIVMSG " + nickname + " :\001" + type + " " + args + "\001");
41} 42}
42 43
43void IRCConnection::sendCTCPPing(const QString &nickname) { 44void IRCConnection::sendCTCPPing(const QString &nickname) {
44 QDateTime tm; 45 QDateTime tm;
45 tm.setTime_t(0); 46 tm.setTime_t(0);
46 QString strtime = QString::number(tm.secsTo(QDateTime::currentDateTime())); 47 QString strtime = QString::number(tm.secsTo(QDateTime::currentDateTime()));
47 sendCTCPRequest(nickname, "PING", strtime); 48 sendCTCPRequest(nickname, "PING", strtime);
48} 49}
49 50
50void IRCConnection::whois(const QString &nickname) { 51void IRCConnection::whois(const QString &nickname) {
51 sendLine("WHOIS " + nickname); 52 sendLine("WHOIS " + nickname);
52} 53}
53 54
54/* 55/*
55 * login() is called right after the connection 56 * login() is called right after the connection
56 * to the IRC server has been established 57 * to the IRC server has been established
57 */ 58 */
58void IRCConnection::login() { 59void IRCConnection::login() {
59 char hostname[256]; 60 char hostname[256];
60 QString loginString; 61 QString loginString;
61 62
62 emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Connected, logging in .."))); 63 emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Connected, logging in ..")));
63 m_connected = TRUE; 64 m_connected = TRUE;
64 gethostname(hostname, sizeof(hostname)-1); 65 gethostname(hostname, sizeof(hostname)-1);
65 hostname[sizeof (hostname) - 1] = 0; 66 hostname[sizeof (hostname) - 1] = 0;
66 67
67 /* Create a logon string and send it */ 68 /* Create a logon string and send it */
68 if (m_server->password().length()>0) { 69 if (m_server->password().length()>0) {
69 loginString += "PASS " + m_server->password() + "\r\n"; 70 loginString += "PASS " + m_server->password() + "\r\n";
70 } 71 }
71 loginString += "NICK " + m_server->nick() + "\r\n" + 72 loginString += "NICK " + m_server->nick() + "\r\n" +
72 "USER " + m_server->username() + " " + hostname + 73 "USER " + m_server->username() + " " + hostname +
73 " " + m_server->hostname() + " :" + m_server->realname() + "\r\n"; 74 " " + m_server->hostname() + " :" + m_server->realname() + "\r\n";
74 sendLine(loginString); 75 sendLine(loginString);
75} 76}
76 77
77/* Called when data arrives on the socket */ 78/* Called when data arrives on the socket */
78void IRCConnection::dataReady() { 79void IRCConnection::dataReady() {
79 while(m_socket->canReadLine()) { 80 while(m_socket->canReadLine()) {
80 IRCMessage message(m_socket->readLine()); 81 IRCMessage message(QString::fromUtf8(m_socket->readLine()));
81 if (!m_loggedIn && message.isNumerical() && message.commandNumber() == 1) { 82 if (!m_loggedIn && message.isNumerical() && message.commandNumber() == 1) {
82 /* Now autojoin all channels specified inside the server profile */ 83 /* Now autojoin all channels specified inside the server profile */
83 QStringList channels = QStringList::split(QChar(','), m_server->channels()); 84 QStringList channels = QStringList::split(QChar(','), m_server->channels());
84 for (QStringList::Iterator it = channels.begin(); it != channels.end(); ++it) { 85 for (QStringList::Iterator it = channels.begin(); it != channels.end(); ++it) {
85 QString channelName = (*it).stripWhiteSpace(); 86 QString channelName = (*it).stripWhiteSpace();
86 if (channelName.startsWith("#") || channelName.startsWith("+")) { 87 if (channelName.startsWith("#") || channelName.startsWith("+")) {
87 sendLine("JOIN "+ channelName); 88 sendLine("JOIN "+ channelName);
88 } 89 }
89 } 90 }
90 m_loggedIn = TRUE; 91 m_loggedIn = TRUE;
91 emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Successfully logged in."))); 92 emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Successfully logged in.")));
92 } 93 }
93 emit messageArrived(&message); 94 emit messageArrived(&message);
94 } 95 }
95} 96}
96 97
97/* Called if any type of socket error occurs */ 98/* Called if any type of socket error occurs */
98void IRCConnection::error(int num) { 99void IRCConnection::error(int num) {
99 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Socket error : ") + strerror(num))); 100 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Socket error : ") + strerror(num)));
100} 101}
101 102
102void IRCConnection::disconnect() { 103void IRCConnection::disconnect() {
103 m_connected = FALSE; 104 m_connected = FALSE;
104 m_loggedIn = FALSE; 105 m_loggedIn = FALSE;
105 emit outputReady(IRCOutput(OUTPUT_CONNCLOSE, tr("Connection closed"))); 106 emit outputReady(IRCOutput(OUTPUT_CONNCLOSE, tr("Connection closed")));
106} 107}
107 108
108bool IRCConnection::isConnected() { 109bool IRCConnection::isConnected() {
109 return m_connected; 110 return m_connected;
110} 111}
111 112
112bool IRCConnection::isLoggedIn() { 113bool IRCConnection::isLoggedIn() {
113 return m_loggedIn; 114 return m_loggedIn;
114} 115}
115 116
116void IRCConnection::close() { 117void IRCConnection::close() {
117 m_socket->close(); 118 m_socket->close();
118 if (m_socket->state()==QSocket::Idle) { 119 if (m_socket->state()==QSocket::Idle) {
119 disconnect(); 120 disconnect();
120 } 121 }
121} 122}
122 123
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp
index c449a65..ae47f69 100644
--- a/noncore/net/opieirc/ircmessageparser.cpp
+++ b/noncore/net/opieirc/ircmessageparser.cpp
@@ -286,398 +286,398 @@ void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) {
286 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); 286 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender")));
287 } 287 }
288 } 288 }
289 else { 289 else {
290 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) )); 290 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) ));
291 } 291 }
292 } 292 }
293 else {emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type"))); 293 else {emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type")));
294 } 294 }
295} 295}
296 296
297void IRCMessageParser::parseLiteralNick(IRCMessage *message) { 297void IRCMessageParser::parseLiteralNick(IRCMessage *message) {
298 IRCPerson mask(message->prefix()); 298 IRCPerson mask(message->prefix());
299 m_session->updateNickname(mask.nick(), message->param(0)); 299 m_session->updateNickname(mask.nick(), message->param(0));
300 /* this way of handling nick changes really sucks 300 /* this way of handling nick changes really sucks
301 if (mask.nick() == m_session->m_server->nick()) { 301 if (mask.nick() == m_session->m_server->nick()) {
302 We are changing our nickname 302 We are changing our nickname
303 m_session->m_server->setNick(message->param(0)); 303 m_session->m_server->setNick(message->param(0));
304 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0))); 304 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0)));
305 output.addParam(0); 305 output.addParam(0);
306 emit outputReady(output); 306 emit outputReady(output);
307 } else { 307 } else {
308 Someone else is 308 Someone else is
309 RCPerson *person = m_session->getPerson(mask.nick()); 309 RCPerson *person = m_session->getPerson(mask.nick());
310 if (person) { 310 if (person) {
311 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 311 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
312 312
313 new code starts here -- this removes the person from all channels 313 new code starts here -- this removes the person from all channels
314 QList<IRCChannel> channels; 314 QList<IRCChannel> channels;
315 m_session->getChannelsByPerson(person, channels); 315 m_session->getChannelsByPerson(person, channels);
316 QListIterator<IRCChannel> it(channels); 316 QListIterator<IRCChannel> it(channels);
317 for (;it.current(); ++it) { 317 for (;it.current(); ++it) {
318 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 318 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
319 it.current()->removePerson(chanperson); 319 it.current()->removePerson(chanperson);
320 chanperson->person->setNick(message->param(0)); 320 chanperson->person->setNick(message->param(0));
321 it.current()->addPerson(chanperson); 321 it.current()->addPerson(chanperson);
322 IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 322 IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
323 output.addParam(person); 323 output.addParam(person);
324 emit outputReady(output); 324 emit outputReady(output);
325 } 325 }
326 new code ends here 326 new code ends here
327 } else { 327 } else {
328 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); 328 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person")));
329 } 329 }
330 }*/ 330 }*/
331} 331}
332 332
333void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { 333void IRCMessageParser::parseLiteralQuit(IRCMessage *message) {
334 IRCPerson mask(message->prefix()); 334 IRCPerson mask(message->prefix());
335 IRCPerson *person = m_session->getPerson(mask.nick()); 335 IRCPerson *person = m_session->getPerson(mask.nick());
336 if (person) { 336 if (person) {
337 QList<IRCChannel> channels; 337 QList<IRCChannel> channels;
338 m_session->getChannelsByPerson(person, channels); 338 m_session->getChannelsByPerson(person, channels);
339 QListIterator<IRCChannel> it(channels); 339 QListIterator<IRCChannel> it(channels);
340 for (;it.current(); ++it) { 340 for (;it.current(); ++it) {
341 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 341 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
342 it.current()->removePerson(chanperson); 342 it.current()->removePerson(chanperson);
343 delete chanperson; 343 delete chanperson;
344 } 344 }
345 m_session->removePerson(person); 345 m_session->removePerson(person);
346 IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) )); 346 IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) ));
347 output.addParam(person); 347 output.addParam(person);
348 emit outputReady(output); 348 emit outputReady(output);
349 delete person; 349 delete person;
350 } else { 350 } else {
351 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); 351 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?")));
352 } 352 }
353} 353}
354 354
355void IRCMessageParser::parseLiteralTopic(IRCMessage *message) { 355void IRCMessageParser::parseLiteralTopic(IRCMessage *message) {
356 IRCPerson mask(message->prefix()); 356 IRCPerson mask(message->prefix());
357 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 357 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
358 if (channel) { 358 if (channel) {
359 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\""); 359 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\"");
360 output.addParam(channel); 360 output.addParam(channel);
361 emit outputReady(output); 361 emit outputReady(output);
362 } else { 362 } else {
363 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?"))); 363 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?")));
364 } 364 }
365} 365}
366 366
367void IRCMessageParser::parseLiteralError(IRCMessage *message) { 367void IRCMessageParser::parseLiteralError(IRCMessage *message) {
368 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); 368 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters()));
369} 369}
370 370
371void IRCMessageParser::parseCTCPPing(IRCMessage *message) { 371void IRCMessageParser::parseCTCPPing(IRCMessage *message) {
372 IRCPerson mask(message->prefix()); 372 IRCPerson mask(message->prefix());
373 if(message->isCTCPReply()) { 373 if(message->isCTCPReply()) {
374 unsigned int sentTime = message->param(0).toUInt(); 374 unsigned int sentTime = message->param(0).toUInt();
375 QDateTime tm; 375 QDateTime tm;
376 tm.setTime_t(0); 376 tm.setTime_t(0);
377 unsigned int receivedTime = tm.secsTo(QDateTime::currentDateTime()); 377 unsigned int receivedTime = tm.secsTo(QDateTime::currentDateTime());
378 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING reply from %1: %2 seconds").arg(mask.nick()).arg(receivedTime-sentTime))); 378 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING reply from %1: %2 seconds").arg(mask.nick()).arg(receivedTime-sentTime)));
379 return; 379 return;
380 } 380 }
381 m_session->m_connection->sendCTCPReply(mask.nick(), "PING", message->allParameters()); 381 m_session->m_connection->sendCTCPReply(mask.nick(), "PING", message->allParameters());
382 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING request from %1").arg(mask.nick()))); 382 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING request from %1").arg(mask.nick())));
383 383
384 //IRCPerson mask(message->prefix()); 384 //IRCPerson mask(message->prefix());
385 QString dest = message->ctcpDestination(); 385 QString dest = message->ctcpDestination();
386 if (dest.startsWith("#")) { 386 if (dest.startsWith("#")) {
387 IRCChannel *channel = m_session->getChannel(dest.lower()); 387 IRCChannel *channel = m_session->getChannel(dest.lower());
388 if (channel) { 388 if (channel) {
389 IRCChannelPerson *person = channel->getPerson(mask.nick()); 389 IRCChannelPerson *person = channel->getPerson(mask.nick());
390 if (person) { 390 if (person) {
391 IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ; 391 IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ;
392 output.addParam(channel); 392 output.addParam(channel);
393 output.addParam(person); 393 output.addParam(person);
394 emit outputReady(output); 394 emit outputReady(output);
395 } else { 395 } else {
396 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?"))); 396 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?")));
397 } 397 }
398 } else { 398 } else {
399 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown channel - Desynchronized?"))); 399 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown channel - Desynchronized?")));
400 } 400 }
401 } else { 401 } else {
402 if (message->ctcpDestination() == m_session->m_server->nick()) { 402 if (message->ctcpDestination() == m_session->m_server->nick()) {
403 IRCPerson *person = m_session->getPerson(mask.nick()); 403 IRCPerson *person = m_session->getPerson(mask.nick());
404 if (!person) { 404 if (!person) {
405 /* Person not yet known, create and add to the current session */ 405 /* Person not yet known, create and add to the current session */
406 person = new IRCPerson(message->prefix()); 406 person = new IRCPerson(message->prefix());
407 m_session->addPerson(person); 407 m_session->addPerson(person);
408 } 408 }
409 IRCOutput output(OUTPUT_QUERYACTION, tr("Received a CTCP PING from ")+ mask.nick() ); 409 IRCOutput output(OUTPUT_QUERYACTION, tr("Received a CTCP PING from ")+ mask.nick() );
410 output.addParam(person); 410 output.addParam(person);
411 emit outputReady(output); 411 emit outputReady(output);
412 } else { 412 } else {
413 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient"))); 413 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient")));
414 } 414 }
415 } 415 }
416 416
417} 417}
418 418
419void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { 419void IRCMessageParser::parseCTCPVersion(IRCMessage *message) {
420 IRCPerson mask(message->prefix()); 420 IRCPerson mask(message->prefix());
421 IRCOutput output(OUTPUT_CTCP); 421 IRCOutput output(OUTPUT_CTCP);
422 if(message->isCTCPRequest()) { 422 if(message->isCTCPRequest()) {
423 m_session->m_connection->sendCTCPReply(mask.nick(), "VERSION", APP_VERSION " " APP_COPYSTR); 423 m_session->m_connection->sendCTCPReply(mask.nick(), "VERSION", APP_VERSION " " APP_COPYSTR);
424 output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick()); 424 output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick());
425 } 425 }
426 426
427 else { 427 else {
428 output.setMessage("Received CTCP VERSION reply from " + mask.nick() + ":" + message->param(0)); 428 output.setMessage("Received CTCP VERSION reply from " + mask.nick() + ":" + message->param(0));
429 } 429 }
430 emit outputReady(output); 430 emit outputReady(output);
431} 431}
432 432
433void IRCMessageParser::parseCTCPAction(IRCMessage *message) { 433void IRCMessageParser::parseCTCPAction(IRCMessage *message) {
434 IRCPerson mask(message->prefix()); 434 IRCPerson mask(message->prefix());
435 QString dest = message->ctcpDestination(); 435 QString dest = message->ctcpDestination();
436 if (dest.startsWith("#")) { 436 if (dest.startsWith("#")) {
437 IRCChannel *channel = m_session->getChannel(dest.lower()); 437 IRCChannel *channel = m_session->getChannel(dest.lower());
438 if (channel) { 438 if (channel) {
439 IRCChannelPerson *person = channel->getPerson(mask.nick()); 439 IRCChannelPerson *person = channel->getPerson(mask.nick());
440 if (person) { 440 if (person) {
441 IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); 441 IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0));
442 output.addParam(channel); 442 output.addParam(channel);
443 output.addParam(person); 443 output.addParam(person);
444 emit outputReady(output); 444 emit outputReady(output);
445 } else { 445 } else {
446 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?"))); 446 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?")));
447 } 447 }
448 } else { 448 } else {
449 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?"))); 449 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?")));
450 } 450 }
451 } else { 451 } else {
452 if (message->ctcpDestination() == m_session->m_server->nick()) { 452 if (message->ctcpDestination() == m_session->m_server->nick()) {
453 IRCPerson *person = m_session->getPerson(mask.nick()); 453 IRCPerson *person = m_session->getPerson(mask.nick());
454 if (!person) { 454 if (!person) {
455 /* Person not yet known, create and add to the current session */ 455 /* Person not yet known, create and add to the current session */
456 person = new IRCPerson(message->prefix()); 456 person = new IRCPerson(message->prefix());
457 m_session->addPerson(person); 457 m_session->addPerson(person);
458 } 458 }
459 IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); 459 IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0));
460 output.addParam(person); 460 output.addParam(person);
461 emit outputReady(output); 461 emit outputReady(output);
462 } else { 462 } else {
463 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); 463 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient")));
464 } 464 }
465 } 465 }
466} 466}
467 467
468void IRCMessageParser::parseCTCPDCC(IRCMessage *message) { 468void IRCMessageParser::parseCTCPDCC(IRCMessage *message) {
469 QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace()); 469 QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace());
470 470
471 if(params[0] == "SEND") { 471 if(params[0] == "SEND") {
472 QString nickname = IRCPerson(message->prefix()).nick(); 472 QString nickname = IRCPerson(message->prefix()).nick();
473 if( params.count() != 5) { 473 if( params.count() != 5) {
474 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from %1").arg(nickname))); 474 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from %1").arg(nickname)));
475 return; 475 return;
476 } 476 }
477 bool accepted = DCCTransferTab::confirm(static_cast<QWidget*>(m_session->parent()), nickname, params[1], params[4].toUInt()); 477 bool accepted = DCCTransferTab::confirm(static_cast<QWidget*>(m_session->parent()), nickname, params[1], params[4].toUInt());
478 if(!accepted) 478 if(!accepted)
479 return; 479 return;
480 QString filename = Opie::Ui::OFileDialog::getSaveFileName(Opie::Ui::OFileSelector::EXTENDED_ALL, 480 QString filename = Opie::Ui::OFileDialog::getSaveFileName(Opie::Ui::OFileSelector::EXTENDED_ALL,
481 QString::null, params[1], MimeTypes(), 0, tr("Save As")); 481 QString::null, params[1], MimeTypes(), 0, tr("Save As"));
482 if(filename.isEmpty()) 482 if(filename.isEmpty())
483 return; 483 return;
484 484
485 odebug << "Receiving file " << filename << " from " << nickname << oendl; 485 odebug << "Receiving file " << filename << " from " << nickname << oendl;
486 static_cast<IRCServerTab*>(m_session->parent())->mainwindow()->addDCC(DCCTransfer::Recv, params[2].toUInt(), params[3].toUInt(), 486 static_cast<IRCServerTab*>(m_session->parent())->mainwindow()->addDCC(DCCTransfer::Recv, params[2].toUInt(), params[3].toUInt(),
487 filename, nickname, params[4].toUInt()); 487 filename, nickname, params[4].toUInt());
488 } 488 }
489} 489}
490 490
491void IRCMessageParser::parseLiteralMode(IRCMessage *message) { 491void IRCMessageParser::parseLiteralMode(IRCMessage *message) {
492 IRCPerson mask(message->prefix()); 492 IRCPerson mask(message->prefix());
493 493
494 if (IRCChannel::isValid(message->param(0))) { 494 if (IRCChannel::isValid(message->param(0))) {
495 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 495 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
496 if (channel) { 496 if (channel) {
497 QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); 497 QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1);
498 QTextIStream stream(&parameters); 498 QTextIStream stream(&parameters);
499 bool set = FALSE; 499 bool set = FALSE;
500 while (!stream.atEnd()) { 500 while (!stream.atEnd()) {
501 stream >> temp; 501 stream >> temp;
502 if (temp.startsWith("+")) { 502 if (temp.startsWith("+")) {
503 set = TRUE; 503 set = TRUE;
504 temp = temp.right(1); 504 temp = temp.right(1);
505 } 505 }
506 else 506 else
507 if (temp.startsWith("-")) { 507 if (temp.startsWith("-")) {
508 set = FALSE; 508 set = FALSE;
509 temp = temp.right(1); 509 temp = temp.right(1);
510 } 510 }
511 else { 511 else {
512 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); 512 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type")));
513 return; 513 return;
514 } 514 }
515 if (temp == "o") { 515 if (temp == "o") {
516 stream >> temp; 516 stream >> temp;
517 IRCChannelPerson *person = channel->getPerson(temp); 517 IRCChannelPerson *person = channel->getPerson(temp);
518 if (person) { 518 if (person) {
519 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set)); 519 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set));
520 output.addParam(channel); 520 output.addParam(channel);
521 output.addParam(person); 521 output.addParam(person);
522 emit outputReady(output); 522 emit outputReady(output);
523 } 523 }
524 else { 524 else {
525 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); 525 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?")));
526 } 526 }
527 } 527 }
528 else 528 else
529 if (temp == "v") { 529 if (temp == "v") {
530 stream >> temp; 530 stream >> temp;
531 IRCChannelPerson *person = channel->getPerson(temp); 531 IRCChannelPerson *person = channel->getPerson(temp);
532 if (person) { 532 if (person) {
533 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set)); 533 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set));
534 output.addParam(channel); 534 output.addParam(channel);
535 output.addParam(person); 535 output.addParam(person);
536 emit outputReady(output); 536 emit outputReady(output);
537 } 537 }
538 else { 538 else {
539 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); 539 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?")));
540 } 540 }
541 } 541 }
542 else { 542 else {
543 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag"))); 543 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag")));
544 } 544 }
545 } 545 }
546 } else { 546 } else {
547 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?"))); 547 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?")));
548 } 548 }
549 } else { 549 } else {
550 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet"))); 550 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet")));
551 } 551 }
552} 552}
553 553
554void IRCMessageParser::parseLiteralKick(IRCMessage *message) { 554void IRCMessageParser::parseLiteralKick(IRCMessage *message) {
555 IRCPerson mask(message->prefix()); 555 IRCPerson mask(message->prefix());
556 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 556 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
557 if (channel) { 557 if (channel) {
558 IRCChannelPerson *person = channel->getPerson(message->param(1)); 558 IRCChannelPerson *person = channel->getPerson(message->param(1));
559 if (person) { 559 if (person) {
560 if (person->nick() == m_session->m_server->nick()) { 560 if (person->nick() == m_session->m_server->nick()) {
561 m_session->removeChannel(channel); 561 m_session->removeChannel(channel);
562 IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")"); 562 IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")");
563 output.addParam(channel); 563 output.addParam(channel);
564 emit outputReady(output); 564 emit outputReady(output);
565 } else { 565 } else {
566 /* someone else got kicked */ 566 /* someone else got kicked */
567 channel->removePerson(person); 567 channel->removePerson(person);
568 IRCOutput output(OUTPUT_OTHERKICK, person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")"); 568 IRCOutput output(OUTPUT_OTHERKICK, person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")");
569 output.addParam(channel); 569 output.addParam(channel);
570 output.addParam(person); 570 output.addParam(person);
571 emit outputReady(output); 571 emit outputReady(output);
572 } 572 }
573 } else { 573 } else {
574 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?"))); 574 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?")));
575 } 575 }
576 } else { 576 } else {
577 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?"))); 577 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?")));
578 } 578 }
579} 579}
580 580
581void IRCMessageParser::parseNumericalNames(IRCMessage *message) { 581void IRCMessageParser::parseNumericalNames(IRCMessage *message) {
582 /* Name list sent when joining a channel */ 582 /* Name list sent when joining a channel */
583 IRCChannel *channel = m_session->getChannel(message->param(2).lower()); 583 IRCChannel *channel = m_session->getChannel(message->param(2).lower());
584 if (channel != 0) { 584 if (channel != 0) {
585 QString people = message->param(3); 585 QString people = message->param(3);
586 QTextIStream stream(&people); 586 QTextIStream stream(&people);
587 QString temp; 587 QString temp;
588 588
589 while (!stream.atEnd()) { 589 while (!stream.atEnd()) {
590 stream >> temp; 590 stream >> temp;
591 591
592 char flagch = temp.at(0).latin1(); 592 char flagch = temp.at(0).latin1();
593 int flag = 0; 593 int flag = 0;
594 QString nick; 594 QString nick;
595 /* Parse person flags */ 595 /* Parse person flags */
596 if (flagch == '~' || flagch == '&' || flagch == '@' || flagch == '+' || 596 if (flagch == '~' || flagch == '&' || flagch == '@' || flagch == '+' ||
597 flagch=='%' || flagch == '*') { 597 flagch=='%' || flagch == '*') {
598 598
599 nick = temp.right(temp.length()-1); 599 nick = temp.right(temp.length()-1);
600 switch (flagch) { 600 switch (flagch) {
601 /** 601 /**
602 * @note '~' and `&' are extensions of the unrealircd irc 602 * @note '~' and `&' are extensions of the unrealircd irc
603 * daemon. This app can't see users w/out checking for these 603 * daemon. This app can't see users w/out checking for these
604 * chars. 604 * chars.
605 */ 605 */
606 case '~': 606 case '~':
607 case '&': 607 case '&':
608 case '@': 608 case '@':
609 flag = IRCChannelPerson::PERSON_FLAG_OP; 609 flag = IRCChannelPerson::PERSON_FLAG_OP;
610 break; 610 break;
611 case '+': 611 case '+':
612 flag = IRCChannelPerson::PERSON_FLAG_VOICE; 612 flag = IRCChannelPerson::PERSON_FLAG_VOICE;
613 break; 613 break;
614 case '%': 614 case '%':
615 flag = IRCChannelPerson::PERSON_FLAG_HALFOP; 615 flag = IRCChannelPerson::PERSON_FLAG_HALFOP;
616 break; 616 break;
617 default : 617 default :
618 flag = 0; 618 flag = 0;
619 break; 619 break;
620 } 620 }
621 } else 621 } else
622 nick = temp; 622 nick = temp;
623 623
624 IRCPerson *person = m_session->getPerson(nick); 624 IRCPerson *person = m_session->getPerson(nick);
625 if (person == 0) { 625 if (person == 0) {
626 person = new IRCPerson(); 626 person = new IRCPerson();
627 person->setNick(nick); 627 person->setNick(nick);
628 m_session->addPerson(person); 628 m_session->addPerson(person);
629 } 629 }
630 IRCChannelPerson *chan_person = new IRCChannelPerson(person); 630 IRCChannelPerson *chan_person = new IRCChannelPerson(person);
631 chan_person->setFlags(flag); 631 chan_person->setFlags(flag);
632 channel->addPerson(chan_person); 632 channel->addPerson(chan_person);
633 } 633 }
634 } else 634 } else
635 emit outputReady(IRCOutput(OUTPUT_ERROR, 635 emit outputReady(IRCOutput(OUTPUT_ERROR,
636 tr("Server message with unknown channel"))); 636 tr("Server message with unknown channel")));
637} 637}
638 638
639void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { 639void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) {
640 /* Done syncing to channel */ 640 /* Done syncing to channel */
641 IRCChannel *channel = m_session->getChannel(message->param(1).lower()); 641 IRCChannel *channel = m_session->getChannel(message->param(1).lower());
642 if (channel) { 642 if (channel) {
643 channel->setHasPeople(TRUE); 643 channel->setHasPeople(TRUE);
644 /* Yes, we want the names before anything happens inside the GUI */ 644 /* Yes, we want the names before anything happens inside the GUI */
645 IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); 645 IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname());
646 output.addParam(channel); 646 output.addParam(channel);
647 emit outputReady(output); 647 emit outputReady(output);
648 } else { 648 } else {
649 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); 649 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel")));
650 } 650 }
651} 651}
652 652
653 653
654void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { 654void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) {
655 /* If we are connnected this error is not critical */ 655 /* If we are connnected this error is not critical */
656 if(m_session->isLoggedIn()) 656 if(m_session->isLoggedIn())
657 return; 657 return;
658 658
659 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); 659 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname")));
660 m_session->endSession(); 660 m_session->endSession();
661} 661}
662 662
663void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) { 663void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) {
664 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname"))); 664 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname")));
665} 665}
666 666
667void IRCMessageParser::parseNumericalTopic(IRCMessage *message) { 667void IRCMessageParser::parseNumericalTopic(IRCMessage *message) {
668 IRCChannel *channel = m_session->getChannel(message->param(1).lower()); 668 IRCChannel *channel = m_session->getChannel(message->param(1).lower());
669 if (channel) { 669 if (channel) {
670 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\"")); 670 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel ") + channel->channelname() + tr(" is \"") + message->param(2) + "\"");
671 output.addParam(channel); 671 output.addParam(channel);
672 emit outputReady(output); 672 emit outputReady(output);
673 } else { 673 } else {
674 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\"")); 674 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel ") + message->param(1) + tr(" is \"") + message->param(2) + "\"");
675 output.addParam(0); 675 output.addParam(0);
676 emit outputReady(output); 676 emit outputReady(output);
677 } 677 }
678} 678}
679 679
680void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) { 680void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) {
681} 681}
682 682
683 683