diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2012-10-13 14:38:12 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2012-10-13 14:38:12 +0000 |
commit | 85683af6f692614dec3c5741811cee3d2565f999 (patch) | |
tree | 640f3103205f68ed6e3dc7be7909b062d31e2f7a | |
parent | 6b30f907de8ee2dd3bb8eedd5bee89ad84740765 (diff) |
- reworked signIn(Thread) function
- fixed password request logic
git-svn-id: http://svn.miranda-ng.org/main/trunk@1907 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/Skype/src/skype.h | 2 | ||||
-rw-r--r-- | protocols/Skype/src/skype_contacts.cpp | 8 | ||||
-rw-r--r-- | protocols/Skype/src/skype_dialogs.cpp | 17 | ||||
-rw-r--r-- | protocols/Skype/src/skype_events.cpp | 3 | ||||
-rw-r--r-- | protocols/Skype/src/skype_proto.cpp | 79 | ||||
-rw-r--r-- | protocols/Skype/src/skype_proto.h | 8 | ||||
-rw-r--r-- | protocols/Skype/src/skype_settings.cpp | 33 | ||||
-rw-r--r-- | protocols/Skype/src/skype_subclassing.cpp | 23 | ||||
-rw-r--r-- | protocols/Skype/src/skype_subclassing.h | 3 | ||||
-rw-r--r-- | protocols/Skype/src/skype_utils.cpp | 28 |
10 files changed, 151 insertions, 53 deletions
diff --git a/protocols/Skype/src/skype.h b/protocols/Skype/src/skype.h index beb8677250..021f0c24e9 100644 --- a/protocols/Skype/src/skype.h +++ b/protocols/Skype/src/skype.h @@ -47,6 +47,8 @@ #include "skype_subclassing.h"
#define MODULE "Skype"
+#define SKYPE_LOGIN_LIMIT 128
+#define SKYPE_PASSWORD_LIMIT 128
#define SKYPE_SETTINGS_NAME "Name"
#define SKYPE_SETTINGS_STATUS "Status"
#define SKYPE_SETTINGS_LOGIN "SkypeLogin"
diff --git a/protocols/Skype/src/skype_contacts.cpp b/protocols/Skype/src/skype_contacts.cpp index d7c01e8b6e..e67abebf76 100644 --- a/protocols/Skype/src/skype_contacts.cpp +++ b/protocols/Skype/src/skype_contacts.cpp @@ -484,7 +484,7 @@ bool CSkypeProto::IsProtoContact(HANDLE hContact) HANDLE CSkypeProto::GetContactBySid(const wchar_t* sid)
{
- HANDLE hContact = ::db_find_first();
+ HANDLE hContact = (HANDLE)::CallService(MS_DB_CONTACT_FINDFIRST, 0, (LPARAM)this->m_szModuleName);
while (hContact)
{
if (this->IsProtoContact(hContact))
@@ -493,7 +493,7 @@ HANDLE CSkypeProto::GetContactBySid(const wchar_t* sid) return hContact;
}
- hContact = ::db_find_next(hContact);
+ hContact = (HANDLE)::CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, (LPARAM)this->m_szModuleName);
}
return 0;
@@ -698,12 +698,12 @@ void __cdecl CSkypeProto::LoadContactList(void*) void CSkypeProto::SetAllContactStatus(int status)
{
- HANDLE hContact = ::db_find_first();
+ 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 = ::db_find_next(hContact);
+ hContact = (HANDLE)::CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, (LPARAM)this->m_szModuleName);
}
}
\ No newline at end of file diff --git a/protocols/Skype/src/skype_dialogs.cpp b/protocols/Skype/src/skype_dialogs.cpp index 5e0bfd4af1..2c5d0cb535 100644 --- a/protocols/Skype/src/skype_dialogs.cpp +++ b/protocols/Skype/src/skype_dialogs.cpp @@ -50,12 +50,16 @@ INT_PTR CALLBACK CSkypeProto::SkypeAccountProc(HWND hwnd, UINT message, WPARAM w TCHAR data[128];
proto = reinterpret_cast<CSkypeProto*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
+ ::mir_free(proto->login);
GetDlgItemText(hwnd, IDC_SL, data, sizeof(data));
proto->SetSettingString(SKYPE_SETTINGS_LOGIN, data);
+ proto->login = ::mir_wstrdup(data);
GetDlgItemText(hwnd, IDC_PW, data, sizeof(data));
proto->SetDecodeSettingString(SKYPE_SETTINGS_PASSWORD, data);
+ proto->SetSettingByte("RememberPassword", true);
+
return TRUE;
}
}
@@ -116,12 +120,16 @@ INT_PTR CALLBACK CSkypeProto::SkypeOptionsProc(HWND hwnd, UINT message, WPARAM w wchar_t data[128];
proto = reinterpret_cast<CSkypeProto*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
+ ::mir_free(proto->login);
GetDlgItemText(hwnd, IDC_SL, data, sizeof(data));
proto->SetSettingString(SKYPE_SETTINGS_LOGIN, data);
+ proto->login = ::mir_wstrdup(data);
GetDlgItemText(hwnd, IDC_PW, data, sizeof(data));
proto->SetDecodeSettingString(SKYPE_SETTINGS_PASSWORD, data);
+ proto->SetSettingByte("RememberPassword", true);
+
return TRUE;
}
}
@@ -173,11 +181,14 @@ INT_PTR CALLBACK CSkypeProto::SkypePasswordProc(HWND hwndDlg, UINT msg, WPARAM w switch (LOWORD(wParam)) {
case IDOK:
ppro->rememberPassword = ::IsDlgButtonChecked(hwndDlg, IDC_SAVEPASSWORD) > 0;
- ppro->SetSettingByte(NULL, "RememberPassword", ppro->rememberPassword);
+ ppro->SetSettingByte("RememberPassword", ppro->rememberPassword);
- ::GetDlgItemText(hwndDlg, IDC_PASSWORD, ppro->password, sizeof(ppro->password));
+ ::mir_free(ppro->password);
+ wchar_t password[SKYPE_PASSWORD_LIMIT];
+ ::GetDlgItemText(hwndDlg, IDC_PASSWORD, password, sizeof(password));
+ ppro->password = ::mir_wstrdup(password);
- ppro->SignIn();
+ ppro->SignIn(false);
::EndDialog(hwndDlg, IDOK);
break;
diff --git a/protocols/Skype/src/skype_events.cpp b/protocols/Skype/src/skype_events.cpp index ef97109d6f..99d5c6bb6e 100644 --- a/protocols/Skype/src/skype_events.cpp +++ b/protocols/Skype/src/skype_events.cpp @@ -4,6 +4,9 @@ int CSkypeProto::OnModulesLoaded(WPARAM, LPARAM) {
this->HookEvent(ME_OPT_INITIALISE, &CSkypeProto::OnOptionsInit);
+ this->login = this->GetSettingString(SKYPE_SETTINGS_LOGIN);
+ this->rememberPassword = this->GetSettingByte("RememberPassword");
+
return 0;
}
diff --git a/protocols/Skype/src/skype_proto.cpp b/protocols/Skype/src/skype_proto.cpp index 6b46b2a3e2..609450a2b6 100644 --- a/protocols/Skype/src/skype_proto.cpp +++ b/protocols/Skype/src/skype_proto.cpp @@ -10,6 +10,10 @@ CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName) //_strlwr(m_szProtoName);
//this->m_szProtoName[0] = toupper(m_szProtoName[0]);
+ this->login = NULL;
+ this->password = NULL;
+ this->rememberPassword = false;
+
this->signin_lock = CreateMutex(0, false, 0);
this->SetAllContactStatus(ID_STATUS_OFFLINE);
@@ -24,12 +28,12 @@ CSkypeProto::~CSkypeProto() CloseHandle(this->signin_lock);
- /*mir_free(this->login);
- mir_free(this->password);*/
+ ::mir_free(this->login);
+ ::mir_free(this->password);
- mir_free(this->m_szProtoName);
- mir_free(this->m_szModuleName);
- mir_free(this->m_tszUserName);
+ ::mir_free(this->m_szProtoName);
+ ::mir_free(this->m_szModuleName);
+ ::mir_free(this->m_tszUserName);
}
HANDLE __cdecl CSkypeProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
@@ -207,7 +211,7 @@ int CSkypeProto::SetStatus(int new_status) if (new_status == ID_STATUS_OFFLINE && old_status != ID_STATUS_OFFLINE)
{
this->m_iStatus = new_status;
- //todo: set all status to offline
+
this->account->Logout(true);
this->account->BlockWhileLoggingOut();
this->account->SetAvailability(CContact::OFFLINE);
@@ -215,9 +219,11 @@ int CSkypeProto::SetStatus(int new_status) }
else
{
- this->m_iStatus = new_status;
if (old_status == ID_STATUS_OFFLINE)
- this->SignIn();
+ if ( !this->SignIn())
+ return 0;
+
+ this->m_iStatus = new_status;
CContact::AVAILABILITY availability = this->MirandaToSkypeStatus(this->m_iStatus);
if(availability != CContact::UNKNOWN)
@@ -259,38 +265,65 @@ void __cdecl CSkypeProto::SignInThread(void*) this->account->LoginWithPassword(::mir_u2a(this->password), false, false);
this->account->BlockWhileLoggingIn();
+ if ( !this->rememberPassword)
+ {
+ for (int i = ::wcslen(this->password); i >= 0; i--)
+ this->password[i] = L'\0';
+ }
- this->SetStatus(this->m_iDesiredStatus);
- this->ForkThread(&CSkypeProto::LoadContactList, this);
- //this->LoadContactList(this);
+ if (this->account->isLoggedOut)
+ {
+ this->m_iStatus = ID_STATUS_OFFLINE;
+ this->SendBroadcast(
+ ACKTYPE_LOGIN,
+ ACKRESULT_FAILED,
+ NULL,
+ this->SkypeToMirandaLoginError(this->account->logoutReason));
+ ::MessageBox(
+ NULL,
+ ::mir_a2u(this->account->logoutReasonString),
+ _T("Skype"),
+ MB_OK);
+ }
+ else
+ {
+ this->SetStatus(this->m_iDesiredStatus);
+ this->ForkThread(&CSkypeProto::LoadContactList, this);
+ //this->LoadContactList(this);
+ }
ReleaseMutex(this->signin_lock);
}
-void CSkypeProto::SignIn()
+bool CSkypeProto::SignIn(bool isReadPassword)
{
- this->login = this->GetSettingString(SKYPE_SETTINGS_LOGIN);
- if (login == NULL)
+ if (::wcscmp(this->login, L"") == 0)
{
- this->SetStatus(ID_STATUS_OFFLINE);
- this->SendBroadcast(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_BADUSERID);
+ this->m_iStatus = ID_STATUS_OFFLINE;
+ this->SendBroadcast(ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_BADUSERID);
::MessageBox(
NULL,
TranslateT("You have not entered a Skype name.\nConfigure this in Options->Network->Skype and try again."),
_T("Skype"),
MB_OK);
- return;
}
- if (g_skype->GetAccount(::mir_u2a(login), this->account))
+ else if (g_skype->GetAccount(::mir_u2a(this->login), this->account))
{
this->m_iStatus = ID_STATUS_CONNECTING;
- this->password = this->GetDecodeSettingString(SKYPE_SETTINGS_PASSWORD);
- if (this->password)
- this->ForkThread(&CSkypeProto::SignInThread, this);
- //this->SignIn(this);
- else
+ this->SendBroadcast(ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, this->m_iStatus);
+ if (isReadPassword)
+ this->password = this->GetDecodeSettingString(SKYPE_SETTINGS_PASSWORD);
+ if (::wcscmp(this->password, L"") == 0)
this->RequestPassword();
+ else
+ {
+ this->ForkThread(&CSkypeProto::SignInThread, this);
+ //this->SignInThread(this);
+ return true;
+ }
}
+
+ return false;
}
bool CSkypeProto::IsOnline()
diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h index ea8d7129e0..f9f1a24a1a 100644 --- a/protocols/Skype/src/skype_proto.h +++ b/protocols/Skype/src/skype_proto.h @@ -108,13 +108,13 @@ protected: CContactGroup::Ref commonList;
CContactGroup::Ref authWaitList;
- TCHAR* login;
- TCHAR* password;
+ wchar_t *login;
+ wchar_t *password;
bool rememberPassword;
void RequestPassword();
HANDLE signin_lock;
- void SignIn();
+ bool SignIn(bool isReadPassword = true);
void __cdecl SignInThread(void*);
bool IsOnline();
@@ -159,6 +159,8 @@ protected: wchar_t* GetAvatarFilePath(wchar_t* skypeName);
+ int SkypeToMirandaLoginError(CAccount::LOGOUTREASON logoutReason);
+
// instances
static LIST<CSkypeProto> instanceList;
static int CompareProtos(const CSkypeProto *p1, const CSkypeProto *p2);
diff --git a/protocols/Skype/src/skype_settings.cpp b/protocols/Skype/src/skype_settings.cpp index 71cf0e2b1c..3e0d4de2d5 100644 --- a/protocols/Skype/src/skype_settings.cpp +++ b/protocols/Skype/src/skype_settings.cpp @@ -32,13 +32,17 @@ DWORD CSkypeProto::GetSettingDword(const char *setting, DWORD errorValue) wchar_t* CSkypeProto::GetSettingString(HANDLE hContact, const char *setting, wchar_t* errorValue)
{
- DBVARIANT dbv;
- wchar_t* result = errorValue;
+ DBVARIANT dbv = {0};
+ wchar_t* result = NULL;
if ( !::DBGetContactSettingWString(hContact, this->m_szModuleName, setting, &dbv))
{
result = ::mir_wstrdup(dbv.pwszVal);
- DBFreeVariant(&dbv);
+ ::DBFreeVariant(&dbv);
+ }
+ else
+ {
+ result = ::mir_wstrdup(errorValue);
}
return result;
@@ -51,19 +55,21 @@ wchar_t* CSkypeProto::GetSettingString(const char *setting, wchar_t* errorValue) wchar_t* CSkypeProto::GetDecodeSettingString(HANDLE hContact, const char *setting, wchar_t* errorValue)
{
- DBVARIANT dbv;
- wchar_t* result = errorValue;
+ DBVARIANT dbv = {0};
+ wchar_t* result = NULL;
if ( !::DBGetContactSettingWString(hContact, this->m_szModuleName, setting, &dbv))
{
result = ::mir_wstrdup(dbv.pwszVal);
- DBFreeVariant(&dbv);
+ ::DBFreeVariant(&dbv);
- CallService(
+ ::CallService(
MS_DB_CRYPT_DECODESTRING,
- wcslen(result) + 1,
+ ::wcslen(result) + 1,
reinterpret_cast<LPARAM>(result));
}
+ else
+ result = ::mir_wstrdup(errorValue);
return result;
}
@@ -117,10 +123,15 @@ bool CSkypeProto::SetSettingString(const char *szSetting, const wchar_t* value) bool CSkypeProto::SetDecodeSettingString(HANDLE hContact, const char *setting, const wchar_t* value)
{
- TCHAR* result = mir_wstrdup(value);
- CallService(MS_DB_CRYPT_ENCODESTRING, sizeof(result), reinterpret_cast<LPARAM>(result));
+ if(::wcscmp(value, L"") != 0)
+ {
+ wchar_t* result = ::mir_wstrdup(value);
+ ::CallService(MS_DB_CRYPT_ENCODESTRING, sizeof(result), reinterpret_cast<LPARAM>(result));
+
+ return !this->SetSettingString(hContact, setting, result);
+ }
- return !this->SetSettingString(hContact, setting, result);
+ return !this->SetSettingString(hContact, setting, value);
}
bool CSkypeProto::SetDecodeSettingString(const char *setting, const wchar_t* value)
diff --git a/protocols/Skype/src/skype_subclassing.cpp b/protocols/Skype/src/skype_subclassing.cpp index 4f9f7bf2f4..ad3c265749 100644 --- a/protocols/Skype/src/skype_subclassing.cpp +++ b/protocols/Skype/src/skype_subclassing.cpp @@ -26,7 +26,8 @@ CConversation* CSkype::newConversation(int oid) CAccount::CAccount(unsigned int oid, SERootObject* root) : Account(oid, root) { - this->isLoggedOut = true; + this->isLoggedIn = false; + this->isLoggedOut = false; } void CAccount::OnChange(int prop) @@ -36,32 +37,36 @@ void CAccount::OnChange(int prop) CAccount::STATUS loginStatus; this->GetPropStatus(loginStatus); if (loginStatus == CAccount::LOGGED_IN) - this->isLoggedOut = false; + this->isLoggedIn = true; if (loginStatus == CAccount::LOGGED_OUT) { - this->isLoggedOut = true; CAccount::LOGOUTREASON whyLogout; this->GetPropLogoutreason(whyLogout); + this->logoutReason = whyLogout; if (whyLogout != Account::LOGOUT_CALLED) { - printf("%s\n", (const char*)tostring(whyLogout)); + // todo: rewrite!! + strcpy(this->logoutReasonString, (const char*)tostring(whyLogout)); } + this->isLoggedOut = true; }
} - } void CAccount::BlockWhileLoggingIn() { - while (this->isLoggedOut) - Sleep(1); + this->isLoggedIn = false; + this->isLoggedOut = false; + while (!this->isLoggedIn && !this->isLoggedOut) + Sleep(1); } void CAccount::BlockWhileLoggingOut() { - while ( !this->isLoggedOut) - Sleep(1); + this->isLoggedOut = false; + while ( !this->isLoggedOut) + Sleep(1); } // CContactGroup diff --git a/protocols/Skype/src/skype_subclassing.h b/protocols/Skype/src/skype_subclassing.h index 46dad87fb6..97ff2952eb 100644 --- a/protocols/Skype/src/skype_subclassing.h +++ b/protocols/Skype/src/skype_subclassing.h @@ -65,7 +65,10 @@ public: typedef DRef<CAccount, Account> Ref; typedef DRefs<CAccount, Account> Refs; + bool isLoggedIn; bool isLoggedOut; + LOGOUTREASON logoutReason; + char logoutReasonString[2048]; CAccount(unsigned int oid, SERootObject* root); diff --git a/protocols/Skype/src/skype_utils.cpp b/protocols/Skype/src/skype_utils.cpp index ae973f5fad..99463853c3 100644 --- a/protocols/Skype/src/skype_utils.cpp +++ b/protocols/Skype/src/skype_utils.cpp @@ -127,4 +127,32 @@ HANDLE CSkypeProto::ForkThreadEx(SkypeThreadFunc pFunc, void *param, UINT* threa 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;
+ }
+
+ return loginError;
}
\ No newline at end of file |