KVIrc  4.9.2
DeveloperAPIs
KviIrcConnection.h
Go to the documentation of this file.
1 #ifndef _KVI_IRCCONNECTION_H_
2 #define _KVI_IRCCONNECTION_H_
3 //=============================================================================
4 //
5 // File : KviIrcConnection.h
6 // Creation date : Mon 03 May 2004 01:45:42 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2004-2010 Szymon Stefanek <pragma at kvirc dot net>
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
33 #include "kvi_settings.h"
34 #include "KviQString.h"
35 #include "KviPointerList.h"
36 #include "KviTimeUtils.h"
37 
38 #include <QObject>
39 #include <QByteArray>
40 #include <QStringList>
41 #include <QList>
42 #include <QPair>
43 
44 class QTimer;
45 class QTextCodec;
46 class KviConsoleWindow;
47 class KviIrcNetworkData;
48 class KviIrcServer;
49 class KviProxy;
50 class KviIrcSocket;
51 class KviIrcLink;
52 class KviDataBuffer;
53 class KviIrcContext;
54 class KviMainWindow;
55 class KviChannelWindow;
56 class KviQueryWindow;
58 class KviIrcUserDataBase;
67 class KviLagMeter;
69 class KviDnsResolver;
70 class KviUserIdentity;
72 class KviCString;
73 
95 class KVIRC_API KviIrcConnection : public QObject
96 {
97  friend class KviConsoleWindow;
98  friend class KviIrcContext;
99  friend class KviIrcLink;
100  friend class KviIrcServerParser;
101  Q_OBJECT
102 protected:
122  KviIrcConnection(KviIrcContext * pContext, KviIrcConnectionTarget * pTarget, KviUserIdentity * pIdentity);
123 
127  ~KviIrcConnection();
128 
129 public:
134  enum State
135  {
138  Connected
139  };
140 
141 private:
142  KviConsoleWindow * m_pConsole; // shallow, never null
143  KviIrcContext * m_pContext; // shallow, never null
144 
147 
148  KviIrcConnectionTarget * m_pTarget; // owned, never null
149 
150  KviIrcLink * m_pLink; // owned, never null
151 
152  // The initial information about the user we'll send out to the server
153  // Note that the ACTUAL user information are in m_pUserInfo instead
154  KviUserIdentity * m_pUserIdentity; // owned, never null
155 
156  // The ACTUAL user information
157  KviIrcConnectionUserInfo * m_pUserInfo; // owned, never null
158  // The ACTUAL server information
160 
161  KviIrcConnectionStateData * m_pStateData; // owned, never null
162 
163  KviPointerList<KviChannelWindow> * m_pChannelList; // owned, never null, elements shallow
164  KviPointerList<KviQueryWindow> * m_pQueryList; // owned, never null, elements shallow
165 
166  KviIrcUserDataBase * m_pUserDataBase; // owned, never null
167 
168  KviNotifyListManager * m_pNotifyListManager; // owned, see restartNotifyList()
169  QTimer * m_pNotifyListTimer; // delayed startup timer for the notify lists
170 
171  KviLagMeter * m_pLagMeter; // owned, may be null (when not running)
172 
176 
178 
179  KviDnsResolver * m_pLocalhostDns; // FIXME: this should go to an aux structure
180 
181  QTextCodec * m_pSrvCodec; // connection codec: never null
182  QTextCodec * m_pTextCodec; // connection codec: never null
184 public:
191  inline KviConsoleWindow * console() { return m_pConsole; };
192 
199  inline KviIrcContext * context() { return m_pContext; };
200 
209  inline KviIrcConnectionTarget * target() { return m_pTarget; };
210 
217  inline KviIrcLink * link() { return m_pLink; };
218 
223  inline State state() { return m_eState; };
224 
232  inline KviIrcUserDataBase * userDataBase() { return m_pUserDataBase; };
233 
245  inline KviIrcConnectionUserInfo * userInfo() { return m_pUserInfo; };
246 
259  inline KviIrcConnectionServerInfo * serverInfo() { return m_pServerInfo; };
260 
273  inline KviIrcConnectionStateData * stateData() { return m_pStateData; };
274 
286  {
287  return m_pAntiCtcpFloodData;
288  };
289 
301  {
302  return m_pNetsplitDetectorData;
303  };
304 
316  {
317  return m_pAsyncWhoisData;
318  };
319 
330  inline KviIrcConnectionStatistics * statistics() { return m_pStatistics; };
331 
340  {
341  return m_pNotifyListManager;
342  };
343 
351  inline KviLagMeter * lagMeter() { return m_pLagMeter; };
352 
357  inline KviIrcConnectionRequestQueue * requestQueue() { return m_pRequestQueue; };
358 
365  inline KviPointerList<KviChannelWindow> * channelList() { return m_pChannelList; };
366 
371  const QString & currentNetworkName();
372 
377  const QString & currentNickName();
378 
383  const QString & currentUserName();
384 
389  const QString & currentServerName();
390 
391  //
392  // Channel management
393  //
394  // FIXME: Delegate to a KviChannelManager
395  //
396 
405  KviChannelWindow * findChannel(const QString & szName);
406 
422  int getCommonChannels(const QString & szNick, QString & szChansBuffer, bool bAddEscapeSequences = true);
423 
435  KviChannelWindow * createChannel(const QString & szName);
436 
442  void registerChannel(KviChannelWindow * c);
443 
449  void unregisterChannel(KviChannelWindow * c);
450 
460  void keepChannelsOpenAfterDisconnect();
461 
466  void closeAllChannels();
467 
472  void closeAllQueries();
473 
474  //
475  // Query management
476  //
477  // FIXME: Delegate to a KviQueryManager ?
478  //
479 
488  KviQueryWindow * findQuery(const QString & szNick);
489 
496  inline KviPointerList<KviQueryWindow> * queryList() { return m_pQueryList; };
497 
502  {
514  CreateQueryVisibilityFollowSettings
515  };
516 
526  KviQueryWindow * createQuery(const QString & szNick, CreateQueryVisibilityMode eVisibilityMode = CreateQueryVisibilityFollowSettings);
527 
533  void registerQuery(KviQueryWindow * q);
534 
540  void unregisterQuery(KviQueryWindow * q);
541 
550  void keepQueriesOpenAfterDisconnect();
551 
559  void resurrectDeadQueries();
560 
566  void restartLagMeter();
567 
568  //
569  // Networking stack public stuff
570  //
571 
595  bool sendData(const char * pcBuffer, int iBuflen = -1);
596 
622  bool sendFmtData(const char * pcFmt, ...);
623 
629  void clearOutputQueue(bool bPrivateMessagesOnly);
630 
635  unsigned int outputQueueSize();
636 
646  void incomingMessage(const char * pcMessage);
647 
656  void incomingMessageNoFilter(const char * pcMessage);
657 
658  //
659  // Encoding related stuff
660  //
661 
669  inline QTextCodec * textCodec() { return m_pTextCodec; };
670 
678  inline QTextCodec * serverCodec() { return m_pSrvCodec; };
679 
692  void setEncoding(const QString & szEncoding);
693 
702  QString decodeText(const char * szText);
703 
712  QByteArray encodeText(const QString & szText);
713 
714 protected:
715  //
716  // Notify list management
717  //
718 
726  void delayedStartNotifyList();
727 
728  //
729  // Login operations
730  //
731 
736  void resolveLocalHost();
737 
738 #ifdef COMPILE_SSL_SUPPORT
739  void handleFailedInitialStartTls();
740  bool trySTARTTLS(bool bAppendPing);
741  void enableStartTlsSupport(bool bEnable);
742 #endif
743 
753  void useProfileData(KviIdentityProfileSet * pSet, const QString & szNetwork);
754 
760  void useRealName(const QString & szRealName);
761 
766  void loginToIrcServer();
767 
773  void joinChannels(const QList<QPair<QString, QString>> & lChannelsAndPasses);
774 
778  void gatherChannelAndPasswordPairs(QList<QPair<QString, QString>> & lChannelsAndPasses);
779 
783  void gatherQueryNames(QStringList & lQueryNames);
784 
795  QString pickNextLoginNickName(bool bForceDefaultIfPrimaryNicknamesEmpty, const QString & szBaseNickForRandomChoices, QString & szChoiceDescriptionBuffer);
796 
797  //
798  // KviIrcServerParser interface
799  //
800 
805  void endOfMotdReceived();
806 
814  void serverInfoReceived(const QString & szServerName, const QString & szUserModes, const QString & szChanModes);
815 
820  void handleAuthenticate(KviCString & szResponse);
821 
826  void handleInitialCapLs();
827 
832  void handleFailedInitialCapLs();
833 
838  void handleInitialCapAck();
839 
844  void handleInitialCapNak();
845 
850  void endInitialCapNegotiation();
851 
857  void changeAwayState(bool bAway);
858 
868  void userInfoReceived(const QString & szUserName, const QString & szHostName);
869 
875  void nickChange(const QString & szNewNick);
876 
883  bool changeUserMode(char cMode, bool bSet);
884 
890  void loginComplete(const QString & szNickName);
891 
892  //
893  // KviIrcContext interface
894  //
895 
903  void start();
904 
909  void abort();
910 
916  void heartbeat(kvi_time_t tNow);
917 
918  //
919  // KviIrcLink interface (down)
920  //
921 
927  void linkAttemptFailed(int iError);
928 
933  void linkEstablished();
934 
939  void linkTerminated();
940 
941 private:
946  void setupTextCodec();
947 
952  void setupSrvCodec();
953 public slots:
958  void unhighlightAllChannels();
959 
964  void unhighlightAllQueries();
965 
970  void restartNotifyList();
971 private slots:
976  void hostNameLookupTerminated(KviDnsResolver * pDns);
977 signals:
982  void awayStateChanged();
983 
988  void userModeChanged();
989 
994  void nickNameChanged();
995 
1001  void channelRegistered(KviChannelWindow * pChan);
1002 
1008  void channelUnregistered(KviChannelWindow * pChan);
1009 
1014  void chanListChanged();
1015 };
1016 
1017 // TODO: KviIdentity
1018 
1019 #endif //_KVI_IRCCONNECTION_H_
QTextCodec * serverCodec()
Returns a pointer to the current global codec for inbound data.
Definition: KviIrcConnection.h:678
KviIrcUserDataBase * userDataBase()
Returns a pointer to the big connection user database.
Definition: KviIrcConnection.h:232
Definition: KviIrcConnection.h:510
KviIrcConnectionServerInfo * serverInfo()
Returns a pointer to the KviIrcConnectionServerInfo object.
Definition: KviIrcConnection.h:259
Definition: KviCString.h:105
KviIrcUserDataBase * m_pUserDataBase
Definition: KviIrcConnection.h:166
Class to enqueue commands to IRC server.
Definition: KviIrcConnectionRequestQueue.h:47
KviIrcConnectionStatistics * m_pStatistics
Definition: KviIrcConnection.h:177
Definition: KviMainWindow.h:60
Definition: KviConsoleWindow.h:75
The class which manages the irc servers.
Definition: KviIrcServer.h:51
Definition: KviIrcConnectionAsyncWhoisData.h:63
#define KVIRC_API
Definition: kvi_settings.h:128
char s char s char s s s s s char char c s *s c s s s d c s *s d c d d d d c
Definition: KviIrcNumericCodes.h:391
KviDnsResolver * m_pLocalhostDns
Definition: KviIrcConnection.h:179
KviConsoleWindow * console()
Returns a pointer to the owning console.
Definition: KviIrcConnection.h:191
An abstraction of a connection to an IRC server.
Definition: KviIrcConnection.h:95
KviPointerList< KviChannelWindow > * channelList()
Returns the list of the channels bound to the current connection.
Definition: KviIrcConnection.h:365
KviPointerList< KviChannelWindow > * m_pChannelList
Definition: KviIrcConnection.h:163
KviIrcContext * context()
Returns a pointer to the owning KviIrcContext.
Definition: KviIrcConnection.h:199
Definition: KviIrcConnection.h:137
KviConsoleWindow * m_pConsole
Definition: KviIrcConnection.h:142
State
The possible "high level" states of this connection.
Definition: KviIrcConnection.h:134
KviUserIdentity * m_pUserIdentity
Definition: KviIrcConnection.h:154
Definition: KviNotifyList.h:41
Definition: KviDataBuffer.h:30
Definition: KviProxy.h:37
KviIrcConnectionServerInfo * m_pServerInfo
Definition: KviIrcConnection.h:159
QTimer * m_pNotifyListTimer
Definition: KviIrcConnection.h:169
#define kvi_time_t
Definition: KviTimeUtils.h:43
State state()
Returns the current state of the connection.
Definition: KviIrcConnection.h:223
KviIrcConnectionUserInfo * userInfo()
Returns a pointer to the KviIrcConnectionUserInfo object.
Definition: KviIrcConnection.h:245
The class which manages a query.
Definition: KviQueryWindow.h:49
#define q
Definition: detector.cpp:81
KviIrcConnectionAntiCtcpFloodData * antiCtcpFloodData()
Returns a pointer to the KviIrcConnectionAntiCtcpFloodData object.
Definition: KviIrcConnection.h:285
KviIrcConnectionStateData * stateData()
Returns a pointer to the KviIrcConnectionStateData object.
Definition: KviIrcConnection.h:273
bool m_bIdentdAttached
Definition: KviIrcConnection.h:146
Definition: KviIrcConnection.h:506
Definition: KviIrcConnectionStatistics.h:31
Definition: KviIrcConnectionUserInfo.h:31
KviIrcConnectionRequestQueue * requestQueue()
Returns a pointer to the current KviIrcConnectionRequestQueue.
Definition: KviIrcConnection.h:357
KviPointerList< KviQueryWindow > * queryList()
Returns the list of the currently open queries.
Definition: KviIrcConnection.h:496
User identity handling class.
Definition: KviUserIdentity.h:42
KviLagMeter * m_pLagMeter
Definition: KviIrcConnection.h:171
KviLagMeter * lagMeter()
Returns a pointer to the current KviLagMeter.
Definition: KviIrcConnection.h:351
Definition: KviIrcConnectionServerInfo.h:296
KviNotifyListManager * m_pNotifyListManager
Definition: KviIrcConnection.h:168
The KviDnsResolver class.
Definition: KviDnsResolver.h:93
QTextCodec * m_pSrvCodec
Definition: KviIrcConnection.h:181
KviIrcConnectionTarget * target()
Returns the target of this connection.
Definition: KviIrcConnection.h:209
Time management.
KviPointerList< KviQueryWindow > * m_pQueryList
Definition: KviIrcConnection.h:164
C++ Template based double linked pointer list class.
KviIrcConnectionStateData * m_pStateData
Definition: KviIrcConnection.h:161
Class which manages the list of identity profiles.
Definition: KviIdentityProfileSet.h:44
QTextCodec * textCodec()
Returns a pointer to the current global codec for outbound text.
Definition: KviIrcConnection.h:669
QTextCodec * m_pTextCodec
Definition: KviIrcConnection.h:182
Definition: KviIrcConnectionStateData.h:40
Definition: KviIrcConnection.h:136
KviIrcLink * link()
Returns the underlying KviIrcLink object.
Definition: KviIrcConnection.h:217
KviIrcConnectionNetsplitDetectorData * m_pNetsplitDetectorData
Definition: KviIrcConnection.h:174
The class which manages the user database.
Definition: KviIrcUserDataBase.h:45
KviIrcConnectionAsyncWhoisData * asyncWhoisData()
Returns a pointer to the KviIrcConnectionAsyncWhoisData object.
Definition: KviIrcConnection.h:315
CreateQueryVisibilityMode
Definition: KviIrcConnection.h:501
Definition: KviIrcServerParser.h:115
Definition: KviLagMeter.h:45
KviIrcConnectionTarget * m_pTarget
Definition: KviIrcConnection.h:148
KviIrcContext * m_pContext
Definition: KviIrcConnection.h:143
State m_eState
Definition: KviIrcConnection.h:145
KviIrcConnectionUserInfo * m_pUserInfo
Definition: KviIrcConnection.h:157
KviIrcConnectionRequestQueue * m_pRequestQueue
Definition: KviIrcConnection.h:183
This file contains compile time settings.
KviIrcConnectionStatistics * statistics()
Returns a pointer to the KviIrcConnectionStatistics object.
Definition: KviIrcConnection.h:330
KviIrcConnectionAsyncWhoisData * m_pAsyncWhoisData
Definition: KviIrcConnection.h:175
KviNotifyListManager * notifyListManager()
Returns a pointer to the current KviNotifyListManager.
Definition: KviIrcConnection.h:339
Definition: KviIrcConnectionTarget.h:35
Definition: KviIrcContext.h:58
This class is the lowest level of the KVIrc networking stack.
Definition: KviIrcSocket.h:71
Definition: KviIrcConnectionAntiCtcpFloodData.h:30
Helper functions for the QString class.
KviIrcConnectionAntiCtcpFloodData * m_pAntiCtcpFloodData
Definition: KviIrcConnection.h:173
Definition: KviIrcConnectionNetsplitDetectorData.h:31
KviIrcConnectionNetsplitDetectorData * netsplitDetectorData()
Returns a pointer to the KviIrcConnectionNetsplitDetectorData object.
Definition: KviIrcConnection.h:300
KviIrcLink * m_pLink
Definition: KviIrcConnection.h:150
The class which manages a channel.
Definition: KviChannelWindow.h:113