diff options
Diffstat (limited to 'protocols')
| -rw-r--r-- | protocols/SkypeWeb/src/common.h | 1 | ||||
| -rw-r--r-- | protocols/SkypeWeb/src/requests/avatars.h | 4 | ||||
| -rw-r--r-- | protocols/SkypeWeb/src/skype_avatars.cpp | 66 | ||||
| -rw-r--r-- | protocols/SkypeWeb/src/skype_proto.cpp | 7 | ||||
| -rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 7 | 
5 files changed, 82 insertions, 3 deletions
diff --git a/protocols/SkypeWeb/src/common.h b/protocols/SkypeWeb/src/common.h index 405836348b..ab5787e07f 100644 --- a/protocols/SkypeWeb/src/common.h +++ b/protocols/SkypeWeb/src/common.h @@ -37,6 +37,7 @@  #include <m_timezones.h>
  #include <m_version.h>
  #include <m_gui.h>
 +#include <m_imgsrvc.h>
  struct CSkypeProto;
 diff --git a/protocols/SkypeWeb/src/requests/avatars.h b/protocols/SkypeWeb/src/requests/avatars.h index bee522e91f..c45c94c1ed 100644 --- a/protocols/SkypeWeb/src/requests/avatars.h +++ b/protocols/SkypeWeb/src/requests/avatars.h @@ -14,11 +14,11 @@ class SetAvatarRequest : public HttpRequest  {
  public:
  	SetAvatarRequest(const char *token, const char *skypename, const char *data) :
 -		HttpRequest(REQUEST_PUT, FORMAT, "api.skype.com/users/%s/profile/avatar ", skypename)
 +		HttpRequest(REQUEST_PUT, FORMAT, "api.skype.com/users/%s/profile/avatar", skypename)
  	{
  		Headers
  			<< CHAR_VALUE("X-Skypetoken", token)
 -			<< CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
 +			<< CHAR_VALUE("Content-Type", "image/jpg");
  		Body << VALUE(data);
  	}
 diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp index bdc8e2e45a..caa9ac88e0 100644 --- a/protocols/SkypeWeb/src/skype_avatars.cpp +++ b/protocols/SkypeWeb/src/skype_avatars.cpp @@ -57,6 +57,16 @@ void CSkypeProto::OnReceiveAvatar(const NETLIBHTTPREQUEST *response, void *arg)  	ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &AI, 0);
  }
 +void CSkypeProto::OnSentAvatar(const NETLIBHTTPREQUEST *response)
 +{
 +	if (response == NULL)
 +		return;
 +
 +	JSONROOT root(response->pData);
 +	if (root == NULL)
 +		return;
 +}
 +
  INT_PTR CSkypeProto::SvcGetAvatarInfo(WPARAM, LPARAM lParam)
  {
  	PROTO_AVATAR_INFORMATIONT* AI = (PROTO_AVATAR_INFORMATIONT*)lParam;
 @@ -136,4 +146,58 @@ void CSkypeProto::SetAvatarUrl(MCONTACT hContact, CMString &tszUrl)  		AI.format = ProtoGetAvatarFormat(AI.filename);
  		ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&AI, 0);
  	}
 -}
\ No newline at end of file +}
 +
 +INT_PTR CSkypeProto::SvcSetMyAvatar(WPARAM wParam, LPARAM lParam)
 +{
 +	TCHAR *path = (TCHAR*)lParam;
 +	TCHAR avatarPath[MAX_PATH];
 +	GetAvatarFileName(NULL, avatarPath, SIZEOF(avatarPath));
 +	if (path != NULL)
 +	{
 +		if (!CopyFile(path, avatarPath, FALSE))
 +		{
 +			debugLogA("CSkypeProto::SetMyAvatar: failed to copy new avatar to avatar cache");
 +			return -1;
 +		}
 +
 +		size_t length;
 +		char *data;
 +		FILE *hFile = _tfopen(path, L"rb");
 +		if (!hFile)
 +		{
 +			debugLogA("CSkypeProto::SetMyAvatar: failed to open avatar file");
 +			return -1;
 +		}
 +
 +		fseek(hFile, 0, SEEK_END);
 +		length = ftell(hFile);
 +		rewind(hFile);
 +
 +		data = (char*)mir_alloc(length);
 +		size_t read = fread(data, sizeof(char), length, hFile);
 +		if (read != length)
 +		{
 +			fclose(hFile);
 +			debugLogA("CToxProto::SetToxAvatar: failed to read avatar file");
 +			return -1;
 +		}
 +		fclose(hFile);
 +
 +
 +		ptrA token(getStringA("TokenSecret"));
 +		ptrA skypename(getStringA("Skypename"));
 +		PushRequest(new SetAvatarRequest(token, skypename, data), &CSkypeProto::OnSentAvatar);
 +	}
 +	else
 +	{
 +		if (IsFileExists(avatarPath))
 +		{
 +			DeleteFile(avatarPath);
 +		}
 +
 +		//db_unset(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH);
 +	}
 +
 +	return 0;
 +}
 diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 75a42b1acc..6434ec4b90 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -17,9 +17,16 @@ PROTO<CSkypeProto>(protoName, userName), password(NULL)  	requestQueue = new RequestQueue(m_hNetlibUser);
  	CreateProtoService(PS_CREATEACCMGRUI, &CSkypeProto::OnAccountManagerInit);
 +	
  	CreateProtoService(PS_GETAVATARINFOT, &CSkypeProto::SvcGetAvatarInfo);
  	CreateProtoService(PS_GETAVATARCAPS, &CSkypeProto::SvcGetAvatarCaps);
  	CreateProtoService(PS_GETMYAVATART, &CSkypeProto::SvcGetMyAvatar);
 +	CreateProtoService(PS_SETMYAVATART, &CSkypeProto::SvcSetMyAvatar);
 +
 +	m_tszAvatarFolder = std::tstring(VARST(_T("%miranda_avatarcache%"))) + _T("\\") + m_tszUserName;
 +	DWORD dwAttributes = GetFileAttributes(m_tszAvatarFolder.c_str());
 +	if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
 +		CreateDirectoryTreeT(m_tszAvatarFolder.c_str());
  	// custom event
  	DBEVENTTYPEDESCR dbEventType = { sizeof(dbEventType) };
 diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 84cb3705e8..d85ccb797c 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -102,9 +102,15 @@ private:  	int __cdecl OnAccountLoaded(WPARAM, LPARAM);
  	INT_PTR __cdecl OnAccountManagerInit(WPARAM, LPARAM);
 +	
 +	std::tstring m_tszAvatarFolder;
 +
  	INT_PTR __cdecl SvcGetAvatarInfo(WPARAM, LPARAM);
  	INT_PTR __cdecl SvcGetAvatarCaps(WPARAM, LPARAM);
  	INT_PTR __cdecl SvcGetMyAvatar(WPARAM, LPARAM);
 +	INT_PTR __cdecl SvcSetMyAvatar(WPARAM, LPARAM);
 +
 +	int InternalSetAvatar(MCONTACT hContact, const char *szJid, const TCHAR *ptszFileName);
  	// requests
  	void PushRequest(HttpRequest *request);
 @@ -165,6 +171,7 @@ private:  	void ReloadAvatarInfo(MCONTACT hContact);
  	void GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen);
  	void OnReceiveAvatar(const NETLIBHTTPREQUEST *response, void *arg);
 +	void OnSentAvatar(const NETLIBHTTPREQUEST *response);
  	MCONTACT GetContact(const char *skypename);
  | 
