File: IRCConnection.h

package info (click to toggle)
sbnc 1.2-26
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 6,216 kB
  • sloc: cpp: 17,556; ansic: 15,514; sh: 13,419; tcl: 5,567; php: 448; makefile: 284
file content (154 lines) | stat: -rw-r--r-- 5,817 bytes parent folder | download | duplicates (3)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*******************************************************************************
 * shroudBNC - an object-oriented framework for IRC                            *
 * Copyright (C) 2005-2007 Gunnar Beutner                                      *
 *                                                                             *
 * 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 option) 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. *
 *******************************************************************************/

/**
 * connection_state_e
 *
 * Describes the status of an IRC connection.
 */
enum connection_state_e {
	State_Unknown, /**< unknown status */
	State_Connecting, /**< first ping event has not yet been received */
	State_Pong, /**< first pong has been sent */
	State_Connected /**< the motd has been received */
};

class CUser;
struct CConfig;
class CChannel;
class CQueue;
class CFloodControl;
class CTimer;

#ifdef SWIGINTERFACE
%template(COwnedObjectCUser) COwnedObject<class CUser>;
%template(CZoneObjectCIRCConnection) CZoneObject<class CIRCConnection, 16>;
#endif

#ifndef SWIG
bool DelayJoinTimer(time_t Now, void *IRCConnection);
bool IRCPingTimer(time_t Now, void *IRCConnection);
bool NickCatchTimer(time_t Now, void *IRCConnection);
#endif

/**
 * CIRCConnection
 *
 * An IRC connection.
 */
class SBNCAPI CIRCConnection : public CConnection, public CObject<CIRCConnection, CUser>, public CZoneObject<CIRCConnection, 16> {
private:
#ifndef SWIG
	friend bool DelayJoinTimer(time_t Now, void *IRCConnection);
	friend bool IRCPingTimer(time_t Now, void *IRCConnection);
	friend bool NickCatchTimer(time_t Now, void *IRCConnection);
#endif

	connection_state_e m_State; /**< the current status of the IRC connection */

	char *m_CurrentNick; /**< the current nick for this IRC connection */
	char *m_Site; /**< the ident\@host of this IRC connection */
	char *m_Server; /**< the hostname of the IRC server */
	char *m_Usermodes; /**< the usermodes */

	CHashtable<CChannel *, false, 16> *m_Channels; /**< the channels this IRC user is on */

	char *m_ServerVersion; /**< the version from the 351 reply */
	char *m_ServerFeat; /**< the server features from the 351 reply */

	CHashtable<char *, false, 32> *m_ISupport; /**< the key/value pairs from the 005 replies */
	
	CTimer *m_DelayJoinTimer; /**< timer for delay-joining channels */
	CTimer *m_PingTimer; /**< timer for sending regular PINGs to the server */
	CTimer *m_NickCatchTimer; /**< used for regaining a user's away nick */

	CQueue *m_QueueLow; /**< low-priority queue */
	CQueue *m_QueueMiddle; /**< middle-priority queue */
	CQueue *m_QueueHigh; /**< high-priority queue */
	CFloodControl *m_FloodControl; /**< flood control object for the IRC connection */

	time_t m_LastResponse; /**< a TS which describes when the last line was received from the server */

	bool m_EatPong; /**< whether to ignore the next PONG event from the IRC server */

	CChannel *AddChannel(const char *Channel);
	void RemoveChannel(const char *Channel);

	void UpdateChannelConfig(void);
	void UpdateHostHelper(const char *Host);
	void UpdateWhoHelper(const char *Nick, const char *Realname, const char *Server);

	bool ModuleEvent(int ArgC, const char **ArgV);

	void WriteUnformattedLine(const char *Line);

	virtual int Read(void);
	virtual void Error(int ErrorValue);
	virtual int Write(void);
	virtual bool HasQueuedData(void) const;
	virtual const char *GetClassName(void) const;

	bool ParseLineArgV(int ArgC, const char **ArgV);

	void AsyncDnsFinished(hostent *Response);
	void AsyncBindIpDnsFinished(hostent *Response);
public:
#ifndef SWIG
	CIRCConnection(const char *Host, unsigned short Port, CUser *Owner, safe_box_t Box, const char *BindIp, bool SSL = false, int Family = AF_INET);
	virtual ~CIRCConnection();
#endif

	CChannel *GetChannel(const char *Name);
	CHashtable<CChannel *, false, 16> *GetChannels(void);

	const char *GetCurrentNick(void) const;
	const char *GetSite(void) /* const */;
	const char *GetServer(void) const;

	const char *GetServerVersion(void) const;
	const char *GetServerFeat(void) const;

	CQueue *GetQueueHigh(void);
	CQueue *GetQueueMiddle(void);
	CQueue *GetQueueLow(void);

	CFloodControl *GetFloodControl(void);

	const CHashtable<char *, false, 32> *GetISupportAll(void) const;
	const char *GetISupport(const char *Feature) const;
	void SetISupport(const char *Feature, const char *Value);
	bool IsChanMode(char Mode) const;
	int RequiresParameter(char Mode) const;
	bool IsNickPrefix(char Char) const;
	bool IsNickMode(char Char) const;
	char PrefixForChanMode(char Mode) const;
	char GetHighestUserFlag(const char *Modes) const;

	void ParseLine(const char *Line);

	void JoinChannels(void);

	void Destroy(void);

	virtual int SSLVerify(int PreVerifyOk, X509_STORE_CTX *Context) const;

	void Kill(const char *Error);

	const char *GetUsermodes(void);
};