From 89f3cf8bbb9dc1fa0fe72f6af6638ac086c7e011 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Wed, 29 Nov 2017 09:33:41 +0300 Subject: libevent, telegram, whatsapp moved to deprecated coz doesn't work --- protocols/WhatsApp/CMakeLists.txt | 4 - protocols/WhatsApp/WhatsApp.vcxproj | 44 - protocols/WhatsApp/WhatsApp.vcxproj.filters | 4 - protocols/WhatsApp/proto_whatsapp/CMakeLists.txt | 2 - .../WhatsApp/proto_whatsapp/Proto_WhatsApp.vcxproj | 28 - .../proto_whatsapp/Proto_WhatsApp.vcxproj.filters | 4 - protocols/WhatsApp/proto_whatsapp/res/Away.ico | Bin 5430 -> 0 bytes .../WhatsApp/proto_whatsapp/res/Invisible.ico | Bin 5430 -> 0 bytes protocols/WhatsApp/proto_whatsapp/res/Offline.ico | Bin 5430 -> 0 bytes protocols/WhatsApp/proto_whatsapp/res/Online.ico | Bin 5430 -> 0 bytes .../WhatsApp/proto_whatsapp/res/Proto_WhatsApp.rc | 72 -- protocols/WhatsApp/proto_whatsapp/src/resource.h | 20 - protocols/WhatsApp/res/add-group.ico | Bin 1150 -> 0 bytes protocols/WhatsApp/res/version.rc | 55 - protocols/WhatsApp/res/whatsapp.ico | Bin 1150 -> 0 bytes protocols/WhatsApp/res/whatsapp.rc | 159 --- protocols/WhatsApp/src/OpenSSL/digest.c | 278 ----- protocols/WhatsApp/src/OpenSSL/evp.h | 221 ---- protocols/WhatsApp/src/OpenSSL/evp_lib.c | 165 --- protocols/WhatsApp/src/OpenSSL/hmac.c | 170 --- protocols/WhatsApp/src/OpenSSL/hmac.h | 103 -- protocols/WhatsApp/src/OpenSSL/m_sha1.c | 128 --- protocols/WhatsApp/src/OpenSSL/md32_common.h | 408 ------- protocols/WhatsApp/src/OpenSSL/p5_crpt2.c | 113 -- protocols/WhatsApp/src/OpenSSL/rc4.h | 23 - protocols/WhatsApp/src/OpenSSL/rc4_enc.c | 314 ------ protocols/WhatsApp/src/OpenSSL/rc4_skey.c | 137 --- protocols/WhatsApp/src/OpenSSL/rsa_sign.c | 75 -- protocols/WhatsApp/src/OpenSSL/sha_locl.h | 443 -------- protocols/WhatsApp/src/WASocketConnection.cpp | 104 -- protocols/WhatsApp/src/WASocketConnection.h | 35 - .../WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp | 347 ------ .../WhatsApp/src/WhatsAPI++/BinTreeNodeReader.h | 73 -- .../WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp | 276 ----- .../WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h | 71 -- protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp | 113 -- protocols/WhatsApp/src/WhatsAPI++/ByteArray.h | 53 - protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp | 94 -- protocols/WhatsApp/src/WhatsAPI++/FMessage.h | 83 -- protocols/WhatsApp/src/WhatsAPI++/IMutex.h | 14 - .../WhatsApp/src/WhatsAPI++/ISocketConnection.h | 24 - protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp | 92 -- protocols/WhatsApp/src/WhatsAPI++/LICENSE | 340 ------ .../WhatsApp/src/WhatsAPI++/MediaUploader.cpp | 134 --- protocols/WhatsApp/src/WhatsAPI++/MediaUploader.h | 18 - protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.cpp | 298 ------ protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.h | 23 - .../WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp | 183 ---- .../WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h | 81 -- protocols/WhatsApp/src/WhatsAPI++/README.md | 30 - protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 1125 -------------------- protocols/WhatsApp/src/WhatsAPI++/WAConnection.h | 415 -------- protocols/WhatsApp/src/WhatsAPI++/WAException.h | 40 - protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp | 182 ---- protocols/WhatsApp/src/WhatsAPI++/WALogin.h | 67 -- protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp | 71 -- protocols/WhatsApp/src/WhatsAPI++/WARegister.h | 23 - protocols/WhatsApp/src/WhatsAPI++/targetver.h | 8 - protocols/WhatsApp/src/WhatsAPI++/utilities.cpp | 386 ------- protocols/WhatsApp/src/WhatsAPI++/utilities.h | 70 -- protocols/WhatsApp/src/avatars.cpp | 134 --- protocols/WhatsApp/src/chat.cpp | 522 --------- protocols/WhatsApp/src/connection.cpp | 145 --- protocols/WhatsApp/src/constants.h | 51 - protocols/WhatsApp/src/contacts.cpp | 191 ---- protocols/WhatsApp/src/db.h | 33 - protocols/WhatsApp/src/definitions.h | 14 - protocols/WhatsApp/src/dialogs.cpp | 235 ---- protocols/WhatsApp/src/dialogs.h | 6 - protocols/WhatsApp/src/entities.h | 34 - protocols/WhatsApp/src/main.cpp | 100 -- protocols/WhatsApp/src/media.cpp | 87 -- protocols/WhatsApp/src/messages.cpp | 137 --- protocols/WhatsApp/src/proto.cpp | 438 -------- protocols/WhatsApp/src/proto.h | 203 ---- protocols/WhatsApp/src/resource.h | 43 - protocols/WhatsApp/src/stdafx.cxx | 8 - protocols/WhatsApp/src/stdafx.h | 90 -- protocols/WhatsApp/src/theme.cpp | 71 -- protocols/WhatsApp/src/theme.h | 20 - protocols/WhatsApp/src/utils.cpp | 93 -- protocols/WhatsApp/src/utils.h | 52 - protocols/WhatsApp/src/version.h | 14 - 83 files changed, 10564 deletions(-) delete mode 100644 protocols/WhatsApp/CMakeLists.txt delete mode 100644 protocols/WhatsApp/WhatsApp.vcxproj delete mode 100644 protocols/WhatsApp/WhatsApp.vcxproj.filters delete mode 100644 protocols/WhatsApp/proto_whatsapp/CMakeLists.txt delete mode 100644 protocols/WhatsApp/proto_whatsapp/Proto_WhatsApp.vcxproj delete mode 100644 protocols/WhatsApp/proto_whatsapp/Proto_WhatsApp.vcxproj.filters delete mode 100644 protocols/WhatsApp/proto_whatsapp/res/Away.ico delete mode 100644 protocols/WhatsApp/proto_whatsapp/res/Invisible.ico delete mode 100644 protocols/WhatsApp/proto_whatsapp/res/Offline.ico delete mode 100644 protocols/WhatsApp/proto_whatsapp/res/Online.ico delete mode 100644 protocols/WhatsApp/proto_whatsapp/res/Proto_WhatsApp.rc delete mode 100644 protocols/WhatsApp/proto_whatsapp/src/resource.h delete mode 100644 protocols/WhatsApp/res/add-group.ico delete mode 100644 protocols/WhatsApp/res/version.rc delete mode 100644 protocols/WhatsApp/res/whatsapp.ico delete mode 100644 protocols/WhatsApp/res/whatsapp.rc delete mode 100644 protocols/WhatsApp/src/OpenSSL/digest.c delete mode 100644 protocols/WhatsApp/src/OpenSSL/evp.h delete mode 100644 protocols/WhatsApp/src/OpenSSL/evp_lib.c delete mode 100644 protocols/WhatsApp/src/OpenSSL/hmac.c delete mode 100644 protocols/WhatsApp/src/OpenSSL/hmac.h delete mode 100644 protocols/WhatsApp/src/OpenSSL/m_sha1.c delete mode 100644 protocols/WhatsApp/src/OpenSSL/md32_common.h delete mode 100644 protocols/WhatsApp/src/OpenSSL/p5_crpt2.c delete mode 100644 protocols/WhatsApp/src/OpenSSL/rc4.h delete mode 100644 protocols/WhatsApp/src/OpenSSL/rc4_enc.c delete mode 100644 protocols/WhatsApp/src/OpenSSL/rc4_skey.c delete mode 100644 protocols/WhatsApp/src/OpenSSL/rsa_sign.c delete mode 100644 protocols/WhatsApp/src/OpenSSL/sha_locl.h delete mode 100644 protocols/WhatsApp/src/WASocketConnection.cpp delete mode 100644 protocols/WhatsApp/src/WASocketConnection.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/ByteArray.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/FMessage.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/IMutex.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/ISocketConnection.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/LICENSE delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/MediaUploader.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/MediaUploader.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/README.md delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WAConnection.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WAException.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WALogin.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WARegister.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/targetver.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/utilities.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/utilities.h delete mode 100644 protocols/WhatsApp/src/avatars.cpp delete mode 100644 protocols/WhatsApp/src/chat.cpp delete mode 100644 protocols/WhatsApp/src/connection.cpp delete mode 100644 protocols/WhatsApp/src/constants.h delete mode 100644 protocols/WhatsApp/src/contacts.cpp delete mode 100644 protocols/WhatsApp/src/db.h delete mode 100644 protocols/WhatsApp/src/definitions.h delete mode 100644 protocols/WhatsApp/src/dialogs.cpp delete mode 100644 protocols/WhatsApp/src/dialogs.h delete mode 100644 protocols/WhatsApp/src/entities.h delete mode 100644 protocols/WhatsApp/src/main.cpp delete mode 100644 protocols/WhatsApp/src/media.cpp delete mode 100644 protocols/WhatsApp/src/messages.cpp delete mode 100644 protocols/WhatsApp/src/proto.cpp delete mode 100644 protocols/WhatsApp/src/proto.h delete mode 100644 protocols/WhatsApp/src/resource.h delete mode 100644 protocols/WhatsApp/src/stdafx.cxx delete mode 100755 protocols/WhatsApp/src/stdafx.h delete mode 100644 protocols/WhatsApp/src/theme.cpp delete mode 100644 protocols/WhatsApp/src/theme.h delete mode 100644 protocols/WhatsApp/src/utils.cpp delete mode 100644 protocols/WhatsApp/src/utils.h delete mode 100644 protocols/WhatsApp/src/version.h (limited to 'protocols/WhatsApp') diff --git a/protocols/WhatsApp/CMakeLists.txt b/protocols/WhatsApp/CMakeLists.txt deleted file mode 100644 index cbca8a0ba4..0000000000 --- a/protocols/WhatsApp/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -file(GLOB SOURCES "src/*.h" "src/WhatsAPI++/*.h" "src/*.cpp" "src/OpenSSL/*.c" "src/WhatsAPI++/*.cpp" "res/*.rc") -set(TARGET WhatsApp) -include(${CMAKE_SOURCE_DIR}/cmake/plugin.cmake) -add_subdirectory(proto_whatsapp) \ No newline at end of file diff --git a/protocols/WhatsApp/WhatsApp.vcxproj b/protocols/WhatsApp/WhatsApp.vcxproj deleted file mode 100644 index ee43a66701..0000000000 --- a/protocols/WhatsApp/WhatsApp.vcxproj +++ /dev/null @@ -1,44 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {13E796AD-BEA4-4213-A1B8-E18E2397E544} - WhatsApp - - - - - - - NotUsing - - - ../stdafx.h - - - - - - - - Sync - - - \ No newline at end of file diff --git a/protocols/WhatsApp/WhatsApp.vcxproj.filters b/protocols/WhatsApp/WhatsApp.vcxproj.filters deleted file mode 100644 index de5ad9f66c..0000000000 --- a/protocols/WhatsApp/WhatsApp.vcxproj.filters +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/protocols/WhatsApp/proto_whatsapp/CMakeLists.txt b/protocols/WhatsApp/proto_whatsapp/CMakeLists.txt deleted file mode 100644 index 5193619806..0000000000 --- a/protocols/WhatsApp/proto_whatsapp/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -set(TARGET Proto_WhatsApp) -include(${CMAKE_SOURCE_DIR}/cmake/icons.cmake) \ No newline at end of file diff --git a/protocols/WhatsApp/proto_whatsapp/Proto_WhatsApp.vcxproj b/protocols/WhatsApp/proto_whatsapp/Proto_WhatsApp.vcxproj deleted file mode 100644 index 0d33d3423f..0000000000 --- a/protocols/WhatsApp/proto_whatsapp/Proto_WhatsApp.vcxproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - Proto_WhatsApp - {64A2B403-90AF-4CF8-BC69-4E8D33872D64} - - - - - \ No newline at end of file diff --git a/protocols/WhatsApp/proto_whatsapp/Proto_WhatsApp.vcxproj.filters b/protocols/WhatsApp/proto_whatsapp/Proto_WhatsApp.vcxproj.filters deleted file mode 100644 index e39f86d5d6..0000000000 --- a/protocols/WhatsApp/proto_whatsapp/Proto_WhatsApp.vcxproj.filters +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/protocols/WhatsApp/proto_whatsapp/res/Away.ico b/protocols/WhatsApp/proto_whatsapp/res/Away.ico deleted file mode 100644 index 9c07e3fa13..0000000000 Binary files a/protocols/WhatsApp/proto_whatsapp/res/Away.ico and /dev/null differ diff --git a/protocols/WhatsApp/proto_whatsapp/res/Invisible.ico b/protocols/WhatsApp/proto_whatsapp/res/Invisible.ico deleted file mode 100644 index cb743a4bfe..0000000000 Binary files a/protocols/WhatsApp/proto_whatsapp/res/Invisible.ico and /dev/null differ diff --git a/protocols/WhatsApp/proto_whatsapp/res/Offline.ico b/protocols/WhatsApp/proto_whatsapp/res/Offline.ico deleted file mode 100644 index 4019c68283..0000000000 Binary files a/protocols/WhatsApp/proto_whatsapp/res/Offline.ico and /dev/null differ diff --git a/protocols/WhatsApp/proto_whatsapp/res/Online.ico b/protocols/WhatsApp/proto_whatsapp/res/Online.ico deleted file mode 100644 index 2143ea1438..0000000000 Binary files a/protocols/WhatsApp/proto_whatsapp/res/Online.ico and /dev/null differ diff --git a/protocols/WhatsApp/proto_whatsapp/res/Proto_WhatsApp.rc b/protocols/WhatsApp/proto_whatsapp/res/Proto_WhatsApp.rc deleted file mode 100644 index 7cd2882d24..0000000000 --- a/protocols/WhatsApp/proto_whatsapp/res/Proto_WhatsApp.rc +++ /dev/null @@ -1,72 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "..\src\resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// Russian (Russia) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) -LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "..\\src\\resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_ICON1 ICON "Offline.ico" -IDI_ICON2 ICON "Online.ico" -IDI_ICON3 ICON "Away.ico" -IDI_ICON4 ICON "Invisible.ico" -#endif // Russian (Russia) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/protocols/WhatsApp/proto_whatsapp/src/resource.h b/protocols/WhatsApp/proto_whatsapp/src/resource.h deleted file mode 100644 index c9b458c21a..0000000000 --- a/protocols/WhatsApp/proto_whatsapp/src/resource.h +++ /dev/null @@ -1,20 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by Proto_WhatsApp.rc -// -#define IDI_ICON1 105 -#define IDI_ICON2 104 -#define IDI_ICON3 128 -#define IDI_ICON4 130 -//#define IDI_ICON5 1002 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 106 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/protocols/WhatsApp/res/add-group.ico b/protocols/WhatsApp/res/add-group.ico deleted file mode 100644 index 65d0d1f41b..0000000000 Binary files a/protocols/WhatsApp/res/add-group.ico and /dev/null differ diff --git a/protocols/WhatsApp/res/version.rc b/protocols/WhatsApp/res/version.rc deleted file mode 100644 index fdeb14668c..0000000000 --- a/protocols/WhatsApp/res/version.rc +++ /dev/null @@ -1,55 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#ifdef APSTUDIO_INVOKED -#error this file is not editable by Microsoft Visual C++ -#endif //APSTUDIO_INVOKED - -#include "..\src\version.h" - -#define APSTUDIO_READONLY_SYMBOLS -#include "afxres.h" -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -VS_VERSION_INFO VERSIONINFO - FILEVERSION __FILEVERSION_STRING - PRODUCTVERSION __FILEVERSION_STRING - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004b0" - BEGIN - VALUE "Author", __AUTHOR - VALUE "FileDescription", __DESCRIPTION - VALUE "FileVersion", __VERSION_STRING - VALUE "InternalName", __PLUGIN_NAME - VALUE "LegalCopyright", __COPYRIGHT - VALUE "OriginalFilename", __FILENAME - VALUE "ProductName", __PLUGIN_NAME - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0, 1200 - END -END - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// diff --git a/protocols/WhatsApp/res/whatsapp.ico b/protocols/WhatsApp/res/whatsapp.ico deleted file mode 100644 index 7a0dc4c68d..0000000000 Binary files a/protocols/WhatsApp/res/whatsapp.ico and /dev/null differ diff --git a/protocols/WhatsApp/res/whatsapp.rc b/protocols/WhatsApp/res/whatsapp.rc deleted file mode 100644 index 37f87d0fbc..0000000000 --- a/protocols/WhatsApp/res/whatsapp.rc +++ /dev/null @@ -1,159 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "..\src\resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// German (Germany) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU) -LANGUAGE LANG_GERMAN, SUBLANG_GERMAN -#pragma code_page(1252) - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "..\\src\\resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_WHATSAPOPTIONS, DIALOG - BEGIN - VERTGUIDE, 60 - VERTGUIDE, 178 - BOTTOMMARGIN, 126 - END -END -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_ACCMGRUI DIALOGEX 0, 0, 188, 144 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 400, 0, 0x0 -BEGIN - LTEXT "Phone number",IDC_STATIC,4,7,55,10 - EDITTEXT IDC_CC,60,6,24,12,ES_AUTOHSCROLL - EDITTEXT IDC_LOGIN,84,6,100,12,ES_AUTOHSCROLL - LTEXT "Nickname",IDC_STATIC,4,23,55,10 - EDITTEXT IDC_NICK,60,22,124,12,ES_AUTOHSCROLL - LTEXT "Default group:",IDC_STATIC,4,37,55,10 - EDITTEXT IDC_DEFGROUP,60,36,124,12,ES_AUTOHSCROLL - CONTROL "Use SSL connection (port 443)",IDC_SSL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,52,180,10 - CONTROL "Use remote message timestamps", IDC_REMOTE_TIME, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 4, 64, 180, 10 - CONTROL "Automatically open group chats",IDC_AUTORUN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,76,180,10 - GROUPBOX "Registration",IDC_STATIC,4,92,184,48 - LTEXT "Enter code",IDC_STATIC,8,123,47,10 - EDITTEXT IDC_PW,45,121,20,12,ES_AUTOHSCROLL | ES_NUMBER - CTEXT "-",IDC_STATIC,64,123,8,10 - EDITTEXT IDC_PW2,72,121,20,12,ES_AUTOHSCROLL | ES_NUMBER - PUSHBUTTON "Request SMS code",IDC_BUTTON_REQUEST_SMS_CODE,12,104,80,14 - PUSHBUTTON "Request Voice code",IDC_BUTTON_REQUEST_VOICE_CODE,99,104,80,14 - PUSHBUTTON "Register code",IDC_BUTTON_REGISTER,100,120,80,14 -END - -IDD_OPTIONS DIALOGEX 0, 0, 188, 164 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "Phone number",IDC_STATIC,4,7,55,10 - EDITTEXT IDC_CC,60,6,24,12,ES_AUTOHSCROLL - EDITTEXT IDC_LOGIN,84,6,100,12,ES_AUTOHSCROLL - LTEXT "Including country code, without '+' or '00'",IDC_STATIC,60,22,118,18 - LTEXT "Nickname",IDC_STATIC,4,43,55,10 - EDITTEXT IDC_NICK,60,42,124,12,ES_AUTOHSCROLL - LTEXT "Default group:",IDC_STATIC,4,57,55,10 - EDITTEXT IDC_DEFGROUP,60,56,124,12,ES_AUTOHSCROLL - CONTROL "Use SSL connection (port 443)",IDC_SSL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,72,180,10 - CONTROL "Use remote message timestamps", IDC_REMOTE_TIME, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 4, 84, 180, 10 - CONTROL "Automatically open group chats",IDC_AUTORUN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,96,180,10 - GROUPBOX "Registration",IDC_STATIC,4,112,184,48 - LTEXT "Enter code",IDC_STATIC,8,143,47,10 - EDITTEXT IDC_PW,45,141,20,12,ES_AUTOHSCROLL | ES_NUMBER - CTEXT "-",IDC_STATIC,64,143,8,10 - EDITTEXT IDC_PW2,72,141,20,12,ES_AUTOHSCROLL | ES_NUMBER - PUSHBUTTON "Request SMS code",IDC_BUTTON_REQUEST_SMS_CODE,12,124,80,14 - PUSHBUTTON "Request Voice code",IDC_BUTTON_REQUEST_VOICE_CODE,100,124,80,14 - PUSHBUTTON "Register code",IDC_BUTTON_REGISTER,100,140,80,14 -END - -IDD_GROUPCHAT_INVITE DIALOGEX 0, 0, 215, 170 -STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION "Invite users" -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - GROUPBOX "Choose a user",IDC_STATIC,4,2,208,130 - CONTROL "",IDC_CLIST,"CListControl",WS_TABSTOP | 0x1,12,12,192,112,WS_EX_CLIENTEDGE - LTEXT "Other user:",IDC_STATIC,4,138,55,8 - EDITTEXT IDC_NEWJID,60,136,152,12,ES_AUTOHSCROLL - DEFPUSHBUTTON "&Invite",IDOK,108,152,50,14 - PUSHBUTTON "Cancel",IDCANCEL,162,152,50,14 -END - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_WHATSAPP ICON "whatsapp.ico" -IDI_ADD_GROUP ICON "add-group.ico" -#endif // German (Germany) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/protocols/WhatsApp/src/OpenSSL/digest.c b/protocols/WhatsApp/src/OpenSSL/digest.c deleted file mode 100644 index 1a6b106dd9..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/digest.c +++ /dev/null @@ -1,278 +0,0 @@ -/* crypto/evp/digest.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ -/* ==================================================================== - * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * openssl-core@openssl.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This product includes cryptographic software written by Eric Young - * (eay@cryptsoft.com). This product includes software written by Tim - * Hudson (tjh@cryptsoft.com). - * - */ - -#include -#include -#include - -#include "evp.h" - -void EVP_MD_CTX_init(EVP_MD_CTX *ctx) - { - memset(ctx,'\0',sizeof *ctx); - } - -EVP_MD_CTX *EVP_MD_CTX_create(void) - { - EVP_MD_CTX *ctx=malloc(sizeof *ctx); - - if (ctx) - EVP_MD_CTX_init(ctx); - - return ctx; - } - -int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) - { - EVP_MD_CTX_init(ctx); - return EVP_DigestInit_ex(ctx, type, NULL); - } - -int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) - { - M_EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED); - if (ctx->digest != type) - { - if (ctx->digest && ctx->digest->ctx_size) - free(ctx->md_data); - ctx->digest=type; - if (type->ctx_size) - { - ctx->md_data=malloc(type->ctx_size); - if (!ctx->md_data) - { - return 0; - } - } - } - return ctx->digest->init(ctx); - } - -int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, - size_t count) - { - return ctx->digest->update(ctx,data,count); - } - -/* The caller can assume that this removes any secret data from the context */ -int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) - { - int ret; - ret = EVP_DigestFinal_ex(ctx, md, size); - EVP_MD_CTX_cleanup(ctx); - return ret; - } - -/* The caller can assume that this removes any secret data from the context */ -int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) - { - int ret; - - ret=ctx->digest->final(ctx,md); - if (size != NULL) - *size=ctx->digest->md_size; - if (ctx->digest->cleanup) - { - ctx->digest->cleanup(ctx); - M_EVP_MD_CTX_set_flags(ctx,EVP_MD_CTX_FLAG_CLEANED); - } - memset(ctx->md_data,0,ctx->digest->ctx_size); - return ret; - } - -int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in) - { - EVP_MD_CTX_init(out); - return EVP_MD_CTX_copy_ex(out, in); - } - -int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) - { - unsigned char *tmp_buf; - if ((in == NULL) || (in->digest == NULL)) - { - return 0; - } -#ifndef OPENSSL_NO_ENGINE - /* Make sure it's safe to copy a digest context using an ENGINE */ -#endif - - if (out->digest == in->digest) - { - tmp_buf = out->md_data; - M_EVP_MD_CTX_set_flags(out,EVP_MD_CTX_FLAG_REUSE); - } - else tmp_buf = NULL; - EVP_MD_CTX_cleanup(out); - memcpy(out,in,sizeof *out); - - if (out->digest->ctx_size) - { - if (tmp_buf) - out->md_data = tmp_buf; - else - { - out->md_data=malloc(out->digest->ctx_size); - if (!out->md_data) - { - return 0; - } - } - memcpy(out->md_data,in->md_data,out->digest->ctx_size); - } - - if (out->digest->copy) - return out->digest->copy(out,in); - - return 1; - } - -int EVP_Digest(const void *data, size_t count, - unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl) - { - EVP_MD_CTX ctx; - int ret; - - EVP_MD_CTX_init(&ctx); - M_EVP_MD_CTX_set_flags(&ctx,EVP_MD_CTX_FLAG_ONESHOT); - ret=EVP_DigestInit_ex(&ctx, type, impl) - && EVP_DigestUpdate(&ctx, data, count) - && EVP_DigestFinal_ex(&ctx, md, size); - EVP_MD_CTX_cleanup(&ctx); - - return ret; - } - -void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx) - { - EVP_MD_CTX_cleanup(ctx); - free(ctx); - } - -/* This call frees resources associated with the context */ -int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) - { - /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final, - * because sometimes only copies of the context are ever finalised. - */ - if (ctx->digest && ctx->digest->cleanup - && !M_EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED)) - ctx->digest->cleanup(ctx); - if (ctx->digest && ctx->digest->ctx_size && ctx->md_data - && !M_EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) - { - memset(ctx->md_data,0,ctx->digest->ctx_size); - free(ctx->md_data); - } - memset(ctx,'\0',sizeof *ctx); - - return 1; - } diff --git a/protocols/WhatsApp/src/OpenSSL/evp.h b/protocols/WhatsApp/src/OpenSSL/evp.h deleted file mode 100644 index bee216913d..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/evp.h +++ /dev/null @@ -1,221 +0,0 @@ -/* crypto/evp/evp.h */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#ifndef HEADER_ENVELOPE_H -#define HEADER_ENVELOPE_H - -/* -#define EVP_RC2_KEY_SIZE 16 -#define EVP_RC4_KEY_SIZE 16 -#define EVP_BLOWFISH_KEY_SIZE 16 -#define EVP_CAST5_KEY_SIZE 16 -#define EVP_RC5_32_12_16_KEY_SIZE 16 -*/ -#define EVP_MAX_MD_SIZE 64 /* longest known is SHA512 */ -#define EVP_MAX_KEY_LENGTH 32 -#define EVP_MAX_IV_LENGTH 16 -#define EVP_MAX_BLOCK_LENGTH 32 - -#define PKCS5_SALT_LEN 8 -/* Default PKCS#5 iteration count */ -#define PKCS5_DEFAULT_ITER 2048 - -#define EVP_PK_RSA 0x0001 -#define EVP_PK_DSA 0x0002 -#define EVP_PK_DH 0x0004 -#define EVP_PK_EC 0x0008 -#define EVP_PKT_SIGN 0x0010 -#define EVP_PKT_ENC 0x0020 -#define EVP_PKT_EXCH 0x0040 -#define EVP_PKS_RSA 0x0100 -#define EVP_PKS_DSA 0x0200 -#define EVP_PKS_EC 0x0400 -#define EVP_PKT_EXP 0x1000 /* <= 512 bit key */ - -#define EVP_PKEY_NONE NID_undef -#define EVP_PKEY_RSA NID_rsaEncryption -#define EVP_PKEY_RSA2 NID_rsa -#define EVP_PKEY_DSA NID_dsa -#define EVP_PKEY_DSA1 NID_dsa_2 -#define EVP_PKEY_DSA2 NID_dsaWithSHA -#define EVP_PKEY_DSA3 NID_dsaWithSHA1 -#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 -#define EVP_PKEY_DH NID_dhKeyAgreement -#define EVP_PKEY_EC NID_X9_62_id_ecPublicKey - -#ifdef __cplusplus -extern "C" { -#endif - -#define EVP_MAX_MD_SIZE 64 /* longest known is SHA512 */ -#define EVP_MAX_KEY_LENGTH 32 -#define EVP_MAX_IV_LENGTH 16 -#define EVP_MAX_BLOCK_LENGTH 32 - -#define EVP_MD_CTX_FLAG_ONESHOT 0x0001 /* digest update will be called - * once only */ -#define EVP_MD_CTX_FLAG_CLEANED 0x0002 /* context has already been - * cleaned */ -#define EVP_MD_CTX_FLAG_REUSE 0x0004 /* Don't free up ctx->md_data - * in EVP_MD_CTX_cleanup */ -#define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008 /* Allow use of non FIPS digest - * in FIPS mode */ - -#define M_EVP_MD_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs)) -#define M_EVP_MD_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs)) -#define M_EVP_MD_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs)) - -typedef void ENGINE; -typedef struct env_md_st EVP_MD; -typedef struct env_md_ctx_st EVP_MD_CTX; -typedef struct evp_cipher_st EVP_CIPHER; -typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX; - -struct evp_cipher_st -{ - int nid; - int block_size; - int key_len; /* Default value for variable length ciphers */ - int iv_len; - unsigned long flags; /* Various flags */ - int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc); /* init key */ - int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, unsigned int inl);/* encrypt/decrypt data */ - int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */ - int ctx_size; /* how big ctx->cipher_data needs to be */ - int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */ - void *app_data; /* Application data */ -} /* EVP_CIPHER */; - -struct evp_cipher_ctx_st -{ - const EVP_CIPHER *cipher; - int encrypt; /* encrypt or decrypt */ - int buf_len; /* number we have left */ - - unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */ - unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */ - unsigned char buf[EVP_MAX_BLOCK_LENGTH];/* saved partial block */ - int num; /* used by cfb/ofb mode */ - - void *app_data; /* application stuff */ - int key_len; /* May change for variable length cipher */ - unsigned long flags; /* Various flags */ - void *cipher_data; /* per EVP data */ - int final_used; - int block_mask; - unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */ -} /* EVP_CIPHER_CTX */; - -struct env_md_ctx_st -{ - const EVP_MD *digest; - unsigned long flags; - void *md_data; -} /* EVP_MD_CTX */; - -struct env_md_st -{ - int type; - int pkey_type; - int md_size; - unsigned long flags; - int (*init)(EVP_MD_CTX *ctx); - int (*update)(EVP_MD_CTX *ctx,const void *data,size_t count); - int (*final)(EVP_MD_CTX *ctx,unsigned char *md); - int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from); - int (*cleanup)(EVP_MD_CTX *ctx); - - /* FIXME: prototype these some day */ - int (*sign)(int type, const unsigned char *m, unsigned int m_length, - unsigned char *sigret, unsigned int *siglen, void *key); - int (*verify)(int type, const unsigned char *m, unsigned int m_length, - const unsigned char *sigbuf, unsigned int siglen, - void *key); - int required_pkey_type[5]; /*EVP_PKEY_xxx */ - int block_size; - int ctx_size; /* how big does the ctx->md_data need to be */ -} /* EVP_MD */; - -typedef int evp_sign_method(int type,const unsigned char *m, - unsigned int m_length,unsigned char *sigret, - unsigned int *siglen, void *key); -typedef int evp_verify_method(int type,const unsigned char *m, - unsigned int m_length,const unsigned char *sigbuf, - unsigned int siglen, void *key); - -int EVP_MD_block_size(const EVP_MD *md); -int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, void *impl); -int EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d, size_t cnt); -int EVP_DigestFinal_ex(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); - -const EVP_MD *EVP_sha1(void); - -int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in); -void EVP_MD_CTX_init(EVP_MD_CTX *ctx); -int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx); - -int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, - const unsigned char *salt, int saltlen, int iter, - int keylen, unsigned char *out); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/protocols/WhatsApp/src/OpenSSL/evp_lib.c b/protocols/WhatsApp/src/OpenSSL/evp_lib.c deleted file mode 100644 index 86ee6fc272..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/evp_lib.c +++ /dev/null @@ -1,165 +0,0 @@ -/* crypto/evp/evp_lib.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include "evp.h" - -int EVP_CIPHER_block_size(const EVP_CIPHER *e) - { - return e->block_size; - } - -int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx) - { - return ctx->cipher->block_size; - } - -const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx) - { - return ctx->cipher; - } - -unsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher) - { - return cipher->flags; - } - -void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx) - { - return ctx->app_data; - } - -void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data) - { - ctx->app_data = data; - } - -int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher) - { - return cipher->iv_len; - } - -int EVP_CIPHER_key_length(const EVP_CIPHER *cipher) - { - return cipher->key_len; - } - -int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx) - { - return ctx->key_len; - } - -int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx) - { - return ctx->cipher->nid; - } - -int EVP_MD_block_size(const EVP_MD *md) - { - return md->block_size; - } - -int EVP_MD_type(const EVP_MD *md) - { - return md->type; - } - -int EVP_MD_pkey_type(const EVP_MD *md) - { - return md->pkey_type; - } - -int EVP_MD_size(const EVP_MD *md) - { - return md->md_size; - } - -const EVP_MD * EVP_MD_CTX_md(const EVP_MD_CTX *ctx) - { - return ctx->digest; - } - -void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags) - { - ctx->flags |= flags; - } - -void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags) - { - ctx->flags &= ~flags; - } - -int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags) - { - return (ctx->flags & flags); - } - -void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags) - { - ctx->flags |= flags; - } - -void EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX *ctx, int flags) - { - ctx->flags &= ~flags; - } - -int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags) - { - return (ctx->flags & flags); - } diff --git a/protocols/WhatsApp/src/OpenSSL/hmac.c b/protocols/WhatsApp/src/OpenSSL/hmac.c deleted file mode 100644 index 9e2d3d439f..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/hmac.c +++ /dev/null @@ -1,170 +0,0 @@ -/* crypto/hmac/hmac.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ -#include -#include -#include -#include "hmac.h" - -#ifndef OPENSSL_FIPS - -void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, - const EVP_MD *md, void *impl) - { - int i,j,reset=0; - unsigned char pad[HMAC_MAX_MD_CBLOCK]; - - if (md != NULL) - { - reset=1; - ctx->md=md; - } - else - md=ctx->md; - - if (key != NULL) - { - reset=1; - j=EVP_MD_block_size(md); - if (j < len) - { - EVP_DigestInit_ex(&ctx->md_ctx,md, impl); - EVP_DigestUpdate(&ctx->md_ctx,key,len); - EVP_DigestFinal_ex(&(ctx->md_ctx),ctx->key, - &ctx->key_length); - } - else - { - memcpy(ctx->key,key,len); - ctx->key_length=len; - } - if(ctx->key_length != HMAC_MAX_MD_CBLOCK) - memset(&ctx->key[ctx->key_length], 0, - HMAC_MAX_MD_CBLOCK - ctx->key_length); - } - - if (reset) - { - for (i=0; ikey[i]; - EVP_DigestInit_ex(&ctx->i_ctx,md, impl); - EVP_DigestUpdate(&ctx->i_ctx,pad,EVP_MD_block_size(md)); - - for (i=0; ikey[i]; - EVP_DigestInit_ex(&ctx->o_ctx,md, impl); - EVP_DigestUpdate(&ctx->o_ctx,pad,EVP_MD_block_size(md)); - } - EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->i_ctx); - } - -void HMAC_Init(HMAC_CTX *ctx, const void *key, int len, - const EVP_MD *md) - { - if(key && md) - HMAC_CTX_init(ctx); - HMAC_Init_ex(ctx,key,len,md, NULL); - } - -void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len) - { - EVP_DigestUpdate(&ctx->md_ctx,data,len); - } - -void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) - { - unsigned int i; - unsigned char buf[EVP_MAX_MD_SIZE]; - - EVP_DigestFinal_ex(&ctx->md_ctx,buf,&i); - EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->o_ctx); - EVP_DigestUpdate(&ctx->md_ctx,buf,i); - EVP_DigestFinal_ex(&ctx->md_ctx,md,len); - } - -void HMAC_CTX_init(HMAC_CTX *ctx) - { - EVP_MD_CTX_init(&ctx->i_ctx); - EVP_MD_CTX_init(&ctx->o_ctx); - EVP_MD_CTX_init(&ctx->md_ctx); - } - -void HMAC_CTX_cleanup(HMAC_CTX *ctx) - { - EVP_MD_CTX_cleanup(&ctx->i_ctx); - EVP_MD_CTX_cleanup(&ctx->o_ctx); - EVP_MD_CTX_cleanup(&ctx->md_ctx); - memset(ctx,0,sizeof *ctx); - } - -unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, - const unsigned char *d, size_t n, unsigned char *md, - unsigned int *md_len) - { - HMAC_CTX c; - static unsigned char m[EVP_MAX_MD_SIZE]; - - if (md == NULL) md=m; - HMAC_CTX_init(&c); - HMAC_Init(&c,key,key_len,evp_md); - HMAC_Update(&c,d,n); - HMAC_Final(&c,md,md_len); - HMAC_CTX_cleanup(&c); - return(md); - } - -#endif diff --git a/protocols/WhatsApp/src/OpenSSL/hmac.h b/protocols/WhatsApp/src/OpenSSL/hmac.h deleted file mode 100644 index be14555645..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/hmac.h +++ /dev/null @@ -1,103 +0,0 @@ -/* crypto/hmac/hmac.h */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ -#ifndef HEADER_HMAC_H -#define HEADER_HMAC_H - -#define HMAC_MAX_MD_CBLOCK 128 /* largest known is SHA512 */ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "evp.h" - -typedef struct hmac_ctx_st - { - const EVP_MD *md; - EVP_MD_CTX md_ctx; - EVP_MD_CTX i_ctx; - EVP_MD_CTX o_ctx; - unsigned int key_length; - unsigned char key[HMAC_MAX_MD_CBLOCK]; - } HMAC_CTX; - -#define HMAC_size(e) (EVP_MD_size((e)->md)) - - -void HMAC_CTX_init(HMAC_CTX *ctx); -void HMAC_CTX_cleanup(HMAC_CTX *ctx); - -#define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */ - -void HMAC_Init(HMAC_CTX *ctx, const void *key, int len, - const EVP_MD *md); /* deprecated */ -void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, - const EVP_MD *md, ENGINE *impl); -void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len); -void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); -unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, - const unsigned char *d, size_t n, unsigned char *md, - unsigned int *md_len); - -void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/protocols/WhatsApp/src/OpenSSL/m_sha1.c b/protocols/WhatsApp/src/OpenSSL/m_sha1.c deleted file mode 100644 index c78fe11a77..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/m_sha1.c +++ /dev/null @@ -1,128 +0,0 @@ -/* crypto/evp/m_sha1.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include - -#define SHA_1 - -#include "evp.h" - -#define SHA_LONG unsigned long - -#define SHA_LBLOCK 16 -#define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a - * contiguous array of 32 bit - * wide big-endian values. */ -#define SHA_LAST_BLOCK (SHA_CBLOCK-8) -#define SHA_DIGEST_LENGTH 20 - -#define NID_rsaEncryption 6 -#define NID_rsa 19 -#define NID_sha1 64 -#define NID_sha1WithRSAEncryption 65 - -typedef struct SHAstate_st - { - SHA_LONG h0,h1,h2,h3,h4; - SHA_LONG Nl,Nh; - SHA_LONG data[SHA_LBLOCK]; - unsigned int num; - } SHA_CTX; - -#include "sha_locl.h" - -/* The following 2 functions sign and verify a X509_SIG ASN1 object - * inside PKCS#1 padded RSA encryption */ -int RSA_sign(int type, const unsigned char *m, unsigned int m_length, - unsigned char *sigret, unsigned int *siglen, void *rsa); -int RSA_verify(int type, const unsigned char *m, unsigned int m_length, - unsigned char *sigbuf, unsigned int siglen, void *rsa); - -#define EVP_PKEY_RSA_method (evp_sign_method *)RSA_sign, \ - (evp_verify_method *)RSA_verify, \ - {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} - -static int init(EVP_MD_CTX *ctx) - { return SHA1_Init(ctx->md_data); } - -static int update(EVP_MD_CTX *ctx,const void *data,size_t count) - { return SHA1_Update(ctx->md_data,data,count); } - -static int final(EVP_MD_CTX *ctx,unsigned char *md) - { return SHA1_Final(md,ctx->md_data); } - -static const EVP_MD sha1_md = - { - NID_sha1, - NID_sha1WithRSAEncryption, - SHA_DIGEST_LENGTH, - 0, - init, - update, - final, - NULL, - NULL, - EVP_PKEY_RSA_method, - SHA_CBLOCK, - sizeof(EVP_MD *)+sizeof(SHA_CTX), - }; - -const EVP_MD *EVP_sha1(void) -{ - return(&sha1_md); -} diff --git a/protocols/WhatsApp/src/OpenSSL/md32_common.h b/protocols/WhatsApp/src/OpenSSL/md32_common.h deleted file mode 100644 index f0ca0fe631..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/md32_common.h +++ /dev/null @@ -1,408 +0,0 @@ -/* crypto/md32_common.h */ -/* ==================================================================== - * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * licensing@OpenSSL.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - */ - -/* - * This is a generic 32 bit "collector" for message digest algorithms. - * Whenever needed it collects input character stream into chunks of - * 32 bit values and invokes a block function that performs actual hash - * calculations. - * - * Porting guide. - * - * Obligatory macros: - * - * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN - * this macro defines byte order of input stream. - * HASH_CBLOCK - * size of a unit chunk HASH_BLOCK operates on. - * HASH_LONG - * has to be at lest 32 bit wide, if it's wider, then - * HASH_LONG_LOG2 *has to* be defined along - * HASH_CTX - * context structure that at least contains following - * members: - * typedef struct { - * ... - * HASH_LONG Nl,Nh; - * either { - * HASH_LONG data[HASH_LBLOCK]; - * unsigned char data[HASH_CBLOCK]; - * }; - * unsigned int num; - * ... - * } HASH_CTX; - * data[] vector is expected to be zeroed upon first call to - * HASH_UPDATE. - * HASH_UPDATE - * name of "Update" function, implemented here. - * HASH_TRANSFORM - * name of "Transform" function, implemented here. - * HASH_FINAL - * name of "Final" function, implemented here. - * HASH_BLOCK_DATA_ORDER - * name of "block" function capable of treating *unaligned* input - * message in original (data) byte order, implemented externally. - * HASH_MAKE_STRING - * macro convering context variables to an ASCII hash string. - * - * MD5 example: - * - * #define DATA_ORDER_IS_LITTLE_ENDIAN - * - * #define HASH_LONG MD5_LONG - * #define HASH_LONG_LOG2 MD5_LONG_LOG2 - * #define HASH_CTX MD5_CTX - * #define HASH_CBLOCK MD5_CBLOCK - * #define HASH_UPDATE MD5_Update - * #define HASH_TRANSFORM MD5_Transform - * #define HASH_FINAL MD5_Final - * #define HASH_BLOCK_DATA_ORDER md5_block_data_order - * - * - */ - -#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) -#error "DATA_ORDER must be defined!" -#endif - -#ifndef HASH_CBLOCK -#error "HASH_CBLOCK must be defined!" -#endif -#ifndef HASH_LONG -#error "HASH_LONG must be defined!" -#endif -#ifndef HASH_CTX -#error "HASH_CTX must be defined!" -#endif - -#ifndef HASH_UPDATE -#error "HASH_UPDATE must be defined!" -#endif -#ifndef HASH_TRANSFORM -#error "HASH_TRANSFORM must be defined!" -#endif -#ifndef HASH_FINAL -#error "HASH_FINAL must be defined!" -#endif - -#ifndef HASH_BLOCK_DATA_ORDER -#error "HASH_BLOCK_DATA_ORDER must be defined!" -#endif - -/* - * Engage compiler specific rotate intrinsic function if available. - */ -#undef ROTATE -#ifndef PEDANTIC -# if defined(_MSC_VER) || defined(__ICC) -# define ROTATE(a,n) _lrotl(a,n) -# elif defined(__MWERKS__) -# if defined(__POWERPC__) -# define ROTATE(a,n) __rlwinm(a,n,0,31) -# elif defined(__MC68K__) - /* Motorola specific tweak. */ -# define ROTATE(a,n) ( n<24 ? __rol(a,n) : __ror(a,32-n) ) -# else -# define ROTATE(a,n) __rol(a,n) -# endif -# elif defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) - /* - * Some GNU C inline assembler templates. Note that these are - * rotates by *constant* number of bits! But that's exactly - * what we need here... - * - */ -# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) -# define ROTATE(a,n) ({ register unsigned int ret; \ - asm ( \ - "roll %1,%0" \ - : "=r"(ret) \ - : "I"(n), "0"(a) \ - : "cc"); \ - ret; \ - }) -# elif defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \ - defined(__powerpc) || defined(__ppc__) || defined(__powerpc64__) -# define ROTATE(a,n) ({ register unsigned int ret; \ - asm ( \ - "rlwinm %0,%1,%2,0,31" \ - : "=r"(ret) \ - : "r"(a), "I"(n)); \ - ret; \ - }) -# elif defined(__s390x__) -# define ROTATE(a,n) ({ register unsigned int ret; \ - asm ("rll %0,%1,%2" \ - : "=r"(ret) \ - : "r"(a), "I"(n)); \ - ret; \ - }) -# endif -# endif -#endif /* PEDANTIC */ - -#ifndef ROTATE -#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) -#endif - -#if defined(DATA_ORDER_IS_BIG_ENDIAN) - -#ifndef PEDANTIC -# if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) -# if ((defined(__i386) || defined(__i386__)) && !defined(I386_ONLY)) || \ - (defined(__x86_64) || defined(__x86_64__)) -# if !defined(B_ENDIAN) - /* - * This gives ~30-40% performance improvement in SHA-256 compiled - * with gcc [on P4]. Well, first macro to be frank. We can pull - * this trick on x86* platforms only, because these CPUs can fetch - * unaligned data without raising an exception. - */ -# define HOST_c2l(c,l) ({ unsigned int r=*((const unsigned int *)(c)); \ - asm ("bswapl %0":"=r"(r):"0"(r)); \ - (c)+=4; (l)=r; }) -# define HOST_l2c(l,c) ({ unsigned int r=(l); \ - asm ("bswapl %0":"=r"(r):"0"(r)); \ - *((unsigned int *)(c))=r; (c)+=4; r; }) -# endif -# endif -# endif -#endif -#if defined(__s390__) || defined(__s390x__) -# define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4, (l)) -# define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, (l)) -#endif - -#ifndef HOST_c2l -#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ - l|=(((unsigned long)(*((c)++)))<<16), \ - l|=(((unsigned long)(*((c)++)))<< 8), \ - l|=(((unsigned long)(*((c)++))) ), \ - l) -#endif -#ifndef HOST_l2c -#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16)&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ - *((c)++)=(unsigned char)(((l) )&0xff), \ - l) -#endif - -#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) - -#ifndef PEDANTIC -# if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) -# if defined(__s390x__) -# define HOST_c2l(c,l) ({ asm ("lrv %0,%1" \ - :"=d"(l) :"m"(*(const unsigned int *)(c)));\ - (c)+=4; (l); }) -# define HOST_l2c(l,c) ({ asm ("strv %1,%0" \ - :"=m"(*(unsigned int *)(c)) :"d"(l));\ - (c)+=4; (l); }) -# endif -# endif -#endif -#if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) -# ifndef B_ENDIAN - /* See comment in DATA_ORDER_IS_BIG_ENDIAN section. */ -# define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4, l) -# define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, l) -# endif -#endif - -#ifndef HOST_c2l -#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ - l|=(((unsigned long)(*((c)++)))<< 8), \ - l|=(((unsigned long)(*((c)++)))<<16), \ - l|=(((unsigned long)(*((c)++)))<<24), \ - l) -#endif -#ifndef HOST_l2c -#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16)&0xff), \ - *((c)++)=(unsigned char)(((l)>>24)&0xff), \ - l) -#endif - -#endif - -/* - * Time for some action:-) - */ - -int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len) - { - const unsigned char *data=data_; - unsigned char *p; - HASH_LONG l; - size_t n; - - if (len==0) return 1; - - l=(c->Nl+(((HASH_LONG)len)<<3))&0xffffffffUL; - /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to - * Wei Dai for pointing it out. */ - if (l < c->Nl) /* overflow */ - c->Nh++; - c->Nh += (unsigned long)(len>>29); /* might cause compiler warning on 16-bit */ - c->Nl=l; - - n = c->num; - if (n != 0) - { - p=(unsigned char *)c->data; - - if (len >= HASH_CBLOCK || len+n >= HASH_CBLOCK) - { - memcpy (p+n,data,HASH_CBLOCK-n); - HASH_BLOCK_DATA_ORDER (c,p,1); - n = HASH_CBLOCK-n; - data += n; - len -= n; - c->num = 0; - memset (p,0,HASH_CBLOCK); /* keep it zeroed */ - } - else - { - memcpy (p+n,data,len); - c->num += (unsigned int)len; - return 1; - } - } - - n = len/HASH_CBLOCK; - if (n > 0) - { - HASH_BLOCK_DATA_ORDER (c,data,n); - n *= HASH_CBLOCK; - data += n; - len -= n; - } - - if (len != 0) - { - p = (unsigned char *)c->data; - c->num = (unsigned)len; - memcpy (p,data,len); - } - return 1; - } - - -void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data) - { - HASH_BLOCK_DATA_ORDER (c,data,1); - } - - -int HASH_FINAL (unsigned char *md, HASH_CTX *c) - { - unsigned char *p = (unsigned char *)c->data; - size_t n = c->num; - - p[n] = 0x80; /* there is always room for one */ - n++; - - if (n > (HASH_CBLOCK-8)) - { - memset (p+n,0,HASH_CBLOCK-n); - n=0; - HASH_BLOCK_DATA_ORDER (c,p,1); - } - memset (p+n,0,HASH_CBLOCK-8-n); - - p += HASH_CBLOCK-8; -#if defined(DATA_ORDER_IS_BIG_ENDIAN) - (void)HOST_l2c(c->Nh,p); - (void)HOST_l2c(c->Nl,p); -#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) - (void)HOST_l2c(c->Nl,p); - (void)HOST_l2c(c->Nh,p); -#endif - p -= HASH_CBLOCK; - HASH_BLOCK_DATA_ORDER (c,p,1); - c->num=0; - memset (p,0,HASH_CBLOCK); - -#ifndef HASH_MAKE_STRING -#error "HASH_MAKE_STRING must be defined!" -#else - HASH_MAKE_STRING(c,md); -#endif - - return 1; - } - -#ifndef MD32_REG_T -#define MD32_REG_T long -/* - * This comment was originaly written for MD5, which is why it - * discusses A-D. But it basically applies to all 32-bit digests, - * which is why it was moved to common header file. - * - * In case you wonder why A-D are declared as long and not - * as MD5_LONG. Doing so results in slight performance - * boost on LP64 architectures. The catch is we don't - * really care if 32 MSBs of a 64-bit register get polluted - * with eventual overflows as we *save* only 32 LSBs in - * *either* case. Now declaring 'em long excuses the compiler - * from keeping 32 MSBs zeroed resulting in 13% performance - * improvement under SPARC Solaris7/64 and 5% under AlphaLinux. - * Well, to be honest it should say that this *prevents* - * performance degradation. - * - * Apparently there're LP64 compilers that generate better - * code if A-D are declared int. Most notably GCC-x86_64 - * generates better code. - * - */ -#endif diff --git a/protocols/WhatsApp/src/OpenSSL/p5_crpt2.c b/protocols/WhatsApp/src/OpenSSL/p5_crpt2.c deleted file mode 100644 index 18b366d2c2..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/p5_crpt2.c +++ /dev/null @@ -1,113 +0,0 @@ -/* p5_crpt2.c */ -/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL - * project 1999. - */ -/* ==================================================================== - * Copyright (c) 1999 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * licensing@OpenSSL.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This product includes cryptographic software written by Eric Young - * (eay@cryptsoft.com). This product includes software written by Tim - * Hudson (tjh@cryptsoft.com). - * - */ -#include -#include -#include - -#include "evp.h" -#include "hmac.h" - -#define SHA_DIGEST_LENGTH 20 - -/* This is an implementation of PKCS#5 v2.0 password based encryption key - * derivation function PBKDF2 using the only currently defined function HMAC - * with SHA1. Verified against test vectors posted by Peter Gutmann - * to the PKCS-TNG mailing list. - */ - -int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, - const unsigned char *salt, int saltlen, int iter, - int keylen, unsigned char *out) -{ - unsigned char digtmp[SHA_DIGEST_LENGTH], *p, itmp[4]; - int cplen, j, k, tkeylen; - unsigned long i = 1; - HMAC_CTX hctx; - - HMAC_CTX_init(&hctx); - p = out; - tkeylen = keylen; - if(!pass) passlen = 0; - else if(passlen == -1) passlen = (int)strlen(pass); - while(tkeylen) { - if(tkeylen > SHA_DIGEST_LENGTH) cplen = SHA_DIGEST_LENGTH; - else cplen = tkeylen; - /* We are unlikely to ever use more than 256 blocks (5120 bits!) - * but just in case... - */ - itmp[0] = (unsigned char)((i >> 24) & 0xff); - itmp[1] = (unsigned char)((i >> 16) & 0xff); - itmp[2] = (unsigned char)((i >> 8) & 0xff); - itmp[3] = (unsigned char)(i & 0xff); - HMAC_Init_ex(&hctx, pass, passlen, EVP_sha1(), NULL); - HMAC_Update(&hctx, salt, saltlen); - HMAC_Update(&hctx, itmp, 4); - HMAC_Final(&hctx, digtmp, NULL); - memcpy(p, digtmp, cplen); - for(j = 1; j < iter; j++) { - HMAC(EVP_sha1(), pass, passlen, - digtmp, SHA_DIGEST_LENGTH, digtmp, NULL); - for(k = 0; k < cplen; k++) p[k] ^= digtmp[k]; - } - tkeylen-= cplen; - i++; - p+= cplen; - } - HMAC_CTX_cleanup(&hctx); - return 1; -} diff --git a/protocols/WhatsApp/src/OpenSSL/rc4.h b/protocols/WhatsApp/src/OpenSSL/rc4.h deleted file mode 100644 index 91376bedd3..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/rc4.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef HEADER_RC4_LOCL_H -#define HEADER_RC4_LOCL_H - -typedef int RC4_INT; - -typedef struct rc4_key_st - { - RC4_INT x,y; - RC4_INT data[256]; - } RC4_KEY; - -#ifdef __cplusplus -extern "C" { -#endif - -void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); -void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, unsigned char *outdata); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/protocols/WhatsApp/src/OpenSSL/rc4_enc.c b/protocols/WhatsApp/src/OpenSSL/rc4_enc.c deleted file mode 100644 index 10e2c79991..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/rc4_enc.c +++ /dev/null @@ -1,314 +0,0 @@ -/* crypto/rc4/rc4_enc.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include "rc4.h" - -/* RC4 as implemented from a posting from - * Newsgroups: sci.crypt - * From: sterndark@netcom.com (David Sterndark) - * Subject: RC4 Algorithm revealed. - * Message-ID: - * Date: Wed, 14 Sep 1994 06:35:31 GMT - */ - -void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, - unsigned char *outdata) - { - register RC4_INT *d; - register RC4_INT x,y,tx,ty; - int i; - - x=key->x; - y=key->y; - d=key->data; - -#if defined(RC4_CHUNK) - /* - * The original reason for implementing this(*) was the fact that - * pre-21164a Alpha CPUs don't have byte load/store instructions - * and e.g. a byte store has to be done with 64-bit load, shift, - * and, or and finally 64-bit store. Peaking data and operating - * at natural word size made it possible to reduce amount of - * instructions as well as to perform early read-ahead without - * suffering from RAW (read-after-write) hazard. This resulted - * in ~40%(**) performance improvement on 21064 box with gcc. - * But it's not only Alpha users who win here:-) Thanks to the - * early-n-wide read-ahead this implementation also exhibits - * >40% speed-up on SPARC and 20-30% on 64-bit MIPS (depending - * on sizeof(RC4_INT)). - * - * (*) "this" means code which recognizes the case when input - * and output pointers appear to be aligned at natural CPU - * word boundary - * (**) i.e. according to 'apps/openssl speed rc4' benchmark, - * crypto/rc4/rc4speed.c exhibits almost 70% speed-up... - * - * Cavets. - * - * - RC4_CHUNK="unsigned long long" should be a #1 choice for - * UltraSPARC. Unfortunately gcc generates very slow code - * (2.5-3 times slower than one generated by Sun's WorkShop - * C) and therefore gcc (at least 2.95 and earlier) should - * always be told that RC4_CHUNK="unsigned long". - * - * - */ - -# define RC4_STEP ( \ - x=(x+1) &0xff, \ - tx=d[x], \ - y=(tx+y)&0xff, \ - ty=d[y], \ - d[y]=tx, \ - d[x]=ty, \ - (RC4_CHUNK)d[(tx+ty)&0xff]\ - ) - - if ( ( ((unsigned long)indata & (sizeof(RC4_CHUNK)-1)) | - ((unsigned long)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 ) - { - RC4_CHUNK ichunk,otp; - const union { long one; char little; } is_endian = {1}; - - /* - * I reckon we can afford to implement both endian - * cases and to decide which way to take at run-time - * because the machine code appears to be very compact - * and redundant 1-2KB is perfectly tolerable (i.e. - * in case the compiler fails to eliminate it:-). By - * suggestion from Terrel Larson - * who also stands for the is_endian union:-) - * - * Special notes. - * - * - is_endian is declared automatic as doing otherwise - * (declaring static) prevents gcc from eliminating - * the redundant code; - * - compilers (those I've tried) don't seem to have - * problems eliminating either the operators guarded - * by "if (sizeof(RC4_CHUNK)==8)" or the condition - * expressions themselves so I've got 'em to replace - * corresponding #ifdefs from the previous version; - * - I chose to let the redundant switch cases when - * sizeof(RC4_CHUNK)!=8 be (were also #ifdefed - * before); - * - in case you wonder "&(sizeof(RC4_CHUNK)*8-1)" in - * [LB]ESHFT guards against "shift is out of range" - * warnings when sizeof(RC4_CHUNK)!=8 - * - * - */ - if (!is_endian.little) - { /* BIG-ENDIAN CASE */ -# define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1)) - for (;len&~(sizeof(RC4_CHUNK)-1);len-=sizeof(RC4_CHUNK)) - { - ichunk = *(RC4_CHUNK *)indata; - otp = RC4_STEP<x=x; - key->y=y; - return; - } - else - { /* LITTLE-ENDIAN CASE */ -# define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1)) - for (;len&~(sizeof(RC4_CHUNK)-1);len-=sizeof(RC4_CHUNK)) - { - ichunk = *(RC4_CHUNK *)indata; - otp = RC4_STEP; - otp |= RC4_STEP<<8; - otp |= RC4_STEP<<16; - otp |= RC4_STEP<<24; - if (sizeof(RC4_CHUNK)==8) - { - otp |= RC4_STEP<>= (sizeof(RC4_CHUNK)-len)<<3; - switch (len&(sizeof(RC4_CHUNK)-1)) - { - case 7: otp = RC4_STEP, i+=8; - case 6: otp |= RC4_STEP<x=x; - key->y=y; - return; - } - } -#endif -#define LOOP(in,out) \ - x=((x+1)&0xff); \ - tx=d[x]; \ - y=(tx+y)&0xff; \ - d[x]=ty=d[y]; \ - d[y]=tx; \ - (out) = d[(tx+ty)&0xff]^ (in); - -#ifndef RC4_INDEX -#define RC4_LOOP(a,b,i) LOOP(*((a)++),*((b)++)) -#else -#define RC4_LOOP(a,b,i) LOOP(a[i],b[i]) -#endif - - i=(int)(len>>3L); - if (i) - { - for (;;) - { - RC4_LOOP(indata,outdata,0); - RC4_LOOP(indata,outdata,1); - RC4_LOOP(indata,outdata,2); - RC4_LOOP(indata,outdata,3); - RC4_LOOP(indata,outdata,4); - RC4_LOOP(indata,outdata,5); - RC4_LOOP(indata,outdata,6); - RC4_LOOP(indata,outdata,7); -#ifdef RC4_INDEX - indata+=8; - outdata+=8; -#endif - if (--i == 0) break; - } - } - i=(int)len&0x07; - if (i) - { - for (;;) - { - RC4_LOOP(indata,outdata,0); if (--i == 0) break; - RC4_LOOP(indata,outdata,1); if (--i == 0) break; - RC4_LOOP(indata,outdata,2); if (--i == 0) break; - RC4_LOOP(indata,outdata,3); if (--i == 0) break; - RC4_LOOP(indata,outdata,4); if (--i == 0) break; - RC4_LOOP(indata,outdata,5); if (--i == 0) break; - RC4_LOOP(indata,outdata,6); if (--i == 0) break; - } - } - key->x=x; - key->y=y; - } diff --git a/protocols/WhatsApp/src/OpenSSL/rc4_skey.c b/protocols/WhatsApp/src/OpenSSL/rc4_skey.c deleted file mode 100644 index 67b765cbbe..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/rc4_skey.c +++ /dev/null @@ -1,137 +0,0 @@ -/* crypto/rc4/rc4_skey.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - - -/* RC4 as implemented from a posting from - * Newsgroups: sci.crypt - * From: sterndark@netcom.com (David Sterndark) - * Subject: RC4 Algorithm revealed. - * Message-ID: - * Date: Wed, 14 Sep 1994 06:35:31 GMT - */ - -#include "rc4.h" - -void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data) - { - register RC4_INT tmp; - register int id1,id2; - register RC4_INT *d; - unsigned int i; - - d= &(key->data[0]); - key->x = 0; - key->y = 0; - id1=id2=0; - -#define SK_LOOP(d,n) { \ - tmp=d[(n)]; \ - id2 = (data[id1] + tmp + id2) & 0xff; \ - if (++id1 == len) id1=0; \ - d[(n)]=d[id2]; \ - d[id2]=tmp; } - -#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) -# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \ - defined(__INTEL__) || \ - defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) - if (sizeof(RC4_INT) > 1) { - /* - * Unlike all other x86 [and x86_64] implementations, - * Intel P4 core [including EM64T] was found to perform - * poorly with wider RC4_INT. Performance improvement - * for IA-32 hand-coded assembler turned out to be 2.8x - * if re-coded for RC4_CHAR! It's however inappropriate - * to just switch to RC4_CHAR for x86[_64], as non-P4 - * implementations suffer from significant performance - * losses then, e.g. PIII exhibits >2x deterioration, - * and so does Opteron. In order to assure optimal - * all-round performance, we detect P4 at run-time by - * checking upon reserved bit 20 in CPU capability - * vector and set up compressed key schedule, which is - * recognized by correspondingly updated assembler - * module... Bit 20 is set up by OPENSSL_ia32_cpuid. - * - * - */ -#ifdef OPENSSL_FIPS - unsigned long *ia32cap_ptr = OPENSSL_ia32cap_loc(); - if (ia32cap_ptr && (*ia32cap_ptr & (1<<28))) { -#else - if (OPENSSL_ia32cap_P & (1<<28)) { -#endif - unsigned char *cp=(unsigned char *)d; - - for (i=0;i<256;i++) cp[i]=i; - for (i=0;i<256;i++) SK_LOOP(cp,i); - /* mark schedule as compressed! */ - d[256/sizeof(RC4_INT)]=-1; - return; - } - } -# endif -#endif - for (i=0; i < 256; i++) d[i]=i; - for (i=0; i < 256; i+=4) - { - SK_LOOP(d,i+0); - SK_LOOP(d,i+1); - SK_LOOP(d,i+2); - SK_LOOP(d,i+3); - } - } diff --git a/protocols/WhatsApp/src/OpenSSL/rsa_sign.c b/protocols/WhatsApp/src/OpenSSL/rsa_sign.c deleted file mode 100644 index 1611834466..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/rsa_sign.c +++ /dev/null @@ -1,75 +0,0 @@ -/* crypto/rsa/rsa_sign.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include - -/* Size of an SSL signature: MD5+SHA1 */ -#define SSL_SIG_LENGTH 36 - -int RSA_sign(int type, const unsigned char *m, unsigned int m_len, - unsigned char *sigret, unsigned int *siglen, void *rsa) -{ - return(0); -} - -int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len, - unsigned char *sigbuf, unsigned int siglen, void *rsa) -{ - return(0); -} - diff --git a/protocols/WhatsApp/src/OpenSSL/sha_locl.h b/protocols/WhatsApp/src/OpenSSL/sha_locl.h deleted file mode 100644 index da160ceba6..0000000000 --- a/protocols/WhatsApp/src/OpenSSL/sha_locl.h +++ /dev/null @@ -1,443 +0,0 @@ -/* crypto/sha/sha_locl.h */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include - -#define DATA_ORDER_IS_BIG_ENDIAN - -#define HASH_LONG SHA_LONG -#define HASH_CTX SHA_CTX -#define HASH_CBLOCK SHA_CBLOCK -#define HASH_MAKE_STRING(c,s) do { \ - unsigned long ll; \ - ll=(c)->h0; HOST_l2c(ll,(s)); \ - ll=(c)->h1; HOST_l2c(ll,(s)); \ - ll=(c)->h2; HOST_l2c(ll,(s)); \ - ll=(c)->h3; HOST_l2c(ll,(s)); \ - ll=(c)->h4; HOST_l2c(ll,(s)); \ - } while (0) - -#if defined(SHA_0) - -# define HASH_UPDATE SHA_Update -# define HASH_TRANSFORM SHA_Transform -# define HASH_FINAL SHA_Final -# define HASH_INIT SHA_Init -# define HASH_BLOCK_DATA_ORDER sha_block_data_order -# define Xupdate(a,ix,ia,ib,ic,id) (ix=(a)=(ia^ib^ic^id)) - -static void sha_block_data_order (SHA_CTX *c, const void *p,size_t num); - -#elif defined(SHA_1) - -# define HASH_UPDATE SHA1_Update -# define HASH_TRANSFORM SHA1_Transform -# define HASH_FINAL SHA1_Final -# define HASH_INIT SHA1_Init -# define HASH_BLOCK_DATA_ORDER sha1_block_data_order -# if defined(__MWERKS__) && defined(__MC68K__) - /* Metrowerks for Motorola fails otherwise:-( */ -# define Xupdate(a,ix,ia,ib,ic,id) do { (a)=(ia^ib^ic^id); \ - ix=(a)=ROTATE((a),1); \ - } while (0) -# else -# define Xupdate(a,ix,ia,ib,ic,id) ( (a)=(ia^ib^ic^id), \ - ix=(a)=ROTATE((a),1) \ - ) -# endif - -#ifndef SHA1_ASM -static -#endif -void sha1_block_data_order (SHA_CTX *c, const void *p,size_t num); - -#else -# error "Either SHA_0 or SHA_1 must be defined." -#endif - -#include "md32_common.h" - -#define INIT_DATA_h0 0x67452301UL -#define INIT_DATA_h1 0xefcdab89UL -#define INIT_DATA_h2 0x98badcfeUL -#define INIT_DATA_h3 0x10325476UL -#define INIT_DATA_h4 0xc3d2e1f0UL - -#if defined(SHA_0) && defined(OPENSSL_FIPS) -FIPS_NON_FIPS_MD_Init(SHA) -#else -int HASH_INIT (SHA_CTX *c) -#endif - { -#if defined(SHA_1) && defined(OPENSSL_FIPS) - FIPS_selftest_check(); -#endif - c->h0=INIT_DATA_h0; - c->h1=INIT_DATA_h1; - c->h2=INIT_DATA_h2; - c->h3=INIT_DATA_h3; - c->h4=INIT_DATA_h4; - c->Nl=0; - c->Nh=0; - c->num=0; - return 1; - } - -#define K_00_19 0x5a827999UL -#define K_20_39 0x6ed9eba1UL -#define K_40_59 0x8f1bbcdcUL -#define K_60_79 0xca62c1d6UL - -/* As pointed out by Wei Dai , F() below can be - * simplified to the code in F_00_19. Wei attributes these optimisations - * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel. - * #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) - * I've just become aware of another tweak to be made, again from Wei Dai, - * in F_40_59, (x&a)|(y&a) -> (x|y)&a - */ -#define F_00_19(b,c,d) ((((c) ^ (d)) & (b)) ^ (d)) -#define F_20_39(b,c,d) ((b) ^ (c) ^ (d)) -#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d))) -#define F_60_79(b,c,d) F_20_39(b,c,d) - -#ifndef OPENSSL_SMALL_FOOTPRINT - -#define BODY_00_15(i,a,b,c,d,e,f,xi) \ - (f)=xi+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ - (b)=ROTATE((b),30); - -#define BODY_16_19(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \ - Xupdate(f,xi,xa,xb,xc,xd); \ - (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ - (b)=ROTATE((b),30); - -#define BODY_20_31(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \ - Xupdate(f,xi,xa,xb,xc,xd); \ - (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ - (b)=ROTATE((b),30); - -#define BODY_32_39(i,a,b,c,d,e,f,xa,xb,xc,xd) \ - Xupdate(f,xa,xa,xb,xc,xd); \ - (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ - (b)=ROTATE((b),30); - -#define BODY_40_59(i,a,b,c,d,e,f,xa,xb,xc,xd) \ - Xupdate(f,xa,xa,xb,xc,xd); \ - (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \ - (b)=ROTATE((b),30); - -#define BODY_60_79(i,a,b,c,d,e,f,xa,xb,xc,xd) \ - Xupdate(f,xa,xa,xb,xc,xd); \ - (f)=xa+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \ - (b)=ROTATE((b),30); - -#ifdef X -#undef X -#endif -#ifndef MD32_XARRAY - /* - * Originally X was an array. As it's automatic it's natural - * to expect RISC compiler to accomodate at least part of it in - * the register bank, isn't it? Unfortunately not all compilers - * "find" this expectation reasonable:-( On order to make such - * compilers generate better code I replace X[] with a bunch of - * X0, X1, etc. See the function body below... - * - */ -# define X(i) XX##i -#else - /* - * However! Some compilers (most notably HP C) get overwhelmed by - * that many local variables so that we have to have the way to - * fall down to the original behavior. - */ -# define X(i) XX[i] -#endif - -#if !defined(SHA_1) || !defined(SHA1_ASM) -static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num) - { - const unsigned char *data=p; - register unsigned A,B,C,D,E,T,l; -#ifndef MD32_XARRAY - unsigned XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, - XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; -#else - SHA_LONG XX[16]; -#endif - - A=c->h0; - B=c->h1; - C=c->h2; - D=c->h3; - E=c->h4; - - for (;;) - { - const union { long one; char little; } is_endian = {1}; - - if (!is_endian.little && sizeof(SHA_LONG)==4 && ((size_t)p%4)==0) - { - const SHA_LONG *W=(const SHA_LONG *)data; - - X( 0) = W[0]; X( 1) = W[ 1]; - BODY_00_15( 0,A,B,C,D,E,T,X( 0)); X( 2) = W[ 2]; - BODY_00_15( 1,T,A,B,C,D,E,X( 1)); X( 3) = W[ 3]; - BODY_00_15( 2,E,T,A,B,C,D,X( 2)); X( 4) = W[ 4]; - BODY_00_15( 3,D,E,T,A,B,C,X( 3)); X( 5) = W[ 5]; - BODY_00_15( 4,C,D,E,T,A,B,X( 4)); X( 6) = W[ 6]; - BODY_00_15( 5,B,C,D,E,T,A,X( 5)); X( 7) = W[ 7]; - BODY_00_15( 6,A,B,C,D,E,T,X( 6)); X( 8) = W[ 8]; - BODY_00_15( 7,T,A,B,C,D,E,X( 7)); X( 9) = W[ 9]; - BODY_00_15( 8,E,T,A,B,C,D,X( 8)); X(10) = W[10]; - BODY_00_15( 9,D,E,T,A,B,C,X( 9)); X(11) = W[11]; - BODY_00_15(10,C,D,E,T,A,B,X(10)); X(12) = W[12]; - BODY_00_15(11,B,C,D,E,T,A,X(11)); X(13) = W[13]; - BODY_00_15(12,A,B,C,D,E,T,X(12)); X(14) = W[14]; - BODY_00_15(13,T,A,B,C,D,E,X(13)); X(15) = W[15]; - BODY_00_15(14,E,T,A,B,C,D,X(14)); - BODY_00_15(15,D,E,T,A,B,C,X(15)); - - data += SHA_CBLOCK; - } - else - { - HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l; - BODY_00_15( 0,A,B,C,D,E,T,X( 0)); HOST_c2l(data,l); X( 2)=l; - BODY_00_15( 1,T,A,B,C,D,E,X( 1)); HOST_c2l(data,l); X( 3)=l; - BODY_00_15( 2,E,T,A,B,C,D,X( 2)); HOST_c2l(data,l); X( 4)=l; - BODY_00_15( 3,D,E,T,A,B,C,X( 3)); HOST_c2l(data,l); X( 5)=l; - BODY_00_15( 4,C,D,E,T,A,B,X( 4)); HOST_c2l(data,l); X( 6)=l; - BODY_00_15( 5,B,C,D,E,T,A,X( 5)); HOST_c2l(data,l); X( 7)=l; - BODY_00_15( 6,A,B,C,D,E,T,X( 6)); HOST_c2l(data,l); X( 8)=l; - BODY_00_15( 7,T,A,B,C,D,E,X( 7)); HOST_c2l(data,l); X( 9)=l; - BODY_00_15( 8,E,T,A,B,C,D,X( 8)); HOST_c2l(data,l); X(10)=l; - BODY_00_15( 9,D,E,T,A,B,C,X( 9)); HOST_c2l(data,l); X(11)=l; - BODY_00_15(10,C,D,E,T,A,B,X(10)); HOST_c2l(data,l); X(12)=l; - BODY_00_15(11,B,C,D,E,T,A,X(11)); HOST_c2l(data,l); X(13)=l; - BODY_00_15(12,A,B,C,D,E,T,X(12)); HOST_c2l(data,l); X(14)=l; - BODY_00_15(13,T,A,B,C,D,E,X(13)); HOST_c2l(data,l); X(15)=l; - BODY_00_15(14,E,T,A,B,C,D,X(14)); - BODY_00_15(15,D,E,T,A,B,C,X(15)); - } - - BODY_16_19(16,C,D,E,T,A,B,X( 0),X( 0),X( 2),X( 8),X(13)); - BODY_16_19(17,B,C,D,E,T,A,X( 1),X( 1),X( 3),X( 9),X(14)); - BODY_16_19(18,A,B,C,D,E,T,X( 2),X( 2),X( 4),X(10),X(15)); - BODY_16_19(19,T,A,B,C,D,E,X( 3),X( 3),X( 5),X(11),X( 0)); - - BODY_20_31(20,E,T,A,B,C,D,X( 4),X( 4),X( 6),X(12),X( 1)); - BODY_20_31(21,D,E,T,A,B,C,X( 5),X( 5),X( 7),X(13),X( 2)); - BODY_20_31(22,C,D,E,T,A,B,X( 6),X( 6),X( 8),X(14),X( 3)); - BODY_20_31(23,B,C,D,E,T,A,X( 7),X( 7),X( 9),X(15),X( 4)); - BODY_20_31(24,A,B,C,D,E,T,X( 8),X( 8),X(10),X( 0),X( 5)); - BODY_20_31(25,T,A,B,C,D,E,X( 9),X( 9),X(11),X( 1),X( 6)); - BODY_20_31(26,E,T,A,B,C,D,X(10),X(10),X(12),X( 2),X( 7)); - BODY_20_31(27,D,E,T,A,B,C,X(11),X(11),X(13),X( 3),X( 8)); - BODY_20_31(28,C,D,E,T,A,B,X(12),X(12),X(14),X( 4),X( 9)); - BODY_20_31(29,B,C,D,E,T,A,X(13),X(13),X(15),X( 5),X(10)); - BODY_20_31(30,A,B,C,D,E,T,X(14),X(14),X( 0),X( 6),X(11)); - BODY_20_31(31,T,A,B,C,D,E,X(15),X(15),X( 1),X( 7),X(12)); - - BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13)); - BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14)); - BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15)); - BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0)); - BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1)); - BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2)); - BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3)); - BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4)); - - BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5)); - BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6)); - BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7)); - BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8)); - BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9)); - BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10)); - BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11)); - BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12)); - BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13)); - BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14)); - BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15)); - BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0)); - BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1)); - BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2)); - BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3)); - BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4)); - BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5)); - BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6)); - BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7)); - BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8)); - - BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9)); - BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10)); - BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11)); - BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12)); - BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13)); - BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14)); - BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15)); - BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0)); - BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1)); - BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2)); - BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3)); - BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4)); - BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5)); - BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6)); - BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7)); - BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8)); - BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9)); - BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10)); - BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11)); - BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12)); - - c->h0=(c->h0+E)&0xffffffffL; - c->h1=(c->h1+T)&0xffffffffL; - c->h2=(c->h2+A)&0xffffffffL; - c->h3=(c->h3+B)&0xffffffffL; - c->h4=(c->h4+C)&0xffffffffL; - - if (--num == 0) break; - - A=c->h0; - B=c->h1; - C=c->h2; - D=c->h3; - E=c->h4; - - } - } -#endif - -#else /* OPENSSL_SMALL_FOOTPRINT */ - -#define BODY_00_15(xi) do { \ - T=E+K_00_19+F_00_19(B,C,D); \ - E=D, D=C, C=ROTATE(B,30), B=A; \ - A=ROTATE(A,5)+T+xi; } while(0) - -#define BODY_16_19(xa,xb,xc,xd) do { \ - Xupdate(T,xa,xa,xb,xc,xd); \ - T+=E+K_00_19+F_00_19(B,C,D); \ - E=D, D=C, C=ROTATE(B,30), B=A; \ - A=ROTATE(A,5)+T; } while(0) - -#define BODY_20_39(xa,xb,xc,xd) do { \ - Xupdate(T,xa,xa,xb,xc,xd); \ - T+=E+K_20_39+F_20_39(B,C,D); \ - E=D, D=C, C=ROTATE(B,30), B=A; \ - A=ROTATE(A,5)+T; } while(0) - -#define BODY_40_59(xa,xb,xc,xd) do { \ - Xupdate(T,xa,xa,xb,xc,xd); \ - T+=E+K_40_59+F_40_59(B,C,D); \ - E=D, D=C, C=ROTATE(B,30), B=A; \ - A=ROTATE(A,5)+T; } while(0) - -#define BODY_60_79(xa,xb,xc,xd) do { \ - Xupdate(T,xa,xa,xb,xc,xd); \ - T=E+K_60_79+F_60_79(B,C,D); \ - E=D, D=C, C=ROTATE(B,30), B=A; \ - A=ROTATE(A,5)+T+xa; } while(0) - -#if !defined(SHA_1) || !defined(SHA1_ASM) -static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num) - { - const unsigned char *data=p; - register unsigned MD32_REG_T A,B,C,D,E,T,l; - int i; - SHA_LONG X[16]; - - A=c->h0; - B=c->h1; - C=c->h2; - D=c->h3; - E=c->h4; - - for (;;) - { - for (i=0;i<16;i++) - { HOST_c2l(data,l); X[i]=l; BODY_00_15(X[i]); } - for (i=0;i<4;i++) - { BODY_16_19(X[i], X[i+2], X[i+8], X[(i+13)&15]); } - for (;i<24;i++) - { BODY_20_39(X[i&15], X[(i+2)&15], X[(i+8)&15],X[(i+13)&15]); } - for (i=0;i<20;i++) - { BODY_40_59(X[(i+8)&15],X[(i+10)&15],X[i&15], X[(i+5)&15]); } - for (i=4;i<24;i++) - { BODY_60_79(X[(i+8)&15],X[(i+10)&15],X[i&15], X[(i+5)&15]); } - - c->h0=(c->h0+A)&0xffffffffL; - c->h1=(c->h1+B)&0xffffffffL; - c->h2=(c->h2+C)&0xffffffffL; - c->h3=(c->h3+D)&0xffffffffL; - c->h4=(c->h4+E)&0xffffffffL; - - if (--num == 0) break; - - A=c->h0; - B=c->h1; - C=c->h2; - D=c->h3; - E=c->h4; - - } - } -#endif - -#endif diff --git a/protocols/WhatsApp/src/WASocketConnection.cpp b/protocols/WhatsApp/src/WASocketConnection.cpp deleted file mode 100644 index 316d8fb5af..0000000000 --- a/protocols/WhatsApp/src/WASocketConnection.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include "stdafx.h" -#include "WASocketConnection.h" - -HNETLIBUSER g_hNetlibUser = nullptr; - -void WASocketConnection::initNetwork(HNETLIBUSER hNetlibUser) throw (WAException) -{ - g_hNetlibUser = hNetlibUser; -} - -void WASocketConnection::quitNetwork() -{ -} - -WASocketConnection::WASocketConnection(const std::string &dir, int port) throw (WAException) -{ - NETLIBOPENCONNECTION noc = { sizeof(noc) }; - noc.szHost = dir.c_str(); - noc.wPort = port; - noc.flags = NLOCF_V2; // | NLOCF_SSL; - this->hConn = Netlib_OpenConnection(g_hNetlibUser, &noc); - if (this->hConn == nullptr) - throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_OPEN); - - this->connected = true; -} - -void WASocketConnection::write(int i) -{ - char buffer; - buffer = (char)i; - - int result = Netlib_Send(this->hConn, &buffer, 1, MSG_NOHTTPGATEWAYWRAP | MSG_NODUMP); - if (result < 1) - throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_SEND); -} - -void WASocketConnection::makeNonBlock() -{ - throw WAException("Error setting socket nonblocking!", WAException::SOCKET_EX, WAException::SOCKET_EX_OPEN); -} - -void WASocketConnection::flush() {} - -void WASocketConnection::write(const std::vector &bytes, int length) -{ - std::string tmpBuf = std::string(bytes.begin(), bytes.end()); - int result = Netlib_Send(hConn, tmpBuf.c_str(), length, MSG_NODUMP); - if (result < length) - throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_SEND); -} - -unsigned char WASocketConnection::read() -{ - SetLastError(0); - - char c; - int result = Netlib_Recv(this->hConn, &c, 1, 0); - if (result <= 0) - throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_RECV); - - return c; -} - -int WASocketConnection::read(unsigned char *buf, int length) -{ - int result = Netlib_Recv(this->hConn, (char*)buf, length, MSG_NODUMP); - if (result <= 0) - throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_RECV); - - return result; -} - -int WASocketConnection::read(std::vector& b, int off, int length) -{ - if (off < 0 || length < 0) - throw new WAException("Out of bounds", WAException::SOCKET_EX, WAException::SOCKET_EX_RECV); - - char* buffer = (char*)_alloca(length); - int result = Netlib_Recv(this->hConn, buffer, length, MSG_NOHTTPGATEWAYWRAP | MSG_NODUMP); - if (result <= 0) - throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_RECV); - - for (int i = 0; i < result; i++) - b[off + i] = buffer[i]; - - return result; -} - -void WASocketConnection::forceShutdown() -{ - Netlib_Shutdown(this->hConn); -} - -void WASocketConnection::log(const char *prefix, const char *str) -{ - Netlib_Logf(g_hNetlibUser, "%s%s", prefix, str); -} - -WASocketConnection::~WASocketConnection() -{ - this->forceShutdown(); - Netlib_CloseHandle(this->hConn); -} diff --git a/protocols/WhatsApp/src/WASocketConnection.h b/protocols/WhatsApp/src/WASocketConnection.h deleted file mode 100644 index 83eb61e7f5..0000000000 --- a/protocols/WhatsApp/src/WASocketConnection.h +++ /dev/null @@ -1,35 +0,0 @@ -#if !defined(WASOCKETCONNECTION_H) -#define WASOCKETCONNECTION_H - -#include "WhatsAPI++/ISocketConnection.h" -#include "WhatsAPI++/WAException.h" - -class WASocketConnection : public ISocketConnection -{ - int readSize; - int maxBufRead; - bool connected; - - HNETLIBCONN hConn; - -public: - WASocketConnection(const std::string &dir, int port) throw (WAException); - virtual ~WASocketConnection(); - - virtual void write(int i); - virtual unsigned char read(); - virtual int read(std::vector& b, int off, int length); - virtual int read(unsigned char*, int length); - virtual void flush(); - virtual void write(const std::vector& b, int length); - // virtual void write(const std::vector& bytes, int offset, int length); - virtual void makeNonBlock(); - virtual void forceShutdown(); - - virtual void log(const char *prefix, const char *str); - - static void initNetwork(HNETLIBUSER hNetlibUser) throw (WAException); - static void quitNetwork(); -}; - -#endif // WASOCKETCONNECTION_H \ No newline at end of file diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp deleted file mode 100644 index b3ed6aa3f5..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp +++ /dev/null @@ -1,347 +0,0 @@ -/* - * BinTreeNodeReader.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "BinTreeNodeReader.h" -#include "WAException.h" -#include "ProtocolTreeNode.h" -#include "utilities.h" - -extern const char *dictionary[], *extended_dict[]; - -BinTreeNodeReader::BinTreeNodeReader(WAConnection *conn, ISocketConnection *connection) : - buf(BUFFER_SIZE) -{ - this->conn = conn; - this->rawIn = connection; - this->readSize = 1; - this->in = NULL; -} - -BinTreeNodeReader::~BinTreeNodeReader() -{ - delete this->in; -} - -ProtocolTreeNode* BinTreeNodeReader::nextTreeInternal() -{ - int b = this->in->read(); - int size = readListSize(b); - b = this->in->read(); - if (b == 2) - return NULL; - - std::string* tag = this->readStringAsString(b); - - if ((size == 0) || (tag == NULL)) - throw WAException("nextTree sees 0 list or null tag", WAException::CORRUPT_STREAM_EX, -1); - int attribCount = (size - 2 + size % 2) / 2; - std::map* attribs = readAttributes(attribCount); - if (size % 2 == 1) { - ProtocolTreeNode* ret = new ProtocolTreeNode(*tag); ret->attributes = attribs; - delete tag; - return ret; - } - b = this->in->read(); - if (isListTag(b)) { - ProtocolTreeNode* ret = new ProtocolTreeNode(*tag, NULL, readList(b)); ret->attributes = attribs; - delete tag; - return ret; - } - - ReadData* obj = this->readString(b); - std::vector* data; - if (obj->type == STRING) { - std::string* s = (std::string*) obj->data; - data = new std::vector(s->begin(), s->end()); - delete s; - } - else data = (std::vector*) obj->data; - - ProtocolTreeNode* ret = new ProtocolTreeNode(*tag, data); ret->attributes = attribs; - delete obj; - delete tag; - return ret; -} - -bool BinTreeNodeReader::isListTag(int b) -{ - return (b == 248) || (b == 0) || (b == 249); -} - -void BinTreeNodeReader::decodeStream(int flags, int offset, int length) -{ - unsigned char *pData = (unsigned char*)&buf[0]; - - if ((flags & 8) != 0) { - if (length < 4) - throw WAException("invalid length" + length, WAException::CORRUPT_STREAM_EX, 0); - - length -= 4; - - this->conn->inputKey.decodeMessage(pData, offset + length, 0, length); - } - - if (this->in != NULL) - delete this->in; - this->in = new ByteArrayInputStream(&this->buf, offset, length); -} - -std::map* BinTreeNodeReader::readAttributes(int attribCount) -{ - std::map* attribs = new std::map(); - for (int i = 0; i < attribCount; i++) { - std::string* key = readStringAsString(); - std::string* value = readStringAsString(); - (*attribs)[*key] = *value; - delete key; - delete value; - } - return attribs; -} - -std::vector* BinTreeNodeReader::readList(int token) -{ - int size = readListSize(token); - std::vector* list = new std::vector(size); - for (int i = 0; i < size; i++) - (*list)[i] = nextTreeInternal(); - - return list; -} - -int BinTreeNodeReader::readListSize(int token) -{ - switch (token) { - case 0: return 0; - case 248: return readInt8(this->in); - case 249: return readInt16(this->in); - default: - throw new WAException("invalid list size in readListSize: token " + token, WAException::CORRUPT_STREAM_EX, 0); - } - return 0; -} - -std::vector* BinTreeNodeReader::readList() -{ - return readList(this->in->read()); -} - -ReadData* BinTreeNodeReader::readString() -{ - return readString(this->in->read()); -} - -ReadData* BinTreeNodeReader::readString(int token) -{ - if (token == -1) - throw WAException("-1 token in readString", WAException::CORRUPT_STREAM_EX, -1); - - int bSize; - ReadData *ret = new ReadData(); - - if (token > 2 && token <= 236) { - if (token != 236) - ret->data = new std::string(dictionary[token]); - else { - token = readInt8(this->in); - ret->data = new std::string(extended_dict[token]); - } - - ret->type = STRING; - return ret; - } - - switch (token) { - case 0: - delete ret; - return NULL; - - case 252: - bSize = readInt8(this->in); - { - std::vector* buf8 = new std::vector(bSize); - fillArray(*buf8, bSize, this->in); - ret->type = ARRAY; - ret->data = buf8; - } - return ret; - - case 253: - bSize = readInt24(this->in); - { - std::vector* buf24 = new std::vector(bSize); - fillArray(*buf24, bSize, this->in); - ret->type = ARRAY; - ret->data = buf24; - } - return ret; - - case 255: - bSize = readInt8(this->in); - { - int size = bSize & 0x7f; - int numnibbles = size * 2 - ((bSize & 0x80) ? 1 : 0); - - std::vector tmp(size); - fillArray(tmp, size, this->in); - std::string s; - for (int i = 0; i < numnibbles; i++) { - char c = (tmp[i / 2] >> (4 - ((i & 1) << 2))) & 0xF; - if (c < 10) s += (c + '0'); - else s += (c - 10 + '-'); - } - - ret->type = STRING; - ret->data = new std::string(s); - } - return ret; - - case 250: - std::string* user = readStringAsString(); - std::string* server = readStringAsString(); - if ((user != NULL) && (server != NULL)) { - std::string* result = new std::string(*user + "@" + *server); - delete user; - delete server; - ret->type = STRING; - ret->data = result; - return ret; - } - if (server != NULL) { - ret->type = STRING; - ret->data = server; - return ret; - } - throw WAException("readString couldn't reconstruct jid", WAException::CORRUPT_STREAM_EX, -1); - } - throw WAException("readString couldn't match token" + (int)token, WAException::CORRUPT_STREAM_EX, -1); -} - -std::string* BinTreeNodeReader::objectAsString(ReadData* o) -{ - if (o->type == STRING) - return (std::string*) o->data; - - if (o->type == ARRAY) { - std::vector* v = (std::vector*) o->data; - std::string* ret = new std::string(v->begin(), v->end()); - delete v; - return ret; - } - - return NULL; -} - -std::string* BinTreeNodeReader::readStringAsString() -{ - ReadData* o = this->readString(); - std::string* ret = this->objectAsString(o); - delete o; - return ret; -} - -std::string* BinTreeNodeReader::readStringAsString(int token) -{ - ReadData* o = this->readString(token); - std::string* ret = this->objectAsString(o); - delete o; - return ret; -} - -void BinTreeNodeReader::fillArray(std::vector& buff, int len, ByteArrayInputStream* in) -{ - int count = 0; - while (count < len) - count += in->read(buff, count, len - count); -} - -void BinTreeNodeReader::fillArray(std::vector& buff, int len, ISocketConnection *in) -{ - int count = 0; - while (count < len) - count += in->read(buff, count, len - count); -} - -void BinTreeNodeReader::getTopLevelStream() -{ - int stanzaSize = readInt24(this->rawIn); - int flags = (stanzaSize >> 20); - stanzaSize &= 0x0FFFFF; - - if (this->buf.size() < (size_t)stanzaSize) { - int newsize = max((int)(this->buf.size() * 3 / 2), stanzaSize); - this->buf.resize(newsize); - } - fillArray(this->buf, stanzaSize, this->rawIn); - - this->decodeStream(flags, 0, stanzaSize); -} - -int BinTreeNodeReader::readInt8(ByteArrayInputStream* in) -{ - return in->read(); -} - -int BinTreeNodeReader::readInt16(ByteArrayInputStream* in) -{ - int intTop = in->read(); - int intBot = in->read(); - int value = (intTop << 8) + intBot; - return value; -} - -int BinTreeNodeReader::readInt24(ByteArrayInputStream* in) -{ - int int1 = in->read(); - int int2 = in->read(); - int int3 = in->read(); - int value = (int1 << 16) + (int2 << 8) + int3; - - return value; -} - -ProtocolTreeNode* BinTreeNodeReader::nextTree() -{ - this->getTopLevelStream(); - return nextTreeInternal(); -} - -void BinTreeNodeReader::streamStart() -{ - this->getTopLevelStream(); - - int tag = this->in->read(); - int size = readListSize(tag); - tag = this->in->read(); - if (tag != 1) - throw WAException("expecting STREAM_START in streamStart", WAException::CORRUPT_STREAM_EX, 0); - - int attribCount = (size - 2 + size % 2) / 2; - std::map* attributes = readAttributes(attribCount); - delete attributes; -} - -int BinTreeNodeReader::readInt8(ISocketConnection *in) -{ - return in->read(); -} - -int BinTreeNodeReader::readInt16(ISocketConnection *in) -{ - unsigned char data[2]; - in->read(data, 2); - return (int(data[0]) << 8) + int(data[1]); -} - -int BinTreeNodeReader::readInt24(ISocketConnection *in) -{ - unsigned char data[3]; - in->read(data, 3); - return (int(data[0]) << 16) + (int(data[1]) << 8) + int(data[2]); -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.h b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.h deleted file mode 100644 index 7a2d43454d..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * BinTreeNodeReader.h - * - * Created on: 26/06/2012 - * Author: Antonio - */ -#ifndef BINTREENODEREADER_H_ -#define BINTREENODEREADER_H_ - -#include "ProtocolTreeNode.h" -#include "ISocketConnection.h" -#include "ByteArray.h" -#include "WAConnection.h" -#include -#include -#include - -#define BUFFER_SIZE 512 - -class WAConnection; - -enum ReadType {STRING, ARRAY}; - -class ReadData { -public: - ReadData() {}; - virtual ~ReadData() {}; - - ReadType type; - void * data; -}; - -class BinTreeNodeReader { -private: - ISocketConnection *rawIn; - ByteArrayInputStream* in; - std::vector buf; - int readSize; - WAConnection *conn; - - ProtocolTreeNode* nextTreeInternal(); - bool isListTag(int b); - void decodeStream(int flags, int offset, int length); - std::map* readAttributes(int attribCount); - std::vector* readList(int token); - int readListSize(int token); - std::vector* readList(); - ReadData* readString(); - ReadData* readString(int token); - static void fillArray(std::vector& buff, int len, ByteArrayInputStream* in); - static void fillArray(std::vector& buff, int len, ISocketConnection *in); - std::string* objectAsString(ReadData* o); - std::string* readStringAsString(); - std::string* readStringAsString(int token); - void getTopLevelStream(); - static int readInt8(ByteArrayInputStream* in); - static int readInt8(ISocketConnection *in); - static int readInt16(ByteArrayInputStream* in); - static int readInt16(ISocketConnection *in); - static int readInt24(ByteArrayInputStream* in); - static int readInt24(ISocketConnection *in); - - -public: - BinTreeNodeReader(WAConnection* conn, ISocketConnection* connection); - ~BinTreeNodeReader(); - ProtocolTreeNode* nextTree(); - void streamStart(); - -}; - -#endif /* BINTREENODEREADER_H_ */ - diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp deleted file mode 100644 index 19bf6a466f..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp +++ /dev/null @@ -1,276 +0,0 @@ -/* - * BinTreeNodeWriter.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "BinTreeNodeWriter.h" -#include "utilities.h" - -BinTreeNodeWriter::BinTreeNodeWriter(WAConnection *_conn, ISocketConnection *_connection, IMutex *_mutex) -{ - bSecure = false; - bFlush = true; - mutex = _mutex; - conn = _conn; - out = new ByteArrayOutputStream(4096); - realOut = _connection; - dataBegin = 0; -} - -BinTreeNodeWriter::~BinTreeNodeWriter() -{ - delete out; -} - -void BinTreeNodeWriter::writeDummyHeader() -{ - dataBegin = (int)out->getPosition(); // save node start offset - - unsigned char zero3[3] = { 0, 0, 0 }; - out->write(zero3, 3); -} - -void BinTreeNodeWriter::processBuffer() -{ - unsigned char num = 0; - if (bSecure) { - unsigned char zero4[4] = { 0, 0, 0, 0 }; - out->write(zero4, 4); // reserve place for hmac - num = 0x80; - } - int num3 = (int)out->getLength() - 3 - dataBegin; - if (num3 >= 1048576L) - throw WAException("Buffer too large: " + num3, WAException::CORRUPT_STREAM_EX, 0); - - std::vector &buffer = out->getBuffer(); - if (bSecure) { - int num4 = num3 - 4; - conn->outputKey.encodeMessage(buffer.data(), dataBegin + 3 + num4, dataBegin + 3, num4); - } - - buffer[dataBegin + 2] = (unsigned char)(num3 & 0xFF); num3 >>= 8; - buffer[dataBegin + 1] = (unsigned char)(num3 & 0xFF); num3 >>= 8; - buffer[dataBegin] = (unsigned char)(num3 & 0xFF) | num; -} - -void BinTreeNodeWriter::streamStart(std::string domain, std::string resource) -{ - this->mutex->lock(); - try { - out->setPosition(0); - out->setLength(0); - out->write('W'); - out->write('A'); - out->write(1); - out->write(5); - - std::map attributes; - attributes["to"] = domain; - attributes["resource"] = resource; - this->writeDummyHeader(); - this->writeListStart((int)attributes.size() * 2 + 1); - out->write(1); - this->writeAttributes(&attributes); - this->processBuffer(); - this->flushBuffer(true); - } - catch (exception& ex) { - this->mutex->unlock(); - throw ex; - } - this->mutex->unlock(); -} - -void BinTreeNodeWriter::writeListStart(int i) -{ - if (i == 0) { - out->write(0); - } - else if (i < 256) { - out->write(248); - writeInt8(i); - } - else { - out->write(249); - writeInt16(i); - } -} - -void BinTreeNodeWriter::writeInt8(int v) -{ - out->write(v & 0xFF); -} - -void BinTreeNodeWriter::writeInt16(int v, ISocketConnection* o) -{ - o->write((v & 0xFF00) >> 8); - o->write((v & 0xFF) >> 0); -} - -void BinTreeNodeWriter::writeInt16(int v) -{ - writeInt16(v, this->out); -} - -void BinTreeNodeWriter::writeInt16(int v, ByteArrayOutputStream* o) -{ - o->write((v & 0xFF00) >> 8); - o->write((v & 0xFF) >> 0); -} - -void BinTreeNodeWriter::writeAttributes(std::map* attributes) -{ - if (attributes != NULL) { - std::map::iterator ii; - for (ii = attributes->begin(); ii != attributes->end(); ii++) { - writeString(ii->first); - writeString(ii->second); - } - } -} - -void BinTreeNodeWriter::writeString(const std::string &tag) -{ - int token = WAConnection::tokenLookup(tag); - if (token != -1) - writeToken(token); - else { - size_t atIndex = tag.find('@'); - if (atIndex == 0 || atIndex == string::npos) - writeBytes((unsigned char*)tag.data(), (int)tag.length()); - else { - std::string server = tag.substr(atIndex + 1); - std::string user = tag.substr(0, atIndex); - writeJid(&user, server); - } - } -} - -void BinTreeNodeWriter::writeJid(std::string* user, const std::string &server) -{ - out->write(250); - if (user != NULL && !user->empty()) - writeString(*user); - else - writeToken(0); - - writeString(server); - -} - -void BinTreeNodeWriter::writeToken(int intValue) -{ - if (intValue & 0x100) { - out->write(236); - out->write(intValue & 0xFF); - } - else out->write(intValue); -} - -void BinTreeNodeWriter::writeBytes(unsigned char* bytes, int length) -{ - if (length >= 256) { - out->write(253); - writeInt24(length); - } - else { - out->write(252); - writeInt8(length); - } - out->write(bytes, length); -} - -void BinTreeNodeWriter::writeInt24(int v) -{ - out->write((v & 0xFF0000) >> 16); - out->write((v & 0xFF00) >> 8); - out->write(v & 0xFF); -} - -void BinTreeNodeWriter::writeInternal(const ProtocolTreeNode &node) -{ - writeListStart( - 1 + (node.attributes == NULL ? 0 : (int)node.attributes->size() * 2) - + (node.children == NULL ? 0 : 1) - + (node.data == NULL ? 0 : 1)); - writeString(node.tag); - writeAttributes(node.attributes); - if (node.data != NULL) - writeBytes((unsigned char*)node.data->data(), (int)node.data->size()); - - if (node.children != NULL && !node.children->empty()) { - writeListStart((int)node.children->size()); - for (size_t a = 0; a < node.children->size(); a++) - writeInternal(*(*node.children)[a]); - } -} - -void BinTreeNodeWriter::flushBuffer(bool flushNetwork) -{ - try { - this->processBuffer(); - } - catch (WAException& ex) { - out->setPosition(0); - out->setLength(0); - throw ex; - } - - if (!flushNetwork) - return; - - std::vector &buffer = out->getBuffer(); - this->realOut->write(buffer, (int)buffer.size()); - if (out->getCapacity() - out->getLength() < 3L || out->getLength() > 4096L) { - delete out; - out = new ByteArrayOutputStream(4096); - } - else { - out->setPosition(0); - out->setLength(0); - } - dataBegin = 0; -} - -void BinTreeNodeWriter::streamEnd() -{ - this->mutex->lock(); - try { - writeListStart(1); - out->write(2); - flushBuffer(true); - } - catch (exception& ex) { - this->mutex->unlock(); - throw ex; - } - this->mutex->unlock(); -} - -void BinTreeNodeWriter::write(const ProtocolTreeNode& node) -{ - this->mutex->lock(); - try { - this->writeDummyHeader(); - - if (bSecure) { - string tmp = node.toString(); - this->realOut->log("XML written:\n", tmp.c_str()); - } - - if (node.tag.empty()) - out->write(0); - else - writeInternal(node); - flushBuffer(bFlush); - } - catch (exception& ex) { - this->mutex->unlock(); - throw WAException(ex.what()); - } - this->mutex->unlock(); -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h deleted file mode 100644 index f7ed6a6bc8..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * BinTreeNodeWriter.h - * - * Created on: 26/06/2012 - * Author: Antonio - */ - - -#ifndef BINTREENODEWRITER_H_ -#define BINTREENODEWRITER_H_ - -#include -#include "ProtocolTreeNode.h" -#include "ISocketConnection.h" -#include "ByteArray.h" -#include "IMutex.h" -#include "WAConnection.h" - -using namespace std; - -#define STREAM_START 1 -#define STREAM_END 2 -#define LIST_EMPTY 0 -#define LIST_8 248 -#define LIST_16 249 -#define JID_PAIR 250 -#define BINARY_8 252 -#define BINARY_24 253 -#define TOKEN_8 254 - -#include - -class BinTreeNodeWriter -{ - friend class WAConnection; - - WAConnection *conn; - ISocketConnection *realOut; - ByteArrayOutputStream *out; - IMutex *mutex; - int dataBegin; - bool bSecure, bFlush; - - void writeListStart(int i); - void writeInt8(int v); - void writeInt16(int v, ISocketConnection* out); - void writeInt16(int v, ByteArrayOutputStream* out); - void writeInt16(int v); - void writeAttributes(std::map* attributes); - void writeString(const std::string &tag); - void writeJid(std::string* user, const std::string &server); - void writeToken(int intValue); - void writeBytes(unsigned char* bytes, int length); - void writeInt24(int v); - void writeInternal(const ProtocolTreeNode &node); - void writeDummyHeader(); - void processBuffer(); - -public: - BinTreeNodeWriter(WAConnection* conn, ISocketConnection* connection, IMutex* mutex); - ~BinTreeNodeWriter(); - - void streamStart(std::string domain, std::string resource); - void flushBuffer(bool flushNetwork); - void streamEnd(); - void write(const ProtocolTreeNode &node); - - void setSecure() { bSecure = true; } -}; - -#endif /* BINTREENODEWRITER_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp b/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp deleted file mode 100644 index 8dbc044e67..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * ByteArray.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "ByteArray.h" -#include "WAException.h" -#include "utilities.h" - -ByteArrayOutputStream::ByteArrayOutputStream(int size) -{ - buf.reserve(size); - position = 0; -} - -void ByteArrayOutputStream::setLength(size_t length) -{ - buf.resize(length); -} - -void ByteArrayOutputStream::setPosition(size_t count) -{ - position = count; -} - - -std::vector& ByteArrayOutputStream::getBuffer() -{ - return buf; -} - -void ByteArrayOutputStream::write(int i) -{ - if (this->position == this->buf.size()) - buf.push_back((unsigned char)i); - else - buf[position] = (unsigned char)i; - position++; -} - -void ByteArrayOutputStream::write(unsigned char* b, size_t len) -{ - if (len == 0) - return; - - for (size_t i = 0; i < len; i++) - write(b[i]); -} - -void ByteArrayOutputStream::write(const std::string &s) -{ - for (size_t i = 0; i < s.size(); i++) - write((unsigned char)s[i]); -} - -ByteArrayOutputStream::~ByteArrayOutputStream() -{ -} - -ByteArrayInputStream::ByteArrayInputStream(std::vector* buf, size_t off, size_t length) -{ - this->buf = buf; - this->pos = off; - this->count = min(off + length, buf->size()); -} - -ByteArrayInputStream::ByteArrayInputStream(std::vector* buf) -{ - this->buf = buf; - this->pos = 0; - this->count = buf->size(); -} - -int ByteArrayInputStream::read() -{ - return (pos < count) ? ((*this->buf)[pos++]) : -1; -} - -int ByteArrayInputStream::read(std::vector& b, size_t off, size_t len) -{ - if (len > (b.size() - off)) - throw new WAException("Index out of bounds"); - - if (len == 0) - return 0; - - int c = read(); - if (c == -1) - return -1; - - b[off] = (unsigned char)c; - - size_t i = 1; - try { - for (; i < len; i++) { - c = read(); - if (c == -1) - break; - - b[off + i] = (unsigned char)c; - } - } - catch (std::exception&) { - } - return (int)i; -} - -ByteArrayInputStream::~ByteArrayInputStream() -{} diff --git a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.h b/protocols/WhatsApp/src/WhatsAPI++/ByteArray.h deleted file mode 100644 index d3375d1f3b..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * ByteArray.h - * - * Created on: 26/06/2012 - * Author: Antonio - */ - - - -#ifndef BYTEARRAY_H_ -#define BYTEARRAY_H_ - -#include -#include - -class ByteArrayOutputStream { -protected: - std::vector buf; - size_t position; - -public: - ByteArrayOutputStream(int size = 32); - virtual ~ByteArrayOutputStream(); - - std::vector& getBuffer(); - void setPosition(size_t count); - void write(int i); - void write(unsigned char* c, size_t length); - void write(const std::string &s); - void setLength(size_t length); - - __forceinline size_t getCapacity() const { return buf.capacity(); } - __forceinline size_t getLength() const { return buf.size(); } - __forceinline size_t getPosition() const { return position; } -}; - -class ByteArrayInputStream { -protected: - std::vector* buf; - size_t pos; - size_t mark; - size_t count; - -public: - ByteArrayInputStream(std::vector* buf, size_t off, size_t length ); - ByteArrayInputStream(std::vector* buf); - int read(); - int read(std::vector& b, size_t off, size_t length); - - virtual ~ByteArrayInputStream(); -}; - -#endif /* BYTEARRAY_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp b/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp deleted file mode 100644 index 8358560f99..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * FMessage.cpp - * - * Created on: 02/07/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "utilities.h" - -FMessage::FMessage() : - key("", false, "") -{ - this->timestamp = 0; - this->media_wa_type = 0; - this->longitude = 0; - this->latitude = 0; - this->media_duration_seconds = 0; - this->media_size = 0; -} - -FMessage::FMessage(const std::string &remote_jid, bool from_me, const std::string &id) : - key(remote_jid, from_me, id) -{ - this->timestamp = time(NULL); - this->media_wa_type = 0; - this->longitude = 0; - this->latitude = 0; - this->media_duration_seconds = 0; - this->media_size = 0; -} - -std::string FMessage::getMessage_WA_Type_StrValue(unsigned char type) -{ - switch (type) { - case FMessage::WA_TYPE_UNDEFINED: - return ""; - case FMessage::WA_TYPE_SYSTEM: - return "system"; - case FMessage::WA_TYPE_AUDIO: - return "audio"; - case FMessage::WA_TYPE_CONTACT: - return "vcard"; - case FMessage::WA_TYPE_IMAGE: - return "image"; - case FMessage::WA_TYPE_LOCATION: - return "location"; - case FMessage::WA_TYPE_VIDEO: - return "video"; - } - - return ""; -} - -FMessage::~FMessage() -{ -} - -Key::Key(const std::string &remote_jid, bool from_me, const std::string &id) -{ - this->remote_jid = remote_jid; - this->from_me = from_me; - this->id = id; -} - -std::string Key::toString() -{ - return "Key[id=" + id + ", from_me=" + (from_me ? "true" : "false") + ", remote_jid=" + remote_jid + "]"; -} - - -unsigned char FMessage::getMessage_WA_Type(const std::string &type) -{ - if (type.empty()) - return WA_TYPE_UNDEFINED; - - std::string typeLower = type; - std::transform(typeLower.begin(), typeLower.end(), typeLower.begin(), ::tolower); - if (typeLower.compare("system") == 0) - return WA_TYPE_SYSTEM; - if (typeLower.compare("image") == 0) - return WA_TYPE_IMAGE; - if (typeLower.compare("audio") == 0) - return WA_TYPE_AUDIO; - if (typeLower.compare("video") == 0) - return WA_TYPE_VIDEO; - if (typeLower.compare("vcard") == 0) - return WA_TYPE_CONTACT; - if (typeLower.compare("location") == 0) - return WA_TYPE_LOCATION; - - return WA_TYPE_UNDEFINED; -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/FMessage.h b/protocols/WhatsApp/src/WhatsAPI++/FMessage.h deleted file mode 100644 index 0d55aa6804..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/FMessage.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * FMessage.h - * - * Created on: 02/07/2012 - * Author: Antonio - */ - - - -#ifndef FMESSAGE_H_ -#define FMESSAGE_H_ - -#include -//#include -#include -#include "IMutex.h" - -struct Key -{ - std::string remote_jid; - bool from_me; - std::string id; - - Key(const std::string &remote_jid, bool from_me, const std::string &id); - std::string toString(); - -}; - -struct FMessage -{ - Key key; - unsigned char media_wa_type; - std::string data; - long long timestamp; - std::string remote_resource; - bool wants_receipt; - unsigned char status; - std::string notifyname; - bool offline; - std::string media_url; - std::string media_name; - - long long media_size; - int media_duration_seconds; - double latitude; - double longitude; - - enum { - WA_TYPE_UNDEFINED = 0, - WA_TYPE_IMAGE = 1, - WA_TYPE_AUDIO = 2, - WA_TYPE_VIDEO = 3, - WA_TYPE_CONTACT = 4, - WA_TYPE_LOCATION = 5, - WA_TYPE_SYSTEM = 7 - }; - - enum { - STATUS_UNSENT = 0, - STATUS_UPLOADING = 1, - STATUS_UPLOADED = 2, - STATUS_SENT_BY_CLIENT = 3, - STATUS_RECEIVED_BY_SERVER = 4, - STATUS_RECEIVED_BY_TARGET = 5, - STATUS_NEVER_SEND = 6, - STATUS_SERVER_BOUNCE = 7, - - STATUS_USER_ADDED = 191, - STATUS_USER_REMOVED = 192, - STATUS_SUBJECT_CHANGED = 193, - STATUS_PICTURE_CHANGED_SET = 194, - STATUS_PICTURE_CHANGED_DELETE = 195 - }; - - static std::string getMessage_WA_Type_StrValue(unsigned char type); - static unsigned char getMessage_WA_Type(const std::string &typeString); - - FMessage(); - FMessage(const std::string &remote_jid, bool from_me, const std::string &id); - virtual ~FMessage(); -}; - -#endif /* FMESSAGE_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/IMutex.h b/protocols/WhatsApp/src/WhatsAPI++/IMutex.h deleted file mode 100644 index 56a5492ac9..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/IMutex.h +++ /dev/null @@ -1,14 +0,0 @@ -#if !defined(IMUTEX_H) -#define IMUTEX_H - -class IMutex -{ -public: - IMutex() {} - virtual ~IMutex() {} - - virtual void lock() = 0; - virtual void unlock() = 0; -}; - -#endif \ No newline at end of file diff --git a/protocols/WhatsApp/src/WhatsAPI++/ISocketConnection.h b/protocols/WhatsApp/src/WhatsAPI++/ISocketConnection.h deleted file mode 100644 index b017df8cdc..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/ISocketConnection.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef ISOCKETCONNECTION_H_ -#define ISOCKETCONNECTION_H_ - -#include - -class ISocketConnection { - -public: - ISocketConnection() {} - virtual ~ISocketConnection() {} - - virtual void write(int i) = 0; - virtual unsigned char read() = 0; - virtual void flush() = 0; - virtual void write(const std::vector& b, int length) = 0; - virtual int read(unsigned char*, int length) = 0; - virtual int read(std::vector& b, int off, int length) = 0; - virtual void makeNonBlock() = 0; - virtual void forceShutdown() = 0; - - virtual void log(const char *prefix, const char *str) = 0; -}; - -#endif /* ISOCKETCONNECTION_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp b/protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp deleted file mode 100644 index 563e5ac7f1..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * WALogin.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "WALogin.h" -#include "ByteArray.h" -#include "ProtocolTreeNode.h" -#include "WAException.h" - -using namespace Utilities; - -KeyStream::KeyStream() : - seq(0) -{ - HMAC_CTX_init(&hmac); -} - -KeyStream::~KeyStream() -{ - HMAC_CTX_cleanup(&hmac); -} - -void KeyStream::init(unsigned char* _key, unsigned char* _keyMac) -{ - memcpy(key, _key, 20); - memcpy(keyMac, _keyMac, 20); - - RC4_set_key(&this->rc4, 20, this->key); - - unsigned char drop[768]; - RC4(&this->rc4, sizeof(drop), drop, drop); -} - -void KeyStream::keyFromPasswordAndNonce(const std::string &pass, const std::vector& nonce, unsigned char *out) -{ - size_t cbSize = nonce.size(); - - uint8_t *pNonce = (uint8_t*)_alloca(cbSize + 1); - memcpy(pNonce, nonce.data(), cbSize); - - for (int i = 0; i < 4; i++) { - pNonce[cbSize] = i + 1; - PKCS5_PBKDF2_HMAC_SHA1(pass.data(), (int)pass.size(), pNonce, (int)cbSize+1, 2, 20, out + i*20); - } -} - -void KeyStream::decodeMessage(unsigned char* buffer, int macOffset, int offset, const int length) -{ - unsigned char digest[20]; - this->hmacsha1(buffer + offset, length, digest); - - if (memcmp(&buffer[macOffset], digest, 4)) - throw WAException("invalid MAC", WAException::CORRUPT_STREAM_EX, 0); - - unsigned char* out = (unsigned char*)_alloca(length); - RC4(&this->rc4, length, buffer + offset, out); - memcpy(buffer + offset, out, length); -} - -void KeyStream::encodeMessage(unsigned char* buffer, int macOffset, int offset, const int length) -{ - unsigned char* out = (unsigned char*)_alloca(length); - RC4(&this->rc4, length, buffer + offset, out); - memcpy(buffer + offset, out, length); - - unsigned char digest[20]; - this->hmacsha1(buffer + offset, length, digest); - memcpy(buffer + macOffset, digest, 4); -} - -void KeyStream::hmacsha1(unsigned char* text, int textLength, unsigned char *out) -{ - HMAC_Init(&hmac, this->keyMac, 20, EVP_sha1()); - HMAC_Update(&hmac, text, textLength); - - unsigned char hmacInt[4]; - hmacInt[0] = (this->seq >> 24); - hmacInt[1] = (this->seq >> 16); - hmacInt[2] = (this->seq >> 8); - hmacInt[3] = (this->seq); - HMAC_Update(&hmac, hmacInt, sizeof(hmacInt)); - - unsigned int mdLength; - HMAC_Final(&hmac, out, &mdLength); - - this->seq++; -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/LICENSE b/protocols/WhatsApp/src/WhatsAPI++/LICENSE deleted file mode 100644 index cccee9ef01..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/LICENSE +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/protocols/WhatsApp/src/WhatsAPI++/MediaUploader.cpp b/protocols/WhatsApp/src/WhatsAPI++/MediaUploader.cpp deleted file mode 100644 index 34a99a9de4..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/MediaUploader.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "../stdafx.h" -#include "MediaUploader.h" - -// TODO get rid of unneeded headers added by NETLIBHTTPREQUEST. it sould look like this: -//POST https://mmiXYZ.whatsapp.net/u/gOzeKj6U64LABC -//Content-Type: multipart/form-data; boundary=zzXXzzYYzzXXzzQQ -//Host: mmiXYZ.whatsapp.net -//User-Agent: WhatsApp/2.12.96 S40Version/14.26 Device/Nokia302 -//Content-Length: 9999999999 -// -//So remove these somehow: -//Accept-Encoding: deflate, gzip -//Connection: Keep-Alive -//Proxy-Connection: Keep-Alive - -static NETLIBHTTPHEADER s_imageHeaders[] = -{ - { "User-Agent", ACCOUNT_USER_AGENT }, - { "Content-Type", "multipart/form-data; boundary=zzXXzzYYzzXXzzQQ" } -}; - -static std::vector* sttFileToMem(const wchar_t *ptszFileName) -{ - HANDLE hFile = CreateFile(ptszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile == INVALID_HANDLE_VALUE) - return NULL; - - DWORD upperSize, lowerSize = GetFileSize(hFile, &upperSize); - std::vector *result = new std::vector(lowerSize); - ReadFile(hFile, (void*)result->data(), lowerSize, &upperSize, NULL); - CloseHandle(hFile); - return result; -} - -namespace MediaUploader -{ - std::string sendData(std::string host, std::string head, std::string filePath, std::string tail) - { - // TODO string crap: can this be done more nicely? - std::wstring stemp = std::wstring(filePath.begin(), filePath.end()); - LPCWSTR sw = stemp.c_str(); - - vector *dataVector = sttFileToMem(sw); - - vector allVector(head.begin(), head.end()); - allVector.insert(allVector.end(), dataVector->begin(), dataVector->end()); - allVector.insert(allVector.end(), tail.begin(), tail.end()); - - NETLIBHTTPREQUEST nlhr = { sizeof(NETLIBHTTPREQUEST) }; - nlhr.requestType = REQUEST_POST; - nlhr.szUrl = (char*)host.c_str(); - nlhr.headers = s_imageHeaders; - nlhr.headersCount = _countof(s_imageHeaders); - nlhr.flags = NLHRF_HTTP11 | NLHRF_SSL; - nlhr.pData = (char*)allVector.data(); - nlhr.dataLength = (int)allVector.size(); - - NETLIBHTTPREQUEST *pnlhr = Netlib_HttpTransaction(g_hNetlibUser, &nlhr); - - string data = pnlhr->pData; - - if (!data.empty()) - return data; - else return 0; - } - - std::string pushfile(std::string url, FMessage * message, std::string from) - { - return getPostString(url, message, from); - } - - std::string getPostString(std::string url, FMessage * message, std::string from) - { - string filePath = message->media_url; - string to = message->key.remote_jid; - string extension = split(filePath, '.')[1]; - - uint8_t digest[16]; - md5_string(filePath, digest); - char dest[33]; - bin2hex(digest, sizeof(digest), dest); - - string cryptoname = dest; - cryptoname += "." + extension; - string boundary = "zzXXzzYYzzXXzzQQ"; - - string hBAOS = "--" + boundary + "\r\n"; - hBAOS += "Content-Disposition: form-data; name=\"to\"\r\n\r\n"; - hBAOS += to + "\r\n"; - hBAOS += "--" + boundary + "\r\n"; - hBAOS += "Content-Disposition: form-data; name=\"from\"\r\n\r\n"; - hBAOS += from + "\r\n"; - hBAOS += "--" + boundary + "\r\n"; - hBAOS += "Content-Disposition: form-data; name=\"file\"; filename=\"" + cryptoname + "\"\r\n"; - hBAOS += "Content-Type: " + getMimeFromExtension(extension) + "\r\n\r\n"; - - string fBAOS = "\r\n--" + boundary + "--\r\n"; - return sendData(url, hBAOS, filePath, fBAOS); - } - - static map extensions; - - std::string getMimeFromExtension(const string &extension) - { - if (extensions.empty()) { - extensions["audio/3gpp"] = "3gp"; - extensions["audio/x-caf"] = "caf"; - extensions["audio/wav"] = "wav"; - extensions["audio/mpeg"] = "mp3"; - extensions["audio/mpeg3"] = "mp3"; - extensions["audio/x-mpeg-32"] = "mp3"; - extensions["audio/x-ms-wma"] = "wma"; - extensions["audio/ogg"] = "ogg"; - extensions["audio/aiff"] = "aif"; - extensions["audio/x-aiff"] = "aif"; - extensions["audio/mp4"] = "m4a"; - extensions["image/jpeg"] = "jpg"; - extensions["image/gif"] = "gif"; - extensions["image/png"] = "png"; - extensions["video/3gpp"] = "3gp"; - extensions["video/mp4"] = "mp4"; - extensions["video/quicktime"] = "mov"; - extensions["video/avi"] = "avi"; - extensions["video/msvideo"] = "avi"; - extensions["video/x-msvideo"] = "avi"; - } - - for (auto it = extensions.begin(); it != extensions.end(); ++it) - if ((*it).second == extension) - return (*it).first; - - return ""; - } -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/MediaUploader.h b/protocols/WhatsApp/src/WhatsAPI++/MediaUploader.h deleted file mode 100644 index 7fb6612095..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/MediaUploader.h +++ /dev/null @@ -1,18 +0,0 @@ -/* -* -*/ -#ifndef MEDIAUPLOADER_H_ -#define MEDIAUPLOADER_H_ - -using namespace std; - -namespace MediaUploader -{ - std::string pushfile(std::string url, FMessage * message, std::string from); - std::string getPostString(std::string url, FMessage * message, std::string from); - std::string sendData(std::string host, std::string head, std::string filePath, std::string tail); - std::string getExtensionFromMime(string mime); - std::string getMimeFromExtension(const string &extension); -}; - -#endif /* MEDIAUPLOADER_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.cpp b/protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.cpp deleted file mode 100644 index dc5466321d..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.cpp +++ /dev/null @@ -1,298 +0,0 @@ -/* - * PhoneNumber.cpp - * - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "PhoneNumber.h" - -struct CountryDescr -{ - char *name; - int countryCode, mcc, mnc; - char *ISO3166, *ISO639; -} -static countries[] = -{ - { "Russia", 7, 250, 20, "RU", "ru" }, - { "Kazakhstan", 7, 401, 77, "KZ", "kk" }, - { "Afghanistan", 93, 412, 1, "AF", "ps" }, - { "Albania", 355, 276, 1, "AL", "sq" }, - { "Alberta", 1403, 302, 720, "CA", "en" }, - { "Alberta", 1780, 302, 720, "CA", "en" }, - { "Algeria", 213, 603, 1, "DZ", "ar" }, - { "Andorra", 376, 213, 3, "AD", "ca" }, - { "Angola", 244, 631, 2, "AO", "pt" }, - { "Anguilla", 1264, 365, 10, "AI", "en" }, - { "Antarctica (Australian bases)", 6721, 232, 1, "AQ", "en" }, - { "Antigua and Barbuda", 1268, 344, 50, "AG", "en" }, - { "Argentina", 54, 722, 10, "AR", "es" }, - { "Armenia", 374, 283, 10, "AM", "hy" }, - { "Aruba", 297, 363, 1, "AW", "nl" }, - { "Ascension", 247, 658, 1, "AC", "en" }, - { "Australia", 61, 505, 1, "AU", "en" }, - { "Austria", 43, 232, 3, "AT", "de" }, - { "Azerbaijan", 994, 400, 1, "AZ", "az" }, - { "Bahamas", 1242, 364, 39, "BS", "en" }, - { "Bahrain", 973, 426, 1, "BH", "ar" }, - { "Bangladesh", 880, 470, 1, "BD", "bn" }, - { "Barbados", 1246, 342, 750, "BB", "en" }, - { "Belarus", 375, 257, 1, "BY", "be" }, - { "Belgium", 32, 206, 1, "BE", "nl" }, - { "Belize", 501, 702, 67, "BZ", "es" }, - { "Benin", 229, 616, 1, "BJ", "fr" }, - { "Bermuda", 1441, 350, 1, "BM", "en" }, - { "Bhutan", 975, 402, 11, "BT", "dz" }, - { "Bolivia", 591, 736, 1, "BO", "es" }, - { "Bosnia and Herzegovina", 387, 218, 3, "BA", "bs" }, - { "Botswana", 267, 652, 4, "BW", "en" }, - { "Brazil", 55, 724, 2, "BR", "pt" }, - { "British Columbia", 1250, 302, 720, "CA", "en" }, - { "British Columbia", 1604, 302, 720, "CA", "en" }, - { "British Columbia", 1778, 302, 720, "CA", "en" }, - { "British Indian Ocean Territory", 246, 348, 1, "IO", "en" }, - { "British Virgin Islands", 1284, 348, 170, "GB", "en" }, - { "Brunei", 673, 528, 11, "BN", "ms" }, - { "Bulgaria", 359, 284, 3, "BG", "bg" }, - { "Burkina Faso", 226, 613, 1, "BF", "fr" }, - { "Burundi", 257, 642, 82, "BI", "rn" }, - { "Cambodia", 855, 456, 2, "KH", "km" }, - { "Cameroon", 237, 624, 1, "CM", "fr" }, - { "Cape Verde", 238, 625, 1, "CV", "pt" }, - { "Cayman Islands", 1345, 346, 50, "GB", "en" }, - { "Central African Republic", 236, 623, 3, "CF", "sg" }, - { "Chad", 235, 622, 4, "TD", "fr" }, - { "Chile", 56, 730, 2, "CL", "es" }, - { "China", 86, 460, 3, "CN", "en" }, - { "Colombia", 57, 732, 102, "CO", "es" }, - { "Comoros", 269, 654, 1, "KM", "fr" }, - { "Democratic Republic of the Congo", 243, 630, 1, "CD", "fr" }, - { "Republic of the Congo", 242, 629, 1, "CG", "fr" }, - { "Cook Islands", 682, 548, 1, "CK", "en" }, - { "Costa Rica", 506, 658, 4, "CR", "es" }, - { "Cote d'Ivoire", 712, 612, 1, "CI", "fr" }, - { "Croatia", 385, 219, 1, "HR", "hr" }, - { "Cuba", 53, 368, 1, "CU", "es" }, - { "Cyprus", 357, 280, 1, "CY", "el" }, - { "Czech Republic", 420, 230, 2, "CZ", "cs" }, - { "Denmark", 45, 238, 1, "DK", "da" }, - { "Djibouti", 253, 638, 1, "DJ", "fr" }, - { "Dominica", 1767, 366, 20, "DM", "en" }, - { "Dominican Republic", 1809, 370, 1, "DO", "es" }, - { "Dominican Republic", 1829, 370, 1, "DO", "en" }, - { "East Timor", 670, 514, 1, "TL", "pt" }, - { "Ecuador", 593, 740, 0, "EC", "es" }, - { "Egypt", 20, 602, 2, "EG", "ar" }, - { "El Salvador", 503, 706, 1, "SV", "es" }, - { "Equatorial Guinea", 240, 627, 3, "GQ", "es" }, - { "Eritrea", 291, 657, 1, "ER", "ti" }, - { "Estonia", 372, 248, 3, "EE", "et" }, - { "Ethiopia", 251, 636, 11, "ET", "am" }, - { "Falkland Islands", 500, 750, 1, "FK", "en" }, - { "Faroe Islands", 298, 288, 2, "FO", "fo" }, - { "Fiji", 679, 542, 1, "FJ", "en" }, - { "Finland", 358, 244, 5, "FI", "fi" }, - { "France", 33, 208, 9, "FR", "fr" }, - { "French Guiana", 594, 742, 1, "GF", "fr" }, - { "French Polynesia", 689, 547, 15, "PF", "fr" }, - { "Gabon", 241, 628, 1, "GA", "fr" }, - { "Gambia", 220, 607, 1, "GM", "en" }, - { "Gaza Strip", 970, 0, 0, "PS", "ar" }, - { "Georgia", 995, 282, 1, "GE", "ka" }, - { "Germany", 49, 262, 1, "DE", "de" }, - { "Ghana", 233, 620, 2, "GH", "ak" }, - { "Gibraltar", 350, 266, 9, "GI", "en" }, - { "Greece", 30, 202, 5, "GR", "el" }, - { "Greenland", 299, 290, 1, "GL", "kl" }, - { "Grenada", 1473, 352, 30, "GD", "en" }, - { "Guadeloupe", 590, 340, 1, "GP", "fr" }, - { "Guam", 1671, 535, 32, "GU", "en" }, - { "Guatemala", 502, 704, 1, "GT", "es" }, - { "Guinea", 224, 611, 1, "GN", "fr" }, - { "Guinea-Bissau", 245, 632, 3, "GW", "pt" }, - { "Guyana", 592, 738, 1, "GY", "pt" }, - { "Haiti", 509, 372, 2, "HT", "fr" }, - { "Honduras", 504, 708, 2, "HN", "es" }, - { "Hong Kong", 852, 454, 0, "HK", "zh" }, - { "Hungary", 36, 216, 70, "HU", "hu" }, - { "Iceland", 354, 274, 2, "IS", "is" }, - { "India", 91, 404, 30, "IN", "hi" }, - { "Indonesia", 62, 510, 10, "ID", "id" }, - { "Iraq", 964, 418, 20, "IQ", "ar" }, - { "Iran", 98, 432, 35, "IR", "fa" }, - { "Ireland (Eire)", 353, 272, 1, "IE", "en" }, - { "Israel", 972, 425, 1, "IL", "he" }, - { "Italy", 39, 222, 10, "IT", "it" }, - { "Jamaica", 1876, 338, 50, "JM", "en" }, - { "Japan", 81, 440, 1, "JP", "ja" }, - { "Jordan", 962, 416, 77, "JO", "ar" }, - { "Kenya", 254, 639, 7, "KE", "sw" }, - { "Kiribati", 686, 545, 1, "KI", "en" }, - { "Kuwait", 965, 419, 4, "KW", "ar" }, - { "Kyrgyzstan", 996, 437, 1, "KG", "ky" }, - { "Laos", 856, 457, 1, "LA", "lo" }, - { "Latvia", 371, 247, 2, "LV", "lv" }, - { "Lebanon", 961, 415, 1, "LB", "ar" }, - { "Lesotho", 266, 651, 1, "LS", "st" }, - { "Liberia", 231, 618, 7, "LR", "en" }, - { "Libya", 218, 606, 0, "LY", "ar" }, - { "Liechtenstein", 423, 295, 2, "LI", "de" }, - { "Lithuania", 370, 246, 3, "LT", "lt" }, - { "Luxembourg", 352, 270, 99, "LU", "fr" }, - { "Macau", 853, 455, 2, "MO", "pt" }, - { "Republic of Macedonia", 389, 294, 1, "MK", "mk" }, - { "Madagascar", 261, 646, 2, "MG", "mg" }, - { "Malawi", 265, 650, 1, "MW", "ny" }, - { "Malaysia", 60, 502, 16, "MY", "en" }, - { "Maldives", 960, 472, 1, "MV", "dv" }, - { "Mali", 223, 610, 2, "ML", "fr" }, - { "Malta", 356, 278, 1, "MT", "mt" }, - { "Manitoba", 1204, 302, 720, "CA", "en" }, - { "Marshall Islands", 692, 551, 1, "MH", "mh" }, - { "Martinique", 596, 340, 1, "MQ", "fr" }, - { "Mauritania", 222, 609, 2, "MR", "ar" }, - { "Mauritius", 230, 617, 1, "MU", "en" }, - { "Mayotte", 262, 654, 1, "YT", "fr" }, - { "Mexico", 52, 334, 3, "MX", "es" }, - { "Federated States of Micronesia", 691, 550, 1, "FM", "en" }, - { "Moldova", 373, 259, 1, "MD", "ru" }, - { "Monaco", 377, 212, 1, "MC", "fr" }, - { "Mongolia", 976, 428, 91, "MN", "mn" }, - { "Montenegro", 382, 297, 2, "ME", "sr" }, - { "Montserrat", 1664, 354, 860, "MS", "en" }, - { "Morocco", 212, 604, 0, "MA", "ar" }, - { "Mozambique", 258, 643, 4, "MZ", "pt" }, - { "Myanmar", 95, 414, 1, "MM", "my" }, - { "Namibia", 264, 649, 3, "NA", "en" }, - { "Nauru", 674, 536, 2, "NR", "na" }, - { "Netherlands", 31, 204, 4, "NL", "nl" }, - { "Netherlands Antilles", 599, 362, 51, "AN", "nl" }, - { "Nepal", 977, 429, 1, "NP", "ne" }, - { "New Brunswick", 1506, 302, 720, "CA", "en" }, - { "New Caledonia", 687, 546, 1, "NC", "fr" }, - { "New Zealand", 64, 530, 1, "NZ", "en" }, - { "Newfoundland", 1709, 302, 720, "CA", "en" }, - { "Nicaragua", 505, 710, 30, "NI", "es" }, - { "Niger", 227, 614, 4, "NE", "fr" }, - { "Nigeria", 234, 621, 20, "NG", "ha" }, - { "Niue", 683, 555, 1, "NU", "en" }, - { "Norfolk Island", 6723, 505, 10, "NF", "en" }, - { "North Korea", 850, 467, 193, "KP", "ko" }, - { "Northern Mariana Islands", 1670, 534, 1, "MP", "en" }, - { "Northwest Territories", 1867, 302, 720, "CA", "en" }, - { "Norway", 47, 242, 4, "NO", "nb" }, - { "Nova Scotia", 1902, 302, 720, "CA", "en" }, - { "Oman", 968, 422, 2, "OM", "ar" }, - { "Ontario", 1416, 302, 720, "CA", "en" }, - { "Ontario", 1519, 302, 720, "CA", "en" }, - { "Ontario", 1613, 302, 720, "CA", "en" }, - { "Ontario", 1647, 302, 720, "CA", "en" }, - { "Ontario", 1705, 302, 720, "CA", "en" }, - { "Ontario", 1807, 302, 720, "CA", "en" }, - { "Ontario", 1905, 302, 720, "CA", "en" }, - { "Pakistan", 92, 410, 1, "PK", "en" }, - { "Palau", 680, 552, 80, "PW", "en" }, - { "Palestine", 970, 425, 6, "PS", "ar" }, - { "Panama", 507, 714, 2, "PA", "es" }, - { "Papua New Guinea", 675, 537, 3, "PG", "ho" }, - { "Paraguay", 595, 744, 6, "PY", "es" }, - { "Peru", 51, 716, 6, "PE", "es" }, - { "Philippines", 63, 515, 2, "PH", "fil" }, - { "Poland", 48, 260, 3, "PL", "pl" }, - { "Portugal", 351, 268, 1, "PT", "pt" }, - { "Qatar", 974, 427, 2, "QA", "ar" }, - { "Quebec", 1418, 302, 720, "CA", "en" }, - { "Quebec", 1450, 302, 720, "CA", "en" }, - { "Quebec", 1514, 302, 720, "CA", "en" }, - { "Quebec", 1819, 302, 720, "CA", "en" }, - { "Reunion", 262, 647, 0, "RE", "fr" }, - { "Romania", 40, 226, 1, "RO", "ro" }, - { "Rwanda", 250, 635, 10, "RW", "rw" }, - { "Saint-Barthelemy", 590, 340, 1, "BL", "fr" }, - { "Saint Helena", 290, 658, 1, "SH", "en" }, - { "Saint Kitts and Nevis", 1869, 356, 50, "KN", "en" }, - { "Saint Lucia", 1758, 358, 50, "LC", "en" }, - { "Saint Martin (French side)", 590, 340, 1, "MF", "fr" }, - { "Saint Pierre and Miquelon", 508, 308, 2, "PM", "fr" }, - { "Saint Vincent and the Grenadines", 1670, 360, 70, "VC", "en" }, - { "Samoa", 685, 549, 1, "WS", "sm" }, - { "Sao Tome and Principe", 239, 626, 1, "ST", "pt" }, - { "Saskatchewan", 1306, 302, 720, "CA", "en" }, - { "Saudi Arabia", 966, 420, 4, "SA", "ar" }, - { "Senegal", 221, 608, 1, "SN", "wo" }, - { "Serbia", 381, 220, 1, "RS", "sr" }, - { "Seychelles", 248, 633, 10, "SC", "fr" }, - { "Sierra Leone", 232, 619, 4, "SL", "en" }, - { "Singapore", 65, 525, 1, "SG", "en" }, - { "Slovakia", 421, 231, 4, "SK", "sk" }, - { "Slovenia", 386, 293, 31, "SI", "sl" }, - { "Solomon Islands", 677, 540, 2, "SB", "en" }, - { "Somalia", 252, 637, 82, "SO", "so" }, - { "South Africa", 27, 655, 1, "ZA", "xh" }, - { "South Korea", 82, 450, 5, "KR", "ko" }, - { "South Sudan", 211, 659, 2, "SS", "en" }, - { "Spain", 34, 214, 1, "ES", "es" }, - { "Sri Lanka", 94, 413, 1, "LK", "si" }, - { "Sudan", 249, 634, 7, "SD", "ar" }, - { "Suriname", 597, 746, 3, "SR", "nl" }, - { "Swaziland", 268, 653, 10, "SZ", "ss" }, - { "Sweden", 46, 240, 7, "SE", "sv" }, - { "Switzerland", 41, 228, 3, "CH", "de" }, - { "Syria", 963, 417, 1, "SY", "ar" }, - { "Taiwan", 886, 466, 1, "TW", "cmn" }, - { "Tajikistan", 992, 436, 1, "TJ", "tg" }, - { "Tanzania", 255, 640, 4, "TZ", "sw" }, - { "Thailand", 66, 520, 0, "TH", "th" }, - { "Togo", 228, 615, 1, "TG", "fr" }, - { "Tokelau", 690, 690, 1, "TK", "tkl" }, - { "Tonga", 676, 539, 1, "TO", "to" }, - { "Trinidad and Tobago", 1868, 374, 12, "TT", "en" }, - { "Tunisia", 216, 605, 1, "TN", "ar" }, - { "Turkey", 90, 286, 2, "TR", "tr" }, - { "Turkmenistan", 993, 438, 1, "TM", "tk" }, - { "Turks and Caicos Islands", 1649, 376, 50, "TC", "en" }, - { "Tuvalu", 688, 553, 1, "TV", "tvl" }, - { "Uganda", 256, 641, 14, "UG", "sw" }, - { "Ukraine", 380, 255, 1, "UA", "uk" }, - { "United Arab Emirates", 971, 424, 2, "AE", "ar" }, - { "United Kingdom", 44, 234, 10, "GB", "en" }, - { "United States of America", 1, 310, 4, "US", "en" }, - { "Uruguay", 598, 748, 7, "UY", "es" }, - { "Uzbekistan", 998, 434, 7, "UZ", "uz" }, - { "Vanuatu", 678, 541, 5, "VU", "bi" }, - { "Venezuela", 58, 734, 4, "VE", "es" }, - { "Vietnam", 84, 452, 1, "VN", "vi" }, - { "U.S. Virgin Islands", 1340, 332, 4, "VI", "en" }, - { "Wallis and Futuna", 681, 543, 1, "WF", "fr" }, - { "West Bank", 970, 0, 1, "PS", "ar" }, - { "Yemen", 967, 421, 2, "YE", "ar" }, - { "Zambia", 260, 645, 2, "ZM", "en" }, - { "Zimbabwe", 263, 648, 2, "ZW", "en" } -}; - -PhoneNumber::PhoneNumber(const std::string &szNumber) -{ - int cc1 = atoi(szNumber.substr(0, 1).c_str()), cc2 = atoi(szNumber.substr(0, 2).c_str()), cc3 = atoi(szNumber.substr(0, 3).c_str()); - - for (int i = 0; i < _countof(countries); i++) { - CountryDescr &p = countries[i]; - if (p.countryCode != cc1 && p.countryCode != cc2 && p.countryCode != cc3) - continue; - - if (p.countryCode == 7) - if (i == 0 && (cc2 == '77' || cc2 == '76')) - continue; - - this->Country = p.name; - this->countryCode = p.countryCode; - this->Number = szNumber.substr(1 + (size_t)floor(log10(double(p.countryCode)))); - this->ISO3166 = p.ISO3166; - this->ISO639 = p.ISO639; - this->mcc = p.mcc; - this->mnc = p.mnc; - return; - } - - throw new WAException("Could not dissect phone number " + szNumber); -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.h b/protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.h deleted file mode 100644 index aa3dd16ef9..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * PhoneNumber.h - * - */ - -#ifndef PHONENUMBER_H_ -#define PHONENUMBER_H_ - -#include - -struct PhoneNumber -{ - PhoneNumber(const std::string &number); - - std::string Country; - std::string Number; - - const char *ISO3166, *ISO639; - int countryCode; - int mcc, mnc; -}; - -#endif /* PHONENUMBER_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp deleted file mode 100644 index 2e04563fda..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * ProtocolTreeNode.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "WAException.h" -#include "ProtocolTreeNode.h" - -static std::string nilstr; - -ProtocolTreeNode::ProtocolTreeNode(const string &_tag, vector* _data, vector *_children) : - tag(_tag) -{ - data = _data; - attributes = NULL; - children = _children; -} - -ProtocolTreeNode::ProtocolTreeNode(const string &_tag, ProtocolTreeNode *_child) : - tag(_tag) -{ - this->data = NULL; - this->attributes = NULL; - this->children = new std::vector(); - children->push_back(_child); -} - -ProtocolTreeNode::~ProtocolTreeNode() -{ - delete this->attributes; - - if (this->children != NULL) { - for (size_t i = 0; i < this->children->size(); i++) - if (this->children->at(i) != NULL) - delete this->children->at(i); - delete this->children; - } - - delete data; -} - - -string ProtocolTreeNode::toString() const -{ - string out; - out += "<" + this->tag; - if (this->attributes != NULL) { - map::iterator ii; - for (ii = attributes->begin(); ii != attributes->end(); ii++) - out += " " + ii->first + "=\"" + ii->second + "\""; - } - out += ">\n"; - out += getDataAsString(); - - if (this->children != NULL) { - vector::iterator ii; - for (ii = children->begin(); ii != children->end(); ii++) - out += (*ii)->toString(); - } - - out += "tag + ">\n"; - - return out; -} - -ProtocolTreeNode* ProtocolTreeNode::getChild(const string& id) -{ - if (this->children == NULL || this->children->size() == 0) - return NULL; - - for (std::size_t i = 0; i < this->children->size(); i++) - if (id.compare((*children)[i]->tag) == 0) - return (*children)[i]; - - return NULL; -} - -ProtocolTreeNode* ProtocolTreeNode::getChild(size_t id) -{ - if (this->children == NULL || this->children->size() == 0) - return NULL; - - if (children->size() > id) - return (*children)[id]; - - return NULL; -} - -const string& ProtocolTreeNode::getAttributeValue(const string& attribute) -{ - if (this->attributes == NULL) - return nilstr; - - map::iterator it = attributes->find(attribute); - if (it == attributes->end()) - return nilstr; - - return it->second; -} - -vector ProtocolTreeNode::getAllChildren() -{ - if (this->children == NULL) - return vector(); - - return *this->children; -} - -std::string ProtocolTreeNode::getDataAsString() const -{ - if (this->data == NULL) - return nilstr; - return std::string(this->data->begin(), this->data->end()); -} - -vector ProtocolTreeNode::getAllChildren(const string &tag) -{ - vector ret; - - if (this->children != NULL) - for (size_t i = 0; i < this->children->size(); i++) - if (tag.compare((*children)[i]->tag) == 0) - ret.push_back((*children)[i]); - - return ret; -} - -bool ProtocolTreeNode::tagEquals(ProtocolTreeNode *node, const string& tag) -{ - return (node != NULL && node->tag.compare(tag) == 0); -} - -void ProtocolTreeNode::require(ProtocolTreeNode *node, const string& tag) -{ - if (!tagEquals(node, tag)) - throw WAException("failed require. node:" + node->toString() + "tag: " + tag, WAException::CORRUPT_STREAM_EX, 0); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -ProtocolTreeNode& operator<<(ProtocolTreeNode &node, const XATTR &attr) -{ - if (node.attributes == NULL) - node.attributes = new map; - - (*node.attributes)[attr.name] = attr.value; - return node; -} - -ProtocolTreeNode* operator<<(ProtocolTreeNode *node, const XATTR &attr) -{ - if (node->attributes == NULL) - node->attributes = new map; - - (*node->attributes)[attr.name] = attr.value; - return node; -} - -ProtocolTreeNode& operator<<(ProtocolTreeNode &node, const XATTRI &attr) -{ - if (node.attributes == NULL) - node.attributes = new map; - - char szValue[100]; - _itoa_s(attr.value, szValue, 10); - (*node.attributes)[attr.name] = szValue; - return node; -} - -ProtocolTreeNode* operator<<(ProtocolTreeNode *node, const XATTRI &attr) -{ - if (node->attributes == NULL) - node->attributes = new map; - - char szValue[100]; - _itoa_s(attr.value, szValue, 10); - (*node->attributes)[attr.name] = szValue; - return node; -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h deleted file mode 100644 index 50e0f4033d..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -* ProtocolTreeNode.h -* -* Created on: 26/06/2012 -* Author: Antonio -*/ - -#if !defined(PROTOCOLNODE_H) -#define PROTOCOLNODE_H - -#include -#include -#include - -using namespace std; - -struct XATTR -{ - __forceinline XATTR(const char *_name, const char *_value) : - name(_name), value(_value) - {} - - __forceinline XATTR(const char *_name, const std::string &_value) : - name(_name), value(_value.c_str()) - {} - - __forceinline XATTR(const std::string &_name, const std::string &_value) : - name(_name.c_str()), value(_value.c_str()) - {} - - const char *name, *value; -}; - -struct XATTRI -{ - __forceinline XATTRI(const char *_name, int _value) : - name(_name), value(_value) - {} - - __forceinline XATTRI(const std::string &_name, int _value) : - name(_name.c_str()), value(_value) - {} - - const char *name; - int value; -}; - -class ProtocolTreeNode -{ - ProtocolTreeNode(const ProtocolTreeNode&); // to prevent copying - -public: - vector* data; - string tag; - map *attributes; - vector *children; - - ProtocolTreeNode(const string &tag, ProtocolTreeNode *child); - ProtocolTreeNode(const string &tag, vector *data = NULL, vector *children = NULL); - ~ProtocolTreeNode(); - - string toString() const; - ProtocolTreeNode* getChild(const string &id); - ProtocolTreeNode* getChild(size_t id); - const string& getAttributeValue(const string &attribute); - - vector getAllChildren(); - vector getAllChildren(const string &tag); - std::string getDataAsString() const; - - static bool tagEquals(ProtocolTreeNode *node, const string &tag); - static void require(ProtocolTreeNode *node, const string &tag); -}; - -ProtocolTreeNode& operator<<(ProtocolTreeNode&, const XATTR&); -ProtocolTreeNode* operator<<(ProtocolTreeNode*, const XATTR&); - -ProtocolTreeNode& operator<<(ProtocolTreeNode&, const XATTRI&); -ProtocolTreeNode* operator<<(ProtocolTreeNode*, const XATTRI&); - -#endif /* PROTOCOLNODE_H_ */ \ No newline at end of file diff --git a/protocols/WhatsApp/src/WhatsAPI++/README.md b/protocols/WhatsApp/src/WhatsAPI++/README.md deleted file mode 100644 index 69e374a6ef..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/README.md +++ /dev/null @@ -1,30 +0,0 @@ -This library can be used for creating WhatsApp-clients and is based on the MojoWhatsup-project written by Antonio Morales. The original source code has been modified by Uli Hecht. - -------------------------------------------------------------------------------------------------- -ORIGINAL "README.MD" BELOW -------------------------------------------------------------------------------------------------- - -MojoWhatsup -=========== - -MojoWhatsup is an IM application for Webos that allows you to chat with your Whatsapp friends - -MojoWhatsup has been developed as a Webos hybrid app, i.e. a javascript webos app (based in Mojo framework) -and a plugin (mojowhatsup_service_plugin) in C++. The plugin supports all Whatsapp communication API. - -Contact: Antonio Morales - -License: - - Copyright (c) 2012, Antonio Morales - - MojoWhatsup is free software: you can redistribute it and/or modify it under the terms - of the GNU General Public License as published by the Free Software Foundation, - either version 2 of the License, or (at your option) any later version. - - MojoWhatsup is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with MojoWhatsup. - If not, see http://www.gnu.org/licenses/. diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp deleted file mode 100644 index b760c58da4..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp +++ /dev/null @@ -1,1125 +0,0 @@ -/* - * WAConnection.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "ProtocolTreeNode.h" -#include "utilities.h" - -const char* dictionary[] = { - "", "", "", "account", "ack", "action", "active", "add", "after", "all", "allow", "apple", "auth", "author", "available", - "bad-protocol", "bad-request", "before", "body", "broadcast", "cancel", "category", "challenge", "chat", "clean", "code", - "composing", "config", "contacts", "count", "create", "creation", "debug", "default", "delete", "delivery", "delta", "deny", - "digest", "dirty", "duplicate", "elapsed", "enable", "encoding", "error", "event", "expiration", "expired", "fail", "failure", - "false", "favorites", "feature", "features", "feature-not-implemented", "field", "first", "free", "from", "g.us", "get", "google", - "group", "groups", "groups_v2", "http://etherx.jabber.org/streams", "http://jabber.org/protocol/chatstates", "ib", "id", "image", - "img", "index", "internal-server-error", "ip", "iq", "item-not-found", "item", "jabber:iq:last", "jabber:iq:privacy", "jabber:x:event", - "jid", "kind", "last", "leave", "list", "max", "mechanism", "media", "message_acks", "message", "method", "microsoft", "missing", - "modify", "mute", "name", "nokia", "none", "not-acceptable", "not-allowed", "not-authorized", "notification", "notify", "off", - "offline", "order", "owner", "owning", "p_o", "p_t", "paid", "participant", "participants", "participating", "paused", "picture", - "pin", "ping", "platform", "port", "presence", "preview", "probe", "prop", "props", "query", "raw", "read", "readreceipts", "reason", - "receipt", "relay", "remote-server-timeout", "remove", "request", "required", "resource-constraint", "resource", "response", "result", - "retry", "rim", "s_o", "s_t", "s.us", "s.whatsapp.net", "seconds", "server-error", "server", "service-unavailable", "set", "show", "silent", - "stat", "status", "stream:error", "stream:features", "subject", "subscribe", "success", "sync", "t", "text", "timeout", "timestamp", "to", - "true", "type", "unavailable", "unsubscribe", "uri", "url", "urn:ietf:params:xml:ns:xmpp-sasl", "urn:ietf:params:xml:ns:xmpp-stanzas", - "urn:ietf:params:xml:ns:xmpp-streams", "urn:xmpp:ping", "urn:xmpp:whatsapp:account", "urn:xmpp:whatsapp:dirty", "urn:xmpp:whatsapp:mms", - "urn:xmpp:whatsapp:push", "urn:xmpp:whatsapp", "user", "user-not-found", "value", "version", "w:g", "w:p:r", "w:p", "w:profile:picture", - "w", "wait", "WAUTH-2", "xmlns:stream", "xmlns", "1", "chatstate", "crypto", "phash", "enc", "class", "off_cnt", "w:g2", "promote", - "demote", "creator", "Bell.caf", "Boing.caf", "Glass.caf", "Harp.caf", "TimePassing.caf", "Tri-tone.caf", "Xylophone.caf", "background", - "backoff", "chunked", "context", "full", "in", "interactive", "out", "registration", "sid", "urn:xmpp:whatsapp:sync", "flt", "s16", "u8", - "adpcm", "amrnb", "amrwb", "mp3", "pcm", "qcelp", "wma", "h263", "h264", "jpeg" -}; - -const char* extended_dict[] = { - "mpeg4", "wmv", "audio/3gpp", "audio/aac", "audio/amr", "audio/mp4", "audio/mpeg", "audio/ogg", "audio/qcelp", "audio/wav", - "audio/webm", "audio/x-caf", "audio/x-ms-wma", "image/gif", "image/jpeg", "image/png", "video/3gpp", "video/avi", "video/mp4", - "video/mpeg", "video/quicktime", "video/x-flv", "video/x-ms-asf", "302", "400", "401", "402", "403", "404", "405", "406", "407", - "409", "410", "500", "501", "503", "504", "abitrate", "acodec", "app_uptime", "asampfmt", "asampfreq", "audio", "clear", "conflict", - "conn_no_nna", "cost", "currency", "duration", "extend", "file", "fps", "g_notify", "g_sound", "gcm", "gone", "google_play", "hash", - "height", "invalid", "jid-malformed", "latitude", "lc", "lg", "live", "location", "log", "longitude", "max_groups", "max_participants", - "max_subject", "mimetype", "mode", "napi_version", "normalize", "orighash", "origin", "passive", "password", "played", - "policy-violation", "pop_mean_time", "pop_plus_minus", "price", "pricing", "redeem", "Replaced by new connection", "resume", - "signature", "size", "sound", "source", "system-shutdown", "username", "vbitrate", "vcard", "vcodec", "video", "width", - "xml-not-well-formed", "checkmarks", "image_max_edge", "image_max_kbytes", "image_quality", "ka", "ka_grow", "ka_shrink", "newmedia", - "library", "caption", "forward", "c0", "c1", "c2", "c3", "clock_skew", "cts", "k0", "k1", "login_rtt", "m_id", "nna_msg_rtt", - "nna_no_off_count", "nna_offline_ratio", "nna_push_rtt", "no_nna_con_count", "off_msg_rtt", "on_msg_rtt", "stat_name", "sts", - "suspect_conn", "lists", "self", "qr", "web", "w:b", "recipient", "w:stats", "forbidden", "aurora.m4r", "bamboo.m4r", "chord.m4r", - "circles.m4r", "complete.m4r", "hello.m4r", "input.m4r", "keys.m4r", "note.m4r", "popcorn.m4r", "pulse.m4r", "synth.m4r", "filehash", - "max_list_recipients", "en-AU", "en-GB", "es-MX", "pt-PT", "zh-Hans", "zh-Hant", "relayelection", "relaylatency", "interruption", - "Apex.m4r", "Beacon.m4r", "Bulletin.m4r", "By The Seaside.m4r", "Chimes.m4r", "Circuit.m4r", "Constellation.m4r", "Cosmic.m4r", - "Crystals.m4r", "Hillside.m4r", "Illuminate.m4r", "Night Owl.m4r", "Opening.m4r", "Playtime.m4r", "Presto.m4r", "Radar.m4r", - "Radiate.m4r", "Ripples.m4r", "Sencha.m4r", "Signal.m4r", "Silk.m4r", "Slow Rise.m4r", "Stargaze.m4r", "Summit.m4r", "Twinkle.m4r", - "Uplift.m4r", "Waves.m4r", "voip", "eligible", "upgrade", "planned", "current", "future", "disable", "expire", "start", "stop", - "accuracy", "speed", "bearing", "recording", "encrypt", "key", "identity", "w:gp2", "admin", "locked", "unlocked", "new", "battery", - "archive", "adm", "plaintext_size", "compressed_size", "delivered", "msg", "pkmsg", "everyone", "v", "transport", "call-id" -}; - -static map tokenMap1, tokenMap2; - -void WAConnection::globalInit() -{ - for (int i = 0; i < _countof(dictionary); i++) - if (*dictionary[i] != 0) - tokenMap1[dictionary[i]] = i; - - for (int i = 0; i < _countof(extended_dict); i++) - tokenMap2[extended_dict[i]] = i; -} - -int WAConnection::tokenLookup(const std::string &str) -{ - std::map::iterator it = tokenMap1.find(str); - if (it != tokenMap1.end()) - return it->second; - - it = tokenMap2.find(str); - if (it != tokenMap2.end()) - return it->second + 0x100; - - return -1; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -void WAConnection::logData(const char *format, ...) -{ - va_list args; - va_start(args, format); - char tmp[4000]; - vsprintf_s(tmp, format, args); - rawConn->log(">> ", tmp); - va_end(args); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -WAConnection::WAConnection(const std::string &user, const std::string &resource, IMutex *mutex, IMutex *write_mutex, ISocketConnection *conn, WAListener *pEventHandler, WAGroupListener *pGroupEventHandler) : - in(this, conn), - out(this, conn, write_mutex) -{ - m_pMutex = mutex; - m_pEventHandler = pEventHandler; - m_pGroupEventHandler = pGroupEventHandler; - - rawConn = conn; - - this->retry = true; - - this->user = user; - this->resource = resource; - this->domain = "s.whatsapp.net"; - this->jid = user + "@" + domain; - - this->supports_receipt_acks = false; - this->iqid = 0; - this->lastTreeRead = 0; - this->expire_date = 0L; - this->account_kind = -1; -} - -WAConnection::~WAConnection() -{ - m_pMutex->lock(); - for (auto it = pending_server_requests.begin(); it != pending_server_requests.end(); ++it) - delete it->second; - m_pMutex->unlock(); -} - -std::string WAConnection::gidToGjid(const std::string &gid) -{ - return gid + "@g.us"; -} - -std::string WAConnection::makeId(const std::string &prefix) -{ - return prefix + Utilities::itoa(++this->iqid, 16); -} - -ProtocolTreeNode* WAConnection::getReceiptAck(const std::string &to, const std::string &id, const std::string &receiptType) throw(WAException) -{ - ProtocolTreeNode *ackNode = new ProtocolTreeNode("ack") - << XATTR("xmlns", "urn:xmpp:receipts") << XATTR("type", receiptType); - - return new ProtocolTreeNode("message", ackNode) << XATTR("to", to) << XATTR("type", "chat") << XATTR("id", id); -} - -bool WAConnection::supportsReceiptAcks() -{ - return supports_receipt_acks; -} - -std::string WAConnection::removeResourceFromJid(const std::string &jid) -{ - size_t slashidx = jid.find('/'); - if (slashidx == std::string::npos) - return jid; - - return jid.substr(0, slashidx + 1); -} - -void WAConnection::setLogin(WALogin* login) -{ - if (login->m_tExpireDate != 0L) - this->expire_date = login->m_tExpireDate; - - if (login->m_iAccountKind != -1) - this->account_kind = login->m_iAccountKind; -} - -bool WAConnection::read() throw(WAException) -{ - ProtocolTreeNode *node; - try { - node = in.nextTree(); - this->lastTreeRead = time(NULL); - } - catch (exception& ex) { - throw WAException(ex.what(), WAException::CORRUPT_STREAM_EX, 0); - } - - if (node == NULL) - return false; - - string tmp = node->toString(); - rawConn->log("XML received\n", tmp.c_str()); - - if (ProtocolTreeNode::tagEquals(node, "iq")) - parseIq(node); - else if (ProtocolTreeNode::tagEquals(node, "presence")) - parsePresense(node); - else if (ProtocolTreeNode::tagEquals(node, "message")) - parseMessage(node); - else if (ProtocolTreeNode::tagEquals(node, "notification")) - parseNotification(node); - else if (ProtocolTreeNode::tagEquals(node, "ack")) - parseAck(node); - else if (ProtocolTreeNode::tagEquals(node, "receipt")) - parseReceipt(node); - else if (ProtocolTreeNode::tagEquals(node, "chatstate")) - parseChatStates(node); - else { - rawConn->log("Warning: Node parsing not handled:\n", tmp.c_str()); - } - - delete node; - return true; -} - -void WAConnection::readGroupList(ProtocolTreeNode *node, std::vector& groups) throw (WAException) -{ - std::vector nodes(node->getAllChildren("group")); - for (size_t i = 0; i < nodes.size(); i++) { - ProtocolTreeNode *groupNode = nodes[i]; - const string &gid = groupNode->getAttributeValue("id"); - string gjid = gidToGjid(gid); - const string &owner = groupNode->getAttributeValue("owner"); - const string &subject = groupNode->getAttributeValue("subject"); - const string &subject_t = groupNode->getAttributeValue("s_t"); - const string &subject_owner = groupNode->getAttributeValue("s_o"); - const string &creation = groupNode->getAttributeValue("creation"); - if (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupInfo(gjid, owner, subject, subject_owner, atoi(subject_t.c_str()), atoi(creation.c_str())); - groups.push_back(gjid); - } -} - -std::map WAConnection::parseCategories(ProtocolTreeNode *dirtyNode) throw (WAException) -{ - std::map categories; - if (dirtyNode->children != NULL) { - for (size_t i = 0; i < dirtyNode->children->size(); i++) { - ProtocolTreeNode *childNode = (*dirtyNode->children)[i]; - if (ProtocolTreeNode::tagEquals(childNode, "category")) { - const string &categoryName = childNode->getAttributeValue("name"); - const string ×tamp = childNode->getAttributeValue("timestamp"); - categories[categoryName] = timestamp; - } - } - } - - return categories; -} - -void WAConnection::parseAck(ProtocolTreeNode *node) throw(WAException) -{ - const string &from = node->getAttributeValue("from"); - const string &cls = node->getAttributeValue("class"); - const string &id = node->getAttributeValue("id"); - // const string &ts = node->getAttributeValue("t"); - - if (cls == "message" && m_pEventHandler != NULL) { - FMessage msg(from, true, id); - msg.status = FMessage::STATUS_RECEIVED_BY_SERVER; - m_pEventHandler->onMessageStatusUpdate(msg); - } -} - -void WAConnection::parseChatStates(ProtocolTreeNode *node) throw (WAException) -{ - const string &from = node->getAttributeValue("from"); - - std::vector messageChildren(node->getAllChildren()); - for (size_t i = 0; i < messageChildren.size(); i++) { - ProtocolTreeNode *childNode = messageChildren[i]; - if (ProtocolTreeNode::tagEquals(childNode, "composing")) { - if (m_pEventHandler != NULL) - m_pEventHandler->onIsTyping(from, true); - } - else if (ProtocolTreeNode::tagEquals(childNode, "paused")) { - if (m_pEventHandler != NULL) - m_pEventHandler->onIsTyping(from, false); - } - } -} - -void WAConnection::parseIq(ProtocolTreeNode *node) throw(WAException) -{ - const string &type = node->getAttributeValue("type"); - if (type.empty()) - throw WAException("missing 'type' attribute in iq stanza", WAException::CORRUPT_STREAM_EX, 0); - - const string &id = node->getAttributeValue("id"); - const string &from = node->getAttributeValue("from"); - - if (type == "result") { - if (id.empty()) - throw WAException("missing 'id' attribute in iq stanza", WAException::CORRUPT_STREAM_EX, 0); - - m_pMutex->lock(); - std::map::iterator it = this->pending_server_requests.find(id); - if (it != this->pending_server_requests.end()) { - it->second->parse(node, from); - delete it->second; - this->pending_server_requests.erase(id); - m_pMutex->unlock(); - return; - } - - m_pMutex->unlock(); - if (id.compare(0, this->user.size(), this->user) == 0) { - ProtocolTreeNode *accountNode = node->getChild(0); - ProtocolTreeNode::require(accountNode, "account"); - const string &kind = accountNode->getAttributeValue("kind"); - if (kind == "paid") - this->account_kind = 1; - else if (kind == "free") - this->account_kind = 0; - else - this->account_kind = -1; - - const string &expiration = accountNode->getAttributeValue("expiration"); - if (expiration.empty()) - throw WAException("no expiration"); - - this->expire_date = atol(expiration.c_str()); - if (this->expire_date == 0) - throw WAException("invalid expire date: " + expiration); - if (m_pEventHandler != NULL) - m_pEventHandler->onAccountChange(this->account_kind, this->expire_date); - } - else { - ProtocolTreeNode *childNode = node->getChild(0); - if (ProtocolTreeNode::tagEquals(childNode, "leave")) { - std::vector nodes(childNode->getAllChildren("group")); - for (size_t i = 0; i < nodes.size(); i++) { - ProtocolTreeNode *groupNode = nodes[i]; - const string &gjid = groupNode->getAttributeValue("id"); - if (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onLeaveGroup(gjid); - } - } - } - } - else if (type == "error") { - m_pMutex->lock(); - std::map::iterator it = this->pending_server_requests.find(id); - if (it != this->pending_server_requests.end()) { - it->second->error(node); - delete it->second; - this->pending_server_requests.erase(id); - } - m_pMutex->unlock(); - } - else if (type == "get") { - ProtocolTreeNode *childNode = node->getChild(0); - if (ProtocolTreeNode::tagEquals(childNode, "ping")) { - if (m_pEventHandler != NULL) - m_pEventHandler->onPing(id); - } - else if ((ProtocolTreeNode::tagEquals(childNode, "query") && !from.empty()) ? false : (ProtocolTreeNode::tagEquals(childNode, "relay")) && !from.empty()) { - const string &pin = childNode->getAttributeValue("pin"); - if (!pin.empty() && m_pEventHandler != NULL) { - int timeoutSeconds = atoi(childNode->getAttributeValue("timeout").c_str()); - m_pEventHandler->onRelayRequest(pin, timeoutSeconds, id); - } - } - } - else if (type == "set") { - ProtocolTreeNode *childNode = node->getChild(0); - if (ProtocolTreeNode::tagEquals(childNode, "query")) { - const string &xmlns = childNode->getAttributeValue("xmlns"); - if (xmlns == "jabber:iq:roster") { - std::vector itemNodes(childNode->getAllChildren("item")); - for (size_t i = 0; i < itemNodes.size(); i++) { - // ProtocolTreeNode *itemNode = itemNodes[i]; - // const string &jid = itemNode->getAttributeValue("jid"); - // const string &subscription = itemNode->getAttributeValue("subscription"); - // ask = itemNode->getAttributeValue("ask"); - } - } - } - } - else throw WAException("unknown iq type attribute: " + type, WAException::CORRUPT_STREAM_EX, 0); -} - -void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAException) -{ - const string &id = messageNode->getAttributeValue("id"); - const string &attribute_t = messageNode->getAttributeValue("t"); - const string &from = messageNode->getAttributeValue("from"); - - const string &typeAttribute = messageNode->getAttributeValue("type"); - if (typeAttribute.empty()) - return; - - const string &participant = messageNode->getAttributeValue("participant"); - if (typeAttribute == "error") { - int errorCode = 0; - std::vector errorNodes(messageNode->getAllChildren("error")); - for (size_t i = 0; i < errorNodes.size(); i++) { - ProtocolTreeNode *errorNode = errorNodes[i]; - errorCode = atoi(errorNode->getAttributeValue("code").c_str()); - } - - FMessage message(from, true, id); - message.status = FMessage::STATUS_SERVER_BOUNCE; - - if (m_pEventHandler != NULL) - m_pEventHandler->onMessageError(message, errorCode); - return; - } - - if (from.empty() || id.empty()) - return; - FMessage fmessage(from, false, id); - - if (typeAttribute == "text") { - ProtocolTreeNode *body = messageNode->getChild("body"); - if (body == NULL || body->data == NULL || body->data->empty()) - return; - - fmessage.wants_receipt = false; - fmessage.timestamp = atoi(attribute_t.c_str()); - fmessage.remote_resource = participant; - fmessage.notifyname = messageNode->getAttributeValue("notify"); - fmessage.data = body->getDataAsString(); - fmessage.status = FMessage::STATUS_UNSENT; - if (fmessage.timestamp == 0) { - fmessage.timestamp = time(NULL); - fmessage.offline = false; - } - } - else if (typeAttribute == "media") { - ProtocolTreeNode *media = messageNode->getChild("media"); - if (media == NULL) - return; - - fmessage.wants_receipt = false; - fmessage.timestamp = atoi(attribute_t.c_str()); - fmessage.notifyname = messageNode->getAttributeValue("notify"); - fmessage.remote_resource = messageNode->getAttributeValue("participant"); - fmessage.media_wa_type = FMessage::getMessage_WA_Type(media->getAttributeValue("type")); - fmessage.media_url = media->getAttributeValue("url"); - fmessage.media_name = media->getAttributeValue("file"); - fmessage.media_size = Utilities::parseLongLong(media->getAttributeValue("size")); - fmessage.media_duration_seconds = atoi(media->getAttributeValue("seconds").c_str()); - - if (fmessage.media_wa_type == FMessage::WA_TYPE_LOCATION) { - const string &name = media->getAttributeValue("name"); - const string &latitudeString = media->getAttributeValue("latitude"); - const string &longitudeString = media->getAttributeValue("longitude"); - if (latitudeString.empty() || longitudeString.empty()) - throw WAException("location message missing lat or long attribute", WAException::CORRUPT_STREAM_EX, 0); - - fmessage.latitude = atof(latitudeString.c_str()); - fmessage.longitude = atof(longitudeString.c_str()); - if (!name.empty()) - fmessage.data = name; - } - else if (fmessage.media_wa_type == FMessage::WA_TYPE_CONTACT) { - ProtocolTreeNode *contactChildNode = media->getChild(0); - if (contactChildNode != NULL) { - fmessage.media_name = contactChildNode->getAttributeValue("name"); - fmessage.data = contactChildNode->getDataAsString(); - size_t off = fmessage.data.find("TEL;"); - if (off != string::npos) { - if ((off = fmessage.data.find(":", off)) != string::npos) { - std::string number; - for (off++;; off++) { - char c = fmessage.data[off]; - if (isdigit(c)) - number += c; - else if (c == '+' || c == ' ') - continue; - else - break; - } - if (!number.empty()) - fmessage.media_url = number; - } - } - } - } - else { - const string &encoding = media->getAttributeValue("encoding"); - if (encoding.empty() || encoding == "text") - fmessage.data = media->getDataAsString(); - else - fmessage.data = media->getAttributeValue("caption"); - } - } - else return; - - if (fmessage.remote_resource.empty()) { - if (m_pEventHandler != NULL) - m_pEventHandler->onMessageForMe(fmessage); - } - else if (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupMessage(fmessage); -} - -void WAConnection::parseNotification(ProtocolTreeNode *node) throw(WAException) -{ - const string &id = node->getAttributeValue("id"); - const string &from = node->getAttributeValue("from"); - const string &type = node->getAttributeValue("type"); - if (type.empty() || from.empty() || m_pEventHandler == NULL) - return; - - const string &participant = node->getAttributeValue("participant"); - int ts = atoi(node->getAttributeValue("t").c_str()); - - if (type == "contacts") { - std::vector children(node->getAllChildren()); - for (size_t i = 0; i < children.size(); i++) { - ProtocolTreeNode *child = children[i]; - - const string &jid = node->getAttributeValue("jid"); - if (jid.empty()) continue; - - bool bAdded; - if (ProtocolTreeNode::tagEquals(child, "add")) - bAdded = true; - else if (ProtocolTreeNode::tagEquals(child, "delete")) - bAdded = false; - else - continue; - - m_pEventHandler->onContactChanged(jid, bAdded); - } - } - else if (type == "picture") { - std::vector children2(node->getAllChildren()); - for (unsigned j = 0; j < children2.size(); j++) { - ProtocolTreeNode *child2 = children2[j]; - if (ProtocolTreeNode::tagEquals(child2, "set")) { - const string &id = child2->getAttributeValue("id"); - const string &jid = child2->getAttributeValue("jid"); - if (!id.empty()) - m_pEventHandler->onPictureChanged(jid, id, true); - } - else if (ProtocolTreeNode::tagEquals(child2, "delete")) { - const string &jid = child2->getAttributeValue("jid"); - m_pEventHandler->onPictureChanged(jid, id, false); - } - } - } - // group chats - else if (type == "participant") { - ProtocolTreeNode *subNode = node->getChild("add"); - if (subNode != NULL) { - const string &jid = subNode->getAttributeValue("jid"); - if (m_pGroupEventHandler) - m_pGroupEventHandler->onGroupAddUser(from, jid, ts); - } - else if ((subNode = node->getChild("remove")) != NULL) { - const string &jid = subNode->getAttributeValue("jid"); - if (m_pGroupEventHandler) - m_pGroupEventHandler->onGroupRemoveUser(from, jid, ts); - } - else return; - - } - else if (type == "subject") { - ProtocolTreeNode *bodyNode = node->getChild("body"); - if (bodyNode != NULL && m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupNewSubject(from, participant, bodyNode->getDataAsString(), ts); - } - else { - rawConn->log("Warning: Unknown Notification received:\n", node->toString().c_str()); - } - - sendAck(node, "notification"); -} - -void WAConnection::parsePresense(ProtocolTreeNode *node) throw(WAException) -{ - const string &xmlns = node->getAttributeValue("xmlns"); - const string &from = node->getAttributeValue("from"); - if (from.empty()) - return; - - int ts = atoi(node->getAttributeValue("t").c_str()); - if (xmlns == "w" && !from.empty()) { - const string &add = node->getAttributeValue("add"); - const string &remove = node->getAttributeValue("remove"); - const string &status = node->getAttributeValue("status"); - if (!add.empty()) { - if (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupAddUser(from, add, ts); - } - else if (!remove.empty()) { - if (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupRemoveUser(from, remove, ts); - } - else if (status == "dirty") { - std::map categories = parseCategories(node); - if (m_pEventHandler != NULL) - m_pEventHandler->onDirty(categories); - } - return; - } - - if (m_pEventHandler != NULL) { - const string &type = node->getAttributeValue("type"); - if (type == "unavailable") { - const string &lastSeen = node->getAttributeValue("last"); - m_pEventHandler->onAvailable(from, false, (lastSeen == "deny") ? 0 : stoul(lastSeen)); - } - else if (type == "available" || type == "") - m_pEventHandler->onAvailable(from, true); - } -} - -void WAConnection::parseReceipt(ProtocolTreeNode *node) throw(WAException) -{ - const string &from = node->getAttributeValue("from"); - const string &id = node->getAttributeValue("id"); - - if (m_pEventHandler != NULL) { - FMessage msg(from, false, id); - msg.status = FMessage::STATUS_RECEIVED_BY_TARGET; - m_pEventHandler->onMessageStatusUpdate(msg); - } - - sendAck(node,"receipt"); -} - -std::vector* WAConnection::processGroupSettings(const std::vector& groups) -{ - std::vector* result = new std::vector(groups.size()); - if (!groups.empty()) { - time_t now = time(NULL); - for (size_t i = 0; i < groups.size(); i++) { - (*result)[i] = new ProtocolTreeNode("item") - << XATTR("jid", groups[i].jid) << XATTR("notify", (groups[i].enabled ? "1" : "0")) - << XATTRI("mute", (groups[i].muteExpiry > now) ? groups[i].muteExpiry - now : 0); - } - } - - return result; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Send* functions - -void WAConnection::sendActive() throw(WAException) -{ - ProtocolTreeNode n("presence"); - out.write(n << XATTR("type", "active")); -} - -void WAConnection::sendAvailableForChat() throw(WAException) -{ - ProtocolTreeNode n("presence"); - out.write(n << XATTR("name", this->nick)); -} - -void WAConnection::sendClientConfig(const std::string &sound, const std::string &pushID, bool preview, const std::string &platform) throw(WAException) -{ - m_pMutex->lock(); - std::string id = makeId("config_"); - this->pending_server_requests[id] = new IqSendClientConfigHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("config") - << XATTR("xmlns", "urn:xmpp:whatsapp:push") << XATTR("sound", sound) << XATTR("id", pushID) << XATTR("preview", preview ? "1" : "0") << XATTR("platform", platform)); - out.write(iq << XATTR("id", id) << XATTR("type", "set") << XATTR("to", this->domain)); -} - -void WAConnection::sendClientConfig(const std::string &pushID, bool preview, const std::string &platform, bool defaultSettings, bool groupSettings, const std::vector& groups) throw(WAException) -{ - ProtocolTreeNode *configNode = new ProtocolTreeNode("config", NULL, this->processGroupSettings(groups)) - << XATTR("xmlns", "urn:xmpp:whatsapp:push") << XATTR("id", pushID) << XATTR("lg", "en") << XATTR("lc", "US") << XATTR("clear", "0") - << XATTR("preview", preview ? "1" : "0") << XATTR("platform", platform) - << XATTR("default", defaultSettings ? "1" : "0") << XATTR("groups", groupSettings ? "1" : "0"); - - std::string id = makeId("config_"); - ProtocolTreeNode iq("iq", configNode); - out.write(iq << XATTR("id", id) << XATTR("type", "set") << XATTR("to", this->domain)); -} - -void WAConnection::sendClose() throw(WAException) -{ - ProtocolTreeNode n("presence"); - out.write(n << XATTR("type", "unavailable")); - out.streamEnd(); -} - -void WAConnection::sendComposing(const std::string &to) throw(WAException) -{ - ProtocolTreeNode n("chatstate", new ProtocolTreeNode("composing")); - out.write(n << XATTR("to", to)); -} - -void WAConnection::sendDeleteAccount() throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("del_acct_"); - this->pending_server_requests[id] = new IqResultSendDeleteAccount(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("remove") << XATTR("xmlns", "urn:xmpp:whatsapp:account")); - out.write(iq << XATTR("id", id) << XATTR("type", "get") << XATTR("to", "s.whatsapp.net")); -} - -void WAConnection::sendGetGroups() throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("iq_"); - this->pending_server_requests[id] = new IqResultGetGroupsHandler(this, "participating"); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("list") << XATTR("type", "participating")); - out.write(iq << XATTR("xmlns", "w:g") << XATTR("id", id) << XATTR("type", "get") << XATTR("to", "g.us")); -} - -void WAConnection::sendGetPicture(const char *jid, const char *type) throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("iq_"); - this->pending_server_requests[id] = new IqResultGetPhotoHandler(this, jid); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("picture") << XATTR("type", type)); - out.write(iq << XATTR("id", id) << XATTR("to", jid) << XATTR("xmlns", "w:profile:picture") << XATTR("type", "get")); -} - -void WAConnection::sendGetPrivacyList() throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("privacylist_"); - this->pending_server_requests[id] = new IqResultPrivayListHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("query", - new ProtocolTreeNode("list") << XATTR("name", "default")) << XATTR("xmlns", "jabber:iq:privacy")); - out.write(iq << XATTR("id", id) << XATTR("type", "get")); -} - -void WAConnection::sendGetServerProperties() throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("get_server_properties_"); - this->pending_server_requests[id] = new IqResultServerPropertiesHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("list") << XATTR("type", "props")); - out.write(iq << XATTR("xmlns", "w:g2") << XATTR("id", id) << XATTR("type", "get") << XATTR("to", "g.us")); -} - -void WAConnection::sendInactive() throw(WAException) -{ - ProtocolTreeNode n("presence"); - out.write(n << XATTR("type", "inactive")); -} - -void WAConnection::sendAck(ProtocolTreeNode *node, const char *classType) -{ - const string &from = node->getAttributeValue("from"); - const string &to = node->getAttributeValue("to"); - const string &participant = node->getAttributeValue("participant"); - const string &id = node->getAttributeValue("id"); - const string &type = node->getAttributeValue("type"); - - ProtocolTreeNode sendNode("ack"); - sendNode << XATTR("to", from) << XATTR("id", id) << XATTR("class", classType); - if (!to.empty()) - sendNode << XATTR("from", to); - if (!participant.empty()) - sendNode << XATTR("participant", participant); - if (!type.empty()) - sendNode << XATTR("type", type); - - out.write(sendNode); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -ProtocolTreeNode* WAConnection::getMessageNode(FMessage* message, ProtocolTreeNode *child) -{ - std::vector* messageChildren = new std::vector(); - messageChildren->push_back(new ProtocolTreeNode("x", new ProtocolTreeNode("server")) << XATTR("xmlns", "jabber:x:event")); - messageChildren->push_back(child); - - return new ProtocolTreeNode("message", NULL, messageChildren) << - XATTR("to", message->key.remote_jid) << XATTR("type", "text") << XATTR("id", message->key.id) << XATTRI("t", message->timestamp); -} - -void WAConnection::sendMessage(FMessage* message) throw(WAException) -{ - if (message->media_wa_type != 0) - sendMessageWithMedia(message); - else - sendMessageWithBody(message); -} - -void WAConnection::sendMessageWithMedia(FMessage* message) throw (WAException) -{ - logData("Send message with media %s %d", message->media_name.c_str(), message->media_size); - logData("media-url:%s", message->media_url.c_str()); - if (message->media_wa_type == FMessage::WA_TYPE_SYSTEM) - throw new WAException("Cannot send system message over the network"); - - // request node for image, audio or video upload - if (message->media_wa_type == FMessage::WA_TYPE_IMAGE || message->media_wa_type == FMessage::WA_TYPE_AUDIO || message->media_wa_type == FMessage::WA_TYPE_VIDEO) { - m_pMutex->lock(); - std::string id = makeId("iq_"); - this->pending_server_requests[id] = new MediaUploadResponseHandler(this, *message); - m_pMutex->unlock(); - - ProtocolTreeNode *mediaNode = new ProtocolTreeNode("media"); - mediaNode << XATTR("hash", message->media_name) << XATTR("type", FMessage::getMessage_WA_Type_StrValue(message->media_wa_type)) << XATTR("size", std::to_string(message->media_size)); - - ProtocolTreeNode *n = new ProtocolTreeNode("iq", mediaNode); - n << XATTR("id", id) << XATTR("to", this->domain) << XATTR("type", "set") << XATTR("xmlns", "w:m"); - out.write(*n); - delete n; - return; - } - - ProtocolTreeNode *mediaNode; - if (message->media_wa_type == FMessage::WA_TYPE_CONTACT && !message->media_name.empty()) { - ProtocolTreeNode *vcardNode = new ProtocolTreeNode("vcard", new std::vector(message->data.begin(), message->data.end())) - << XATTR("name", message->media_name); - mediaNode = new ProtocolTreeNode("media", vcardNode); - } - else { - mediaNode = new ProtocolTreeNode("media", new std::vector(message->data.begin(), message->data.end()), NULL) - << XATTR("encoding", "text"); - } - - mediaNode << XATTR("xmlns", "urn:xmpp:whatsapp:mms") << XATTR("type", FMessage::getMessage_WA_Type_StrValue(message->media_wa_type)); - - if (message->media_wa_type == FMessage::WA_TYPE_LOCATION) - mediaNode << XATTR("latitude", Utilities::doubleToStr(message->latitude)) << XATTR("longitude", Utilities::doubleToStr(message->longitude)); - else { - mediaNode << XATTR("file", message->media_name) << XATTRI("size", message->media_size) << XATTR("url", message->media_url); - if (message->media_wa_type == FMessage::WA_TYPE_CONTACT || message->media_name.empty() || message->media_url.empty() || message->media_size <= 0) - mediaNode << XATTRI("seconds", message->media_duration_seconds); - } - - ProtocolTreeNode *n = WAConnection::getMessageNode(message, mediaNode); - out.write(*n); - delete n; - -} - -// TODO remove this code from WA purple -static std::string query_field(std::string work, std::string lo, bool integer = false) -{ - size_t p = work.find("\"" + lo + "\""); - if (p == std::string::npos) - return ""; - - work = work.substr(p + ("\"" + lo + "\"").size()); - - p = work.find("\""); - if (integer) - p = work.find(":"); - if (p == std::string::npos) - return ""; - - work = work.substr(p + 1); - - p = 0; - while (p < work.size()) { - if (work[p] == '"' && (p == 0 || work[p - 1] != '\\')) - break; - p++; - } - if (integer) { - p = 0; - while (p < work.size() && work[p] >= '0' && work[p] <= '9') - p++; - } - if (p == std::string::npos) - return ""; - - work = work.substr(0, p); - - return work; -} - -void WAConnection::processUploadResponse(ProtocolTreeNode * node, FMessage * message) -{ - ProtocolTreeNode* duplicate = node->getChild("duplicate"); - - // setup vars for media message - string fileType; - string caption, url, fileName, fileSize, filePath, fileHash; - caption = message->data; - - // parse node - if (duplicate != NULL) { - url = duplicate->getAttributeValue("url"); - fileSize = duplicate->getAttributeValue("size"); - fileHash = duplicate->getAttributeValue("filehash"); - fileType = duplicate->getAttributeValue("type"); - string tempfileName = duplicate->getAttributeValue("url"); - size_t index = tempfileName.find_last_of('/')+1; - fileName = tempfileName.substr(index); - } - else { - ProtocolTreeNode *media = node->getChild("media"); - if (media == NULL) - return; - - string url = media->getAttributeValue("url"); - if(url.empty()) - return; - - string json = MediaUploader::pushfile(url,message, this->user); - if (json.empty()) - return; - - //TODO why does the JSONNode not work? -> Throws some exception when trying to access elements after parsing. - - /*JSONNode resp = JSONNode::parse(json.c_str()); - fileName = resp["name"].as_string(); - url = resp["url"].as_string(); - fileSize = resp["size"].as_string(); - fileHash = resp["filehash"].as_string(); - fileType = resp["type"].as_string(); - */ - - // TODO remove this code from WA purple - size_t offset = json.find("{"); - if (offset == std::string::npos) - return; - json = json.substr(offset + 1); - - /* Look for closure */ - size_t cl = json.find("{"); - if (cl == std::string::npos) - cl = json.size(); - std::string work = json.substr(0, cl); - - fileName = query_field(work, "name"); - url = query_field(work, "url"); - fileSize = query_field(work, "size"); - fileHash = query_field(work, "filehash"); - fileType = query_field(work, "type"); - - } - - // TODO show caption and(?) link to media file in message window and history - ProtocolTreeNode *mediaNode = new ProtocolTreeNode("media"); - mediaNode << XATTR("type", fileType) - << XATTR("url", url) << XATTR("encoding", "raw") << XATTR("file", fileName) - << XATTR("size", fileSize)<< XATTR("caption", caption); - - ProtocolTreeNode * messageNode = new ProtocolTreeNode("message", mediaNode); - messageNode << XATTR("to", message->key.remote_jid) << XATTR("type", "media") - << XATTR("id", message->key.id) << XATTRI("t", (int)time(0)); - out.write(*messageNode); - delete messageNode; -} - -void WAConnection::sendMessageWithBody(FMessage* message) throw (WAException) -{ - ProtocolTreeNode *bodyNode = new ProtocolTreeNode("body", new std::vector(message->data.begin(), message->data.end())); - ProtocolTreeNode *n = WAConnection::getMessageNode(message, bodyNode); - out.write(*n); - delete n; -} - -void WAConnection::sendMessageReceived(const FMessage &message) throw(WAException) -{ - ProtocolTreeNode n("receipt"); - out.write(n << XATTR("type", "read") << XATTR("to", message.key.remote_jid) << XATTR("id", message.key.id)); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -void WAConnection::sendPaused(const std::string &to) throw(WAException) -{ - ProtocolTreeNode n("chatstate", new ProtocolTreeNode("paused")); - out.write(n << XATTR("to", to)); -} - -void WAConnection::sendPing() throw(WAException) -{ - m_pMutex->lock(); - std::string id = makeId("ping_"); - this->pending_server_requests[id] = new IqResultPingHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("ping")); - out.write(iq << XATTR("id", id) << XATTR("xmlns", "w:p") << XATTR("type", "get") << XATTR("to", "s.whatsapp.net")); -} - -void WAConnection::sendPong(const std::string &id) throw(WAException) -{ - ProtocolTreeNode iq("iq"); - out.write(iq << XATTR("type", "result") << XATTR("to", this->domain) << XATTR("id", id)); -} - -void WAConnection::sendPresenceSubscriptionRequest(const std::string &to) throw(WAException) -{ - ProtocolTreeNode n("presence"); - out.write(n << XATTR("type", "subscribe") << XATTR("to", to)); -} - -void WAConnection::sendSetPicture(const char *jid, std::vector* data, std::vector* preview) throw (WAException) -{ - m_pMutex->lock(); - std::string id = this->makeId("set_photo_"); - this->pending_server_requests[id] = new IqResultSetPhotoHandler(this, jid); - m_pMutex->unlock(); - - std::vector* messageChildren = new std::vector(); - if (preview) - messageChildren->push_back(new ProtocolTreeNode("picture", preview, NULL) << XATTR("type", "preview")); - if (data) - messageChildren->push_back(new ProtocolTreeNode("picture", data, NULL) << XATTR("type", "image")); - - ProtocolTreeNode iq("iq", NULL, messageChildren); - out.write(iq << XATTR("id", id) << XATTR("type", "set") << XATTR("to", jid) << XATTR("xmlns", "w:profile:picture")); -} - -void WAConnection::sendStatusUpdate(std::string& status) throw (WAException) -{ - std::string id = this->makeId(Utilities::intToStr((int)time(NULL))); - FMessage message("s.us", true, id); - ProtocolTreeNode *body = new ProtocolTreeNode("body", new std::vector(status.begin(), status.end()), NULL); - ProtocolTreeNode *n = getMessageNode(&message, body); - out.write(*n); - delete n; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Group chats - -void WAConnection::sendGetGroupInfo(const std::string &gjid) throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("iq_"); - this->pending_server_requests[id] = new IqResultGetGroupInfoHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("query") << XATTR("request", "interactive")); - out.write(iq << XATTR("xmlns", "w:g2") << XATTR("id", id) << XATTR("type", "get") << XATTR("to", gjid)); -} - -void WAConnection::sendGetParticipants(const std::string &gjid) throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("iq_"); - this->pending_server_requests[id] = new IqResultGetGroupParticipantsHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("list")); - out.write(iq << XATTR("xmlns", "w:g") << XATTR("id", id) << XATTR("type", "get") << XATTR("to", gjid)); -} - -void WAConnection::readAttributeList(ProtocolTreeNode *node, std::vector& vector, const std::string &tag, const std::string &attribute) throw (WAException) -{ - std::vector nodes(node->getAllChildren(tag)); - for (size_t i = 0; i < nodes.size(); i++) { - ProtocolTreeNode *tagNode = nodes[i]; - vector.push_back(tagNode->getAttributeValue(attribute)); - } -} - -void WAConnection::sendCreateGroupChat(const std::string &subject) throw (WAException) -{ - logData("sending create group: %s", subject.c_str()); - - m_pMutex->lock(); - std::string id = makeId("create_group_"); - this->pending_server_requests[id] = new IqResultCreateGroupChatHandler(this, subject); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("group") << XATTR("action", "create") << XATTR("subject", subject)); - out.write(iq << XATTR("xmlns", "w:g") << XATTR("id", id) << XATTR("type", "set") << XATTR("to", "g.us")); -} - -void WAConnection::sendClearDirty(const std::string &category) throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("clean_dirty_"); - this->pending_server_requests[id] = new IqResultClearDirtyHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode *categoryNode = new ProtocolTreeNode("category") << XATTR("name", category); - ProtocolTreeNode *cleanNode = new ProtocolTreeNode("clean", categoryNode) << XATTR("xmlns", "urn:xmpp:whatsapp:dirty"); - ProtocolTreeNode iq("iq", cleanNode); - out.write(iq << XATTR("id", id) << XATTR("type", "set") << XATTR("to", "s.whatsapp.net")); -} - -void WAConnection::sendJoinLeaveGroup(const char *gjid, bool bJoin) throw (WAException) -{ - std::string id = makeId("iq_"); - - ProtocolTreeNode *groupNode = new ProtocolTreeNode("group") << XATTR("id", gjid); - ProtocolTreeNode *leaveNode = new ProtocolTreeNode((bJoin) ? "join" : "leave", groupNode); - ProtocolTreeNode iq("iq", leaveNode); - out.write(iq << XATTR("xmlns", "w:g2") << XATTR("id", id) << XATTR("type", "set") << XATTR("to", "g.us")); -} - -void WAConnection::sendAddParticipants(const std::string &gjid, const std::vector &participants) throw (WAException) -{ - sendVerbParticipants(gjid, participants, "add"); -} - -void WAConnection::sendRemoveParticipants(const std::string &gjid, const std::vector &participants) throw (WAException) -{ - sendVerbParticipants(gjid, participants, "remove"); -} - -void WAConnection::sendVerbParticipants(const std::string &gjid, const std::vector &participants, const std::string &inner_tag) throw (WAException) -{ - std::string id = makeId("iq_"); - - size_t size = participants.size(); - std::vector* children = new std::vector(size); - for (size_t i = 0; i < size; i++) - (*children)[i] = new ProtocolTreeNode("participant") << XATTR("jid", participants[i]); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode(inner_tag, NULL, children)); - out.write(iq << XATTR("xmlns", "w:g") << XATTR("id", id) << XATTR("type", "set") << XATTR("to", gjid)); -} - -void WAConnection::sendSetNewSubject(const std::string &gjid, const std::string &subject) throw (WAException) -{ - std::string id = this->makeId("iq_"); - - std::vector *data = new std::vector(subject.begin(), subject.end()); - ProtocolTreeNode iq("iq", new ProtocolTreeNode("subject", data)); - out.write(iq << XATTR("xmlns", "w:g2") << XATTR("id", id) << XATTR("type", "set") << XATTR("to", gjid)); -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h deleted file mode 100644 index 0756a77abe..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h +++ /dev/null @@ -1,415 +0,0 @@ -/* - * WAConnection.h - * - * Created on: 26/06/2012 - * Author: Antonio - */ - - - - -#ifndef WACONNECTION_H_ -#define WACONNECTION_H_ - -#include -#include -#include -#include "WAException.h" -#include "FMessage.h" -#include "WALogin.h" -#include "utilities.h" -#include "BinTreeNodeReader.h" -#include "BinTreeNodeWriter.h" -#include "MediaUploader.h" - -#pragma warning(disable : 4290) - -class WALogin; -class WASocketConnection; -class KeyStream; -class BinTreeNodeReader; - -class WAListener { -public: - virtual void onMessageForMe(const FMessage ¶mFMessage) throw (WAException) = 0; - virtual void onMessageStatusUpdate(const FMessage ¶mFMessage) = 0; - virtual void onMessageError(const FMessage &message, int paramInt) = 0; - virtual void onPing(const std::string ¶mString) throw (WAException) = 0; - virtual void onPingResponseReceived() = 0; - virtual void onAvailable(const std::string ¶mString, bool paramBoolean, DWORD lastSeenTime = 0) = 0; - virtual void onClientConfigReceived(const std::string ¶mString) = 0; - virtual void onIsTyping(const std::string ¶mString, bool paramBoolean) = 0; - virtual void onAccountChange(int paramInt, time_t paramLong) = 0; - virtual void onPrivacyBlockListAdd(const std::string ¶mString) = 0; - virtual void onPrivacyBlockListClear() = 0; - virtual void onDirty(const std::map& paramHashtable) = 0; - virtual void onDirtyResponse(int paramHashtable) = 0; - virtual void onRelayRequest(const std::string ¶mString1, int paramInt, const std::string ¶mString2) = 0; - virtual void onSendGetPicture(const std::string &jid, const std::vector& data, const std::string &id) = 0; - virtual void onContactChanged(const std::string &jid, bool added) = 0; - virtual void onPictureChanged(const std::string &jid, const std::string &id, bool set) = 0; - virtual void onDeleteAccount(bool result) = 0; -}; - -class WAGroupListener { -public: - virtual void onGroupAddUser(const std::string &gjid, const std::string &ujid, int ts) = 0; - virtual void onGroupRemoveUser(const std::string &gjid, const std::string &ujid, int ts) = 0; - virtual void onGroupNewSubject(const std::string &from, const std::string &author, const std::string &newSubject, int paramInt) = 0; - virtual void onGroupMessage(const FMessage ¶mFMessage) = 0; - virtual void onServerProperties(std::map* nameValueMap) = 0; - virtual void onGroupCreated(const std::string &gjid, const std::string &nick) = 0; - virtual void onGroupInfo(const std::string &jid, const std::string &owner, const std::string &subject, const std::string &subject_owner, int time_subject, int time_created) = 0; - virtual void onSetSubject(const std::string ¶mString) = 0; - virtual void onAddGroupParticipants(const std::string ¶mString, const std::vector ¶mVector, int paramHashtable) = 0; - virtual void onRemoveGroupParticipants(const std::string ¶mString, const std::vector ¶mVector, int paramHashtable) = 0; - virtual void onGetParticipants(const std::string &gjid, const std::vector &participants) = 0; - virtual void onLeaveGroup(const std::string ¶mString) = 0; -}; - -class GroupSetting { -public: - std::string jid; - bool enabled; - time_t muteExpiry; - - GroupSetting() { - enabled = true; - jid = ""; - muteExpiry = 0; - } -}; - -class WAConnection -{ - class IqResultHandler { - protected: - WAConnection* con; - public: - IqResultHandler(WAConnection* con) {this->con = con;} - virtual void parse(ProtocolTreeNode* paramProtocolTreeNode, const std::string ¶mString) throw (WAException)=0; - void error(ProtocolTreeNode* node, int code) { - con->logData("WAConnection: error node %s: code = %d", node->getAttributeValue("id").c_str(), code); - } - void error(ProtocolTreeNode* node) throw (WAException) { - std::vector nodes(node->getAllChildren("error")); - for (size_t i = 0; i < nodes.size(); i++) { - ProtocolTreeNode* errorNode = nodes[i]; - if (errorNode != NULL) { - const string &errorCodeString = errorNode->getAttributeValue("code"); - if (!errorCodeString.empty()) { - int errorCode = atoi(errorCodeString.c_str()); - error(node, errorCode); - } - } - } - } - - virtual ~IqResultHandler() {} - }; - - class IqResultPingHandler: public IqResultHandler { - public: - IqResultPingHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode*, const std::string&) throw (WAException) { - if (this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onPingResponseReceived(); - } - - void error(ProtocolTreeNode*) throw (WAException) { - if (this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onPingResponseReceived(); - } - }; - - class IqResultGetGroupsHandler: public IqResultHandler { - private: - std::string type; - public: - IqResultGetGroupsHandler(WAConnection* con, const std::string &type ):IqResultHandler(con) {this->type = type;} - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - std::vector groups; - this->con->readGroupList(node, groups); - } - }; - - class IqResultServerPropertiesHandler: public IqResultHandler { - public: - IqResultServerPropertiesHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - std::vector nodes(node->getAllChildren("prop")); - std::map nameValueMap; - for (size_t i = 0; i < nodes.size();i++) { - ProtocolTreeNode* propNode = nodes[i]; - const string &nameAttr = propNode->getAttributeValue("name"); - const string &valueAttr = propNode->getAttributeValue("value"); - nameValueMap[nameAttr] = valueAttr; - } - - if (this->con->m_pGroupEventHandler != NULL) - this->con->m_pGroupEventHandler->onServerProperties(&nameValueMap); - } - }; - - class IqResultPrivayListHandler: public IqResultHandler { - public: - IqResultPrivayListHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - ProtocolTreeNode* queryNode = node->getChild(0); - ProtocolTreeNode::require(queryNode, "query"); - ProtocolTreeNode* listNode = queryNode->getChild(0); - ProtocolTreeNode::require(listNode, "list"); - if (this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onPrivacyBlockListClear(); - if (listNode->children != NULL) { - for (size_t i = 0; i < listNode->children->size(); i++) { - ProtocolTreeNode* itemNode = (*listNode->children)[i]; - ProtocolTreeNode::require(itemNode, "item"); - if (itemNode->getAttributeValue("type").compare("jid") == 0) { - const string &jid = itemNode->getAttributeValue("value"); - if (!jid.empty() && this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onPrivacyBlockListAdd(jid); - } - } - } - } - }; - - class IqResultGetGroupInfoHandler: public IqResultHandler { - public: - IqResultGetGroupInfoHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { - ProtocolTreeNode* groupNode = node->getChild(0); - ProtocolTreeNode::require(groupNode, "group"); - const string &owner = groupNode->getAttributeValue("owner"); - const string &subject = groupNode->getAttributeValue("subject"); - const string &subject_t = groupNode->getAttributeValue("s_t"); - const string &subject_owner = groupNode->getAttributeValue("s_o"); - const string &creation = groupNode->getAttributeValue("creation"); - if (this->con->m_pGroupEventHandler != NULL) - this->con->m_pGroupEventHandler->onGroupInfo(from, owner, subject, subject_owner, atoi(subject_t.c_str()), atoi(creation.c_str())); - } - }; - - class IqResultGetGroupParticipantsHandler: public IqResultHandler { - public: - IqResultGetGroupParticipantsHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { - if (this->con->m_pGroupEventHandler != NULL) { - std::vector participants; - this->con->readAttributeList(node, participants, "participant", "jid"); - this->con->m_pGroupEventHandler->onGetParticipants(from, participants); - } - } - }; - - class IqResultCreateGroupChatHandler: public IqResultHandler { - std::string subject; - public: - IqResultCreateGroupChatHandler(WAConnection* con, const std::string &_subject) : - IqResultHandler(con), - subject(_subject) {} - virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { - ProtocolTreeNode* groupNode = node->getChild(0); - ProtocolTreeNode::require(groupNode, "group"); - const string &groupId = groupNode->getAttributeValue("id"); - if (!groupId.empty() && con->m_pGroupEventHandler != NULL) - this->con->m_pGroupEventHandler->onGroupCreated(groupId + "@" + from, subject); - } - }; - - class IqResultGetPhotoHandler: public IqResultHandler { - private: - std::string jid; - std::string oldId; - std::string newId; - public: - IqResultGetPhotoHandler(WAConnection* con, const std::string &jid):IqResultHandler(con) { - this->jid = jid; - } - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - const string &attributeValue = node->getAttributeValue("type"); - - if (!attributeValue.empty() && attributeValue == "result" && this->con->m_pEventHandler != NULL) { - std::vector children(node->getAllChildren("picture")); - for (size_t i = 0; i < children.size(); i++) { - ProtocolTreeNode* current = children[i]; - const string &id = current->getAttributeValue("id"); - if (!id.empty() && current->data != NULL && current->data->size() > 0) { - if (current->data != NULL) - this->con->m_pEventHandler->onSendGetPicture(this->jid, *current->data, id); - break; - } - } - } - } - void error(ProtocolTreeNode*) throw (WAException) { - if (this->con->m_pEventHandler != NULL) { - std::vector v; - this->con->m_pEventHandler->onSendGetPicture("error", v, ""); - } - } - }; - - class IqResultSetPhotoHandler: public IqResultHandler { - private: - std::string jid; - public: - IqResultSetPhotoHandler(WAConnection* con, const std::string &jid):IqResultHandler(con) {this->jid = jid;} - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - if (this->con->m_pEventHandler != NULL) { - ProtocolTreeNode* child = node->getChild("picture"); - if (child != NULL) - this->con->m_pEventHandler->onPictureChanged(this->jid, "", true); - else - this->con->m_pEventHandler->onPictureChanged(this->jid, "", false); - } - } - }; - - class IqResultSendDeleteAccount: public IqResultHandler { - public: - IqResultSendDeleteAccount(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode*, const std::string&) throw (WAException) { - if (this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onDeleteAccount(true); - } - - void error(ProtocolTreeNode*) throw (WAException) { - if (this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onDeleteAccount(false); - } - }; - - class IqResultClearDirtyHandler: public IqResultHandler { - public: - IqResultClearDirtyHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode*, const std::string&) throw (WAException) { - } - }; - - class IqSendClientConfigHandler: public IqResultHandler { - public: - IqSendClientConfigHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - con->logData("Clientconfig response %s", node->toString().c_str()); - } - - void error(ProtocolTreeNode* node) throw (WAException) { - con->logData("Clientconfig response error %s", node->toString().c_str()); - } - }; - - class MediaUploadResponseHandler : public IqResultHandler { - private: - FMessage message; - public: - MediaUploadResponseHandler(WAConnection* con, const FMessage &message) :IqResultHandler(con) { this->message = message; } - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - this->con->processUploadResponse(node, &message); - } - void error(ProtocolTreeNode* node) throw (WAException) { - con->logData("Error on Media Upload Request: %s", node->toString().c_str()); - } - }; - - friend class WALogin; - -private: - ISocketConnection *rawConn; - BinTreeNodeReader in; - BinTreeNodeWriter out; - WAListener *m_pEventHandler; - WAGroupListener *m_pGroupEventHandler; - int iqid; - std::map pending_server_requests; - IMutex *m_pMutex; - - void parseAck(ProtocolTreeNode *node) throw (WAException); - void parseChatStates(ProtocolTreeNode *node) throw (WAException); - void parseIq(ProtocolTreeNode *node) throw(WAException); - void parseMessage(ProtocolTreeNode* node) throw(WAException); - void parseNotification(ProtocolTreeNode *node) throw(WAException); - void parsePresense(ProtocolTreeNode*) throw(WAException); - void parseReceipt(ProtocolTreeNode *node) throw (WAException); - std::map parseCategories(ProtocolTreeNode* node) throw(WAException); - - void processUploadResponse(ProtocolTreeNode *node, FMessage *message); - - void sendMessageWithMedia(FMessage* message) throw(WAException); - void sendMessageWithBody(FMessage* message) throw(WAException); - ProtocolTreeNode* getReceiptAck(const std::string &to, const std::string &id, const std::string &receiptType) throw(WAException); - std::string makeId(const std::string &prefix); - void readGroupList(ProtocolTreeNode* node, std::vector& groups) throw (WAException); - std::string gidToGjid(const std::string &gid); - void readAttributeList(ProtocolTreeNode* node, std::vector &vector, const std::string &tag, const std::string &attribute) throw (WAException); - void sendVerbParticipants(const std::string &gjid, const std::vector &participants, const std::string &inner_tag) throw (WAException); - bool supportsReceiptAcks(); - static ProtocolTreeNode* getMessageNode(FMessage* message, ProtocolTreeNode* node); - std::vector* processGroupSettings(const std::vector& gruops); - -public: - WAConnection(const std::string &user, const std::string &resource, IMutex* mutex, IMutex *write_mutex, ISocketConnection *conn, WAListener* m_pEventHandler, WAGroupListener* m_pGroupEventHandler); - virtual ~WAConnection(); - - std::string user; - std::string domain; - std::string resource; - std::string jid; - std::string nick; - - KeyStream inputKey, outputKey; - - bool retry; - bool supports_receipt_acks; - time_t expire_date; - int account_kind; - time_t lastTreeRead; - - static void globalInit(void); - static int tokenLookup(const std::string&); - - void logData(const char *format, ...); - void flush() { out.flushBuffer(true); } - - static std::string removeResourceFromJid(const std::string &jid); - - void setFlush(bool _flush) { if (out.bFlush = _flush) out.flushBuffer(true); } - - void setLogin(WALogin *login); - void sendMessage(FMessage* message) throw(WAException); - void sendAvailableForChat() throw(WAException); - - bool read() throw(WAException); - - void sendAck(ProtocolTreeNode * node, const char *classType); - void sendPing() throw(WAException); - void sendPong(const std::string &id) throw(WAException); - void sendComposing(const std::string &to) throw(WAException); - void sendActive() throw(WAException); - void sendInactive() throw(WAException); - void sendPaused(const std::string &to) throw(WAException); - void sendMessageReceived(const FMessage &message) throw(WAException); - void sendPresenceSubscriptionRequest(const std::string &to) throw (WAException); - void sendClientConfig(const std::string &sound, const std::string &pushID, bool preview, const std::string &platform) throw(WAException); - void sendClientConfig(const std::string &pushID, bool preview, const std::string &platform, bool defaultSettings, bool groupSettings, const std::vector& groups) throw(WAException); - void sendClose() throw (WAException); - void sendAvailable() throw (WAException); // U.H. - void sendGetPrivacyList() throw (WAException); - void sendGetServerProperties() throw (WAException); - void sendGetGroups() throw (WAException); - void sendCreateGroupChat(const std::string &subject) throw (WAException); - void sendGetGroupInfo(const std::string &gjid) throw (WAException); - void sendGetParticipants(const std::string &gjid) throw (WAException); - void sendClearDirty(const std::string &category) throw (WAException); - void sendJoinLeaveGroup(const char *gjid, bool bJoin) throw (WAException); - void sendAddParticipants(const std::string &gjid, const std::vector &participants) throw (WAException); - void sendRemoveParticipants(const std::string &gjid, const std::vector &participant) throw (WAException); - void sendSetNewSubject(const std::string &gjid, const std::string &subject) throw (WAException); - void sendStatusUpdate(std::string& status) throw (WAException); - void sendGetPicture(const char *jid, const char *type) throw (WAException); - void sendSetPicture(const char *jid, std::vector* data, std::vector* preview) throw (WAException); - void sendDeleteAccount() throw(WAException); -}; - -#endif /* WACONNECTION_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAException.h b/protocols/WhatsApp/src/WhatsAPI++/WAException.h deleted file mode 100644 index 4255850ffc..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WAException.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * WAException.h - * - * Created on: 27/06/2012 - * Author: Antonio - */ - - - -#ifndef WAEXCEPTION_H_ -#define WAEXCEPTION_H_ - -#include -#include - -class WAException: public std::runtime_error { -public: - int type; - int subtype; - time_t expire_date; // in seconds - - static const int LOGIN_FAILURE_EX = 1; - static const int LOGIN_FAILURE_EX_TYPE_PASSWORD = 0; - static const int LOGIN_FAILURE_EX_TYPE_EXPIRED = 1; - - static const int CORRUPT_STREAM_EX = 2; - - static const int SOCKET_EX = 3; - static const int SOCKET_EX_RESOLVE_HOST = 0; - static const int SOCKET_EX_OPEN = 1; - static const int SOCKET_EX_INIT = 2; - static const int SOCKET_EX_SEND = 3; - static const int SOCKET_EX_RECV = 4; - - WAException(const std::string &err): runtime_error(err) {this->type = 0; this->subtype = 0; this->expire_date = 0;}; - WAException(const std::string &err, int type, int subtype): runtime_error(err), type(type), subtype(subtype), expire_date(0) {}; - WAException(const std::string &err, int type, int subtype, time_t expireDate): runtime_error(err), type(type), subtype(subtype), expire_date(expireDate) {}; -}; - -#endif /* WAEXCEPTION_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp deleted file mode 100644 index 12f7c7a863..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * WALogin.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "WALogin.h" -#include "ByteArray.h" -#include "ProtocolTreeNode.h" -#include -#include -#include -#include - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -using namespace Utilities; - -WALogin::WALogin(WAConnection* connection, const std::string &password) -{ - m_pConnection = connection; - m_szPassword = password; - m_iAccountKind = -1; - m_tExpireDate = 0L; -} - -std::vector WALogin::login(const std::vector& authBlob) -{ - m_pConnection->out.streamStart(m_pConnection->domain, m_pConnection->resource); - - m_pConnection->logData("sent stream start"); - - sendFeatures(); - - m_pConnection->logData("sent features"); - - sendAuth(authBlob); - - m_pConnection->logData("send auth, auth blob size %d", authBlob.size()); - - m_pConnection->in.streamStart(); - - m_pConnection->logData("read stream start"); - - return this->readFeaturesUntilChallengeOrSuccess(); -} - -void WALogin::sendResponse(const std::vector& challengeData) -{ - std::vector* authBlob = this->getAuthBlob(challengeData); - m_pConnection->out.write(ProtocolTreeNode("response", authBlob)); -} - -void WALogin::sendFeatures() -{ - std::vector* children = new std::vector(); - ProtocolTreeNode* receiptsChild = new ProtocolTreeNode("readreceipts"); - children->push_back(receiptsChild); - - ProtocolTreeNode* groupsChild = new ProtocolTreeNode("groups_v2"); - children->push_back(groupsChild); - - ProtocolTreeNode* privacyChild = new ProtocolTreeNode("privacy"); - children->push_back(privacyChild); - - ProtocolTreeNode* presenceChild = new ProtocolTreeNode("presence"); - children->push_back(presenceChild); - - m_pConnection->out.write(ProtocolTreeNode("stream:features", NULL, children)); -} - -void WALogin::sendAuth(const std::vector& existingChallenge) -{ - std::vector* data = NULL; - if (!existingChallenge.empty()) - data = getAuthBlob(existingChallenge); - - ProtocolTreeNode n("auth", data); - m_pConnection->out.write(n << XATTR("mechanism", "WAUTH-2") << XATTR("user", m_pConnection->user)); -} - -std::vector* WALogin::getAuthBlob(const std::vector& nonce) -{ - unsigned char out[4*20]; - KeyStream::keyFromPasswordAndNonce(m_szPassword, nonce, out); - - m_pConnection->inputKey.init(out + 40, out + 60); - m_pConnection->outputKey.init(out, out + 20); - - std::vector* list = new std::vector(0); - for (int i = 0; i < 4; i++) - list->push_back(0); - - list->insert(list->end(), m_pConnection->user.begin(), m_pConnection->user.end()); - list->insert(list->end(), nonce.begin(), nonce.end()); - - m_pConnection->outputKey.encodeMessage(&((*list)[0]), 0, 4, (int)list->size() - 4); - return list; -} - -std::vector WALogin::readFeaturesUntilChallengeOrSuccess() -{ - while (ProtocolTreeNode *root = m_pConnection->in.nextTree()) { - if (ProtocolTreeNode::tagEquals(root, "challenge")) { - std::vector challengedata(root->data->begin(), root->data->end()); - delete root; - - this->sendResponse(challengedata); - m_pConnection->logData("Send response"); - std::vector data = this->readSuccess(); - m_pConnection->logData("Read success"); - return std::vector(data.begin(), data.end()); - } - - if (ProtocolTreeNode::tagEquals(root, "success")) { - std::vector ret(root->data->begin(), root->data->end()); - this->parseSuccessNode(root); - delete root; - return ret; - } - - if (ProtocolTreeNode::tagEquals(root, "stream:features")) - m_pConnection->supports_receipt_acks = root->getChild("receipt_acks") != NULL; - - delete root; - } - throw WAException("fell out of loop in readFeaturesAndChallenge", WAException::CORRUPT_STREAM_EX, 0); -} - -void WALogin::parseSuccessNode(ProtocolTreeNode* node) -{ - m_pConnection->out.setSecure(); - - const string &expiration = node->getAttributeValue("expiration"); - if (!expiration.empty()) { - m_tExpireDate = atol(expiration.c_str()); - if (m_tExpireDate == 0) - throw WAException("invalid expire date: " + expiration); - } - - const string &kind = node->getAttributeValue("kind"); - if (kind == "paid") - m_iAccountKind = 1; - else if (kind == "free") - m_iAccountKind = 0; - else - m_iAccountKind = -1; -} - -std::vector WALogin::readSuccess() -{ - ProtocolTreeNode *node = m_pConnection->in.nextTree(); - - if (ProtocolTreeNode::tagEquals(node, "failure")) { - delete node; - throw WAException("Login failure", WAException::LOGIN_FAILURE_EX, WAException::LOGIN_FAILURE_EX_TYPE_PASSWORD); - } - - ProtocolTreeNode::require(node, "success"); - this->parseSuccessNode(node); - - const string &status = node->getAttributeValue("status"); - if (status == "expired") { - delete node; - throw WAException("Account expired on" + std::string(ctime(&m_tExpireDate)), WAException::LOGIN_FAILURE_EX, WAException::LOGIN_FAILURE_EX_TYPE_EXPIRED, m_tExpireDate); - } - if (status == "active") { - if (node->getAttributeValue("expiration").empty()) { - delete node; - throw WAException("active account with no expiration"); - } - } - else m_iAccountKind = -1; - - std::vector data = *node->data; - delete node; - return data; -} - -WALogin::~WALogin() -{} diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.h b/protocols/WhatsApp/src/WhatsAPI++/WALogin.h deleted file mode 100644 index 0d4d30af5b..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * WALogin.h - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#ifndef WALOGIN_H_ -#define WALOGIN_H_ - -#include "BinTreeNodeReader.h" -#include "BinTreeNodeWriter.h" -#include "WAConnection.h" -#include - -#include "../OpenSSL/rc4.h" -#include "../OpenSSL/hmac.h" - -class WAConnection; -class BinTreeNodeReader; -class BinTreeNodeWriter; - -class KeyStream { -private: - RC4_KEY rc4; - unsigned char key[20], keyMac[20]; - int seq; - HMAC_CTX hmac; - - void hmacsha1(unsigned char* text, int textLength, unsigned char *out); - -public: - KeyStream(); - ~KeyStream(); - - void init(unsigned char *_key, unsigned char *_keyMac); - - static void keyFromPasswordAndNonce(const std::string &pass, const std::vector& nonce, unsigned char *out); - void decodeMessage(unsigned char* buffer, int macOffset, int offset, const int length); - void encodeMessage(unsigned char* buffer, int macOffset, int offset, const int length); -}; - - -class WALogin { -private: - WAConnection *m_pConnection; - - std::vector* getAuthBlob(const std::vector& nonce); - void sendResponse(const std::vector& challengeData); - void sendFeatures(); - void sendAuth(const std::vector& nonce); - std::vector readFeaturesUntilChallengeOrSuccess(); - void parseSuccessNode(ProtocolTreeNode *node); - std::vector readSuccess(); - -public: - time_t m_tExpireDate; - int m_iAccountKind; - std::string m_szPassword; - - WALogin(WAConnection* connection, const std::string &password); - ~WALogin(); - - std::vector login(const std::vector &blob); -}; - -#endif /* WALOGIN_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp b/protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp deleted file mode 100644 index f7371c7fc8..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * WARegister.cpp - * - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "WARegister.h" -#include "PhoneNumber.h" - -using namespace Utilities; - -static char WaToken[] = WHATSAPP_TOKEN; - - -///////////////////////////////////////////////////////////////////////////////////////// -// Token generation -// -std::string WAToken::GenerateToken(const string &number) -{ - uint8_t digest[16]; - md5_string(WaToken + number, digest); - - char dest[33]; - bin2hex(digest, sizeof(digest), dest); - return dest; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Account registration -// -CMStringA WARegister::RequestCodeUrl(const std::string &phoneNumber, const std::string &code) -{ - try { - std::string id = GenerateIdentity(phoneNumber); - - PhoneNumber pn(phoneNumber); - std::string token = WAToken::GenerateToken(pn.Number); - - const char *n = pn.Number.c_str(); - - if (!code.empty() && code != "voice" && code != "sms") - return CMStringA(FORMAT, "https://v.whatsapp.net/v2/register?cc=%d&in=%s&id=%s&code=%s", pn.countryCode, n, id.c_str(), code.c_str()); - - return CMStringA(FORMAT, "https://v.whatsapp.net/v2/code?cc=%d&in=%s&to=%d%s&method=%s&mcc=%03d&mnc=%03d&token=%s&id=%s&lg=%s&lc=%s", - pn.countryCode, n, pn.countryCode, n, code.c_str(), pn.mcc, pn.mnc, token.c_str(), id.c_str(), pn.ISO639, pn.ISO3166); - } - catch (...) - {} - - return CMStringA(); -} - - -std::string WARegister::GenerateIdentity(const std::string &phone) -{ - std::string id = phone; - std::reverse(id.begin(), id.end()); - - BYTE hash[MIR_SHA1_HASH_SIZE]; - mir_sha1_hash((PBYTE)id.c_str(), (int)id.length(), hash); - - id.clear(); - for (int i = 0; i < sizeof(hash); i++) { - char buf[10]; - sprintf_s(buf, "%%%02x", hash[i]); - id += buf; - } - - return id; -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/WARegister.h b/protocols/WhatsApp/src/WhatsAPI++/WARegister.h deleted file mode 100644 index f2fe0e230b..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WARegister.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * WARegister.h - */ - -#ifndef WAREGISTER_H_ -#define WAREGISTER_H_ - -#include - -struct WAToken -{ - static std::string GenerateToken(const std::string &number); -}; - -class WARegister -{ - static std::string GenerateIdentity(const std::string &phone); - -public: - static CMStringA RequestCodeUrl(const std::string &phone, const std::string &code); -}; - -#endif /* WAREGISTER_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/targetver.h b/protocols/WhatsApp/src/WhatsAPI++/targetver.h deleted file mode 100644 index 343ce14c2f..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/targetver.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -// Durch Einbeziehen von"SDKDDKVer.h" wird die hцchste verfьgbare Windows-Plattform definiert. - -// Wenn Sie die Anwendung fьr eine frьhere Windows-Plattform erstellen mцchten, schlieЯen Sie "WinSDKVer.h" ein, und -// legen Sie das _WIN32_WINNT-Makro auf die zu unterstьtzende Plattform fest, bevor Sie "SDKDDKVer.h" einschlieЯen. - -#include diff --git a/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp b/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp deleted file mode 100644 index 9c56a0c7dd..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp +++ /dev/null @@ -1,386 +0,0 @@ -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "utilities.h" -#include "WAException.h" - -namespace Utilities { - -const static char digits[] = { - '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', 'a', 'b', - 'c', 'd', 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', - 'u', 'v', 'w', 'x', 'y', 'z' -}; - -std::string reverseString(const std::string &str) -{ - return std::string(str.rbegin(), str.rend()); -} - -std::string itoa(int value, unsigned int base) -{ - const char digitMap[] = "0123456789abcdef"; - - std::string buf; - // Guard: - if (base == 0 || base > 16) { - - // Error: may add more trace/log output here - return buf; - } - // Take care of negative int: - std::string sign; - int _value = value; - // Check for case when input is zero: - if (_value == 0) return "0"; - if (value < 0) { - _value = -value; - sign = "-"; - } - - // Translating number to string with base: - - for (int i = 30; _value && i; --i) { - buf = digitMap[_value % base] + buf; - _value /= base; - } - - return sign.append(buf); -} - - -std::string processIdentity(const std::string &id) -{ - std::string buffer_str = reverseString(id); - - unsigned char digest[16]; - md5_string(buffer_str, digest); - buffer_str.clear(); - - for (int i = 0; i < 16; i++) { - int tmp = digest[i] + 128; - int f = tmp & 0xff; - - buffer_str = buffer_str.append(itoa(f, 16)); - } - - return buffer_str; -} - -void debug(const std::string &msg) -{ -#ifdef _LOGWIN32 - cout << "DEBUG: " << msg << endl; -#else - syslog(LOG_ERR, msg.c_str()); -#endif -} - -std::string str(int64_t i, int radix) -{ - if (radix < 2 || radix > 36) - throw WAException("radix must be in 2..36"); - char buf[65]; - int charPos = 64; - bool negative = (i < 0); - - if (!negative) { - i = -i; - } - - while (i <= -radix) { - buf[charPos--] = digits[(int)(-(i % radix))]; - i = i / radix; - } - buf[charPos] = digits[(int)(-i)]; - - if (negative) { - buf[--charPos] = '-'; - } - - std::string aux(buf, 65); - - return std::string(aux, charPos, (65 - charPos)); -} - -int64_t randLong() -{ - std::srand((unsigned)time(NULL)); - int64_t r = (int64_t)((char)(std::rand() % 256)); - - for (int i = 0; i < 7; i++) - r = (r << 8) + ((char)(std::rand() % 256)); - - return r; -} - -int64_t absLong(int64_t num) -{ - return (num >= 0 ? num : -num); -} - - -std::string intToStr(int i) -{ - std::stringstream convert; - convert << i; - return convert.str(); -} - -std::string doubleToStr(double d) -{ - std::stringstream convert; - convert << d; - return convert.str(); -} - -time_t parseBBDate(const string& s) -{ - if (s.length() < 17) - return time(NULL); - - struct tm timeinfo; - timeinfo.tm_year = atoi(s.substr(0, 4).c_str()) - 1900; - timeinfo.tm_mon = atoi(s.substr(4, 2).c_str()) - 1; - timeinfo.tm_mday = atoi(s.substr(6, 2).c_str()); - timeinfo.tm_hour = atoi(s.substr(9, 2).c_str()); - timeinfo.tm_min = atoi(s.substr(12, 2).c_str()); - timeinfo.tm_sec = atoi(s.substr(15, 2).c_str()); - - //return timegm(&timeinfo); - return mktime(&timeinfo); -} - -long long parseLongLong(const std::string &str) -{ - std::stringstream sstr(str); - long long val; - sstr >> val; - - return val; -} - -string bytesToHex(unsigned char* bytes, int length) -{ - string ret(length * 2, ' '); - string::iterator p = ret.begin(); - for (int c = 0; c < length; c++) { - int ub = bytes[c]; - *p++ = forDigit(ub >> 4); - *p++ = forDigit(ub % 16); - } - - return ret; -} - -unsigned char forDigit(int b) -{ - if (b < 10) - return (unsigned char)(48 + b); - return (unsigned char)(97 + b - 10); -} - -bool saveStringToFile(const string& data, const string& filePath) -{ - std::ofstream out(filePath.c_str()); - if (out.fail()) return false; - out << data; - if (out.fail()) return false; - out.close(); - if (out.fail()) return false; - return true; -} - -bool saveBytesToFile(const std::vector& data, const string& filePath) -{ - std::fstream out(filePath.c_str(), ios::out | ios::binary); - if (out.fail()) return false; - out.write((const char*)&data[0], data.size()); - if (out.fail()) return false; - out.close(); - if (out.fail()) return false; - return true; -} - - -bool saveBytesToFile(const string& data, const string& filePath) -{ - std::fstream out(filePath.c_str(), ios::out | ios::binary); - if (out.fail()) return false; - out.write(data.c_str(), data.length()); - if (out.fail()) return false; - out.close(); - if (out.fail()) return false; - return true; -} - -vector* loadFileToBytes(const string& path) -{ - vector* bytes = NULL; - std::ifstream in(path.c_str(), ios::in | ios::binary | ios::ate); - size_t size = in.tellg(); - if (in.fail()) return NULL; - - in.seekg(0, ios::beg); - char *buffer = new char[size]; - in.read(buffer, size); - bytes = new vector(buffer, buffer + size); - delete[] buffer; - in.close(); - if (in.fail()) return NULL; - - return bytes; -} - -bool fileExists(const std::string &path) -{ - return _access(path.c_str(), 0) == 0; -} - - -string removeWaDomainFromJid(const string& jid) -{ - string result = jid; - - size_t index = jid.find("@s.whatsapp.net"); - if (index != string::npos) { - result.replace(index, 15, ""); - return result; - } - - index = jid.find("@g.us"); - if (index != string::npos) { - result.replace(index, 5, ""); - return result; - } - - return jid; -} - -string getNameFromPath(const std::string &path) -{ - size_t i = path.rfind('/'); - if (i == string::npos) - i = 0; - else - i = i + 1; - return path.substr(i); -} - -vector* getChallengeData(const std::string &challengeFile) -{ - return loadFileToBytes(challengeFile); -} - -bool saveChallengeData(const std::vector& data, const std::string &challengeFile) -{ - return saveBytesToFile(data, challengeFile); -} - -std::string utf8_to_utf16(const std::string &utf8) -{ - std::vector unicode; - for (size_t i = 0; i < utf8.size();) { - unsigned long uni; - size_t todo; - unsigned char ch = utf8[i++]; - if (ch <= 0x7F) { - uni = ch; - todo = 0; - } - else if (ch <= 0xBF) { - throw std::logic_error("not a UTF-8 string"); - } - else if (ch <= 0xDF) { - uni = ch & 0x1F; - todo = 1; - } - else if (ch <= 0xEF) { - uni = ch & 0x0F; - todo = 2; - } - else if (ch <= 0xF7) { - uni = ch & 0x07; - todo = 3; - } - else { - throw std::logic_error("not a UTF-8 string"); - } - for (size_t j = 0; j < todo; ++j) { - if (i == utf8.size()) - throw std::logic_error("not a UTF-8 string"); - ch = utf8[i++]; - if (ch < 0x80 || ch > 0xBF) - throw std::logic_error("not a UTF-8 string"); - uni <<= 6; - uni += ch & 0x3F; - } - if (uni >= 0xD800 && uni <= 0xDFFF) - throw std::logic_error("not a UTF-8 string"); - if (uni > 0x10FFFF) - throw std::logic_error("not a UTF-8 string"); - unicode.push_back(uni); - } - std::string utf16; - for (size_t i = 0; i < unicode.size(); ++i) { - unsigned long uni = unicode[i]; - if (uni <= 0x7F) { - utf16 += (char)uni; - } - else - if (uni <= 0xFFFF) { - stringstream value; - value << std::setw(4) << std::setfill('0') << Utilities::itoa(uni, 16).c_str(); - utf16 += "\\u" + value.str(); - } - else { - stringstream value1, value2; - uni -= 0x10000; - value1 << std::setw(4) << std::setfill('0') << Utilities::itoa(((uni >> 10) + 0xD800), 16); - utf16 += "\\u" + value1.str(); - - value2 << std::setw(4) << std::setfill('0') << Utilities::itoa(((uni & 0x3FF) + 0xDC00), 16); - utf16 += "\\u" + value2.str(); - } - } - return utf16; -} - -std::string string_format(const char* fmt, va_list ap) -{ - int size = 100; - std::string str; - while (true) { - str.resize(size); - //va_start(ap, fmt); - int n = vsnprintf((char *)str.c_str(), size, fmt, ap); - //va_end(ap); - if (n > -1 && n < size) { - str.resize(n); - return str; - } - if (n > -1) - size = n + 1; - else - size *= 2; - } - return str; -} - -std::string string_format(const std::string fmt, va_list ap) -{ - return string_format(fmt.c_str(), ap); -} - -std::string string_format(const std::string fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - std::string ret = string_format(fmt, ap); - va_end(ap); - return ret; -} - -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/utilities.h b/protocols/WhatsApp/src/WhatsAPI++/utilities.h deleted file mode 100644 index 5f5dd5713a..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/utilities.h +++ /dev/null @@ -1,70 +0,0 @@ -/*************************************************************************** -** -** Copyright (c) 2012, Tarek Galal -** -** This file is part of Wazapp, an IM application for Meego Harmattan -** platform that allows communication with Whatsapp users. -** -** Wazapp is free software: you can redistribute it and/or modify it under -** the terms of the GNU General Public License as published by the -** Free Software Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Wazapp is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -** See the GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Wazapp. If not, see http://www.gnu.org/licenses/. -** -****************************************************************************/ - -#ifndef WA_UTILITIES -#define WA_UTILITIES - -#include -#include -#include -#include -#include - -#define _LOGWIN32 // #TODO -#ifndef _LOGWIN32 -#include -#endif - -using namespace std; - -// these functions must be declared somewhere in the same linking module -std::string base64_encode(void*, size_t); -void md5_string(const std::string &data, unsigned char digest[16]); - -namespace Utilities{ - string getMcc(); - string getMnc(); - string reverseString(const string& str); - string processIdentity(const std::string &password); - int64_t randLong(); - int64_t absLong(int64_t num); - string str(int64_t number, int radix); - std::string itoa(int value, unsigned int base); - std::string intToStr(int i); - std::string doubleToStr(double d); - long long parseLongLong(const std::string &str); - time_t parseBBDate(const string& s); - long long getCurrentTimeMillis(); - std::string bytesToHex(unsigned char* bytes, int length); - unsigned char forDigit(int b); - bool saveStringToFile(const string& data, const string& filePath); - bool saveBytesToFile(const string& data, const string& filePath); - bool saveBytesToFile(const std::vector& data, const string& filePath); - string removeWaDomainFromJid(const string& jid); - string getNameFromPath(const std::string &path); - vector* loadFileToBytes(const string& path); - bool fileExists(const std::string &path); - std::vector* getChallengeData(const std::string &file); - bool saveChallengeData(const std::vector& data, const std::string &file); - std::string utf8_to_utf16(const std::string &utf8); -} -#endif diff --git a/protocols/WhatsApp/src/avatars.cpp b/protocols/WhatsApp/src/avatars.cpp deleted file mode 100644 index 4a7bf6e310..0000000000 --- a/protocols/WhatsApp/src/avatars.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "stdafx.h" - -INT_PTR WhatsAppProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) -{ - PROTO_AVATAR_INFORMATION *pai = (PROTO_AVATAR_INFORMATION*)lParam; - - ptrA id(getStringA(pai->hContact, isChatRoom(pai->hContact) ? "ChatRoomID" : WHATSAPP_KEY_ID)); - if (id == NULL) - return GAIR_NOAVATAR; - - std::wstring tszFileName = GetAvatarFileName(pai->hContact); - wcsncpy_s(pai->filename, tszFileName.c_str(), _TRUNCATE); - pai->format = PA_FORMAT_JPEG; - - ptrA szAvatarId(getStringA(pai->hContact, WHATSAPP_KEY_AVATAR_ID)); - if (szAvatarId == NULL || (wParam & GAIF_FORCE) != 0) - if (pai->hContact != NULL && m_pConnection != nullptr) { - m_pConnection->sendGetPicture(id, "image"); - return GAIR_WAITFOR; - } - - debugLogA("No avatar"); - return GAIR_NOAVATAR; -} - -INT_PTR WhatsAppProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) -{ - switch (wParam) { - case AF_PROPORTION: - return PIP_SQUARE; - - case AF_FORMATSUPPORTED: // Jabber supports avatars of virtually all formats - return PA_FORMAT_JPEG; - - case AF_ENABLED: - return TRUE; - - case AF_MAXSIZE: - POINT *size = (POINT*)lParam; - if (size) - size->x = size->y = 640; - return 0; - } - return -1; -} - -std::wstring WhatsAppProto::GetAvatarFileName(MCONTACT hContact) -{ - std::wstring result = m_tszAvatarFolder + L"\\"; - - std::string jid; - if (hContact != NULL) { - ptrA szId(getStringA(hContact, isChatRoom(hContact) ? "ChatRoomID" : WHATSAPP_KEY_ID)); - if (szId == NULL) - return L""; - - jid = szId; - } - else jid = m_szJid; - - return result + std::wstring(_A2T(jid.c_str())) + L".jpg"; -} - -INT_PTR WhatsAppProto::GetMyAvatar(WPARAM wParam, LPARAM lParam) -{ - std::wstring tszOwnAvatar(m_tszAvatarFolder + L"\\myavatar.jpg"); - wcsncpy_s((wchar_t*)wParam, lParam, tszOwnAvatar.c_str(), _TRUNCATE); - return 0; -} - -static std::vector* sttFileToMem(const wchar_t *ptszFileName) -{ - HANDLE hFile = CreateFile(ptszFileName, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); - if (hFile == INVALID_HANDLE_VALUE) - return nullptr; - - DWORD upperSize, lowerSize = GetFileSize(hFile, &upperSize); - std::vector *result = new std::vector(lowerSize); - ReadFile(hFile, (void*)result->data(), lowerSize, &upperSize, nullptr); - CloseHandle(hFile); - return result; -} - -int WhatsAppProto::InternalSetAvatar(MCONTACT hContact, const char *szJid, const wchar_t *ptszFileName) -{ - if (!isOnline() || ptszFileName == nullptr) - return 1; - - if (_waccess(ptszFileName, 4) != 0) - return errno; - - ResizeBitmap resize = { 0 }; - if ((resize.hBmp = Bitmap_Load(ptszFileName)) == nullptr) - return 2; - resize.size = sizeof(resize); - resize.fit = RESIZEBITMAP_KEEP_PROPORTIONS; - resize.max_height = resize.max_width = 96; - - HBITMAP hbmpPreview = (HBITMAP)CallService(MS_IMG_RESIZE, (LPARAM)&resize, 0); - if (hbmpPreview == nullptr) - return 3; - - wchar_t tszTempFile[MAX_PATH], tszMyFile[MAX_PATH]; - if (hContact == NULL) { - mir_snwprintf(tszMyFile, L"%s\\myavatar.jpg", m_tszAvatarFolder.c_str()); - mir_snwprintf(tszTempFile, L"%s\\myavatar.preview.jpg", m_tszAvatarFolder.c_str()); - } - else { - std::wstring tszContactAva = GetAvatarFileName(hContact); - wcsncpy_s(tszMyFile, tszContactAva.c_str(), _TRUNCATE); - wcsncpy_s(tszTempFile, (tszContactAva + L".preview").c_str(), _TRUNCATE); - } - - IMGSRVC_INFO saveInfo = { sizeof(saveInfo), nullptr }; - saveInfo.hbm = hbmpPreview; - saveInfo.tszName = tszTempFile; - saveInfo.dwMask = IMGI_HBITMAP; - saveInfo.fif = FIF_JPEG; - CallService(MS_IMG_SAVE, (WPARAM)&saveInfo, IMGL_WCHAR); - - if (hbmpPreview != resize.hBmp) - DeleteObject(hbmpPreview); - DeleteObject(resize.hBmp); - - CopyFile(ptszFileName, tszMyFile, FALSE); - - m_pConnection->sendSetPicture(szJid, sttFileToMem(ptszFileName), sttFileToMem(tszTempFile)); - return 0; -} - -INT_PTR WhatsAppProto::SetMyAvatar(WPARAM, LPARAM lParam) -{ - return InternalSetAvatar(NULL, m_szJid.c_str(), (const wchar_t*)lParam); -} diff --git a/protocols/WhatsApp/src/chat.cpp b/protocols/WhatsApp/src/chat.cpp deleted file mode 100644 index 24cdc5a177..0000000000 --- a/protocols/WhatsApp/src/chat.cpp +++ /dev/null @@ -1,522 +0,0 @@ -#include "stdafx.h" - -static const wchar_t *sttStatuses[] = { LPGENW("Members"), LPGENW("Owners") }; - -enum -{ - IDM_CANCEL, - - IDM_INVITE, IDM_LEAVE, IDM_TOPIC, - - IDM_AVATAR, IDM_KICK, - IDM_CPY_NICK, IDM_CPY_TOPIC, - IDM_ADD_RJID, IDM_CPY_RJID -}; - -///////////////////////////////////////////////////////////////////////////////////////// -// protocol menu handler - create a new group - -INT_PTR __cdecl WhatsAppProto::OnCreateGroup(WPARAM, LPARAM) -{ - ENTER_STRING es = { 0 }; - es.cbSize = sizeof(es); - es.type = ESF_MULTILINE; - es.caption = L"Enter a subject for new group"; - es.szModuleName = m_szModuleName; - if (EnterString(&es)) { - if (isOnline()) { - std::string groupName(T2Utf(es.ptszResult)); - m_pConnection->sendCreateGroupChat(groupName); - } - mir_free(es.ptszResult); - } - - return FALSE; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// handler to pass events from SRMM to WAConnection - -int WhatsAppProto::onGroupChatEvent(WPARAM, LPARAM lParam) -{ - GCHOOK *gch = (GCHOOK*)lParam; - if (mir_strcmp(gch->pszModule, m_szModuleName)) - return 0; - - std::string chat_id(T2Utf(gch->ptszID)); - WAChatInfo *pInfo = SafeGetChat(chat_id); - if (pInfo == nullptr) - return 0; - - switch (gch->iType) { - case GC_USER_LOGMENU: - ChatLogMenuHook(pInfo, gch); - break; - - case GC_USER_NICKLISTMENU: - NickListMenuHook(pInfo, gch); - break; - - case GC_USER_MESSAGE: - if (isOnline()) { - std::string msg(T2Utf(gch->ptszText)); - - try { - int msgId = GetSerial(); - time_t now = time(nullptr); - std::string id = Utilities::intToStr(now) + "-" + Utilities::intToStr(msgId); - - FMessage fmsg(chat_id, true, id); - fmsg.timestamp = now; - fmsg.data = msg; - m_pConnection->sendMessage(&fmsg); - - pInfo->m_unsentMsgs[id] = gch->ptszText; - } - CODE_BLOCK_CATCH_ALL - } - break; - - case GC_USER_PRIVMESS: - string jid = string(_T2A(gch->ptszUID)) + "@s.whatsapp.net"; - MCONTACT hContact = ContactIDToHContact(jid); - if (hContact == 0) { - hContact = AddToContactList(jid, (char*)_T2A(gch->ptszUID)); - setWord(hContact, "Status", ID_STATUS_ONLINE); - - db_set_b(hContact, "CList", "Hidden", 1); - setWString(hContact, "Nick", gch->ptszUID); - db_set_dw(hContact, "Ignore", "Mask1", 0); - } - CallService(MS_MSG_SENDMESSAGE, hContact, 0); - break; - } - - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// chat log menu event handler - -static gc_item sttLogListItems[] = -{ - { LPGENW("&Invite a user"), IDM_INVITE, MENU_ITEM }, - { nullptr, 0, MENU_SEPARATOR }, - { LPGENW("&Room options"), 0, MENU_NEWPOPUP }, - { LPGENW("View/change &topic"), IDM_TOPIC, MENU_POPUPITEM }, - { LPGENW("&Quit chat session"), IDM_LEAVE, MENU_POPUPITEM }, -#ifdef _DEBUG - { LPGENW("Set &avatar"), IDM_AVATAR, MENU_POPUPITEM }, // doesn't work, therefore commented out -#endif - { nullptr, 0, MENU_SEPARATOR }, - { LPGENW("Copy room &JID"), IDM_CPY_RJID, MENU_ITEM }, - { LPGENW("Copy room topic"), IDM_CPY_TOPIC, MENU_ITEM }, -}; - -void WhatsAppProto::ChatLogMenuHook(WAChatInfo *pInfo, struct GCHOOK *gch) -{ - switch (gch->dwData) { - case IDM_INVITE: - InviteChatUser(pInfo); - break; - - case IDM_TOPIC: - EditChatSubject(pInfo); - break; - - case IDM_CPY_RJID: - utils::copyText(pcli->hwndContactList, pInfo->tszJid); - break; - - case IDM_CPY_TOPIC: - utils::copyText(pcli->hwndContactList, pInfo->tszNick); - break; - - case IDM_LEAVE: - if (isOnline()) - m_pConnection->sendJoinLeaveGroup(_T2A(pInfo->tszJid), false); - break; - - case IDM_AVATAR: - SetChatAvatar(pInfo); - break; - } -} - -void WhatsAppProto::EditChatSubject(WAChatInfo *pInfo) -{ - CMStringW title(FORMAT, TranslateT("Set new subject for %s"), pInfo->tszNick); - ptrW tszOldValue(getWStringA(pInfo->hContact, WHATSAPP_KEY_NICK)); - - ENTER_STRING es = { 0 }; - es.cbSize = sizeof(es); - es.type = ESF_RICHEDIT; - es.szModuleName = m_szModuleName; - es.ptszInitVal = tszOldValue; - es.caption = title; - es.szDataPrefix = "setSubject_"; - if (EnterString(&es)) { - T2Utf gjid(pInfo->tszJid); - T2Utf gsubject(es.ptszResult); - m_pConnection->sendSetNewSubject(std::string(gjid), std::string(gsubject)); - mir_free(es.ptszResult); - } -} - -void WhatsAppProto::SetChatAvatar(WAChatInfo *pInfo) -{ - wchar_t tszFileName[MAX_PATH], filter[256]; - Bitmap_GetFilter(filter, _countof(filter)); - - OPENFILENAME ofn = { 0 }; - ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; - ofn.lpstrFilter = filter; - ofn.hwndOwner = nullptr; - ofn.lpstrFile = tszFileName; - ofn.nMaxFile = ofn.nMaxFileTitle = _countof(tszFileName); - ofn.Flags = OFN_HIDEREADONLY; - ofn.lpstrInitialDir = L"."; - ofn.lpstrDefExt = L""; - if (GetOpenFileName(&ofn)) - if (_waccess(tszFileName, 4) != -1) - InternalSetAvatar(pInfo->hContact, _T2A(pInfo->tszJid), tszFileName); -} - -///////////////////////////////////////////////////////////////////////////////////////// -// nicklist menu event handler - -static gc_item sttNickListItems[] = -{ - { LPGENW("&Add to roster"), IDM_ADD_RJID, MENU_POPUPITEM }, - { nullptr, 0, MENU_SEPARATOR }, - { LPGENW("&Kick"), IDM_KICK, MENU_ITEM }, - { nullptr, 0, MENU_SEPARATOR }, - { LPGENW("Copy &nickname"), IDM_CPY_NICK, MENU_ITEM }, - { LPGENW("Copy real &JID"), IDM_CPY_RJID, MENU_ITEM }, -}; - -void WhatsAppProto::NickListMenuHook(WAChatInfo *pInfo, struct GCHOOK *gch) -{ - switch (gch->dwData) { - case IDM_ADD_RJID: - AddChatUser(pInfo, gch->ptszUID); - break; - - case IDM_KICK: - KickChatUser(pInfo, gch->ptszUID); - break; - - case IDM_CPY_NICK: - utils::copyText(pcli->hwndContactList, ptrW(GetChatUserNick(std::string((char*)_T2A(gch->ptszUID))))); - break; - - case IDM_CPY_RJID: - utils::copyText(pcli->hwndContactList, gch->ptszUID); - break; - } -} - -void WhatsAppProto::AddChatUser(WAChatInfo*, const wchar_t *ptszJid) -{ - std::string jid((char*)_T2A(ptszJid)); - MCONTACT hContact = ContactIDToHContact(jid); - if (hContact && !db_get_b(hContact, "CList", "NotInList", 0)) - return; - - PROTOSEARCHRESULT psr = { 0 }; - psr.cbSize = sizeof(psr); - psr.flags = PSR_UNICODE; - psr.id.w = (wchar_t*)ptszJid; - psr.nick.w = GetChatUserNick(jid); - - ADDCONTACTSTRUCT acs = { 0 }; - acs.handleType = HANDLE_SEARCHRESULT; - acs.szProto = m_szModuleName; - acs.psr = &psr; - CallService(MS_ADDCONTACT_SHOW, (WPARAM)pcli->hwndContactList, (LPARAM)&acs); -} - -void WhatsAppProto::KickChatUser(WAChatInfo *pInfo, const wchar_t *ptszJid) -{ - if (!isOnline()) - return; - - std::string gjid((char*)_T2A(pInfo->tszJid)); - std::vector jids(1); - jids[0] = (char*)_T2A(ptszJid); - m_pConnection->sendRemoveParticipants(gjid, jids); -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Leave groupchat emulator for contact's deletion - -int WhatsAppProto::OnDeleteChat(WPARAM hContact, LPARAM) -{ - if (isChatRoom(hContact) && isOnline()) { - ptrW tszID(getWStringA(hContact, WHATSAPP_KEY_ID)); - if (tszID) - m_pConnection->sendJoinLeaveGroup(_T2A(tszID), false); - } - - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// handler to customize chat menus - -int WhatsAppProto::OnChatMenu(WPARAM, LPARAM lParam) -{ - GCMENUITEMS *gcmi = (GCMENUITEMS*)lParam; - if (gcmi == nullptr) - return 0; - - if (mir_strcmpi(gcmi->pszModule, m_szModuleName)) - return 0; - - if (gcmi->Type == MENU_ON_LOG) - Chat_AddMenuItems(gcmi->hMenu, _countof(sttLogListItems), sttLogListItems); - else if (gcmi->Type == MENU_ON_NICKLIST) - Chat_AddMenuItems(gcmi->hMenu, _countof(sttNickListItems), sttNickListItems); - - return 0; -} - -/////////////////////////////////////////////////////////////////////////////// -// chat helpers - -WAChatInfo* WhatsAppProto::InitChat(const std::string &jid, const std::string &nick) -{ - wchar_t *ptszJid = str2t(jid), *ptszNick = str2t(nick); - - WAChatInfo *pInfo = new WAChatInfo(ptszJid, ptszNick); - m_chats[jid] = pInfo; - - MCONTACT hOldContact = ContactIDToHContact(jid); - if (hOldContact && !isChatRoom(hOldContact)) { - delSetting(hOldContact, "ID"); - setByte(hOldContact, "ChatRoom", 1); - setString(hOldContact, "ChatRoomID", jid.c_str()); - } - - Chat_NewSession(GCW_CHATROOM, m_szModuleName, ptszJid, ptszNick); - - pInfo->hContact = (hOldContact != NULL) ? hOldContact : ContactIDToHContact(jid); - - for (int i = _countof(sttStatuses) - 1; i >= 0; i--) - Chat_AddGroup(m_szModuleName, ptszJid, TranslateW(sttStatuses[i])); - - Chat_Control(m_szModuleName, ptszJid, getBool(WHATSAPP_KEY_AUTORUNCHATS, true) ? SESSION_INITDONE : WINDOW_HIDDEN); - Chat_Control(m_szModuleName, ptszJid, SESSION_ONLINE); - - if (m_pConnection) - m_pConnection->sendGetParticipants(jid); - - return pInfo; -} - -wchar_t* WhatsAppProto::GetChatUserNick(const std::string &jid) -{ - wchar_t* tszNick; - if (m_szJid != jid) { - MCONTACT hContact = ContactIDToHContact(jid); - tszNick = (hContact == 0) ? utils::removeA(str2t(jid)) : mir_wstrdup(pcli->pfnGetContactDisplayName(hContact, 0)); - } - else tszNick = str2t(m_szNick); - - if (tszNick == nullptr) - tszNick = mir_wstrdup(TranslateT("Unknown user")); - return tszNick; -} - -WAChatInfo* WhatsAppProto::SafeGetChat(const std::string &jid) -{ - mir_cslock lck(m_csChats); - return m_chats[jid]; -} - -/////////////////////////////////////////////////////////////////////////////// -// WAGroupListener members - -void WhatsAppProto::onGroupInfo(const std::string &jid, const std::string &owner, const std::string &subject, const std::string &subject_owner, int time_subject, int) -{ - WAChatInfo *pInfo = SafeGetChat(jid); - if (pInfo == nullptr) { - pInfo = InitChat(jid, subject); - pInfo->bActive = true; - time_subject = 0; - } - else Chat_Control(m_szModuleName, pInfo->tszJid, SESSION_ONLINE); - - if (!subject.empty()) { - pInfo->tszOwner = str2t(owner); - - onGroupNewSubject(jid, subject_owner, subject, time_subject); - } -} - -void WhatsAppProto::onGroupMessage(const FMessage &pMsg) -{ - // we need to add a contact, so there's no difference at all - if (pMsg.media_wa_type == FMessage::WA_TYPE_CONTACT) { - onMessageForMe(pMsg); - return; - } - - WAChatInfo *pInfo = SafeGetChat(pMsg.key.remote_jid); - if (pInfo == nullptr) { - pInfo = InitChat(pMsg.key.remote_jid, ""); - pInfo->bActive = true; - } - - std::string msg(pMsg.data); - if (!pMsg.media_url.empty()) { - if (!msg.empty()) - msg.append("\n"); - msg += pMsg.media_url; - } - - ptrW tszText(str2t(msg)); - ptrW tszUID(str2t(pMsg.remote_resource)); - ptrW tszNick(GetChatUserNick(pMsg.remote_resource)); - - GCEVENT gce = { m_szModuleName, pInfo->tszJid, GC_EVENT_MESSAGE }; - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszUID = tszUID; - gce.ptszNick = tszNick; - gce.time = pMsg.timestamp; - gce.ptszText = tszText; - gce.bIsMe = m_szJid == pMsg.remote_resource; - Chat_Event(&gce); - - if (isOnline()) - m_pConnection->sendMessageReceived(pMsg); -} - -void WhatsAppProto::onGroupNewSubject(const std::string &gjid, const std::string &author, const std::string &newSubject, int ts) -{ - WAChatInfo *pInfo = SafeGetChat(gjid); - if (pInfo == nullptr) - return; - - ptrW tszText(str2t(newSubject)); - ptrW tszTextDb(getWStringA(pInfo->hContact, WHATSAPP_KEY_NICK)); - if (!mir_wstrcmp(tszText, tszTextDb)) // notify about subject change only if differs from the stored one - return; - - ptrW tszUID(str2t(author)); - ptrW tszNick(GetChatUserNick(author)); - - GCEVENT gce = { m_szModuleName, pInfo->tszJid, GC_EVENT_TOPIC }; - gce.dwFlags = GCEF_ADDTOLOG + ((ts == 0) ? GCEF_NOTNOTIFY : 0); - gce.ptszUID = tszUID; - gce.ptszNick = tszNick; - gce.time = ts; - gce.ptszText = tszText; - Chat_Event(&gce); - - setWString(pInfo->hContact, WHATSAPP_KEY_NICK, tszText); -} - -void WhatsAppProto::onGroupAddUser(const std::string &gjid, const std::string &ujid, int ts) -{ - WAChatInfo *pInfo = SafeGetChat(gjid); - if (pInfo == nullptr || !pInfo->bActive) - return; - - ptrW tszUID(str2t(ujid)); - ptrW tszNick(GetChatUserNick(ujid)); - - GCEVENT gce = { m_szModuleName, pInfo->tszJid, GC_EVENT_JOIN }; - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszUID = tszUID; - gce.ptszNick = tszNick; - gce.time = ts; - Chat_Event(&gce); -} - -void WhatsAppProto::onGroupRemoveUser(const std::string &gjid, const std::string &ujid, int ts) -{ - WAChatInfo *pInfo = SafeGetChat(gjid); - if (pInfo == nullptr) - return; - - ptrW tszUID(str2t(ujid)); - ptrW tszNick(GetChatUserNick(ujid)); - - GCEVENT gce = { m_szModuleName, pInfo->tszJid, GC_EVENT_PART }; - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszUID = tszUID; - gce.ptszNick = tszNick; - gce.time = ts; - Chat_Event(&gce); -} - -void WhatsAppProto::onLeaveGroup(const std::string &gjid) -{ - WAChatInfo *pInfo = SafeGetChat(gjid); - if (pInfo == nullptr) - return; - - Chat_Terminate(m_szModuleName, pInfo->tszJid); - - db_delete_contact(pInfo->hContact); - m_chats.erase((char*)_T2A(pInfo->tszJid)); -} - -void WhatsAppProto::onGetParticipants(const std::string &gjid, const std::vector &participants) -{ - mir_cslock lck(m_csChats); - - WAChatInfo *pInfo = m_chats[gjid]; - if (pInfo == nullptr) - return; - - pInfo->bActive = true; - for (size_t i = 0; i < participants.size(); i++) { - std::string curr = participants[i]; - - ptrW ujid(str2t(curr)), nick(GetChatUserNick(curr)); - bool bIsOwner = !mir_wstrcmp(ujid, pInfo->tszOwner); - - GCEVENT gce = { m_szModuleName, pInfo->tszJid, GC_EVENT_JOIN }; - gce.ptszNick = nick; - gce.ptszUID = utils::removeA(ujid); - gce.ptszStatus = (bIsOwner) ? L"Owners" : L"Members"; - Chat_Event(&gce); - } -} - -void WhatsAppProto::onGroupCreated(const std::string &gjid, const std::string &subject) -{ - WAChatInfo *pInfo = InitChat(gjid, subject); - pInfo->tszOwner = str2t(m_szJid); - - // also set new subject if it's present - if (!subject.empty()) - onGroupNewSubject(gjid, "Server", subject, 0); -} - -void WhatsAppProto::onGroupMessageReceived(const FMessage &msg) -{ - WAChatInfo *pInfo = SafeGetChat(msg.key.remote_jid); - if (pInfo == nullptr) - return; - - auto p = pInfo->m_unsentMsgs.find(msg.key.id); - if (p == pInfo->m_unsentMsgs.end()) - return; - - ptrW tszUID(str2t(m_szJid)); - ptrW tszNick(str2t(m_szNick)); - - GCEVENT gce = { m_szModuleName, pInfo->tszJid, GC_EVENT_MESSAGE }; - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszUID = tszUID; - gce.ptszNick = tszNick; - gce.time = time(nullptr); - gce.ptszText = p->second.c_str(); - gce.bIsMe = m_szJid == msg.remote_resource; - Chat_Event(&gce); - - pInfo->m_unsentMsgs.erase(p); -} diff --git a/protocols/WhatsApp/src/connection.cpp b/protocols/WhatsApp/src/connection.cpp deleted file mode 100644 index a7fa47958f..0000000000 --- a/protocols/WhatsApp/src/connection.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include "stdafx.h" - -void WhatsAppProto::stayConnectedLoop(void*) -{ - ptrA cc(getStringA(WHATSAPP_KEY_CC)); - if (mir_strlen(cc) == 0) { - NotifyEvent(m_tszUserName, TranslateT("Please enter a country code."), NULL, WHATSAPP_EVENT_CLIENT); - return; - } - - ptrA in(getStringA(WHATSAPP_KEY_LOGIN)); - if (mir_strlen(in) == 0) { - NotifyEvent(m_tszUserName, TranslateT("Please enter a phone number without country code."), NULL, WHATSAPP_EVENT_CLIENT); - return; - } - - m_szPhoneNumber = std::string(cc) + std::string(in); - m_szJid = m_szPhoneNumber + "@s.whatsapp.net"; - - ptrA szNick(getStringA(WHATSAPP_KEY_NICK)); - if (mir_strlen(szNick) == 0) { - NotifyEvent(m_tszUserName, TranslateT("Please enter a nickname."), NULL, WHATSAPP_EVENT_CLIENT); - return; - } - m_szNick = szNick; - - ptrA szPassword(getStringA(WHATSAPP_KEY_PASS)); - if (mir_strlen(szPassword) == 0) { - NotifyEvent(m_tszUserName, TranslateT("Please enter a password."), NULL, WHATSAPP_EVENT_CLIENT); - return; - } - - // ----------------------------- - Mutex writerMutex; - bool error = false; - - m_pSocket = nullptr; - - while (true) { - if (m_pConnection != nullptr) { - delete m_pConnection; - m_pConnection = nullptr; - } - if (m_pSocket != nullptr) { - delete m_pSocket; - m_pSocket = nullptr; - } - - if (m_iDesiredStatus == ID_STATUS_OFFLINE || error) { - debugLogA("Set status to offline"); - SetAllContactStatuses(ID_STATUS_OFFLINE, true); - ToggleStatusMenuItems(false); - int prevStatus = m_iStatus; - m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; - ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)prevStatus, m_iStatus); - break; - } - - debugLogA("Connecting..."); - - try { - unsigned passLen; - ptrA passBin((char*)mir_base64_decode(szPassword, &passLen)); - std::string password(passBin, passLen), resource = ACCOUNT_RESOURCE; - int portNumber; - if (getByte(WHATSAPP_KEY_SSL, 0)) - portNumber = 443, resource += "-443"; - else - portNumber = 5222, resource += "-5222"; - - m_pSocket = new WASocketConnection("c.whatsapp.net", portNumber); - m_pConnection = new WAConnection(m_szPhoneNumber, resource, &connMutex, &writerMutex, m_pSocket, this, this); - { - WALogin login(m_pConnection, password); - - m_Challenge = login.login(m_Challenge); - m_pConnection->setLogin(&login); - } - m_pConnection->nick = m_szNick; - if (m_iDesiredStatus != ID_STATUS_INVISIBLE) - m_pConnection->sendAvailableForChat(); - - debugLogA("Set status to online"); - m_iStatus = m_iDesiredStatus; - ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus); - ToggleStatusMenuItems(true); - - ForkThread(&WhatsAppProto::ProcessBuddyList, nullptr); - - // #TODO Move out of try block. Exception is expected on disconnect - while (true) { - m_tLastWriteTime = time(nullptr); - if (!m_pConnection->read()) - break; - } - debugLogA("Exit from read-loop"); - } - catch (WAException &e) { - debugLogA("Exception: %s", e.what()); - error = true; - } - catch (exception &e) { - debugLogA("Exception: %s", e.what()); - error = true; - } - catch (...) { - debugLogA("Unknown exception"); - error = true; - } - } - debugLogA("Break out from loop"); -} - -void WhatsAppProto::sentinelLoop(void*) -{ - while (WaitForSingleObjectEx(update_loop_lock_, 1000, true) == WAIT_TIMEOUT) { - if (m_iStatus != ID_STATUS_OFFLINE && m_pConnection != nullptr && m_iDesiredStatus == m_iStatus) { - // #TODO Quiet after pong or tree read? - int quietInterval = difftime(time(nullptr), m_tLastWriteTime); - if (quietInterval >= MAX_SILENT_INTERVAL) { - try { - debugLogA("send ping"); - m_tLastWriteTime = time(nullptr); - m_pConnection->sendPing(); - } - catch (exception &e) { - debugLogA("Exception: %s", e.what()); - } - } - } - } - ResetEvent(update_loop_lock_); - debugLogA("Exiting sentinel loop"); -} - -void WhatsAppProto::onPing(const std::string &id) -{ - if (isOnline()) { - try { - debugLogA("Sending pong with id %s", id.c_str()); - m_pConnection->sendPong(id); - } - CODE_BLOCK_CATCH_ALL - } -} diff --git a/protocols/WhatsApp/src/constants.h b/protocols/WhatsApp/src/constants.h deleted file mode 100644 index 963ae3c7ce..0000000000 --- a/protocols/WhatsApp/src/constants.h +++ /dev/null @@ -1,51 +0,0 @@ -#if !defined(CONSTANTS_H) -#define CONSTANTS_H - -// Version management -#define PRODUCT_NAME L"WhatsApp Protocol" - -// Limits -#define WHATSAPP_GROUP_NAME_LIMIT 420 - -// Defaults -#define DEFAULT_MAP_STATUSES 0 -#define DEFAULT_SYSTRAY_NOTIFY 0 - -#define DEFAULT_EVENT_NOTIFICATIONS_ENABLE 1 -#define DEFAULT_EVENT_FEEDS_ENABLE 1 -#define DEFAULT_EVENT_OTHER_ENABLE 1 -#define DEFAULT_EVENT_CLIENT_ENABLE 1 -#define DEFAULT_EVENT_COLBACK 0x00ffffff -#define DEFAULT_EVENT_COLTEXT 0x00000000 -#define DEFAULT_EVENT_TIMEOUT_TYPE 0 -#define DEFAULT_EVENT_TIMEOUT -1 - -// #TODO Move constants below to WhatsAPI++ - -// WhatsApp -#define WHATSAPP_TOKEN "PdA2DJyKoUrwLw1Bg6EIhzh502dF9noR9uFCllGk1478194306452" -#define WHATSAPP_LOGIN_SERVER "c.whatsapp.net" -#define ACCOUNT_USER_AGENT "WhatsApp/2.16.11 S40Version/14.26 Device/Nokia302" -#define ACCOUNT_URL_CODEREQUESTV2 "https://v.whatsapp.net/v2/code" -#define ACCOUNT_URL_REGISTERREQUESTV2 "https://v.whatsapp.net/v2/register" -#define ACCOUNT_URL_EXISTSV2 "https://v.whatsapp.net/v2/exist" - -// WhatsApp Samsung Galaxy S3 -#define ACCOUNT_RESOURCE "S40" - -#define WHATSAPP_RECV_MESSAGE 1 -#define WHATSAPP_SEND_MESSAGE 2 - -#define MAX_SILENT_INTERVAL 55 - -// Event flags -#define WHATSAPP_EVENT_CLIENT 0x10000000 // WhatsApp error or info message -#define WHATSAPP_EVENT_NOTIFICATION 0x40000000 // WhatsApp notification -#define WHATSAPP_EVENT_OTHER 0x80000000 // WhatsApp other event - friend requests/new messages - -#define IS_CHAT 1 - -#define REG_STATE_REQ_CODE 1 -#define REG_STATE_REG_CODE 2 - -#endif diff --git a/protocols/WhatsApp/src/contacts.cpp b/protocols/WhatsApp/src/contacts.cpp deleted file mode 100644 index 7674985311..0000000000 --- a/protocols/WhatsApp/src/contacts.cpp +++ /dev/null @@ -1,191 +0,0 @@ -#include "stdafx.h" - -MCONTACT WhatsAppProto::AddToContactList(const std::string &jid, const char *new_name) -{ - if (jid == m_szJid) - return NULL; - - // First, check if this contact exists - MCONTACT hContact = ContactIDToHContact(jid); - if (hContact) { - if (new_name != nullptr) { - DBVARIANT dbv; - string oldName; - if (db_get_utf(hContact, m_szModuleName, WHATSAPP_KEY_NICK, &dbv)) - oldName = jid.c_str(); - else { - oldName = dbv.pszVal; - db_free(&dbv); - } - - if (oldName.compare(string(new_name)) != 0) { - db_set_utf(hContact, m_szModuleName, WHATSAPP_KEY_NICK, new_name); - - CMStringW tmp(FORMAT, TranslateT("is now known as '%s'"), ptrW(mir_utf8decodeW(new_name))); - this->NotifyEvent(_A2T(oldName.c_str()), tmp, hContact, WHATSAPP_EVENT_OTHER); - } - } - - if (db_get_b(hContact, "CList", "Hidden", 0) > 0) - db_unset(hContact, "CList", "Hidden"); - - return hContact; - } - - // If not, make a new contact! - if ((hContact = db_add_contact()) == 0) - return INVALID_CONTACT_ID; - - Proto_AddToContact(hContact, m_szModuleName); - setString(hContact, "ID", jid.c_str()); - debugLogA("Added contact %s", jid.c_str()); - setString(hContact, "MirVer", "WhatsApp"); - db_unset(hContact, "CList", "MyHandle"); - db_set_b(hContact, "CList", "NotOnList", 1); - db_set_ws(hContact, "CList", "Group", m_tszDefaultGroup); - - if (new_name != nullptr) - db_set_utf(hContact, m_szModuleName, WHATSAPP_KEY_NICK, new_name); - - return hContact; -} - -MCONTACT WhatsAppProto::ContactIDToHContact(const std::string &phoneNumber) -{ - // Cache - std::map::iterator it = m_hContactByJid.find(phoneNumber); - if (it != m_hContactByJid.end()) - return it->second; - - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { - const char *id = isChatRoom(hContact) ? "ChatRoomID" : WHATSAPP_KEY_ID; - - ptrA szId(getStringA(hContact, id)); - if (!mir_strcmp(phoneNumber.c_str(), szId)) { - m_hContactByJid[phoneNumber] = hContact; - return hContact; - } - } - - return 0; -} - -void WhatsAppProto::SetAllContactStatuses(int status, bool reset_client) -{ - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { - if (reset_client) { - ptrW tszMirVer(getWStringA(hContact, "MirVer")); - if (mir_wstrcmp(tszMirVer, L"WhatsApp")) - setWString(hContact, "MirVer", L"WhatsApp"); - - db_set_ws(hContact, "CList", "StatusMsg", L""); - } - - if (getWord(hContact, "Status", ID_STATUS_OFFLINE) != status) - setWord(hContact, "Status", status); - } -} - -void WhatsAppProto::ProcessBuddyList(void*) -{ - // m_pConnection->setFlush(false); - - // for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { - // ptrA jid(getStringA(hContact, WHATSAPP_KEY_ID)); - // if (jid) - // m_pConnection->sendQueryLastOnline((char*)jid); - // } - - // m_pConnection->setFlush(true); - - try { - m_pConnection->sendGetGroups(); - } - CODE_BLOCK_CATCH_ALL -} - -void WhatsAppProto::onAvailable(const std::string ¶mString, bool paramBoolean, DWORD lastSeenTime) -{ - MCONTACT hContact = AddToContactList(paramString); - if (hContact != NULL) { - if (paramBoolean) { - setWord(hContact, "Status", ID_STATUS_ONLINE); - setDword(hContact, WHATSAPP_KEY_LAST_SEEN, time(nullptr)); - } - else { - setWord(hContact, "Status", ID_STATUS_OFFLINE); - if (lastSeenTime != 0) { - setDword(hContact, WHATSAPP_KEY_LAST_SEEN, lastSeenTime); - setByte(hContact, WHATSAPP_KEY_LAST_SEEN_DENIED, 0); - } - else - setByte(hContact, WHATSAPP_KEY_LAST_SEEN_DENIED, 1); - } - UpdateStatusMsg(hContact); - } -} - -void WhatsAppProto::UpdateStatusMsg(MCONTACT hContact) -{ - std::wstringstream ss; - DWORD lastSeen = getDword(hContact, WHATSAPP_KEY_LAST_SEEN, 0); - WORD status = getWord(hContact, "Status", ID_STATUS_OFFLINE); - bool denied = getBool(hContact, WHATSAPP_KEY_LAST_SEEN_DENIED, false); - if (lastSeen > 0) { - time_t ts = lastSeen; - wchar_t stzLastSeen[MAX_PATH]; - if (status == ID_STATUS_ONLINE) - wcsftime(stzLastSeen, _countof(stzLastSeen), TranslateT("Last online on %x at %X"), localtime(&ts)); - else - wcsftime(stzLastSeen, _countof(stzLastSeen), denied ? TranslateT("Denied: Last online on %x at %X") : TranslateT("Last seen on %x at %X"), localtime(&ts)); - - ss << stzLastSeen; - } - - db_set_ws(hContact, "CList", "StatusMsg", ss.str().c_str()); -} - -void WhatsAppProto::onContactChanged(const std::string&, bool) -{ -} - -void WhatsAppProto::onPictureChanged(const std::string &jid, const std::string&, bool) -{ - if (isOnline()) - m_pConnection->sendGetPicture(jid.c_str(), "image"); -} - -void WhatsAppProto::onSendGetPicture(const std::string &jid, const std::vector& data, const std::string &id) -{ - MCONTACT hContact = ContactIDToHContact(jid); - if (hContact) { - debugLogA("Updating avatar for jid %s", jid.c_str()); - - // Save avatar - std::wstring filename = GetAvatarFileName(hContact); - FILE *f = _wfopen(filename.c_str(), L"wb"); - size_t r = fwrite(std::string(data.begin(), data.end()).c_str(), 1, data.size(), f); - fclose(f); - - PROTO_AVATAR_INFORMATION ai = { 0 }; - ai.hContact = hContact; - ai.format = PA_FORMAT_JPEG; - wcsncpy_s(ai.filename, filename.c_str(), _TRUNCATE); - - int ackResult; - if (r > 0) { - setString(hContact, WHATSAPP_KEY_AVATAR_ID, id.c_str()); - ackResult = ACKRESULT_SUCCESS; - } - else { - ackResult = ACKRESULT_FAILED; - } - ProtoBroadcastAck(ai.hContact, ACKTYPE_AVATAR, ackResult, (HANDLE)&ai, 0); - } -} - -wchar_t* WhatsAppProto::GetContactDisplayName(const string& jid) -{ - MCONTACT hContact = ContactIDToHContact(jid); - return (hContact) ? pcli->pfnGetContactDisplayName(hContact, 0) : L"none"; -} diff --git a/protocols/WhatsApp/src/db.h b/protocols/WhatsApp/src/db.h deleted file mode 100644 index 22936d4f64..0000000000 --- a/protocols/WhatsApp/src/db.h +++ /dev/null @@ -1,33 +0,0 @@ -// DB keys -#define WHATSAPP_KEY_ID "ID" -#define WHATSAPP_KEY_LOGIN "Login" -#define WHATSAPP_KEY_CC "CountryCode" -#define WHATSAPP_KEY_NICK "Nick" -#define WHATSAPP_KEY_PASS "Password" -#define WHATSAPP_KEY_IDX "DeviceID" -#define WHATSAPP_KEY_MAP_STATUSES "MapStatuses" -#define WHATSAPP_KEY_LOGGING_ENABLE "LoggingEnable" -#define WHATSAPP_KEY_NAME "RealName" -#define WHATSAPP_KEY_LAST_SEEN "LastSeen" -#define WHATSAPP_KEY_LAST_SEEN_DENIED "LastSeenDenied" -#define WHATSAPP_KEY_AVATAR_ID "AvatarId" -#define WHATSAPP_KEY_SYSTRAY_NOTIFY "UseSystrayNotify" -#define WHATSAPP_KEY_DEF_GROUP "DefaultGroup" -#define WHATSAPP_KEY_REG_CODE "RegistrationCode" -#define WHATSAPP_KEY_SSL "UseSSL" -#define WHATSAPP_KEY_AUTORUNCHATS "AutoRunChats" -#define WHATSAPP_KEY_USE_REMOTE_TIME "UseRemoteTime" - -#define WHATSAPP_KEY_EVENT_CLIENT_ENABLE "EventClientEnable" -#define WHATSAPP_KEY_EVENT_OTHER_ENABLE "EventOtherEnable" - -#define WHATSAPP_KEY_EVENT_CLIENT_COLBACK "PopupClientColorBack" -#define WHATSAPP_KEY_EVENT_CLIENT_COLTEXT "PopupClientColorText" -#define WHATSAPP_KEY_EVENT_CLIENT_TIMEOUT "PopupClientTimeout" -#define WHATSAPP_KEY_EVENT_CLIENT_DEFAULT "PopupClientColorDefault" - -#define WHATSAPP_KEY_EVENT_OTHER_COLBACK "PopupOtherColorBack" -#define WHATSAPP_KEY_EVENT_OTHER_COLTEXT "PopupOtherColorText" -#define WHATSAPP_KEY_EVENT_OTHER_TIMEOUT "PopupOtherTimeout" -#define WHATSAPP_KEY_EVENT_OTHER_DEFAULT "PopupOtherColorDefault" - diff --git a/protocols/WhatsApp/src/definitions.h b/protocols/WhatsApp/src/definitions.h deleted file mode 100644 index 7f8f8a7222..0000000000 --- a/protocols/WhatsApp/src/definitions.h +++ /dev/null @@ -1,14 +0,0 @@ -#if !defined(DEFINITIONS_H) -#define DEFINITIONS_H - -#define FLAG_CONTAINS(x,y) ( ( x & y ) == y ) -#define REMOVE_FLAG(x,y) ( x = ( x & ~y )) - -#define CODE_BLOCK_CATCH_ALL \ - catch (WAException& e) { debugLogA("Exception: %s", e.what()); \ - } catch (exception& e) { debugLogA("Exception: %s", e.what()); \ - } catch (...) { debugLogA("Unknown exception"); } - -#define NIIF_INTERN_TCHAR NIIF_INTERN_UNICODE - -#endif \ No newline at end of file diff --git a/protocols/WhatsApp/src/dialogs.cpp b/protocols/WhatsApp/src/dialogs.cpp deleted file mode 100644 index 1083463564..0000000000 --- a/protocols/WhatsApp/src/dialogs.cpp +++ /dev/null @@ -1,235 +0,0 @@ -#include "stdafx.h" - -#define szAskSendSms LPGENW("An SMS with registration code will be sent to your mobile phone.\nNotice that you are not able to use the real WhatsApp and this plugin simultaneously!\nContinue?") -#define szAskCall LPGENW("A call with registration code will be made to your mobile phone.\nNotice that you are not able to use the real WhatsApp and this plugin simultaneously!\nContinue?") -#define szPasswordSet LPGENW("Your password has been set automatically. You can proceed with login now.") -#define szSpecifyCode LPGENW("Please correctly specify your registration code received by SMS/Voice.") - -class COptionsDlg : public CProtoDlgBase -{ - CCtrlEdit m_pw1, m_pw2, m_cc, m_login, m_nick, m_group; - CCtrlCheck m_ssl, m_autorun, m_remoteTime; - CCtrlButton m_requestSMS, m_requestVoice, m_register; - -public: - COptionsDlg(WhatsAppProto *pThis, int dlgId) : - CProtoDlgBase(pThis, dlgId, false), - m_cc(this, IDC_CC), - m_pw1(this, IDC_PW), - m_pw2(this, IDC_PW2), - m_ssl(this, IDC_SSL), - m_remoteTime(this, IDC_REMOTE_TIME), - m_nick(this, IDC_NICK), - m_group(this, IDC_DEFGROUP), - m_login(this, IDC_LOGIN), - m_autorun(this, IDC_AUTORUN), - m_requestSMS(this, IDC_BUTTON_REQUEST_SMS_CODE), - m_requestVoice(this, IDC_BUTTON_REQUEST_VOICE_CODE), - m_register(this, IDC_BUTTON_REGISTER) - { - CreateLink(m_ssl, WHATSAPP_KEY_SSL, DBVT_BYTE, false); - CreateLink(m_remoteTime, WHATSAPP_KEY_USE_REMOTE_TIME, DBVT_BYTE, false); - CreateLink(m_autorun, WHATSAPP_KEY_AUTORUNCHATS, DBVT_BYTE, true); - - CreateLink(m_cc, WHATSAPP_KEY_CC, L""); - CreateLink(m_nick, WHATSAPP_KEY_NICK, L""); - CreateLink(m_login, WHATSAPP_KEY_LOGIN, L""); - CreateLink(m_group, WHATSAPP_KEY_DEF_GROUP, L""); - - m_requestSMS.OnClick = Callback(this, &COptionsDlg::OnRequestSMSClick); - m_requestVoice.OnClick = Callback(this, &COptionsDlg::OnRequestVoiceClick); - m_register.OnClick = Callback(this, &COptionsDlg::OnRegisterClick); - } - - virtual void OnInitDialog() - { - m_pw1.SendMsg(EM_LIMITTEXT, 3, 0); - m_pw2.SendMsg(EM_LIMITTEXT, 3, 0); - bool bEnable = m_proto->getBool("CodeRequestDone", false); - m_pw1.Enable(bEnable); - m_pw2.Enable(bEnable); - } - - void OnRequestVoiceClick(CCtrlButton*) - { - if (IDYES != MessageBox(GetHwnd(), TranslateW(szAskCall), PRODUCT_NAME, MB_YESNO)) - return; - - ptrA cc(m_cc.GetTextA()), number(m_login.GetTextA()); - string password; - if (m_proto->Register(REG_STATE_REQ_CODE, string(cc), string(number), "voice", password)) { - if (!password.empty()) { - MessageBox(GetHwnd(), TranslateW(szPasswordSet), PRODUCT_NAME, MB_ICONWARNING); - m_proto->setString(WHATSAPP_KEY_PASS, password.c_str()); - } - else { - // unblock sms code entry field - m_pw1.Enable(); - m_pw2.Enable(); - m_proto->setByte("CodeRequestDone", 1); - } - } - } - - void OnRequestSMSClick(CCtrlButton*) - { - if (IDYES != MessageBox(GetHwnd(), TranslateW(szAskSendSms), PRODUCT_NAME, MB_YESNO)) - return; - - ptrA cc(m_cc.GetTextA()), number(m_login.GetTextA()); - string password; - if (m_proto->Register(REG_STATE_REQ_CODE, string(cc), string(number), "sms", password)) { - if (!password.empty()) { - MessageBox(GetHwnd(), TranslateW(szPasswordSet), PRODUCT_NAME, MB_ICONWARNING); - m_proto->setString(WHATSAPP_KEY_PASS, password.c_str()); - } - else { - // unblock sms code entry field - m_pw1.Enable(); - m_pw2.Enable(); - m_proto->setByte("CodeRequestDone", 1); - } - } - } - - void OnRegisterClick(CCtrlButton*) - { - if (GetWindowTextLength(m_pw1.GetHwnd()) != 3 || GetWindowTextLength(m_pw2.GetHwnd()) != 3) - MessageBox(GetHwnd(), TranslateW(szSpecifyCode), PRODUCT_NAME, MB_ICONEXCLAMATION); - else { - char code[10]; - GetWindowTextA(m_pw1.GetHwnd(), code, 4); - GetWindowTextA(m_pw2.GetHwnd(), code + 3, 4); - - string password; - ptrA cc(m_cc.GetTextA()), number(m_login.GetTextA()); - if (m_proto->Register(REG_STATE_REG_CODE, string(cc), string(number), string(code), password)) { - m_proto->setString(WHATSAPP_KEY_PASS, password.c_str()); - MessageBox(GetHwnd(), TranslateW(szPasswordSet), PRODUCT_NAME, MB_ICONWARNING); - } - } - m_proto->setByte("CodeRequestDone", 0); - } - - virtual void OnApply() - { - ptrW tszGroup(m_group.GetText()); - if (mir_wstrcmp(m_proto->m_tszDefaultGroup, tszGroup)) - m_proto->m_tszDefaultGroup = tszGroup.detach(); - - if (m_proto->isOnline()) - MessageBox(GetHwnd(), TranslateT("Changes will be applied after protocol restart"), m_proto->m_tszUserName, MB_OK); - } -}; - -INT_PTR WhatsAppProto::SvcCreateAccMgrUI(WPARAM, LPARAM lParam) -{ - COptionsDlg *pDlg = new COptionsDlg(this, IDD_ACCMGRUI); - pDlg->SetParent((HWND)lParam); - pDlg->Show(); - return (INT_PTR)pDlg->GetHwnd(); -} - -int WhatsAppProto::OnOptionsInit(WPARAM wParam, LPARAM) -{ - OPTIONSDIALOGPAGE odp = { 0 }; - odp.szTitle.w = m_tszUserName; - odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE | ODPF_DONTTRANSLATE; - odp.szGroup.w = LPGENW("Network"); - - odp.szTab.w = LPGENW("Account"); - odp.pDialog = new COptionsDlg(this, IDD_OPTIONS); - Options_AddPage(wParam, &odp); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Invite dialog - -class CInviteDialog : public CProtoDlgBase -{ - CCtrlClc m_clc; - CCtrlEdit m_entry; - CCtrlButton m_btnOk; - - void FilterList(CCtrlClc *) - { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { - char *proto = GetContactProto(hContact); - if (mir_strcmp(proto, m_proto->m_szModuleName) || m_proto->isChatRoom(hContact)) - if (HANDLE hItem = m_clc.FindContact(hContact)) - m_clc.DeleteItem(hItem); - } - } - - void ResetListOptions(CCtrlClc *) - { - m_clc.SetBkBitmap(0, nullptr); - m_clc.SetBkColor(GetSysColor(COLOR_WINDOW)); - m_clc.SetGreyoutFlags(0); - m_clc.SetLeftMargin(4); - m_clc.SetIndent(10); - m_clc.SetHideEmptyGroups(true); - m_clc.SetHideOfflineRoot(true); - for (int i = 0; i <= FONTID_MAX; i++) - m_clc.SetTextColor(i, GetSysColor(COLOR_WINDOWTEXT)); - } - -public: - CInviteDialog(WhatsAppProto *pThis) : - CProtoDlgBase(pThis, IDD_GROUPCHAT_INVITE, false), - m_clc(this, IDC_CLIST), - m_entry(this, IDC_NEWJID), - m_btnOk(this, IDOK) - { - m_btnOk.OnClick = Callback(this, &CInviteDialog::btnOk_OnClick); - m_clc.OnNewContact = - m_clc.OnListRebuilt = Callback(this, &CInviteDialog::FilterList); - m_clc.OnOptionsChanged = Callback(this, &CInviteDialog::ResetListOptions); - } - - void OnInitDialog() - { - SetWindowLongPtr(m_clc.GetHwnd(), GWL_STYLE, - GetWindowLongPtr(m_clc.GetHwnd(), GWL_STYLE) | CLS_CHECKBOXES | CLS_HIDEEMPTYGROUPS | CLS_USEGROUPS | CLS_GREYALTERNATE); - m_clc.SendMsg(CLM_SETEXSTYLE, CLS_EX_DISABLEDRAGDROP | CLS_EX_TRACKSELECT, 0); - - ResetListOptions(&m_clc); - FilterList(&m_clc); - } - - void btnOk_OnClick(CCtrlButton*) - { - m_proto->m_szInviteJids.clear(); - - // invite users from clist - for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) { - if (m_proto->isChatRoom(hContact)) - continue; - - if (HANDLE hItem = m_clc.FindContact(hContact)) { - if (m_clc.GetCheck(hItem)) { - ptrA jid(m_proto->getStringA(hContact, "ID")); - if (jid != NULL) - m_proto->m_szInviteJids.push_back((char*)jid); - } - } - } - - ptrA tszText(m_entry.GetTextA()); - if (tszText != NULL) - m_proto->m_szInviteJids.push_back(string(tszText)); - } -}; - -void WhatsAppProto::InviteChatUser(WAChatInfo *pInfo) -{ - CInviteDialog dlg(this); - if (!dlg.DoModal()) - return; - - if (isOnline()) { - m_pConnection->sendAddParticipants((char*)_T2A(pInfo->tszJid), m_szInviteJids); - m_szInviteJids.clear(); - } -} diff --git a/protocols/WhatsApp/src/dialogs.h b/protocols/WhatsApp/src/dialogs.h deleted file mode 100644 index bb244c6834..0000000000 --- a/protocols/WhatsApp/src/dialogs.h +++ /dev/null @@ -1,6 +0,0 @@ -#if !defined(DIALOGS_H) -#define DIALOGS_H - -INT_PTR CALLBACK InviteDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); - -#endif \ No newline at end of file diff --git a/protocols/WhatsApp/src/entities.h b/protocols/WhatsApp/src/entities.h deleted file mode 100644 index 7ed362990e..0000000000 --- a/protocols/WhatsApp/src/entities.h +++ /dev/null @@ -1,34 +0,0 @@ -#if !defined(ENTITIES_H) -#define ENTITIES_H - -struct send_direct -{ - send_direct(MCONTACT hContact, const std::string &msg, HANDLE msgid) : - hContact(hContact), msg(msg), msgid(msgid) - {} - - MCONTACT hContact; - std::string msg; - HANDLE msgid; -}; - -struct input_box -{ - wstring text; - wstring title; - wstring defaultValue; - int limit; - - void(__cdecl WhatsAppProto::*thread)(void*); - WhatsAppProto *proto; - void *userData; -}; - -struct input_box_ret // has to be deleted by input-box handler -{ - void *userData; // has to be deleted by input-box handler - char *value; // mir_free() has to be called by input-box handler -}; - - -#endif // ENTITIES_H \ No newline at end of file diff --git a/protocols/WhatsApp/src/main.cpp b/protocols/WhatsApp/src/main.cpp deleted file mode 100644 index 84d29e07be..0000000000 --- a/protocols/WhatsApp/src/main.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "stdafx.h" -#include "version.h" - -CLIST_INTERFACE *pcli; -int hLangpack; - -HINSTANCE g_hInstance; - -PLUGININFOEX pluginInfo = { - sizeof(PLUGININFOEX), - __PLUGIN_NAME, - PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), - __DESCRIPTION, - __AUTHOR, - __AUTHOREMAIL, - __COPYRIGHT, - __AUTHORWEB, - UNICODE_AWARE, //not transient - // {4f1ff7fa-4d75-44b9-93b0-2ced2e4f9e3e} - { 0x4f1ff7fa, 0x4d75, 0x44b9, { 0x93, 0xb0, 0x2c, 0xed, 0x2e, 0x4f, 0x9e, 0x3e } } - -}; - -///////////////////////////////////////////////////////////////////////////// -// Protocol instances - -static int compare_protos(const WhatsAppProto *p1, const WhatsAppProto *p2) -{ - return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName); -} - -OBJLIST g_Instances(1, compare_protos); - -DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID) -{ - g_hInstance = hInstance; - return TRUE; -} - -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) -{ - return &pluginInfo; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Interface information - -extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; - -///////////////////////////////////////////////////////////////////////////////////////// -// Load - -static PROTO_INTERFACE* protoInit(const char *proto_name, const wchar_t *username) -{ - WhatsAppProto *proto = new WhatsAppProto(proto_name, username); - g_Instances.insert(proto); - return proto; -} - -static int protoUninit(PROTO_INTERFACE* proto) -{ - g_Instances.remove((WhatsAppProto*)proto); - return EXIT_SUCCESS; -} - -extern "C" int __declspec(dllexport) Load(void) -{ - mir_getLP(&pluginInfo); - pcli = Clist_GetInterface(); - - PROTOCOLDESCRIPTOR pd = { 0 }; - pd.cbSize = sizeof(pd); - pd.szName = "WhatsApp"; - pd.type = PROTOTYPE_PROTOCOL; - pd.fnInit = protoInit; - pd.fnUninit = protoUninit; - Proto_RegisterModule(&pd); - - InitIcons(); - //InitContactMenus(); - - // Init native User-Agent - MFileVersion v; - Miranda_GetFileVersion(&v); - - WAConnection::globalInit(); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Unload - -extern "C" int __declspec(dllexport) Unload(void) -{ - g_Instances.destroy(); - - WASocketConnection::quitNetwork(); - - return 0; -} diff --git a/protocols/WhatsApp/src/media.cpp b/protocols/WhatsApp/src/media.cpp deleted file mode 100644 index f2f1fb3afe..0000000000 --- a/protocols/WhatsApp/src/media.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "stdafx.h" - -HANDLE WhatsAppProto::SendFile(MCONTACT hContact, const wchar_t* desc, wchar_t **ppszFiles) { - if (!isOnline()) - return nullptr; - - ptrA jid(getStringA(hContact, "ID")); - if (jid == NULL) - return nullptr; - - // input validation - char *name = mir_utf8encodeW(ppszFiles[0]); - string mime = MediaUploader::getMimeFromExtension(split(name, '.')[1]); - if (mime.empty()) { - mir_free(name); - return nullptr; - } - - // get file size - FILE *hFile = _wfopen(ppszFiles[0], L"rb"); - if (hFile == nullptr) { - debugLogA(__FUNCTION__": cannot open file %s", ppszFiles[0]); - mir_free(name); - return nullptr; - } - _fseeki64(hFile, 0, SEEK_END); - uint64_t fileSize = _ftelli64(hFile); - fclose(hFile); - - // get filetype from mimeType - int fileType = FMessage::getMessage_WA_Type(split(mime, '/')[0]); - - // check max file sizes - switch (fileType) { - case FMessage::WA_TYPE_IMAGE: - if (fileSize >= 5 * 1024 * 1024) { - mir_free(name); - return nullptr; - } - break; - case FMessage::WA_TYPE_AUDIO: - if (fileSize >= 10 * 1024 * 1024) { - mir_free(name); - return nullptr; - } - break; - case FMessage::WA_TYPE_VIDEO: - if (fileSize >= 20 * 1024 * 1024) { - mir_free(name); - return nullptr; - } - break; - default: - mir_free(name); - return nullptr; - } - - int msgId = GetSerial(); - time_t now = time(nullptr); - std::string msgid = Utilities::intToStr(now) + "-" + Utilities::intToStr(msgId); - FMessage * fmsg = new FMessage(std::string(jid), true, msgid); - fmsg->media_url = name; - fmsg->media_size = fileSize; - fmsg->media_wa_type = fileType; - fmsg->data = mir_utf8encodeW(desc); - - // calculate file hash - unsigned char hash[MIR_SHA256_HASH_SIZE]; - SHA256_CONTEXT sha256; - mir_sha256_init(&sha256); - - FILE *fd = _wfopen(ppszFiles[0], L"rb"); - int read = 0; - do { - char buf[1024]; - read = (int)fread(buf, 1, 1024, fd); - mir_sha256_write(&sha256, buf, read); - } while (read > 0); - fclose(fd); - - mir_sha256_final(&sha256, hash); - fmsg->media_name = mir_base64_encode((BYTE*)hash,sizeof(hash)); - - // request media upload url - m_pConnection->sendMessage(fmsg); - return (HANDLE)fmsg; // TODO what to return here to make the upload shown complete when done and how to handle errors? -} \ No newline at end of file diff --git a/protocols/WhatsApp/src/messages.cpp b/protocols/WhatsApp/src/messages.cpp deleted file mode 100644 index 0d1ebff87e..0000000000 --- a/protocols/WhatsApp/src/messages.cpp +++ /dev/null @@ -1,137 +0,0 @@ -#include "stdafx.h" - -int WhatsAppProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre) -{ - CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hContact, (LPARAM)PROTOTYPE_CONTACTTYPING_OFF); - - return Proto_RecvMessage(hContact, pre); -} - -void WhatsAppProto::onMessageForMe(const FMessage &pMsg) -{ - // someone sent us a contact. launch contact addition dialog - if (pMsg.media_wa_type == FMessage::WA_TYPE_CONTACT) { - MCONTACT hContact = AddToContactList(pMsg.media_url, pMsg.media_name.c_str()); - - ADDCONTACTSTRUCT acs = { 0 }; - acs.handleType = HANDLE_CONTACT; - acs.hContact = hContact; - acs.szProto = m_szModuleName; - CallServiceSync(MS_ADDCONTACT_SHOW, 0, (LPARAM)&acs); - } - else { - std::string msg(pMsg.data); - if (!pMsg.media_url.empty()) { - if (!msg.empty()) - msg.append("\n"); - msg += pMsg.media_url; - } - - MCONTACT hContact = this->AddToContactList(pMsg.key.remote_jid, pMsg.notifyname.c_str()); - - PROTORECVEVENT recv = { 0 }; - recv.szMessage = const_cast(msg.c_str()); - if (getByte(WHATSAPP_KEY_USE_REMOTE_TIME, 0)) - recv.timestamp = pMsg.timestamp; - else - recv.timestamp = time(nullptr); - - ProtoChainRecvMsg(hContact, &recv); - } - - if (isOnline()) - m_pConnection->sendMessageReceived(pMsg); -} - -int WhatsAppProto::SendMsg(MCONTACT hContact, int, const char *msg) -{ - ptrA jid(getStringA(hContact, "ID")); - if (jid == NULL) - return 0; - - if (m_pConnection == nullptr) { - debugLogA("No connection"); - return 0; - } - - int msgId = GetSerial(); - try { - time_t now = time(nullptr); - std::string id = Utilities::intToStr(now) + "-" + Utilities::intToStr(msgId); - FMessage fmsg(std::string(jid), true, id); - fmsg.timestamp = now; - fmsg.data = msg; - - m_pConnection->sendMessage(&fmsg); - utils::setStatusMessage(hContact, nullptr); - } - catch (exception &e) { - debugLogA("exception: %s", e.what()); - ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)msgId, (LPARAM)e.what()); - } - catch (...) { - debugLogA("unknown exception"); - ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)msgId, (LPARAM)"Failed sending message"); - } - - return msgId; -} - -void WhatsAppProto::onIsTyping(const std::string ¶mString, bool paramBoolean) -{ - MCONTACT hContact = this->AddToContactList(paramString); - if (hContact != NULL) { - CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hContact, (LPARAM) - paramBoolean ? PROTOTYPE_CONTACTTYPING_INFINITE : PROTOTYPE_CONTACTTYPING_OFF); - } -} - -int WhatsAppProto::UserIsTyping(MCONTACT hContact, int type) -{ - if (hContact && isOnline()) { - ptrA jid(getStringA(hContact, WHATSAPP_KEY_ID)); - if (jid && isOnline()) { - if (type == PROTOTYPE_SELFTYPING_ON) - m_pConnection->sendComposing((char*)jid); - else - m_pConnection->sendPaused((char*)jid); - } - } - - return 0; -} - -void WhatsAppProto::onMessageStatusUpdate(const FMessage &fmsg) -{ - MCONTACT hContact = this->ContactIDToHContact(fmsg.key.remote_jid); - if (hContact == 0) - return; - - if (isChatRoom(hContact)) { - onGroupMessageReceived(fmsg); - return; - } - - const wchar_t *ptszBy; - switch (fmsg.status) { - case FMessage::STATUS_RECEIVED_BY_SERVER: ptszBy = TranslateT("server"); break; - case FMessage::STATUS_RECEIVED_BY_TARGET: ptszBy = pcli->pfnGetContactDisplayName(hContact, 0); break; - default: - return; - } - - size_t delim = fmsg.key.id.find('-'); - if (delim == string::npos) - return; - - int msgId = atoi(fmsg.key.id.substr(delim+1).c_str()); - - if (fmsg.status == FMessage::STATUS_RECEIVED_BY_SERVER) - ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)msgId, 0); - - time_t ts = atol(fmsg.key.id.substr(0, delim).c_str()); - - wchar_t ttime[64]; - wcsftime(ttime, _countof(ttime), L"%X", localtime(&ts)); - utils::setStatusMessage(hContact, CMStringW(FORMAT, TranslateT("Message received: %s by %s"), ttime, ptszBy)); -} diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp deleted file mode 100644 index 6b048b33a4..0000000000 --- a/protocols/WhatsApp/src/proto.cpp +++ /dev/null @@ -1,438 +0,0 @@ -#include "stdafx.h" - -#include "WhatsAPI++/WARegister.h" - -struct SearchParam -{ - SearchParam(const wchar_t *_jid, LONG _id) : - jid(_jid), id(_id) - {} - - std::wstring jid; - LONG id; -}; - -WhatsAppProto::WhatsAppProto(const char *proto_name, const wchar_t *username) - : PROTO(proto_name, username), - m_tszDefaultGroup(getWStringA(WHATSAPP_KEY_DEF_GROUP)) -{ - update_loop_lock_ = CreateEvent(nullptr, false, false, nullptr); - - db_set_resident(m_szModuleName, "StatusMsg"); - - CreateProtoService(PS_CREATEACCMGRUI, &WhatsAppProto::SvcCreateAccMgrUI); - - CreateProtoService(PS_GETAVATARINFO, &WhatsAppProto::GetAvatarInfo); - CreateProtoService(PS_GETAVATARCAPS, &WhatsAppProto::GetAvatarCaps); - CreateProtoService(PS_GETMYAVATAR, &WhatsAppProto::GetMyAvatar); - CreateProtoService(PS_SETMYAVATAR, &WhatsAppProto::SetMyAvatar); - - HookProtoEvent(ME_DB_CONTACT_DELETED, &WhatsAppProto::OnDeleteChat); - HookProtoEvent(ME_OPT_INITIALISE, &WhatsAppProto::OnOptionsInit); - HookProtoEvent(ME_CLIST_PREBUILDSTATUSMENU, &WhatsAppProto::OnBuildStatusMenu); - - // Create standard network connection - wchar_t descr[512]; - mir_snwprintf(descr, TranslateT("%s server connection"), m_tszUserName); - - NETLIBUSER nlu = {}; - nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_UNICODE; - nlu.szSettingsModule = m_szModuleName; - nlu.szDescriptiveName.w = descr; - m_hNetlibUser = Netlib_RegisterUser(&nlu); - if (m_hNetlibUser == nullptr) { - wchar_t error[200]; - mir_snwprintf(error, TranslateT("Unable to initialize Netlib for %s."), m_tszUserName); - MessageBox(nullptr, error, L"Miranda NG", MB_OK | MB_ICONERROR); - } - - WASocketConnection::initNetwork(m_hNetlibUser); - - m_tszAvatarFolder = std::wstring(VARSW(L"%miranda_avatarcache%")) + L"\\" + m_tszUserName; - DWORD dwAttributes = GetFileAttributes(m_tszAvatarFolder.c_str()); - if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) - CreateDirectoryTreeW(m_tszAvatarFolder.c_str()); - - if (m_tszDefaultGroup == NULL) - m_tszDefaultGroup = mir_wstrdup(L"WhatsApp"); - Clist_GroupCreate(0, m_tszDefaultGroup); - - SetAllContactStatuses(ID_STATUS_OFFLINE, true); -} - -WhatsAppProto::~WhatsAppProto() -{ - CloseHandle(update_loop_lock_); -} - -int WhatsAppProto::OnEvent(PROTOEVENTTYPE evType, WPARAM, LPARAM) -{ - switch (evType) { - case EV_PROTO_ONMENU: - InitMenu(); - break; - - case EV_PROTO_ONLOAD: - // Register group chat - GCREGISTER gcr = {}; - gcr.dwFlags = GC_TYPNOTIF | GC_CHANMGR; - gcr.ptszDispName = m_tszUserName; - gcr.pszModule = m_szModuleName; - Chat_Register(&gcr); - - HookProtoEvent(ME_GC_EVENT, &WhatsAppProto::onGroupChatEvent); - HookProtoEvent(ME_GC_BUILDMENU, &WhatsAppProto::OnChatMenu); - HookProtoEvent(ME_USERINFO_INITIALISE, &WhatsAppProto::OnUserInfo); - break; - } - return TRUE; -} - -DWORD_PTR WhatsAppProto::GetCaps(int type, MCONTACT) -{ - switch (type) { - case PFLAGNUM_1: - return PF1_IM | PF1_FILESEND | PF1_CHAT | PF1_BASICSEARCH | PF1_ADDSEARCHRES | PF1_MODEMSGRECV; - case PFLAGNUM_2: - return PF2_ONLINE | PF2_INVISIBLE; - case PFLAGNUM_3: - return 0; - case PFLAGNUM_4: - return PF4_NOCUSTOMAUTH | PF4_FORCEADDED | PF4_NOAUTHDENYREASON | PF4_IMSENDOFFLINE | PF4_OFFLINEFILES | PF4_SUPPORTTYPING | PF4_AVATARS; - case PFLAGNUM_5: - return 0; - case PFLAG_UNIQUEIDTEXT: - return (DWORD_PTR)"WhatsApp ID"; - case PFLAG_UNIQUEIDSETTING: - return (DWORD_PTR)"ID"; - } - return 0; -} - -int WhatsAppProto::SetStatus(int new_status) -{ - if (m_iDesiredStatus == new_status) - return 0; - - int oldStatus = m_iStatus; - debugLogA("===== Beginning SetStatus process"); - - // Routing statuses not supported by WhatsApp - switch (new_status) { - case ID_STATUS_INVISIBLE: - case ID_STATUS_OFFLINE: - m_iDesiredStatus = new_status; - break; - - case ID_STATUS_IDLE: - default: - m_iDesiredStatus = ID_STATUS_INVISIBLE; - if (getByte(WHATSAPP_KEY_MAP_STATUSES, DEFAULT_MAP_STATUSES)) - break; - case ID_STATUS_ONLINE: - case ID_STATUS_FREECHAT: - m_iDesiredStatus = ID_STATUS_ONLINE; - break; - } - - if (m_iDesiredStatus == ID_STATUS_OFFLINE) { - if (m_pSocket != nullptr) { - SetEvent(update_loop_lock_); - m_pSocket->forceShutdown(); - debugLogA("Forced shutdown"); - } - - m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; - ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); - } - else if (m_pSocket == nullptr && !IsStatusConnecting(m_iStatus)) { - m_iStatus = ID_STATUS_CONNECTING; - ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); - - ResetEvent(update_loop_lock_); - ForkThread(&WhatsAppProto::sentinelLoop, nullptr); - ForkThread(&WhatsAppProto::stayConnectedLoop, nullptr); - } - else if (m_pConnection != nullptr) { - if (m_iDesiredStatus == ID_STATUS_ONLINE) { - m_pConnection->sendAvailableForChat(); - m_iStatus = ID_STATUS_ONLINE; - ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); - } - else if (m_iStatus == ID_STATUS_ONLINE && m_iDesiredStatus == ID_STATUS_INVISIBLE) { - m_pConnection->sendClose(); - m_iStatus = ID_STATUS_INVISIBLE; - SetAllContactStatuses(ID_STATUS_OFFLINE, true); - ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); - } - } - else ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); - - return 0; -} - -MCONTACT WhatsAppProto::AddToList(int flags, PROTOSEARCHRESULT *psr) -{ - if (psr->id.w == nullptr) - return NULL; - - std::string phone(T2Utf(psr->id.w)); - std::string jid(phone + "@s.whatsapp.net"); - - MCONTACT hContact = AddToContactList(jid, phone.c_str()); - if (!(flags & PALF_TEMPORARY)) - db_unset(hContact, "CList", "NotOnList"); - - m_pConnection->sendPresenceSubscriptionRequest(jid.c_str()); - return hContact; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -void WhatsAppProto::SearchAckThread(void *targ) -{ - Sleep(100); - - SearchParam *param = (SearchParam*)targ; - PROTOSEARCHRESULT psr = { 0 }; - psr.cbSize = sizeof(psr); - psr.flags = PSR_UNICODE; - psr.nick.w = psr.firstName.w = psr.lastName.w = L""; - psr.id.w = (wchar_t*)param->jid.c_str(); - - ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)param->id, (LPARAM)&psr); - ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)param->id, 0); - - delete param; -} - -HANDLE WhatsAppProto::SearchBasic(const wchar_t* id) -{ - if (isOffline()) - return nullptr; - - // fake - we always accept search - SearchParam *param = new SearchParam(id, GetSerial()); - ForkThread(&WhatsAppProto::SearchAckThread, param); - return (HANDLE)param->id; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -static NETLIBHTTPHEADER s_registerHeaders[] = -{ - { "User-Agent", ACCOUNT_USER_AGENT }, - { "Accept", "text/json" }, - { "Content-Type", "application/x-www-form-urlencoded" } -}; - -bool WhatsAppProto::Register(int state, const string &cc, const string &number, const string &code, string &ret) -{ - string idx; - DBVARIANT dbv; - - if (g_hNetlibUser == nullptr) { - NotifyEvent(m_tszUserName, TranslateT("Network connection error."), NULL, WHATSAPP_EVENT_CLIENT); - return false; - } - - if (!getString(WHATSAPP_KEY_IDX, &dbv)) { - idx = dbv.pszVal; - db_free(&dbv); - } - - if (idx.empty()) { - std::stringstream tm; - tm << time(nullptr); - BYTE idxBuf[16]; - utils::md5string(tm.str(), idxBuf); - idx = std::string((const char*)idxBuf, 16); - setString(WHATSAPP_KEY_IDX, idx.c_str()); - } - - CMStringA url = WARegister::RequestCodeUrl(cc + number, code); - if (url.IsEmpty()) - return false; - - NETLIBHTTPREQUEST nlhr = { sizeof(NETLIBHTTPREQUEST) }; - nlhr.requestType = REQUEST_POST; - nlhr.szUrl = url.GetBuffer(); - nlhr.headers = s_registerHeaders; - nlhr.headersCount = _countof(s_registerHeaders); - nlhr.flags = NLHRF_HTTP11 | NLHRF_SSL; - - NETLIBHTTPREQUEST* pnlhr = Netlib_HttpTransaction(g_hNetlibUser, &nlhr); - - const wchar_t *ptszTitle = TranslateT("Registration"); - if (pnlhr == nullptr) { - NotifyEvent(ptszTitle, TranslateT("Registration failed. Invalid server response."), NULL, WHATSAPP_EVENT_CLIENT); - return false; - } - - debugLogA("Server response: %s", pnlhr->pData); - - JSONNode resp = JSONNode::parse(pnlhr->pData); - if (!resp) { - NotifyEvent(ptszTitle, TranslateT("Registration failed. Invalid server response."), NULL, WHATSAPP_EVENT_CLIENT); - return false; - } - - // Status = fail - std::string status = resp["status"].as_string(); - if (status == "fail") { - std::string reason = resp["reason"].as_string(); - if (reason == "stale") - NotifyEvent(ptszTitle, TranslateT("Registration failed due to stale code. Please request a new code"), NULL, WHATSAPP_EVENT_CLIENT); - else { - CMStringW tmp(FORMAT, TranslateT("Registration failed. Reason: %s"), _A2T(reason.c_str())); - NotifyEvent(ptszTitle, tmp, NULL, WHATSAPP_EVENT_CLIENT); - } - - const JSONNode &tmpVal = resp["retry_after"]; - if (tmpVal) { - CMStringW tmp(FORMAT, TranslateT("Please try again in %i seconds"), tmpVal.as_int()); - NotifyEvent(ptszTitle, tmp, NULL, WHATSAPP_EVENT_OTHER); - } - return false; - } - - // Request code - if (state == REG_STATE_REQ_CODE) { - std::string pw = resp["pw"].as_string(); - if (!pw.empty()) - ret = pw; - else if (status == "sent") - NotifyEvent(ptszTitle, TranslateT("Registration code has been sent to your phone."), NULL, WHATSAPP_EVENT_OTHER); - return true; - } - - // Register - if (state == REG_STATE_REG_CODE) { - std::string pw = resp["pw"].as_string(); - if (!pw.empty()) { - ret = pw; - return true; - } - NotifyEvent(ptszTitle, TranslateT("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT); - } - - return false; -} - -////////////////////////////////////////////////////////////////////////////// -// EVENTS - -int WhatsAppProto::OnUserInfo(WPARAM, LPARAM hContact) -{ - ptrA jid(getStringA(hContact, WHATSAPP_KEY_ID)); - if (jid && isOnline()) { - m_pConnection->sendGetPicture((char*)jid, "image"); - m_pConnection->sendPresenceSubscriptionRequest((char*)jid); - } - - return 0; -} - -void WhatsAppProto::RequestFriendship(MCONTACT hContact) -{ - if (hContact == NULL || isOffline()) - return; - - ptrA jid(getStringA(hContact, WHATSAPP_KEY_ID)); - if (jid) { - m_pConnection->sendPresenceSubscriptionRequest((char*)jid); - } -} - -LRESULT CALLBACK PopupDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) { - case WM_COMMAND: - // After a click, destroy popup - PUDeletePopup(hwnd); - break; - - case WM_CONTEXTMENU: - PUDeletePopup(hwnd); - break; - - case UM_FREEPLUGINDATA: - // After close, free - mir_free(PUGetPluginData(hwnd)); - return FALSE; - } - - return DefWindowProc(hwnd, message, wParam, lParam); -}; - -void WhatsAppProto::NotifyEvent(const string& title, const string& info, MCONTACT contact, DWORD flags, wchar_t* url) -{ - wchar_t *rawTitle = mir_a2u_cp(title.c_str(), CP_UTF8); - wchar_t *rawInfo = mir_a2u_cp(info.c_str(), CP_UTF8); - NotifyEvent(rawTitle, rawInfo, contact, flags, url); - mir_free(rawTitle); - mir_free(rawInfo); -} - -void WhatsAppProto::NotifyEvent(const wchar_t *title, const wchar_t *info, MCONTACT contact, DWORD flags, wchar_t* szUrl) -{ - int ret, timeout = 0; - COLORREF colorBack = 0, colorText = 0; - - switch (flags) { - case WHATSAPP_EVENT_CLIENT: - if (!getByte(WHATSAPP_KEY_EVENT_CLIENT_ENABLE, DEFAULT_EVENT_CLIENT_ENABLE)) - goto exit; - if (!getByte(WHATSAPP_KEY_EVENT_CLIENT_DEFAULT, 0)) { - colorBack = getDword(WHATSAPP_KEY_EVENT_CLIENT_COLBACK, DEFAULT_EVENT_COLBACK); - colorText = getDword(WHATSAPP_KEY_EVENT_CLIENT_COLTEXT, DEFAULT_EVENT_COLTEXT); - } - timeout = getDword(WHATSAPP_KEY_EVENT_CLIENT_TIMEOUT, 0); - flags |= NIIF_WARNING; - break; - - case WHATSAPP_EVENT_OTHER: - if (!getByte(WHATSAPP_KEY_EVENT_OTHER_ENABLE, DEFAULT_EVENT_OTHER_ENABLE)) - goto exit; - if (!getByte(WHATSAPP_KEY_EVENT_OTHER_DEFAULT, 0)) { - colorBack = getDword(WHATSAPP_KEY_EVENT_OTHER_COLBACK, DEFAULT_EVENT_COLBACK); - colorText = getDword(WHATSAPP_KEY_EVENT_OTHER_COLTEXT, DEFAULT_EVENT_COLTEXT); - } - timeout = getDword(WHATSAPP_KEY_EVENT_OTHER_TIMEOUT, -1); - Skin_PlaySound("OtherEvent"); - flags |= NIIF_INFO; - break; - } - - if (!getByte(WHATSAPP_KEY_SYSTRAY_NOTIFY, DEFAULT_SYSTRAY_NOTIFY)) { - if (ServiceExists(MS_POPUP_ADDPOPUP)) { - POPUPDATAT pd; - pd.colorBack = colorBack; - pd.colorText = colorText; - pd.iSeconds = timeout; - pd.lchContact = contact; - pd.lchIcon = IcoLib_GetIconByHandle(m_hProtoIcon); // TODO: Icon test - pd.PluginData = szUrl; - pd.PluginWindowProc = PopupDlgProc; - mir_wstrcpy(pd.lptzContactName, title); - mir_wstrcpy(pd.lptzText, info); - ret = PUAddPopupT(&pd); - - if (ret == 0) - return; - } - } - else { - int niif_flags = flags; - REMOVE_FLAG(niif_flags, WHATSAPP_EVENT_CLIENT | WHATSAPP_EVENT_NOTIFICATION | WHATSAPP_EVENT_OTHER); - if (!Clist_TrayNotifyW(m_szModuleName, title, info, niif_flags, 1000 * timeout)) - goto exit; - } - - if (FLAG_CONTAINS(flags, WHATSAPP_EVENT_CLIENT)) - MessageBox(nullptr, info, title, MB_OK | MB_ICONINFORMATION); - -exit: - if (szUrl != nullptr) - mir_free(szUrl); -} diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h deleted file mode 100644 index f885369ddf..0000000000 --- a/protocols/WhatsApp/src/proto.h +++ /dev/null @@ -1,203 +0,0 @@ -#if !defined(PROTO_H) -#define PROTO_H - -class WASocketConnection; - -#include "WhatsAPI++/WAConnection.h" - -struct WAChatInfo -{ - WAChatInfo(wchar_t *_jid, wchar_t *_nick) : - tszJid(_jid), tszNick(_nick) - { - bActive = false; - } - - map m_unsentMsgs; - ptrW tszJid, tszNick, tszOwner; - bool bActive; - - MCONTACT hContact; -}; - -class WhatsAppProto : public PROTO, public WAListener, public WAGroupListener -{ -public: - WhatsAppProto(const char *proto_name, const wchar_t *username); - ~WhatsAppProto(); - - inline bool isOnline() const - { return (m_pConnection != NULL); - } - - inline bool isOffline() const - { return (m_iStatus == ID_STATUS_OFFLINE); - } - - inline bool isInvisible() const - { return (m_iStatus == ID_STATUS_INVISIBLE); - } - - // PROTO_INTERFACE /////////////////////////////////////////////////////////////////// - - virtual MCONTACT __cdecl AddToList(int flags, PROTOSEARCHRESULT* psr); - - virtual DWORD_PTR __cdecl GetCaps(int type, MCONTACT hContact = NULL); - - virtual HANDLE __cdecl SearchBasic(const wchar_t* id); - - virtual int __cdecl RecvMsg(MCONTACT hContact, PROTORECVEVENT*); - - virtual int __cdecl SendMsg(MCONTACT hContact, int flags, const char* msg); - - virtual HANDLE __cdecl SendFile(MCONTACT hContact, const wchar_t*, wchar_t **ppszFiles); - - virtual int __cdecl SetStatus(int iNewStatus); - - virtual int __cdecl UserIsTyping(MCONTACT hContact, int type); - - virtual int __cdecl OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam); - - // Services ////////////////////////////////////////////////////////////////////////// - - INT_PTR __cdecl SvcCreateAccMgrUI(WPARAM, LPARAM); - - // Events //////////////////////////////////////////////////////////////////////////// - - int __cdecl OnOptionsInit(WPARAM, LPARAM); - int __cdecl OnUserInfo(WPARAM, LPARAM); - int __cdecl OnBuildStatusMenu(WPARAM, LPARAM); - - // Worker Threads //////////////////////////////////////////////////////////////////// - - void __cdecl stayConnectedLoop(void*); - void __cdecl sentinelLoop(void*); - - // Processing Threads //////////////////////////////////////////////////////////////// - - void __cdecl ProcessBuddyList(void*); - void __cdecl SearchAckThread(void*); - - // Contacts handling ///////////////////////////////////////////////////////////////// - - MCONTACT AddToContactList(const std::string &jid, const char *new_name = NULL); - - MCONTACT ContactIDToHContact(const std::string&); - void SetAllContactStatuses(int status, bool reset_client = false); - void UpdateStatusMsg(MCONTACT hContact); - wchar_t* GetContactDisplayName(const string &jid); - void RequestFriendship(MCONTACT hContact); - - // Group chats /////////////////////////////////////////////////////////////////////// - - std::vector m_szInviteJids; - map m_chats; - mir_cs m_csChats; - ptrW m_tszDefaultGroup; - - void ChatLogMenuHook(WAChatInfo *pInfo, GCHOOK *gch); - void NickListMenuHook(WAChatInfo *pInfo, GCHOOK *gch); - - void AddChatUser(WAChatInfo *pInfo, const wchar_t *ptszJid); - void EditChatSubject(WAChatInfo *pInfo); - void InviteChatUser(WAChatInfo *pInfo); - void KickChatUser(WAChatInfo *pInfo, const wchar_t *ptszJid); - wchar_t* GetChatUserNick(const std::string &jid); - void SetChatAvatar(WAChatInfo *pInfo); - - void onGroupMessageReceived(const FMessage &fmsg); - - WAChatInfo* InitChat(const std::string &jidjid, const std::string &nick); - WAChatInfo* SafeGetChat(const std::string &jid); - - int __cdecl onGroupChatEvent(WPARAM, LPARAM); - int __cdecl OnDeleteChat(WPARAM, LPARAM); - int __cdecl OnChatMenu(WPARAM, LPARAM); - INT_PTR __cdecl OnCreateGroup(WPARAM, LPARAM); - - // Registration ////////////////////////////////////////////////////////////////////// - - bool Register(int state, const string &cc, const string &number, const string &code, string &password); - -private: - // Helpers ////////////////////////////////////////////////////////////////////////// - - LONG m_iSerial; - __forceinline LONG GetSerial() - { return ::_InterlockedIncrement(&m_iSerial); - } - - void ToggleStatusMenuItems(bool bEnable); - - /// Avatars ////////////////////////////////////////////////////////////////////////// - - std::wstring GetAvatarFileName(MCONTACT); - std::wstring m_tszAvatarFolder; - - INT_PTR __cdecl GetAvatarInfo(WPARAM, LPARAM); - INT_PTR __cdecl GetAvatarCaps(WPARAM, LPARAM); - INT_PTR __cdecl GetMyAvatar(WPARAM, LPARAM); - INT_PTR __cdecl SetMyAvatar(WPARAM, LPARAM); - - int InternalSetAvatar(MCONTACT hContact, const char *szJid, const wchar_t *ptszFileName); - - // Private data ////////////////////////////////////////////////////////////////////// - - void InitMenu(); - HGENMENU m_hMenuCreateGroup; - - HANDLE update_loop_lock_; - - WASocketConnection *m_pSocket; - WAConnection *m_pConnection; - Mutex connMutex; - time_t m_tLastWriteTime; - - std::vector m_Challenge; - std::string m_szPhoneNumber; - std::string m_szJid, m_szNick; - std::map m_hContactByJid; - map> isMemberByGroupContact; - -protected: - // WAListener methods //////////////////////////////////////////////////////////////// - virtual void onMessageForMe(const FMessage ¶mFMessage); - virtual void onMessageStatusUpdate(const FMessage ¶mFMessage); - virtual void onMessageError(const FMessage&, int) { } - virtual void onPing(const std::string &id) throw (WAException); - virtual void onPingResponseReceived() { } - virtual void onAvailable(const std::string ¶mString, bool paramBoolean, DWORD lastSeenTime); - virtual void onClientConfigReceived(const std::string&) { } - virtual void onIsTyping(const std::string ¶mString, bool paramBoolean); - virtual void onAccountChange(int, time_t) { } - virtual void onPrivacyBlockListAdd(const std::string&) { } - virtual void onPrivacyBlockListClear() { } - virtual void onDirty(const std::map&) { } - virtual void onDirtyResponse(int) { } - virtual void onRelayRequest(const std::string&, int, const std::string&) { } - virtual void onSendGetPicture(const std::string &jid, const std::vector& data, const std::string &id); - virtual void onPictureChanged(const std::string &jid, const std::string &id, bool set); - virtual void onContactChanged(const std::string &jid, bool added); - virtual void onDeleteAccount(bool) {} - - // WAGroupListener methods /////////////////////////////////////////////////////////// - virtual void onGroupAddUser(const std::string &gjid, const std::string &ujid, int ts); - virtual void onGroupRemoveUser(const std::string &gjid, const std::string &ujid, int ts); - virtual void onGroupNewSubject(const std::string &from, const std::string &author, const std::string &newSubject, int ts); - virtual void onGroupMessage(const FMessage ¶mFMessage); - virtual void onServerProperties(std::map*) { } - virtual void onGroupCreated(const std::string &gjid, const std::string &nick); - virtual void onGroupInfo(const std::string &jid, const std::string &owner, const std::string &subject, const std::string &subject_owner, int time_subject, int time_created); - virtual void onSetSubject(const std::string&) { } - virtual void onAddGroupParticipants(const std::string&, const std::vector&, int) { } - virtual void onRemoveGroupParticipants(const std::string&, const std::vector&, int) { } - virtual void onGetParticipants(const std::string &gjid, const std::vector &participants); - virtual void onLeaveGroup(const std::string ¶mString); - - // Information providing ///////////////////////////////////////////////////////////// - - void NotifyEvent(const wchar_t *title, const wchar_t *info, MCONTACT contact, DWORD flags, wchar_t *url = NULL); - void NotifyEvent(const std::string &title, const std::string &info, MCONTACT contact, DWORD flags, wchar_t *url = NULL); -}; - -#endif diff --git a/protocols/WhatsApp/src/resource.h b/protocols/WhatsApp/src/resource.h deleted file mode 100644 index 61d5bf626d..0000000000 --- a/protocols/WhatsApp/src/resource.h +++ /dev/null @@ -1,43 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by ..\res\whatsapp.rc -// -#define IDD_INPUTBOX 102 -#define IDR_REGISTERUTILITY 103 -#define IDD_ACCMGRUI 104 -#define IDD_GROUPCHAT_INVITE 105 -#define IDD_OPTIONS 106 -#define IDI_WHATSAPP 203 -#define IDI_ADD_GROUP 206 -#define IDI_RENAME_GROUP 208 -#define IDC_CLIST 1001 -#define IDC_NEWJID 1002 -#define IDC_LOGIN 1003 -#define IDC_PW 1004 -#define IDC_SSL 1005 -#define IDC_NICK 1006 -#define IDC_BUTTON_REQUEST_SMS_CODE 1007 -#define IDC_BUTTON_REGISTER 1008 -#define IDC_CC 1009 -#define IDC_VALUE 1010 -#define IDC_SSL2 1010 -#define IDC_CANCEL 1011 -#define IDC_OK 1012 -#define IDC_PW2 1013 -#define IDC_TEXT 1014 -#define IDC_INVITE 1015 -#define IDC_AUTORUN 1016 -#define IDC_DEFGROUP 1017 -#define IDC_REMOTE_TIME 1018 -#define IDC_BUTTON_REQUEST_VOICE_CODE 1019 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 107 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1020 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/protocols/WhatsApp/src/stdafx.cxx b/protocols/WhatsApp/src/stdafx.cxx deleted file mode 100644 index 43acd6332d..0000000000 --- a/protocols/WhatsApp/src/stdafx.cxx +++ /dev/null @@ -1,8 +0,0 @@ -// stdafx.cpp : Quelldatei, die nur die Standard-Includes einbindet. -// WhatsAPI++.pch ist der vorkompilierte Header. -// stdafx.obj enthдlt die vorkompilierten Typinformationen. - -#include "stdafx.h" - -// TODO: Auf zusдtzliche Header verweisen, die in STDAFX.H -// und nicht in dieser Datei erforderlich sind. diff --git a/protocols/WhatsApp/src/stdafx.h b/protocols/WhatsApp/src/stdafx.h deleted file mode 100755 index 4714359264..0000000000 --- a/protocols/WhatsApp/src/stdafx.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - -WhatsApp plugin for Miranda NG -Copyright © 2013-14 Uli Hecht - -*/ - -#pragma once - -//#pragma warning(push) -//#pragma warning(disable:4312) -#pragma warning(disable:4996) -#pragma warning(disable:4290) - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../../libs/libaxolotl/src/signal_protocol.h" - -#include "constants.h" -#include "utils.h" -#include "db.h" -#include "resource.h" -#include "theme.h" -#include "definitions.h" -#include "WASocketConnection.h" -#include "proto.h" -#include "dialogs.h" -#include "entities.h" - -#if defined _DEBUG -#include -#include -#endif - -//#pragma warning(pop) - -extern HINSTANCE g_hInstance; -extern std::string g_strUserAgent; -extern DWORD g_mirandaVersion; -extern HNETLIBUSER g_hNetlibUser; diff --git a/protocols/WhatsApp/src/theme.cpp b/protocols/WhatsApp/src/theme.cpp deleted file mode 100644 index e280a623ec..0000000000 --- a/protocols/WhatsApp/src/theme.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "stdafx.h" - -extern OBJLIST g_Instances; - -static IconItem icons[] = -{ - { LPGEN("WhatsApp icon"), "whatsApp", IDI_WHATSAPP }, - { LPGEN("Create chat group"), "createGroup", IDI_ADD_GROUP } -}; - -void InitIcons(void) -{ - Icon_Register(g_hInstance, "Protocols/WhatsApp", icons, _countof(icons), "WhatsApp"); -} - -HANDLE GetIconHandle(const char* name) -{ - for (size_t i = 0; i < _countof(icons); i++) - if (mir_strcmp(icons[i].szName, name) == 0) - return icons[i].hIcolib; - - return nullptr; -} - -char* GetIconDescription(const char* name) -{ - for (size_t i = 0; i < _countof(icons); i++) - if (mir_strcmp(icons[i].szName, name) == 0) - return icons[i].szDescr; - - return ""; -} - -// Helper functions -static WhatsAppProto* GetInstanceByHContact(MCONTACT hContact) -{ - char *proto = GetContactProto(hContact); - if (!proto) - return nullptr; - - for (int i = 0; i < g_Instances.getCount(); i++) - if (!mir_strcmp(proto, g_Instances[i].m_szModuleName)) - return &g_Instances[i]; - - return nullptr; -} - -void WhatsAppProto::InitMenu() -{ - CMenuItem mi; - mi.flags = (isOnline() ? 0 : CMIF_GRAYED); - mi.position = 201001; - - mi.pszService = "/CreateGroup"; - CreateProtoService(mi.pszService, &WhatsAppProto::OnCreateGroup); - mi.root = Menu_GetProtocolRoot(this); - mi.name.a = LPGEN("Create group"); - mi.hIcolibItem = GetIconHandle("createGroup"); - m_hMenuCreateGroup = Menu_AddProtoMenuItem(&mi, m_szModuleName); -} - -int WhatsAppProto::OnBuildStatusMenu(WPARAM, LPARAM) -{ - ToggleStatusMenuItems(isOnline()); - return 0; -} - -void WhatsAppProto::ToggleStatusMenuItems(bool bEnable) -{ - Menu_EnableItem(m_hMenuCreateGroup, bEnable); -} diff --git a/protocols/WhatsApp/src/theme.h b/protocols/WhatsApp/src/theme.h deleted file mode 100644 index 2e67c54365..0000000000 --- a/protocols/WhatsApp/src/theme.h +++ /dev/null @@ -1,20 +0,0 @@ -#if !defined(THEME_H) -#define THEME_H - -void InitIcons(void); -HANDLE GetIconHandle(const char *name); - -//void InitContactMenus(void); - -/* Contact menu item indexes */ -enum -{ - CMI_ADD_CONTACT_TO_GROUP, - CMI_REMOVE_CONTACT_FROM_GROUP, - CMI_LEAVE_GROUP, - CMI_REMOVE_GROUP, - CMI_CHANGE_GROUP_SUBJECT, - CMITEMS_COUNT -}; - -#endif \ No newline at end of file diff --git a/protocols/WhatsApp/src/utils.cpp b/protocols/WhatsApp/src/utils.cpp deleted file mode 100644 index d335133912..0000000000 --- a/protocols/WhatsApp/src/utils.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "stdafx.h" - -wchar_t* utils::removeA(wchar_t *str) -{ - if (str == nullptr) - return nullptr; - - wchar_t *p = wcschr(str, '@'); - if (p) *p = 0; - return str; -} - -void utils::copyText(HWND hwnd, const wchar_t *text) -{ - if (!hwnd || !text) return; - - if (!OpenClipboard(hwnd)) - return; - - EmptyClipboard(); - HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t)*(mir_wstrlen(text) + 1)); - mir_wstrcpy((wchar_t*)GlobalLock(hMem), text); - GlobalUnlock(hMem); - SetClipboardData(CF_UNICODETEXT, hMem); - CloseClipboard(); -} - -std::string getLastErrorMsg() -{ - LPVOID lpMsgBuf; - DWORD dw = WSAGetLastError(); // retrieve the system error message for the last-error code - - FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, - dw, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&lpMsgBuf, - 0, nullptr); - - std::string ret((LPSTR)lpMsgBuf); - LocalFree(lpMsgBuf); - return ret; -} - -void utils::setStatusMessage(MCONTACT hContact, const wchar_t *ptszMessage) -{ - if (ptszMessage != nullptr) - Srmm_SetStatusText(hContact, ptszMessage, Skin_LoadIcon(SKINICON_EVENT_MESSAGE)); - else - Srmm_SetStatusText(hContact, nullptr); -} - -BYTE* utils::md5string(const BYTE *data, int size, BYTE *digest) -{ - mir_md5_state_t md5_state; - mir_md5_init(&md5_state); - mir_md5_append(&md5_state, data, size); - mir_md5_finish(&md5_state, digest); - return digest; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// external stubs for WhatsAPI++ - -std::string base64_encode(void* pData, size_t len) -{ - return (char*)ptrA(mir_base64_encode((BYTE*)pData, (unsigned)len)); -} - -void md5_string(const std::string &data, BYTE digest[16]) -{ - utils::md5string(data, digest); -} - -std::vector &split(const std::string &s, char delim, std::vector &elems) { - std::stringstream ss(s); - std::string item; - while (std::getline(ss, item, delim)) { - if (item.length() > 0) { - elems.push_back(item); - } - } - return elems; -} - -std::vector split(const std::string &s, char delim) { - std::vector elems; - split(s, delim, elems); - return elems; -} diff --git a/protocols/WhatsApp/src/utils.h b/protocols/WhatsApp/src/utils.h deleted file mode 100644 index eddd9fab45..0000000000 --- a/protocols/WhatsApp/src/utils.h +++ /dev/null @@ -1,52 +0,0 @@ -#if !defined(WHATS_NG_UTILS_H) -#define WHATS_NG_UTILS_H - -#include "WhatsAPI++/IMutex.h" - -class Mutex : public IMutex -{ - mir_cs m_cs; - -public: - Mutex() {} - virtual ~Mutex() {} - - virtual void lock() - { - CRITICAL_SECTION &cs = m_cs; - ::EnterCriticalSection(&cs); - } - - virtual void unlock() - { - CRITICAL_SECTION &cs = m_cs; - ::LeaveCriticalSection(&cs); - } -}; - - -std::string getLastErrorMsg(); - -__forceinline wchar_t* str2t(const std::string &str) -{ return mir_utf8decodeW(str.c_str()); -} - -std::vector split(const std::string &s, char delim); -std::vector &split(const std::string &s, char delim, std::vector &elems); - -namespace utils -{ - wchar_t* removeA(wchar_t *str); - void copyText(HWND hwnd, const wchar_t *text); - - void setStatusMessage(MCONTACT hContact, const wchar_t *ptszMessage); - - BYTE* md5string(const BYTE*, int, BYTE* digest); - __forceinline BYTE* md5string(const std::string &str, BYTE* digest) - { - return md5string((BYTE*)str.data(), (int)str.length(), digest); - } -}; - - -#endif \ No newline at end of file diff --git a/protocols/WhatsApp/src/version.h b/protocols/WhatsApp/src/version.h deleted file mode 100644 index 3d788dc995..0000000000 --- a/protocols/WhatsApp/src/version.h +++ /dev/null @@ -1,14 +0,0 @@ -#define __MAJOR_VERSION 0 -#define __MINOR_VERSION 1 -#define __RELEASE_NUM 3 -#define __BUILD_NUM 3 - -#include - -#define __PLUGIN_NAME "WhatsApp protocol" -#define __FILENAME "WhatsApp.dll" -#define __DESCRIPTION "WhatsApp protocol support for Miranda NG." -#define __AUTHOR "Uli Hecht" -#define __AUTHOREMAIL "" -#define __AUTHORWEB "https://miranda-ng.org/p/WhatsApp/" -#define __COPYRIGHT "© 2013-14 Uli Hecht, 2015-17 Miranda NG Team" -- cgit v1.2.3