summaryrefslogtreecommitdiff
Unidiff
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
@@ -622,62 +622,62 @@ void IRCMessageParser::parseNumericalNames(IRCMessage *message) {
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