summaryrefslogtreecommitdiff
path: root/protocols/SkypeWeb/src/requests/files.h
blob: 6afd64d7f5b48da13b08caf9f99df239d6fcd481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once

struct ASMObjectCreateRequest : public AsyncHttpRequest
{
	ASMObjectCreateRequest(CSkypeProto *ppro, CFileUploadParam *fup) :
		AsyncHttpRequest(REQUEST_POST, HOST_OTHER, "https://api.asm.skype.com/v1/objects", &CSkypeProto::OnASMObjectCreated)
	{
		flags &= (~NLHRF_DUMPASTEXT);
		pUserInfo = fup;
		
		AddHeader("Authorization", CMStringA(FORMAT, "skype_token %s", ppro->m_szApiToken.get()));
		AddHeader("Content-Type", "text/json");
		AddHeader("X-Client-Version", "0/0.0.0.0");

		CMStringA szContact(FORMAT, "%d:%s", ppro->isChatRoom(fup->hContact) ? 19 : 8, ppro->getId(fup->hContact).c_str());
		T2Utf uszFileName(fup->tszFileName);
		const char *szFileName = strrchr(uszFileName.get() + 1, '\\');

		JSONNode node, jPermissions, jPermission(JSON_ARRAY);
		jPermissions.set_name("permissions");
		jPermission.set_name(szContact.c_str());
		jPermission << CHAR_PARAM("", "read");
		jPermissions << jPermission;
		node << CHAR_PARAM("type", "sharing/file") << CHAR_PARAM("filename", szFileName) << jPermissions;
		m_szParam = node.write().c_str();
	}
};

struct ASMObjectUploadRequest : public AsyncHttpRequest
{
	ASMObjectUploadRequest(CSkypeProto *ppro, const char *szObject, const PBYTE data, const size_t size, CFileUploadParam *fup) :
		AsyncHttpRequest(REQUEST_PUT, HOST_OTHER, 0, &CSkypeProto::OnASMObjectUploaded)
	{
		m_szUrl.AppendFormat("https://api.asm.skype.com/v1/objects/%s/content/original", szObject);
		pUserInfo = fup;

		AddHeader("Authorization", CMStringA(FORMAT, "skype_token %s", ppro->m_szApiToken.get()));
		AddHeader("Content-Type", "application/octet-stream");

		pData = (char*)mir_alloc(size);
		memcpy(pData, data, size);
		dataLength = (int)size;
	}

	~ASMObjectUploadRequest()
	{
		mir_free(pData);
	}
};