summaryrefslogtreecommitdiffstats
path: root/src/kvirc/kernel/kvi_irclink.h
blob: 1426d2e47f8f281c087121bc572de9614f4b454d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef _KVI_IRCLINK_H_
#define _KVI_IRCLINK_H_
//=============================================================================
//
//   File : kvi_irclink.h
//   Created on Mon 03 May 2004 01:45:42 by Szymon Stefanek
//
//   This file is part of the KVIrc IRC client distribution
//   Copyright (C) 2004 Szymon Stefanek <pragma at kvirc dot net>
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

#include "kvi_settings.h"
#include "kvi_qstring.h"
#include <tqobject.h>

class KviConsole;
class KviIrcServer;
class KviProxy;
class KviIrcSocket;
class KviDns;
class KviIrcConnection;
class KviIrcConnectionTarget;
class KviIrcConnectionTargetResolver;
class KviDataBuffer;
class KviMexLinkFilter;


class KVIRC_API KviIrcLink : public TQObject
{
	friend class KviIrcConnection; // upper protocol in the stack
	friend class KviIrcSocket; // lower protocol in the stack
	Q_OBJECT
  TQ_OBJECT
public:
	enum State { Idle, Connecting, Connected };
protected:
	// only KviConsole can create this
	// pConsole must NOT be null
	// pServer is a shallow pointer: Connection makes a copy of it internally, must NOT be null
	// pProxy may be null if a proxy is not desicred. Connection makes a copy of it internally
	KviIrcLink(KviIrcConnection * pConnection);
	~KviIrcLink();
private:
	KviIrcConnection               * m_pConnection;       // shallow, never null
	KviIrcConnectionTarget         * m_pTarget;           // shallow, never null
	KviConsole                     * m_pConsole;          // shallow, never null
	KviIrcSocket                   * m_pSocket;           // owned, may be null!
	KviMexLinkFilter               * m_pLinkFilter;       // owned, may be null!

	State                            m_eState;

	char                           * m_pReadBuffer;
	unsigned int                     m_uReadBufferLen;
	unsigned int                     m_uReadPackets;

	KviIrcConnectionTargetResolver * m_pResolver;         // owned
public:
	// da socket(): may be null!
	KviIrcSocket * socket(){ return m_pSocket; };
	// da connection: never null
	KviIrcConnection * connection(){ return m_pConnection; };
	// da console: never null
	KviConsole * console(){ return m_pConsole; };
	State state(){ return m_eState; };
protected:
	//
	// interface for KviIrcConnection (up)
	//

	// This is used by KviIrcConnection::send*()
	// This should be used to intercept the outgoing packets
	// when implementing a new protocol
	virtual bool sendPacket(KviDataBuffer * pData);
	// this aborts any connection or attempt
	void abort();
protected:
	//
	// local overridables (called internally)
	//
	
	// This is the function used to start a connection attempt.
	// It starts the server or proxy DNS lookup
	// The function MUST be asynchronous: it must return succesfully
	// and report any error by using m_pConnection->linkAttemptFailed()
	void start();
protected:
	//
	// interface for KviIrcSocket (down)
	//
	
	// This is called by KviIrcSocket to process a packet
	// of raw data from the server. The buffer is iLength+1
	// bytes long and contains a null terminator
	void processData(char * buffer,int iLength);
	// this is called at each state change
	void socketStateChange();
protected slots:
	void linkFilterDestroyed();
private:
	void destroySocket();
	void createSocket(const TQString &szLinkFilterName);
signals:
	void connectionFailed(); // the connection attempt has failed
private slots:
	void resolverTerminated();
};

#endif //!_KVI_IRCLINK_H_