1
//=============================================================================
3
// File : KviIrcServerParser.cpp
4
// Creation date : Sun Jun 30 2000 03:25:17 by Szymon Stefanek
6
// This file is part of the KVIrc irc client distribution
7
// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net)
9
// This program is FREE software. You can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your opinion) any later version.
14
// This program is distributed in the HOPE that it will be USEFUL,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
// See the GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program. If not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
//=============================================================================
25
#define _KVI_SPARSER_CPP_
27
#include "KviIrcServerParser.h"
28
#include "KviWindow.h"
30
#include "KviLocale.h"
31
#include "KviIrcSocket.h"
32
#include "KviOptions.h"
33
#include "KviKvsEventManager.h"
34
#include "KviKvsEventTriggers.h"
35
#include "KviIrcConnectionStateData.h"
37
KviIrcServerParser * g_pServerParser = 0;
40
KviIrcServerParser::KviIrcServerParser()
43
setObjectName("server_parser");
46
KviIrcServerParser::~KviIrcServerParser()
50
void KviIrcServerParser::parseMessage(const char * message,KviIrcConnection * pConnection)
54
KviIrcMessage msg(message,pConnection);
57
if(KviKvsEventManager::instance()->hasRawHandlers(msg.numeric()))
59
KviKvsVariantList parms;
60
parms.append(pConnection->decodeText(msg.safePrefix()));
61
parms.append(pConnection->decodeText(msg.command()));
63
for(KviCString * str = msg.firstParam();str;str = msg.nextParam())
64
parms.append(pConnection->console()->decodeText(str->ptr()));
66
if(KviKvsEventManager::instance()->triggerRaw(msg.numeric(),pConnection->console(),&parms))
70
messageParseProc proc = m_numericParseProcTable[msg.numeric()];
74
if(!msg.unrecognized())return; // parsed
76
// we don't have a proc for this
78
// special handling of unknown RPL_WHOIS* messages
80
// - we're in the middle of a RPL_WHOIS* sequence (i.e. have received a RPL_WHOIS* message since less than 10 seconds)
81
// - we have not received RPL_ENDOFWHOIS yet (the time of the last RPL_WHOIS* is reset to zero when a RPL_ENDOFWHOIS is received)
82
// - this message is unrecognized and looks like a RPL_WHOIS*
83
// then pass it to the WhoisOther handler.
85
// Thnx Elephantman :)
87
if(msg.paramCount() >= 3) // might look like :prefix RPL_WHOIS* <target> <nick> [?] :<something>
89
kvi_time_t tNow = kvi_unixTime();
91
if((tNow - pConnection->stateData()->lastReceivedWhoisReply()) < 10)
93
// we're in the middle of a RPL_WHOIS* sequence and haven't
94
// received a RPL_ENDOFWHOIS yet.
95
parseNumericWhoisOther(&msg);
96
if(!msg.unrecognized())return;
101
for(int i=0;m_literalParseProcTable[i].msgName;i++)
103
if(kvi_strEqualCS(m_literalParseProcTable[i].msgName,msg.command()))
105
(this->*(m_literalParseProcTable[i].proc))(&msg);
106
if(!msg.unrecognized())return; // parsed
111
if(KviKvsEventManager::instance()->hasAppHandlers(KviEvent_OnUnhandledLiteral))
113
KviKvsVariantList parms;
114
parms.append(pConnection->decodeText(msg.safePrefix()));
115
parms.append(pConnection->decodeText(msg.command()));
117
for(KviCString * str = msg.firstParam();str;str = msg.nextParam())
118
parms.append(pConnection->console()->decodeText(str->ptr()));
120
if(KviKvsEventManager::instance()->trigger(KviEvent_OnUnhandledLiteral,pConnection->console(),&parms))
125
// unhandled || unrecognized
126
if(!msg.haltOutput() && !_OUTPUT_MUTE)
128
QString szWText = pConnection->decodeText(msg.allParams());
129
if(msg.unrecognized())
131
pConnection->console()->output(KVI_OUT_UNRECOGNIZED,
132
__tr2qs("[Server parser]: Encountered problems while parsing the following message:"));
133
pConnection->console()->output(KVI_OUT_UNRECOGNIZED,
134
__tr2qs("[Server parser]: [%s][%s] %Q"),msg.prefix(),msg.command(),&szWText);
135
pConnection->console()->output(KVI_OUT_UNRECOGNIZED,
136
__tr2qs("[Server parser]: %s"),m_szLastParserError.ptr());
138
// ignore spurious CRLF pairs (some servers send them a lot) unless we want PARANOID output
139
if((!msg.isEmpty()) || _OUTPUT_PARANOIC)
140
pConnection->console()->output(KVI_OUT_UNHANDLED,
141
"[%s][%s] %Q",msg.prefix(),msg.command(),&szWText);
147
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
148
#include "KviIrcServerParser.moc"
149
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES