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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
|
#include "skype_proto.h"
int CSkypeProto::OnModulesLoaded(WPARAM, LPARAM)
{
this->InitSkype();
this->InitChat();
this->InitNetLib();
this->InitCustomFolders();
this->HookEvent(ME_OPT_INITIALISE, &CSkypeProto::OnOptionsInit);
this->HookEvent(ME_USERINFO_INITIALISE, &CSkypeProto::OnUserInfoInit);
return 0;
}
int CSkypeProto::OnPreShutdown(WPARAM, LPARAM)
{
this->SetStatus(ID_STATUS_OFFLINE);
this->UninitNetLib();
this->UninitSkype();
return 0;
}
int CSkypeProto::OnContactDeleted(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
if (hContact && this->IsOnline())
{
if (this->IsChatRoom(hContact))
{
wchar_t *chatID = ::db_get_wsa(hContact, this->m_szModuleName, "ChatRoomID");
this->LeaveChat(chatID);
CConversation::Ref conversation;
this->skype->GetConversationByIdentity(::mir_utf8encodeW(chatID), conversation);
conversation->RetireFrom();
conversation->Delete();
}
else
this->RevokeAuth(wParam, lParam);
}
return 0;
}
int CSkypeProto::OnMessagePreCreate(WPARAM, LPARAM lParam)
{
MessageWindowEvent *evt = (MessageWindowEvent *)lParam;
MessageRef message(evt->seq);
SEBinary guid;
if (message->GetPropGuid(guid))
{
evt->dbei->pBlob = (PBYTE)::mir_realloc(evt->dbei->pBlob, (evt->dbei->cbBlob + 32));
::memcpy(&evt->dbei->pBlob[evt->dbei->cbBlob], guid.data(), 32);
evt->dbei->cbBlob += 32;
}
return 1;
}
void CSkypeProto::OnMessageSended(CConversation::Ref conversation, CMessage::Ref message, CContact::Ref receiver)
{
SEString data;
uint timestamp;
message->GetPropTimestamp(timestamp);
CMessage::SENDING_STATUS sstatus;
message->GetPropSendingStatus(sstatus);
CMessage::CONSUMPTION_STATUS status;
message->GetPropConsumptionStatus(status);
message->GetPropBodyXml(data);
wchar_t *text = ::mir_utf8decodeW(CSkypeProto::RemoveHtml(data));
CConversation::TYPE type;
conversation->GetPropType(type);
if (type == CConversation::DIALOG)
{
HANDLE hContact = this->AddContact(receiver);
//if (sstatus != CMessage::SENDING)
{
this->SendBroadcast(
hContact,
ACKTYPE_MESSAGE,
sstatus == CMessage::FAILED_TO_SEND ? ACKRESULT_FAILED : ACKRESULT_SUCCESS,
(HANDLE)message->getOID(), 0);
SEBinary guid;
message->GetPropGuid(guid);
this->RaiseMessageSendedEvent(
hContact,
timestamp,
guid.data(),
text);
}
}
else
{
receiver->GetIdentity(data);
wchar_t *sid = ::mir_utf8decodeW(data);
conversation->GetPropIdentity(data);
wchar_t *cid = ::mir_utf8decodeW(data);
//this->SendChatMessage(cid, sid, ::mir_utf8decodeA(text));
wchar_t *nick = (wchar_t *)::db_get_wsa(NULL, this->m_szModuleName, "Nick");
if (::wcsicmp(nick, L"") == 0)
{
nick = sid;
}
this->SendChatMessage(
cid,
nick,
text);
::mir_free(sid);
::mir_free(cid);
}
::mir_free(text);
}
void CSkypeProto::OnMessageReceived(CConversation::Ref conversation, CMessage::Ref message, CContact::Ref author)
{
SEString data;
uint timestamp;
message->GetPropTimestamp(timestamp);
CMessage::CONSUMPTION_STATUS status;
message->GetPropConsumptionStatus(status);
message->GetPropBodyXml(data);
wchar_t *text = ::mir_utf8decodeW(CSkypeProto::RemoveHtml(data));
CConversation::TYPE type;
conversation->GetPropType(type);
if (type == CConversation::DIALOG)
{
HANDLE hContact = this->AddContact(author);
SEBinary guid;
message->GetPropGuid(guid);
this->RaiseMessageReceivedEvent(
hContact,
timestamp,
guid.data(),
text,
status != CMessage::UNCONSUMED_NORMAL);
}
else
{
message->GetPropAuthor(data);
wchar_t *sid = ::mir_utf8decodeW(data);
conversation->GetPropIdentity(data);
wchar_t *cid = ::mir_utf8decodeW(data);
this->SendChatMessage(cid, sid, text);
::mir_free(sid);
::mir_free(cid);
}
::mir_free(text);
}
void CSkypeProto::OnTransferChanged(int prop, CTransfer::Ref transfer)
{
if (prop == Transfer::P_STATUS)
{
Transfer::STATUS status;
transfer->GetPropStatus(status);
auto ft = this->FindFileTransfer(transfer);
SEString data;
transfer->GetPropPartnerHandle(data);
mir_ptr<wchar_t> sid(::mir_utf8decodeW(data));
HANDLE hContact = this->GetContactBySid(sid);
switch(status)
{
/*case CTransfer::NEW:
break;*/
/*case CTransfer::WAITING_FOR_ACCEPT:
break;*/
case CTransfer::CONNECTING:
this->SendBroadcast(hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, (HANDLE)ft, 0);
break;
case CTransfer::TRANSFERRING:
case CTransfer::TRANSFERRING_OVER_RELAY:
this->SendBroadcast(hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)ft, 0);
break;
case CTransfer::FAILED:
this->SendBroadcast(hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)ft, 0);
break;
case CTransfer::COMPLETED:
this->SendBroadcast(hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, (HANDLE)ft, 0);
break;
case CTransfer::CANCELLED:
case CTransfer::CANCELLED_BY_REMOTE:
this->SendBroadcast(hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)ft, 0);
break;
}
}
if (prop == Transfer::P_BYTESTRANSFERRED)
{
//PROTOFILETRANSFERSTATUS
//this->SendBroadcast(hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)ccid, 0);
//SEString transferProgressStr;
//transfer->GetPropBytestransferred(transferProgressStr);
//uint transferProgress = transferProgressStr.toUInt();
//SEString fileSizeStr;
//transfer->GetPropFilesize(fileSizeStr);
//// fileSize is float here, to avoid trouble with
//// files lessthan 100 bytes in size.
//float fileSize = (float)fileSizeStr.toUInt();
//float progress = (100 * transferProgress) / fileSize;
//uint transferRate;
//transfer->GetPropBytespersecond(transferRate);
//float transferRateInKb = (float)transferRate / 1024;
//PROTOFILETRANSFERSTATUS pfts = {0};
//pfts.cbSize = sizeof(pfts);
////pfts.szCurrentFile
//pfts.currentFileProgress = progress;
//pfts.
//this->SendBroadcast(hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)ccid, 0);
// printf("Progress: %3.0f%% (%1.0f KB/s)\n", progress, transferRateInKb);
}
}
void CSkypeProto::OnFileReceived(CConversation::Ref conversation, CMessage::Ref message)
{
CTransfer::Refs transferList;
message->GetTransfers(transferList);
Sid::fetch(transferList);
Transfer::TYPE transferType;
Transfer::STATUS transferStatus;
for (uint i = 0; i < transferList.size(); i++)
{
auto transfer = transferList[i];
transfer.fetch();
transfer->SetOnTransferCallback(
(CTransfer::OnTransfer)&CSkypeProto::OnTransferChanged,
this);
//this->transferList.append(transfer);
// For incomings, we need to check for transfer status, just to be sure.
// In some cases, a transfer can appear with STATUS == PLACEHOLDER
// As such transfers cannot be accepted, we will need to just store
// the reference to Transfer Object and then check for further
// status changes in Transfer::OnChange
transfer->GetPropType(transferType);
transfer->GetPropStatus(transferStatus);
if ((transferType == Transfer::INCOMING) && (transferStatus == Transfer::NEW))
{
//transferList[i]->AutoAccept();
SEString name;
transfer->GetPropFilename(name);
wchar_t *path = ::mir_utf8decodeW(name);
SEString data;
transfer->GetPropPartnerHandle(data);
mir_ptr<wchar_t> sid(::mir_utf8decodeW(data));
HANDLE hContact = this->GetContactBySid(sid);
auto ft = new FileTransfer(this);
ft->transfers.append(transfer);
transfer->GetPropChatmsgGuid(ft->guid);
this->fileTransferList.insert(ft);
PROTORECVFILET pre = {0};
pre.flags = PREF_TCHAR;
pre.fileCount = 1;
pre.timestamp = time(NULL);
pre.tszDescription = L" ";
pre.ptszFiles = &path;
pre.lParam = (LPARAM)ft;
::ProtoChainRecvFile(hContact, &pre);
::mir_free(path);
}
}
//SEString bodyXml;
//message->GetPropBodyXml(bodyXml);
//printf("File transfer msg BodyXML:\n%s\n", (const char*)bodyXml);
}
void CSkypeProto::OnMessage(CConversation::Ref conversation, CMessage::Ref message)
{
CMessage::TYPE messageType;
message->GetPropType(messageType);
//CMessage::SENDING_STATUS sendingStatus;
//message->GetPropSendingStatus(sendingStatus);
//CMessage::CONSUMPTION_STATUS status;
//message->GetPropConsumptionStatus(status);
switch (messageType)
{
case CMessage::POSTED_EMOTE:
//int i = 0;
break;
case CMessage::POSTED_TEXT:
{
SEString identity;
message->GetPropAuthor(identity);
wchar_t *sid = ::mir_utf8decodeW(identity);
if (::wcsicmp(sid, this->login) == 0)
{
CParticipant::Refs participants;
conversation->GetParticipants(participants, CConversation::OTHER_CONSUMERS);
participants[0]->GetPropIdentity(identity);
CContact::Ref receiver;
this->skype->GetContact(identity, receiver);
this->OnMessageSended(conversation, message, receiver);
}
else
{
CContact::Ref author;
this->skype->GetContact(identity, author);
this->OnMessageReceived(conversation, message, author);
}
::mir_free(sid);
}
break;
case CMessage::POSTED_FILES:
this->OnFileReceived(conversation, message);
break;
case CMessage::ADDED_CONSUMERS:
{
SEString data;
conversation->GetPropIdentity(data);
wchar_t *cid = ::mir_utf8decodeW(data);
HANDLE hContact = this->GetChatRoomByID(cid);
if ( !hContact || ::db_get_w(hContact, this->m_szModuleName, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
{
SEStringList empty;
this->StartChat(cid, empty);
CParticipant::Refs participants;
conversation->GetParticipants(participants, CConversation::OTHER_CONSUMERS);
for (uint i = 0; i < participants.size(); i++)
{
participants[i]->GetPropIdentity(data);
CContact::Ref contact;
CContact::AVAILABILITY status;
this->skype->GetContact(data, contact);
contact->GetPropAvailability(status);
CParticipant::RANK rank;
participants[i]->GetPropRank(rank);
this->AddChatContact(
cid,
::mir_utf8decodeW(data),
::mir_utf8decodeW(CParticipant::GetRankName(rank)),
status);
}
}
{
message->GetPropIdentities(data);
StringList alreadyInChat(this->GetChatUsers(cid), " ");
StringList needToAdd(data, " ");
for (int i = 0; i < needToAdd.getCount(); i++)
{
char *sid = needToAdd[i];
if (::wcsicmp(::mir_a2u(sid), this->login) != 0 && !alreadyInChat.contains(sid))
{
CContact::Ref contact;
CContact::AVAILABILITY status;
this->skype->GetContact(sid, contact);
contact->GetPropAvailability(status);
//todo: fix rank
this->AddChatContact(
cid,
::mir_a2u(sid),
::mir_utf8decodeW(CParticipant::GetRankName(CParticipant::WRITER)),
status);
}
}
}
}
break;
case CMessage::RETIRED:
{
SEString data;
conversation->GetPropIdentity(data);
wchar_t *cid = ::mir_utf8decodeW(data);
StringList alreadyInChat(this->GetChatUsers(cid), " ");
message->GetPropAuthor(data);
wchar_t *sid = ::mir_utf8decodeW(data);
if (::wcsicmp(sid, this->login) != 0)
if (alreadyInChat.contains(::mir_u2a(sid)))
this->RemoveChatContact(cid, sid);
}
break;
case CMessage::RETIRED_OTHERS:
{
SEString data;
conversation->GetPropIdentity(data);
wchar_t *cid = ::mir_utf8decodeW(data);
message->GetPropIdentities(data);
StringList alreadyInChat(this->GetChatUsers(cid), " ");
StringList needToKick(data, " ");
for (int i = 0; i < needToKick.getCount(); i++)
{
wchar_t *sid = ::mir_utf8decodeW(needToKick[i]);
if (::wcsicmp(sid, this->login) != 0 && !alreadyInChat.contains(::mir_u2a(sid)))
this->KickChatContact(cid, sid);
}
}
break;
case CMessage::SPAWNED_CONFERENCE:
{
SEString data;
conversation->GetPropIdentity(data);
char *cid = ::mir_strdup(data);
/*HANDLE hContact = this->GetChatRoomByID(cid);
if ( !hContact || ::DBGetContactSettingWord(hContact, this->m_szModuleName, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
{
this->JoinChat(cid);
}*/
}
break;
case CMessage::STARTED_LIVESESSION:
//conversation->LeaveLiveSession();
uint timestamp;
message->GetPropTimestamp(timestamp);
SEString identity;
message->GetPropAuthor(identity);
CContact::Ref author;
this->skype->GetContact(identity, author);
HANDLE hContact = this->AddContact(author);
wchar_t *message = new wchar_t[14];
::wcscpy(message, L"Incoming call");
this->AddDataBaseEvent(
hContact,
SKYPE_DB_EVENT_TYPE_CALL,
timestamp,
DBEF_UTF,
::wcslen(message) + 1,
(PBYTE)message);
break;
//case CMessage::REQUESTED_AUTH:
// break;
//case CMessage::GRANTED_AUTH:
// break;
//case CMessage::BLOCKED:
// break;
}
}
|