From 7d24302b79edea781e0f5bb5f449eb50dc88f275 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 17 Dec 2012 14:20:44 +0000 Subject: - added proxy settings support git-svn-id: http://svn.miranda-ng.org/main/trunk@2759 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Skype/src/skype_contacts.cpp | 13 ++--- protocols/Skype/src/skype_database.cpp | 6 +-- protocols/Skype/src/skype_proto.cpp | 86 ++++++++++++++++++++++++++----- protocols/Skype/src/skype_proto.h | 4 +- protocols/Skype/src/skype_subclassing.cpp | 11 ++++ protocols/Skype/src/skype_subclassing.h | 4 ++ protocols/Skype/src/skype_utils.cpp | 10 ++-- 7 files changed, 104 insertions(+), 30 deletions(-) (limited to 'protocols') diff --git a/protocols/Skype/src/skype_contacts.cpp b/protocols/Skype/src/skype_contacts.cpp index 500878ac08..e92fc135b7 100644 --- a/protocols/Skype/src/skype_contacts.cpp +++ b/protocols/Skype/src/skype_contacts.cpp @@ -565,7 +565,7 @@ HANDLE CSkypeProto::GetContactFromAuthEvent(HANDLE hEvent) return ::DbGetAuthEventContact(&dbei); } -HANDLE CSkypeProto::AddContactBySid(const char* sid, const wchar_t* nick, DWORD flags) +HANDLE CSkypeProto::AddContactBySid(const char* sid, const char* nick, DWORD flags) { HANDLE hContact = this->GetContactBySid(sid); if ( !hContact) @@ -574,7 +574,7 @@ HANDLE CSkypeProto::AddContactBySid(const char* sid, const wchar_t* nick, DWORD ::CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)this->m_szModuleName); ::DBWriteContactSettingString(hContact, this->m_szModuleName, "sid", sid); - this->SetSettingString(hContact, "Nick", nick); + ::DBWriteContactSettingString(hContact, this->m_szModuleName, "Nick", nick); CContact::Ref contact; if (g_skype->GetContact(sid, contact)) @@ -690,13 +690,13 @@ void __cdecl CSkypeProto::LoadContactList(void*) SEString data; contact->GetPropSkypename(data); - const char *sid = (const char *)data; + char *sid = ::mir_strdup((const char *)data); contact->GetPropDisplayname(data); - wchar_t *nick = ::mir_utf8decodeW((const char *)data); + char *nick = ::mir_strdup((const char *)data); contact->GetPropFullname(data); - wchar_t *name = ::mir_utf8decodeW((const char *)data); + char *name = ::mir_strdup((const char *)data); DWORD flags = 0; CContact::AVAILABILITY availability; @@ -706,7 +706,8 @@ void __cdecl CSkypeProto::LoadContactList(void*) { flags |= 256; contact->GetPropPstnnumber(data); - sid = (const char *)data; + ::mir_free(sid); + sid = ::mir_strdup((const char *)data); } else if (availability == CContact::PENDINGAUTH) flags = PALF_TEMPORARY; diff --git a/protocols/Skype/src/skype_database.cpp b/protocols/Skype/src/skype_database.cpp index 887061afbe..9d87b9b2c7 100644 --- a/protocols/Skype/src/skype_database.cpp +++ b/protocols/Skype/src/skype_database.cpp @@ -27,7 +27,7 @@ void CSkypeProto::RaiseAuthRequestEvent( CCSDATA ccs = {0}; ccs.szProtoService = PSR_AUTH; - ccs.hContact = this->AddContactBySid(sid, ::mir_a2u(nick)); + ccs.hContact = this->AddContactBySid(sid, nick); ccs.wParam = 0; ccs.lParam = (LPARAM)⪯ pre.timestamp = timestamp; @@ -64,7 +64,7 @@ void CSkypeProto::RaiseMessageReceivedEvent( CCSDATA ccs = {0}; ccs.szProtoService = PSR_MESSAGE; - ccs.hContact = this->AddContactBySid(sid, ::mir_a2u(nick)); + ccs.hContact = this->AddContactBySid(sid, nick); ccs.wParam = 0; ccs.lParam = (LPARAM)⪯ pre.flags = PREF_UTF; @@ -84,7 +84,7 @@ void CSkypeProto::RaiseMessageSendedEvent( CCSDATA ccs = {0}; ccs.szProtoService = PSR_MESSAGE; - ccs.hContact = this->AddContactBySid(sid, ::mir_a2u(nick)); + ccs.hContact = this->AddContactBySid(sid, nick); ccs.wParam = 0; ccs.lParam = (LPARAM)⪯ pre.flags = PREF_UTF; diff --git a/protocols/Skype/src/skype_proto.cpp b/protocols/Skype/src/skype_proto.cpp index 85a91146dd..c4bd2c6a30 100644 --- a/protocols/Skype/src/skype_proto.cpp +++ b/protocols/Skype/src/skype_proto.cpp @@ -44,7 +44,8 @@ CSkypeProto::~CSkypeProto() HANDLE __cdecl CSkypeProto::AddToList(int flags, PROTOSEARCHRESULT* psr) { - return this->AddContactBySid(::mir_u2a(psr->id), psr->nick, 0); + //todo:ref + return this->AddContactBySid(::mir_u2a(psr->id), ::mir_u2a(psr->nick), 0); } HANDLE __cdecl CSkypeProto::AddToListByEvent(int flags, int iContact, HANDLE hDbEvent) @@ -233,8 +234,9 @@ int __cdecl CSkypeProto::SendMsg(HANDLE hContact, int flags, const char* msg) { int result = ::InterlockedIncrement((LONG volatile*)&dwCMDNum); - CConversation::Ref conversation; - g_skype->GetConversationByIdentity(::mir_u2a(this->GetSettingString(hContact, "sid")), conversation); + CConversation::Ref conversation = CConversation::FindBySid( + g_skype, + ::DBGetString(hContact, this->m_szModuleName, "sid")); if (conversation) { Message::Ref message; @@ -307,22 +309,27 @@ int __cdecl CSkypeProto::UserIsTyping( HANDLE hContact, int type ) { if (hContact && this->IsOnline() && this->m_iStatus != ID_STATUS_INVISIBLE) { - CConversation::Ref conversation; - g_skype->GetConversationByIdentity(::mir_u2a(this->GetSettingString(hContact, "sid")), conversation); - if (conversation) + if (::strcmp(::DBGetString(hContact, this->m_szModuleName, "sid"), this->login) != 0) { - switch (type) + CConversation::Ref conversation = CConversation::FindBySid( + g_skype, + ::DBGetString(hContact, this->m_szModuleName, "sid")); + if (conversation) { - case PROTOTYPE_SELFTYPING_ON: - conversation->SetMyTextStatusTo(Participant::WRITING); - return 0; - - case PROTOTYPE_SELFTYPING_OFF: - conversation->SetMyTextStatusTo(Participant::READING); // mb TEXT_UNKNOWN? - return 0; + switch (type) + { + case PROTOTYPE_SELFTYPING_ON: + conversation->SetMyTextStatusTo(Participant::WRITING); + return 0; + + case PROTOTYPE_SELFTYPING_OFF: + conversation->SetMyTextStatusTo(Participant::READING); // mb TEXT_UNKNOWN? + return 0; + } } } } + return 1; } @@ -379,6 +386,57 @@ bool CSkypeProto::SignIn(bool isReadPassword) this->account->SetOnAccountChangedCallback( (CAccount::OnAccountChanged)&CSkypeProto::OnAccountChanged, this); + // + if (this->hNetlibUser) + { + NETLIBUSERSETTINGS nlus = { sizeof(NETLIBUSERSETTINGS) }; + if ( + !::CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)this->hNetlibUser, (LPARAM)&nlus) && + nlus.useProxy) + { + char address[MAX_PATH]; + ::mir_snprintf(address, MAX_PATH, "%s:%d", nlus.szProxyServer, nlus.wProxyPort); + + switch (nlus.proxyType) + { + case PROXYTYPE_HTTP: + case PROXYTYPE_HTTPS: + g_skype->SetInt(SETUPKEY_HTTPS_PROXY_ENABLE, 1); + g_skype->SetInt(SETUPKEY_SOCKS_PROXY_ENABLE, 0); + g_skype->SetStr(SETUPKEY_HTTPS_PROXY_ADDR, address); + if (nlus.useProxyAuth) + { + g_skype->SetStr(SETUPKEY_HTTPS_PROXY_USER, nlus.szProxyAuthUser); + g_skype->SetStr(SETUPKEY_HTTPS_PROXY_PWD, nlus.szProxyAuthPassword); + } + break; + + case PROXYTYPE_SOCKS4: + case PROXYTYPE_SOCKS5: + g_skype->SetInt(SETUPKEY_HTTPS_PROXY_ENABLE, 0); + g_skype->SetInt(SETUPKEY_SOCKS_PROXY_ENABLE, 1); + g_skype->SetStr(SETUPKEY_SOCKS_PROXY_ADDR, address); + if (nlus.useProxyAuth) + { + g_skype->SetStr(SETUPKEY_SOCKS_PROXY_USER, nlus.szProxyAuthUser); + g_skype->SetStr(SETUPKEY_SOCKS_PROXY_PWD, nlus.szProxyAuthPassword); + } + break; + + default: + g_skype->Delete(SETUPKEY_HTTPS_PROXY_ENABLE); + g_skype->Delete(SETUPKEY_HTTPS_PROXY_ADDR); + g_skype->Delete(SETUPKEY_HTTPS_PROXY_USER); + g_skype->Delete(SETUPKEY_HTTPS_PROXY_PWD); + g_skype->Delete(SETUPKEY_SOCKS_PROXY_ENABLE); + g_skype->Delete(SETUPKEY_SOCKS_PROXY_ADDR); + g_skype->Delete(SETUPKEY_SOCKS_PROXY_USER); + g_skype->Delete(SETUPKEY_SOCKS_PROXY_PWD); + break; + } + } + } + // this->account->LoginWithPassword(this->password, false, false); return true; } diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h index 8a5eae3498..db10c7522e 100644 --- a/protocols/Skype/src/skype_proto.h +++ b/protocols/Skype/src/skype_proto.h @@ -206,7 +206,7 @@ protected: bool IsProtoContact(HANDLE hContact); HANDLE GetContactBySid(const char* sid); HANDLE GetContactFromAuthEvent(HANDLE hEvent); - HANDLE AddContactBySid(const char* skypeName, const wchar_t* nick, DWORD flags = 0); + HANDLE AddContactBySid(const char* sid, const char* nick, DWORD flags = 0); int SkypeToMirandaStatus(CContact::AVAILABILITY availability); CContact::AVAILABILITY MirandaToSkypeStatus(int status); @@ -251,7 +251,7 @@ protected: int SkypeToMirandaLoginError(CAccount::LOGOUTREASON logoutReason); - void ShowNotification(const char *sid, const wchar_t *message, int flags = 0); + void ShowNotification(const char *nick, const wchar_t *message, int flags = 0); // instances static LIST instanceList; diff --git a/protocols/Skype/src/skype_subclassing.cpp b/protocols/Skype/src/skype_subclassing.cpp index adbd6a5120..d8843a800f 100644 --- a/protocols/Skype/src/skype_subclassing.cpp +++ b/protocols/Skype/src/skype_subclassing.cpp @@ -197,6 +197,17 @@ void CConversation::OnMessage(const MessageRef & message) (proto->*callback)(message->ref()); } +CConversation::Ref CConversation::FindBySid(CSkype *skype, SEString sid) +{ + SEStringList participants; + participants.append(sid); + + CConversation::Ref conversation; + skype->GetConversationByParticipants(participants, conversation); + + return conversation; +} + void CConversation::SetOnMessageReceivedCallback(OnMessageReceived callback, CSkypeProto* proto) { this->proto = proto; diff --git a/protocols/Skype/src/skype_subclassing.h b/protocols/Skype/src/skype_subclassing.h index 2624ba3f76..f2d571ae98 100644 --- a/protocols/Skype/src/skype_subclassing.h +++ b/protocols/Skype/src/skype_subclassing.h @@ -7,6 +7,8 @@ struct CSkypeProto; +class CSkype; + class CMessage : public Message { public: @@ -27,6 +29,8 @@ public: CConversation(unsigned int oid, SERootObject* root); + static CConversation::Ref FindBySid(CSkype *skype, SEString sid); + void SetOnMessageReceivedCallback(OnMessageReceived callback, CSkypeProto* proto); private: diff --git a/protocols/Skype/src/skype_utils.cpp b/protocols/Skype/src/skype_utils.cpp index a43c621769..73df520aa0 100644 --- a/protocols/Skype/src/skype_utils.cpp +++ b/protocols/Skype/src/skype_utils.cpp @@ -452,20 +452,20 @@ int CSkypeProto::SkypeToMirandaLoginError(CAccount::LOGOUTREASON logoutReason) return loginError; } -void CSkypeProto::ShowNotification(const char *sid, const wchar_t *message, int flags) +void CSkypeProto::ShowNotification(const char *nick, const wchar_t *message, int flags) { if (::Miranda_Terminated()) return; - if ( !ServiceExists(MS_POPUP_ADDPOPUPEX) || !DBGetContactSettingByte(NULL, "PopUp", "ModuleIsEnabled", 1)) + if ( !ServiceExists(MS_POPUP_ADDPOPUPT) || !DBGetContactSettingByte(NULL, "PopUp", "ModuleIsEnabled", 1)) MessageBoxW(NULL, message, TranslateT("Skype Protocol"), MB_OK); else { - if ( !sid) - sid = ""; + if ( !nick) + nick = ""; POPUPDATAT_V2 ppd = {0}; ppd.cbSize = sizeof(POPUPDATAT_V2); ppd.lchContact = NULL; - lstrcpyn(ppd.lpwzContactName, ::mir_a2u(sid), MAX_CONTACTNAME); + lstrcpyn(ppd.lpwzContactName, ::mir_a2u(nick), MAX_CONTACTNAME); lstrcpyn(ppd.lpwzText, message, MAX_SECONDLINE); ppd.lchIcon = Skin_GetIcon("Skype_main"); ppd.colorBack = ppd.colorText = 0; -- cgit v1.2.3