diff options
Diffstat (limited to 'protocols/Tlen')
| -rw-r--r-- | protocols/Tlen/src/jabber.h | 1 | ||||
| -rw-r--r-- | protocols/Tlen/src/jabber_util.cpp | 11 | ||||
| -rw-r--r-- | protocols/Tlen/src/jabber_ws.cpp | 4 | ||||
| -rw-r--r-- | protocols/Tlen/src/tlen_avatar.cpp | 70 | 
4 files changed, 27 insertions, 59 deletions
| diff --git a/protocols/Tlen/src/jabber.h b/protocols/Tlen/src/jabber.h index c62d1110e5..deab57ac51 100644 --- a/protocols/Tlen/src/jabber.h +++ b/protocols/Tlen/src/jabber.h @@ -464,7 +464,6 @@ char *JabberTextEncode(const char *str);  char *JabberTextDecode(const char *str);
  char *JabberBase64Encode(const char *buffer, int bufferLen);
  char *JabberBase64Decode(const char *buffer, int *resultLen);
 -int JabberGetPictureType(const char* buf);
  void TlenLogMessage(TlenProtocol *proto, HANDLE hContact, DWORD flags, const char *message);
  BOOL IsAuthorized(TlenProtocol *proto, const char *jid);
  //char *JabberGetVersionText();
 diff --git a/protocols/Tlen/src/jabber_util.cpp b/protocols/Tlen/src/jabber_util.cpp index 00ce04e579..0fe8d0b10d 100644 --- a/protocols/Tlen/src/jabber_util.cpp +++ b/protocols/Tlen/src/jabber_util.cpp @@ -615,17 +615,6 @@ void JabberStringAppend(char **str, int *sizeAlloced, const char *fmt, ...)  	va_end(vararg);
  }
 -int JabberGetPictureType( const char* buf )
 -{
 -	if ( buf != NULL ) {
 -		if ( memcmp( buf, "GIF89", 5 ) == 0 )    return PA_FORMAT_GIF;
 -		if ( memcmp( buf, "\x89PNG", 4 ) == 0 )  return PA_FORMAT_PNG;
 -		if ( memcmp( buf, "BM", 2 ) == 0 )       return PA_FORMAT_BMP;
 -		if ( memcmp( buf, "\xFF\xD8", 2 ) == 0 ) return PA_FORMAT_JPEG;
 -	}
 -	return PA_FORMAT_UNKNOWN;
 -}
 -
  BOOL IsAuthorized(TlenProtocol *proto, const char *jid)
  {
  	JABBER_LIST_ITEM *item = JabberListGetItemPtr(proto, LIST_ROSTER, jid);
 diff --git a/protocols/Tlen/src/jabber_ws.cpp b/protocols/Tlen/src/jabber_ws.cpp index c2cb853b02..b1cb066d7a 100644 --- a/protocols/Tlen/src/jabber_ws.cpp +++ b/protocols/Tlen/src/jabber_ws.cpp @@ -32,13 +32,13 @@ BOOL JabberWsInit(TlenProtocol *proto)  	nlu.cbSize = sizeof(nlu);
  	nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_TCHAR;	// | NUF_HTTPGATEWAY;
 -	mir_sntprintf( name, SIZEOF(name), TranslateT("%s connection"), proto->m_tszUserName);
 +	mir_sntprintf(name, SIZEOF(name), TranslateT("%s connection"), proto->m_tszUserName);
  	nlu.ptszDescriptiveName = name;
  	nlu.szSettingsModule = proto->m_szModuleName;
  	proto->hNetlibUser = (HANDLE) CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM) &nlu);
  	nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_NOOPTIONS | NUF_TCHAR;
 -	mir_sntprintf( name, SIZEOF(name), TranslateT("%s SOCKS connection"), proto->m_tszUserName);
 +	mir_sntprintf(name, SIZEOF(name), TranslateT("%s SOCKS connection"), proto->m_tszUserName);
  	nlu.ptszDescriptiveName = name;
  	proto->hFileNetlibUser = (HANDLE) CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM) &nlu);
  	nlus.cbSize = sizeof(nlus);
 diff --git a/protocols/Tlen/src/tlen_avatar.cpp b/protocols/Tlen/src/tlen_avatar.cpp index 1df8c8836d..28f3953061 100644 --- a/protocols/Tlen/src/tlen_avatar.cpp +++ b/protocols/Tlen/src/tlen_avatar.cpp @@ -33,45 +33,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  void TlenGetAvatarFileName(TlenProtocol *proto, JABBER_LIST_ITEM *item, TCHAR* ptszDest, int cbLen)
  {
 -	DWORD dwAttributes;
 -	int tPathLen;
  	int format = PA_FORMAT_PNG;
 -	TCHAR* tszFileType;
  	TCHAR* tmpPath = Utils_ReplaceVarsT( TEXT("%miranda_avatarcache%") );
 -	tPathLen = mir_sntprintf( ptszDest, cbLen, TEXT("%s\\Tlen"), tmpPath );
 +	int tPathLen = mir_sntprintf(ptszDest, cbLen, TEXT("%s\\Tlen"), tmpPath );
  	mir_free(tmpPath);
 -	dwAttributes = GetFileAttributes( ptszDest );
 +	DWORD dwAttributes = GetFileAttributes( ptszDest );
  	if (dwAttributes == 0xffffffff || ( dwAttributes & FILE_ATTRIBUTE_DIRECTORY ) == 0)
  		CreateDirectoryTreeT(ptszDest);
  	ptszDest[ tPathLen++ ] = '\\';
 -	if (item != NULL) {
 +	if (item != NULL)
  		format = item->avatarFormat;
 -	} else if (proto->threadData != NULL) {
 +	else if (proto->threadData != NULL)
  		format = proto->threadData->avatarFormat;
 -	} else {
 +	else
  		format = db_get_dw(NULL, proto->m_szModuleName, "AvatarFormat", PA_FORMAT_UNKNOWN);
 -	}
 -	tszFileType = TEXT("png");
 -	switch(format) {
 -		case PA_FORMAT_JPEG: tszFileType = TEXT("jpg");   break;
 -		case PA_FORMAT_ICON: tszFileType = TEXT("ico");   break;
 -		case PA_FORMAT_PNG:  tszFileType = TEXT("png");   break;
 -		case PA_FORMAT_GIF:  tszFileType = TEXT("gif");   break;
 -		case PA_FORMAT_BMP:  tszFileType = TEXT("bmp");   break;
 -	}
 -	if ( item != NULL ) {
 -		char* hash;
 -		hash = JabberSha1(item->jid);
 -		TCHAR* hashT = mir_a2t(hash);
 -		mir_free( hash );
 -		mir_sntprintf( ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%s.%s"), hashT, tszFileType );
 -		mir_free( hashT );
 -	} else {
 -		TCHAR* m_tszModuleName = mir_a2t(proto->m_szModuleName);
 -		mir_sntprintf( ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%s_avatar.%s"), m_tszModuleName, tszFileType );
 -		mir_free( m_tszModuleName );
 -	}
 +
 +	const TCHAR *tszFileType = ProtoGetAvatarExtension(format);
 +	if ( item != NULL )
 +		mir_sntprintf(ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%S%s"), ptrA( JabberSha1(item->jid)), tszFileType);
 +	else
 +		mir_sntprintf(ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%S_avatar%s"), proto->m_szModuleName, tszFileType);
  }
  static void RemoveAvatar(TlenProtocol *proto, HANDLE hContact) {
 @@ -88,15 +70,13 @@ static void RemoveAvatar(TlenProtocol *proto, HANDLE hContact) {  }
  static void SetAvatar(TlenProtocol *proto, HANDLE hContact, JABBER_LIST_ITEM *item, char *data, int len, DWORD format) {
 -	FILE* out;
  	TCHAR filename[MAX_PATH];
  	char md5[33];
  	mir_md5_state_t ctx;
  	DWORD digest[4];
 -	if (format == PA_FORMAT_UNKNOWN && len > 4) {
 -		format = JabberGetPictureType(data);
 -	}
 +	if (format == PA_FORMAT_UNKNOWN && len > 4)
 +		format = ProtoGetBufferFormat(data);
  	mir_md5_init( &ctx );
  	mir_md5_append( &ctx, ( BYTE* )data, len);
 @@ -114,10 +94,10 @@ static void SetAvatar(TlenProtocol *proto, HANDLE hContact, JABBER_LIST_ITEM *it  	}
  	TlenGetAvatarFileName(proto, item, filename, sizeof filename );
  	DeleteFile(filename);
 -	out = _tfopen( filename, TEXT("wb") );
 -	if ( out != NULL ) {
 -		fwrite( data, len, 1, out );
 -		fclose( out );
 +	FILE *out = _tfopen( filename, TEXT("wb") );
 +	if (out != NULL) {
 +		fwrite(data, len, 1, out);
 +		fclose(out);
  		db_set_ts(hContact, "ContactPhoto", "File", filename );
  		db_set_s(hContact, proto->m_szModuleName, "AvatarHash",  md5);
  		db_set_dw(hContact, proto->m_szModuleName, "AvatarFormat",  format);
 @@ -274,20 +254,20 @@ static void TlenGetAvatarThread(void *ptr) {  				if (resp->dataLength > 0) {
  					int i;
  					for (i=0; i<resp->headersCount; i++ ) {
 -						if (strcmpi(resp->headers[i].szName, "Content-Type") == 0) {
 -							if (strcmpi(resp->headers[i].szValue, "image/png") == 0) {
 +						if (!strcmpi(resp->headers[i].szName, "Content-Type")) {
 +							if (!strcmpi(resp->headers[i].szValue, "image/png"))
  								format = PA_FORMAT_PNG;
 -							} else if (strcmpi(resp->headers[i].szValue, "image/x-png") == 0) {
 +							else if (!strcmpi(resp->headers[i].szValue, "image/x-png"))
  								format = PA_FORMAT_PNG;
 -							} else if (strcmpi(resp->headers[i].szValue, "image/jpeg") == 0) {
 +							else if (!strcmpi(resp->headers[i].szValue, "image/jpeg"))
  								format = PA_FORMAT_JPEG;
 -							} else if (strcmpi(resp->headers[i].szValue, "image/jpg") == 0) {
 +							else if (!strcmpi(resp->headers[i].szValue, "image/jpg"))
  								format = PA_FORMAT_JPEG;
 -							} else if (strcmpi(resp->headers[i].szValue, "image/gif") == 0) {
 +							else if (!strcmpi(resp->headers[i].szValue, "image/gif"))
  								format = PA_FORMAT_GIF;
 -							} else if (strcmpi(resp->headers[i].szValue, "image/bmp") == 0) {
 +							else if (!strcmpi(resp->headers[i].szValue, "image/bmp"))
  								format = PA_FORMAT_BMP;
 -							}
 +
  							break;
  						}
  					}
 | 
