From f94f16702b87c3c876096723f8e6ad94d63847aa Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 6 May 2013 16:07:39 +0000 Subject: more mem leaks git-svn-id: http://svn.miranda-ng.org/main/trunk@4593 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Skype/src/skype_avatars.cpp | 38 ++--- protocols/Skype/src/skype_chat.cpp | 292 ++++++++++++++------------------- protocols/Skype/src/skype_contacts.cpp | 35 ++-- protocols/Skype/src/skype_dialogs.cpp | 17 +- protocols/Skype/src/skype_events.cpp | 17 +- protocols/Skype/src/skype_profile.cpp | 40 ++--- protocols/Skype/src/skype_proto.h | 8 +- 7 files changed, 175 insertions(+), 272 deletions(-) diff --git a/protocols/Skype/src/skype_avatars.cpp b/protocols/Skype/src/skype_avatars.cpp index 9e53ff1485..27bf4a5dd0 100644 --- a/protocols/Skype/src/skype_avatars.cpp +++ b/protocols/Skype/src/skype_avatars.cpp @@ -62,9 +62,8 @@ wchar_t * CSkypeProto::GetContactAvatarFilePath(HANDLE hContact) if (m_hAvatarsFolder == NULL || FoldersGetCustomPathT(m_hAvatarsFolder, path, MAX_PATH, _T(""))) { - wchar_t *tmpPath = ::Utils_ReplaceVarsT(L"%miranda_avatarcache%"); + mir_ptr tmpPath( ::Utils_ReplaceVarsT(L"%miranda_avatarcache%")); ::mir_sntprintf(path, MAX_PATH, _T("%s\\%S"), tmpPath, this->m_szModuleName); - ::mir_free(tmpPath); } DWORD dwAttributes = GetFileAttributes(path); @@ -97,15 +96,13 @@ INT_PTR __cdecl CSkypeProto::GetAvatarInfo(WPARAM, LPARAM lParam) mir_ptr sid = ::db_get_wsa(pai->hContact, this->m_szModuleName, SKYPE_SETTINGS_LOGIN); if (sid) { - wchar_t *path = this->GetContactAvatarFilePath(pai->hContact); + mir_ptr path( this->GetContactAvatarFilePath(pai->hContact)); if (path && !_waccess(path, 0)) { ::wcsncpy(pai->filename, path, SIZEOF(pai->filename)); pai->format = PA_FORMAT_JPEG; return GAIR_SUCCESS; } - - ::mir_free(path); } return GAIR_NOAVATAR; @@ -159,11 +156,10 @@ INT_PTR __cdecl CSkypeProto::GetMyAvatar(WPARAM wParam, LPARAM lParam) if (!wParam) return -2; - wchar_t *path = this->GetContactAvatarFilePath(NULL); + mir_ptr path( this->GetContactAvatarFilePath(NULL)); if (path && CSkypeProto::FileExists(path)) { ::wcsncpy((wchar_t *)wParam, path, (int)lParam); - ::mir_free(path); return 0; } @@ -173,57 +169,49 @@ INT_PTR __cdecl CSkypeProto::GetMyAvatar(WPARAM wParam, LPARAM lParam) INT_PTR __cdecl CSkypeProto::SetMyAvatar(WPARAM, LPARAM lParam) { wchar_t *path = (wchar_t *)lParam; - int iRet = -1; - if (path) { - wchar_t *avatarPath = this->GetContactAvatarFilePath(NULL); + mir_ptr avatarPath( this->GetContactAvatarFilePath(NULL)); if ( !::wcscmp(path, avatarPath)) { this->Log(L"New avatar path are same with old."); - return iRet; + return -1; } SEBinary avatar = this->GetAvatarBinary(path); if (avatar.size() == 0) { this->Log(L"Failed to read avatar file."); - return iRet; + return -1; } if (this->IsAvatarChanged(avatar)) { this->Log(L"New avatar are same with old."); - return iRet; + return -1; } if ( !::CopyFile(path, avatarPath, FALSE)) { this->Log(L"Failed to copy new avatar to local storage."); - return iRet; + return -1; } Skype::VALIDATERESULT result = Skype::NOT_VALIDATED; if (!this->account->SetAvatar(avatar, result)) { this->Log(CSkypeProto::ValidationReasons[result]); - return iRet; + return -1; } uint newTS = this->account->GetUintProp(Account::P_AVATAR_IMAGE); ::db_set_dw(NULL, this->m_szModuleName, "AvatarTS", newTS); - iRet = 0; - - ::mir_free(avatarPath); - } - else - { - this->account->SetBinProperty(Account::P_AVATAR_IMAGE, SEBinary()); - ::db_unset(NULL, this->m_szModuleName, "AvatarTS"); - iRet = 0; + return 0; } - return iRet; + this->account->SetBinProperty(Account::P_AVATAR_IMAGE, SEBinary()); + ::db_unset(NULL, this->m_szModuleName, "AvatarTS"); + return 0; } SEBinary CSkypeProto::GetAvatarBinary(wchar_t *path) diff --git a/protocols/Skype/src/skype_chat.cpp b/protocols/Skype/src/skype_chat.cpp index 00926950b5..742786a3a6 100644 --- a/protocols/Skype/src/skype_chat.cpp +++ b/protocols/Skype/src/skype_chat.cpp @@ -33,7 +33,7 @@ HANDLE CSkypeProto::GetChatRoomByCid(const wchar_t *cid) if (this->IsProtoContact(hContact) && this->IsChatRoom(hContact)) { mir_ptr chatID(::db_get_wsa(hContact, this->m_szModuleName, "ChatRoomID")); - if (::wcscmp(cid, chatID) == 0) + if ( lstrcmp(cid, chatID) == 0) return hContact; } @@ -168,10 +168,10 @@ void CSkypeProto::CreateChatWindow(CConversation::Ref conversation, bool showWin SEString data; conversation->GetPropIdentity(data); - wchar_t *cid = ::mir_utf8decodeW(data); + mir_ptr cid( ::mir_utf8decodeW(data)); conversation->GetPropDisplayname(data); - wchar_t *chatName = ::mir_utf8decodeW(data); + mir_ptr chatName( ::mir_utf8decodeW(data)); GCSESSION gcw = {0}; gcw.cbSize = sizeof(gcw); @@ -198,9 +198,6 @@ void CSkypeProto::CreateChatWindow(CConversation::Ref conversation, bool showWin gcd.iType = GC_EVENT_CONTROL; ::CallServiceSync(MS_GC_EVENT, showWindow ? SESSION_INITDONE : WINDOW_HIDDEN, (LPARAM)&gce); ::CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce); - - ::mir_free(cid); - ::mir_free(chatName); } CConversation::Ref CSkypeProto::StartChat(StringList &invitedContacts) @@ -250,7 +247,7 @@ void CSkypeProto::InviteConactsToChat(CConversation::Ref conversation, const Str SEString data; conversation->GetPropIdentity(data); - wchar_t *cid = ::mir_utf8decodeW(data); + mir_ptr cid( ::mir_utf8decodeW(data)); InviteChatParam *param = new InviteChatParam(cid, invitedContacts, this); @@ -269,8 +266,6 @@ void CSkypeProto::InviteConactsToChat(CConversation::Ref conversation, const Str } delete param; - - ::mir_free(cid); } void CSkypeProto::JoinToChat(CConversation::Ref conversation, bool showWindow) @@ -280,7 +275,7 @@ void CSkypeProto::JoinToChat(CConversation::Ref conversation, bool showWindow) SEString data; conversation->GetPropIdentity(data); - wchar_t *cid = ::mir_utf8decodeW(data); + mir_ptr cid( ::mir_utf8decodeW(data)); this->CreateChatWindow(conversation, showWindow); @@ -306,8 +301,6 @@ void CSkypeProto::JoinToChat(CConversation::Ref conversation, bool showWindow) CSkypeProto::Roles[rank], CSkypeProto::SkypeToMirandaStatus(status)); } - - ::mir_free(cid); } void CSkypeProto::AddConactsToChat(CConversation::Ref conversation, const StringList &invitedContacts) @@ -348,7 +341,7 @@ void CSkypeProto::AddConactsToChat(CConversation::Ref conversation, const String void CSkypeProto::LeaveChat(const wchar_t *cid) { - wchar_t *chatID = ::mir_wstrdup(cid); + mir_ptr chatID( ::mir_wstrdup(cid)); GCDEST gcd = { m_szModuleName, { NULL }, GC_EVENT_CONTROL }; gcd.ptszID = chatID; @@ -359,16 +352,14 @@ void CSkypeProto::LeaveChat(const wchar_t *cid) gce.pDest = &gcd; ::CallServiceSync(MS_GC_EVENT, SESSION_OFFLINE, (LPARAM)&gce); ::CallServiceSync(MS_GC_EVENT, SESSION_TERMINATE, (LPARAM)&gce); - - ::mir_free(chatID); } void CSkypeProto::RaiseChatEvent(const wchar_t *cid, const wchar_t *sid, int evt, DWORD flags, DWORD itemData, const wchar_t *status, const wchar_t *message) { HANDLE hContact = this->GetContactBySid(sid); - wchar_t *nick = hContact ? + mir_ptr nick( hContact ? ::mir_a2u((char *)::CallService(MS_CLIST_GETCONTACTDISPLAYNAME, WPARAM(hContact), 0)) : - ::mir_wstrdup(sid); + ::mir_wstrdup(sid)); GCDEST gcd = { this->m_szModuleName, { NULL }, evt }; gcd.ptszID = ::mir_wstrdup(cid); @@ -385,8 +376,6 @@ void CSkypeProto::RaiseChatEvent(const wchar_t *cid, const wchar_t *sid, int evt gce.ptszText = message; gce.time = time(NULL); ::CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); - - ::mir_free(nick); } void CSkypeProto::SendChatMessage(const wchar_t *cid, const wchar_t *sid, const wchar_t *message) @@ -449,94 +438,79 @@ int __cdecl CSkypeProto::OnGCEventHook(WPARAM, LPARAM lParam) if (::strcmp(gch->pDest->pszModule, this->m_szModuleName)) return 0; - wchar_t *cid = ::mir_wstrdup(gch->pDest->ptszID); - wchar_t *sid = ::mir_wstrdup(gch->ptszUID); + mir_ptr cid( ::mir_wstrdup(gch->pDest->ptszID)); + mir_ptr sid( ::mir_wstrdup(gch->ptszUID)); - switch (gch->pDest->iType) - { - case GC_SESSION_TERMINATE: - { - CConversation::Ref conversation; - if (g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false)) - { - Participant::Refs participants; - conversation->GetParticipants(participants, CConversation::MYSELF); - participants[0]->Retire(); - } - } - break; + CConversation::Ref conversation; + switch (gch->pDest->iType) { + case GC_SESSION_TERMINATE: + if (g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false)) + { + Participant::Refs participants; + conversation->GetParticipants(participants, CConversation::MYSELF); + participants[0]->Retire(); + } + break; - case GC_USER_MESSAGE: - if (gch->ptszText && gch->ptszText[0]) + case GC_USER_MESSAGE: + if (gch->ptszText && gch->ptszText[0]) + { + if (g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false)) { - CConversation::Ref conversation; - if (g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false)) - { - CMessage::Ref message; - mir_ptr text(::mir_utf8encodeW(gch->ptszText)); - conversation->PostText((char *)text, message); - } + CMessage::Ref message; + mir_ptr text(::mir_utf8encodeW(gch->ptszText)); + conversation->PostText((char *)text, message); } - break; + } + break; - case GC_USER_CHANMGR: - { - CConversation::Ref conversation; - if (g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false)) - { - StringList invitedContacts(this->GetChatUsers(cid)); - this->InviteConactsToChat(conversation, invitedContacts); - } - } - break; + case GC_USER_CHANMGR: + if (g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false)) + { + StringList invitedContacts(this->GetChatUsers(cid)); + this->InviteConactsToChat(conversation, invitedContacts); + } + break; - case GC_USER_PRIVMESS: - ::CallService(MS_MSG_SENDMESSAGE, (WPARAM)this->GetContactBySid(sid), 0); - break; + case GC_USER_PRIVMESS: + ::CallService(MS_MSG_SENDMESSAGE, (WPARAM)this->GetContactBySid(sid), 0); + break; - case GC_USER_LOGMENU: - switch(gch->dwData) + case GC_USER_LOGMENU: + switch(gch->dwData) { + case 10: + if (g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false)) { - case 10: - { - CConversation::Ref conversation; - if (g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false)) - { - StringList invitedContacts(this->GetChatUsers(cid)); - this->InviteConactsToChat(conversation, invitedContacts); - } - } - break; - - case 20: - this->LeaveChat(cid); - break; + StringList invitedContacts(this->GetChatUsers(cid)); + this->InviteConactsToChat(conversation, invitedContacts); } break; - case GC_USER_NICKLISTMENU: - switch (gch->dwData) - { - case 10: - ::CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)this->GetContactBySid(sid), 0); - break; + case 20: + this->LeaveChat(cid); + break; + } + break; - case 20: - CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)this->GetContactBySid(sid), 0); - break; + case GC_USER_NICKLISTMENU: + switch (gch->dwData) { + case 10: + ::CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)this->GetContactBySid(sid), 0); + break; - case 110: - this->LeaveChat(cid); - break; - } + case 20: + CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)this->GetContactBySid(sid), 0); break; - case GC_USER_TYPNOTIFY: + case 110: + this->LeaveChat(cid); break; - } - ::mir_free(sid); - ::mir_free(cid); + } + break; + case GC_USER_TYPNOTIFY: + break; + } return 0; } @@ -559,8 +533,7 @@ int __cdecl CSkypeProto::OnGCMenuHook(WPARAM, LPARAM lParam) } else if (gcmi->Type == MENU_ON_NICKLIST) { - wchar_t *id = mir_wstrdup(gcmi->pszUID); - if (!::wcsicmp(this->login, id)) + if (!::wcsicmp(this->login, gcmi->pszUID)) { static const struct gc_item Items[] = { @@ -582,7 +555,6 @@ int __cdecl CSkypeProto::OnGCMenuHook(WPARAM, LPARAM lParam) gcmi->nItems = SIZEOF(Items); gcmi->Item = (gc_item*)Items; } - mir_free(id); } return 0; @@ -609,7 +581,7 @@ void CSkypeProto::UpdateChatUserStatus(CContact::Ref contact) SEString identity; contact->GetIdentity(identity); - wchar_t *sid = ::mir_utf8decodeW(identity); + mir_ptr sid( ::mir_utf8decodeW(identity)); GC_INFO gci = {0}; gci.Flags = BYINDEX | ID; @@ -627,30 +599,22 @@ void CSkypeProto::UpdateChatUserStatus(CContact::Ref contact) GC_EVENT_SETCONTACTSTATUS, 0, CSkypeProto::SkypeToMirandaStatus(availability)); - - //::mir_free(gci.pszID); } - - ::mir_free(sid); } INT_PTR CALLBACK CSkypeProto::InviteToChatProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { InviteChatParam *param = (InviteChatParam *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch (msg) - { + switch (msg) { case WM_INITDIALOG: - { - TranslateDialogDefault(hwndDlg); - - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - param = (InviteChatParam *)lParam; + TranslateDialogDefault(hwndDlg); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + param = (InviteChatParam *)lParam; + { HWND hwndClist = GetDlgItem(hwndDlg, IDC_CCLIST); SetWindowLongPtr(hwndClist, GWL_STYLE, GetWindowLongPtr(hwndClist, GWL_STYLE) & ~CLS_HIDEOFFLINE); - - // WindowSetIcon(hwndDlg, "msn"); } break; @@ -658,83 +622,75 @@ INT_PTR CALLBACK CSkypeProto::InviteToChatProc(HWND hwndDlg, UINT msg, WPARAM wP ::EndDialog(hwndDlg, 0); break; - case WM_NCDESTROY: -// WindowFreeIcon(hwndDlg); - //delete param; - break; - case WM_NOTIFY: - { - NMCLISTCONTROL *nmc = (NMCLISTCONTROL *)lParam; - if (nmc->hdr.idFrom == IDC_CCLIST) { - switch (nmc->hdr.code) + NMCLISTCONTROL *nmc = (NMCLISTCONTROL *)lParam; + if (nmc->hdr.idFrom == IDC_CCLIST) { - case CLN_NEWCONTACT: - if (param && (nmc->flags & (CLNF_ISGROUP | CLNF_ISINFO)) == 0) + switch (nmc->hdr.code) { - param->ppro->ChatValidateContact(nmc->hItem, nmc->hdr.hwndFrom, param->invitedContacts); - } - break; + case CLN_NEWCONTACT: + if (param && (nmc->flags & (CLNF_ISGROUP | CLNF_ISINFO)) == 0) + { + param->ppro->ChatValidateContact(nmc->hItem, nmc->hdr.hwndFrom, param->invitedContacts); + } + break; - case CLN_LISTREBUILT: - if (param) - { - param->ppro->ChatPrepare(NULL, nmc->hdr.hwndFrom, param->invitedContacts); + case CLN_LISTREBUILT: + if (param) + { + param->ppro->ChatPrepare(NULL, nmc->hdr.hwndFrom, param->invitedContacts); + } + break; } - break; } } - } - break; + break; case WM_COMMAND: - { - switch (LOWORD(wParam)) + switch (LOWORD(wParam)) { + case IDC_ADDSCR: + if (param->ppro->IsOnline()) { - case IDC_ADDSCR: - if (param->ppro->IsOnline()) - { - wchar_t sid[SKYPE_SID_LIMIT]; - ::GetDlgItemText(hwndDlg, IDC_EDITSCR, sid, SIZEOF(sid)); - - CLCINFOITEM cii = {0}; - cii.cbSize = sizeof(cii); - cii.flags = CLCIIF_CHECKBOX | CLCIIF_BELOWCONTACTS; - cii.pszText = ::wcslwr(sid); - - HANDLE hItem = (HANDLE)::SendDlgItemMessage( - hwndDlg, - IDC_CCLIST, - CLM_ADDINFOITEM, - 0, - (LPARAM)&cii); - ::SendDlgItemMessage(hwndDlg, IDC_CCLIST, CLM_SETCHECKMARK, (LPARAM)hItem, 1); - } - break; + wchar_t sid[SKYPE_SID_LIMIT]; + ::GetDlgItemText(hwndDlg, IDC_EDITSCR, sid, SIZEOF(sid)); + + CLCINFOITEM cii = {0}; + cii.cbSize = sizeof(cii); + cii.flags = CLCIIF_CHECKBOX | CLCIIF_BELOWCONTACTS; + cii.pszText = ::wcslwr(sid); + + HANDLE hItem = (HANDLE)::SendDlgItemMessage( + hwndDlg, + IDC_CCLIST, + CLM_ADDINFOITEM, + 0, + (LPARAM)&cii); + ::SendDlgItemMessage(hwndDlg, IDC_CCLIST, CLM_SETCHECKMARK, (LPARAM)hItem, 1); + } + break; - case IDOK: - { - HWND hwndList = ::GetDlgItem(hwndDlg, IDC_CCLIST); + case IDOK: + { + HWND hwndList = ::GetDlgItem(hwndDlg, IDC_CCLIST); - param->invitedContacts.clear(); - param->ppro->GetInvitedContacts(NULL, hwndList, param->invitedContacts); + param->invitedContacts.clear(); + param->ppro->GetInvitedContacts(NULL, hwndList, param->invitedContacts); - if ( !param->invitedContacts.empty()) - { - //SetWindowLongPtr(hwndDlg, 0, (LONG_PTR)bct); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - ::EndDialog(hwndDlg, IDOK); - } - else - param->ppro->ShowNotification(::TranslateT("You did not select any contact")); + if ( !param->invitedContacts.empty()) + { + //SetWindowLongPtr(hwndDlg, 0, (LONG_PTR)bct); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + ::EndDialog(hwndDlg, IDOK); } - break; - - case IDCANCEL: - ::EndDialog(hwndDlg, IDCANCEL); - break; + else + param->ppro->ShowNotification(::TranslateT("You did not select any contact")); } + break; + + case IDCANCEL: + ::EndDialog(hwndDlg, IDCANCEL); + break; } break; } diff --git a/protocols/Skype/src/skype_contacts.cpp b/protocols/Skype/src/skype_contacts.cpp index f50d60e416..aacbe82006 100644 --- a/protocols/Skype/src/skype_contacts.cpp +++ b/protocols/Skype/src/skype_contacts.cpp @@ -47,12 +47,11 @@ void CSkypeProto::UpdateContactStatus(HANDLE hContact, CContact::Ref contact) void CSkypeProto::UpdateContactNickName(SEObject *obj, HANDLE hContact) { // todo: P_DISPLAYNAME = 21 is unworked - wchar_t *nick = ::mir_utf8decodeW(obj->GetStrProp(/* *::P_FULLNAME */ 5)); + mir_ptr nick( ::mir_utf8decodeW(obj->GetStrProp(/* *::P_FULLNAME */ 5))); if ( !::wcslen(nick)) ::db_unset(hContact, this->m_szModuleName, "Nick"); else ::db_set_ws(hContact, this->m_szModuleName, "Nick", nick); - ::mir_free(nick); } void CSkypeProto::UpdateContactOnlineSinceTime(SEObject *obj, HANDLE hContact) @@ -83,8 +82,7 @@ void CSkypeProto::OnContactChanged(CContact::Ref contact, int prop) if (hContact) { - switch(prop) - { + switch(prop) { case CContact::P_AUTHREQ_TIMESTAMP: { uint newTS = 0; @@ -199,7 +197,7 @@ HANDLE CSkypeProto::GetContactFromAuthEvent(HANDLE hEvent) HANDLE CSkypeProto::AddContact(CContact::Ref contact) { - wchar_t *sid = ::mir_utf8decodeW(contact->GetSid()); + mir_ptr sid( ::mir_utf8decodeW(contact->GetSid())); CContact::AVAILABILITY availability; contact->GetPropAvailability(availability); @@ -210,10 +208,9 @@ HANDLE CSkypeProto::AddContact(CContact::Ref contact) hContact = (HANDLE)::CallService(MS_DB_CONTACT_ADD, 0, 0); ::CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)this->m_szModuleName); - wchar_t *nick = ::mir_utf8decodeW(contact->GetNick()); + mir_ptr nick( ::mir_utf8decodeW(contact->GetNick())); - switch(availability) - { + switch(availability) { case CContact::SKYPEOUT: ::db_set_b(hContact, this->m_szModuleName, "IsSkypeOut", 1); break; @@ -242,12 +239,8 @@ HANDLE CSkypeProto::AddContact(CContact::Ref contact) db_set_ts(hContact, "CList", "Group", dbv.ptszVal); db_free(&dbv); } - - ::mir_free(nick); } - ::mir_free(sid); - return hContact; } @@ -388,15 +381,13 @@ void CSkypeProto::OnContactFinded(CContact::Ref contact, HANDLE hSearch) { contact->GetPropEmails(data); - wchar_t *emails = ::mir_utf8decodeW(data); + mir_ptr emails( ::mir_utf8decodeW(data)); wchar_t* main = ::wcstok(emails, L" "); if (main != NULL) { psr.email = main; } - - ::mir_free(emails); } this->SendBroadcast(ACKTYPE_SEARCH, ACKRESULT_DATA, hSearch, (LPARAM)&psr); @@ -404,7 +395,7 @@ void CSkypeProto::OnContactFinded(CContact::Ref contact, HANDLE hSearch) void __cdecl CSkypeProto::SearchBySidAsync(void* arg) { - wchar_t *sid = (wchar_t*)arg; + mir_ptr sid((wchar_t*)arg); HANDLE hContact = this->GetContactBySid(sid); if (hContact) @@ -425,18 +416,15 @@ void __cdecl CSkypeProto::SearchBySidAsync(void* arg) bool valid; if (!search->IsValid(valid) || !valid || !search->Submit()) - { return; - } + search->BlockWhileSearch(); search->Release(); - - ::mir_free(sid); } void __cdecl CSkypeProto::SearchByEmailAsync(void* arg) { - wchar_t *email = (wchar_t *)arg; + mir_ptr email((wchar_t *)arg); CContactSearch::Ref search; g_skype->CreateContactSearch(search); @@ -449,13 +437,10 @@ void __cdecl CSkypeProto::SearchByEmailAsync(void* arg) bool valid; if (!search->AddEmailTerm(::mir_u2a(email), valid) || !valid || !search->Submit()) - { return; - } + search->BlockWhileSearch(); search->Release(); - - ::mir_free(email); } void __cdecl CSkypeProto::SearchByNamesAsync(void* arg) diff --git a/protocols/Skype/src/skype_dialogs.cpp b/protocols/Skype/src/skype_dialogs.cpp index 73968b9dc2..5cb21f53a6 100644 --- a/protocols/Skype/src/skype_dialogs.cpp +++ b/protocols/Skype/src/skype_dialogs.cpp @@ -17,27 +17,20 @@ INT_PTR CALLBACK CSkypeProto::SkypeMainOptionsProc(HWND hwnd, UINT message, WPAR SetDlgItemText(hwnd, IDC_SL, sid); } { - char *pwd = ::db_get_sa(NULL, proto->m_szModuleName, SKYPE_SETTINGS_PASSWORD); - + mir_ptr pwd( ::db_get_sa(NULL, proto->m_szModuleName, SKYPE_SETTINGS_PASSWORD)); if (pwd) - { - ::CallService( - MS_DB_CRYPT_DECODESTRING, - ::strlen(pwd), - reinterpret_cast(pwd)); - } + ::CallService(MS_DB_CRYPT_DECODESTRING, ::strlen(pwd), pwd); SetDlgItemTextA(hwnd, IDC_PW, pwd); - ::mir_free(pwd); } { int port = rand() % 10000 + 10000; SetDlgItemInt(hwnd, IDC_PORT, ::db_get_w(NULL, proto->m_szModuleName, "Port", port), FALSE); SendMessage(GetDlgItem(hwnd, IDC_PORT), EM_SETLIMITTEXT, 5, 0); } - { - CheckDlgButton(hwnd, IDC_USE_ALT_PORTS, ::db_get_b(NULL, proto->m_szModuleName, "UseAlternativePorts", 1)); - } + + CheckDlgButton(hwnd, IDC_USE_ALT_PORTS, ::db_get_b(NULL, proto->m_szModuleName, "UseAlternativePorts", 1)); + if (proto->IsOnline()) { SendMessage(GetDlgItem(hwnd, IDC_SL), EM_SETREADONLY, 1, 0); diff --git a/protocols/Skype/src/skype_events.cpp b/protocols/Skype/src/skype_events.cpp index e2622a604b..53a938a30b 100644 --- a/protocols/Skype/src/skype_events.cpp +++ b/protocols/Skype/src/skype_events.cpp @@ -178,15 +178,12 @@ void CSkypeProto::OnMessageReceived(CConversation::Ref &conversation, CMessage:: else { message->GetPropAuthor(data); - wchar_t *sid = ::mir_utf8decodeW(data); + mir_ptr sid( ::mir_utf8decodeW(data)); conversation->GetPropIdentity(data); - wchar_t *cid = ::mir_utf8decodeW(data); - - this->SendChatMessage(cid, sid, ::mir_utf8decodeW(text)); + mir_ptr cid( ::mir_utf8decodeW(data)); - ::mir_free(sid); - ::mir_free(cid); + this->SendChatMessage(cid, sid, mir_ptr(::mir_utf8decodeW(text))); } } @@ -253,7 +250,7 @@ void CSkypeProto::OnMessageSended(CConversation::Ref &conversation, CMessage::Re if (::wcsicmp(nick, L"") == 0) nick = ::db_get_wsa(NULL, this->m_szModuleName, SKYPE_SETTINGS_LOGIN); - this->SendChatMessage(cid, nick, ::mir_utf8decodeW(text)); + this->SendChatMessage(cid, nick, mir_ptr(::mir_utf8decodeW(text))); } } @@ -493,7 +490,7 @@ void CSkypeProto::OnMessage(CConversation::Ref conversation, CMessage::Ref messa SEString data; conversation->GetPropIdentity(data); - wchar_t *cid = ::mir_utf8decodeW(data); + mir_ptr cid( ::mir_utf8decodeW(data)); message->GetPropIdentities(data); @@ -511,7 +508,6 @@ void CSkypeProto::OnMessage(CConversation::Ref conversation, CMessage::Ref messa } else if ( !alreadyInChat.contains(sid)) this->KickChatContact(cid, sid); - ::mir_free(cid); } } break; @@ -564,10 +560,9 @@ void CSkypeProto::OnMessage(CConversation::Ref conversation, CMessage::Ref messa SEString data; conversation->GetPropIdentity(data); - wchar_t *cid = ::mir_utf8decodeW(data); + mir_ptr cid( ::mir_utf8decodeW(data)); HANDLE hContact = this->GetChatRoomByCid(cid); this->RaiseChatEvent(cid, this->login, /*GC_EVENT_NOTICE*/ 0x0020, /*GCEF_ADDTOLOG*/ 0x0001, 0, NULL, ::TranslateT("There was incoming call")); - ::mir_free(cid); } break; diff --git a/protocols/Skype/src/skype_profile.cpp b/protocols/Skype/src/skype_profile.cpp index 1240cf8272..3e9a1c2e20 100644 --- a/protocols/Skype/src/skype_profile.cpp +++ b/protocols/Skype/src/skype_profile.cpp @@ -8,7 +8,7 @@ void CSkypeProto::UpdateProfileAvatar(SEObject *obj, HANDLE hContact) DWORD oldTS = ::db_get_dw(hContact, this->m_szModuleName, "AvatarTS", 0); - wchar_t *path = this->GetContactAvatarFilePath(hContact); + mir_ptr path( this->GetContactAvatarFilePath(hContact)); bool isAvatarFileExists = CSkypeProto::FileExists(path); if (newTS > oldTS || !isAvatarFileExists) { @@ -49,18 +49,15 @@ void CSkypeProto::UpdateProfileAvatar(SEObject *obj, HANDLE hContact) this->SendBroadcast(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, NULL, 0); } } - - ::mir_free(path); } void CSkypeProto::UpdateProfileAboutText(SEObject *obj, HANDLE hContact) { - wchar_t *aboutText = hContact ? ::mir_utf8decodeW(obj->GetStrProp(Contact::P_ABOUT)) : ::mir_utf8decodeW(obj->GetStrProp(Account::P_ABOUT)); + mir_ptr aboutText(hContact ? ::mir_utf8decodeW(obj->GetStrProp(Contact::P_ABOUT)) : ::mir_utf8decodeW(obj->GetStrProp(Account::P_ABOUT))); if ( !::wcslen(aboutText)) ::db_unset(hContact, this->m_szModuleName, "About"); else ::db_set_ws(hContact, this->m_szModuleName, "About", aboutText); - ::mir_free(aboutText); } void CSkypeProto::UpdateProfileBirthday(SEObject *obj, HANDLE hContact) @@ -97,18 +94,17 @@ void CSkypeProto::UpdateProfileBirthday(SEObject *obj, HANDLE hContact) void CSkypeProto::UpdateProfileCity(SEObject *obj, HANDLE hContact) { - wchar_t *city = hContact ? ::mir_utf8decodeW(obj->GetStrProp(Contact::P_CITY)) : ::mir_utf8decodeW(obj->GetStrProp(Account::P_CITY)); + mir_ptr city(hContact ? ::mir_utf8decodeW(obj->GetStrProp(Contact::P_CITY)) : ::mir_utf8decodeW(obj->GetStrProp(Account::P_CITY))); if ( !::wcslen(city)) ::db_unset(hContact, this->m_szModuleName, "City"); else ::db_set_ws(hContact, this->m_szModuleName, "City", city); - ::mir_free(city); } void CSkypeProto::UpdateProfileCountry(SEObject *obj, HANDLE hContact) { char *country; - char *isocode = hContact ? ::mir_strdup(obj->GetStrProp(Contact::P_COUNTRY)) : ::mir_strdup(obj->GetStrProp(Account::P_COUNTRY)); + mir_ptr isocode(hContact ? ::mir_strdup(obj->GetStrProp(Contact::P_COUNTRY)) : ::mir_strdup(obj->GetStrProp(Account::P_COUNTRY))); if ( !::strlen(isocode)) { country = (char *)CallService(MS_UTILS_GETCOUNTRYBYNUMBER, 0xFFFF, 0); @@ -119,12 +115,11 @@ void CSkypeProto::UpdateProfileCountry(SEObject *obj, HANDLE hContact) country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode, 0); ::db_set_ws(hContact, this->m_szModuleName, "Country", ::mir_a2t(country)); } - ::mir_free(isocode); } void CSkypeProto::UpdateProfileEmails(SEObject *obj, HANDLE hContact) { - wchar_t *emails = hContact ? ::mir_a2u(obj->GetStrProp(Contact::P_EMAILS)) : ::mir_a2u(obj->GetStrProp(Account::P_EMAILS)); + mir_ptr emails(hContact ? ::mir_a2u(obj->GetStrProp(Contact::P_EMAILS)) : ::mir_a2u(obj->GetStrProp(Account::P_EMAILS))); if (::wcscmp(emails, L"") == 0) { ::db_unset(hContact, this->m_szModuleName, "e-mail0"); @@ -143,12 +138,11 @@ void CSkypeProto::UpdateProfileEmails(SEObject *obj, HANDLE hContact) ::db_set_ws(hContact, this->m_szModuleName, key.c_str(), emls[i]); } } - ::mir_free(emails); } void CSkypeProto::UpdateProfileFullName(SEObject *obj, HANDLE hContact) { - wchar_t *fullname = hContact ? ::mir_utf8decodeW(obj->GetStrProp(Contact::P_FULLNAME)) : ::mir_utf8decodeW(obj->GetStrProp(Account::P_FULLNAME)); + mir_ptr fullname(hContact ? ::mir_utf8decodeW(obj->GetStrProp(Contact::P_FULLNAME)) : ::mir_utf8decodeW(obj->GetStrProp(Account::P_FULLNAME))); if ( !::wcslen(fullname)) { ::db_unset(hContact, this->m_szModuleName, "FirstName"); @@ -162,7 +156,6 @@ void CSkypeProto::UpdateProfileFullName(SEObject *obj, HANDLE hContact) if (names.size() > 1) ::db_set_ws(hContact, this->m_szModuleName, "LastName", names[1]); } - ::mir_free(fullname); } void CSkypeProto::UpdateProfileGender(SEObject *obj, HANDLE hContact) @@ -176,17 +169,16 @@ void CSkypeProto::UpdateProfileGender(SEObject *obj, HANDLE hContact) void CSkypeProto::UpdateProfileHomepage(SEObject *obj, HANDLE hContact) { - wchar_t *homepage = hContact ? ::mir_a2u(obj->GetStrProp(Contact::P_HOMEPAGE)) : ::mir_a2u(obj->GetStrProp(Account::P_HOMEPAGE)); + mir_ptr homepage(hContact ? ::mir_a2u(obj->GetStrProp(Contact::P_HOMEPAGE)) : ::mir_a2u(obj->GetStrProp(Account::P_HOMEPAGE))); if (::wcscmp(homepage, L"") == 0) ::db_unset(hContact, this->m_szModuleName, "Homepage"); else ::db_set_ws(hContact, this->m_szModuleName, "Homepage", homepage); - ::mir_free(homepage); } void CSkypeProto::UpdateProfileLanguages(SEObject *obj, HANDLE hContact) { - wchar_t *isocodes = hContact ? ::mir_utf8decodeW(obj->GetStrProp(Contact::P_LANGUAGES)) : ::mir_utf8decodeW(obj->GetStrProp(Account::P_LANGUAGES)); + mir_ptr isocodes(hContact ? ::mir_utf8decodeW(obj->GetStrProp(Contact::P_LANGUAGES)) : ::mir_utf8decodeW(obj->GetStrProp(Account::P_LANGUAGES))); if ( !::wcslen(isocodes)) { ::db_unset(hContact, this->m_szModuleName, "Language1"); @@ -208,57 +200,51 @@ void CSkypeProto::UpdateProfileLanguages(SEObject *obj, HANDLE hContact) } } } - ::mir_free(isocodes); } void CSkypeProto::UpdateProfileMobilePhone(SEObject *obj, HANDLE hContact) { - wchar_t *phone = hContact ? ::mir_a2u(obj->GetStrProp(Contact::P_PHONE_MOBILE)) : ::mir_a2u(obj->GetStrProp(Account::P_PHONE_MOBILE)); + mir_ptr phone(hContact ? ::mir_a2u(obj->GetStrProp(Contact::P_PHONE_MOBILE)) : ::mir_a2u(obj->GetStrProp(Account::P_PHONE_MOBILE))); if ( !::wcslen(phone)) ::db_unset(hContact, this->m_szModuleName, "Cellular"); else ::db_set_ws(hContact, this->m_szModuleName, "Cellular", phone); - ::mir_free(phone); } void CSkypeProto::UpdateProfilePhone(SEObject *obj, HANDLE hContact) { - wchar_t *phone = hContact ? ::mir_a2u(obj->GetStrProp(Contact::P_PHONE_HOME)) : ::mir_a2u(obj->GetStrProp(Account::P_PHONE_HOME)); + mir_ptr phone(hContact ? ::mir_a2u(obj->GetStrProp(Contact::P_PHONE_HOME)) : ::mir_a2u(obj->GetStrProp(Account::P_PHONE_HOME))); if ( !::wcslen(phone)) ::db_unset(hContact, this->m_szModuleName, "Phone"); else ::db_set_ws(hContact, this->m_szModuleName, "Phone", phone); - ::mir_free(phone); } void CSkypeProto::UpdateProfileOfficePhone(SEObject *obj, HANDLE hContact) { - wchar_t *phone = hContact ? ::mir_a2u(obj->GetStrProp(Contact::P_PHONE_OFFICE)) : ::mir_a2u(obj->GetStrProp(Account::P_PHONE_OFFICE)); + mir_ptr phone(hContact ? ::mir_a2u(obj->GetStrProp(Contact::P_PHONE_OFFICE)) : ::mir_a2u(obj->GetStrProp(Account::P_PHONE_OFFICE))); if ( !::wcslen(phone)) ::db_unset(hContact, this->m_szModuleName, "CompanyPhone"); else ::db_set_ws(hContact, this->m_szModuleName, "CompanyPhone", phone); - ::mir_free(phone); } void CSkypeProto::UpdateProfileState(SEObject *obj, HANDLE hContact) { - wchar_t *state = hContact ? ::mir_utf8decodeW(obj->GetStrProp(Contact::P_PROVINCE)) : ::mir_utf8decodeW(obj->GetStrProp(Account::P_PROVINCE)); + mir_ptr state(hContact ? ::mir_utf8decodeW(obj->GetStrProp(Contact::P_PROVINCE)) : ::mir_utf8decodeW(obj->GetStrProp(Account::P_PROVINCE))); if ( !::wcslen(state)) ::db_unset(hContact, this->m_szModuleName, "State"); else ::db_set_ws(hContact, this->m_szModuleName, "State", state); - ::mir_free(state); } void CSkypeProto::UpdateProfileStatusMessage(SEObject *obj, HANDLE hContact) { - wchar_t *statusMessage = hContact ? ::mir_utf8decodeW(obj->GetStrProp(Contact::P_MOOD_TEXT)) : ::mir_utf8decodeW(obj->GetStrProp(Account::P_MOOD_TEXT)); + mir_ptr statusMessage(hContact ? ::mir_utf8decodeW(obj->GetStrProp(Contact::P_MOOD_TEXT)) : ::mir_utf8decodeW(obj->GetStrProp(Account::P_MOOD_TEXT))); if ( !::wcslen(statusMessage)) ::db_unset(hContact, this->m_szModuleName, "XStatusMsg"); else ::db_set_ws(hContact, this->m_szModuleName, "XStatusMsg", statusMessage); - ::mir_free(statusMessage); } void CSkypeProto::UpdateProfileTimezone(SEObject *obj, HANDLE hContact) diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h index 8a610b3da0..3e008be7f6 100644 --- a/protocols/Skype/src/skype_proto.h +++ b/protocols/Skype/src/skype_proto.h @@ -65,8 +65,8 @@ struct PasswordRequestBoxParam ~PasswordRequestBoxParam() { - if (login) ::mir_free(login); - if (password) ::mir_free(password); + ::mir_free(login); + ::mir_free(password); } }; @@ -79,8 +79,8 @@ struct PasswordChangeBoxParam ~PasswordChangeBoxParam() { - if (password) ::mir_free(password); - if (password2) ::mir_free(password2); + ::mir_free(password); + ::mir_free(password2); } }; -- cgit v1.2.3