diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2016-02-07 09:54:16 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2016-02-07 09:54:16 +0000 |
commit | 7bdabace3f6ab47b8571cdec9bfd6f5b2c360b46 (patch) | |
tree | 5d450c2098f6316df8bc3f42c7988c94eb1c2a0d /protocols | |
parent | 941dca4cf7a93100c19a6e3b92e1bc6bf9e71f04 (diff) |
SkypeWeb: files sending
git-svn-id: http://svn.miranda-ng.org/main/trunk@16233 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/SkypeWeb/src/http_request.h | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/asm/files.h (renamed from protocols/SkypeWeb/src/requests/asm/images.h) | 15 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/messages.h | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/poll.h | 1 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/trouter.h | 1 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_db.cpp | 3 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_db.h | 1 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_events.cpp | 5 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_files.cpp | 43 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_messages.cpp | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_polling.cpp | 3 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_trouter.cpp | 3 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.h | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/stdafx.h | 2 |
16 files changed, 65 insertions, 30 deletions
diff --git a/protocols/SkypeWeb/src/http_request.h b/protocols/SkypeWeb/src/http_request.h index cc0c04fe84..816c5b3807 100644 --- a/protocols/SkypeWeb/src/http_request.h +++ b/protocols/SkypeWeb/src/http_request.h @@ -58,7 +58,7 @@ struct FORMAT_VALUE : public VALUE }
};
-class HttpRequest : protected NETLIBHTTPREQUEST, public MZeroedObject
+class HttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject
{
HttpRequest& operator=(const HttpRequest&); // to prevent copying;
diff --git a/protocols/SkypeWeb/src/requests/asm/images.h b/protocols/SkypeWeb/src/requests/asm/files.h index d1494c01ef..7d13524945 100644 --- a/protocols/SkypeWeb/src/requests/asm/images.h +++ b/protocols/SkypeWeb/src/requests/asm/files.h @@ -3,18 +3,20 @@ class ASMObjectCreateRequest : public HttpRequest
{
public:
- ASMObjectCreateRequest(LoginInfo &li, const char *szContact) :
+ ASMObjectCreateRequest(LoginInfo &li, const char *szContact, const char *szFileName) :
HttpRequest(REQUEST_POST, "api.asm.skype.com/v1/objects")
{
+ flags &= (~NLHRF_DUMPASTEXT);
Headers
- << CHAR_VALUE("Authorization:", CMStringA(::FORMAT, "skype_token %s", li.api.szToken));
+ << CHAR_VALUE("Authorization", CMStringA(::FORMAT, "skype_token %s", li.api.szToken))
+ << CHAR_VALUE("Content-Type", "text/json");
JSONNode node, jPermissions, jPermission(JSON_ARRAY);
jPermissions.set_name("permissions");
jPermission.set_name(szContact);
- jPermission << JSONNode("read", (char*)NULL);
+ //jPermission << JSONNode("read");
jPermissions << jPermission;
- node << JSONNode("type", "pish/image") << jPermissions;
+ node << JSONNode("type", "sharing/file") << JSONNode("filename", szFileName) << jPermissions;
Body << VALUE(node.write().c_str());
@@ -25,10 +27,11 @@ class ASMObjectUploadRequest : public HttpRequest {
public:
ASMObjectUploadRequest(LoginInfo &li, const char *szObject, const PBYTE data, const size_t size) :
- HttpRequest(REQUEST_PUT, FORMAT, "api.asm.skype.com/v1/objects/%s/content/imgpsh", szObject)
+ HttpRequest(REQUEST_PUT, FORMAT, "api.asm.skype.com/v1/objects/%s/content/original", szObject)
{
Headers
- << CHAR_VALUE("Authorization:", CMStringA(::FORMAT, "skype_token %s", li.api.szToken));
+ << CHAR_VALUE("Authorization", CMStringA(::FORMAT, "skype_token %s", li.api.szToken))
+ << CHAR_VALUE("Content-Type", "application/octet-stream");
pData = (char*)mir_alloc(size);
memcpy(pData, data, size);
diff --git a/protocols/SkypeWeb/src/requests/messages.h b/protocols/SkypeWeb/src/requests/messages.h index 66df812202..5132d13003 100644 --- a/protocols/SkypeWeb/src/requests/messages.h +++ b/protocols/SkypeWeb/src/requests/messages.h @@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. class SendMessageRequest : public HttpRequest
{
public:
- SendMessageRequest(const char *username, time_t timestamp, const char *message, LoginInfo &li) :
+ SendMessageRequest(const char *username, time_t timestamp, const char *message, LoginInfo &li, const char *MessageType = nullptr) :
HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages", li.endpoint.szServer, username)
{
Headers
@@ -32,7 +32,7 @@ public: JSONNode node;
node
<< JSONNode("clientmessageid", CMStringA(::FORMAT, "%llu", (ULONGLONG)timestamp))
- << JSONNode("messagetype", "Text")
+ << JSONNode("messagetype", MessageType ? MessageType : "Text")
<< JSONNode("contenttype", "text")
<< JSONNode("content", message);
diff --git a/protocols/SkypeWeb/src/requests/poll.h b/protocols/SkypeWeb/src/requests/poll.h index 25b05d56b1..24c5146de6 100644 --- a/protocols/SkypeWeb/src/requests/poll.h +++ b/protocols/SkypeWeb/src/requests/poll.h @@ -25,6 +25,7 @@ public: HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/endpoints/SELF/subscriptions/0/poll", li.endpoint.szServer)
{
timeout = 60000;
+ flags |= NLHRF_PERSISTENT;
Headers
<< CHAR_VALUE("Accept", "application/json, text/javascript")
<< FORMAT_VALUE("RegistrationToken", "registrationToken=%s", li.endpoint.szToken);
diff --git a/protocols/SkypeWeb/src/requests/trouter.h b/protocols/SkypeWeb/src/requests/trouter.h index 910c442695..1de1dc83ac 100644 --- a/protocols/SkypeWeb/src/requests/trouter.h +++ b/protocols/SkypeWeb/src/requests/trouter.h @@ -132,6 +132,7 @@ public: HttpRequest(REQUEST_GET, FORMAT, "%ssocket.io/1/xhr-polling/%s", socketio.c_str(), sessId.c_str())
{
timeout = 60000;
+ flags |= NLHRF_PERSISTENT;
Url
<< CHAR_VALUE("sr", sr.c_str())
<< CHAR_VALUE("issuer", "edf")
diff --git a/protocols/SkypeWeb/src/skype_db.cpp b/protocols/SkypeWeb/src/skype_db.cpp index 091f776601..06ff6fa8d5 100644 --- a/protocols/SkypeWeb/src/skype_db.cpp +++ b/protocols/SkypeWeb/src/skype_db.cpp @@ -68,7 +68,8 @@ MEVENT CSkypeProto::AppendDBEvent(MCONTACT hContact, MEVENT hEvent, const char * mir_cslock lck(m_AppendMessageLock);
DBEVENTINFO dbei = { sizeof(dbei) };
dbei.cbBlob = db_event_getBlobSize(hEvent);
- dbei.pBlob = mir_ptr<BYTE>((PBYTE)mir_alloc(dbei.cbBlob));
+ mir_ptr<BYTE> blob((PBYTE)mir_alloc(dbei.cbBlob));
+ dbei.pBlob = blob;
db_event_get(hEvent, &dbei);
JSONNode jMsg = JSONNode::parse((char*)dbei.pBlob);
diff --git a/protocols/SkypeWeb/src/skype_db.h b/protocols/SkypeWeb/src/skype_db.h index f8794b0990..ed1edaa653 100644 --- a/protocols/SkypeWeb/src/skype_db.h +++ b/protocols/SkypeWeb/src/skype_db.h @@ -27,6 +27,7 @@ enum SKYPE_DB_EVENT_TYPE SKYPE_DB_EVENT_TYPE_URIOBJ,
SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE,
SKYPE_DB_EVENT_TYPE_MOJI,
+ SKYPE_DB_EVENT_TYPE_FILE,
SKYPE_DB_EVENT_TYPE_UNKNOWN
};
diff --git a/protocols/SkypeWeb/src/skype_events.cpp b/protocols/SkypeWeb/src/skype_events.cpp index e3c35af674..f48cbb1e9f 100644 --- a/protocols/SkypeWeb/src/skype_events.cpp +++ b/protocols/SkypeWeb/src/skype_events.cpp @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "stdafx.h"
-#define INVALID_DATA Translate("Invalid data!")
+#define INVALID_DATA Translate("SkypeWeb error: Invalid data!")
INT_PTR CSkypeProto::GetEventText(WPARAM, LPARAM lParam)
{
@@ -135,13 +135,14 @@ INT_PTR CSkypeProto::GetEventText(WPARAM, LPARAM lParam) }
break;
}
+ case SKYPE_DB_EVENT_TYPE_FILE:
case SKYPE_DB_EVENT_TYPE_MOJI:
case SKYPE_DB_EVENT_TYPE_URIOBJ:
{
HXML xml = xmlParseString(ptrT(mir_utf8decodeT((char*)pEvent->dbei->pBlob)), 0, _T("URIObject"));
if (xml != NULL)
{
- szText.Append(_T2A(xmlGetText(xml)));
+ //szText.Append(_T2A(xmlGetText(xml)));
HXML xmlA = xmlGetChildByPath(xml, _T("a"), 0);
if (xmlA != NULL)
{
diff --git a/protocols/SkypeWeb/src/skype_files.cpp b/protocols/SkypeWeb/src/skype_files.cpp index 38cb2f7357..451cf2d9dc 100644 --- a/protocols/SkypeWeb/src/skype_files.cpp +++ b/protocols/SkypeWeb/src/skype_files.cpp @@ -18,24 +18,24 @@ void CSkypeProto::SendFileThread(void *p) //SendFileFiled(fup, VKERR_OFFLINE);
return;
}
- if (!fup->IsAccess()) {
- //SendFileFiled(fup, VKERR_FILE_NOT_EXIST);
- return;
- }
+// if (!fup->IsAccess()) {
+// //SendFileFiled(fup, VKERR_FILE_NOT_EXIST);
+// return;
+// }
- ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)fup);
+ ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, (HANDLE)fup);
- SendRequest(new ASMObjectCreateRequest(li, CMStringA(FORMAT, "%d:%s", isChatRoom(fup->hContact) ? 19 : 8, ptrA(getStringA(fup->hContact, SKYPE_SETTINGS_ID)))), &CSkypeProto::OnASMObjectCreated, fup);
+ SendRequest(new ASMObjectCreateRequest(li, CMStringA(FORMAT, "%d:%s", isChatRoom(fup->hContact) ? 19 : 8, ptrA(getStringA(fup->hContact, SKYPE_SETTINGS_ID))), T2Utf(fup->tszFileName)), &CSkypeProto::OnASMObjectCreated, fup);
}
void CSkypeProto::OnASMObjectCreated(const NETLIBHTTPREQUEST *response, void *arg)
{
CFileUploadParam *fup = (CFileUploadParam*)arg;
- if (response->pData)
+ if (response && response->pData)
{
JSONNode node = JSONNode::parse((char*)response->pData);
std::string strObjectId = node["id"].as_string();
-
+ fup->uid = mir_strdup(strObjectId.c_str());
FILE *pFile = _tfopen(fup->tszFileName, _T("rb"));
if (pFile == NULL) return;
@@ -48,20 +48,39 @@ void CSkypeProto::OnASMObjectCreated(const NETLIBHTTPREQUEST *response, void *ar }
fseek(pFile, 0, SEEK_SET);
-
- mir_ptr<BYTE> pData((PBYTE)mir_alloc(lFileLen));
+
+ mir_ptr<BYTE> pData((BYTE*)mir_alloc(lFileLen));
long lBytes = (long)fread(pData, sizeof(BYTE), lFileLen, pFile);
if (lBytes != lFileLen) {
+ fclose(pFile);
mir_free(pData);
return;
}
- SendRequest(new ASMObjectUploadRequest(li, strObjectId.c_str(), pData, lBytes));
+ fup->size = lBytes;
+ ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)fup);
+ SendRequest(new ASMObjectUploadRequest(li, strObjectId.c_str(), pData, lBytes), &CSkypeProto::OnASMObjectUploaded, fup);
}
}
void CSkypeProto::OnASMObjectUploaded(const NETLIBHTTPREQUEST *response, void *arg)
{
CFileUploadParam *fup = (CFileUploadParam*)arg;
- char *szUrl = response->szUrl;
+ if (response == nullptr) return;
+ CMStringA url(response->szUrl);
+
+ HXML xml = xmlCreateNode(L"URIObject", nullptr, 0);
+ HXML xmlTitle = xmlAddChild(xml, L"Title", fup->tszFileName);
+ HXML xmlDescr = xmlAddChild(xml, L"Description", fup->tszDesc);
+ HXML xmlA = xmlAddChild(xml, L"a", CMStringW(FORMAT, L"https://login.skype.com/login/sso?go=webclient.xmm&docid=%s", _A2T(fup->uid)));
+ HXML xmlOrigName = xmlAddChild(xml, L"OriginalName", fup->tszFileName);
+ HXML xmlSize = xmlAddChild(xml, L"FileSize", CMStringW(FORMAT, L"%d", fup->size));
+
+ xmlAddAttr(xml, L"Type", L"File.1");
+ xmlAddAttr(xml, L"uri", CMStringW(FORMAT, L"https://api.asm.skype.com/v1/objects/%s", _A2T(fup->uid)));
+ xmlAddAttr(xml, L"url_thumbnail", CMStringW(FORMAT, L"https://api.asm.skype.com/v1/objects/%s/views/thumbnail", _A2T(fup->uid)));
+
+ SendRequest(new SendMessageRequest(ptrA(getStringA(fup->hContact, SKYPE_SETTINGS_ID)), time(NULL), T2Utf(xmlToString(xml, nullptr)), li, "RichText/Media_GenericFile"));
+ xmlDestroyNode(xml);
+ ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, (HANDLE)fup);
}
\ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 32550276f8..e3e9e6df10 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -241,6 +241,10 @@ void CSkypeProto::OnPrivateMessageEvent(const JSONNode &node) {
AddDbEvent(SKYPE_DB_EVENT_TYPE_MOJI, hContact, timestamp, DBEF_UTF, strContent.c_str(), szMessageId);
}
+ else if (strMessageType == "RichText/Media_GenericFile")
+ {
+ AddDbEvent(SKYPE_DB_EVENT_TYPE_FILE, hContact, timestamp, DBEF_UTF, strContent.c_str(), szMessageId);
+ }
//else if (messageType == "Event/SkypeVideoMessage") {}
//else if (messageType.c_str() == "RichText/Location") {}
else
diff --git a/protocols/SkypeWeb/src/skype_polling.cpp b/protocols/SkypeWeb/src/skype_polling.cpp index 3e5ccdd9e1..196d7ad731 100644 --- a/protocols/SkypeWeb/src/skype_polling.cpp +++ b/protocols/SkypeWeb/src/skype_polling.cpp @@ -30,6 +30,7 @@ void CSkypeProto::PollingThread(void*) while ((nErrors < POLLING_ERRORS_LIMIT) && m_iStatus != ID_STATUS_OFFLINE)
{
PollRequest *request = new PollRequest(li);
+ request->nlc = m_pollingConnection;
NLHR_PTR response(request->Send(m_hNetlibUser));
delete request;
@@ -74,7 +75,7 @@ void CSkypeProto::PollingThread(void*) }
}
m_pollingConnection = response->nlc;
- } // fallthrough
+ }
if (m_iStatus != ID_STATUS_OFFLINE)
{
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index adff39a405..8a99ced993 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -97,7 +97,7 @@ DWORD_PTR CSkypeProto::GetCaps(int type, MCONTACT) switch (type)
{
case PFLAGNUM_1:
- return PF1_IM | PF1_AUTHREQ | PF1_CHAT | PF1_BASICSEARCH | PF1_MODEMSG;
+ return PF1_IM | PF1_AUTHREQ | PF1_CHAT | PF1_BASICSEARCH | PF1_MODEMSG | PF1_FILE;
case PFLAGNUM_2:
return PF2_ONLINE | PF2_INVISIBLE | PF2_SHORTAWAY | PF2_HEAVYDND;
case PFLAGNUM_3:
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 0954790c7b..4681836833 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -324,8 +324,8 @@ private: mir_free(lst[i]);
}
- __forceinline bool IsOnline()
- { return (m_iStatus > ID_STATUS_OFFLINE && m_hPollingThread);
+ __forceinline bool IsOnline() const
+ { return (m_iStatus > ID_STATUS_OFFLINE);
}
__forceinline bool IsMe(const char *szSkypename)
diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index e7b1057a49..a539328feb 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -142,6 +142,7 @@ void CSkypeProto::TRouterThread(void*) while (errors < POLLING_ERRORS_LIMIT && m_iStatus > ID_STATUS_OFFLINE)
{
TrouterPollRequest *request = new TrouterPollRequest(TRouter.socketIo, TRouter.connId, TRouter.st, TRouter.se, TRouter.sig, TRouter.instance, TRouter.ccid, TRouter.sessId);
+ request->nlc = m_TrouterConnection;
NLHR_PTR response(request->Send(m_hNetlibUser));
delete request;
if (response == NULL)
@@ -171,7 +172,7 @@ void CSkypeProto::TRouterThread(void*) m_hTrouterHealthEvent.Wait();
}
m_TrouterConnection = response->nlc;
- } // fallthrough
+ }
}
m_hTrouterThread = NULL;
m_TrouterConnection = NULL;
diff --git a/protocols/SkypeWeb/src/skype_utils.h b/protocols/SkypeWeb/src/skype_utils.h index 084e1393a3..df74ce5acf 100644 --- a/protocols/SkypeWeb/src/skype_utils.h +++ b/protocols/SkypeWeb/src/skype_utils.h @@ -93,6 +93,8 @@ struct CFileUploadParam : public MZeroedObject { ptrT tszDesc;
char* atr;
char* fname;
+ char *uid;
+ size_t size;
MCONTACT hContact;
__forceinline CFileUploadParam(MCONTACT _hContact, const TCHAR* _desc, TCHAR** _files) : hContact(_hContact), tszDesc(mir_tstrdup(_desc)), tszFileName(mir_tstrdup(_files[0])) {};
diff --git a/protocols/SkypeWeb/src/stdafx.h b/protocols/SkypeWeb/src/stdafx.h index 01747e1deb..4a18fd8ea4 100644 --- a/protocols/SkypeWeb/src/stdafx.h +++ b/protocols/SkypeWeb/src/stdafx.h @@ -125,7 +125,7 @@ struct MessageId #include "requests\chatrooms.h"
#include "requests\trouter.h"
#include "requests\mslogin.h"
-#include "requests\asm\images.h"
+#include "requests\asm\files.h"
#include "request_queue.h"
#include "skype_proto.h"
|