summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/WhatsApp')
-rw-r--r--protocols/WhatsApp/res/whatsapp.rc22
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp10
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp7
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp8
-rw-r--r--protocols/WhatsApp/src/constants.h3
-rw-r--r--protocols/WhatsApp/src/dialogs.cpp43
-rw-r--r--protocols/WhatsApp/src/media.cpp18
-rw-r--r--protocols/WhatsApp/src/proto.cpp6
-rw-r--r--protocols/WhatsApp/src/resource.h9
9 files changed, 86 insertions, 40 deletions
diff --git a/protocols/WhatsApp/res/whatsapp.rc b/protocols/WhatsApp/res/whatsapp.rc
index 77d59786c9..37f87d0fbc 100644
--- a/protocols/WhatsApp/res/whatsapp.rc
+++ b/protocols/WhatsApp/res/whatsapp.rc
@@ -84,11 +84,12 @@ BEGIN
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 "SMS code",IDC_STATIC,8,105,47,10
- EDITTEXT IDC_PW,64,104,20,12,ES_AUTOHSCROLL | ES_NUMBER
- CTEXT "-",IDC_STATIC,86,105,8,10
- EDITTEXT IDC_PW2,96,104,20,12,ES_AUTOHSCROLL | ES_NUMBER
- PUSHBUTTON "Request code",IDC_BUTTON_REQUEST_CODE,12,120,80,14
+ 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
@@ -109,11 +110,12 @@ BEGIN
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 "SMS code",IDC_STATIC,8,125,47,10
- EDITTEXT IDC_PW,64,124,20,12,ES_AUTOHSCROLL | ES_NUMBER
- CTEXT "-",IDC_STATIC,86,125,8,10
- EDITTEXT IDC_PW2,96,124,20,12,ES_AUTOHSCROLL | ES_NUMBER
- PUSHBUTTON "Request code",IDC_BUTTON_REQUEST_CODE,12,140,80,14
+ 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
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<unsigned char> 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<unsigned char> challengedata(root->data->begin(), root->data->end());
delete root;
this->sendResponse(challengedata);
@@ -119,12 +118,14 @@ std::vector<unsigned char> WALogin::readFeaturesUntilChallengeOrSuccess()
m_pConnection->logData("Read success");
return std::vector<unsigned char>(data.begin(), data.end());
}
- if (ProtocolTreeNode::tagEquals(root, "success")) {
+ else if (ProtocolTreeNode::tagEquals(root, "success")) {
std::vector<unsigned char> 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<WhatsAppProto>
{
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