diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-04-13 19:45:44 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-04-13 19:45:44 +0000 |
commit | cfba0c6c4d9a42a5384b61f109836783c0adc8a7 (patch) | |
tree | 79911a62bd2a4a020dd0795c905251bb45da9156 | |
parent | 1fba29f58dee5744dd0266b7368b5c004679c011 (diff) |
SkypeWeb: added removing html from messages
git-svn-id: http://svn.miranda-ng.org/main/trunk@12795 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/SkypeWeb/src/skype_history_sync.cpp | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_messages.cpp | 16 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 1 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.cpp | 69 |
4 files changed, 84 insertions, 6 deletions
diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index 56ba691498..08bb862b7a 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -57,7 +57,9 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) ? FindContact(ptrA(ContactUrlToName(conversationLink)))
: FindContact(skypename);
- AddMessageToDb(hContact, timestamp, flags, clientMsgId, content, emoteOffset);
+ ptrA message(RemoveHtml(content));
+
+ AddMessageToDb(hContact, timestamp, flags, clientMsgId, message, emoteOffset);
}
}
}
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index bc9431da38..0fab2ce165 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -67,7 +67,12 @@ MEVENT CSkypeProto::AddMessageToDb(MCONTACT hContact, DWORD timestamp, DWORD fla int CSkypeProto::OnReceiveMessage(const char *messageId, const char *url, time_t timestamp, char *content, int emoteOffset, bool isRead)
{
ptrA skypename(ContactUrlToName(url));
+ debugLogA("Incoming message from %s", skypename);
+
MCONTACT hContact = AddContact(skypename, true);
+ if (hContact == NULL)
+ return 0;
+
PROTORECVEVENT recv = { 0 };
recv.flags = PREF_UTF;
recv.timestamp = timestamp;
@@ -75,9 +80,10 @@ int CSkypeProto::OnReceiveMessage(const char *messageId, const char *url, time_t recv.lParam = emoteOffset;
recv.pCustomData = (void*)messageId;
recv.cbCustomDataSize = mir_strlen(messageId);
+
if (isRead)
recv.flags |= PREF_CREATEREAD;
- debugLogA("Incoming message from %s", skypename);
+
return ProtoChainRecvMsg(hContact, &recv);
}
@@ -202,6 +208,8 @@ void CSkypeProto::OnPrivateMessageEvent(JSONNODE *node) ptrA content(mir_t2a(ptrT(json_as_string(json_get(node, "content")))));
int emoteOffset = json_as_int(json_get(node, "skypeemoteoffset"));
+ ptrA message(RemoveHtml(content));
+
if (IsMe(skypename))
{
ptrA conversationLink(mir_t2a(ptrT(json_as_string(json_get(node, "conversationLink")))));
@@ -211,7 +219,7 @@ void CSkypeProto::OnPrivateMessageEvent(JSONNODE *node) int hMessage = atoi(clientMsgId);
ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)hMessage, 0);
debugLogA(__FUNCTION__" timestamp = %d clientmsgid = %s", timestamp, clientMsgId);
- AddMessageToDb(hContact, timestamp, DBEF_UTF | DBEF_SENT, clientMsgId, &content[emoteOffset], emoteOffset);
+ AddMessageToDb(hContact, timestamp, DBEF_UTF | DBEF_SENT, clientMsgId, message, emoteOffset);
}
else
{
@@ -225,11 +233,9 @@ void CSkypeProto::OnPrivateMessageEvent(JSONNODE *node) else if (!mir_strcmpi(messageType, "Text") || !mir_strcmpi(messageType, "RichText"))
{
debugLogA(__FUNCTION__" timestamp = %d clientmsgid = %s", timestamp, clientMsgId);
- OnReceiveMessage(clientMsgId, from, timestamp, content, emoteOffset);
+ OnReceiveMessage(clientMsgId, from, timestamp, message, emoteOffset);
}
else if (!mir_strcmpi(messageType, "Event/SkypeVideoMessage"))
- {
return; //not supported
- }
}
}
\ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index adbde10032..3f7baea634 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -235,6 +235,7 @@ private: bool IsOnline();
MEVENT AddEventToDb(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob);
time_t IsoToUnixTime(const TCHAR *stamp);
+ char *RemoveHtml(const char *text);
char *GetStringChunk(const char *haystack, size_t len, const char *start, const char *end);
bool IsMe(const char *skypeName);
int SkypeToMirandaStatus(const char *status);
diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index dfb57323c8..bf3fb13fd9 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -94,6 +94,75 @@ time_t CSkypeProto::IsoToUnixTime(const TCHAR *stamp) return (t >= 0) ? t : 0;
}
+struct HtmlEntity
+{
+ const char *entity;
+ char symbol;
+};
+
+const HtmlEntity htmlEntities[] =
+{
+ { "nbsp", ' ' },
+ { "amp", '&' },
+ { "quot", '"' },
+ { "lt", '<' },
+ { "gt", '>' },
+ { "apos", '\'' },
+ { "copy", '©' },
+ // TODO: add more
+};
+
+char *CSkypeProto::RemoveHtml(const char *text)
+{
+ std::string new_string = "";
+ std::string data = text;
+
+ if (data.find("\x1b\xe3\xac\x8d\x1d") != -1)
+ data = "CONVERSATION MEMBERS:" + data.substr(5, data.length() - 5);
+
+ for (std::string::size_type i = 0; i < data.length(); i++)
+ {
+ if (data.at(i) == '<' && data.at(i + 1) != ' ')
+ {
+ i = data.find(">", i);
+ if (i == std::string::npos)
+ break;
+
+ continue;
+ }
+
+ if (data.at(i) == '&') {
+ std::string::size_type begin = i;
+ i = data.find(";", i);
+ if (i == std::string::npos) {
+ i = begin;
+ }
+ else {
+ std::string entity = data.substr(begin + 1, i - begin - 1);
+
+ bool found = false;
+ for (int j = 0; j < SIZEOF(htmlEntities); j++)
+ {
+ if (!stricmp(entity.c_str(), htmlEntities[j].entity))
+ {
+ new_string += htmlEntities[j].symbol;
+ found = true;
+ break;
+ }
+ }
+
+ if (found)
+ continue;
+ else
+ i = begin;
+ }
+ }
+
+ new_string += data.at(i);
+ }
+
+ return mir_strdup(new_string.c_str());
+}
bool CSkypeProto::IsMe(const char *skypeName)
{
|