diff options
author | aunsane <aunsane@gmail.com> | 2017-12-21 16:08:58 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2017-12-21 16:09:15 +0300 |
commit | 70c13e5c4475aedd296c51e68070e85096eb4f39 (patch) | |
tree | 83ed7d0e4bf25d25babfd7fdfe741e9e457f6c6d | |
parent | f4184ffdc42c7a1753a77ea8087f5f16635ac942 (diff) |
Tox: improved profile encription management
-rw-r--r-- | include/m_system_cpp.h | 12 | ||||
-rw-r--r-- | protocols/Tox/res/resource.rc | 46 | ||||
-rw-r--r-- | protocols/Tox/src/resource.h | 11 | ||||
-rw-r--r-- | protocols/Tox/src/stdafx.h | 7 | ||||
-rw-r--r-- | protocols/Tox/src/tox_accounts.cpp | 6 | ||||
-rw-r--r-- | protocols/Tox/src/tox_avatars.cpp | 4 | ||||
-rw-r--r-- | protocols/Tox/src/tox_bootstrap.cpp | 4 | ||||
-rw-r--r-- | protocols/Tox/src/tox_connection.cpp | 6 | ||||
-rw-r--r-- | protocols/Tox/src/tox_contacts.cpp | 35 | ||||
-rw-r--r-- | protocols/Tox/src/tox_menus.cpp | 32 | ||||
-rw-r--r-- | protocols/Tox/src/tox_menus.h | 3 | ||||
-rw-r--r-- | protocols/Tox/src/tox_messages.cpp | 8 | ||||
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 62 | ||||
-rw-r--r-- | protocols/Tox/src/tox_options.h | 32 | ||||
-rw-r--r-- | protocols/Tox/src/tox_profile.cpp | 170 | ||||
-rw-r--r-- | protocols/Tox/src/tox_profile.h | 25 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.cpp | 16 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 12 | ||||
-rw-r--r-- | protocols/Tox/src/tox_services.cpp | 2 | ||||
-rw-r--r-- | protocols/Tox/src/tox_transfer.cpp | 34 |
20 files changed, 337 insertions, 190 deletions
diff --git a/include/m_system_cpp.h b/include/m_system_cpp.h index e26ef5a3de..11ccbfc0b2 100644 --- a/include/m_system_cpp.h +++ b/include/m_system_cpp.h @@ -92,9 +92,8 @@ public: __inline explicit pass_ptrA(char *_p) : mir_ptr(_p) {}
__inline ~pass_ptrA() { zero(); }
__inline char* operator = (char *_p){ zero(); return mir_ptr::operator=(_p); }
- __inline void zero()
- {
- if (data) SecureZeroMemory(data, mir_strlen(data));
+ __inline void zero() {
+ if (data) SecureZeroMemory(data, mir_strlen(data));
}
};
@@ -105,14 +104,11 @@ public: __inline explicit pass_ptrW(wchar_t *_p) : mir_ptr(_p) {}
__inline ~pass_ptrW() { zero(); }
__inline wchar_t* operator = (wchar_t *_p){ zero(); return mir_ptr::operator=(_p); }
- __inline void zero()
- {
- if (data) SecureZeroMemory(data, mir_wstrlen(data)*sizeof(wchar_t));
+ __inline void zero() {
+ if (data) SecureZeroMemory(data, mir_wstrlen(data)*sizeof(wchar_t));
}
};
-typedef pass_ptrW pass_ptrT;
-
///////////////////////////////////////////////////////////////////////////////
// mir_cslockfull - controllable locker for the critical sections
diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc index 3ba18ad5cb..b501959882 100644 --- a/protocols/Tox/res/resource.rc +++ b/protocols/Tox/res/resource.rc @@ -99,8 +99,6 @@ BEGIN EDITTEXT IDC_TOXID,81,15,217,12,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
LTEXT "Name:",IDC_STATIC,12,48,69,11
EDITTEXT IDC_NAME,81,46,217,12,ES_AUTOHSCROLL
- LTEXT "Password:",IDC_STATIC,12,64,69,8,NOT WS_VISIBLE
- EDITTEXT IDC_PASSWORD,81,62,217,12,ES_PASSWORD | ES_AUTOHSCROLL | NOT WS_VISIBLE
LTEXT "Default group:",IDC_STATIC,12,80,69,12
EDITTEXT IDC_GROUP,81,78,217,12,ES_AUTOHSCROLL
PUSHBUTTON "Create Tox profile",IDC_PROFILE_NEW,81,30,107,13
@@ -121,6 +119,9 @@ BEGIN "Button",BS_AUTOCHECKBOX | WS_TABSTOP,24,125,274,10
CONTROL "Enable local network peer discovery",IDC_ENABLE_LOCALDISCOVERY,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,153,286,10
+ PUSHBUTTON "Remove password",IDC_PASSWORD_REMOVE,81,62,107,13
+ PUSHBUTTON "Change password",IDC_PASSWORD_CHANGE,191,62,107,13
+ PUSHBUTTON "Set password",IDC_PASSWORD_CREATE,136,62,107,13
END
IDD_SEARCH DIALOGEX 0, 0, 109, 113
@@ -141,16 +142,15 @@ BEGIN EDITTEXT IDC_DNS_ID,2,13,217,14,ES_AUTOHSCROLL
END
-IDD_PASSWORD_ENTER DIALOGEX 0, 0, 211, 76
+IDD_PASSWORD_ENTER DIALOGEX 0, 0, 211, 70
STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_CONTROLPARENT | WS_EX_APPWINDOW
CAPTION "Enter password"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
EDITTEXT IDC_PASSWORD,7,24,199,12,ES_PASSWORD | ES_AUTOHSCROLL
- CONTROL "Save password",IDC_SAVEPERMANENTLY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,40,199,12
- DEFPUSHBUTTON "OK",IDOK,101,57,50,14
- PUSHBUTTON "Cancel",IDCANCEL,156,57,50,14
+ DEFPUSHBUTTON "OK",IDOK,101,51,50,14
+ PUSHBUTTON "Cancel",IDCANCEL,156,51,50,14
LTEXT "Tox profile is encrypted. Enter the password to continue.",IDC_STATIC,7,5,199,18
END
@@ -198,6 +198,21 @@ BEGIN LTEXT "",IDC_PASSWORD_VALIDATION,7,81,197,8
END
+IDD_PASSWORD_CREATE DIALOGEX 0, 0, 209, 84
+STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_CONTROLPARENT | WS_EX_APPWINDOW
+CAPTION "Set password"
+FONT 8, "MS Shell Dlg", 0, 0, 0x1
+BEGIN
+ DEFPUSHBUTTON "OK",IDOK,101,65,50,14
+ PUSHBUTTON "Cancel",IDCANCEL,154,65,50,14
+ EDITTEXT IDC_PASSWORD_NEW,7,14,197,12,ES_PASSWORD | ES_AUTOHSCROLL
+ LTEXT "New password:",-1,7,4,197,8
+ EDITTEXT IDC_PASSWORD_CONFIRM,7,39,197,12,ES_PASSWORD | ES_AUTOHSCROLL
+ LTEXT "Confirm password:",-1,7,29,197,8
+ LTEXT "",IDC_PASSWORD_VALIDATION,7,55,197,8
+END
+
/////////////////////////////////////////////////////////////////////////////
//
@@ -241,7 +256,7 @@ BEGIN BEGIN
RIGHTMARGIN, 206
VERTGUIDE, 7
- BOTTOMMARGIN, 71
+ BOTTOMMARGIN, 65
END
IDD_OPTIONS_NODES, DIALOG
@@ -269,6 +284,13 @@ BEGIN VERTGUIDE, 7
BOTTOMMARGIN, 107
END
+
+ IDD_PASSWORD_CREATE, DIALOG
+ BEGIN
+ RIGHTMARGIN, 204
+ VERTGUIDE, 7
+ BOTTOMMARGIN, 79
+ END
END
#endif // APSTUDIO_INVOKED
@@ -293,6 +315,16 @@ BEGIN 0
END
+IDD_PASSWORD_CHANGE2 AFX_DIALOG_LAYOUT
+BEGIN
+ 0
+END
+
+IDD_PASSWORD_CREATE AFX_DIALOG_LAYOUT
+BEGIN
+ 0
+END
+
#endif // English resources
/////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Tox/src/resource.h b/protocols/Tox/src/resource.h index bc2b71876f..4ea9d24d31 100644 --- a/protocols/Tox/src/resource.h +++ b/protocols/Tox/src/resource.h @@ -10,9 +10,10 @@ #define IDD_SEARCH 105
#define IDD_OPTIONS_MAIN 106
#define IDD_OPTIONS_NODES 107
+#define IDD_PASSWORD_CHANGE2 107
#define IDD_ADDNODE 108
#define IDD_NODE_EDITOR 109
-
+#define IDD_PASSWORD_CREATE 110
#define IDC_EDITSCR 174
#define IDC_TOXID 1001
#define IDC_CLIPBOARD 1002
@@ -33,8 +34,12 @@ #define IDC_ADDNODE 1016
#define IDC_IPV4 1017
#define IDC_IPV6 1018
+#define IDC_PASSWORD_REMOVE 1018
#define IDC_PORT 1019
+#define IDC_PASSWORD_CHANGE 1019
#define IDC_PKEY 1020
+#define IDC_PASSWORD_CHANGE2 1020
+#define IDC_PASSWORD_CREATE 1020
#define IDC_UPDATENODES 1021
#define IDC_MAXCONNECTRETRIES 1025
#define IDC_MAXRECONNECTRETRIES 1026
@@ -44,13 +49,11 @@ #define IDC_PASSWORD_CONFIRM 1030
#define IDC_PASSWORD_VALIDATION 1031
-
-
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 117
+#define _APS_NEXT_RESOURCE_VALUE 118
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1032
#define _APS_NEXT_SYMED_VALUE 101
diff --git a/protocols/Tox/src/stdafx.h b/protocols/Tox/src/stdafx.h index 86da917de9..281c585bc5 100644 --- a/protocols/Tox/src/stdafx.h +++ b/protocols/Tox/src/stdafx.h @@ -7,13 +7,6 @@ #include <commctrl.h>
#include <msapi/comptr.h>
-#include <mmreg.h>
-#include <MMDeviceAPI.h>
-
-#define EXIT_ON_ERROR(hres) if (FAILED(hres)) { goto Exit; }
-
-DEFINE_PROPERTYKEY(PKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 14);
-
#include <vector>
#include <regex>
#include <map>
diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp index fb7834f1db..866a0dbd3b 100644 --- a/protocols/Tox/src/tox_accounts.cpp +++ b/protocols/Tox/src/tox_accounts.cpp @@ -41,13 +41,13 @@ int CToxProto::OnAccountLoaded(WPARAM, LPARAM) int CToxProto::OnAccountRenamed(WPARAM, LPARAM)
{
- mir_cslock lock(profileLock);
+ mir_cslock lock(m_profileLock);
ptrW newPath(GetToxProfilePath());
wchar_t oldPath[MAX_PATH];
- mir_snwprintf(oldPath, MAX_PATH, L"%s\\%s.tox", VARSW(L"%miranda_userdata%"), wszAccountName);
+ mir_snwprintf(oldPath, MAX_PATH, L"%s\\%s.tox", VARSW(L"%miranda_userdata%"), m_accountName);
_wrename(oldPath, newPath);
- wszAccountName = mir_wstrdup(m_tszUserName);
+ m_accountName = mir_wstrdup(m_tszUserName);
return 0;
}
diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp index 3e41c796f6..9d234b1dd8 100644 --- a/protocols/Tox/src/tox_avatars.cpp +++ b/protocols/Tox/src/tox_avatars.cpp @@ -77,7 +77,7 @@ void CToxProto::SetToxAvatar(const wchar_t* path) debugLogA(__FUNCTION__": send avatar to friend (%d)", friendNumber);
TOX_ERR_FILE_SEND error;
- uint32_t fileNumber = tox_file_send(toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, length, hash, nullptr, 0, &error);
+ uint32_t fileNumber = tox_file_send(m_toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, length, hash, nullptr, 0, &error);
if (error != TOX_ERR_FILE_SEND_OK) {
mir_free(data);
debugLogA(__FUNCTION__": failed to set new avatar (%d)", error);
@@ -173,7 +173,7 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam) debugLogA(__FUNCTION__": unset avatar for friend (%d)", friendNumber);
TOX_ERR_FILE_SEND error;
- tox_file_send(toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, 0, nullptr, nullptr, 0, &error);
+ tox_file_send(m_toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, 0, nullptr, nullptr, 0, &error);
if (error != TOX_ERR_FILE_SEND_OK) {
debugLogA(__FUNCTION__": failed to unset avatar (%d)", error);
return 0;
diff --git a/protocols/Tox/src/tox_bootstrap.cpp b/protocols/Tox/src/tox_bootstrap.cpp index 5f1ae93dc1..f144c0af16 100644 --- a/protocols/Tox/src/tox_bootstrap.cpp +++ b/protocols/Tox/src/tox_bootstrap.cpp @@ -2,7 +2,7 @@ void CToxProto::BootstrapUdpNode(Tox *tox, const char *address, int port, const char *hexKey) { - if (!toxThread) + if (!m_toxThread) return; if (address == nullptr || hexKey == nullptr) @@ -16,7 +16,7 @@ void CToxProto::BootstrapUdpNode(Tox *tox, const char *address, int port, const void CToxProto::BootstrapTcpRelay(Tox *tox, const char *address, int port, const char *hexKey) { - if (!toxThread) + if (!m_toxThread) return; if (address == nullptr || hexKey == nullptr) diff --git a/protocols/Tox/src/tox_connection.cpp b/protocols/Tox/src/tox_connection.cpp index 4c578a9696..80a84b74c0 100644 --- a/protocols/Tox/src/tox_connection.cpp +++ b/protocols/Tox/src/tox_connection.cpp @@ -2,7 +2,7 @@ bool CToxProto::IsOnline() { - return toxThread && m_iStatus >= ID_STATUS_ONLINE; + return m_toxThread && m_iStatus >= ID_STATUS_ONLINE; } void CToxProto::TryConnect(Tox *tox) @@ -99,7 +99,7 @@ void CToxProto::PollingThread(void*) } tox_options_free(options); - this->toxThread = &toxThread; + m_toxThread = &toxThread; InitToxCore(toxThread.Tox()); BootstrapNodes(toxThread.Tox()); ForkThread(&CToxProto::CheckingThread, toxThread.Tox()); @@ -113,7 +113,7 @@ void CToxProto::PollingThread(void*) } UninitToxCore(toxThread.Tox()); - this->toxThread = nullptr; + m_toxThread = nullptr; hPollingThread = nullptr; debugLogA(__FUNCTION__": leaving"); diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index 3b76b37407..4e1ee4abf4 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -96,8 +96,8 @@ MCONTACT CToxProto::AddContact(const char *address, const char *nick, const char if (mir_strlen(dnsId))
setWString(hContact, TOX_SETTINGS_DNS, ptrW(mir_utf8decodeW(dnsId)));
- if (wszGroup)
- db_set_ws(hContact, "CList", "Group", wszGroup);
+ if (m_defaultGroup)
+ db_set_ws(hContact, "CList", "Group", m_defaultGroup);
setByte(hContact, "Auth", 1);
setByte(hContact, "Grant", 1);
@@ -112,7 +112,7 @@ uint32_t CToxProto::GetToxFriendNumber(MCONTACT hContact) {
ToxBinAddress pubKey(ptrA(getStringA(hContact, TOX_SETTINGS_ID)));
TOX_ERR_FRIEND_BY_PUBLIC_KEY error;
- uint32_t friendNumber = tox_friend_by_public_key(toxThread->Tox(), pubKey.GetPubKey(), &error);
+ uint32_t friendNumber = tox_friend_by_public_key(m_toxThread->Tox(), pubKey.GetPubKey(), &error);
if (error != TOX_ERR_FRIEND_BY_PUBLIC_KEY_OK)
debugLogA(__FUNCTION__": failed to get friend number (%d)", error);
return friendNumber;
@@ -123,7 +123,7 @@ void CToxProto::LoadFriendList(Tox *tox) size_t count = tox_self_get_friend_list_size(tox);
if (count > 0) {
uint32_t *friends = (uint32_t*)mir_alloc(count * sizeof(uint32_t));
- tox_self_get_friend_list(toxThread->Tox(), friends);
+ tox_self_get_friend_list(m_toxThread->Tox(), friends);
for (size_t i = 0; i < count; i++) {
uint32_t friendNumber = friends[i];
@@ -139,13 +139,13 @@ void CToxProto::LoadFriendList(Tox *tox) TOX_ERR_FRIEND_QUERY getNameResult;
uint8_t nick[TOX_MAX_NAME_LENGTH] = { 0 };
- if (tox_friend_get_name(toxThread->Tox(), friendNumber, nick, &getNameResult))
+ if (tox_friend_get_name(m_toxThread->Tox(), friendNumber, nick, &getNameResult))
setWString(hContact, "Nick", ptrW(mir_utf8decodeW((char*)nick)));
else
debugLogA(__FUNCTION__": failed to get friend name (%d)", getNameResult);
TOX_ERR_FRIEND_GET_LAST_ONLINE getLastOnlineResult;
- uint64_t timestamp = tox_friend_get_last_online(toxThread->Tox(), friendNumber, &getLastOnlineResult);
+ uint64_t timestamp = tox_friend_get_last_online(m_toxThread->Tox(), friendNumber, &getLastOnlineResult);
if (getLastOnlineResult == TOX_ERR_FRIEND_GET_LAST_ONLINE_OK)
setDword(hContact, "LastEventDateTS", timestamp);
else
@@ -166,7 +166,7 @@ INT_PTR CToxProto::OnRequestAuth(WPARAM hContact, LPARAM lParam) ToxBinAddress address(ptrA(getStringA(hContact, TOX_SETTINGS_ID)));
TOX_ERR_FRIEND_ADD addFriendResult;
- int32_t friendNumber = tox_friend_add(toxThread->Tox(), address, (uint8_t*)reason, length, &addFriendResult);
+ int32_t friendNumber = tox_friend_add(m_toxThread->Tox(), address, (uint8_t*)reason, length, &addFriendResult);
if (addFriendResult != TOX_ERR_FRIEND_ADD_OK) {
debugLogA(__FUNCTION__": failed to request auth(%d)", addFriendResult);
return addFriendResult;
@@ -192,7 +192,7 @@ INT_PTR CToxProto::OnGrantAuth(WPARAM hContact, LPARAM) ToxBinAddress pubKey(ptrA(getStringA(hContact, TOX_SETTINGS_ID)));
TOX_ERR_FRIEND_ADD error;
- tox_friend_add_norequest(toxThread->Tox(), pubKey, &error);
+ tox_friend_add_norequest(m_toxThread->Tox(), pubKey, &error);
if (error != TOX_ERR_FRIEND_ADD_OK) {
debugLogA(__FUNCTION__": failed to grant auth (%d)", error);
return error;
@@ -201,7 +201,7 @@ INT_PTR CToxProto::OnGrantAuth(WPARAM hContact, LPARAM) db_unset(hContact, "CList", "NotOnList");
delSetting(hContact, "Grant");
- SaveToxProfile(toxThread->Tox());
+ SaveToxProfile(m_toxThread->Tox());
return 0;
}
@@ -214,21 +214,12 @@ int CToxProto::OnContactDeleted(MCONTACT hContact, LPARAM) if (!isChatRoom(hContact)) {
int32_t friendNumber = GetToxFriendNumber(hContact);
TOX_ERR_FRIEND_DELETE error;
- if (!tox_friend_delete(toxThread->Tox(), friendNumber, &error)) {
+ if (!tox_friend_delete(m_toxThread->Tox(), friendNumber, &error)) {
debugLogA(__FUNCTION__": failed to delete friend (%d)", error);
return error;
}
- SaveToxProfile(toxThread->Tox());
+ SaveToxProfile(m_toxThread->Tox());
}
- /*else
- {
- OnLeaveChatRoom(hContact, 0);
- int groupNumber = 0; // ???
- if (groupNumber == TOX_ERROR || tox_del_groupchat(tox, groupNumber) == TOX_ERROR)
- {
- return 1;
- }
- }*/
return 0;
}
@@ -339,7 +330,7 @@ void CToxProto::OnConnectionStatusChanged(Tox *tox, uint32_t friendNumber, TOX_C proto->debugLogA(__FUNCTION__": send avatar to friend (%d)", friendNumber);
TOX_ERR_FILE_SEND error;
- uint32_t fileNumber = tox_file_send(proto->toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, length, hash, nullptr, 0, &error);
+ uint32_t fileNumber = tox_file_send(proto->m_toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, length, hash, nullptr, 0, &error);
if (error != TOX_ERR_FILE_SEND_OK) {
Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to set new avatar");
fclose(hFile);
@@ -355,7 +346,7 @@ void CToxProto::OnConnectionStatusChanged(Tox *tox, uint32_t friendNumber, TOX_C }
else {
proto->debugLogA(__FUNCTION__": unset avatar for friend (%d)", friendNumber);
- tox_file_send(proto->toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, 0, nullptr, nullptr, 0, nullptr);
+ tox_file_send(proto->m_toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, 0, nullptr, nullptr, 0, nullptr);
}
}
diff --git a/protocols/Tox/src/tox_menus.cpp b/protocols/Tox/src/tox_menus.cpp index ffa47b8621..34b3047fb4 100644 --- a/protocols/Tox/src/tox_menus.cpp +++ b/protocols/Tox/src/tox_menus.cpp @@ -61,7 +61,17 @@ void CToxProto::InitContactMenu() int CToxProto::PrebuildStatusMenu(WPARAM, LPARAM)
{
bool isOnline = IsOnline();
+ Menu_EnableItem(StatusMenuItems[SMI_PASSWORD], isOnline);
+ Menu_EnableItem(StatusMenuItems[SMI_PASSWORD_CREATE], isOnline);
Menu_EnableItem(StatusMenuItems[SMI_PASSWORD_CHANGE], isOnline);
+ Menu_EnableItem(StatusMenuItems[SMI_PASSWORD_REMOVE], isOnline);
+
+ pass_ptrW password(getWStringA(TOX_SETTINGS_PASSWORD));
+ bool passwordExists = mir_wstrlen(password) > 0;
+ Menu_ShowItem(StatusMenuItems[SMI_PASSWORD_CREATE], !passwordExists);
+ Menu_ShowItem(StatusMenuItems[SMI_PASSWORD_CHANGE], passwordExists);
+ Menu_ShowItem(StatusMenuItems[SMI_PASSWORD_REMOVE], passwordExists);
+
return 0;
}
@@ -80,12 +90,32 @@ int CToxProto::OnInitStatusMenu() mi.position = SMI_POSITION + SMI_TOXID_COPY;
StatusMenuItems[SMI_TOXID_COPY] = Menu_AddProtoMenuItem(&mi, m_szModuleName);
+ // Password
+ mi.pszService = nullptr;
+ mi.name.w = LPGENW("Password");
+ StatusMenuItems[SMI_PASSWORD] = Menu_AddProtoMenuItem(&mi, m_szModuleName);
+ mi.root = StatusMenuItems[SMI_PASSWORD];
+
+ // Create password command
+ mi.pszService = "/CreatePassword";
+ CreateProtoService(mi.pszService, &CToxProto::OnCreatePassword);
+ mi.name.w = LPGENW("Create password");
+ mi.position = SMI_PASSWORD_CREATE;
+ StatusMenuItems[SMI_PASSWORD_CREATE] = Menu_AddProtoMenuItem(&mi, m_szModuleName);
+
// Change password command
mi.pszService = "/ChangePassword";
CreateProtoService(mi.pszService, &CToxProto::OnChangePassword);
mi.name.w = LPGENW("Change password");
- mi.position = SMI_POSITION + SMI_PASSWORD_CHANGE;
+ mi.position = SMI_PASSWORD_CHANGE;
StatusMenuItems[SMI_PASSWORD_CHANGE] = Menu_AddProtoMenuItem(&mi, m_szModuleName);
+ // Remove password command
+ mi.pszService = "/RemovePassword";
+ CreateProtoService(mi.pszService, &CToxProto::OnRemovePassword);
+ mi.name.w = LPGENW("Remove password");
+ mi.position = SMI_PASSWORD_REMOVE;
+ StatusMenuItems[SMI_PASSWORD_REMOVE] = Menu_AddProtoMenuItem(&mi, m_szModuleName);
+
return 0;
}
diff --git a/protocols/Tox/src/tox_menus.h b/protocols/Tox/src/tox_menus.h index 8c23f6dd28..85b9f55055 100644 --- a/protocols/Tox/src/tox_menus.h +++ b/protocols/Tox/src/tox_menus.h @@ -15,7 +15,10 @@ enum CMI_MENU_ITEMS enum SMI_MENU_ITEMS
{
SMI_TOXID_COPY,
+ SMI_PASSWORD,
+ SMI_PASSWORD_CREATE,
SMI_PASSWORD_CHANGE,
+ SMI_PASSWORD_REMOVE,
SMI_MAX // this item shall be the last one
};
diff --git a/protocols/Tox/src/tox_messages.cpp b/protocols/Tox/src/tox_messages.cpp index 2fd5eb761b..0d7ad78b04 100644 --- a/protocols/Tox/src/tox_messages.cpp +++ b/protocols/Tox/src/tox_messages.cpp @@ -69,7 +69,7 @@ void CToxProto::SendMessageAsync(void *arg) }
TOX_ERR_FRIEND_SEND_MESSAGE sendError;
- int messageNumber = tox_friend_send_message(toxThread->Tox(), friendNumber, type, msg, msgLen, &sendError);
+ int messageNumber = tox_friend_send_message(m_toxThread->Tox(), friendNumber, type, msg, msgLen, &sendError);
if (sendError != TOX_ERR_FRIEND_SEND_MESSAGE_OK) {
debugLogA(__FUNCTION__": failed to send message for %d (%d)", friendNumber, sendError);
ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)param->hMessage, (LPARAM)_T2A(ToxErrorToString(sendError)));
@@ -149,7 +149,7 @@ void CToxProto::GetStatusMessageAsync(void* arg) }
TOX_ERR_FRIEND_QUERY error;
- size_t size = tox_friend_get_status_message_size(toxThread->Tox(), friendNumber, &error);
+ size_t size = tox_friend_get_status_message_size(m_toxThread->Tox(), friendNumber, &error);
if (error != TOX_ERR_FRIEND_QUERY::TOX_ERR_FRIEND_QUERY_OK) {
debugLogA(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error);
ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_FAILED, (HANDLE)hContact, 0);
@@ -157,7 +157,7 @@ void CToxProto::GetStatusMessageAsync(void* arg) }
ptrA statusMessage((char*)mir_calloc(size + 1));
- if (!tox_friend_get_status_message(toxThread->Tox(), friendNumber, (uint8_t*)(char*)statusMessage, &error)) {
+ if (!tox_friend_get_status_message(m_toxThread->Tox(), friendNumber, (uint8_t*)(char*)statusMessage, &error)) {
debugLogA(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error);
ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_FAILED, (HANDLE)hContact, 0);
return;
@@ -175,7 +175,7 @@ int CToxProto::OnUserIsTyping(MCONTACT hContact, int type) return 0;
TOX_ERR_SET_TYPING error;
- if (!tox_self_set_typing(toxThread->Tox(), friendNumber, type == PROTOTYPE_SELFTYPING_ON, &error))
+ if (!tox_self_set_typing(m_toxThread->Tox(), friendNumber, type == PROTOTYPE_SELFTYPING_ON, &error))
debugLogA(__FUNCTION__": failed to send typing (%d)", error);
return 0;
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index 08a4ab8cdc..71353d3263 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -5,7 +5,8 @@ CToxOptionsMain::CToxOptionsMain(CToxProto *proto, int idDialog) m_toxAddress(this, IDC_TOXID), m_toxAddressCopy(this, IDC_CLIPBOARD),
m_profileCreate(this, IDC_PROFILE_NEW), m_profileImport(this, IDC_PROFILE_IMPORT),
m_profileExport(this, IDC_PROFILE_EXPORT), m_nickname(this, IDC_NAME),
- m_password(this, IDC_PASSWORD), m_group(this, IDC_GROUP),
+ m_passwordCreate(this, IDC_PASSWORD_CREATE), m_passwordChange(this, IDC_PASSWORD_CHANGE),
+ m_passwordRemove(this, IDC_PASSWORD_REMOVE), m_group(this, IDC_GROUP),
m_enableUdp(this, IDC_ENABLE_UDP), m_enableUdpHolePunching(this, IDC_ENABLE_HOLEPUNCHING),
m_enableIPv6(this, IDC_ENABLE_IPV6), m_enableLocalDiscovery(this, IDC_ENABLE_LOCALDISCOVERY),
m_maxConnectRetries(this, IDC_MAXCONNECTRETRIES), m_maxConnectRetriesSpin(this, IDC_MAXCONNECTRETRIESSPIN),
@@ -13,7 +14,6 @@ CToxOptionsMain::CToxOptionsMain(CToxProto *proto, int idDialog) {
CreateLink(m_toxAddress, TOX_SETTINGS_ID, L"");
CreateLink(m_nickname, "Nick", L"");
- CreateLink(m_password, "Password", L"");
CreateLink(m_group, TOX_SETTINGS_GROUP, L"Tox");
CreateLink(m_enableUdp, "EnableUDP", DBVT_BYTE, TRUE);
CreateLink(m_enableUdpHolePunching, "EnableUDPHolePunching", DBVT_BYTE, TRUE);
@@ -25,6 +25,10 @@ CToxOptionsMain::CToxOptionsMain(CToxProto *proto, int idDialog) CreateLink(m_maxReconnectRetries, "MaxReconnectRetries", DBVT_BYTE, TOX_MAX_RECONNECT_RETRIES);
}
+ m_passwordCreate.OnClick = Callback(this, &CToxOptionsMain::PasswordCreate_OnClick);
+ m_passwordChange.OnClick = Callback(this, &CToxOptionsMain::PasswordChange_OnClick);
+ m_passwordRemove.OnClick = Callback(this, &CToxOptionsMain::PasswordRemove_OnClick);
+
m_enableUdp.OnChange = Callback(this, &CToxOptionsMain::EnableUdp_OnClick);
m_enableUdpHolePunching.Enable(m_enableUdp.GetState());
@@ -42,17 +46,26 @@ void CToxOptionsMain::OnInitDialog() if (CToxProto::IsFileExists(profilePath)) {
m_toxAddress.Enable();
- ShowWindow(m_profileCreate.GetHwnd(), FALSE);
- ShowWindow(m_profileImport.GetHwnd(), FALSE);
+ m_profileCreate.Hide();
+ m_profileImport.Hide();
- ShowWindow(m_toxAddressCopy.GetHwnd(), TRUE);
- ShowWindow(m_profileExport.GetHwnd(), TRUE);
+ m_toxAddressCopy.Show();
+ m_profileExport.Show();
}
- SendMessage(m_toxAddress.GetHwnd(), EM_LIMITTEXT, TOX_ADDRESS_SIZE * 2, 0);
- SendMessage(m_nickname.GetHwnd(), EM_LIMITTEXT, TOX_MAX_NAME_LENGTH, 0);
- SendMessage(m_password.GetHwnd(), EM_LIMITTEXT, 32, 0);
- SendMessage(m_group.GetHwnd(), EM_LIMITTEXT, 64, 0);
+ m_passwordCreate.Enable(m_proto->IsOnline());
+ m_passwordChange.Enable(m_proto->IsOnline());
+ m_passwordRemove.Enable(m_proto->IsOnline());
+
+ pass_ptrW password(m_proto->getWStringA(TOX_SETTINGS_PASSWORD));
+ bool passwordExists = mir_wstrlen(password) > 0;
+ m_passwordCreate.Show(!passwordExists);
+ m_passwordChange.Show(passwordExists);
+ m_passwordRemove.Show(passwordExists);
+
+ m_toxAddress.SetMaxLength(TOX_ADDRESS_SIZE * 2);
+ m_nickname.SetMaxLength(TOX_MAX_NAME_LENGTH);
+ m_group.SetMaxLength(64);
m_maxConnectRetriesSpin.SetRange(255, 1);
m_maxConnectRetriesSpin.SetPosition(m_proto->getByte("MaxConnectRetries", TOX_MAX_CONNECT_RETRIES));
@@ -60,6 +73,26 @@ void CToxOptionsMain::OnInitDialog() m_maxReconnectRetriesSpin.SetPosition(m_proto->getByte("MaxReconnectRetries", TOX_MAX_RECONNECT_RETRIES));
}
+void CToxOptionsMain::PasswordCreate_OnClick(CCtrlButton*)
+{
+ m_proto->OnCreatePassword(0, 0);
+}
+
+void CToxOptionsMain::PasswordChange_OnClick(CCtrlButton*)
+{
+ m_proto->OnChangePassword(0, 0);
+}
+
+void CToxOptionsMain::PasswordRemove_OnClick(CCtrlButton*)
+{
+ m_proto->OnRemovePassword(0, 0);
+ pass_ptrW password(m_proto->getWStringA(TOX_SETTINGS_PASSWORD));
+ bool passwordExists = mir_wstrlen(password) > 0;
+ m_passwordCreate.Show(!passwordExists);
+ m_passwordChange.Show(passwordExists);
+ m_passwordRemove.Show(passwordExists);
+}
+
void CToxOptionsMain::EnableUdp_OnClick(CCtrlBase*)
{
m_enableUdpHolePunching.Enable(m_enableUdp.GetState());
@@ -105,7 +138,6 @@ void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*) m_toxAddress.SetTextA(ptrA(m_proto->getStringA(TOX_SETTINGS_ID)));
m_nickname.SetText(ptrW(m_proto->getWStringA("Nick")));
- m_password.SetText(ptrW(m_proto->getWStringA("Password")));
ShowWindow(m_profileCreate.GetHwnd(), FALSE);
ShowWindow(m_profileImport.GetHwnd(), FALSE);
@@ -200,8 +232,8 @@ void CToxOptionsMain::ProfileExport_OnClick(CCtrlButton*) void CToxOptionsMain::OnApply()
{
ptrW group(m_group.GetText());
- if (mir_wstrcmp(group, m_proto->wszGroup)) {
- m_proto->wszGroup = mir_wstrdup(group);
+ if (mir_wstrcmp(group, m_proto->m_defaultGroup)) {
+ m_proto->m_defaultGroup = mir_wstrdup(group);
Clist_GroupCreate(0, group);
}
@@ -209,9 +241,9 @@ void CToxOptionsMain::OnApply() CallProtoService(m_proto->m_szModuleName, PS_SETMYNICKNAME, SMNN_UNICODE, (LPARAM)ptrW(m_nickname.GetText()));
// todo: add checkbox
- m_proto->setWString("Password", pass_ptrT(m_password.GetText()));
+ //m_proto->setWString("Password", pass_ptrW(m_password.GetText()));
- m_proto->SaveToxProfile(m_proto->toxThread->Tox());
+ m_proto->SaveToxProfile(m_proto->m_toxThread->Tox());
}
}
diff --git a/protocols/Tox/src/tox_options.h b/protocols/Tox/src/tox_options.h index 011aaf6b76..5a85edea61 100644 --- a/protocols/Tox/src/tox_options.h +++ b/protocols/Tox/src/tox_options.h @@ -13,9 +13,12 @@ private: CCtrlButton m_profileExport;
CCtrlEdit m_nickname;
- CCtrlEdit m_password;
CCtrlEdit m_group;
+ CCtrlButton m_passwordCreate;
+ CCtrlButton m_passwordChange;
+ CCtrlButton m_passwordRemove;
+
CCtrlCheck m_enableUdp;
CCtrlCheck m_enableUdpHolePunching;
CCtrlCheck m_enableIPv6;
@@ -29,6 +32,10 @@ private: protected:
void OnInitDialog();
+ void PasswordCreate_OnClick(CCtrlButton*);
+ void PasswordChange_OnClick(CCtrlButton*);
+ void PasswordRemove_OnClick(CCtrlButton*);
+
void EnableUdp_OnClick(CCtrlBase*);
void ToxAddressCopy_OnClick(CCtrlButton*);
@@ -54,29 +61,6 @@ public: /////////////////////////////////////////////////////////////////////////////////
-class CToxOptionsMultimedia : public CToxDlgBase
-{
-private:
- typedef CToxDlgBase CSuper;
-
- CCtrlCombo m_audioInput;
- CCtrlCombo m_audioOutput;
-
-protected:
- void EnumDevices(CCtrlCombo &combo, IMMDeviceEnumerator *pEnumerator, EDataFlow dataFlow, const char* setting);
-
- void OnInitDialog();
- void OnApply();
- void OnDestroy();
-
-public:
- CToxOptionsMultimedia(CToxProto *proto);
-
- static CDlgBase *CreateOptionsPage(void *param) { return new CToxOptionsMultimedia((CToxProto*)param); }
-};
-
-/////////////////////////////////////////////////////////////////////////////////
-
class CToxNodeEditor : public CDlgBase
{
private:
diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index 21198eb7f1..77f9285050 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -20,12 +20,12 @@ static INT_PTR CALLBACK EnterPassword(void *param) {
CToxProto *proto = (CToxProto*)param;
- pass_ptrW password(proto->getWStringA("Password"));
+ pass_ptrW password(proto->getWStringA(TOX_SETTINGS_PASSWORD));
if (mir_wstrlen(password) == 0) {
CToxEnterPasswordDlg passwordDlg(proto);
if (!passwordDlg.DoModal())
return 0;
- password = passwordDlg.GetPassword();
+ password = proto->getWStringA(TOX_SETTINGS_PASSWORD);
}
return (INT_PTR)password.detach();
}
@@ -34,7 +34,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) {
debugLogA(__FUNCTION__": loading tox profile");
- mir_cslock locker(profileLock);
+ mir_cslock lock(m_profileLock);
ptrW profilePath(GetToxProfilePath());
if (!IsFileExists(profilePath))
@@ -83,6 +83,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) if (!tox_pass_decrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), decryptedData, &coreDecryptError)) {
ShowNotification(TranslateT("Unable to decrypt Tox profile"), MB_ICONERROR);
debugLogA(__FUNCTION__": failed to decrypt tox profile (%d)", coreDecryptError);
+ delSetting(TOX_SETTINGS_PASSWORD);
mir_free(data);
return false;
}
@@ -103,13 +104,13 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) void CToxProto::SaveToxProfile(Tox *tox)
{
- mir_cslock locker(profileLock);
+ mir_cslock lock(m_profileLock);
size_t size = tox_get_savedata_size(tox);
uint8_t *data = (uint8_t*)mir_calloc(size);
tox_get_savedata(tox, data);
- pass_ptrA password(mir_utf8encodeW(pass_ptrT(getWStringA("Password"))));
+ pass_ptrA password(mir_utf8encodeW(pass_ptrW(getWStringA(TOX_SETTINGS_PASSWORD))));
if (password && mir_strlen(password))
{
TOX_ERR_ENCRYPTION coreEncryptError;
@@ -165,10 +166,109 @@ INT_PTR CToxProto::OnCopyToxID(WPARAM, LPARAM) return 0;
}
+INT_PTR CToxProto::OnCreatePassword(WPARAM, LPARAM)
+{
+ pass_ptrW password(getWStringA(TOX_SETTINGS_PASSWORD));
+ CToxCreatePasswordDlg passwordDlg(this);
+ passwordDlg.DoModal();
+ return 0;
+}
+
INT_PTR CToxProto::OnChangePassword(WPARAM, LPARAM)
{
CToxChangePasswordDlg passwordDlg(this);
- return passwordDlg.DoModal();
+ passwordDlg.DoModal();
+ return 0;
+}
+
+INT_PTR CToxProto::OnRemovePassword(WPARAM, LPARAM)
+{
+ const wchar_t *message = TranslateT("Removing the password will lead to decryption of the profile.\r\nAre you sure to remove password?");
+ int result = MessageBox(NULL, message, TranslateT("Remove password"), MB_YESNO | MB_ICONQUESTION);
+ if (result == IDYES) {
+ delSetting(TOX_SETTINGS_PASSWORD);
+ SaveToxProfile(m_toxThread->Tox());
+ }
+ return 0;
+}
+
+/* ENTER PASSWORD */
+
+CToxEnterPasswordDlg::CToxEnterPasswordDlg(CToxProto *proto)
+ : CToxDlgBase(proto, IDD_PASSWORD_ENTER, false),
+ m_password(this, IDC_PASSWORD),
+ m_ok(this, IDOK)
+{
+ m_password.OnChange = Callback(this, &CToxEnterPasswordDlg::Password_OnChange);
+ m_ok.OnClick = Callback(this, &CToxEnterPasswordDlg::OnOk);
+}
+
+void CToxEnterPasswordDlg::OnInitDialog()
+{
+ m_ok.Disable();
+}
+
+void CToxEnterPasswordDlg::Password_OnChange(CCtrlBase*)
+{
+ m_ok.Enable(GetWindowTextLength(m_password.GetHwnd()) != 0);
+}
+
+void CToxEnterPasswordDlg::OnOk(CCtrlButton*)
+{
+ m_proto->setWString(TOX_SETTINGS_PASSWORD, pass_ptrW(m_password.GetText()));
+ EndDialog(m_hwnd, 1);
+}
+
+/* CREATE PASSWORD */
+
+CToxCreatePasswordDlg::CToxCreatePasswordDlg(CToxProto *proto)
+ : CToxDlgBase(proto, IDD_PASSWORD_CREATE, false),
+ m_newPassword(this, IDC_PASSWORD_NEW),
+ m_confirmPassword(this, IDC_PASSWORD_CONFIRM),
+ m_passwordValidation(this, IDC_PASSWORD_VALIDATION),
+ m_ok(this, IDOK)
+{
+ m_newPassword.OnChange = Callback(this, &CToxCreatePasswordDlg::Password_OnChange);
+ m_confirmPassword.OnChange = Callback(this, &CToxCreatePasswordDlg::Password_OnChange);
+ m_ok.OnClick = Callback(this, &CToxCreatePasswordDlg::OnOk);
+}
+
+void CToxCreatePasswordDlg::OnInitDialog()
+{
+ LOGFONT lf;
+ HFONT hFont = (HFONT)m_passwordValidation.SendMsg(WM_GETFONT, 0, 0);
+ GetObject(hFont, sizeof(lf), &lf);
+ lf.lfWeight = FW_BOLD;
+ m_passwordValidation.SendMsg(WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);
+
+ m_ok.Disable();
+}
+
+void CToxCreatePasswordDlg::Password_OnChange(CCtrlBase*)
+{
+ pass_ptrW newPassword(m_newPassword.GetText());
+ if (mir_wstrlen(newPassword) == 0) {
+ m_ok.Disable();
+ m_passwordValidation.SetText(TranslateT("New password is empty"));
+ return;
+ }
+
+ pass_ptrW confirmPassword(m_confirmPassword.GetText());
+ if (mir_wstrcmp(newPassword, confirmPassword) != 0) {
+ m_ok.Disable();
+ m_passwordValidation.SetText(TranslateT("New password is not equal to confirmation"));
+ return;
+ }
+
+ m_passwordValidation.SetText(L"");
+ m_ok.Enable();
+}
+
+void CToxCreatePasswordDlg::OnOk(CCtrlButton*)
+{
+ m_proto->setWString(TOX_SETTINGS_PASSWORD, pass_ptrW(m_newPassword.GetText()));
+ m_proto->SaveToxProfile(m_proto->m_toxThread->Tox());
+ EndDialog(m_hwnd, 1);
}
/* CHANGE PASSWORD */
@@ -189,17 +289,20 @@ CToxChangePasswordDlg::CToxChangePasswordDlg(CToxProto *proto) void CToxChangePasswordDlg::OnInitDialog()
{
- pass_ptrW password(m_proto->getWStringA("Password"));
- if (mir_wstrlen(password) == 0)
- m_oldPassword.Disable();
+ LOGFONT lf;
+ HFONT hFont = (HFONT)m_passwordValidation.SendMsg(WM_GETFONT, 0, 0);
+ GetObject(hFont, sizeof(lf), &lf);
+ lf.lfWeight = FW_BOLD;
+ m_passwordValidation.SendMsg(WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);
+
m_ok.Disable();
}
void CToxChangePasswordDlg::Password_OnChange(CCtrlBase*)
{
- pass_ptrW password(m_proto->getWStringA("Password"));
+ pass_ptrW dbPassword(m_proto->getWStringA(TOX_SETTINGS_PASSWORD));
pass_ptrW oldPassword(m_oldPassword.GetText());
- if (mir_wstrlen(password) > 0 && mir_wstrcmp(password, oldPassword) != 0) {
+ if (mir_wstrlen(dbPassword) > 0 && mir_wstrcmp(dbPassword, oldPassword) != 0) {
m_ok.Disable();
m_passwordValidation.SetText(TranslateT("Old password is not valid"));
return;
@@ -225,48 +328,7 @@ void CToxChangePasswordDlg::Password_OnChange(CCtrlBase*) void CToxChangePasswordDlg::OnOk(CCtrlButton*)
{
- //if(m_proto->m_savePermanently.Enabled())
- m_proto->setWString("Password", pass_ptrT(m_newPassword.GetText()));
- m_proto->SaveToxProfile(m_proto->toxThread->Tox());
- EndDialog(m_hwnd, 1);
-}
-
-wchar_t* CToxChangePasswordDlg::GetPassword()
-{
- return m_newPassword.GetText();
-}
-
-/* ENTER PASSWORD */
-
-CToxEnterPasswordDlg::CToxEnterPasswordDlg(CToxProto *proto)
- : CToxDlgBase(proto, IDD_PASSWORD_ENTER, false),
- m_password(this, IDC_PASSWORD),
- m_savePermanently(this, IDC_SAVEPERMANENTLY),
- m_ok(this, IDOK)
-{
- //m_savePermanently
- m_password.OnChange = Callback(this, &CToxEnterPasswordDlg::Password_OnChange);
- m_ok.OnClick = Callback(this, &CToxEnterPasswordDlg::OnOk);
-}
-
-void CToxEnterPasswordDlg::OnInitDialog()
-{
- m_ok.Disable();
-}
-
-void CToxEnterPasswordDlg::Password_OnChange(CCtrlBase*)
-{
- m_ok.Enable(GetWindowTextLength(m_password.GetHwnd()) != 0);
-}
-
-void CToxEnterPasswordDlg::OnOk(CCtrlButton*)
-{
- if (m_savePermanently.Enabled())
- m_proto->setWString("Password", pass_ptrT(m_password.GetText()));
+ m_proto->setWString(TOX_SETTINGS_PASSWORD, pass_ptrW(m_newPassword.GetText()));
+ m_proto->SaveToxProfile(m_proto->m_toxThread->Tox());
EndDialog(m_hwnd, 1);
}
-
-wchar_t* CToxEnterPasswordDlg::GetPassword()
-{
- return m_password.GetText();
-}
diff --git a/protocols/Tox/src/tox_profile.h b/protocols/Tox/src/tox_profile.h index 446a4b7c03..4aedae071f 100644 --- a/protocols/Tox/src/tox_profile.h +++ b/protocols/Tox/src/tox_profile.h @@ -7,7 +7,6 @@ class CToxEnterPasswordDlg : public CToxDlgBase {
private:
CCtrlEdit m_password;
- CCtrlCheck m_savePermanently;
CCtrlButton m_ok;
@@ -18,8 +17,27 @@ protected: public:
CToxEnterPasswordDlg(CToxProto *proto);
+};
+
+/* CREATE PASSWORD */
+
+class CToxCreatePasswordDlg : public CToxDlgBase
+{
+private:
+ CCtrlEdit m_newPassword;
+ CCtrlEdit m_confirmPassword;
+
+ CCtrlBase m_passwordValidation;
- wchar_t* GetPassword();
+ CCtrlButton m_ok;
+
+protected:
+ void OnInitDialog();
+ void Password_OnChange(CCtrlBase*);
+ void OnOk(CCtrlButton*);
+
+public:
+ CToxCreatePasswordDlg(CToxProto *proto);
};
/* CHANGE PASSWORD */
@@ -33,6 +51,7 @@ private: CCtrlEdit m_confirmPassword;
CCtrlBase m_passwordValidation;
+
CCtrlButton m_ok;
protected:
@@ -42,8 +61,6 @@ protected: public:
CToxChangePasswordDlg(CToxProto *proto);
-
- wchar_t* GetPassword();
};
#endif //_TOX_PROFILE_H_
\ No newline at end of file diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 419ef2ff2a..60864594e7 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -2,17 +2,17 @@ CToxProto::CToxProto(const char* protoName, const wchar_t* userName)
: PROTO<CToxProto>(protoName, userName),
- toxThread(nullptr), isTerminated(false),
+ m_toxThread(nullptr), isTerminated(false),
hCheckingThread(nullptr), hPollingThread(nullptr),
hMessageProcess(1)
{
InitNetlib();
- wszAccountName = mir_wstrdup(userName);
- wszGroup = getWStringA(TOX_SETTINGS_GROUP);
- if (wszGroup == nullptr)
- wszGroup = mir_wstrdup(L"Tox");
- Clist_GroupCreate(0, wszGroup);
+ m_accountName = mir_wstrdup(userName);
+ m_defaultGroup = getWStringA(TOX_SETTINGS_GROUP);
+ if (m_defaultGroup == nullptr)
+ m_defaultGroup = mir_wstrdup(L"Tox");
+ Clist_GroupCreate(0, m_defaultGroup);
CreateProtoService(PS_CREATEACCMGRUI, &CToxProto::OnAccountManagerInit);
@@ -170,7 +170,7 @@ int CToxProto::SetStatus(int iNewStatus) // change status
m_iStatus = iNewStatus;
- tox_self_set_status(toxThread->Tox(), MirandaToToxStatus(iNewStatus));
+ tox_self_set_status(m_toxThread->Tox(), MirandaToToxStatus(iNewStatus));
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
return 0;
@@ -191,7 +191,7 @@ int CToxProto::SetAwayMsg(int, const wchar_t *msg) if (IsOnline()) {
T2Utf statusMessage(msg);
TOX_ERR_SET_INFO error;
- if (!tox_self_set_status_message(toxThread->Tox(), (uint8_t*)(char*)statusMessage, min(TOX_MAX_STATUS_MESSAGE_LENGTH, mir_strlen(statusMessage)), &error))
+ if (!tox_self_set_status_message(m_toxThread->Tox(), (uint8_t*)(char*)statusMessage, min(TOX_MAX_STATUS_MESSAGE_LENGTH, mir_strlen(statusMessage)), &error))
debugLogA(__FUNCTION__": failed to set status status message %s (%d)", msg, error);
}
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 8e88d7bca1..24896724d7 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -3,8 +3,9 @@ struct CToxProto : public PROTO<CToxProto>
{
- friend CToxChangePasswordDlg;
friend CToxEnterPasswordDlg;
+ friend CToxCreatePasswordDlg;
+ friend CToxChangePasswordDlg;
friend CToxOptionsMain;
friend CToxOptionsNodeList;
@@ -63,9 +64,10 @@ public: static INT_PTR ParseToxUri(WPARAM, LPARAM lParam);
private:
- CToxThread *toxThread;
- mir_cs profileLock;
- ptrW wszAccountName, wszGroup;
+ CToxThread *m_toxThread;
+ mir_cs m_profileLock;
+ ptrW m_accountName;
+ ptrW m_defaultGroup;
CTransferList transfers;
ULONG hMessageProcess;
@@ -87,7 +89,9 @@ private: int OnDeleteToxProfile();
INT_PTR __cdecl OnCopyToxID(WPARAM, LPARAM);
+ INT_PTR __cdecl OnCreatePassword(WPARAM, LPARAM);
INT_PTR __cdecl OnChangePassword(WPARAM, LPARAM);
+ INT_PTR __cdecl OnRemovePassword(WPARAM, LPARAM);
// tox core
Tox_Options* GetToxOptions();
diff --git a/protocols/Tox/src/tox_services.cpp b/protocols/Tox/src/tox_services.cpp index 532eef79d7..a2c9e549a9 100644 --- a/protocols/Tox/src/tox_services.cpp +++ b/protocols/Tox/src/tox_services.cpp @@ -8,7 +8,7 @@ INT_PTR CToxProto::SetMyNickname(WPARAM wParam, LPARAM lParam) if (IsOnline()) {
T2Utf szNick8(nickname);
TOX_ERR_SET_INFO error;
- if (!tox_self_set_name(toxThread->Tox(), szNick8, mir_strlen(szNick8), &error))
+ if (!tox_self_set_name(m_toxThread->Tox(), szNick8, mir_strlen(szNick8), &error))
debugLogA(__FUNCTION__": failed to set nick name");
}
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp index 3fb9ad77b7..6becdc1a26 100644 --- a/protocols/Tox/src/tox_transfer.cpp +++ b/protocols/Tox/src/tox_transfer.cpp @@ -96,7 +96,7 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const wchar_t **szFil FileTransferParam *transfer = (FileTransferParam*)hTransfer;
if (*action == FILERESUME_SKIP) {
- tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
+ tox_file_control(m_toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
transfers.Remove(transfer);
return 0;
}
@@ -104,22 +104,22 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const wchar_t **szFil if (*action == FILERESUME_RENAME)
transfer->ChangeName(*szFilename);
- ToxHexAddress pubKey = GetContactPublicKey(toxThread->Tox(), transfer->friendNumber);
+ ToxHexAddress pubKey = GetContactPublicKey(m_toxThread->Tox(), transfer->friendNumber);
wchar_t *mode = *action == FILERESUME_OVERWRITE ? L"wb" : L"ab";
if (!transfer->OpenFile(mode)) {
debugLogA(__FUNCTION__": failed to open file (%d) from %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
- tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
+ tox_file_control(m_toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
transfers.Remove(transfer);
return NULL;
}
TOX_ERR_FILE_CONTROL error;
debugLogA(__FUNCTION__": start receiving file (%d) from %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
- if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error)) {
+ if (!tox_file_control(m_toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error)) {
debugLogA(__FUNCTION__": failed to start receiving of file(%d) from %s(%d) cause (%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber, error);
ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
- tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
+ tox_file_control(m_toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
transfers.Remove(transfer);
}
@@ -128,7 +128,7 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const wchar_t **szFil void CToxProto::OnTransferCompleted(FileTransferParam *transfer)
{
- ToxHexAddress pubKey = GetContactPublicKey(toxThread->Tox(), transfer->friendNumber);
+ ToxHexAddress pubKey = GetContactPublicKey(m_toxThread->Tox(), transfer->friendNumber);
debugLogA(__FUNCTION__": finised the transfer of file (%d) from %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
bool isFileFullyTransfered = transfer->pfts.currentFileProgress == transfer->pfts.currentFileSize;
@@ -177,7 +177,7 @@ void CToxProto::OnDataReceiving(Tox *tox, uint32_t friendNumber, uint32_t fileNu if (fwrite(data, sizeof(uint8_t), length, transfer->hFile) != length) {
proto->debugLogA(__FUNCTION__": failed write to file (%d)", fileNumber);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
- tox_file_control(proto->toxThread->Tox(), friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
+ tox_file_control(proto->m_toxThread->Tox(), friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
return;
}
@@ -210,11 +210,11 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const wchar_t*, wchar_t **ppszFi uint64_t fileSize = _ftelli64(hFile);
rewind(hFile);
- ToxHexAddress pubKey = GetContactPublicKey(toxThread->Tox(), friendNumber);
+ ToxHexAddress pubKey = GetContactPublicKey(m_toxThread->Tox(), friendNumber);
char *name = mir_utf8encodeW(fileName);
TOX_ERR_FILE_SEND sendError;
- uint32_t fileNumber = tox_file_send(toxThread->Tox(), friendNumber, TOX_FILE_KIND_DATA, fileSize, nullptr, (uint8_t*)name, mir_strlen(name), &sendError);
+ uint32_t fileNumber = tox_file_send(m_toxThread->Tox(), friendNumber, TOX_FILE_KIND_DATA, fileSize, nullptr, (uint8_t*)name, mir_strlen(name), &sendError);
if (sendError != TOX_ERR_FILE_SEND_OK) {
debugLogA(__FUNCTION__": failed to send file (%d) to %s(%d) cause (%d)", fileNumber, (const char*)pubKey, friendNumber, sendError);
mir_free(fileDir);
@@ -272,14 +272,14 @@ void CToxProto::OnFileSendData(Tox *tox, uint32_t friendNumber, uint32_t fileNum }
TOX_ERR_FILE_SEND_CHUNK error;
- if (!tox_file_send_chunk(proto->toxThread->Tox(), friendNumber, fileNumber, position, data, length, &error)) {
+ if (!tox_file_send_chunk(proto->m_toxThread->Tox(), friendNumber, fileNumber, position, data, length, &error)) {
if (error == TOX_ERR_FILE_SEND_CHUNK_FRIEND_NOT_CONNECTED) {
mir_free(data);
return;
}
proto->debugLogA(__FUNCTION__": failed to send file chunk (%d) to %s(%d) cause (%d)", fileNumber, (const char*)pubKey, friendNumber, error);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
- tox_file_control(proto->toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
+ tox_file_control(proto->m_toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
mir_free(data);
return;
}
@@ -296,7 +296,7 @@ int CToxProto::CancelTransfer(MCONTACT, HANDLE hTransfer) {
FileTransferParam *transfer = (FileTransferParam*)hTransfer;
debugLogA(__FUNCTION__": Transfer (%d) is canceled", transfer->fileNumber);
- tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
+ tox_file_control(m_toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
transfers.Remove(transfer);
return 0;
@@ -308,13 +308,13 @@ void CToxProto::PauseOutgoingTransfers(uint32_t friendNumber) // only for sending
FileTransferParam *transfer = transfers.GetAt(i);
if (transfer->friendNumber == friendNumber && transfer->GetDirection() == 0) {
- ToxHexAddress pubKey = GetContactPublicKey(toxThread->Tox(), friendNumber);
+ ToxHexAddress pubKey = GetContactPublicKey(m_toxThread->Tox(), friendNumber);
debugLogA(__FUNCTION__": sending ask to pause the transfer of file (%d) to %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
TOX_ERR_FILE_CONTROL error;
- if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_PAUSE, &error)) {
+ if (!tox_file_control(m_toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_PAUSE, &error)) {
debugLogA(__FUNCTION__": failed to pause the transfer (%d) to %s(%d) cause(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber, error);
- tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
+ tox_file_control(m_toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
}
}
}
@@ -326,11 +326,11 @@ void CToxProto::ResumeIncomingTransfers(uint32_t friendNumber) // only for receiving
FileTransferParam *transfer = transfers.GetAt(i);
if (transfer->friendNumber == friendNumber && transfer->GetDirection() == 1) {
- ToxHexAddress pubKey = GetContactPublicKey(toxThread->Tox(), friendNumber);
+ ToxHexAddress pubKey = GetContactPublicKey(m_toxThread->Tox(), friendNumber);
debugLogA(__FUNCTION__": sending ask to resume the transfer of file (%d) from %s(%d) cause(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
TOX_ERR_FILE_CONTROL error;
- if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error)) {
+ if (!tox_file_control(m_toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error)) {
debugLogA(__FUNCTION__": failed to resume the transfer (%d) from %s(%d) cause(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber, error);
CancelTransfer(NULL, transfer);
}
|