diff options
author | George Hazan <ghazan@miranda.im> | 2019-12-18 14:07:14 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-12-18 14:07:14 +0300 |
commit | 406f0e4a4f42979778757243ed29c2753cbb1107 (patch) | |
tree | e4b9a02689c3c38ab9f53924faec3204e3ff2254 /protocols/Facebook | |
parent | dc1d550fc8d2bc39a3f1b371f4dedbd045576c35 (diff) |
Facebook:
- normal behaviour of ServerThread();
- added OnLoggedIn() function;
- correct OnShutdown() processing;
- DBKEY_USERNAME replaced with DBKEY_LOGIN to provide compatibility with the old protocol
Diffstat (limited to 'protocols/Facebook')
-rw-r--r-- | protocols/Facebook/src/db.h | 1 | ||||
-rw-r--r-- | protocols/Facebook/src/dialogs.cpp | 6 | ||||
-rw-r--r-- | protocols/Facebook/src/mqtt.cpp | 25 | ||||
-rw-r--r-- | protocols/Facebook/src/proto.cpp | 11 | ||||
-rw-r--r-- | protocols/Facebook/src/proto.h | 17 | ||||
-rw-r--r-- | protocols/Facebook/src/server.cpp | 51 |
6 files changed, 46 insertions, 65 deletions
diff --git a/protocols/Facebook/src/db.h b/protocols/Facebook/src/db.h index 73d0b249a4..dd79f18faa 100644 --- a/protocols/Facebook/src/db.h +++ b/protocols/Facebook/src/db.h @@ -32,7 +32,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define DBKEY_SECOND_NAME "SecondName" #define DBKEY_LAST_NAME "LastName" #define DBKEY_NICK "Nick" -#define DBKEY_USERNAME "Username" #define DBKEY_PASS "Password" #define DBKEY_CLIENT_ID "ClientID" #define DBKEY_DEVICE_ID "DeviceID" diff --git a/protocols/Facebook/src/dialogs.cpp b/protocols/Facebook/src/dialogs.cpp index 4e544e729b..01206706de 100644 --- a/protocols/Facebook/src/dialogs.cpp +++ b/protocols/Facebook/src/dialogs.cpp @@ -22,8 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" - - INT_PTR CALLBACK FBAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { FacebookProto *proto = reinterpret_cast<FacebookProto*>(GetWindowLongPtr(hwnd, GWLP_USERDATA)); @@ -37,7 +35,7 @@ INT_PTR CALLBACK FBAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp proto = reinterpret_cast<FacebookProto*>(lparam); SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam); - ptrA login(db_get_sa(0, proto->ModuleName(), DBKEY_USERNAME)); + ptrA login(db_get_sa(0, proto->ModuleName(), DBKEY_LOGIN)); if (login != nullptr) SetDlgItemTextA(hwnd, IDC_UN, login); @@ -66,7 +64,7 @@ INT_PTR CALLBACK FBAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp char str[128]; GetDlgItemTextA(hwnd, IDC_UN, str, _countof(str)); - db_set_s(0, proto->ModuleName(), DBKEY_USERNAME, str); + db_set_s(0, proto->ModuleName(), DBKEY_LOGIN, str); GetDlgItemTextA(hwnd, IDC_PW, str, _countof(str)); db_set_s(0, proto->ModuleName(), DBKEY_PASS, str); diff --git a/protocols/Facebook/src/mqtt.cpp b/protocols/Facebook/src/mqtt.cpp index 1ffe35a4ac..2d1e6a02e8 100644 --- a/protocols/Facebook/src/mqtt.cpp +++ b/protocols/Facebook/src/mqtt.cpp @@ -212,14 +212,6 @@ void FacebookProto::MqttOpen() thrift.writeField(FB_THRIFT_TYPE_STRING); thrift << m_szAuthToken << (BYTE)0; - //FILE *out = fopen("C:\\qq.out", "wb"); - //fwrite(thrift.data(), 1, thrift.size(), out); - //fclose(out); - // - //out = fopen("C:\\qq.size", "w"); - //fprintf(out, "%d", thrift.size()); - //fclose(out); - size_t dataSize = thrift.size() + 100; BYTE *pData = (BYTE *)mir_alloc(dataSize); @@ -241,23 +233,6 @@ void FacebookProto::MqttOpen() deflateEnd(&zStreamOut); dataSize = dataSize - zStreamOut.avail_out; - //pData[2]++; - - //dataSize -= 4; - - //out = fopen("C:\\qq_deflated.out", "wb"); - //fwrite(pData, 1, dataSize, out); - //fclose(out); - // - //out = fopen("C:\\qq_deflated.size", "w"); - //fprintf(out, "%d", dataSize); - //fclose(out); - - //dataSize = 369; - //out = fopen("c:\\Users\\Uzivatel\\Desktop\\deflated_purple", "rb"); - //fread(pData, 1, dataSize, out); - //fclose(out); - uint8_t protocolVersion = 3; uint8_t flags = FB_MQTT_CONNECT_FLAG_USER | FB_MQTT_CONNECT_FLAG_PASS | FB_MQTT_CONNECT_FLAG_CLR | FB_MQTT_CONNECT_FLAG_QOS1; MqttMessage payload(FB_MQTT_MESSAGE_TYPE_CONNECT, 0, dataSize + 12); // size of things between size and payload (header, ...) diff --git a/protocols/Facebook/src/proto.cpp b/protocols/Facebook/src/proto.cpp index 101d641910..0f60c7c420 100644 --- a/protocols/Facebook/src/proto.cpp +++ b/protocols/Facebook/src/proto.cpp @@ -78,6 +78,12 @@ void FacebookProto::OnModulesLoaded() { } +void FacebookProto::OnShutdown() +{ + if (m_mqttConn != nullptr) + Netlib_Shutdown(m_mqttConn); +} + ///////////////////////////////////////////////////////////////////////////////////////// INT_PTR FacebookProto::GetCaps(int type, MCONTACT) @@ -175,7 +181,8 @@ int FacebookProto::SetStatus(int iNewStatus) ////////////////////////////////////////////////////////////////////////////// // EVENTS -INT_PTR FacebookProto::SvcCreateAccMgrUI(WPARAM, LPARAM lParam) { +INT_PTR FacebookProto::SvcCreateAccMgrUI(WPARAM, LPARAM lParam) +{ return (INT_PTR) CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_FACEBOOKACCOUNT), (HWND) lParam, FBAccountProc, (LPARAM) this); -}
\ No newline at end of file +} diff --git a/protocols/Facebook/src/proto.h b/protocols/Facebook/src/proto.h index 29c55a197e..761b49edb2 100644 --- a/protocols/Facebook/src/proto.h +++ b/protocols/Facebook/src/proto.h @@ -300,13 +300,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #define FB_API_CONTACTS_COUNT "500" - #define FACEBOOK_MESSAGE_LIMIT 100000 - - - - class FacebookProto; struct AsyncHttpRequest : public MTHttpRequest<FacebookProto> @@ -344,9 +339,9 @@ public: class FacebookProto : public PROTO<FacebookProto> { - AsyncHttpRequest* CreateRequest(const char* szName, const char* szMethod); - AsyncHttpRequest* CreateRequestGQL(int64_t id); - NETLIBHTTPREQUEST* ExecuteRequest(AsyncHttpRequest *pReq); + AsyncHttpRequest *CreateRequest(const char *szName, const char *szMethod); + AsyncHttpRequest *CreateRequestGQL(int64_t id); + NETLIBHTTPREQUEST *ExecuteRequest(AsyncHttpRequest *pReq); // MQTT functions bool MqttConnect(); @@ -359,13 +354,14 @@ class FacebookProto : public PROTO<FacebookProto> CMStringA m_szClientID; // stored, random alphanumeric string of 20 chars __int64 m_uid; // stored, Facebook user id __int64 m_iMqttId; - + bool m_invisible; bool m_bOnline; CMStringA m_szAuthToken; // calculated - void OnLoggedOut(); + void OnLoggedIn(); + void OnLoggedOut(); void __cdecl ServerThread(void *); @@ -381,6 +377,7 @@ public: // PROTO_INTERFACE void OnModulesLoaded() override; + void OnShutdown() override; INT_PTR GetCaps(int type, MCONTACT hContact) override; diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp index 4b0251fd2a..72942d8cce 100644 --- a/protocols/Facebook/src/server.cpp +++ b/protocols/Facebook/src/server.cpp @@ -20,23 +20,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" +void FacebookProto::OnLoggedIn() +{ + m_bOnline = true; + + ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, m_iDesiredStatus); + m_iStatus = m_iDesiredStatus; +} + void FacebookProto::OnLoggedOut() { + OnShutdown(); + m_bOnline = false; } ///////////////////////////////////////////////////////////////////////////////////////// -void FacebookProto::ServerThread(void *) +void FacebookProto::ServerThread(void *) { - m_szAuthToken = getMStringA(DBKEY_TOKEN); if (m_szAuthToken.IsEmpty()) { - auto* pReq = CreateRequest("authenticate", "auth.login"); + auto *pReq = CreateRequest("authenticate", "auth.login"); pReq->m_szUrl = FB_API_URL_AUTH; - - pReq << CHAR_PARAM("email", getMStringA(DBKEY_USERNAME)); + + pReq << CHAR_PARAM("email", getMStringA(DBKEY_LOGIN)); pReq << CHAR_PARAM("password", getMStringA(DBKEY_PASS)); pReq->CalcSig(); @@ -44,11 +53,10 @@ void FacebookProto::ServerThread(void *) JsonReply reply(ExecuteRequest(pReq)); if (reply.error()) { - ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_FAILED, (HANDLE) m_iStatus, m_iDesiredStatus); + ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_FAILED, (HANDLE)m_iStatus, m_iDesiredStatus); m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; - ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE) m_iStatus, m_iDesiredStatus); - + ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, m_iDesiredStatus); return; } @@ -60,24 +68,29 @@ void FacebookProto::ServerThread(void *) setString(DBKEY_ID, m_szUid); } - auto* pReq = CreateRequestGQL(FB_API_QUERY_CONTACTS); + auto *pReq = CreateRequestGQL(FB_API_QUERY_CONTACTS); pReq << CHAR_PARAM("query_params", "{\"0\":[\"user\"],\"1\":\"" FB_API_CONTACTS_COUNT "\"}"); pReq->CalcSig(); JsonReply reply(ExecuteRequest(pReq)); - if (reply.error()) - goto FAIL; - - // TODO: process contacts + if (reply.error()) { +FAIL: + ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_FAILED, (HANDLE)m_iStatus, m_iDesiredStatus); + m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; + ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, m_iDesiredStatus); + return; + } + // TODO: process contacts if (!MqttConnect()) goto FAIL; MqttOpen(); + OnLoggedIn(); int bufSize = 2048; - char* buf = (char*) mir_alloc(bufSize); + char *buf = (char *)mir_alloc(bufSize); while (!Miranda_IsTerminated()) { int ret = Netlib_Recv(m_mqttConn, buf, bufSize); @@ -96,13 +109,5 @@ void FacebookProto::ServerThread(void *) debugLogA("exiting ServerThread"); int oldStatus = m_iStatus; m_iDesiredStatus = m_iStatus = ID_STATUS_OFFLINE; - ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE) oldStatus, m_iStatus); - - return; - -FAIL: - ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_FAILED, (HANDLE) m_iStatus, m_iDesiredStatus); - - m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; - ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE) m_iStatus, m_iDesiredStatus); + ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); } |