diff options
-rw-r--r-- | protocols/WhatsApp/WhatsApp_10.vcxproj | 10 | ||||
-rw-r--r-- | protocols/WhatsApp/WhatsApp_10.vcxproj.filters | 26 | ||||
-rw-r--r-- | protocols/WhatsApp/res/whatsapp.rc | bin | 7498 -> 8152 bytes | |||
-rw-r--r-- | protocols/WhatsApp/src/common.h | 3 | ||||
-rw-r--r-- | protocols/WhatsApp/src/constants.h | 3 | ||||
-rw-r--r-- | protocols/WhatsApp/src/db.h | 1 | ||||
-rw-r--r-- | protocols/WhatsApp/src/dialogs.cpp | 43 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.cpp | 120 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.h | 3 |
9 files changed, 170 insertions, 39 deletions
diff --git a/protocols/WhatsApp/WhatsApp_10.vcxproj b/protocols/WhatsApp/WhatsApp_10.vcxproj index b06e3b82ca..f8556bb73c 100644 --- a/protocols/WhatsApp/WhatsApp_10.vcxproj +++ b/protocols/WhatsApp/WhatsApp_10.vcxproj @@ -253,6 +253,7 @@ </ClCompile>
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="res\resource.h" />
<ClInclude Include="src\cJSON.h" />
<ClInclude Include="src\common.h" />
<ClInclude Include="src\constants.h" />
@@ -263,7 +264,6 @@ <ClInclude Include="src\OpenSSL\hmac.h" />
<ClInclude Include="src\OpenSSL\rc4.h" />
<ClInclude Include="src\proto.h" />
- <ClInclude Include="src\resource.h" />
<ClInclude Include="src\stdafx.h" />
<ClInclude Include="src\theme.h" />
<ClInclude Include="src\utils.h" />
@@ -286,6 +286,14 @@ <ResourceCompile Include="res\version.rc" />
<ResourceCompile Include="res\whatsapp.rc" />
</ItemGroup>
+ <ItemGroup>
+ <None Include="res\add-group.ico" />
+ <None Include="res\add-user-to-group.ico" />
+ <None Include="res\change-group-subject.ico" />
+ <None Include="res\leave-group.ico" />
+ <None Include="res\remove-user-from-group.ico" />
+ <None Include="res\whatsapp.ico" />
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
diff --git a/protocols/WhatsApp/WhatsApp_10.vcxproj.filters b/protocols/WhatsApp/WhatsApp_10.vcxproj.filters index a82a221122..71333b820a 100644 --- a/protocols/WhatsApp/WhatsApp_10.vcxproj.filters +++ b/protocols/WhatsApp/WhatsApp_10.vcxproj.filters @@ -145,9 +145,6 @@ <ClInclude Include="src\proto.h">
<Filter>Miranda Plugin\Header Files</Filter>
</ClInclude>
- <ClInclude Include="src\resource.h">
- <Filter>Miranda Plugin\Header Files</Filter>
- </ClInclude>
<ClInclude Include="src\theme.h">
<Filter>Miranda Plugin\Header Files</Filter>
</ClInclude>
@@ -205,6 +202,9 @@ <ClInclude Include="src\OpenSSL\rc4.h">
<Filter>WhatsAPI++\OpenSSL</Filter>
</ClInclude>
+ <ClInclude Include="res\resource.h">
+ <Filter>Miranda Plugin\Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\whatsapp.rc">
@@ -214,4 +214,24 @@ <Filter>Resources</Filter>
</ResourceCompile>
</ItemGroup>
+ <ItemGroup>
+ <None Include="res\whatsapp.ico">
+ <Filter>Resources</Filter>
+ </None>
+ <None Include="res\add-group.ico">
+ <Filter>Resources</Filter>
+ </None>
+ <None Include="res\add-user-to-group.ico">
+ <Filter>Resources</Filter>
+ </None>
+ <None Include="res\change-group-subject.ico">
+ <Filter>Resources</Filter>
+ </None>
+ <None Include="res\leave-group.ico">
+ <Filter>Resources</Filter>
+ </None>
+ <None Include="res\remove-user-from-group.ico">
+ <Filter>Resources</Filter>
+ </None>
+ </ItemGroup>
</Project>
\ No newline at end of file diff --git a/protocols/WhatsApp/res/whatsapp.rc b/protocols/WhatsApp/res/whatsapp.rc Binary files differindex 486310794c..93ba3a7353 100644 --- a/protocols/WhatsApp/res/whatsapp.rc +++ b/protocols/WhatsApp/res/whatsapp.rc diff --git a/protocols/WhatsApp/src/common.h b/protocols/WhatsApp/src/common.h index 6075138f94..92631c1365 100644 --- a/protocols/WhatsApp/src/common.h +++ b/protocols/WhatsApp/src/common.h @@ -74,13 +74,14 @@ class WhatsAppProto; #include "constants.h"
#include "utils.h"
#include "db.h"
-#include "resource.h"
+#include "../res/resource.h"
#include "dialogs.h"
#include "theme.h"
#include "definitions.h"
#include "WASocketConnection.h"
#include "proto.h"
#include "entities.h"
+#include "cJSON.h"
#if defined _DEBUG
#include <stdlib.h>
diff --git a/protocols/WhatsApp/src/constants.h b/protocols/WhatsApp/src/constants.h index e14a02cf3f..7ec8e6390a 100644 --- a/protocols/WhatsApp/src/constants.h +++ b/protocols/WhatsApp/src/constants.h @@ -64,4 +64,7 @@ #define IS_CHAT 1
+#define REG_STATE_REQ_CODE 1
+#define REG_STATE_REG_CODE 2
+
#endif
\ No newline at end of file diff --git a/protocols/WhatsApp/src/db.h b/protocols/WhatsApp/src/db.h index d78d2e75d6..39508a98b9 100644 --- a/protocols/WhatsApp/src/db.h +++ b/protocols/WhatsApp/src/db.h @@ -31,6 +31,7 @@ #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_EVENT_CLIENT_ENABLE "EventClientEnable"
#define WHATSAPP_KEY_EVENT_OTHER_ENABLE "EventOtherEnable"
diff --git a/protocols/WhatsApp/src/dialogs.cpp b/protocols/WhatsApp/src/dialogs.cpp index 81a17351fb..ef0c2fac4c 100644 --- a/protocols/WhatsApp/src/dialogs.cpp +++ b/protocols/WhatsApp/src/dialogs.cpp @@ -52,13 +52,46 @@ INT_PTR CALLBACK WhatsAppAccountProc( HWND hwnd, UINT message, WPARAM wparam, LP return TRUE;
case WM_COMMAND:
- if (LOWORD(wparam) == IDC_BUTTON_REQUEST_CODE)
+ if (LOWORD(wparam) == IDC_BUTTON_REQUEST_CODE || LOWORD(wparam) == IDC_BUTTON_REGISTER)
{
- if (MessageBox(NULL, _T("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 simultaneousley!\nContinue?"),
- PRODUCT_NAME, MB_YESNO) == IDYES)
+ proto = reinterpret_cast<WhatsAppProto*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
+
+ char cc[5];
+ GetDlgItemTextA(hwnd, IDC_CC, cc, sizeof(cc));
+ char number[128];
+ GetDlgItemTextA(hwnd, IDC_LOGIN, number, sizeof(number));
+
+ if (LOWORD(wparam) == IDC_BUTTON_REQUEST_CODE)
+ {
+ if (MessageBox(NULL, TranslateT("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 simultaneousley!\nContinue?"),
+ PRODUCT_NAME, MB_YESNO) == IDYES)
+ {
+ proto->Register(REG_STATE_REQ_CODE, string(cc), string(number), string());
+ }
+ }
+ else if (LOWORD(wparam) == IDC_BUTTON_REGISTER)
{
- proto = reinterpret_cast<WhatsAppProto*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
- proto->RequestCode();
+ char code[7];
+ if (SendDlgItemMessage(hwnd, IDC_REG_CODE_1, WM_GETTEXTLENGTH, 0, 0) == 3 &&
+ SendDlgItemMessage(hwnd, IDC_REG_CODE_2, WM_GETTEXTLENGTH, 0, 0) == 3)
+ {
+ GetDlgItemTextA(hwnd, IDC_REG_CODE_1, code, 4);
+ GetDlgItemTextA(hwnd, IDC_REG_CODE_2, &(code[3]), 4);
+ }
+ else
+ {
+ MessageBox(NULL, TranslateT("Please correctly specify your registration code received by SMS"),
+ PRODUCT_NAME, MB_ICONEXCLAMATION);
+ return TRUE;
+ }
+ string pw = proto->Register(REG_STATE_REG_CODE, string(cc), string(number), string(code));
+ if (!pw.empty())
+ {
+ CallService(MS_DB_CRYPT_ENCODESTRING,sizeof(pw.c_str()),reinterpret_cast<LPARAM>(pw.c_str()));
+ db_set_s(0, proto->ModuleName(), WHATSAPP_KEY_PASS, pw.c_str());
+ MessageBox(NULL, TranslateT("Your password has been set automatically.\nIf you change your password manually you may lose it and need to request a new code!"),
+ PRODUCT_NAME, MB_ICONWARNING);
+ }
}
}
diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index 8c9669d58c..acfe83f5a6 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -166,31 +166,19 @@ HANDLE WhatsAppProto::SearchBasic( const PROTOCHAR* id ) return email;
}
-void WhatsAppProto::RequestCode()
+string WhatsAppProto::Register(int state, string cc, string number, string code)
{
- std::string cc, number, idx;
+ string idx;
+ string ret;
DBVARIANT dbv;
if ( WASocketConnection::hNetlibUser == NULL)
{
- NotifyEvent(m_tszUserName,TranslateT("Network-connection error."),NULL,WHATSAPP_EVENT_CLIENT);
- return;
+ NotifyEvent(m_tszUserName, TranslateT("Network-connection error."), NULL, WHATSAPP_EVENT_CLIENT);
+ return ret;
}
- if ( !db_get_s(NULL,m_szModuleName,WHATSAPP_KEY_IDX,&dbv,DBVT_ASCIIZ))
- {
- idx = dbv.pszVal;
- db_free(&dbv);
- }
- if (idx.empty())
- {
- std::stringstream tm;
- tm << time(NULL);
- BYTE idxBuf[16];
- utils::md5string(tm.str(), idxBuf);
- idx = std::string((const char*) idxBuf, 16);
- db_set_s(0, m_szModuleName,WHATSAPP_KEY_IDX, idx.c_str());
- }
+ /*
if ( !db_get_s(NULL,m_szModuleName,WHATSAPP_KEY_CC,&dbv, DBVT_ASCIIZ))
{
cc = dbv.pszVal;
@@ -201,7 +189,7 @@ void WhatsAppProto::RequestCode() return;
}
}
- if ( !db_get_s(NULL,m_szModuleName,WHATSAPP_KEY_LOGIN,&dbv, DBVT_ASCIIZ))
+ if ( !db_get_s(NULL,m_szModuleName,WHATSAPP_KEY_LOGIN,&dbv, DBVT_ASCIIZ))
{
number = dbv.pszVal;
db_free(&dbv);
@@ -211,8 +199,35 @@ void WhatsAppProto::RequestCode() return;
}
}
+ */
+ if ( !db_get_s(NULL,m_szModuleName,WHATSAPP_KEY_IDX,&dbv,DBVT_ASCIIZ))
+ {
+ idx = dbv.pszVal;
+ db_free(&dbv);
+ }
+ if (idx.empty())
+ {
+ std::stringstream tm;
+ tm << time(NULL);
+ BYTE idxBuf[16];
+ utils::md5string(tm.str(), idxBuf);
+ idx = std::string((const char*) idxBuf, 16);
+ db_set_s(0, m_szModuleName,WHATSAPP_KEY_IDX, idx.c_str());
+ }
- std::string token(Utilities::md5String(std::string(ACCOUNT_TOKEN_PREFIX1) + ACCOUNT_TOKEN_PREFIX2 + number));
+ string url;
+ if (state == REG_STATE_REQ_CODE)
+ {
+ string token(Utilities::md5String(std::string(ACCOUNT_TOKEN_PREFIX1) + ACCOUNT_TOKEN_PREFIX2 + number));
+ url = string(ACCOUNT_URL_CODEREQUESTV2);
+ url += "?lc=US&lg=en&mcc=000&mnc=000&method=sms&token="+ token;
+ }
+ else if (state == REG_STATE_REG_CODE)
+ {
+ url = string(ACCOUNT_URL_REGISTERREQUESTV2);
+ url += "?code="+ code;
+ }
+ url += "&cc="+ cc +"&in="+ number +"&id="+ idx;
NETLIBHTTPHEADER agentHdr;
agentHdr.szName = "User-Agent";
@@ -230,9 +245,6 @@ void WhatsAppProto::RequestCode() NETLIBHTTPREQUEST nlhr = {sizeof(NETLIBHTTPREQUEST)};
nlhr.requestType = REQUEST_POST;
- string url = std::string(ACCOUNT_URL_CODEREQUESTV2);
- url += "?cc="+ cc + "&in="+ number +
- "&lc=US&lg=en&mcc=000&mnc=000&method=sms&id=" + idx + "&token="+ token;
nlhr.szUrl = (char*) url.c_str();
nlhr.headers = &headers[0];
nlhr.headersCount = 3;
@@ -241,13 +253,67 @@ void WhatsAppProto::RequestCode() NETLIBHTTPREQUEST* pnlhr = (NETLIBHTTPREQUEST*) CallService(MS_NETLIB_HTTPTRANSACTION,
(WPARAM) WASocketConnection::hNetlibUser, (LPARAM)&nlhr);
+ LOG("Server response: %s", pnlhr->pData);
MessageBoxA(NULL, pnlhr->pData, "Debug", MB_OK);
- // #TODO
-}
+ cJSON* resp = cJSON_Parse(pnlhr->pData);
+ cJSON* val;
+ string title = this->TranslateStr("Registration");
-void WhatsAppProto::RegisterCode(const std::string& code)
-{
+ // Invalid
+ if (resp == NULL)
+ {
+ this->NotifyEvent(title, this->TranslateStr("Registration failed. Invalid server response."), NULL, WHATSAPP_EVENT_CLIENT);
+ return ret;
+ }
+
+ // Status = fail
+ val = cJSON_GetObjectItem(resp, "status");
+ if (strcmp(val->valuestring, "fail") == 0)
+ {
+ cJSON* tmpVal = cJSON_GetObjectItem(resp, "reason");
+ if (strcmp(tmpVal->valuestring, "stale") == 0)
+ {
+ this->NotifyEvent(title, this->TranslateStr("Registration failed due to stale code. Please request a new code"), NULL, WHATSAPP_EVENT_CLIENT);
+ }
+ else
+ {
+ this->NotifyEvent(title, this->TranslateStr("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT);
+ }
+
+ tmpVal = cJSON_GetObjectItem(resp, "retry_after");
+ if (tmpVal != NULL)
+ {
+ this->NotifyEvent(title, this->TranslateStr("Please try again in %i seconds", tmpVal->valueint), NULL, WHATSAPP_EVENT_OTHER);
+ }
+ }
+
+ // Request code
+ else if (state == REG_STATE_REQ_CODE)
+ {
+ if (strcmp(val->valuestring, "sent") == 0)
+ {
+ this->NotifyEvent(title, this->TranslateStr("Registration code has been sent to your phone."), NULL, WHATSAPP_EVENT_OTHER);
+ }
+ }
+
+ // Register
+ else if (state == REG_STATE_REG_CODE)
+ {
+ val = cJSON_GetObjectItem(resp, "pw");
+ if (val == NULL)
+ {
+ this->NotifyEvent(title, this->TranslateStr("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT);
+ }
+ if (strcmp(val->valuestring, "ok") == 0)
+ {
+ ret = val->valuestring;
+ }
+ }
+
+ cJSON_Delete(resp);
+
+ return ret;
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h index e7a548f9af..524b429dae 100644 --- a/protocols/WhatsApp/src/proto.h +++ b/protocols/WhatsApp/src/proto.h @@ -134,8 +134,7 @@ public: }
// Registration
- void RequestCode();
- void RegisterCode(const std::string& code);
+ string Register(int state, string cc, string number, string code);
// Helpers
std::tstring GetAvatarFolder();
|