summaryrefslogtreecommitdiff
authorskyhusker <skyhusker>2005-01-16 02:14:38 (UTC)
committer skyhusker <skyhusker>2005-01-16 02:14:38 (UTC)
commit986280fcb93a2c9550aa83a3109deb885ce50e8f (patch) (unidiff)
treed507028d909e7e7f1703aa80b3b2d7201573bd93
parente420e24bb1506e313cc38174111d424ba7274e33 (diff)
downloadopie-986280fcb93a2c9550aa83a3109deb885ce50e8f.zip
opie-986280fcb93a2c9550aa83a3109deb885ce50e8f.tar.gz
opie-986280fcb93a2c9550aa83a3109deb885ce50e8f.tar.bz2
Fixed a bug in nickname handling with networks using nickname:password for auth
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircmessageparser.cpp48
1 files changed, 28 insertions, 20 deletions
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp
index fde156c..cfad2c1 100644
--- a/noncore/net/opieirc/ircmessageparser.cpp
+++ b/noncore/net/opieirc/ircmessageparser.cpp
@@ -50,52 +50,52 @@ IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = {
50 { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN 50 { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN
51 { 265, "%1", "1", 0 }, // RPL_LOCALUSERS 51 { 265, "%1", "1", 0 }, // RPL_LOCALUSERS
52 { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS 52 { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS
53 { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5" }, // RPL_WHOISUSER 53 { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5" }, // RPL_WHOISUSER
54 { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER 54 { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER
55 { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE 55 { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE
56 { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS 56 { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS
57 { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT 57 { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT
58 { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC 58 { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC
59 { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/ 59 { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/
60 { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY 60 { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY
61 { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES 61 { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES
62 { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS 62 { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS
63 { 372, "%1", "1", 0 }, // RPL_MOTD 63 { 372, "%1", "1", 0 }, // RPL_MOTD
64 { 375, "%1", "1", 0 }, // RPL_MOTDSTART 64 { 375, "%1", "1", 0 }, // RPL_MOTDSTART
65 { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD 65 { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD
66 { 377, "%1", "1", 0 }, // RPL_MOTD2 66 { 377, "%1", "1", 0 }, // RPL_MOTD2
67 { 378, "%1", "1", 0 }, // RPL_MOTD3 67 { 378, "%1", "1", 0 }, // RPL_MOTD3
68 { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME 68 { 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 69 { 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 70 { 406, QT_TR_NOOP("There is no history information for %1"), "1" }, // ERR_WASNOSUCHNICK
71 { 409, "%1", "1", 0 }, // ERR_NOORIGIN 71 { 409, "%1", "1", 0 }, // ERR_NOORIGIN
72 { 411, "%1", "1", 0 }, // ERR_NORECIPIENT 72 { 411, "%1", "1", 0 }, // ERR_NORECIPIENT
73 { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND 73 { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND
74 { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_NOMOTD 74 { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_ERR_UNKNOWNCOMMAND
75 { 422, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL
76 { 422, "%1", "1", 0 }, // ERR_NOMOTD 75 { 422, "%1", "1", 0 }, // ERR_NOMOTD
77 { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE 76 { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE
77 { 442, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL
78 { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK 78 { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK
79 { 482, QT_TR_NOOP("[%1] Operation not permitted, you don't have enough channel privileges"), "1", 0 }, //ERR_CHANOPRIVSNEEDED 79 { 482, QT_TR_NOOP("[%1] Operation not permitted, you don't have enough channel privileges"), "1", 0 }, //ERR_CHANOPRIVSNEEDED
80 { 0, 0, 0, 0 } 80 { 0, 0, 0, 0 }
81}; 81};
82 82
83 83
84IRCMessageParser::IRCMessageParser(IRCSession *session) { 84IRCMessageParser::IRCMessageParser(IRCSession *session) {
85 m_session = session; 85 m_session = session;
86} 86}
87 87
88void IRCMessageParser::parse(IRCMessage *message) { 88void IRCMessageParser::parse(IRCMessage *message) {
89 /* Find out what kind of message we have here and call the appropriate handler using 89 /* Find out what kind of message we have here and call the appropriate handler using
90 the parser tables. If no handler can be found, print out an error message */ 90 the parser tables. If no handler can be found, print out an error message */
91 if (message->isNumerical()) { 91 if (message->isNumerical()) {
92 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { 92 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) {
93 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { 93 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) {
94 parseNumerical(message, i); 94 parseNumerical(message, i);
95 return; 95 return;
96 } 96 }
97 } 97 }
98 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) ))); 98 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) )));
99 } else if (message->isCTCP()) { 99 } else if (message->isCTCP()) {
100 for (int i=0; ctcpParserProcTable[i].commandName; i++) { 100 for (int i=0; ctcpParserProcTable[i].commandName; i++) {
101 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { 101 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) {
@@ -115,48 +115,52 @@ void IRCMessageParser::parse(IRCMessage *message) {
115 } 115 }
116} 116}
117 117
118void IRCMessageParser::parseNumerical(IRCMessage *message, int position) { 118void IRCMessageParser::parseNumerical(IRCMessage *message, int position) {
119 QString out = tr(numericalParserProcTable[position].message); 119 QString out = tr(numericalParserProcTable[position].message);
120 QString paramString = numericalParserProcTable[position].params; 120 QString paramString = numericalParserProcTable[position].params;
121 121
122 if(!out.isEmpty() && !paramString.isEmpty()) { 122 if(!out.isEmpty() && !paramString.isEmpty()) {
123 QStringList params = message->params(numericalParserProcTable[position].params); 123 QStringList params = message->params(numericalParserProcTable[position].params);
124 124
125 QStringList::Iterator end = params.end(); 125 QStringList::Iterator end = params.end();
126 for (QStringList::Iterator it = params.begin(); it != end; ++it) { 126 for (QStringList::Iterator it = params.begin(); it != end; ++it) {
127 out = out.arg(*it); 127 out = out.arg(*it);
128 } 128 }
129 129
130 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); 130 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
131 } 131 }
132 132
133 if(numericalParserProcTable[position].proc) 133 if(numericalParserProcTable[position].proc)
134 (this->*(numericalParserProcTable[position].proc))(message); 134 (this->*(numericalParserProcTable[position].proc))(message);
135} 135}
136 136
137void IRCMessageParser::parseNumericalServerName(IRCMessage *message) { 137void IRCMessageParser::parseNumericalServerName(IRCMessage *message) {
138 emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>")); 138 emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>"));
139 /* Register EFFECTIVE nickname, some networks (as irc-hispano) uses nick:password
140 * for authentication and the parser gets confused */
141 m_session->m_server->setNick(message->param(0));
142
139} 143}
140 144
141void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) { 145void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) {
142 m_session->setValidUsermodes(message->param(2)); 146 m_session->setValidUsermodes(message->param(2));
143 m_session->setValidChannelmodes(message->param(3)); 147 m_session->setValidChannelmodes(message->param(3));
144 148
145} 149}
146 150
147void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) { 151void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) {
148 /* XXX: Add some usefull features here */ 152 /* XXX: Add some usefull features here */
149 QString out = message->allParameters(); 153 QString out = message->allParameters();
150 out = out.mid(out.find(' ')+1); 154 out = out.mid(out.find(' ')+1);
151 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); 155 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
152} 156}
153void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) { 157void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) {
154 QDateTime dt; 158 QDateTime dt;
155 QTime t; 159 QTime t;
156 t = t.addSecs(message->param(2).toInt()); 160 t = t.addSecs(message->param(2).toInt());
157 dt.setTime_t(message->param(3).toInt()); 161 dt.setTime_t(message->param(3).toInt());
158 162
159 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 has been idle for %2").arg(message->param(1)).arg(t.toString()))); 163 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 has been idle for %2").arg(message->param(1)).arg(t.toString())));
160 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 signed on %2").arg(message->param(1)).arg(dt.toString()))); 164 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 signed on %2").arg(message->param(1)).arg(dt.toString())));
161 165
162} 166}
@@ -228,67 +232,71 @@ void IRCMessageParser::parseLiteralPart(IRCMessage *message) {
228 emit outputReady(output); 232 emit outputReady(output);
229 delete person; 233 delete person;
230 } else { 234 } else {
231 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); 235 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?")));
232 } 236 }
233 } 237 }
234 } else { 238 } else {
235 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?"))); 239 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?")));
236 } 240 }
237} 241}
238 242
239void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { 243void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) {
240 if (m_session->m_server->nick().lower() == message->param(0).lower() ) { 244 if (m_session->m_server->nick().lower() == message->param(0).lower() ) {
241 /* IRC Query message detected, verify sender and display it */ 245 /* IRC Query message detected, verify sender and display it */
242 IRCPerson mask(message->prefix()); 246 IRCPerson mask(message->prefix());
243 IRCPerson *person = m_session->getPerson(mask.nick()); 247 IRCPerson *person = m_session->getPerson(mask.nick());
244 if (!person) { 248 if (!person) {
245 /* Person not yet known, create and add to the current session */ 249 /* Person not yet known, create and add to the current session */
246 person = new IRCPerson(message->prefix()); 250 person = new IRCPerson(message->prefix());
247 m_session->addPerson(person); 251 m_session->addPerson(person);
248 } 252 }
249 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1)); 253 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1));
250 output.addParam(person); 254 output.addParam(person);
251 emit outputReady(output); 255 emit outputReady(output);
252 } else if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') { 256 }
253 /* IRC Channel message detected, verify sender, channel and display it */ 257 else
254 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 258 if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') {
255 if (channel) { 259 /* IRC Channel message detected, verify sender, channel and display it */
256 IRCPerson mask(message->prefix()); 260 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
257 IRCChannelPerson *person = channel->getPerson(mask.nick()); 261 if (channel) {
258 if (person) { 262 IRCPerson mask(message->prefix());
259 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); 263 IRCChannelPerson *person = channel->getPerson(mask.nick());
260 output.addParam(channel); 264 if (person) {
261 output.addParam(person); 265 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1));
262 emit outputReady(output); 266 output.addParam(channel);
263 } else { 267 output.addParam(person);
264 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); 268 emit outputReady(output);
269 }
270 else {
271 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender")));
272 }
273 }
274 else {
275 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) ));
265 } 276 }
266 } else { 277 }
267 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) )); 278 else {emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type")));
268 }
269 } else {
270 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type")));
271 } 279 }
272} 280}
273 281
274void IRCMessageParser::parseLiteralNick(IRCMessage *message) { 282void IRCMessageParser::parseLiteralNick(IRCMessage *message) {
275 IRCPerson mask(message->prefix()); 283 IRCPerson mask(message->prefix());
276 m_session->updateNickname(mask.nick(), message->param(0)); 284 m_session->updateNickname(mask.nick(), message->param(0));
277 /* this way of handling nick changes really sucks 285 /* this way of handling nick changes really sucks
278 if (mask.nick() == m_session->m_server->nick()) { 286 if (mask.nick() == m_session->m_server->nick()) {
279 We are changing our nickname 287 We are changing our nickname
280 m_session->m_server->setNick(message->param(0)); 288 m_session->m_server->setNick(message->param(0));
281 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0))); 289 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0)));
282 output.addParam(0); 290 output.addParam(0);
283 emit outputReady(output); 291 emit outputReady(output);
284 } else { 292 } else {
285 Someone else is 293 Someone else is
286 RCPerson *person = m_session->getPerson(mask.nick()); 294 RCPerson *person = m_session->getPerson(mask.nick());
287 if (person) { 295 if (person) {
288 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 296 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
289 297
290 new code starts here -- this removes the person from all channels 298 new code starts here -- this removes the person from all channels
291 QList<IRCChannel> channels; 299 QList<IRCChannel> channels;
292 m_session->getChannelsByPerson(person, channels); 300 m_session->getChannelsByPerson(person, channels);
293 QListIterator<IRCChannel> it(channels); 301 QListIterator<IRCChannel> it(channels);
294 for (;it.current(); ++it) { 302 for (;it.current(); ++it) {