summaryrefslogtreecommitdiff
path: root/icqj_s7_sss_mod/utilities.h
blob: ca9970c12e2b8f190a0148935a6679d55328a898 (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
// ---------------------------------------------------------------------------80
//                ICQ plugin for Miranda Instant Messenger
//                ________________________________________
// 
// Copyright © 2000,2001 Richard Hughes, Roland Rabien, Tristan Van de Vreede
// Copyright © 2001,2002 Jon Keating, Richard Hughes
// Copyright © 2002,2003,2004 Martin Öberg, Sam Kothari, Robert Rainwater
// Copyright © 2004,2005,2006,2007 Joe Kucera
// Copyright © 2006,2007 [sss], chaos.persei, [sin], Faith Healer, Thief, Angeli-Ka, nullbie
// 
// 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.
//
// -----------------------------------------------------------------------------
//
// File name      : $HeadURL: https://icqjplusmod.googlecode.com/svn/trunk/utilities.h $
// Revision       : $Revision: 43 $
// Last change on : $Date: 2007-08-20 01:51:06 +0300 (Пн, 20 авг 2007) $
// Last change by : $Author: sss123next $
//
// DESCRIPTION:
//
//  Describe me here please...
//
// -----------------------------------------------------------------------------

#ifndef __UTILITIES_H
#define __UTILITIES_H
#define F_TEMPVIS  1
#define mir_asctime(ptr) ((ptr==NULL)?("<invalid timestamp>"):asctime(ptr))
typedef struct icq_ack_args_s
{
  HANDLE hContact;
  int    nAckType;
  int    nAckResult;
  HANDLE hSequence;
  LPARAM pszMessage;
} icq_ack_args;


typedef struct icq_contacts_cache_s
{
  HANDLE hContact;
  DWORD dwUin;
  DWORD flags;
} icq_contacts_cache;


/*---------* Functions *---------------*/

void EnableDlgItem(HWND hwndDlg, UINT control, int state);
void icq_EnableMultipleControls(HWND hwndDlg, const UINT* controls, int cControls, int state);
void icq_ShowMultipleControls(HWND hwndDlg, const UINT* controls, int cControls, int state);
int IcqStatusToMiranda(WORD wStatus);
WORD MirandaStatusToIcq(int nStatus);
int MirandaStatusToSupported(int nMirandaStatus);
char *MirandaStatusToString(int);
char *MirandaStatusToStringUtf(int);
char**MirandaStatusToAwayMsg(int nStatus);
int IDFromCacheByUin(DWORD dwUin);
int CacheIDCount(void);
int SetCacheFlagsByID(int ID, DWORD flags);
int GetCacheByID(int ID, icq_contacts_cache *icc);
int GetFromCacheByID(int ID, HANDLE *hContact, DWORD *dwUin);

int AwayMsgTypeToStatus(int nMsgType);

void SetGatewayIndex(HANDLE hConn, DWORD dwIndex);
DWORD GetGatewayIndex(HANDLE hConn);
void FreeGatewayIndex(HANDLE hConn);

void AddToSpammerList(DWORD dwUIN);
BOOL IsOnSpammerList(DWORD dwUIN);

void InitCache();
void UninitCache();
void DeleteFromCache(HANDLE hContact);
HANDLE HContactFromUIN(DWORD dwUin, int *Added);
HANDLE HContactFromUID(DWORD dwUIN, char *pszUID, int *Added);
char *NickFromHandle(HANDLE hContact);
char *NickFromHandleUtf(HANDLE hContact);
char *strUID(DWORD dwUIN, char *pszUID);
void NickFromHandleStatic(HANDLE hContact, char *szNick, WORD wLen);
void SetContactHidden(HANDLE hContact, BYTE bHidden);
void makeUserOffline(HANDLE hContact);

size_t __fastcall strlennull(const char *string);
int __fastcall strcmpnull(const char *str1, const char *str2);
int null_snprintf(char *buffer, size_t count, const char* fmt, ...);
char* __fastcall null_strdup(const char *string);
size_t __fastcall null_strcut(char *string, size_t maxlen);

void parseServerAddress(char *szServer, WORD* wPort);

char *DemangleXml(const char *string, int len);
char *MangleXml(const char *string, int len);
char *EliminateHtml(const char *string, int len);
char* ApplyEncoding(const char *string, const char* pszEncoding);


void ResetSettingsOnListReload(void);
void ResetSettingsOnConnect(void);
void ResetSettingsOnLoad(void);
int RandRange(int nLow, int nHigh);

BOOL IsStringUIN(char* pszString);

void icq_SendProtoAck(HANDLE hContact, DWORD dwCookie, int nAckResult, int nAckType, char* pszMessage);

void SetCurrentStatus(int nStatus);

BOOL writeDbInfoSettingString(HANDLE hContact, const char* szSetting, char** buf, WORD* pwLength);
BOOL writeDbInfoSettingWord(HANDLE hContact, const char *szSetting, char **buf, WORD* pwLength);
BOOL writeDbInfoSettingWordWithTable(HANDLE hContact, const char *szSetting, struct fieldnames_t *table, char **buf, WORD* pwLength);
BOOL writeDbInfoSettingByte(HANDLE hContact, const char *szSetting, char **buf, WORD* pwLength);
BOOL writeDbInfoSettingByteWithTable(HANDLE hContact, const char *szSetting, struct fieldnames_t *table, char **buf, WORD* pwLength);

int GetGMTOffset(void);

BOOL validateStatusMessageRequest(HANDLE hContact, WORD byMessageType);

#define icqOnline ((gnCurrentStatus != ID_STATUS_OFFLINE) && (gnCurrentStatus != ID_STATUS_CONNECTING))

void __fastcall SAFE_FREE(void** p);
void* __fastcall SAFE_MALLOC(size_t size);
void* __fastcall SAFE_REALLOC(void* p, size_t size);

HANDLE NetLib_OpenConnection(HANDLE hUser, const char* szIdent, NETLIBOPENCONNECTION* nloc);
HANDLE NetLib_BindPort(NETLIBNEWCONNECTIONPROC_V2 pFunc, void* lParam, WORD* pwPort, DWORD* pdwIntIP);
void NetLib_CloseConnection(HANDLE *hConnection, int bServerConn);
void NetLib_SafeCloseHandle(HANDLE *hConnection);
int NetLog_Server(const char *fmt,...);
int NetLog_Direct(const char *fmt,...);
int NetLog_Uni(BOOL bDC, const char *fmt,...);

int ICQBroadcastAck(HANDLE hContact,int type,int result,HANDLE hProcess,LPARAM lParam);

int __fastcall ICQTranslateDialog(HWND hwndDlg);
char* __fastcall ICQTranslate(const char* src);
char* __fastcall ICQTranslateUtf(const char* src);
char* __fastcall ICQTranslateUtfStatic(const char* src, char* buf, size_t bufsize);

HANDLE ICQCreateThreadEx(pThreadFuncEx AFunc, void* arg, DWORD* pThreadID);
void ICQCreateThread(pThreadFuncEx AFunc, void* arg);

char* GetUserPassword(BOOL bAlways);
WORD GetMyStatusFlags();

BOOL invis_for(DWORD dwUin, HANDLE hContact);

typedef struct{
	DWORD dwUin; //contact uin (dword)
	HANDLE hContact;  //(HANDLE)
	int PSD; //value for calling setuserstatus (-1 for disable)
	BOOL popup; //set TRUE for show popup (BOOL)
	int popuptype; //set popup event type (int)
	BOOL historyevent; //set history event type (BOOL)
	BOOL logtofile; //set TRUE for write event to file (BOOL)
	char* msg; //set event message (char)
	int icqeventtype; //set db event type for history (int)
	int dbeventflag; //set additional db flags (int)
	BOOL nottmpcontact; //work with contact which not temporary (BOOL)
	BOOL fornotonlist; //work with contact which not on list (BOOL)
	BOOL foroffline; //work with offline contact (BOOL)
	BOOL weofflinefor; //work with contact which we offline for (BOOL)
}CHECKCONTACT;
void CheckContact(CHECKCONTACT chk);
BYTE bVisibility;

int IncognitoAwayRequest(WPARAM wParam, LPARAM lParam);
BOOL bIncognitoRequest;

/* Unicode FS utility functions */

int IsValidRelativePath(const char *filename);
char* ExtractFileName(const char *fullname);
char* FileNameToUtf(const char *filename);
int FileStatUtf(const char *path, struct _stati64 *buffer);
int MakeDirUtf(const char *dir);
int OpenFileUtf(const char *filename, int oflag, int pmode);

/* Unicode UI utility functions */
WCHAR* GetWindowTextUcs(HWND hWnd);
void SetWindowTextUcs(HWND hWnd, WCHAR *text);
char* GetWindowTextUtf(HWND hWnd);
char* GetDlgItemTextUtf(HWND hwndDlg, int iItem);
void SetWindowTextUtf(HWND hWnd, const char* szText);
void SetDlgItemTextUtf(HWND hwndDlg, int iItem, const char* szText);
LONG SetWindowLongUtf(HWND hWnd, int nIndex, LONG dwNewLong);
LRESULT CallWindowProcUtf(WNDPROC OldProc, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

int ComboBoxAddStringUtf(HWND hCombo, const char* szString, DWORD data);
int ListBoxAddStringUtf(HWND hList, const char* szString);

int MessageBoxUtf(HWND hWnd, const char* szText, const char* szCaption, UINT uType);
HWND DialogBoxUtf(BOOL bModal, HINSTANCE hInstance, const char* szTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam);
HWND CreateDialogUtf(HINSTANCE hInstance, const char* lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc);

void HistoryLog(HANDLE hContact, DWORD dwUin, char *data, int event_type, int flag);
void LogToFile(HANDLE hContact, DWORD dwUin, char *string, int event_type);
void SetTimeStamps(DWORD *dwFT1, DWORD *dwFT2, DWORD *dwFT3);
BOOL gbSecureIM;
WORD GetProtoVersion();

#endif /* __UTILITIES_H */