From a90a4275934b9b3c5889b3fbf3fb312a83714ede Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 19 Nov 2013 21:44:15 +0000 Subject: password converter for Jabber git-svn-id: http://svn.miranda-ng.org/main/trunk@6944 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/JabberG/src/jabber_chat.cpp | 6 ++--- protocols/JabberG/src/jabber_groupchat.cpp | 10 +++---- protocols/JabberG/src/jabber_iqid.cpp | 2 +- protocols/JabberG/src/jabber_opt.cpp | 18 ++++++------- protocols/JabberG/src/jabber_proto.cpp | 7 +---- protocols/JabberG/src/jabber_proto.h | 4 +-- protocols/JabberG/src/jabber_std.cpp | 43 +++++++++++++++++++++++------- protocols/JabberG/src/jabber_thread.cpp | 4 +-- 8 files changed, 55 insertions(+), 39 deletions(-) (limited to 'protocols') diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index 4ac1cf5967..a4aa2d292d 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -153,12 +153,12 @@ int CJabberProto::GcInit(JABBER_LIST_ITEM *item) } else setTString(hContact, "MyNick", item->nick); - ptrT passw( JGetStringCrypt(hContact, "LoginPassword")); + ptrT passw( getTStringA(hContact, "Password")); if (lstrcmp_null(passw, item->password)) { if ( !item->password || !item->password[0]) - delSetting(hContact, "LoginPassword"); + delSetting(hContact, "Password"); else - JSetStringCrypt(hContact, "LoginPassword", item->password); + setTString(hContact, "Password", item->password); } } mir_free(szNick); diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp index 099e6eb7e3..f671e163c6 100644 --- a/protocols/JabberG/src/jabber_groupchat.cpp +++ b/protocols/JabberG/src/jabber_groupchat.cpp @@ -127,8 +127,8 @@ struct JabberGcRecentInfo mir_snprintf(setting, sizeof(setting), "rcMuc_%d_nick", iRecent); nick = ppro->getTStringA(setting); - mir_snprintf(setting, sizeof(setting), "rcMuc_%d_passwordW", iRecent); - password = ppro->JGetStringCrypt(NULL, setting); + mir_snprintf(setting, sizeof(setting), "password_rcMuc_%d", iRecent); + password = ppro->getTStringA(NULL, setting); return room || server || nick || password; } @@ -155,9 +155,9 @@ struct JabberGcRecentInfo else ppro->delSetting(setting); - mir_snprintf(setting, sizeof(setting), "rcMuc_%d_passwordW", iRecent); + mir_snprintf(setting, sizeof(setting), "password_rcMuc_%d", iRecent); if (password) - ppro->JSetStringCrypt(NULL, setting, password); + ppro->setTString(setting, password); else ppro->delSetting(setting); } @@ -194,7 +194,7 @@ INT_PTR __cdecl CJabberProto::OnJoinChat(WPARAM wParam, LPARAM) if ((nick = getTStringA("Nick")) == NULL) return 0; - ptrT password( JGetStringCrypt(hContact, "LoginPassword")); + ptrT password(getTStringA(hContact, "Password")); if (getWord(hContact, "Status", 0) != ID_STATUS_ONLINE) { TCHAR *p = _tcschr(jid, '@'); diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index 7fd1035a92..5546369dce 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -334,7 +334,7 @@ void CJabberProto::GroupchatJoinByHContact(HANDLE hContact, bool autojoin) return; } - GroupchatJoinRoom(server, room, nick, ptrT(JGetStringCrypt(hContact, "LoginPassword")), autojoin); + GroupchatJoinRoom(server, room, nick, ptrT(getTStringA(hContact, "Password")), autojoin); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp index f29b17bd5b..524050fd1c 100644 --- a/protocols/JabberG/src/jabber_opt.cpp +++ b/protocols/JabberG/src/jabber_opt.cpp @@ -447,7 +447,7 @@ protected: SendDlgItemMessage(m_hwnd, IDC_PRIORITY_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(127, -128)); - TCHAR *passw = m_proto->JGetStringCrypt(NULL, "LoginPassword"); + TCHAR *passw = m_proto->getTStringA(NULL, "Password"); if (passw) { m_txtPassword.SetText(passw); mir_free(passw); @@ -504,12 +504,10 @@ protected: // clear saved password *m_proto->m_savedPassword = 0; - if (m_chkSavePassword.GetState() == BST_CHECKED) { - TCHAR *text = m_txtPassword.GetText(); - m_proto->JSetStringCrypt(NULL, "LoginPassword", text); - mir_free(text); - } - else m_proto->delSetting("LoginPassword"); + if (m_chkSavePassword.GetState() == BST_CHECKED) + m_proto->setTString("Password", ptrT(m_txtPassword.GetText())); + else + m_proto->delSetting("Password"); int index = m_cbLocale.GetCurSel(); if (index >= 0) { @@ -1622,7 +1620,7 @@ protected: m_gotservers = false; - TCHAR *passw = m_proto->JGetStringCrypt(NULL, "LoginPassword"); + TCHAR *passw = m_proto->getTStringA(NULL, "Password"); if (passw) { m_txtPassword.SetText(passw); mir_free(passw); @@ -1748,10 +1746,10 @@ protected: if (m_chkSavePassword.GetState() == BST_CHECKED) { TCHAR *text = m_txtPassword.GetText(); - m_proto->JSetStringCrypt(NULL, "LoginPassword", text); + m_proto->setTString("Password", text); mir_free(text); } - else m_proto->delSetting("LoginPassword"); + else m_proto->delSetting("Password"); switch (m_cbType.GetItemData(m_cbType.GetCurSel())) { case ACC_OK: diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 6830a578f6..79e5cf523d 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -156,12 +156,6 @@ CJabberProto::CJabberProto(const char *aProtoName, const TCHAR *aUserName) : if ((m_tszSelectedLang = getTStringA("XmlLang")) == NULL) m_tszSelectedLang = mir_tstrdup(_T("en")); - - ptrA szPassword( getStringA("Password")); - if (szPassword != NULL) { - JSetStringCrypt(NULL, "LoginPassword", _A2T(szPassword)); - delSetting("Password"); - } } CJabberProto::~CJabberProto() @@ -264,6 +258,7 @@ int CJabberProto::OnModulesLoadedEx(WPARAM, LPARAM) HookProtoEvent(ME_IDLE_CHANGED, &CJabberProto::OnIdleChanged); CheckAllContactsAreTransported(); + ConvertPasswords(); // Set all contacts to offline for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index d69341f93a..63b2660862 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -677,11 +677,9 @@ struct CJabberProto : public PROTO, public IJabberInterface void SearchAddToRecent(const TCHAR *szAddr, HWND hwndDialog = NULL); //---- jabber_std.cpp ---------------------------------------------- + void ConvertPasswords(); void JLoginFailed(int errorCode); - TCHAR* JGetStringCrypt(HANDLE hContact, char* valueName); - DWORD JSetStringCrypt(HANDLE hContact, char* valueName, const TCHAR *parValue); - //---- jabber_svc.c ------------------------------------------------------------------ void CheckMenuItems(); diff --git a/protocols/JabberG/src/jabber_std.cpp b/protocols/JabberG/src/jabber_std.cpp index daf1078a8f..cd6f95e4a1 100644 --- a/protocols/JabberG/src/jabber_std.cpp +++ b/protocols/JabberG/src/jabber_std.cpp @@ -40,10 +40,10 @@ void __forceinline sttCryptString(char *str) } } -TCHAR* CJabberProto::JGetStringCrypt(HANDLE hContact, char *valueName) +static TCHAR* JSetStringCrypt(LPCSTR szModule, HANDLE hContact, char *valueName) { DBVARIANT dbv; - if ( db_get_s(hContact, m_szModuleName, valueName, &dbv)) + if (db_get_s(hContact, szModule, valueName, &dbv)) return NULL; sttCryptString(dbv.pszVal); @@ -52,11 +52,36 @@ TCHAR* CJabberProto::JGetStringCrypt(HANDLE hContact, char *valueName) return res; } -DWORD CJabberProto::JSetStringCrypt(HANDLE hContact, char *valueName, const TCHAR *parValue) +void CJabberProto::ConvertPasswords() { - char *tmp = mir_utf8encodeT(parValue); - sttCryptString(tmp); - setString(hContact, valueName, tmp); - mir_free(tmp); - return 0; -} + ptrT passw(JSetStringCrypt(m_szModuleName, NULL, "LoginPassword")); + if (passw == NULL) + return; + + setTString("Password", passw); + delSetting("LoginPassword"); + + for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + if ((passw = JSetStringCrypt(m_szModuleName, hContact, "LoginPassword")) == NULL) + continue; + + setTString(hContact, "Password", passw); + delSetting(hContact, "LoginPassword"); + } + + for (int i = 0;; i++) { + char varName[100]; + mir_snprintf(varName, sizeof(varName), "rcMuc_%d_server", i); + ptrA str(getStringA(NULL, varName)); + if (str == NULL) + break; + + mir_snprintf(varName, sizeof(varName), "rcMuc_%d", i); + if ((passw = JSetStringCrypt(m_szModuleName, NULL, varName)) != NULL) { + delSetting(varName); + + mir_snprintf(varName, sizeof(varName), "password_rcMuc_%d", i); + setTString(varName, passw); + } + } +} \ No newline at end of file diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 97962bbb13..1e4d068847 100644 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -98,7 +98,7 @@ static INT_PTR CALLBACK JabberPasswordDlgProc(HWND hwndDlg, UINT msg, WPARAM wPa BOOL savePassword = IsDlgButtonChecked(hwndDlg, IDC_SAVE_PERM); param->pro->setByte("SavePassword", savePassword); if (savePassword) { - param->pro->JSetStringCrypt(NULL,"LoginPassword",param->onlinePassword); + param->pro->setTString("Password", param->onlinePassword); param->saveOnlinePassword = TRUE; } } @@ -347,7 +347,7 @@ LBL_FatalError: } } else { - TCHAR *passw = JGetStringCrypt(NULL, "LoginPassword"); + TCHAR *passw = getTStringA(NULL, "Password"); if (passw == NULL) { JLoginFailed(LOGINERR_BADUSERID); debugLogA("Thread ended, password is not configured"); -- cgit v1.2.3