1 #ifndef _KVI_IRCCONNECTIONSTATEDATA_H_
2 #define _KVI_IRCCONNECTIONSTATEDATA_H_
3 //=============================================================================
4 //
5 //   File : KviIrcConnectionStateData.h
6 //   Creation date : Sat 26 Jun 2004 09:31:52 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 
27 #include "kvi_settings.h"
28 #include "KviQString.h"
29 #include "KviTimeUtils.h"
30 
31 #include <QStringList>
32 
33 //
34 // This class is used as container for miscellaneous connection state variables
35 // that do not have a class for their own.
36 // If you need to add some "minor" variable to the connection state then
37 // this is the right place for it.
38 //
39 
40 class KVIRC_API KviIrcConnectionStateData
41 {
42 	friend class KviIrcConnection;
43 	friend class KviIrcServerParser;
44 	friend class KviUserParser;
45 
46 public:
47 	KviIrcConnectionStateData();
48 	~KviIrcConnectionStateData();
49 
50 protected:
51 	// The members of this enum must be in the correct
52 	// order since the nickname selection algorithm
53 	// uses their numeric values for comparisons.
54 	enum LoginNickNameState
55 	{
56 		UsedConnectionSpecificNickName,
57 		UsedProfileSpecificNickName,
58 		UsedAlternativeProfileSpecificNickName,
59 		UsedServerSpecificNickName,
60 		UsedAlternativeServerSpecificNickName,
61 		UsedNetworkSpecificNickName,
62 		UsedAlternativeNetworkSpecificNickName,
63 		UsedGlobalNickName1,
64 		UsedGlobalNickName2,
65 		UsedGlobalNickName3,
66 		UsedGlobalNickName4,
67 		UsedRandomNickName1,
68 		UsedRandomNickName2,
69 		UsedRandomNickName3,
70 		UsedRandomNickName4,
71 		UsedManualNickname // Given up assigning it automatically
72 	};
73 
74 	///
75 	/// the current login nickname state
76 	///
77 	LoginNickNameState m_eLoginNickNameState = UsedConnectionSpecificNickName;
78 
79 	bool m_bInsideInitialCapLs = false; // true if there's a CAP LS request pending
80 	///
81 	/// This is set to true if a forced STARTTLS request has been sent
82 	/// to the server followed by a PING. We use this flag to gracefully
83 	/// handle a ERR_NOTREGISTERED related to the PING if STARTTLS is not supported.
84 	///
85 	/// Note that in this case the STARTTLS support wasn't detected by a previous CAP LS
86 	/// (which wasn't sent at all).
87 	///
88 	bool m_bInsideInitialStartTls = false;
89 	bool m_bIgnoreOneYouHaveNotRegisteredError = false; // true if we have sent a CAP LS request followed by a PING which will generate an error (and we need to ignore it)
90 	bool m_bInsideInitialCapReq = false;        // true if there's a CAP REQ request pending
91 	bool m_bInsideAuthenticate = false;         // true if there's a AUTHENTICATE request pending
92 	bool m_bSentStartTls = false;               // the state of STARTTLS protocol
93 	bool m_bSentQuit = false;                   // have we sent the quit message for this connection ?
94 	QString m_szCommandToExecAfterConnect;      // yes.. this is a special command to execute after connection
95 	bool m_bSimulateUnexpectedDisconnect = false; // this is set to true if we have to simulate an unexpected disconnect even if we have sent a normal quit message
96 	kvi_time_t m_tLastReceivedChannelWhoReply;  // the time that we have received our last channel who reply
97 	kvi_time_t m_tLastSentChannelWhoRequest;    // the time that we have sent our last channel who request
98 	kvi_time_t m_tLastReceivedWhoisReply = 0;   // the time that we have received the last whois reply, reset to 0 when we receive an /END OF WHOIS
99 	QStringList m_lEnabledCaps;                 // the CAPs currently enabled
100 	bool m_bIdentifyMsgCapabilityEnabled = false; // do we have the msg-identity CAP enabled ?
101 	QString m_szSentSaslMethod;
102 public:
103 	///
104 	/// Sets the current login nickname state
105 	///
setLoginNickNameState(const LoginNickNameState & eLoginNickNameState)106 	void setLoginNickNameState(const LoginNickNameState & eLoginNickNameState)
107 	{
108 		m_eLoginNickNameState = eLoginNickNameState;
109 	}
110 
111 	///
112 	/// Returns the current login nickname state
113 	///
loginNickNameState()114 	const LoginNickNameState & loginNickNameState() const
115 	{
116 		return m_eLoginNickNameState;
117 	}
118 
enabledCaps()119 	const QStringList & enabledCaps() const { return m_lEnabledCaps; }
120 	void changeEnabledCapList(const QString & szCapList);
121 
identifyMsgCapabilityEnabled()122 	bool identifyMsgCapabilityEnabled() const
123 	{
124 		return m_bIdentifyMsgCapabilityEnabled;
125 	}
126 
sentSaslMethod()127 	const QString & sentSaslMethod() const { return m_szSentSaslMethod; }
setSentSaslMethod(const QString & szMethod)128 	void setSentSaslMethod(const QString& szMethod) { m_szSentSaslMethod = szMethod; }
129 
sentStartTls()130 	bool sentStartTls() const { return m_bSentStartTls; }
setSentStartTls()131 	void setSentStartTls() { m_bSentStartTls = true; }
132 
isInsideAuthenticate()133 	bool isInsideAuthenticate() const { return m_bInsideAuthenticate; }
setInsideAuthenticate(bool bInside)134 	void setInsideAuthenticate(bool bInside) { m_bInsideAuthenticate = bInside; }
135 
isInsideInitialCapLs()136 	bool isInsideInitialCapLs() const { return m_bInsideInitialCapLs; }
setInsideInitialCapLs(bool bInside)137 	void setInsideInitialCapLs(bool bInside) { m_bInsideInitialCapLs = bInside; }
138 
isInsideInitialStartTls()139 	bool isInsideInitialStartTls() const { return m_bInsideInitialStartTls; }
setInsideInitialStartTls(bool bInside)140 	void setInsideInitialStartTls(bool bInside) { m_bInsideInitialStartTls = bInside; }
141 
setIgnoreOneYouHaveNotRegisteredError(bool bIgnore)142 	void setIgnoreOneYouHaveNotRegisteredError(bool bIgnore)
143 	{
144 		m_bIgnoreOneYouHaveNotRegisteredError = bIgnore;
145 	}
ignoreOneYouHaveNotRegisteredError()146 	bool ignoreOneYouHaveNotRegisteredError() const
147 	{
148 		return m_bIgnoreOneYouHaveNotRegisteredError;
149 	}
150 
isInsideInitialCapReq()151 	bool isInsideInitialCapReq() const { return m_bInsideInitialCapReq; }
setInsideInitialCapReq(bool bInside)152 	void setInsideInitialCapReq(bool bInside) { m_bInsideInitialCapReq = bInside; }
153 
sentQuit()154 	bool sentQuit() const { return m_bSentQuit; }
setSentQuit()155 	void setSentQuit() { m_bSentQuit = true; }
156 
lastReceivedChannelWhoReply()157 	kvi_time_t lastReceivedChannelWhoReply() const { return m_tLastReceivedChannelWhoReply; }
setLastReceivedChannelWhoReply(kvi_time_t tTime)158 	void setLastReceivedChannelWhoReply(kvi_time_t tTime) { m_tLastReceivedChannelWhoReply = tTime; }
159 
lastSentChannelWhoRequest()160 	kvi_time_t lastSentChannelWhoRequest() const { return m_tLastSentChannelWhoRequest; }
setLastSentChannelWhoRequest(kvi_time_t tTime)161 	void setLastSentChannelWhoRequest(kvi_time_t tTime) { m_tLastSentChannelWhoRequest = tTime; }
162 
lastReceivedWhoisReply()163 	kvi_time_t lastReceivedWhoisReply() const { return m_tLastReceivedWhoisReply; }
setLastReceivedWhoisReply(kvi_time_t tTime)164 	void setLastReceivedWhoisReply(kvi_time_t tTime) { m_tLastReceivedWhoisReply = tTime; }
165 
simulateUnexpectedDisconnect()166 	bool simulateUnexpectedDisconnect() const { return m_bSimulateUnexpectedDisconnect; }
setSimulateUnexpectedDisconnect(bool bSimulate)167 	void setSimulateUnexpectedDisconnect(bool bSimulate) { m_bSimulateUnexpectedDisconnect = bSimulate; }
168 
commandToExecAfterConnect()169 	const QString & commandToExecAfterConnect() const { return m_szCommandToExecAfterConnect; }
setCommandToExecAfterConnect(const QString & szCmd)170 	void setCommandToExecAfterConnect(const QString & szCmd) { m_szCommandToExecAfterConnect = szCmd; }
171 };
172 
173 #endif //!_KVI_IRCCONNECTIONSTATEDATA_H_
174