From 1fba29f58dee5744dd0266b7368b5c004679c011 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 13 Apr 2015 19:10:20 +0000 Subject: SkypeWeb: escaping json on sending git-svn-id: http://svn.miranda-ng.org/main/trunk@12794 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/main.cpp | 2 +- protocols/SkypeWeb/src/requests/messages.h | 49 ++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 14 deletions(-) (limited to 'protocols') diff --git a/protocols/SkypeWeb/src/main.cpp b/protocols/SkypeWeb/src/main.cpp index d4ba2fdf65..3c95a3cf8f 100644 --- a/protocols/SkypeWeb/src/main.cpp +++ b/protocols/SkypeWeb/src/main.cpp @@ -48,7 +48,7 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) return &pluginInfo; } -extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_PROTOCOL, MIID_LAST}; +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; extern "C" int __declspec(dllexport) Load(void) { diff --git a/protocols/SkypeWeb/src/requests/messages.h b/protocols/SkypeWeb/src/requests/messages.h index 663a075a7b..1eb0115ae3 100644 --- a/protocols/SkypeWeb/src/requests/messages.h +++ b/protocols/SkypeWeb/src/requests/messages.h @@ -27,12 +27,18 @@ public: Headers << CHAR_VALUE("Accept", "application/json, text/javascript") << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) - << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8"); + << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); - CMStringA data; - data.AppendFormat("{\"clientmessageid\":\"%lld\",\"content\":\"%s\",\"messagetype\":\"RichText\",\"contenttype\":\"text\"}", timestamp, message); + JSONNODE *node = json_new(5); + json_push_back(node, json_new_i("clientmessageid", timestamp)); + json_push_back(node, json_new_a("messagetype", "RichText")); + json_push_back(node, json_new_a("contenttype", "text")); + json_push_back(node, json_new_a("content", message)); + ptrA data(mir_utf8encodeT(ptrT(json_write(node)))); Body << VALUE(data); + + json_delete(node); } }; @@ -45,12 +51,22 @@ public: Headers << CHAR_VALUE("Accept", "application/json, text/javascript") << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) - << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8"); + << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); + + CMStringA content; + content.AppendFormat("%s %s", username, message); - CMStringA data; - data.AppendFormat("{\"clientmessageid\":\"%lld\",\"content\":\"%s %s\",\"messagetype\":\"RichText\",\"contenttype\":\"text\",\"skypeemoteoffset\":\"%d\"}", timestamp, username, message, (int)(mir_strlen(username) + 1)); + JSONNODE *node = json_new(5); + json_push_back(node, json_new_i("clientmessageid", timestamp)); + json_push_back(node, json_new_a("messagetype", "RichText")); + json_push_back(node, json_new_a("contenttype", "text")); + json_push_back(node, json_new_a("content", content)); + json_push_back(node, json_new_i("skypeemoteoffset", (int)(mir_strlen(username) + 1))); + ptrA data(mir_utf8encodeT(ptrT(json_write(node)))); Body << VALUE(data); + + json_delete(node); } }; @@ -63,13 +79,20 @@ public: Headers << CHAR_VALUE("Accept", "application/json, text/javascript") << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) - << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8"); - CMStringA state; - state = (iState == PROTOTYPE_SELFTYPING_ON) ? "Control/Typing" : "Control/ClearTyping"; - CMStringA data; - data.AppendFormat("{\"clienmessageid\":%lld, \"content\":\"\", \"messagetype\":\"%s\", \"contenttype\":\"text\"}", time(NULL), state); + << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); + char *state = (iState == PROTOTYPE_SELFTYPING_ON) ? "Control/Typing" : "Control/ClearTyping"; + + JSONNODE *node = json_new(5); + json_push_back(node, json_new_i("clientmessageid", time(NULL))); + json_push_back(node, json_new_a("messagetype", state)); + json_push_back(node, json_new_a("contenttype", "text")); + json_push_back(node, json_new_a("content", "")); + + ptrA data(mir_utf8encodeT(ptrT(json_write(node)))); Body << VALUE(data); + + json_delete(node); } }; @@ -82,7 +105,7 @@ public: Headers << CHAR_VALUE("Accept", "application/json, text/javascript") << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) - << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8"); + << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); } }; @@ -95,7 +118,7 @@ public: Headers << CHAR_VALUE("Accept", "application/json, text/javascript") << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) - << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8"); + << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); } }; -- cgit v1.2.3