From 06ca08ab518ba90cc82db8cc9ac27b5a25340510 Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Mon, 21 Sep 2015 19:06:14 +0000 Subject: WhatsApp: - Request password with Voice (patch by Cassio) - minor fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@15418 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 10 ++++- protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp | 7 ++-- protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp | 8 ++-- protocols/WhatsApp/src/constants.h | 3 -- protocols/WhatsApp/src/dialogs.cpp | 43 +++++++++++++++++----- protocols/WhatsApp/src/media.cpp | 18 +++++++-- protocols/WhatsApp/src/proto.cpp | 6 ++- protocols/WhatsApp/src/resource.h | 9 +++-- 8 files changed, 74 insertions(+), 30 deletions(-) (limited to 'protocols/WhatsApp/src') diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp index 524bb80f2a..e6640b0156 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp @@ -875,7 +875,15 @@ void WAConnection::processUploadResponse(ProtocolTreeNode * node, FMessage * mes fileName = tempfileName.substr(index); } else { - string json = MediaUploader::pushfile(node->getChild("media")->getAttributeValue("url"),message, this->user); + 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; diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp index 5184dab86e..efcb9551fb 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp @@ -108,9 +108,8 @@ std::vector WALogin::readFeaturesUntilChallengeOrSuccess() if (ProtocolTreeNode::tagEquals(root, "stream:features")) { m_pConnection->supports_receipt_acks = root->getChild("receipt_acks") != NULL; delete root; - continue; } - if (ProtocolTreeNode::tagEquals(root, "challenge")) { + else if (ProtocolTreeNode::tagEquals(root, "challenge")) { std::vector challengedata(root->data->begin(), root->data->end()); delete root; this->sendResponse(challengedata); @@ -119,12 +118,14 @@ std::vector WALogin::readFeaturesUntilChallengeOrSuccess() m_pConnection->logData("Read success"); return std::vector(data.begin(), data.end()); } - if (ProtocolTreeNode::tagEquals(root, "success")) { + else if (ProtocolTreeNode::tagEquals(root, "success")) { std::vector ret(root->data->begin(), root->data->end()); this->parseSuccessNode(root); delete root; return ret; } + else + delete root; } throw WAException("fell out of loop in readFeaturesAndChallenge", WAException::CORRUPT_STREAM_EX, 0); } diff --git a/protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp b/protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp index 476bb9ced4..2bf0cb8b83 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp @@ -27,7 +27,6 @@ std::string WAToken::GenerateToken(const string &number) ///////////////////////////////////////////////////////////////////////////////////////// // Account registration - CMStringA WARegister::RequestCodeUrl(const std::string &phoneNumber, const std::string &code) { try { @@ -38,11 +37,11 @@ CMStringA WARegister::RequestCodeUrl(const std::string &phoneNumber, const std:: const char *n = pn.Number.c_str(); - if (!code.empty()) + 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=sms&mcc=%03d&mnc=%03d&token=%s&id=%s&lg=%s&lc=%s", - pn.countryCode, n, pn.countryCode, n, pn.mcc, pn.mnc, token.c_str(), id.c_str(), pn.ISO639, pn.ISO3166); + 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 (...) {} @@ -50,6 +49,7 @@ CMStringA WARegister::RequestCodeUrl(const std::string &phoneNumber, const std:: return CMStringA(); } + std::string WARegister::GenerateIdentity(const std::string &phone) { std::string id = phone; diff --git a/protocols/WhatsApp/src/constants.h b/protocols/WhatsApp/src/constants.h index 7ea5bd115c..655d484b1a 100644 --- a/protocols/WhatsApp/src/constants.h +++ b/protocols/WhatsApp/src/constants.h @@ -25,11 +25,8 @@ // WhatsApp #define WHATSAPP_LOGIN_SERVER "c.whatsapp.net" #define ACCOUNT_USER_AGENT "WhatsApp/2.12.89 S40Version/14.26 Device/Nokia302" -#define ACCOUNT_URL_CODEREQUEST "https://r.whatsapp.net/v1/code.php" #define ACCOUNT_URL_CODEREQUESTV2 "https://v.whatsapp.net/v2/code" -#define ACCOUNT_URL_REGISTERREQUEST "https://r.whatsapp.net/v1/register.php" #define ACCOUNT_URL_REGISTERREQUESTV2 "https://v.whatsapp.net/v2/register" -#define ACCOUNT_URL_UPLOADREQUEST "https://mms.whatsapp.net/client/iphone/upload.php" #define ACCOUNT_URL_EXISTSV2 "https://v.whatsapp.net/v2/exist" // WhatsApp Nokia 302 S40 diff --git a/protocols/WhatsApp/src/dialogs.cpp b/protocols/WhatsApp/src/dialogs.cpp index aba0493fda..6bc7889e06 100644 --- a/protocols/WhatsApp/src/dialogs.cpp +++ b/protocols/WhatsApp/src/dialogs.cpp @@ -1,13 +1,15 @@ #include "common.h" #define szAskSendSms LPGEN("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 szPasswordSet LPGEN("Your password has been set automatically. You can proceed with login now") +#define szAskCall LPGEN("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 LPGEN("Your password has been set automatically. You can proceed with login now.") +#define szSpecifyCode LPGEN("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_request, m_register; + CCtrlButton m_requestSMS, m_requestVoice, m_register; public: COptionsDlg(WhatsAppProto *pThis, int dlgId) : @@ -21,7 +23,8 @@ public: m_group(this, IDC_DEFGROUP), m_login(this, IDC_LOGIN), m_autorun(this, IDC_AUTORUN), - m_request(this, IDC_BUTTON_REQUEST_CODE), + 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); @@ -33,7 +36,8 @@ public: CreateLink(m_login, WHATSAPP_KEY_LOGIN, _T("")); CreateLink(m_group, WHATSAPP_KEY_DEF_GROUP, _T("")); - m_request.OnClick = Callback(this, &COptionsDlg::OnRequestClick); + m_requestSMS.OnClick = Callback(this, &COptionsDlg::OnRequestSMSClick); + m_requestVoice.OnClick = Callback(this, &COptionsDlg::OnRequestVoiceClick); m_register.OnClick = Callback(this, &COptionsDlg::OnRegisterClick); } @@ -46,14 +50,14 @@ public: m_pw2.Enable(bEnable); } - void OnRequestClick(CCtrlButton*) + void OnRequestVoiceClick(CCtrlButton*) { - if (IDYES != MessageBox(GetHwnd(), TranslateT(szAskSendSms), PRODUCT_NAME, MB_YESNO)) + if (IDYES != MessageBox(GetHwnd(), TranslateT(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), string(), password)) { + if (m_proto->Register(REG_STATE_REQ_CODE, string(cc), string(number), "voice", password)) { if (!password.empty()) { MessageBox(GetHwnd(), TranslateT(szPasswordSet), PRODUCT_NAME, MB_ICONWARNING); m_proto->setString(WHATSAPP_KEY_PASS, password.c_str()); @@ -67,10 +71,31 @@ public: } } + void OnRequestSMSClick(CCtrlButton*) + { + if (IDYES != MessageBox(GetHwnd(), TranslateT(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(), TranslateT(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(), TranslateT("Please correctly specify your registration code received by SMS"), PRODUCT_NAME, MB_ICONEXCLAMATION); + MessageBox(GetHwnd(), TranslateT(szSpecifyCode), PRODUCT_NAME, MB_ICONEXCLAMATION); else { char code[10]; GetWindowTextA(m_pw1.GetHwnd(), code, 4); @@ -105,7 +130,7 @@ INT_PTR WhatsAppProto::SvcCreateAccMgrUI(WPARAM wParam, LPARAM lParam) return (INT_PTR)pDlg->GetHwnd(); } -int WhatsAppProto::OnOptionsInit(WPARAM wParam, LPARAM lParam) +int WhatsAppProto::OnOptionsInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; odp.ptszTitle = m_tszUserName; diff --git a/protocols/WhatsApp/src/media.cpp b/protocols/WhatsApp/src/media.cpp index 0435eea06d..1d127bafe8 100644 --- a/protocols/WhatsApp/src/media.cpp +++ b/protocols/WhatsApp/src/media.cpp @@ -11,13 +11,16 @@ HANDLE WhatsAppProto::SendFile(MCONTACT hContact, const TCHAR* desc, TCHAR **pps // input validation char *name = mir_utf8encodeW(ppszFiles[0]); string mime = MediaUploader::getMimeFromExtension(split(name, '.')[1]); - if (mime.empty()) + if (mime.empty()) { + mir_free(name); return 0; + } // get file size FILE *hFile = _tfopen(ppszFiles[0], _T("rb")); if (hFile == NULL) { debugLogA(__FUNCTION__": cannot open file %s", ppszFiles[0]); + mir_free(name); return 0; } _fseeki64(hFile, 0, SEEK_END); @@ -30,18 +33,25 @@ HANDLE WhatsAppProto::SendFile(MCONTACT hContact, const TCHAR* desc, TCHAR **pps // check max file sizes switch (fileType) { case FMessage::WA_TYPE_IMAGE: - if (fileSize >= 5 * 1024 * 1024) + if (fileSize >= 5 * 1024 * 1024) { + mir_free(name); return 0; + } break; case FMessage::WA_TYPE_AUDIO: - if (fileSize >= 10 * 1024 * 1024) + if (fileSize >= 10 * 1024 * 1024) { + mir_free(name); return 0; + } break; case FMessage::WA_TYPE_VIDEO: - if (fileSize >= 20 * 1024 * 1024) + if (fileSize >= 20 * 1024 * 1024) { + mir_free(name); return 0; + } break; default: + mir_free(name); return 0; } diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index 0db6f3fa84..dcc8367e16 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -278,8 +278,10 @@ bool WhatsAppProto::Register(int state, const string &cc, const string &number, 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 - NotifyEvent(ptszTitle, TranslateT("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT); + else { + CMString tmp(FORMAT, TranslateT("Registration failed. Reason: %s"), reason.c_str()); + NotifyEvent(ptszTitle, tmp, NULL, WHATSAPP_EVENT_CLIENT); + } const JSONNode &tmpVal = resp["retry_after"]; if (tmpVal) { diff --git a/protocols/WhatsApp/src/resource.h b/protocols/WhatsApp/src/resource.h index c8f4f9f296..61d5bf626d 100644 --- a/protocols/WhatsApp/src/resource.h +++ b/protocols/WhatsApp/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by d:\miranda-ng\protocols\WhatsApp\res\whatsapp.rc +// Used by ..\res\whatsapp.rc // #define IDD_INPUTBOX 102 #define IDR_REGISTERUTILITY 103 @@ -16,7 +16,7 @@ #define IDC_PW 1004 #define IDC_SSL 1005 #define IDC_NICK 1006 -#define IDC_BUTTON_REQUEST_CODE 1007 +#define IDC_BUTTON_REQUEST_SMS_CODE 1007 #define IDC_BUTTON_REGISTER 1008 #define IDC_CC 1009 #define IDC_VALUE 1010 @@ -29,14 +29,15 @@ #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 106 +#define _APS_NEXT_RESOURCE_VALUE 107 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1019 +#define _APS_NEXT_CONTROL_VALUE 1020 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif -- cgit v1.2.3