~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/kvirc/sparser/KviIrcServerParser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//
 
3
//   File : KviIrcServerParser.cpp
 
4
//   Creation date : Sun Jun 30 2000 03:25:17 by Szymon Stefanek
 
5
//
 
6
//   This file is part of the KVIrc irc client distribution
 
7
//   Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net)
 
8
//
 
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.
 
13
//
 
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.
 
18
//
 
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.
 
22
//
 
23
//=============================================================================
 
24
 
 
25
#define _KVI_SPARSER_CPP_
 
26
 
 
27
#include "KviIrcServerParser.h"
 
28
#include "KviWindow.h"
 
29
#include "kvi_out.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"
 
36
 
 
37
KviIrcServerParser * g_pServerParser = 0;
 
38
 
 
39
 
 
40
KviIrcServerParser::KviIrcServerParser()
 
41
: QObject(0)
 
42
{
 
43
        setObjectName("server_parser");
 
44
}
 
45
 
 
46
KviIrcServerParser::~KviIrcServerParser()
 
47
{
 
48
}
 
49
 
 
50
void KviIrcServerParser::parseMessage(const char * message,KviIrcConnection * pConnection)
 
51
{
 
52
        if(*message != 0 )
 
53
        {
 
54
                KviIrcMessage msg(message,pConnection);
 
55
                if(msg.isNumeric())
 
56
                {
 
57
                        if(KviKvsEventManager::instance()->hasRawHandlers(msg.numeric()))
 
58
                        {
 
59
                                KviKvsVariantList parms;
 
60
                                parms.append(pConnection->decodeText(msg.safePrefix()));
 
61
                                parms.append(pConnection->decodeText(msg.command()));
 
62
 
 
63
                                for(KviCString * str = msg.firstParam();str;str = msg.nextParam())
 
64
                                        parms.append(pConnection->console()->decodeText(str->ptr()));
 
65
 
 
66
                                if(KviKvsEventManager::instance()->triggerRaw(msg.numeric(),pConnection->console(),&parms))
 
67
                                        msg.setHaltOutput();
 
68
                        }
 
69
 
 
70
                        messageParseProc proc = m_numericParseProcTable[msg.numeric()];
 
71
                        if(proc)
 
72
                        {
 
73
                                (this->*proc)(&msg);
 
74
                                if(!msg.unrecognized())return; // parsed
 
75
                        } else {
 
76
                                // we don't have a proc for this
 
77
 
 
78
                                // special handling of unknown RPL_WHOIS* messages
 
79
                                // if
 
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.
 
84
                                //
 
85
                                // Thnx Elephantman :)
 
86
 
 
87
                                if(msg.paramCount() >= 3) // might look like :prefix RPL_WHOIS* <target> <nick> [?] :<something>
 
88
                                {
 
89
                                        kvi_time_t tNow = kvi_unixTime();
 
90
 
 
91
                                        if((tNow - pConnection->stateData()->lastReceivedWhoisReply()) < 10)
 
92
                                        {
 
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;
 
97
                                        }
 
98
                                }
 
99
                        }
 
100
                } else {
 
101
                        for(int i=0;m_literalParseProcTable[i].msgName;i++)
 
102
                        {
 
103
                                if(kvi_strEqualCS(m_literalParseProcTable[i].msgName,msg.command()))
 
104
                                {
 
105
                                        (this->*(m_literalParseProcTable[i].proc))(&msg);
 
106
                                        if(!msg.unrecognized())return; // parsed
 
107
                                }
 
108
                        }
 
109
 
 
110
 
 
111
                        if(KviKvsEventManager::instance()->hasAppHandlers(KviEvent_OnUnhandledLiteral))
 
112
                        {
 
113
                                KviKvsVariantList parms;
 
114
                                parms.append(pConnection->decodeText(msg.safePrefix()));
 
115
                                parms.append(pConnection->decodeText(msg.command()));
 
116
 
 
117
                                for(KviCString * str = msg.firstParam();str;str = msg.nextParam())
 
118
                                        parms.append(pConnection->console()->decodeText(str->ptr()));
 
119
 
 
120
                                if(KviKvsEventManager::instance()->trigger(KviEvent_OnUnhandledLiteral,pConnection->console(),&parms))
 
121
                                        msg.setHaltOutput();
 
122
                        }
 
123
                }
 
124
 
 
125
                // unhandled || unrecognized
 
126
                if(!msg.haltOutput() && !_OUTPUT_MUTE)
 
127
                {
 
128
                        QString szWText = pConnection->decodeText(msg.allParams());
 
129
                        if(msg.unrecognized())
 
130
                        {
 
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());
 
137
                        } else {
 
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);
 
142
                        }
 
143
                }
 
144
        }
 
145
}
 
146
 
 
147
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
 
148
#include "KviIrcServerParser.moc"
 
149
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES