summaryrefslogtreecommitdiff
path: root/noncore/net/opieirc/ircmessageparser.cpp
authorwazlaf <wazlaf>2002-09-29 19:54:12 (UTC)
committer wazlaf <wazlaf>2002-09-29 19:54:12 (UTC)
commit1dd254c95a582c2c86c816516a1b4433d8142d8a (patch) (unidiff)
treea3225293a4b399494a04e5bb07154bd673ba0acf /noncore/net/opieirc/ircmessageparser.cpp
parentf91ea4e068f38e9df17b06c87cd8635628837a4f (diff)
downloadopie-1dd254c95a582c2c86c816516a1b4433d8142d8a.zip
opie-1dd254c95a582c2c86c816516a1b4433d8142d8a.tar.gz
opie-1dd254c95a582c2c86c816516a1b4433d8142d8a.tar.bz2
some more message types supported to make this work more smoothly with freenode.net
Diffstat (limited to 'noncore/net/opieirc/ircmessageparser.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opieirc/ircmessageparser.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp
index 5c70753..d1b70a5 100644
--- a/noncore/net/opieirc/ircmessageparser.cpp
+++ b/noncore/net/opieirc/ircmessageparser.cpp
@@ -1,62 +1,65 @@
1#include <qtextstream.h> 1#include <qtextstream.h>
2#include "ircmessageparser.h" 2#include "ircmessageparser.h"
3#include "ircversion.h" 3#include "ircversion.h"
4 4
5/* Lookup table for literal commands */ 5/* Lookup table for literal commands */
6IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { 6IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = {
7 { "PING", FUNC(parseLiteralPing) }, 7 { "PING", FUNC(parseLiteralPing) },
8 { "NOTICE", FUNC(parseLiteralNotice) }, 8 { "NOTICE", FUNC(parseLiteralNotice) },
9 { "JOIN", FUNC(parseLiteralJoin) }, 9 { "JOIN", FUNC(parseLiteralJoin) },
10 { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, 10 { "PRIVMSG", FUNC(parseLiteralPrivMsg) },
11 { "NICK", FUNC(parseLiteralNick) }, 11 { "NICK", FUNC(parseLiteralNick) },
12 { "PART", FUNC(parseLiteralPart) }, 12 { "PART", FUNC(parseLiteralPart) },
13 { "QUIT", FUNC(parseLiteralQuit) }, 13 { "QUIT", FUNC(parseLiteralQuit) },
14 { "ERROR", FUNC(parseLiteralError) }, 14 { "ERROR", FUNC(parseLiteralError) },
15 { "ERROR:", FUNC(parseLiteralError) }, 15 { "ERROR:", FUNC(parseLiteralError) },
16 { "MODE", FUNC(parseLiteralMode) }, 16 { "MODE", FUNC(parseLiteralMode) },
17 { "KICK", FUNC(parseLiteralKick) }, 17 { "KICK", FUNC(parseLiteralKick) },
18 { "TOPIC", FUNC(parseLiteralTopic) },
18 { 0 , 0 } 19 { 0 , 0 }
19}; 20};
20 21
21/* Lookup table for literal commands */ 22/* Lookup table for literal commands */
22IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { 23IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = {
23 { "PING", FUNC(parseCTCPPing) }, 24 { "PING", FUNC(parseCTCPPing) },
24 { "VERSION", FUNC(parseCTCPVersion) }, 25 { "VERSION", FUNC(parseCTCPVersion) },
25 { "ACTION", FUNC(parseCTCPAction) }, 26 { "ACTION", FUNC(parseCTCPAction) },
26 { 0 , 0 } 27 { 0 , 0 }
27}; 28};
28 29
29/* Lookup table for numerical commands */ 30/* Lookup table for numerical commands */
30IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { 31IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = {
31 { 1, FUNC(parseNumerical001) }, // RPL_WELCOME 32 { 1, FUNC(parseNumerical001) }, // RPL_WELCOME
32 { 2, FUNC(parseNumerical002) }, // RPL_YOURHOST 33 { 2, FUNC(parseNumerical002) }, // RPL_YOURHOST
33 { 3, FUNC(parseNumerical003) }, // RPL_CREATED 34 { 3, FUNC(parseNumerical003) }, // RPL_CREATED
34 { 4, FUNC(parseNumerical004) }, // RPL_MYINFO 35 { 4, FUNC(parseNumerical004) }, // RPL_MYINFO
35 { 5, FUNC(parseNumerical005) }, // RPL_BOUNCE, RPL_PROTOCTL 36 { 5, FUNC(parseNumerical005) }, // RPL_BOUNCE, RPL_PROTOCTL
36 { 251, FUNC(parseNumericalStats) }, // RPL_LUSERCLIENT 37 { 251, FUNC(parseNumericalStats) }, // RPL_LUSERCLIENT
37 { 254, FUNC(nullFunc)}, // RPL_LUSERCHANNELS 38 { 254, FUNC(nullFunc)}, // RPL_LUSERCHANNELS
38 { 255, FUNC(parseNumericalStats) }, // RPL_LUSERNAME 39 { 255, FUNC(parseNumericalStats) }, // RPL_LUSERNAME
40 { 332, FUNC(parseNumericalTopic) }, // RPL_TOPIC
41 { 333, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME
39 { 353, FUNC(parseNumericalNames) }, // RPL_NAMREPLY 42 { 353, FUNC(parseNumericalNames) }, // RPL_NAMREPLY
40 { 366, FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES 43 { 366, FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES
41 { 375, FUNC(parseNumericalStats) }, // RPL_MOTDSTART 44 { 375, FUNC(parseNumericalStats) }, // RPL_MOTDSTART
42 { 372, FUNC(parseNumericalStats) }, // RPL_MOTD 45 { 372, FUNC(parseNumericalStats) }, // RPL_MOTD
43 { 376, FUNC(parseNumericalStats) }, // RPL_ENDOFMOTD 46 { 376, FUNC(parseNumericalStats) }, // RPL_ENDOFMOTD
44 { 377, FUNC(parseNumericalStats) }, // RPL_MOTD2 47 { 377, FUNC(parseNumericalStats) }, // RPL_MOTD2
45 { 378, FUNC(parseNumericalStats) }, // RPL_MOTD3 48 { 378, FUNC(parseNumericalStats) }, // RPL_MOTD3
46 { 401, FUNC(parseNumericalNoSuchNick) }, // ERR_NOSUCHNICK 49 { 401, FUNC(parseNumericalNoSuchNick) }, // ERR_NOSUCHNICK
47 { 406, FUNC(parseNumericalNoSuchNick) }, // ERR_WASNOSUCHNICK 50 { 406, FUNC(parseNumericalNoSuchNick) }, // ERR_WASNOSUCHNICK
48 { 412, FUNC(parseNumericalStats) }, // ERR_NOTEXTTOSEND 51 { 412, FUNC(parseNumericalStats) }, // ERR_NOTEXTTOSEND
49 { 433, FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE 52 { 433, FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE
50 { 0, 0 } 53 { 0, 0 }
51}; 54};
52 55
53IRCMessageParser::IRCMessageParser(IRCSession *session) { 56IRCMessageParser::IRCMessageParser(IRCSession *session) {
54 m_session = session; 57 m_session = session;
55} 58}
56 59
57void IRCMessageParser::parse(IRCMessage *message) { 60void IRCMessageParser::parse(IRCMessage *message) {
58 /* Find out what kind of message we have here and call the appropriate handler using 61 /* Find out what kind of message we have here and call the appropriate handler using
59 the parser tables. If no handler can be found, print out an error message */ 62 the parser tables. If no handler can be found, print out an error message */
60 if (message->isNumerical()) { 63 if (message->isNumerical()) {
61 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { 64 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) {
62 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { 65 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) {
@@ -170,49 +173,49 @@ void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) {
170 IRCPerson *person = m_session->getPerson(mask.nick()); 173 IRCPerson *person = m_session->getPerson(mask.nick());
171 if (!person) { 174 if (!person) {
172 /* Person not yet known, create and add to the current session */ 175 /* Person not yet known, create and add to the current session */
173 person = new IRCPerson(message->prefix()); 176 person = new IRCPerson(message->prefix());
174 m_session->addPerson(person); 177 m_session->addPerson(person);
175 } 178 }
176 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1)); 179 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1));
177 output.addParam(person); 180 output.addParam(person);
178 emit outputReady(output); 181 emit outputReady(output);
179 } else if (message->param(0).at(0) == '#') { 182 } else if (message->param(0).at(0) == '#') {
180 /* IRC Channel message detected, verify sender, channel and display it */ 183 /* IRC Channel message detected, verify sender, channel and display it */
181 IRCChannel *channel = m_session->getChannel(message->param(0)); 184 IRCChannel *channel = m_session->getChannel(message->param(0));
182 if (channel) { 185 if (channel) {
183 IRCPerson mask(message->prefix()); 186 IRCPerson mask(message->prefix());
184 IRCChannelPerson *person = channel->getPerson(mask.nick()); 187 IRCChannelPerson *person = channel->getPerson(mask.nick());
185 if (person) { 188 if (person) {
186 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); 189 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1));
187 output.addParam(channel); 190 output.addParam(channel);
188 output.addParam(person); 191 output.addParam(person);
189 emit outputReady(output); 192 emit outputReady(output);
190 } else { 193 } else {
191 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); 194 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender")));
192 } 195 }
193 } else { 196 } else {
194 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel"))); 197 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel ") + message->param(0)));
195 } 198 }
196 } else { 199 } else {
197 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type"))); 200 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type")));
198 } 201 }
199} 202}
200 203
201void IRCMessageParser::parseLiteralNick(IRCMessage *message) { 204void IRCMessageParser::parseLiteralNick(IRCMessage *message) {
202 IRCPerson mask(message->prefix()); 205 IRCPerson mask(message->prefix());
203 206
204 if (mask.nick() == m_session->m_server->nick()) { 207 if (mask.nick() == m_session->m_server->nick()) {
205 /* We are changing our nickname */ 208 /* We are changing our nickname */
206 m_session->m_server->setNick(message->param(0)); 209 m_session->m_server->setNick(message->param(0));
207 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as ")+message->param(0)); 210 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as ")+message->param(0));
208 output.addParam(0); 211 output.addParam(0);
209 emit outputReady(output); 212 emit outputReady(output);
210 } else { 213 } else {
211 /* Someone else is */ 214 /* Someone else is */
212 IRCPerson *person = m_session->getPerson(mask.nick()); 215 IRCPerson *person = m_session->getPerson(mask.nick());
213 if (person) { 216 if (person) {
214 IRCOutput output(OUTPUT_NICKCHANGE, mask.nick() + tr(" is now known as ") + message->param(0)); 217 IRCOutput output(OUTPUT_NICKCHANGE, mask.nick() + tr(" is now known as ") + message->param(0));
215 output.addParam(person); 218 output.addParam(person);
216 emit outputReady(output); 219 emit outputReady(output);
217 } else { 220 } else {
218 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); 221 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person")));
@@ -221,48 +224,60 @@ void IRCMessageParser::parseLiteralNick(IRCMessage *message) {
221} 224}
222 225
223void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { 226void IRCMessageParser::parseLiteralQuit(IRCMessage *message) {
224 IRCPerson mask(message->prefix()); 227 IRCPerson mask(message->prefix());
225 IRCPerson *person = m_session->getPerson(mask.nick()); 228 IRCPerson *person = m_session->getPerson(mask.nick());
226 if (person) { 229 if (person) {
227 QList<IRCChannel> channels; 230 QList<IRCChannel> channels;
228 m_session->getChannelsByPerson(person, channels); 231 m_session->getChannelsByPerson(person, channels);
229 QListIterator<IRCChannel> it(channels); 232 QListIterator<IRCChannel> it(channels);
230 for (;it.current(); ++it) { 233 for (;it.current(); ++it) {
231 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 234 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
232 it.current()->removePerson(chanperson); 235 it.current()->removePerson(chanperson);
233 delete chanperson; 236 delete chanperson;
234 } 237 }
235 m_session->removePerson(person); 238 m_session->removePerson(person);
236 IRCOutput output(OUTPUT_QUIT, mask.nick() + tr(" has quit ") + "(" + message->param(0) + ")"); 239 IRCOutput output(OUTPUT_QUIT, mask.nick() + tr(" has quit ") + "(" + message->param(0) + ")");
237 output.addParam(person); 240 output.addParam(person);
238 emit outputReady(output); 241 emit outputReady(output);
239 delete person; 242 delete person;
240 } else { 243 } else {
241 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); 244 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?")));
242 } 245 }
243} 246}
244 247
248void IRCMessageParser::parseLiteralTopic(IRCMessage *message) {
249 IRCPerson mask(message->prefix());
250 IRCChannel *channel = m_session->getChannel(message->param(0));
251 if (channel) {
252 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\"");
253 output.addParam(channel);
254 emit outputReady(output);
255 } else {
256 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?")));
257 }
258}
259
245void IRCMessageParser::parseLiteralError(IRCMessage *message) { 260void IRCMessageParser::parseLiteralError(IRCMessage *message) {
246 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); 261 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters()));
247} 262}
248 263
249void IRCMessageParser::parseCTCPPing(IRCMessage *message) { 264void IRCMessageParser::parseCTCPPing(IRCMessage *message) {
250 IRCPerson mask(message->prefix()); 265 IRCPerson mask(message->prefix());
251 m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters()); 266 m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters());
252 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); 267 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick()));
253} 268}
254 269
255void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { 270void IRCMessageParser::parseCTCPVersion(IRCMessage *message) {
256 IRCPerson mask(message->prefix()); 271 IRCPerson mask(message->prefix());
257 m_session->m_connection->sendCTCP(mask.nick(), APP_VERSION " " APP_COPYSTR); 272 m_session->m_connection->sendCTCP(mask.nick(), APP_VERSION " " APP_COPYSTR);
258 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick())); 273 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick()));
259} 274}
260 275
261void IRCMessageParser::parseCTCPAction(IRCMessage *message) { 276void IRCMessageParser::parseCTCPAction(IRCMessage *message) {
262 IRCPerson mask(message->prefix()); 277 IRCPerson mask(message->prefix());
263 QString dest = message->ctcpDestination(); 278 QString dest = message->ctcpDestination();
264 if (dest.startsWith("#")) { 279 if (dest.startsWith("#")) {
265 IRCChannel *channel = m_session->getChannel(dest); 280 IRCChannel *channel = m_session->getChannel(dest);
266 if (channel) { 281 if (channel) {
267 IRCChannelPerson *person = channel->getPerson(mask.nick()); 282 IRCChannelPerson *person = channel->getPerson(mask.nick());
268 if (person) { 283 if (person) {
@@ -463,24 +478,40 @@ void IRCMessageParser::parseNumericalNames(IRCMessage *message) {
463 478
464void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { 479void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) {
465 /* Done syncing to channel */ 480 /* Done syncing to channel */
466 IRCChannel *channel = m_session->getChannel(message->param(1)); 481 IRCChannel *channel = m_session->getChannel(message->param(1));
467 if (channel) { 482 if (channel) {
468 channel->setHasPeople(TRUE); 483 channel->setHasPeople(TRUE);
469 /* Yes, we want the names before anything happens inside the GUI */ 484 /* Yes, we want the names before anything happens inside the GUI */
470 IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); 485 IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname());
471 output.addParam(channel); 486 output.addParam(channel);
472 emit outputReady(output); 487 emit outputReady(output);
473 } else { 488 } else {
474 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); 489 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel")));
475 } 490 }
476} 491}
477 492
478 493
479void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { 494void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) {
480 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); 495 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname")));
481 m_session->endSession(); 496 m_session->endSession();
482} 497}
483 498
484void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) { 499void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) {
485 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname"))); 500 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname")));
486} 501}
502
503void IRCMessageParser::parseNumericalTopic(IRCMessage *message) {
504 IRCChannel *channel = m_session->getChannel(message->param(1));
505 if (channel) {
506 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\""));
507 output.addParam(channel);
508 emit outputReady(output);
509 } else {
510 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\""));
511 output.addParam(0);
512 emit outputReady(output);
513 }
514}
515
516void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *message) {
517}