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
319
|
#include "skype_proto.h"
wchar_t *CSkypeProto::ValidationReasons[] =
{
LPGENW("NOT_VALIDATED") /* NOT_VALIDATED */,
LPGENW("Validation succeeded") /* VALIDATED_OK */,
LPGENW("Password is too short") /* TOO_SHORT */,
LPGENW("The value exceeds max size limit for the given property") /* TOO_LONG */,
LPGENW("Value contains illegal characters") /* CONTAINS_INVALID_CHAR */,
LPGENW("Value contains whitespace") /* CONTAINS_SPACE */,
LPGENW("Password cannot be the same as skypename") /* SAME_AS_USERNAME */,
LPGENW("Value has invalid format") /* INVALID_FORMAT */,
LPGENW("Value contains invalid word") /* CONTAINS_INVALID_WORD */,
LPGENW("Password is too simple") /* TOO_SIMPLE */,
LPGENW("Value starts with an invalid character") /* STARTS_WITH_INVALID_CHAR */,
};
std::map<std::wstring, std::wstring> CSkypeProto::languages;
void CSkypeProto::InitLanguages()
{
List_String languageCodeList;
List_String languageNameList;
if (g_skype->GetISOLanguageInfo(languageCodeList, languageNameList))
for (size_t i = 0; i < languageCodeList.size(); i++)
CSkypeProto::languages[::mir_a2u(languageCodeList[i])] = ::mir_a2u(languageNameList[i]);
}
void CSkypeProto::InitCustomFolders()
{
if (m_bInitDone)
return;
m_bInitDone = true;
TCHAR AvatarsFolder[MAX_PATH];
::mir_sntprintf(AvatarsFolder, SIZEOF(AvatarsFolder), _T("%%miranda_avatarcache%%\\%S"), this->m_szModuleName);
m_hAvatarsFolder = ::FoldersRegisterCustomPathT(LPGEN("Avatars"), m_szModuleName, AvatarsFolder, m_tszUserName);
}
// ---
void CSkypeProto::CreateServiceObj(const char* szService, SkypeServiceFunc serviceProc)
{
char moduleName[MAXMODULELABELLENGTH];
::mir_snprintf(moduleName, sizeof(moduleName), "%s%s", this->m_szModuleName, szService);
::CreateServiceFunctionObj(moduleName, (MIRANDASERVICEOBJ)*(void**)&serviceProc, this);
}
void CSkypeProto::CreateServiceObjParam(const char* szService, SkypeServiceFunc serviceProc, LPARAM lParam)
{
char moduleName[MAXMODULELABELLENGTH];
::mir_snprintf(moduleName, sizeof(moduleName), "%s%s", this->m_szModuleName, szService);
::CreateServiceFunctionObjParam(moduleName, (MIRANDASERVICEOBJPARAM)*(void**)&serviceProc, this, lParam);
}
HANDLE CSkypeProto::CreateEvent(const char* szService)
{
char moduleName[MAXMODULELABELLENGTH];
::mir_snprintf(moduleName, sizeof(moduleName), "%s%s", this->m_szModuleName, szService);
return ::CreateHookableEvent(moduleName);
}
void CSkypeProto::FakeAsync(void *param)
{
::Sleep(100);
::CallService(MS_PROTO_BROADCASTACK, 0, (LPARAM)param);
::mir_free(param);
}
int CSkypeProto::SendBroadcast(HANDLE hContact, int type, int result, HANDLE hProcess, LPARAM lParam)
{
return ::ProtoBroadcastAck(this->m_szModuleName, hContact, type, result, hProcess, lParam);
}
int CSkypeProto::SendBroadcast(int type, int result, HANDLE hProcess, LPARAM lParam)
{
return this->SendBroadcast(NULL, type, result, hProcess, lParam);
}
DWORD CSkypeProto::SendBroadcastAsync(HANDLE hContact, int type, int hResult, HANDLE hProcess, LPARAM lParam, size_t paramSize)
{
ACKDATA *ack = (ACKDATA *)::mir_calloc(sizeof(ACKDATA) + paramSize);
ack->cbSize = sizeof(ACKDATA);
ack->szModule = this->m_szModuleName;
ack->hContact = hContact;
ack->type = type;
ack->result = hResult;
ack->hProcess = hProcess;
ack->lParam = lParam;
if (paramSize)
::memcpy(ack+1, (void*)lParam, paramSize);
::mir_forkthread(&CSkypeProto::FakeAsync, ack);
return 0;
}
void CSkypeProto::ForkThread(SkypeThreadFunc pFunc, void *param)
{
UINT threadID;
::CloseHandle((HANDLE)::mir_forkthreadowner(
(pThreadFuncOwner)*(void**)&pFunc,
this,
param,
&threadID));
}
HANDLE CSkypeProto::ForkThreadEx(SkypeThreadFunc pFunc, void *param, UINT* threadID)
{
UINT lthreadID;
return (HANDLE)::mir_forkthreadowner(
(pThreadFuncOwner)*(void**)&pFunc,
this,
param,
threadID ? threadID : <hreadID);
}
//
int CSkypeProto::SkypeToMirandaLoginError(CAccount::LOGOUTREASON logoutReason)
{
int loginError = 0;
// todo: rewrite!!
switch (logoutReason)
{
case CAccount::SERVER_OVERLOADED:
case CAccount::P2P_CONNECT_FAILED:
case CAccount::SERVER_CONNECT_FAILED:
loginError = LOGINERR_NOSERVER;
break;
case CAccount::HTTPS_PROXY_AUTH_FAILED:
case CAccount::SOCKS_PROXY_AUTH_FAILED:
loginError = LOGINERR_PROXYFAILURE;
break;
case CAccount::INCORRECT_PASSWORD:
case CAccount::UNACCEPTABLE_PASSWORD:
loginError = LOGINERR_WRONGPASSWORD;
break;
case CAccount::INVALID_APP_ID:
loginError = 1001;
break;
}
return loginError;
}
void CSkypeProto::ShowNotification(const wchar_t *caption, const wchar_t *message, int flags, HANDLE hContact)
{
if (::Miranda_Terminated()) return;
if ( !::ServiceExists(MS_POPUP_ADDPOPUPT) || !::db_get_b(NULL, "PopUp", "ModuleIsEnabled", 1))
::MessageBoxW(NULL, message, caption, MB_OK | flags);
else
{
POPUPDATAW ppd = {0};
ppd.lchContact = hContact;
//if (!hContact)
{
::wcsncpy(ppd.lpwzContactName, caption, MAX_CONTACTNAME);
}
::wcsncpy(ppd.lpwzText, message, MAX_SECONDLINE);
ppd.lchIcon = ::Skin_GetIcon("Skype_main");
PUAddPopUpW(&ppd);
}
}
void CSkypeProto::ShowNotification(const wchar_t *message, int flags, HANDLE hContact)
{
CSkypeProto::ShowNotification(::TranslateT(MODULE), message, flags, hContact);
}
struct HtmlEntity
{
const char *entity;
char symbol;
};
const HtmlEntity htmlEntities[]={
{"nbsp", ' '},
{"amp", '&'},
{"quot", '"'},
{"lt", '<'},
{"gt", '>'},
{"apos", '\''},
{"copy", '©'},
// TODO: add more
};
char *CSkypeProto::RemoveHtml(const char *text)
{
std::string new_string = "";
std::string data = text;
for (std::string::size_type i = 0; i < data.length(); i++)
{
if (data.at(i) == '<' && data.at(i+1) != ' ')
{
i = data.find(">", i);
if (i == std::string::npos)
break;
continue;
}
if (data.at(i) == '&') {
std::string::size_type begin = i;
i = data.find(";", i);
if (i == std::string::npos) {
i = begin;
} else {
std::string entity = data.substr(begin+1, i-begin-1);
bool found = false;
for (int j=0; j<SIZEOF(htmlEntities); j++)
{
if (!stricmp(entity.c_str(), htmlEntities[j].entity)) {
new_string += htmlEntities[j].symbol;
found = true;
break;
}
}
if (found)
continue;
else
i = begin;
}
}
new_string += data.at(i);
}
return ::mir_strdup(new_string.c_str());
}
int CSkypeProto::SkypeToMirandaStatus(CContact::AVAILABILITY availability)
{
int status = ID_STATUS_OFFLINE;
switch (availability)
{
case CContact::ONLINE:
case CContact::SKYPE_ME:
status = ID_STATUS_ONLINE;
break;
case CContact::ONLINE_FROM_MOBILE:
case CContact::SKYPE_ME_FROM_MOBILE:
status = ID_STATUS_ONTHEPHONE;
break;
case CContact::AWAY:
case CContact::AWAY_FROM_MOBILE:
status = ID_STATUS_AWAY;
break;
case CContact::DO_NOT_DISTURB:
case CContact::DO_NOT_DISTURB_FROM_MOBILE:
status = ID_STATUS_DND;
break;
case CContact::SKYPEOUT:
status = ID_STATUS_OUTTOLUNCH;
break;
case CContact::CONNECTING:
status = ID_STATUS_CONNECTING;
break;
}
return status;
}
CContact::AVAILABILITY CSkypeProto::MirandaToSkypeStatus(int status)
{
CContact::AVAILABILITY availability = CContact::UNKNOWN;
switch(status)
{
case ID_STATUS_ONLINE:
availability = CContact::ONLINE;
break;
case ID_STATUS_AWAY:
availability = CContact::AWAY;
break;
case ID_STATUS_DND:
availability = CContact::DO_NOT_DISTURB;
break;
case ID_STATUS_INVISIBLE:
availability = CContact::INVISIBLE;
break;
}
return availability;
}
bool CSkypeProto::FileExists(wchar_t *path)
{
//return ::GetFileAttributes(fileName) != DWORD(-1)
WIN32_FIND_DATA wfd;
HANDLE hFind = ::FindFirstFile(path, &wfd);
if (INVALID_HANDLE_VALUE != hFind)
{
::FindClose(hFind);
return true;
}
return false;
}
|