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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
|
#include "skype_proto.h"
void CSkypeProto::UpdateContactAboutText(HANDLE hContact, CContact::Ref contact)
{
SEString data;
contact->GetPropAbout(data);
wchar_t* aboutText = ::mir_utf8decodeW((const char*)data);
if (wcscmp(aboutText, L"") == 0)
this->DeleteSetting(hContact, "About");
else
this->SetSettingString(hContact, "About", aboutText);
::mir_free(aboutText);
}
void CSkypeProto::UpdateContactAuthState(HANDLE hContact, CContact::Ref contact)
{
uint newTS = 0;
contact->GetPropAuthreqTimestamp(newTS);
DWORD oldTS = this->GetSettingDword(hContact, "AuthTS");
if (newTS > oldTS)
{
CContact::AVAILABILITY data;
contact->GetPropAvailability(data);
this->SetSettingWord(hContact, SKYPE_SETTINGS_STATUS, this->SkypeToMirandaStatus(data));
if (data == CContact::PENDINGAUTH)
this->SetSettingWord(hContact, "Auth", 1);
else
this->DeleteSetting(hContact, "Auth");
this->SetSettingDword(hContact, "AuthTS", newTS);
}
}
void CSkypeProto::UpdateContactAvatar(HANDLE hContact, CContact::Ref contact)
{
uint newTS = 0;
contact->GetPropAvatarTimestamp(newTS);
DWORD oldTS = this->GetSettingDword(hContact, "AvatarTS");
if (newTS > oldTS)
{
SEBinary data;
contact->GetPropAvatarImage(data);
if (data.size() > 0)
{
wchar_t* path = this->GetAvatarFilePath(this->GetSettingString(hContact, "sid"));
FILE* fp = _wfopen(path, L"w");
if (fp)
{
for (uint i = 0; i < data.size(); i++)
{
if (i)
fputc(',', fp);
fputc('\'', fp);
switch(data[i])
{
case '\n':
fputc('\\', fp);
fputc('n', fp);
break;
default:
fputc(data[i], fp);
}
}
CloseHandle(fp);
}
}
// todo: need to register avatar to contact
this->SetSettingDword(hContact, "AvatarTS", newTS);
}
}
void CSkypeProto::UpdateContactBirthday(HANDLE hContact, CContact::Ref contact)
{
uint data;
contact->GetPropBirthday(data);
if (data > 0)
{
struct tm* ptm;
time_t timeGMT = (time_t)data;
ptm = gmtime(&timeGMT);
this->SetSettingByte(hContact, "BirthDay", ptm->tm_mday);
this->SetSettingByte(hContact, "BirthMonth", ptm->tm_mon);
// todo: fix stupid year constant
this->SetSettingWord(hContact, "BirthYear", ptm->tm_year + 1917);
}
else
{
this->DeleteSetting(hContact, "BirthDay");
this->DeleteSetting(hContact, "BirthMonth");
this->DeleteSetting(hContact, "BirthYear");
}
}
void CSkypeProto::UpdateContactCity(HANDLE hContact, CContact::Ref contact)
{
SEString data;
contact->GetPropCity(data);
wchar_t* city = ::mir_a2u((const char*)data);
if (wcscmp(city, L"") == 0)
this->DeleteSetting(hContact, "City");
else
this->SetSettingString(hContact, "City", city);
::mir_free(city);
}
void CSkypeProto::UpdateContactCountry(HANDLE hContact, CContact::Ref contact)
{
// country (en, ru, etc)
SEString data;
contact->GetPropCountry(data);
// todo: write me
//BYTE countryId = this->GetCountryIdByName((const char*)sData);
//this->SetSettingByte(hContact, "Country", countryId);
}
void CSkypeProto::UpdateContactEmails(HANDLE hContact, CContact::Ref contact)
{
SEString data;
contact->GetPropEmails(data);
wchar_t* emails = ::mir_a2u((const char*)data);
if (wcscmp(emails, L"") == 0)
{
this->DeleteSetting(hContact, "e-mail0");
this->DeleteSetting(hContact, "e-mail1");
this->DeleteSetting(hContact, "e-mail2");
}
else
{
wchar_t* p = wcstok(emails, L" ");
if (p == NULL)
{
this->SetSettingString(hContact, "e-mail0", emails);
}
else
{
this->SetSettingString(hContact, "e-mail0", p);
p = wcstok(NULL, L" ");
if (p) this->SetSettingString(hContact, "e-mail1", p);
p = wcstok(NULL, L" ");
if (p) this->SetSettingString(hContact, "e-mail2", p);
}
}
::mir_free(emails);
}
void CSkypeProto::UpdateContactGender(HANDLE hContact, CContact::Ref contact)
{
uint data;
contact->GetPropGender(data);
if (data)
this->SetSettingByte(hContact, "Gender", (BYTE)(data == 1 ? 'M' : 'F'));
else
this->DeleteSetting(hContact, "Gender");
}
void CSkypeProto::UpdateContactHomepage(HANDLE hContact, CContact::Ref contact)
{
SEString data;
contact->GetPropHomepage(data);
wchar_t* homepage = ::mir_a2u((const char*)data);
if (wcscmp(homepage, L"") == 0)
this->DeleteSetting(hContact, "Homepage");
else
this->SetSettingString(hContact, "Homepage", homepage);
::mir_free(homepage);
}
void CSkypeProto::UpdateContactLanguages(HANDLE hContact, CContact::Ref contact)
{
// sanguages (en, ru, etc), space searated
SEString data;
contact->GetPropLanguages(data);
// todo: write me
}
void CSkypeProto::UpdateContactMobilePhone(HANDLE hContact, CContact::Ref contact)
{
SEString data;
contact->GetPropPhoneMobile(data);
wchar_t* phone = ::mir_a2u((const char*)data);
if (wcscmp(phone, L"") == 0)
this->DeleteSetting(hContact, "Cellular");
else
this->SetSettingString(hContact, "Cellular", phone);
::mir_free(phone);
}
void CSkypeProto::UpdateContactPhone(HANDLE hContact, CContact::Ref contact)
{
SEString data;
contact->GetPropPhoneHome(data);
wchar_t* phone = ::mir_a2u((const char*)data);
if (wcscmp(phone, L"") == 0)
this->DeleteSetting(hContact, "Phone");
else
this->SetSettingString(hContact, "Phone", phone);
::mir_free(phone);
}
void CSkypeProto::UpdateContactOfficePhone(HANDLE hContact, CContact::Ref contact)
{
SEString data;
contact->GetPropPhoneOffice(data);
wchar_t* phone = ::mir_a2u((const char*)data);
if (wcscmp(phone, L"") == 0)
this->DeleteSetting(hContact, "CompanyPhone");
else
this->SetSettingString(hContact, "CompanyPhone", phone);
::mir_free(phone);
}
void CSkypeProto::UpdateContactState(HANDLE hContact, CContact::Ref contact)
{
SEString data;
contact->GetPropProvince(data);
wchar_t* state = ::mir_a2u((const char*)data);
if (wcscmp(state, L"") == 0)
this->DeleteSetting(hContact, "State");
else
this->SetSettingString(hContact, "State", state);
::mir_free(state);
}
void CSkypeProto::UpdateContactStatus(HANDLE hContact, CContact::Ref contact)
{
CContact::AVAILABILITY availability;
contact->GetPropAvailability(availability);
this->SetSettingWord(hContact, SKYPE_SETTINGS_STATUS, this->SkypeToMirandaStatus(availability));
}
void CSkypeProto::UpdateContactStatusMessage(HANDLE hContact, CContact::Ref contact)
{
uint newTS = 0;
contact->GetPropMoodTimestamp(newTS);
DWORD oldTS = this->GetSettingDword(hContact, "XStatusTS");
if (newTS > oldTS)
{
SEString data;
contact->GetPropMoodText(data);
wchar_t* status = ::mir_utf8decodeW((const char*)data);
if (wcscmp(status, L"") == 0)
this->DeleteSetting(hContact, "XStatusMsg");
else
this->SetSettingString(hContact, "XStatusMsg", status);
::mir_free(status);
this->SetSettingDword(hContact, "XStatusTS", newTS);
}
}
void CSkypeProto::UpdateContactTimezone(HANDLE hContact, CContact::Ref contact)
{
uint data;
contact->GetPropTimezone(data);
// todo: check me
if (data > 0)
this->SetSettingByte(hContact, "TimeZone", (data - 24*3600) / 3600);
else
this->DeleteSetting(hContact, "TimeZone");
}
void CSkypeProto::UpdateContactProfile(HANDLE hContact, CContact::Ref contact)
{
uint newTS = 0;
contact->GetPropProfileTimestamp(newTS);
DWORD oldTS = this->GetSettingDword(hContact, "ProfileTS");
if (newTS > oldTS)
{
this->UpdateContactAboutText(hContact, contact);
this->UpdateContactBirthday(hContact, contact);
this->UpdateContactCity(hContact, contact);
this->UpdateContactCountry(hContact, contact);
this->UpdateContactEmails(hContact, contact);
this->UpdateContactGender(hContact, contact);
this->UpdateContactHomepage(hContact, contact);
this->UpdateContactLanguages(hContact, contact);
this->UpdateContactMobilePhone(hContact, contact);
this->UpdateContactPhone(hContact, contact);
this->UpdateContactOfficePhone(hContact, contact);
this->UpdateContactState(hContact, contact);
this->UpdateContactTimezone(hContact, contact);
this->SetSettingDword(hContact, "ProfileTS", newTS);
}
}
void CSkypeProto::OnContactChanged(CContact::Ref contact, int prop)
{
SEString data;
contact->GetPropSkypename(data);
wchar_t* sid = ::mir_a2u((const char*)data);
HANDLE hContact = this->GetContactBySid(sid);
if (hContact)
{
switch(prop)
{
case CContact::P_ABOUT:
this->UpdateContactAboutText(hContact, contact);
break;
case CContact::P_AUTHREQ_TIMESTAMP:
{
uint newTS = 0;
contact->GetPropAuthreqTimestamp(newTS);
DWORD oldTS = this->GetSettingDword(hContact, "AuthTS");
if (newTS > oldTS)
{
char* sid = ::mir_utf8decodeA((const char*)data);
contact->GetPropDisplayname(data);
char* nick = ::mir_utf8decodeA((const char*)data);
contact->GetPropReceivedAuthrequest(data);
char* reason = ::mir_utf8decodeA((const char*)data);
contact->GetPropFullname(data);
char* fullname = ::mir_utf8decodeA((const char*)data);
char* first = strtok(fullname, " ");
char* last = strtok(NULL, " ");
if (last == NULL)
{
last = "";
}
this->RaiseAuthRequestEvent(newTS, sid, nick, first, last, reason);
}
}
break;
case CContact::P_AUTHREQUEST_COUNT:
// todo: all authrequests after first should be catch here
this->UpdateContactAuthState(hContact, contact);
break;
case CContact::P_AVAILABILITY:
this->UpdateContactStatus(hContact, contact);
break;
case CContact::P_AVATAR_IMAGE:
case CContact::P_AVATAR_TIMESTAMP:
this->UpdateContactAvatar(hContact, contact);
break;
case CContact::P_BIRTHDAY:
this->UpdateContactBirthday(hContact, contact);
break;
case CContact::P_CITY:
this->UpdateContactCity(hContact, contact);
break;
case CContact::P_COUNTRY:
this->UpdateContactCountry(hContact, contact);
break;
case CContact::P_EMAILS:
this->UpdateContactEmails(hContact, contact);
break;
case CContact::P_GENDER:
this->UpdateContactGender(hContact, contact);
break;
case CContact::P_HOMEPAGE:
this->UpdateContactHomepage(hContact, contact);
break;
case CContact::P_LANGUAGES:
this->UpdateContactLanguages(hContact, contact);
break;
case CContact::P_MOOD_TEXT:
case CContact::P_MOOD_TIMESTAMP:
this->UpdateContactStatusMessage(hContact, contact);
break;
case CContact::P_PHONE_HOME:
this->UpdateContactPhone(hContact, contact);
break;
case CContact::P_PHONE_MOBILE:
this->UpdateContactMobilePhone(hContact, contact);
break;
case CContact::P_PHONE_OFFICE:
this->UpdateContactOfficePhone(hContact, contact);
break;
case CContact::P_PROFILE_TIMESTAMP:
this->UpdateContactProfile(hContact, contact);
break;
case CContact::P_PROVINCE:
this->UpdateContactState(hContact, contact);
break;
case CContact::P_TIMEZONE:
this->UpdateContactTimezone(hContact, contact);
break;
}
}
else
{
}
//else
//{
// switch(prop)
// {
// case CContact::P_RECEIVED_AUTHREQUEST:
// contact->GetPropDisplayname(data);
// wchar_t* displayName = ::mir_a2u((const char*)data);
// CCSDATA ccs = {0};
// ccs.szProtoService = PSR_AUTH;
// ccs.hContact = this->AddContactBySkypeName(skypeName, displayName, PALF_TEMPORARY);
// //pre.szMessage = (LPSTR)btBuff;
// //CreateBlobFromContact(ccs.hContact, lpwszMessage, dwMessageSize, btBuff, SIZEOF(btBuff), (size_t*)&pre.lParam);
// CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&ccs);
// break;
// }
//}
//if (prop == CContact::P_AVAILABILITY)
//{
// SEString data;
// contact->GetPropSkypename(data);
// wchar_t* skypeName = ::mir_a2u((const char*)data);
// HANDLE hContact = this->GetContactBySkypeName(skypeName);
// if (hContact)
// {
// CContact::AVAILABILITY availability;
// contact->GetPropAvailability(availability);
// this->SetSettingWord(hContact, SKYPE_SETTINGS_STATUS, this->SkypeToMirandaStatus(availability));
// if (availability == CContact::PENDINGAUTH)
// this->SetSettingWord(hContact, "Auth", 1);
// else
// this->DeleteSetting(hContact, "Auth");
// }
//}
}
void CSkypeProto::OnContactListChanged(const ContactRef& contact)
{
bool result;
contact->IsMemberOfHardwiredGroup(CContactGroup::ALL_BUDDIES, result);
if (result)
{
if ( !this->contactList.contains(contact))
{
CContact::Ref newContact(contact);
this->contactList.append(newContact);
newContact.fetch();
newContact->SetOnContactChangedCallback(
(CContact::OnContactChanged)&CSkypeProto::OnContactChanged,
this);
}
}
contact->IsMemberOfHardwiredGroup(CContactGroup::CONTACTS_WAITING_MY_AUTHORIZATION, result);
if (result)
{
SEString data;
uint newTS = 0;
contact->GetPropAuthreqTimestamp(newTS);
contact->GetPropSkypename(data);
char* sid = ::mir_utf8decodeA((const char*)data);
contact->GetPropDisplayname(data);
char* nick = ::mir_utf8decodeA((const char*)data);
contact->GetPropReceivedAuthrequest(data);
char* reason = ::mir_utf8decodeA((const char*)data);
contact->GetPropFullname(data);
char* fullname = ::mir_utf8decodeA((const char*)data);
char* first = strtok(fullname, " ");
char* last = strtok(NULL, " ");
if (last == NULL)
{
last = "";
}
this->RaiseAuthRequestEvent(newTS, sid, nick, first, last, reason);
}
}
bool CSkypeProto::IsProtoContact(HANDLE hContact)
{
return ::CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)this->m_szModuleName) < 0;
}
HANDLE CSkypeProto::GetContactBySid(const wchar_t* sid)
{
HANDLE hContact = (HANDLE)::CallService(MS_DB_CONTACT_FINDFIRST, 0, (LPARAM)this->m_szModuleName);
while (hContact)
{
if (this->IsProtoContact(hContact))
{
if (::wcscmp(sid, this->GetSettingString(hContact, "sid", L"")) == 0)
return hContact;
}
hContact = (HANDLE)::CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, (LPARAM)this->m_szModuleName);
}
return 0;
}
HANDLE CSkypeProto::GetContactFromAuthEvent(HANDLE hEvent)
{
DWORD body[3];
DBEVENTINFO dbei = { sizeof(DBEVENTINFO) };
dbei.cbBlob = sizeof(DWORD) * 2;
dbei.pBlob = (PBYTE)&body;
if (::CallService(MS_DB_EVENT_GET, (WPARAM)hEvent, (LPARAM)&dbei))
return INVALID_HANDLE_VALUE;
if (dbei.eventType != EVENTTYPE_AUTHREQUEST)
return INVALID_HANDLE_VALUE;
if (strcmp(dbei.szModule, this->m_szModuleName) != 0)
return INVALID_HANDLE_VALUE;
return ::DbGetAuthEventContact(&dbei);
}
HANDLE CSkypeProto::AddContactBySid(const wchar_t* sid, const wchar_t* nick, DWORD flags)
{
HANDLE hContact = this->GetContactBySid(sid);
if ( !hContact)
{
hContact = (HANDLE)::CallService(MS_DB_CONTACT_ADD, 0, 0);
::CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)this->m_szModuleName);
this->SetSettingString(hContact, "sid", sid);
this->SetSettingString(hContact, "Nick", nick);
//::DBWriteContactSettingWString(hContact, "CList", "MyHandle", displayName);
if (flags & PALF_TEMPORARY)
{
::DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1);
::DBWriteContactSettingByte(hContact, "CList", "Hidden", 1);
}
}
else
{
if ( !(flags & PALF_TEMPORARY))
::DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1);
}
return hContact;
}
int CSkypeProto::SkypeToMirandaStatus(CContact::AVAILABILITY availability)
{
int status = ID_STATUS_OFFLINE;
switch (availability)
{
case CContact::ONLINE:
case CContact::ONLINE_FROM_MOBILE:
status = ID_STATUS_ONLINE;
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;
}
return status;
}
void CSkypeProto::RemoveContact(HANDLE hContact)
{
if (this->IsOnline() && hContact)
{
CContact::Ref contact;
SEString sid(::mir_u2a(this->GetSettingString(hContact, "sid")));
if (g_skype->GetContact(sid, contact))
{
contact->SetBuddyStatus(false);
this->contactList.remove_val(contact);
}
}
}
CContact::AVAILABILITY CSkypeProto::MirandaToSkypeStatus(int status)
{
CContact::AVAILABILITY availability = CContact::UNKNOWN;
switch(this->m_iStatus)
{
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;
}
void __cdecl CSkypeProto::LoadContactList(void*)
{
g_skype->GetHardwiredContactGroup(CContactGroup::ALL_BUDDIES, this->commonList);
this->commonList.fetch();
this->commonList->SetOnContactListChangedCallback(
(CContactGroup::OnContactListChanged)&CSkypeProto::OnContactListChanged,
this);
this->commonList->GetContacts(this->contactList);
Sid::fetch(this->contactList);
for (unsigned int i = 0; i < this->contactList.size(); i++)
{
CContact::Ref contact = this->contactList[i];
contact->SetOnContactChangedCallback(
(CContact::OnContactChanged)&CSkypeProto::OnContactChanged,
this);
SEString data;
contact->GetPropSkypename(data);
wchar_t* sid = ::mir_utf8decodeW((const char*)data);
contact->GetPropDisplayname(data);
wchar_t* nick = ::mir_utf8decodeW((const char*)data);
contact->GetPropFullname(data);
wchar_t* name = ::mir_utf8decodeW((const char*)data);
DWORD flags = 0;
CContact::AVAILABILITY availability;
contact->GetPropAvailability(availability);
if (availability == CContact::PENDINGAUTH)
flags = PALF_TEMPORARY;
HANDLE hContact = this->AddContactBySid(sid, nick, flags);
this->UpdateContactAuthState(hContact, contact);
this->UpdateContactAvatar(hContact, contact);
this->UpdateContactProfile(hContact, contact);
this->UpdateContactStatus(hContact, contact);
this->UpdateContactStatusMessage(hContact, contact);
}
// raise auth event for all non auth contacts
CContact::Refs authContacts;
g_skype->GetHardwiredContactGroup(CContactGroup::CONTACTS_WAITING_MY_AUTHORIZATION, this->authWaitList);
this->authWaitList.fetch();
this->authWaitList->SetOnContactListChangedCallback(
(CContactGroup::OnContactListChanged)&CSkypeProto::OnContactListChanged,
this);
this->authWaitList->GetContacts(authContacts);
//Sid::fetch(this->contactList);
for (unsigned int i = 0; i < authContacts.size(); i++)
{
CContact::Ref contact = authContacts[i];
/*contact->SetOnContactChangedCallback(
(CContact::OnContactChanged)&CSkypeProto::OnContactChanged,
this);*/
SEString data;
uint newTS = 0;
contact->GetPropAuthreqTimestamp(newTS);
contact->GetPropSkypename(data);
char* sid = ::mir_utf8decodeA((const char*)data);
contact->GetPropDisplayname(data);
char* nick = ::mir_utf8decodeA((const char*)data);
contact->GetPropReceivedAuthrequest(data);
char* reason = ::mir_utf8decodeA((const char*)data);
contact->GetPropFullname(data);
char* fullname = ::mir_utf8decodeA((const char*)data);
char* first = strtok(fullname, " ");
char* last = strtok(NULL, " ");
if (last == NULL) last = "";
this->RaiseAuthRequestEvent(newTS, sid, nick, first, last, reason);
}
}
void CSkypeProto::SetAllContactStatus(int status)
{
HANDLE hContact = (HANDLE)::CallService(MS_DB_CONTACT_FINDFIRST, 0, (LPARAM)this->m_szModuleName);
while (hContact)
{
if (this->IsProtoContact(hContact))
//if ( !this->GetSettingWord(hContact, SKYPE_SETTINGS_STATUS, ID_STATUS_OFFLINE) == status)
this->SetSettingWord(hContact, SKYPE_SETTINGS_STATUS, status);
hContact = (HANDLE)::CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, (LPARAM)this->m_szModuleName);
}
}
void CSkypeProto::OnSearchCompleted(HANDLE hSearch)
{
this->SendBroadcast(ACKTYPE_SEARCH, ACKRESULT_SUCCESS, hSearch, 0);
}
void CSkypeProto::OnContactFinded(HANDLE hSearch, CContact::Ref contact)
{
PROTOSEARCHRESULT isr = {0};
isr.cbSize = sizeof(isr);
isr.flags = PSR_TCHAR;
SEString data;
contact->GetPropSkypename(data);
isr.id = ::mir_utf8decodeW((const char *)data);
contact->GetPropDisplayname(data);
isr.nick = ::mir_utf8decodeW((const char *)data);
{
contact->GetPropFullname(data);
wchar_t *fullname = ::mir_utf8decodeW((const char*)data);
wchar_t *first = wcstok(fullname, L" ");
wchar_t *last = wcstok(NULL, L" ");
if (last != NULL)
{
last = L"";
}
isr.firstName = first;
isr.lastName = last;
}
{
contact->GetPropEmails(data);
wchar_t *emails = ::mir_utf8decodeW((const char*)data);
wchar_t* main = wcstok(emails, L" ");
if (main != NULL)
{
isr.email = main;
}
}
this->SendBroadcast(ACKTYPE_SEARCH, ACKRESULT_DATA, hSearch, (LPARAM)&isr);
}
void __cdecl CSkypeProto::SearchBySidAsync(void* arg)
{
const wchar_t *sid = (wchar_t *)arg;
HANDLE hContact = this->GetContactBySid(sid);
if (hContact)
{
this->ShowNotification(sid, _T("Contact already in your contact list"), 0);
this->SendBroadcast(ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)SKYPE_SEARCH_BYSID, 0);
return;
}
CContactSearch::Ref search;
g_skype->CreateIdentitySearch(::mir_u2a(sid), search);
search.fetch();
search->SetProtoInfo(this, (HANDLE)SKYPE_SEARCH_BYSID);
search->SetOnContactFindedCallback(
(CContactSearch::OnContactFinded)&CSkypeProto::OnContactFinded);
search->SetOnSearchCompleatedCallback(
(CContactSearch::OnSearchCompleted)&CSkypeProto::OnSearchCompleted);
bool valid;
if (!search->IsValid(valid) || !valid || !search->Submit())
{
return;
}
search->BlockWhileSearch();
search->Release();
}
void __cdecl CSkypeProto::SearchByEmailAsync(void* arg)
{
const wchar_t *email = (wchar_t *)arg;
CContactSearch::Ref search;
g_skype->CreateContactSearch(search);
search.fetch();
search->SetProtoInfo(this, (HANDLE)SKYPE_SEARCH_BYEMAIL);
search->SetOnContactFindedCallback(
(CContactSearch::OnContactFinded)&CSkypeProto::OnContactFinded);
search->SetOnSearchCompleatedCallback(
(CContactSearch::OnSearchCompleted)&CSkypeProto::OnSearchCompleted);
bool valid;
if (!search->AddEmailTerm(::mir_u2a(email), valid) || !valid || !search->Submit())
{
return;
}
search->BlockWhileSearch();
search->Release();
}
void __cdecl CSkypeProto::SearchByNamesAsync(void* arg)
{
}
|