diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-05-09 18:20:41 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-05-09 18:20:41 +0000 |
commit | 98ea54f7f9eac65c369538e0f293ac7ec3e8db51 (patch) | |
tree | ac16c667c685bf68ef3368bc4b4c2f54cb81da3b /protocols/SkypeWeb | |
parent | ead1af24335c627c11ef2e23f7a31131c0412a2e (diff) |
SkypeWeb: TRouter refactoring.
git-svn-id: http://svn.miranda-ng.org/main/trunk@13499 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/SkypeWeb')
-rw-r--r-- | protocols/SkypeWeb/src/skype_contacts.cpp | 56 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_events.cpp | 13 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_messages.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_poll_processing.cpp | 18 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.cpp | 11 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 20 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_trouter.cpp | 67 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.cpp | 18 |
8 files changed, 132 insertions, 73 deletions
diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index 72237b51d0..f4f1f87e99 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -130,37 +130,47 @@ void CSkypeProto::LoadContactsAuth(const NETLIBHTTPREQUEST *response) node = json_get(item, "sender");
ptrA skypename(mir_t2a(ptrT(json_as_string(node))));
- JSONNODE *node = json_get(root, "greeting");
+ node = json_get(root, "greeting");
CMStringA reason = ptrA(mir_t2a(ptrT(json_as_string(node))));
+ node = json_get(root, "event_time");
+ ptrT eventTimeStr(json_as_string(node));
+ time_t eventTime = IsoToUnixTime(eventTimeStr);
+
if (reason == "null")
reason.Empty();
MCONTACT hContact = AddContact(skypename);
if (hContact)
{
- delSetting(hContact, "Auth");
-
- PROTORECVEVENT pre = { 0 };
- pre.flags = PREF_UTF;
- pre.timestamp = time(NULL);
- pre.lParam = (DWORD)(sizeof(DWORD) * 2 + mir_strlen(skypename) + reason.GetLength() + 5);
-
- /*blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), id(ASCIIZ), reason(ASCIIZ)*/
- PBYTE pBlob, pCurBlob;
- pCurBlob = pBlob = (PBYTE)mir_calloc(pre.lParam);
-
- *((PDWORD)pCurBlob) = 0;
- pCurBlob += sizeof(DWORD);
- *((PDWORD)pCurBlob) = (DWORD)hContact;
- pCurBlob += sizeof(DWORD);
- pCurBlob += 3;
- mir_strcpy((char*)pCurBlob, skypename);
- pCurBlob += mir_strlen(skypename) + 1;
- mir_strcpy((char*)pCurBlob, reason);
- pre.szMessage = (char*)pBlob;
-
- ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre);
+ time_t lastEventTime = db_get_dw(hContact, m_szModuleName, "LastAuthRequestTime", 0);
+
+ if (lastEventTime == 0 || lastEventTime < eventTime)
+ {
+ db_set_dw(hContact, m_szModuleName,"LastAuthRequestTime", eventTime);
+ delSetting(hContact, "Auth");
+
+ PROTORECVEVENT pre = { 0 };
+ pre.flags = PREF_UTF;
+ pre.timestamp = time(NULL);
+ pre.lParam = (DWORD)(sizeof(DWORD) * 2 + mir_strlen(skypename) + reason.GetLength() + 5);
+
+ /*blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), id(ASCIIZ), reason(ASCIIZ)*/
+ PBYTE pBlob, pCurBlob;
+ pCurBlob = pBlob = (PBYTE)mir_calloc(pre.lParam);
+
+ *((PDWORD)pCurBlob) = 0;
+ pCurBlob += sizeof(DWORD);
+ *((PDWORD)pCurBlob) = (DWORD)hContact;
+ pCurBlob += sizeof(DWORD);
+ pCurBlob += 3;
+ mir_strcpy((char*)pCurBlob, skypename);
+ pCurBlob += mir_strlen(skypename) + 1;
+ mir_strcpy((char*)pCurBlob, reason);
+ pre.szMessage = (char*)pBlob;
+
+ ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre);
+ }
}
}
json_delete(items);
diff --git a/protocols/SkypeWeb/src/skype_events.cpp b/protocols/SkypeWeb/src/skype_events.cpp index 6ca36100cb..03297983e8 100644 --- a/protocols/SkypeWeb/src/skype_events.cpp +++ b/protocols/SkypeWeb/src/skype_events.cpp @@ -124,4 +124,15 @@ void CSkypeProto::InitPopups() ppc.colorText = RGB(0, 0, 0);
ppc.iSeconds = -1;
m_hPopupClassNotify = Popup_RegisterClass(&ppc);
-}
\ No newline at end of file +}
+
+/*int CSkypeProto::ProcessSrmmEvent(WPARAM, LPARAM lParam)
+{
+ debugLogA(__FUNCTION__);
+ MessageWindowEventData *event = (MessageWindowEventData *)lParam;
+
+ if (event->uType == MSG_WINDOW_EVT_OPENING)
+ SetSrmmReadStatus(event->hContact);
+
+ return 0;
+}*/
\ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 320bd1177b..1b65a34a9f 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -304,7 +304,7 @@ void CSkypeProto::OnPrivateMessageEvent(JSONNODE *node) AddMessageToDb(hContact, timestamp, DBEF_UTF, clientMsgId, data.GetBuffer());
}
- } //Picture
+ }
else if (!mir_strcmpi(messageType, "RichText/Contacts")){}
if (clientMsgId && (!mir_strcmpi(messageType, "Text") || !mir_strcmpi(messageType, "RichText")))
diff --git a/protocols/SkypeWeb/src/skype_poll_processing.cpp b/protocols/SkypeWeb/src/skype_poll_processing.cpp index ead44bb3a3..327bbaae3d 100644 --- a/protocols/SkypeWeb/src/skype_poll_processing.cpp +++ b/protocols/SkypeWeb/src/skype_poll_processing.cpp @@ -137,7 +137,23 @@ void CSkypeProto::ProcessNewMessageRes(JSONNODE *node) void CSkypeProto::ProcessConversationUpdateRes(JSONNODE *node)
{
- return; //it should be rewritten
+ JSONNODE *lastMessage = json_get(node, "lastMessage");
+ JSONNODE *properties = json_get(node, "properties" );
+
+ ptrA convLink(mir_t2a(json_as_string(json_get(lastMessage, "conversationLink"))));
+
+ if (strstr(convLink, "/8:"))
+ {
+ ptrA skypename(ContactUrlToName(convLink));
+ MCONTACT hContact = FindContact(skypename);
+
+ if (hContact != NULL)
+ {
+ ptrA consumptionhorizon(mir_t2a(json_as_string(json_get(properties, "consumptionhorizon"))));
+
+ //server return bad data
+ }
+ }
}
void CSkypeProto::ProcessThreadUpdateRes(JSONNODE *node)
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 9e9910f594..8c0b9b36d0 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -43,21 +43,14 @@ PROTO<CSkypeProto>(protoName, userName), password(NULL) CreateProtoService("/IncomingCallCLE", &CSkypeProto::OnIncomingCallCLE);
CreateProtoService("/IncomingCallPP", &CSkypeProto::OnIncomingCallPP);
+ //HookProtoEvent(ME_MSG_WINDOWEVENT, &CSkypeProto::ProcessSrmmEvent);
+
m_tszAvatarFolder = std::tstring(VARST(_T("%miranda_avatarcache%"))) + _T("\\") + m_tszUserName;
DWORD dwAttributes = GetFileAttributes(m_tszAvatarFolder.c_str());
if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
CreateDirectoryTreeT(m_tszAvatarFolder.c_str());
db_set_resident(m_szModuleName, "Status");
- db_set_resident(m_szModuleName, "Trouter_ccid");
- db_set_resident(m_szModuleName, "Trouter_connId");
- db_set_resident(m_szModuleName, "Trouter_instance");
- db_set_resident(m_szModuleName, "Trouter_socketio");
- db_set_resident(m_szModuleName, "Trouter_url");
- db_set_resident(m_szModuleName, "Trouter_st");
- db_set_resident(m_szModuleName, "Trouter_se");
- db_set_resident(m_szModuleName, "Trouter_sig");
- db_set_resident(m_szModuleName, "Trouter_SessId");
//hooks
m_hCallHook = CreateHookableEvent(MODULE"/IncomingCall");
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 3f8d51007e..f639f1d18b 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -23,6 +23,19 @@ typedef void(CSkypeProto::*SkypeResponseWithArgCallback)(const NETLIBHTTPREQUEST typedef HRESULT(MarkupCallback)(IHTMLDocument3 *pHtmlDoc, BSTR &message);
+struct TRInfo
+{
+ char *socketIo;
+ char *connId;
+ char *st;
+ char *se;
+ char *instance;
+ char *ccid;
+ char *sessId;
+ char *sig;
+ char *url;
+};
+
struct CSkypeProto : public PROTO < CSkypeProto >
{
friend CSkypePasswordEditor;
@@ -103,6 +116,8 @@ private: bool HistorySynced;
+ TRInfo TRouter;
+
HANDLE
m_hPopupClassCall,
m_hPopupClassNotify;
@@ -310,6 +325,8 @@ private: char *ParseUrl(const char *url, const char *token);
+ void SetSrmmReadStatus(MCONTACT hContact);
+
char *ChatUrlToName (const char *url);
char *ContactUrlToName (const char *url);
char *SelfUrlToName (const char *url);
@@ -323,7 +340,8 @@ private: time_t GetLastMessageTime(MCONTACT hContact);
//events
- void CSkypeProto::InitDBEvents();
+ void InitDBEvents();
+ //int __cdecl ProcessSrmmEvent(WPARAM, LPARAM);
//services
INT_PTR __cdecl OnIncomingCallCLE (WPARAM wParam, LPARAM lParam);
diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index cf637b462a..d12e744bcb 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -43,13 +43,13 @@ void CSkypeProto::OnCreateTrouter(const NETLIBHTTPREQUEST *response) return;
}
- setString("Trouter_ccid", ccid);
- setString("Trouter_connId", connId);
- setString("Trouter_instance", instance);
- setString("Trouter_socketio", socketio);
- setString("Trouter_url", url);
+ TRouter.ccid = mir_strdup(ccid);
+ TRouter.connId = mir_strdup(connId);
+ TRouter.instance = mir_strdup(instance);
+ TRouter.socketIo = mir_strdup(socketio);
+ TRouter.url = mir_strdup(url);
- SendRequest(new CreateTrouterPoliciesRequest(TokenSecret, connId), &CSkypeProto::OnTrouterPoliciesCreated);
+ SendRequest(new CreateTrouterPoliciesRequest(TokenSecret, TRouter.connId), &CSkypeProto::OnTrouterPoliciesCreated);
}
void CSkypeProto::OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response)
@@ -78,17 +78,19 @@ void CSkypeProto::OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response) return;
}
- setString("Trouter_st", st);
- setString("Trouter_se", se);
- setString("Trouter_sig", sig);
+ TRouter.st = mir_strdup(st);
+ TRouter.se = mir_strdup(se);
+ TRouter.sig = mir_strdup(sig);
SendRequest(new GetTrouterRequest
(
- getStringA("Trouter_socketio"),
- getStringA("Trouter_connId"),
- st, se, sig,
- getStringA("Trouter_instance"),
- getStringA("Trouter_ccid")
+ TRouter.socketIo,
+ TRouter.connId,
+ TRouter.st,
+ TRouter.se,
+ TRouter.sig,
+ TRouter.instance,
+ TRouter.ccid
), &CSkypeProto::OnGetTrouter, (void *)false);
@@ -106,24 +108,24 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response, void *p) CMStringA data(response->pData);
int iStart = 0;
CMStringA szToken = data.Tokenize(":", iStart).Trim();
- setString("Trouter_SessId", szToken);
+ TRouter.sessId = mir_strdup(szToken.GetBuffer());
m_hTrouterThread = ForkThreadEx(&CSkypeProto::TRouterThread, 0, NULL);
+
if (!isHealth)
- SendRequest(new RegisterTrouterRequest(TokenSecret, ptrA(getStringA("Trouter_url")), szToken));
+ SendRequest(new RegisterTrouterRequest(TokenSecret, TRouter.url, TRouter.sessId));
}
void CSkypeProto::OnHealth(const NETLIBHTTPREQUEST*)
{
- ptrA socketIo(getStringA("Trouter_socketio"));
- ptrA connId(getStringA("Trouter_connId"));
- ptrA st(getStringA("Trouter_st"));
- ptrA se(getStringA("Trouter_se"));
- ptrA instance(getStringA("Trouter_instance"));
- ptrA ccid(getStringA("Trouter_ccid"));
- ptrA sessId(getStringA("Trouter_SessId"));
- ptrA sig(getStringA("Trouter_sig"));
-
- SendRequest(new GetTrouterRequest(socketIo, connId, st, se, sig, instance, ccid), &CSkypeProto::OnGetTrouter, (void *)true);
+
+ SendRequest(new GetTrouterRequest(TRouter.socketIo,
+ TRouter.connId,
+ TRouter.st,
+ TRouter.se,
+ TRouter.sig,
+ TRouter.instance,
+ TRouter.ccid),
+ &CSkypeProto::OnGetTrouter, (void *)true);
}
void CSkypeProto::OnTrouterEvent(JSONNODE *body, JSONNODE *)
@@ -180,18 +182,9 @@ void CSkypeProto::TRouterThread(void*) int errors = 0;
- ptrA socketIo(getStringA("Trouter_socketio"));
- ptrA connId(getStringA("Trouter_connId"));
- ptrA st(getStringA("Trouter_st"));
- ptrA se(getStringA("Trouter_se"));
- ptrA instance(getStringA("Trouter_instance"));
- ptrA ccid(getStringA("Trouter_ccid"));
- ptrA sessId(getStringA("Trouter_SessId"));
- ptrA sig(getStringA("Trouter_sig"));
-
while (!isTerminated && errors < POLLING_ERRORS_LIMIT)
{
- TrouterPollRequest *request = new TrouterPollRequest(socketIo, connId, st, se, sig, instance, ccid, sessId) ;
+ TrouterPollRequest *request = new TrouterPollRequest(TRouter.socketIo, TRouter.connId, TRouter.st, TRouter.se, TRouter.sig, TRouter.instance, TRouter.ccid, TRouter.sessId) ;
request->nlc = m_TrouterConnection;
NETLIBHTTPREQUEST *response = request->Send(m_hNetlibUser);
@@ -222,7 +215,7 @@ void CSkypeProto::TRouterThread(void*) }
else
{
- SendRequest(new HealthTrouterRequest(ccid), &CSkypeProto::OnHealth);
+ SendRequest(new HealthTrouterRequest(TRouter.ccid), &CSkypeProto::OnHealth);
CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
delete request;
break;
diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index 0024ba63c8..4ef74fb50e 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -22,6 +22,24 @@ bool CSkypeProto::IsOnline() return m_iStatus > ID_STATUS_OFFLINE && m_hPollingThread;
}
+void CSkypeProto::SetSrmmReadStatus(MCONTACT hContact)
+{
+ time_t time = getDword(hContact, "LastMsgReadTime", 0);
+ if (!time)
+ return;
+
+ TCHAR ttime[64];
+ _locale_t locale = _create_locale(LC_ALL, "");
+ _tcsftime_l(ttime, SIZEOF(ttime), _T("%X - %x"), localtime(&time), locale);
+ _free_locale(locale);
+
+ StatusTextData st = { 0 };
+ st.cbSize = sizeof(st);
+ st.hIcon = LoadSkinnedIcon(SKINICON_OTHER_HISTORY);
+ mir_sntprintf(st.tszText, SIZEOF(st.tszText), TranslateT("Message read: %s"), ttime);
+ CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, (LPARAM)&st);
+}
+
time_t CSkypeProto::IsoToUnixTime(const TCHAR *stamp)
{
TCHAR date[9];
|