diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/SkypeWeb/src/http_request.h | 7 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/main.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_messages.cpp | 138 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 6 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_trouter.cpp | 5 |
6 files changed, 95 insertions, 65 deletions
diff --git a/protocols/SkypeWeb/src/http_request.h b/protocols/SkypeWeb/src/http_request.h index e69355a300..a730aa7fd6 100644 --- a/protocols/SkypeWeb/src/http_request.h +++ b/protocols/SkypeWeb/src/http_request.h @@ -192,6 +192,13 @@ protected: return *this;
}
+ HttpRequestBody & operator<<(const LONG_VALUE ¶m)
+ {
+ AppendSeparator();
+ content.AppendFormat("%s=%lld", param.szName, param.llValue);
+ return *this;
+ }
+
HttpRequestBody & operator<<(const CHAR_VALUE ¶m)
{
AppendSeparator();
diff --git a/protocols/SkypeWeb/src/main.cpp b/protocols/SkypeWeb/src/main.cpp index 2dcb3b0046..65da7e20fe 100644 --- a/protocols/SkypeWeb/src/main.cpp +++ b/protocols/SkypeWeb/src/main.cpp @@ -69,8 +69,10 @@ extern "C" int __declspec(dllexport) Load(void) CSkypeProto::InitIcons();
CSkypeProto::InitMenus();
CSkypeProto::InitLanguages();
+
CreateServiceFunction(MODULE"/GetEventIcon", &CSkypeProto::EventGetIcon);
CreateServiceFunction(MODULE"/GetEventText", &CSkypeProto::GetEventText);
+
HookEvent(ME_SYSTEM_MODULESLOADED, &CSkypeProto::OnModulesLoaded);
return 0;
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index c303e4cedd..94fcb0180e 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -20,21 +20,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /* MESSAGE RECEIVING */
// incoming message flow
-int CSkypeProto::OnReceiveMessage(const char *messageId, const char *url, time_t timestamp, char *content, int emoteOffset, bool isRead)
+int CSkypeProto::OnReceiveMessage(MCONTACT hContact, const char *szContent, const char *szMessageId, time_t timestamp, int emoteOffset, bool isRead)
{
- CMStringA skypename(UrlToSkypename(url));
- debugLogA("Incoming message from %s", skypename);
-
- MCONTACT hContact = AddContact(skypename, true);
- if (hContact == NULL)
- return 0;
-
PROTORECVEVENT recv = { 0 };
recv.timestamp = timestamp;
- recv.szMessage = content;
+ recv.szMessage = mir_strdup(szContent);
recv.lParam = emoteOffset;
- recv.pCustomData = (void*)messageId;
- recv.cbCustomDataSize = (DWORD)mir_strlen(messageId);
+ recv.pCustomData = (void*)mir_strdup(szMessageId);
+ recv.cbCustomDataSize = (DWORD)mir_strlen(szMessageId);
if (isRead)
recv.flags |= PREF_CREATEREAD;
@@ -70,6 +63,8 @@ int CSkypeProto::OnSendMessage(MCONTACT hContact, int, const char *szMessage) else
SendRequest(new SendMessageRequest(m_szRegToken, username, param->hMessage, szMessage, m_szServer), &CSkypeProto::OnMessageSent, param);
+ m_OutMessages.insert((void*)param->hMessage);
+
return param->hMessage;
}
@@ -80,19 +75,33 @@ void CSkypeProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg) HANDLE hMessage = (HANDLE)param->hMessage;
delete param;
- if (response == NULL || response->resultCode != 201)
+ if (response != NULL)
{
- std::string error("Unknown error");
- if (response && response->pData != NULL)
+ if (response->resultCode == 201)
{
- JSONNode root = JSONNode::parse(response->pData);
- const JSONNode &node = root["errorCode"];
- if (node)
- error = node.as_string();
+ if (m_OutMessages.getIndex(hMessage) != -1)
+ {
+ ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, hMessage, 0);
+ m_OutMessages.remove(hMessage);
+ }
+ }
+ else
+ {
+ std::string strError = Translate("Unknown error!");
+
+ if (response->pData != NULL)
+ {
+ JSONNode jRoot = JSONNode::parse(response->pData);
+ const JSONNode &jErr = jRoot["errorCode"];
+
+ if(jErr)
+ {
+ strError = jErr.as_string();
+ }
+ }
+
+ ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, hMessage, (LPARAM)strError.c_str());
}
- ptrT username(getTStringA(hContact, "Skypename"));
- debugLogA(__FUNCTION__": failed to send message for %s (%s)", username, error.c_str());
- ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, hMessage, (LPARAM)error.c_str());
}
}
@@ -124,71 +133,80 @@ int CSkypeProto::OnPreCreateMessage(WPARAM, LPARAM lParam) void CSkypeProto::OnPrivateMessageEvent(const JSONNode &node)
{
CMStringA szMessageId = node["clientmessageid"] ? node["clientmessageid"].as_string().c_str() : node["skypeeditedid"].as_string().c_str();
+ CMStringA szConversationName(UrlToSkypename(node["conversationLink"].as_string().c_str()));
+ CMStringA szFromSkypename(UrlToSkypename(node["from"].as_string().c_str()));
- bool isEdited = node["skypeeditedid"];
- time_t timestamp = getByte("UseLocalTime", 0) ? time(NULL) : IsoToUnixTime(node["composetime"].as_string().c_str());
-
- CMStringA skypename(UrlToSkypename(node["conversationLink"].as_string().c_str()));
- CMStringA from(UrlToSkypename(node["from"].as_string().c_str()));
+ std::string strMessageType = node["messagetype"].as_string();
+ std::string strContent = node["content"].as_string();
+ ptrA szClearedContent(RemoveHtml(strContent.c_str()));
- std::string content = node["content"].as_string();
- int emoteOffset = node["skypeemoteoffset"].as_int();
+ bool bEdited = node["skypeeditedid"];
+ time_t timestamp = getByte("UseLocalTime", 0) ? time(NULL) : IsoToUnixTime(node["composetime"].as_string().c_str());
- ptrA message(RemoveHtml(content.c_str()));
+ int nEmoteOffset = node["skypeemoteoffset"].as_int();
- std::string messageType = node["messagetype"].as_string();
- MCONTACT hContact = AddContact(skypename, true);
+ MCONTACT hContact = AddContact(szConversationName, true);
if (HistorySynced)
db_set_dw(hContact, m_szModuleName, "LastMsgTime", (DWORD)timestamp);
- if (messageType == "Control/Typing")
+ if (strMessageType == "Control/Typing")
+ {
CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_INFINITE);
-
- else if (messageType == "Control/ClearTyping")
+ }
+ else if (strMessageType == "Control/ClearTyping")
+ {
CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_OFF);
-
- else if (messageType == "Text" || messageType == "RichText")
+ }
+ else if (strMessageType == "Text" || strMessageType == "RichText")
{
- if (IsMe(from))
+ if (IsMe(szFromSkypename))
{
- long hMessage = atol(szMessageId);
- ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)hMessage, 0);
- debugLogA(__FUNCTION__" timestamp = %d clientmsgid = %s", timestamp, szMessageId);
-
- AddDbEvent(emoteOffset == 0 ? EVENTTYPE_MESSAGE : SKYPE_DB_EVENT_TYPE_ACTION, hContact,
- timestamp, DBEF_UTF | DBEF_SENT, &message[emoteOffset], szMessageId);
-
- return;
+ HANDLE hMessage = (HANDLE)atol(szMessageId);
+ if (m_OutMessages.getIndex(hMessage) != -1)
+ {
+ ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, hMessage, 0);
+ m_OutMessages.remove(hMessage);
+ }
+ else
+ {
+ AddDbEvent(nEmoteOffset == 0 ? EVENTTYPE_MESSAGE : SKYPE_DB_EVENT_TYPE_ACTION, hContact,
+ timestamp, DBEF_UTF | DBEF_SENT, &szClearedContent[nEmoteOffset], szMessageId);
+ }
}
- CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_OFF);
-
- debugLogA(__FUNCTION__" timestamp = %d clientmsgid = %s", timestamp, szMessageId);
- MEVENT dbevent = GetMessageFromDb(hContact, szMessageId);
- if (isEdited && dbevent != NULL)
+ else
{
- AppendDBEvent(hContact, dbevent, message, szMessageId, timestamp);
+ CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_OFF);
+ MEVENT hDbEvent = GetMessageFromDb(hContact, szMessageId);
+
+ if (bEdited && hDbEvent != NULL)
+ {
+ AppendDBEvent(hContact, hDbEvent, szClearedContent, szMessageId, timestamp);
+ }
+ else
+ {
+ OnReceiveMessage(hContact, szClearedContent, szMessageId, timestamp, nEmoteOffset);
+ }
}
- else OnReceiveMessage(szMessageId, node["conversationLink"].as_string().c_str(), timestamp, message, emoteOffset);
}
- else if (messageType == "Event/SkypeVideoMessage") {}
- else if (messageType == "Event/Call")
+ else if (strMessageType == "Event/Call")
{
- AddDbEvent(SKYPE_DB_EVENT_TYPE_CALL_INFO, hContact, timestamp, DBEF_UTF, content.c_str(), szMessageId);
+ AddDbEvent(SKYPE_DB_EVENT_TYPE_CALL_INFO, hContact, timestamp, DBEF_UTF, strContent.c_str(), szMessageId);
}
- else if (messageType == "RichText/Files")
+ else if (strMessageType == "RichText/Files")
{
- AddDbEvent(SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO, hContact, timestamp, DBEF_UTF, content.c_str(), szMessageId);
+ AddDbEvent(SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO, hContact, timestamp, DBEF_UTF, strContent.c_str(), szMessageId);
}
- else if (messageType == "RichText/UriObject")
+ else if (strMessageType == "RichText/UriObject")
{
- AddDbEvent(SKYPE_DB_EVENT_TYPE_URIOBJ, hContact, timestamp, DBEF_UTF, content.c_str(), szMessageId);
+ AddDbEvent(SKYPE_DB_EVENT_TYPE_URIOBJ, hContact, timestamp, DBEF_UTF, strContent.c_str(), szMessageId);
}
+ //else if (messageType == "Event/SkypeVideoMessage") {}
//else if (!mir_strcmpi(messageType.c_str(), "RichText/Contacts")) {}
//else if (!mir_strcmpi(messageType.c_str(), "RichText/Location")) {}
else
{
- AddDbEvent(SKYPE_DB_EVENT_TYPE_UNKNOWN, hContact, timestamp, DBEF_UTF, content.c_str(), szMessageId);
+ AddDbEvent(SKYPE_DB_EVENT_TYPE_UNKNOWN, hContact, timestamp, DBEF_UTF, strContent.c_str(), szMessageId);
}
}
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 78b44fe2e2..60294c425f 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h"
CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName) :
- PROTO<CSkypeProto>(protoName, userName), m_PopupClasses(1), m_InviteDialogs(1), m_GCCreateDialogs(1)
+ PROTO<CSkypeProto>(protoName, userName), m_PopupClasses(1), m_InviteDialogs(1), m_GCCreateDialogs(1), m_OutMessages(3, PtrKeySortT)
{
m_hProtoIcon = Icons[0].Handle;
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index d121b2c6a5..ecf3d39ee0 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -105,7 +105,7 @@ private: TRInfo TRouter;
LIST<void> m_PopupClasses;
-
+ LIST<void> m_OutMessages;
//dialogs
LIST<CSkypeInviteDlg> m_InviteDialogs;
LIST<CSkypeGCCreateDlg> m_GCCreateDialogs;
@@ -239,7 +239,7 @@ private: MEVENT GetMessageFromDb(MCONTACT hContact, const char *messageId, LONGLONG timestamp = 0);
MEVENT AddDbEvent(WORD type, MCONTACT hContact, DWORD timestamp, DWORD flags, const char *content, const char *uid);
MEVENT AppendDBEvent(MCONTACT hContact, MEVENT hEvent, const char *szContent, const char *szUid, time_t edit_time);
- int OnReceiveMessage(const char *messageId, const char *url, time_t timestamp, char *content, int emoteOffset = 0, bool isRead = false);
+ int OnReceiveMessage(MCONTACT hContact, const char *szContent, const char *szMessageId, time_t timestamp, int emoteOffset = 0, bool isRead = false);
int OnSendMessage(MCONTACT hContact, int flags, const char *message);
void OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg);
@@ -323,7 +323,7 @@ private: void CALLBACK SkypeUnsetTimer(void*);
void CALLBACK SkypeSetTimer(void*);
void ProcessTimer();
- static void CALLBACK CSkypeProto::TimerProc(HWND, UINT, UINT_PTR, DWORD);
+ static void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD);
//---/
time_t GetLastMessageTime(MCONTACT hContact);
diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index efc8ab8128..e39c08e599 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -108,8 +108,11 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response) else
SetEvent(m_hTrouterEvent);
- if (time(NULL) - (TRouter.lastRegistrationTime - 120) <= 0)
+ if ((time(NULL) - TRouter.lastRegistrationTime) >= 3600)
+ {
SendRequest(new RegisterTrouterRequest(m_szTokenSecret, TRouter.url.c_str(), TRouter.sessId.c_str()));
+ TRouter.lastRegistrationTime = time(NULL);
+ }
}
void CSkypeProto::OnHealth(const NETLIBHTTPREQUEST*)
|