diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-04-03 21:06:18 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-04-03 21:06:18 +0000 |
commit | 035b5186bba8c0cab7d349f849c5c1db7cad7e39 (patch) | |
tree | f494a37398b31665d4deb6ebd2e2e52eb98292ef | |
parent | 77633ec5799b374a1899d05ae69a2e5f978f2a7c (diff) |
SkypeWeb: messaging support (patch from MikalaiR)
git-svn-id: http://svn.miranda-ng.org/main/trunk@12595 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/SkypeWeb/src/requests/messages.h | 5 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_messages.cpp | 60 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_poll_processing.cpp | 25 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.cpp | 37 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 24 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.cpp | 14 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/version.h | 2 |
7 files changed, 122 insertions, 45 deletions
diff --git a/protocols/SkypeWeb/src/requests/messages.h b/protocols/SkypeWeb/src/requests/messages.h index ecd939bbd0..389d9fa7bb 100644 --- a/protocols/SkypeWeb/src/requests/messages.h +++ b/protocols/SkypeWeb/src/requests/messages.h @@ -17,7 +17,10 @@ public: << CHAR_VALUE("Origin", "https://web.skype.com")
<< CHAR_VALUE("Connection", "keep-alive");
- Body << FORMAT_VALUE("{\"clientmessageid\":\"\",\"content\":\"%s\",\"messagetype\":\"RichText\",\"contenttype\":\"text\"}", message);
+ CMStringA data;
+ data.AppendFormat("{\"clientmessageid\":\"\",\"content\":\"%s\",\"messagetype\":\"RichText\",\"contenttype\":\"text\"}", message);
+
+ Body << VALUE(data);
}
};
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index c4f9498885..869d7e75d5 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -3,21 +3,21 @@ /* MESSAGE RECEIVING */
// writing message/even into db
-int CSkypeProto::OnReceiveMessage(MCONTACT hContact, PROTORECVEVENT *pre)
+int CSkypeProto::OnReceiveMessage(const char *from, const char *convLink, time_t timeStamp, char *content)
{
- //return Proto_RecvMessage(hContact, pre);
- if (pre->szMessage == NULL)
- return NULL;
-
- DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.szModule = GetContactProto(hContact);
- dbei.timestamp = pre->timestamp;
- dbei.flags = DBEF_UTF;
- dbei.eventType = pre->lParam;
- dbei.cbBlob = (DWORD)mir_strlen(pre->szMessage) + 1;
- dbei.pBlob = (PBYTE)pre->szMessage;
-
- return (INT_PTR)db_event_add(hContact, &dbei);
+ PROTORECVEVENT recv = { 0 };
+ recv.flags = PREF_UTF;
+ recv.timestamp = timeStamp;
+ recv.szMessage = content;
+ debugLogA("Incoming message from %s", ContactUrlToName(from));
+ if (IsMe(ContactUrlToName(from)))
+ {
+ recv.flags |= PREF_SENT;
+ MCONTACT hContact = GetContact(ContactUrlToName(convLink));
+ return ProtoChainRecvMsg(hContact, &recv);
+ }
+ MCONTACT hContact = GetContact(ContactUrlToName(from));
+ return ProtoChainRecvMsg(hContact, &recv);
}
/* MESSAGE SENDING */
@@ -26,4 +26,36 @@ int CSkypeProto::OnReceiveMessage(MCONTACT hContact, PROTORECVEVENT *pre) int CSkypeProto::OnSendMessage(MCONTACT hContact, int flags, const char *szMessage)
{
return 0;
+}
+
+void CSkypeProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
+{
+ SendMessageParam *param = (SendMessageParam*)arg;
+
+ ptrT error(mir_tstrdup(TranslateT("Unknown error")));
+ ptrT username(getTStringA(param->hContact, "Skypename"));
+
+ if (response != NULL && (response->resultCode == 201 || response->resultCode == 200))
+ {
+ JSONROOT root(response->pData);
+ JSONNODE *node = json_get(root, "errorCode");
+ if (node)
+ error = json_as_string(node);
+ }
+
+ int status = ACKRESULT_FAILED;
+
+ if (error == NULL)
+ {
+ status = ACKRESULT_SUCCESS;
+ }
+ else
+ debugLog(_T("CSkypeProto::OnMessageSent: failed to send message for %s (%s)"), username, error);
+
+ ProtoBroadcastAck(
+ param->hContact,
+ ACKTYPE_MESSAGE,
+ status,
+ param->hMessage,
+ error);
}
\ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_poll_processing.cpp b/protocols/SkypeWeb/src/skype_poll_processing.cpp index c69722d93d..24baf6f8e1 100644 --- a/protocols/SkypeWeb/src/skype_poll_processing.cpp +++ b/protocols/SkypeWeb/src/skype_poll_processing.cpp @@ -94,24 +94,21 @@ void CSkypeProto::ProcessNewMessageRes(JSONNODE *node) else if (strstr(conversationLink, "/8:"))
{
if (!mir_strcmpi(messagetype, "Control/Typing"))
- {
- MCONTACT hContact = GetContact(ContactUrlToName(from));
- CallService(MS_PROTO_CONTACTISTYPING, hContact, 5);
- }
+ {
+ MCONTACT hContact = GetContact(ContactUrlToName(from));
+ CallService(MS_PROTO_CONTACTISTYPING, hContact, 5);
+ }
else if (!mir_strcmpi(messagetype, "Control/ClearTyping"))
{
return;
}
- else if (!mir_strcmpi(messagetype, "Text") || !mir_strcmpi(messagetype, "RichText")) {
- PROTORECVEVENT recv = { 0 };
- recv.flags = PREF_UTF;
- recv.timestamp = timeStamp;
- recv.szMessage = content;
- debugLogA("Incoming message from %s", ContactUrlToName(from));
- if (IsMe(ContactUrlToName(from)))
- return; //it should be rewritten
- MCONTACT hContact = GetContact(ContactUrlToName(from));
- OnReceiveMessage(hContact, &recv);
+ else if (!mir_strcmpi(messagetype, "Text") || !mir_strcmpi(messagetype, "RichText"))
+ {
+ OnReceiveMessage(from, conversationLink, timeStamp, content);
+ }
+ else if (!mir_strcmpi(messagetype, "Event/SkypeVideoMessage"))
+ {
+ return; //not supported
}
}
}
\ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 69d8eed9fc..61b8f2445a 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -108,15 +108,46 @@ int CSkypeProto::RecvContacts(MCONTACT, PROTORECVEVENT*) { return 0; } int CSkypeProto::RecvFile(MCONTACT hContact, PROTOFILEEVENT *pre) { return 0; }
-int CSkypeProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre) { return 0; }
-
int CSkypeProto::RecvUrl(MCONTACT, PROTORECVEVENT*) { return 0; }
int CSkypeProto::SendContacts(MCONTACT, int, int, MCONTACT*) { return 0; }
HANDLE CSkypeProto::SendFile(MCONTACT hContact, const PROTOCHAR *szDescription, PROTOCHAR **ppszFiles) { return 0; }
-int CSkypeProto::SendMsg(MCONTACT hContact, int flags, const char *msg) { return 0; }
+int CSkypeProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
+{
+ UINT hMessage = InterlockedIncrement(&hMessageProcess); + + SendMessageParam *param = (SendMessageParam*)mir_calloc(sizeof(SendMessageParam)); + param->hContact = hContact; + param->hMessage = (HANDLE)hMessage; + param->msg = msg; + param->flags = flags; + + ForkThread(&CSkypeProto::SendMsgThread, (void*)param); + + return hMessage;
+}
+
+void CSkypeProto::SendMsgThread(void *arg) +{ + SendMessageParam *param = (SendMessageParam*)arg; + + if (!IsOnline()) + { + ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hMessage, (LPARAM)Translate("You cannot send messages when you are offline.")); + mir_free(param); + return; + } + + CMStringA message = (param->flags & PREF_UNICODE) ? ptrA(mir_utf8encode(param->msg)) : param->msg; // TODO: mir_utf8encode check taken from FacebookRM, is it needed? Usually we get PREF_UTF8 flag instead. + + ptrA token(getStringA("registrationToken")); + ptrA username(getStringA(param->hContact, "Skypename")); + PushRequest( + new SendMsgRequest(token, username, message, getStringA("Server"))/*, + &CSkypeProto::OnMessageSent*/); +}
int CSkypeProto::SendUrl(MCONTACT, int, const char*) { return 0; }
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index add8444093..5e598a8e99 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -1,9 +1,23 @@ #ifndef _SKYPE_PROTO_H_
#define _SKYPE_PROTO_H_
+struct SendMessageParam
+{
+ MCONTACT hContact;
+ HANDLE hMessage;
+ const char *msg;
+ int flags;
+};
+
+enum ARG_FREE_TYPE
+{
+ ARG_NO_FREE,
+ ARG_MIR_FREE
+};
+
typedef void(CSkypeProto::*SkypeResponseCallback)(const NETLIBHTTPREQUEST *response);
-struct CSkypeProto : public PROTO<CSkypeProto>
+struct CSkypeProto : public PROTO < CSkypeProto >
{
friend CSkypePasswordEditor;
@@ -44,7 +58,6 @@ public: virtual int __cdecl RecvContacts(MCONTACT hContact, PROTORECVEVENT*);
virtual int __cdecl RecvFile(MCONTACT hContact, PROTOFILEEVENT*);
- virtual int __cdecl RecvMsg(MCONTACT hContact, PROTORECVEVENT*);
virtual int __cdecl RecvUrl(MCONTACT hContact, PROTORECVEVENT*);
virtual int __cdecl SendContacts(MCONTACT hContact, int flags, int nContacts, MCONTACT *hContactsList);
@@ -89,7 +102,7 @@ private: std::map<std::string, std::string> RegInfo;
HANDLE m_pollingConnection, m_hPollingThread;
static std::map<std::tstring, std::tstring> languages;
-
+ ULONG hMessageProcess;
static INT_PTR CALLBACK PasswordEditorProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// accounts
@@ -171,8 +184,10 @@ private: int __cdecl OnContactDeleted(MCONTACT, LPARAM);
// messages
- int OnReceiveMessage(MCONTACT hContact, PROTORECVEVENT *pre);
+ int OnReceiveMessage(const char *from, const char *convLink, time_t timeStamp, char *content);
int OnSendMessage(MCONTACT hContact, int flags, const char *message);
+ void __cdecl CSkypeProto::SendMsgThread(void *arg);
+ void OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg);
//polling
void __cdecl ParsePollData(JSONNODE *data);
void __cdecl PollingThread(void*);
@@ -180,6 +195,7 @@ private: void CSkypeProto::ProcessUserPresenceRes(JSONNODE *node);
void CSkypeProto::ProcessNewMessageRes(JSONNODE *node);
// utils
+ bool IsOnline();
time_t __stdcall IsoToUnixTime(const TCHAR *stamp);
char *GetStringChunk(const char *haystack, size_t len, const char *start, const char *end);
bool IsMe(const char *skypeName);
diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index 428f778d5b..5d365c0cb1 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -1,5 +1,10 @@ #include "common.h"
+bool CSkypeProto::IsOnline()
+{
+ return m_iStatus > ID_STATUS_OFFLINE && m_hPollingThread;
+}
+
time_t __stdcall CSkypeProto::IsoToUnixTime(const TCHAR *stamp)
{
TCHAR date[9];
@@ -136,14 +141,7 @@ void CSkypeProto::ShowNotification(const TCHAR *message, int flags, MCONTACT hCo bool CSkypeProto::IsFileExists(std::tstring path)
{
- WIN32_FIND_DATA wfd;
- HANDLE hFind = FindFirstFile(path.c_str(), &wfd);
- if (INVALID_HANDLE_VALUE != hFind)
- {
- FindClose(hFind);
- return true;
- }
- return false;
+ return _taccess(path.c_str(), 0) == 0;
}
char *CSkypeProto::ContactUrlToName(const char *url)
diff --git a/protocols/SkypeWeb/src/version.h b/protocols/SkypeWeb/src/version.h index 95bac7ffe5..6af653b5c6 100644 --- a/protocols/SkypeWeb/src/version.h +++ b/protocols/SkypeWeb/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 0
-#define __BUILD_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>
|