summaryrefslogtreecommitdiff
path: root/protocols/WinPopup/src/winpopup_proto.h
blob: 6016a583f8e117cbb1c16f4accf58e4eb33596d3 (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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*

WinPopup Protocol plugin for Miranda IM.

Copyright (C) 2004-2010 Nikolay Raspopov

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.
*/

// Äàííûå èñïîëüçóåìûå ïëàãèíîì â áàçå äàííûõ Miranda IM
//
// Ñîáñòâåííûå äàííûå ïëàãèíà:
// Nick						String	- ñâîå íàçâàíèå ìàøèíû (àâò.îáíîâëÿåòñÿ)
// User						String	- ñâîå íàçâàíèå ïîëüçîâàòåëÿ (àâò.îáíîâëÿåòñÿ)
// Workgroup				String	- ñâîå íàçâàíèå äîìåíà èëè ðàáî÷åé ãðóïïû ìàøèíû (àâò.îáíîâëÿåòñÿ)
// Auto-answer				BYTE	- ôëàã àâòî-îòâåòà (ïî-óìîë÷àíèþ: 0)
// Filter-dups				BYTE	- ôëàã ôèëüòðàöèè äóáëèêàòîâ (ïî-óìîë÷àíèþ: 1)
// SendMethod   			BYTE    - ñïîñîá îòñûëêè ñîîáùåíèé: 0 - mailslot, 1 - NetBIOS, 2 - Messenger  (ïî-óìîë÷àíèþ: 0)
// RegisterNick 			BYTE    - ôëàã ðåãèñòðàöèè NetBIOS èìåíè Nick<01> è Nick<03> (ïî-óìîë÷àíèþ: 1)
// RegisterUser 			BYTE    - ôëàã ðåãèñòðàöèè NetBIOS èìåíè User<03> (ïî-óìîë÷àíèþ: 1)
// RegisterStatus 			BYTE	- ôëàã ðåãèñòðàöèè NetBIOS èìåíè MNS_STATUS<ab> (ïî-óìîë÷àíèþ: 1)
// Check00ForOnline			BYTE	- ôëàã äîïîëíèòåëüíîé ïðîâåðêè NetBIOS èì¸í Nick<00> íà îíëàéí ñòàòóñ, äëÿ âñåõ êîíòàêòîâ (ïî óìîë÷àíèþ: 0) (ïåðåèìåíîâàíî èç AlwaysCheck00ForOnline)
// AvatarFile				String	- ïóòü ê ôàéëó àâàòàðà
//
// Äàííûå ïëàãèíà äëÿ êîíòàêòîâ:
// Nick						String	- íàçâàíèå ìàøèíû
// IP						DWORD	- àäðåñ ìàøèíû
// RealIP					DWORD	- àäðåñ ìàøèíû (ñîâïàäàåò ñ IP)
// IPTimeL					DWORD	- âðåìÿ ïîñëåäíåãî ðåñîëâèíãà èìåíè â àäðåñ
// IPTimeH					DWORD
// LastSeenL				DWORD	- âðåìÿ ïîñëåäíåé ïðîâåðêà êîíòàêòà
// LastSeenH				DWORD
// PingCounter				WORD	- ñ÷¸ò÷èê ïîñëàííûõ ïèíãîâ áåç îòâåòà (áîëüøå íå èñïîëüçóåòñÿ)
// Status					WORD	- ñòàòóñ êîíòàêòà
// About					String	- êîììåíòàðèé
// AlwaysOnline				BYTE	- ôëàã îòîáðàæåíèÿ êîíòàêòà â online-ñîñòîÿíèè âñåãäà
// Check00ForOnline 		BYTE	- ôëàã äîïîëíèòåëüíîé ïðîâåðêè NetBIOS èìåíè Nick<00> íà îíëàéí ñòàòóñ (ïî óìîë÷àíèþ: 0)
// AvatarFile				String	- ïóòü ê ôàéëó àâàòàðà
// Group					BYTE	- 1/0 - ýòî ãðóïïîâîé êîíòàêò
//
// Íåèñïîëüçóåìûå íàñòðîéêè:
// ChatRoom					BYTE	- 1/0 - ýòî ÷àò
// ChatRoomID				String	- èäåíòèôèêàòîð ÷àòà, îáû÷íî èìÿ ðàáî÷åé ãðóïïû
//
// Äàííûå CList (ãëàâíîãî ñïèñêà êîíòàêîâ) äëÿ êîíòàêòîâ:
// MyHandle					String	- íàçâàíèå êîíòàêòà (ðåä. ïîëüçîâàòåëåì)
// NotOnList				BYTE	- ôëàã âðåìåííîãî êîíòàêòà
// Hidden					BYTE	- ôëàã ñêðûòîãî êîíòàêòà
//
// Äàííûå Icons (èêîíêè ñòàòóñà) äëÿ ïëàãèíà:
// WinPopup Protocol40071	String	- ïóòü ê èêîíêå ñòàòóñà
// WinPopup Protocol40072	String	- ïóòü ê èêîíêå ñòàòóñà
// WinPopup Protocol40073	String	- ïóòü ê èêîíêå ñòàòóñà
// WinPopup Protocol40074	String	- ïóòü ê èêîíêå ñòàòóñà
// WinPopup Protocol40075	String	- ïóòü ê èêîíêå ñòàòóñà
// WinPopup Protocol40076	String	- ïóòü ê èêîíêå ñòàòóñà
// WinPopup Protocol40077	String	- ïóòü ê èêîíêå ñòàòóñà
// WinPopup Protocol40078	String	- ïóòü ê èêîíêå ñòàòóñà
// WinPopup Protocol40079	String	- ïóòü ê èêîíêå ñòàòóñà
// WinPopup Protocol40080	String	- ïóòü ê èêîíêå ñòàòóñà

// Íàçâàíèå ïëàãèíà
#define modname				"WinPopup Protocol"
#define modname_t			_T( modname )
// Êðàòêîå íàçâàíèå ïëàãèíà
#define modtitle			"WinPopup"
#define modtitle_t			_T( modtitle )
// "Íå ìîãó îñòàíîâèòü Ñëóæáó Ñîîáùåíèé"
#define T_STOP_ERROR		TranslateT("Cannot stop Messenger service")
// "Íå ìîãó çàïóñòèòü Ñëóæáó Ñîîáùåíèé"
#define T_START_ERROR		TranslateT("Cannot start Messenger service")
// "Íå ìîãó âêëþ÷èòü Ñëóæáó Ñîîáùåíèé"
#define T_ENABLE_ERROR		TranslateT("Cannot enable Messenger service")
// "Íå ìîãó ñîçäàòü ïðè¸ìíûé ìåéëñëîò"
#define T_CREATE_ERROR		TranslateT("Cannot create receiving mailslot")
// "Îøèáêà"
#define T_ERROR				TranslateT("Error")
// Íàçâàíèå ñåðâèñà Messenger
#define MESSENGER			_T("Messenger")
// Íàçâàíèå ìåéëñëîòà Messenger
#define MESSENGER_MAIL		_T("messngr")
// Âðåìÿ äîâåðèÿ IP àäðåñó (3 ÷àñà)
#define MAX_TRUSTED_IP_TIME	3*60*60
// Ìèíèìàëüíîê âðåìÿ îáíîâëåíèÿ êîíòàêòà (ðàç â 30 ñ)
#define MIN_PING_INTERVAL	30

typedef struct _ContactData
{
	HANDLE			cookie;		// Èäåíòèôèêàòîð çàïðîñà ÿäðà ìèðàíäû äëÿ îòâåòà
	HANDLE			hContact;	// Õýíäëåð êîíòàêòà
} ContactData;

typedef struct _SendMsgData
{
	HANDLE			cookie;		// Èäåíòèôèêàòîð çàïðîñà ÿäðà ìèðàíäû äëÿ îòâåòà
	HANDLE			hContact;	// Õýíäëåð êîíòàêòà
	CString			text;
} SendMsgData;

typedef struct _ThreadEvent
{
	HANDLE			evt;		// Õýíäëåð ñîáûòèÿ
	HANDLE			cookie;		// Èäåíòèôèêàòîð çàïðîñà ÿäðà ìèðàíäû äëÿ îòâåòà
} ThreadEvent;

typedef CAtlMap < WPARAM, CString > CIntStrMap;
typedef CAtlMap < HANDLE, ThreadEvent > CThreadContactMap;

// Êëàññ äëÿ êîíâåðòàöèè ANSI ñòðîêè â OEM è ïîñëåäóþùåãî õðàíåíèÿ
class COemString
{
public:
	COemString(LPCTSTR ansi) :
		len( (size_t)lstrlen( ansi ) + 1 ),
		pos( 0 )
	{
		oem = (LPSTR)mir_alloc( len );
		CharToOemBuff( ansi, oem, (DWORD)len );
	}

	~COemString()
	{
		mir_free( oem );
	}

	inline operator LPCSTR() const
	{
		return oem + pos;
	}

	// Äëèíà ñòðîêè (áåç null)
	inline int GetLength() const
	{
		return (int)( len - pos - 1 );
	}

	// "Îòðåçàíèå" îò íà÷àëà ñòðîêè
	inline void CutFromStart(int n)
	{
		if ( GetLength() > n )
			pos += n;
		else
			pos = len - 1;
	}

protected:
	size_t	len;
	size_t	pos;
	LPSTR	oem;
};

// Êëàññ äëÿ êîíâåðòàöèè OEM ñòðîêè â ANSI è ïîñëåäóþùåãî õðàíåíèÿ
class CAnsiString
{
public:
	CAnsiString(LPCSTR oem) :
		len( lstrlenA( oem ) + 1 ),
		pos( 0 )
	{
		ansi = (LPTSTR)mir_alloc( len * sizeof( TCHAR ) );
		OemToCharBuff( oem, ansi, (DWORD)len );
	}
	~CAnsiString()
	{
		mir_free( ansi );
	}
	inline operator LPCTSTR() const
	{
		return ansi + pos;
	}
	// Äëèíà ñòðîêè (áåç null)
	inline int GetLength() const
	{
		return len - pos - 1;
	}
	// "Îòðåçàíèå" îò íà÷àëà ñòðîêè
	inline void CutFromStart(int n)
	{
		if ( len - pos - 1 > n )
			pos += n;
		else
			pos = len - 1;
	}
protected:
	int		len;
	int		pos;
	LPTSTR	ansi;
};

extern volatile WPARAM		pluginRequestedStatus;	// Òðåáóåìûé ñòàòóñ
extern volatile WPARAM		pluginCurrentStatus;	// Òåêóùèé ñòàòóñ
extern CIntStrMap			pluginStatusMessage;	// Êàðòà ñòàòóñíûõ ñîîáùåíèé
extern CString				pluginMachineName;		// Èìÿ êîìïüþòåðà
extern CString				pluginUserName;			// Èìÿ ïîëüçîâàòåëÿ
extern CString				pluginDomainName;		// Èìÿ äîìåíà èëè ãðóïïû
extern HMODULE				pluginModule;			// Õýíäëåð íà ìîäóëü
extern volatile bool		pluginInstalled;		// Ôëàã ðàçðåøåíèÿ ðàáîòû ïëàãèíà,
													// ñáðàñûâàåòñÿ â false ïðè äåèíñòàëëÿöèè
													// èëè ïðè âûêëþ÷åíèè
extern volatile bool		pluginInitialized;		// Ôëàã çàâåðøåíèÿ èíèöèàëèçàöèè ïëàãèíà
extern HANDLE				pluginNetLibUser;		// Õýíäëåð NetLib
extern HANDLE				pluginInternalState;	// Õýíäëåð ñîáûòèÿ (ñèãíàëüíîå ñîñòîÿíèå - ïëàãèí îñòàíîâëåí)
extern bool					pluginChatEnabled;		// Èñïîëüçóåì Chat-ïëàãèí?
extern OSVERSIONINFO		pluginOS;				// Âåðñèÿ ñèñòåìû

// Ïîëó÷åíèå íèêà êîíòàêòà
CString GetNick(HANDLE hContact);
// Óñòàíîâêà íèêà êîíòàêòà
void SetNick(HANDLE hContact, LPCTSTR szNick);
// Âûâîä â ñòàíäàðòíûé äëÿ ìèðàíäû ëîã NetLib
int LOG(const char *fmt,...);
// Ïîëó÷åíèå ïóòè ãäå õðàíÿòñÿ àâàòàðû
void GetAvatarCache(LPTSTR szPath);
// Ïîëó÷åíèå "óíèêàëüíîãî" ÷èñëà
HANDLE GenerateCookie();
// Win32 API âåðñèÿ ôóíêöèè time() (äëÿ îñâîáîæäåíèÿ îò çàâèñèìîñòè CRT)
DWORD time();
// Îïðåäåëåíèå ïðèíàäëåæíîñòè êîíòàêòà ïëàãèíó
bool IsMyContact(HANDLE hContact);
// Óñòàíîâêà ñòàòóñà ïëàãèíà
void SetPluginStatus(WPARAM status);
// Âêëþ÷åíèå âñåõ ïîäñèñòåì ïëàãèíà
bool InternalStartup();
// Âûêëþ÷åíèå âñåõ ïîäñèñòåì ïëàãèíà
void InternalShutdown();
// Ïåðåâîä ïëàãèíà â Online
void GotoOnline();
// Ïåðåâîä ïëàãèíà â Offline
void GotoOffline();
// Ðàáî÷àÿ íèòü àñèíõðîííîãî ïåðåõîäà ïëàãèíà â Online
void GotoOnlineTread(LPVOID status);
// Ðàáî÷àÿ íèòü àñèíõðîííîãî ïåðåõîäà ïëàãèíà â Offline
void GotoOfflineTread(LPVOID status);
// Ðàáî÷àÿ íèòü àñèíõðîííîãî ïîëó÷åíèÿ ýâåé-ñîîáùåíèÿ êîíòàêòà
void GetAwayMsgThread(LPVOID param);
// Ðàáî÷àÿ íèòü àñèíõðîííîãî âîçâðàùåíèÿ èíôîðìàöèè î êîíòàêòå
void GetInfoThread(LPVOID param);
// Àâòîîòâåò÷èê ñòàòóñíîãî ñîîáùåíèÿ
void Autoanswer(HANDLE hContact);
// Ïðè¸ì ñîîáùåíèÿ, ïðîâåðêà íà äóáëèêàòû, î÷èñòêà è îòïðàâêà â áàçó Miranda IM
void ReceiveContactMessage(LPCTSTR msg_from, LPCTSTR msg_to, LPCTSTR msg_text, int msg_len);
// Äîáàâëåíèå êîíòàêòà ïî èìåíè (ñ íàõîæäåíèåì åãî IP-àäðåñà)
HANDLE AddToListByName (const CString& sName, WPARAM flags, LPCTSTR notes, bool bInteractive, bool bGroup);
// Ïîëó÷åíèå "nameL" | ("nameH" << 32) êîíòàêòà
DWORD GetElapsed(HANDLE hContact, const char* name);
// Óñòàíîâêà "LastSeen" êîíòàêòà ðàâíûì òåêóùåìó âðåìåíè
void SetElapsed(HANDLE hContact, const char* name);
// Ïîèñê êîíòàêòà ïî "IP"
HANDLE GetContact(ip addr);
// Ïîèñê êîíòàêòà ïî "Nick"
HANDLE GetContact(LPCTSTR name);
// Óñòàíîâêà ñòàòóñà êîíòàêòà (simple == true - óñòàíîâêà òîëüêî online/offline)
void SetContactStatus(HANDLE hContact, int status, bool simple);
// Óñòàíîâêà ýâåé-òåêñòà êîíòàêòà
void SetContactAway(HANDLE hContact, LPCSTR away);
// Óñòàíîâêà àâàòàðà êîíòàêòà
void SetContactAvatar(HANDLE hContact, LPCVOID pBuffer, DWORD nLength);
// Ïîëó÷åíèå IP-àäðåñà êîíòàêòà (ñ ïðîâåðêîé è ðåñîëâèíãîì, åñëè òðåáóåòñÿ)
ip GetContactIP(HANDLE hContact);
// Óñòàíîâêà "IP" êîíòàêòà
void SetContactIP(HANDLE hContact, ip addr);
// Ýòî ãðóïïîâîé êîíòàêò?
bool IsGroup(HANDLE hContact);
// Óñòàíîâêà ãðóïïîâîãî êîíòàêòà
void SetGroup(HANDLE hContact, bool bGroup);
// Èñïîëüçóåòñÿ ñòàðûé ìåòîä îíëàéí-ïðîâåðêè?
bool IsLegacyOnline(HANDLE hContact);
// Óñòàíîâêà ñòàðîãî ìåòîäà îíëàéí-ïðîâåðêè
void SetLegacyOnline(HANDLE hContact, bool bOnline);
// Ïîñûëêà ñîîáùåíèÿ
bool SendContactMessage(HANDLE hContact, LPCTSTR msg, DWORD& err);
// Ðàáî÷àÿ íèòü àñèíõðîííîé ïîñûëêè ñîîáùåíèÿ
void SendMsgThread(LPVOID param);
// Ðàáî÷àÿ íèòü àñèíõðîííîãî çàïðîñà àâàòàðà
void GetAvatarInfoThread(LPVOID param);
// Ìî¸ èìÿ?
bool IsItMe(LPCTSTR name);
// Íîðìàëèçàöèÿ ðàçáèåíèÿ ñîîáùåíèÿ íà ñòðîêè
void Normalize(CString& msg);
// Ïîëó÷åíèå ñïèñêà ðàáî÷èõ ãðóïï / äîìåíîâ
void EnumWorkgroups(CAtlList< CString >& lst, LPNETRESOURCE hRoot = NULL);

// Ìàêðîñ îðãàíèçàöèè öèêëà ïåðåáîðà ñâîèõ êîíòàêòîâ â ñïèñêå êîíòàêòîâ
#define FOR_EACH_CONTACT(h) \
	HANDLE h = (HANDLE)CallService( MS_DB_CONTACT_FINDFIRST, 0, 0 ); \
	for ( ; h != NULL; \
	h = (HANDLE)CallService( MS_DB_CONTACT_FINDNEXT, (WPARAM)h, 0 ) ) \
		if ( IsMyContact( h ) )

// Ìàêðîñ äëÿ ïå÷àòè íàçâàíèÿ ñòàòóñà (îòëàäî÷íûé)
#define STATUS2TEXT(s) \
	((((s) == ID_STATUS_OFFLINE) ? "Offline" : \
	(((s) == ID_STATUS_ONLINE) ? "Online" : \
	(((s) == ID_STATUS_AWAY) ? "Away" : \
	(((s) == ID_STATUS_DND) ? "DND" : \
	(((s) == ID_STATUS_NA) ? "NA" : \
	(((s) == ID_STATUS_OCCUPIED) ? "Occupied" : \
	(((s) == ID_STATUS_FREECHAT) ? "Free to chat" : \
	(((s) == ID_STATUS_INVISIBLE) ? "Invisible" : \
	(((s) == ID_STATUS_ONTHEPHONE) ? "On the phone" : \
	(((s) == ID_STATUS_OUTTOLUNCH) ? "Out to lunch" : \
	(((s) == ID_STATUS_IDLE) ? "Idle" : \
	(((s) == (ID_STATUS_CONNECTING + 0)) ? "Connecting 1" : \
	(((s) == (ID_STATUS_CONNECTING + 1)) ? "Connecting 2" : \
	(((s) <  (ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) ? "Connecting > 2" : \
	"Unknown")))))))))))))))