diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2012-12-13 18:29:32 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2012-12-13 18:29:32 +0000 |
commit | 6f291839eda68d23b65604cb5d5c685094072ed5 (patch) | |
tree | 86b7c6af0d480407529f782ede7c648790264378 /protocols/Skype/src | |
parent | b886dbff1977162ea1a6fa000c8275ecdf561e85 (diff) |
- refactored login/logout
git-svn-id: http://svn.miranda-ng.org/main/trunk@2740 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Skype/src')
-rw-r--r-- | protocols/Skype/src/skype_account.cpp | 43 | ||||
-rw-r--r-- | protocols/Skype/src/skype_profile.cpp | 2 | ||||
-rw-r--r-- | protocols/Skype/src/skype_proto.cpp | 39 | ||||
-rw-r--r-- | protocols/Skype/src/skype_proto.h | 9 | ||||
-rw-r--r-- | protocols/Skype/src/skype_subclassing.cpp | 51 | ||||
-rw-r--r-- | protocols/Skype/src/skype_subclassing.h | 10 | ||||
-rw-r--r-- | protocols/Skype/src/skype_utils.cpp | 35 |
7 files changed, 100 insertions, 89 deletions
diff --git a/protocols/Skype/src/skype_account.cpp b/protocols/Skype/src/skype_account.cpp new file mode 100644 index 0000000000..18505d9af4 --- /dev/null +++ b/protocols/Skype/src/skype_account.cpp @@ -0,0 +1,43 @@ +#include "skype_proto.h"
+
+void CSkypeProto::OnAccountChanged(int prop)
+{
+ switch(prop)
+ {
+ case CAccount::P_STATUS:
+ CAccount::STATUS loginStatus;
+ this->account->GetPropStatus(loginStatus);
+
+ if (loginStatus == CAccount::LOGGED_IN)
+ {
+ this->ForkThread(&CSkypeProto::SignInAsync, 0);
+ //this->SignInAsync(this);
+ }
+
+ if ((loginStatus == CAccount::LOGGED_OUT || loginStatus == CAccount::LOGGED_OUT_AND_PWD_SAVED))
+ {
+ CAccount::LOGOUTREASON whyLogout;
+ this->account->GetPropLogoutreason(whyLogout);
+ if (whyLogout != CAccount::LOGOUT_CALLED)
+ {
+ this->m_iStatus = ID_STATUS_OFFLINE;
+ this->SendBroadcast(
+ ACKTYPE_LOGIN,
+ ACKRESULT_FAILED,
+ NULL,
+ this->SkypeToMirandaLoginError(whyLogout));
+
+ this->ShowNotification(NULL, CSkypeProto::LogoutReasons[whyLogout - 1]);
+ }
+ }
+ break;
+
+ default :
+ OnProfileChanged(prop);
+ }
+}
+
+bool CSkypeProto::IsOnline()
+{
+ return this->m_iStatus > ID_STATUS_OFFLINE;
+}
\ No newline at end of file diff --git a/protocols/Skype/src/skype_profile.cpp b/protocols/Skype/src/skype_profile.cpp index 1c7dfa4110..1fe5122066 100644 --- a/protocols/Skype/src/skype_profile.cpp +++ b/protocols/Skype/src/skype_profile.cpp @@ -313,7 +313,7 @@ void CSkypeProto::UpdateOwnProfile() }
}
-void CSkypeProto::OnAccountChanged(int prop)
+void CSkypeProto::OnProfileChanged(int prop)
{
switch(prop)
{
diff --git a/protocols/Skype/src/skype_proto.cpp b/protocols/Skype/src/skype_proto.cpp index a9e95a4df8..5d2d8b0bba 100644 --- a/protocols/Skype/src/skype_proto.cpp +++ b/protocols/Skype/src/skype_proto.cpp @@ -265,10 +265,9 @@ int CSkypeProto::SetStatus(int new_status) switch (new_status) {
case ID_STATUS_OFFLINE:
- if (this->account->IsOnline()) {
+ if (this->IsOnline()) {
this->account->SetAvailability(CContact::OFFLINE);
this->account->Logout(true);
- this->account->BlockWhileLoggingOut();
this->m_iStatus = new_status;
this->SetAllContactStatus(ID_STATUS_OFFLINE);
@@ -346,29 +345,20 @@ int __cdecl CSkypeProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPA void __cdecl CSkypeProto::SignInAsync(void*)
{
- this->account.fetch();
- this->account->LoginWithPassword(this->password, false, false);
- this->account->BlockWhileLoggingIn();
- if ( !this->rememberPassword)
- memset(this->password, 0, strlen(this->password));
-
- if (this->account->isLoggedOut) {
- this->m_iStatus = ID_STATUS_OFFLINE;
- this->SendBroadcast(ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, this->SkypeToMirandaLoginError(this->account->logoutReason));
- this->ShowNotification(NULL, ::mir_a2u(this->account->logoutReasonString));
- return;
- }
-
g_skype->GetConversationList(g_skype->inbox, CConversation::INBOX_CONVERSATIONS);
fetch(g_skype->inbox);
- g_skype->SetOnConversationAddedCallback((CSkype::OnConversationAdded)&CSkypeProto::OnConversationAdded, this);
+ g_skype->SetOnConversationAddedCallback(
+ (CSkype::OnConversationAdded)&CSkypeProto::OnConversationAdded,
+ this);
for (uint i = 0 ; i < g_skype->inbox.size(); i++)
- g_skype->inbox[i]->SetOnMessageReceivedCallback((CConversation::OnMessageReceived)&CSkypeProto::OnOnMessageReceived, this);
+ g_skype->inbox[i]->SetOnMessageReceivedCallback(
+ (CConversation::OnMessageReceived)&CSkypeProto::OnOnMessageReceived,
+ this);
this->SetStatus(this->m_iDesiredStatus);
- this->LoadContactList(this);
this->LoadOwnInfo(this);
+ this->LoadContactList(this);
}
bool CSkypeProto::SignIn(bool isReadPassword)
@@ -391,8 +381,11 @@ bool CSkypeProto::SignIn(bool isReadPassword) this->RequestPassword();
else
{
- this->ForkThread(&CSkypeProto::SignInAsync, 0);
- //this->SignInAsync(this);
+ this->account.fetch();
+ this->account->SetOnAccountChangedCallback(
+ (CAccount::OnAccountChanged)&CSkypeProto::OnAccountChanged,
+ this);
+ this->account->LoginWithPassword(this->password, false, false);
return true;
}
}
@@ -400,12 +393,6 @@ bool CSkypeProto::SignIn(bool isReadPassword) return false;
}
-bool CSkypeProto::IsOnline()
-{
- return this->account && this->account->IsOnline();
- //return this->m_iStatus != ID_STATUS_OFFLINE;
-}
-
void CSkypeProto::RequestPassword()
{
::DialogBoxParam(
diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h index 4de33f6dcc..edae4c6acc 100644 --- a/protocols/Skype/src/skype_proto.h +++ b/protocols/Skype/src/skype_proto.h @@ -153,6 +153,10 @@ protected: CContactGroup::Ref commonList;
CContactGroup::Ref authWaitList;
+ // account
+ bool IsOnline();
+ void OnAccountChanged(int prop);
+
wchar_t *login;
char *password;
bool rememberPassword;
@@ -162,8 +166,7 @@ protected: bool SignIn(bool isReadPassword = true);
void __cdecl SignInAsync(void*);
- bool IsOnline();
-
+ static wchar_t* LogoutReasons[];
static LanguagesListEntry languages[223];
// messages
@@ -232,7 +235,7 @@ protected: void UpdateOwnProfile();
void UpdateOwnAbout();
- void OnAccountChanged(int prop);
+ void OnProfileChanged(int prop);
void __cdecl LoadOwnInfo(void*);
diff --git a/protocols/Skype/src/skype_subclassing.cpp b/protocols/Skype/src/skype_subclassing.cpp index 5e63c5d553..e6b6ec6d34 100644 --- a/protocols/Skype/src/skype_subclassing.cpp +++ b/protocols/Skype/src/skype_subclassing.cpp @@ -57,9 +57,6 @@ void CSkype::SetOnConversationAddedCallback(OnConversationAdded callback, CSkype CAccount::CAccount(unsigned int oid, SERootObject* root) : Account(oid, root)
{
- this->isLoggedIn = false;
- this->isLoggedOut = false;
-
this->proto = NULL;
this->callback == NULL;
}
@@ -72,52 +69,8 @@ void CAccount::SetOnAccountChangedCallback(OnAccountChanged callback, CSkypeProt void CAccount::OnChange(int prop)
{
- if (prop == CAccount::P_STATUS)
- {
- CAccount::STATUS loginStatus;
- this->GetPropStatus(loginStatus);
- if (loginStatus == CAccount::LOGGED_IN)
- this->isLoggedIn = true;
-
- if (loginStatus == CAccount::LOGGED_OUT)
- {
- CAccount::LOGOUTREASON whyLogout;
- this->GetPropLogoutreason(whyLogout);
- this->logoutReason = whyLogout;
- if (whyLogout != Account::LOGOUT_CALLED)
- {
- // todo: rewrite!!
- strcpy(this->logoutReasonString, (const char*)tostring(whyLogout));
- }
- this->isLoggedIn = false;
- this->isLoggedOut = true;
- }
- }
- else
- {
- if (this->proto)
- (proto->*callback)(prop);
- }
-}
-
-void CAccount::BlockWhileLoggingIn()
-{
- this->isLoggedIn = false;
- this->isLoggedOut = false;
- while (!this->isLoggedIn && !this->isLoggedOut)
- Sleep(1);
-}
-
-void CAccount::BlockWhileLoggingOut()
-{
- this->isLoggedOut = false;
- while ( !this->isLoggedOut)
- Sleep(1);
-}
-
-bool CAccount::IsOnline()
-{
- return (this == NULL) ? false : this->isLoggedIn;
+ if (this->proto)
+ (proto->*callback)(prop);
}
// CContactGroup
diff --git a/protocols/Skype/src/skype_subclassing.h b/protocols/Skype/src/skype_subclassing.h index 16ea04f276..7f7b7dfd32 100644 --- a/protocols/Skype/src/skype_subclassing.h +++ b/protocols/Skype/src/skype_subclassing.h @@ -102,18 +102,8 @@ 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);
- void BlockWhileLoggingIn();
- void BlockWhileLoggingOut();
-
- bool IsOnline();
-
void SetOnAccountChangedCallback(OnAccountChanged callback, CSkypeProto* proto);
private:
diff --git a/protocols/Skype/src/skype_utils.cpp b/protocols/Skype/src/skype_utils.cpp index ea4b8f3d1e..b7006faab0 100644 --- a/protocols/Skype/src/skype_utils.cpp +++ b/protocols/Skype/src/skype_utils.cpp @@ -1,5 +1,36 @@ #include "skype_proto.h"
+wchar_t* CSkypeProto::LogoutReasons[] =
+{ + LPGENW("LOGOUT_CALLED") /* LOGOUT_CALLED */, + LPGENW("HTTPS_PROXY_AUTH_FAILED") /* HTTPS_PROXY_AUTH_FAILED */, + LPGENW("SOCKS_PROXY_AUTH_FAILED") /* SOCKS_PROXY_AUTH_FAILED */, + LPGENW("P2P_CONNECT_FAILED") /* P2P_CONNECT_FAILED */, + LPGENW("SERVER_CONNECT_FAILED") /* SERVER_CONNECT_FAILED */, + LPGENW("SERVER_OVERLOADED") /* SERVER_OVERLOADED */, + LPGENW("DB_IN_USE") /* DB_IN_USE */, + LPGENW("Invalid skypename") /* INVALID_SKYPENAME */, + LPGENW("Invalid email") /* INVALID_EMAIL */, + LPGENW("Unacceptable password") /* UNACCEPTABLE_PASSWORD */, + LPGENW("SKYPENAME_TAKEN") /* SKYPENAME_TAKEN */, + LPGENW("REJECTED_AS_UNDERAGE") /* REJECTED_AS_UNDERAGE */, + LPGENW("NO_SUCH_IDENTITY") /* NO_SUCH_IDENTITY */, + LPGENW("Incorrect password") /* INCORRECT_PASSWORD */, + LPGENW("Too many login attempts") /* TOO_MANY_LOGIN_ATTEMPTS */, + LPGENW("PASSWORD_HAS_CHANGED") /* PASSWORD_HAS_CHANGED */, + LPGENW("PERIODIC_UIC_UPDATE_FAILED") /* PERIODIC_UIC_UPDATE_FAILED */, + LPGENW("DB_DISK_FULL") /* DB_DISK_FULL */, + LPGENW("DB_IO_ERROR") /* DB_IO_ERROR */, + LPGENW("DB_CORRUPT") /* DB_CORRUPT */, + LPGENW("DB_FAILURE") /* DB_FAILURE */, + LPGENW("INVALID_APP_ID") /* INVALID_APP_ID */, + LPGENW("APP_ID_FAILURE") /* APP_ID_FAILURE */, + LPGENW("UNSUPPORTED_VERSION") /* UNSUPPORTED_VERSION */, + LPGENW("ATO (Account TakeOver) detected, account blocked") /* ATO_BLOCKED */, + LPGENW("Logout from another instance") /* REMOTE_LOGOUT */,
+ LPGENW("") /* ACCESS_TOKEN_RENEWAL_FAILED */
+};
+
LanguagesListEntry CSkypeProto::languages[] =
{
{"Abkhazian", "ab"},
@@ -412,6 +443,10 @@ int CSkypeProto::SkypeToMirandaLoginError(CAccount::LOGOUTREASON logoutReason) case CAccount::UNACCEPTABLE_PASSWORD:
loginError = LOGINERR_WRONGPASSWORD;
break;
+
+ case CAccount::INVALID_APP_ID:
+ loginError = 1001;
+ break;
}
return loginError;
|