diff options
author | Szymon Tokarz <wsx22@o2.pl> | 2013-01-16 00:30:40 +0000 |
---|---|---|
committer | Szymon Tokarz <wsx22@o2.pl> | 2013-01-16 00:30:40 +0000 |
commit | 78f816ea826eee970c84fd1f9c43d8d3445540a8 (patch) | |
tree | 4b7a88e5bb0c6f768bd4624e28b52ccae918b5e9 /protocols | |
parent | bb8ab1271bfc9a1559e3357e9aa781a0f795ae6f (diff) |
Gadu-Gadu protocol
- avatar related code cleanup and fixes
- workaround for avs issue (when custom defined protected avatar could be not show if contact has no protocol avatar)
git-svn-id: http://svn.miranda-ng.org/main/trunk@3117 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Gadu-Gadu/src/avatar.cpp | 29 | ||||
-rw-r--r-- | protocols/Gadu-Gadu/src/core.cpp | 6 | ||||
-rw-r--r-- | protocols/Gadu-Gadu/src/gg_proto.h | 4 | ||||
-rw-r--r-- | protocols/Gadu-Gadu/src/image.cpp | 4 | ||||
-rw-r--r-- | protocols/Gadu-Gadu/src/services.cpp | 63 |
5 files changed, 73 insertions, 33 deletions
diff --git a/protocols/Gadu-Gadu/src/avatar.cpp b/protocols/Gadu-Gadu/src/avatar.cpp index bd5df31d5d..c6b49157fd 100644 --- a/protocols/Gadu-Gadu/src/avatar.cpp +++ b/protocols/Gadu-Gadu/src/avatar.cpp @@ -150,21 +150,21 @@ typedef struct char *AvatarURL;
} GGGETAVATARDATA;
-void GGPROTO::getAvatar(HANDLE hContact, char *szAvatarURL)
+void GGPROTO::requestAvatarTransfer(HANDLE hContact, char *szAvatarURL)
{
#ifdef DEBUGMODE
- netlog("getAvatar(): start");
+ netlog("requestAvatarTransfer(): start");
#endif
if (pth_avatar.dwThreadId) {
GGGETAVATARDATA *data = (GGGETAVATARDATA*)mir_alloc(sizeof(GGGETAVATARDATA));
data->hContact = hContact;
data->AvatarURL = mir_strdup(szAvatarURL);
- gg_EnterCriticalSection(&avatar_mutex, "getAvatar", 1, "avatar_mutex", 1);
+ gg_EnterCriticalSection(&avatar_mutex, "requestAvatarTransfer", 1, "avatar_mutex", 1);
list_add(&avatar_transfers, data, 0);
- gg_LeaveCriticalSection(&avatar_mutex, "getAvatar", 1, 1, "avatar_mutex", 1);
+ gg_LeaveCriticalSection(&avatar_mutex, "requestAvatarTransfer", 1, 1, "avatar_mutex", 1);
} else {
- netlog("getAvatar(): Can not list_add element to avatar_transfers list. No pth_avatar.dwThreadId");
+ netlog("requestAvatarTransfer(): Can not list_add element to avatar_transfers list. No pth_avatar.dwThreadId");
}
}
@@ -174,10 +174,10 @@ typedef struct int iWaitFor;
} GGREQUESTAVATARDATA;
-void GGPROTO::requestAvatar(HANDLE hContact, int iWaitFor)
+void GGPROTO::requestAvatarInfo(HANDLE hContact, int iWaitFor)
{
#ifdef DEBUGMODE
- netlog("requestAvatar(): start");
+ netlog("requestAvatarInfo(): start");
#endif
if (pth_avatar.dwThreadId) {
@@ -185,12 +185,12 @@ void GGPROTO::requestAvatar(HANDLE hContact, int iWaitFor) GGREQUESTAVATARDATA *data = (GGREQUESTAVATARDATA*)mir_alloc(sizeof(GGREQUESTAVATARDATA));
data->hContact = hContact;
data->iWaitFor = iWaitFor;
- gg_EnterCriticalSection(&avatar_mutex, "requestAvatar", 2, "avatar_mutex", 1);
+ gg_EnterCriticalSection(&avatar_mutex, "requestAvatarInfo", 2, "avatar_mutex", 1);
list_add(&avatar_requests, data, 0);
- gg_LeaveCriticalSection(&avatar_mutex, "requestAvatar", 2, 1, "avatar_mutex", 1);
+ gg_LeaveCriticalSection(&avatar_mutex, "requestAvatarInfo", 2, 1, "avatar_mutex", 1);
}
} else {
- netlog("requestAvatar(): Can not list_add element to avatar_requests list. No pth_avatar.dwThreadId");
+ netlog("requestAvatarInfo(): Can not list_add element to avatar_requests list. No pth_avatar.dwThreadId");
}
}
@@ -230,10 +230,15 @@ void __cdecl GGPROTO::avatarrequestthread(void*) PROTO_AVATAR_INFORMATIONT pai = {0};
pai.cbSize = sizeof(pai);
pai.hContact = hContact;
- if (getavatarinfo((WPARAM)GAIF_FORCE, (LPARAM)&pai) != GAIR_WAITFOR)
+ INT_PTR res = getavatarinfo((WPARAM)GAIF_FORCE, (LPARAM)&pai);
+ if (res == GAIR_NOAVATAR){
+ ProtoBroadcastAck(m_szModuleName, hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, NULL, 0);
+ } else if (res == GAIR_SUCCESS) {
ProtoBroadcastAck(m_szModuleName, hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0);
+ } //if GAIR_WAITFOR -> ignore
+ } else {
+ ProtoBroadcastAck(m_szModuleName, hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, 0, 0);
}
- else ProtoBroadcastAck(m_szModuleName, hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, 0, 0);
} else {
gg_LeaveCriticalSection(&avatar_mutex, "avatarrequestthread", 3, 2, "avatar_mutex", 1);
}
diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp index cb31486925..dd73329a0a 100644 --- a/protocols/Gadu-Gadu/src/core.cpp +++ b/protocols/Gadu-Gadu/src/core.cpp @@ -593,7 +593,7 @@ retry: e->event.notify60[i].time, e->event.notify60[i].remote_ip, e->event.notify60[i].remote_port,
e->event.notify60[i].version);
mir_free(descrT);
- requestAvatar(getcontact(e->event.notify60[i].uin, 0, 0, NULL), 0);
+ requestAvatarInfo(getcontact(e->event.notify60[i].uin, 0, 0, NULL), 0);
}
break;
}
@@ -804,7 +804,7 @@ retry: mir_free(descrT);
if (oldstatus == ID_STATUS_OFFLINE && db_get_w(hContact, m_szModuleName, GG_KEY_STATUS, (WORD)ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE)
- requestAvatar(hContact, 0);
+ requestAvatarInfo(hContact, 0);
}
break;
@@ -1197,7 +1197,7 @@ retry: // Avatar change notify
if (type != NULL && !strcmp(type, "28")) {
netlog("mainthread() (%x): Client %s changed his avatar.", this, sender);
- requestAvatar(getcontact(atoi(sender), 0, 0, NULL), 0);
+ requestAvatarInfo(getcontact(atoi(sender), 0, 0, NULL), 0);
}
mir_free(type);
mir_free(sender);
diff --git a/protocols/Gadu-Gadu/src/gg_proto.h b/protocols/Gadu-Gadu/src/gg_proto.h index 3c75f1179d..de9c3af0e1 100644 --- a/protocols/Gadu-Gadu/src/gg_proto.h +++ b/protocols/Gadu-Gadu/src/gg_proto.h @@ -143,8 +143,8 @@ struct GGPROTO : public PROTO_INTERFACE, public MZeroedObject /* Avatar functions */
void getAvatarFilename(HANDLE hContact, TCHAR *pszDest, int cbLen);
- void getAvatar(HANDLE hContact, char *szAvatarURL);
- void requestAvatar(HANDLE hContact, int iWaitFor);
+ void requestAvatarTransfer(HANDLE hContact, char *szAvatarURL);
+ void requestAvatarInfo(HANDLE hContact, int iWaitFor);
void getUserAvatar();
void setAvatar(const TCHAR *szFilename);
void getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts);
diff --git a/protocols/Gadu-Gadu/src/image.cpp b/protocols/Gadu-Gadu/src/image.cpp index 2ffb9e073c..4bb12b042b 100644 --- a/protocols/Gadu-Gadu/src/image.cpp +++ b/protocols/Gadu-Gadu/src/image.cpp @@ -828,9 +828,9 @@ int GGPROTO::img_displayasmsg(HANDLE hContact, void *img) if ( _taccess(szPath, 0)){
int ret = CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)szPath);
if (ret == 0){
- netlog("getAvatarFilename(): Created new directory for image cache: %S.", szPath);
+ netlog("img_displayasmsg(): Created new directory for image cache: %S.", szPath);
} else {
- netlog("getAvatarFilename(): Can not create directory for image cache: %S. errno=%d: %s", szPath, errno, strerror(errno));
+ netlog("img_displayasmsg(): Can not create directory for image cache: %S. errno=%d: %s", szPath, errno, strerror(errno));
TCHAR error[512];
mir_sntprintf(error, SIZEOF(error), TranslateT("Can not create image cache directory. ERROR: %d: %s\n%s"), errno, _tcserror(errno), szPath);
showpopup(m_tszUserName, error, GG_POPUP_ERROR | GG_POPUP_ALLOW_MSGBOX | GG_POPUP_ONCE);
diff --git a/protocols/Gadu-Gadu/src/services.cpp b/protocols/Gadu-Gadu/src/services.cpp index 55ac5ffdce..09067b1ff0 100644 --- a/protocols/Gadu-Gadu/src/services.cpp +++ b/protocols/Gadu-Gadu/src/services.cpp @@ -168,6 +168,37 @@ INT_PTR GGPROTO::getavatarcaps(WPARAM wParam, LPARAM lParam) return 0;
}
+int GetImageFormat(TCHAR *filename)
+{
+ size_t len = lstrlen(filename);
+
+ if (len < 5)
+ return PA_FORMAT_UNKNOWN;
+
+ if (_tcsicmp(_T(".png"), &filename[len-4]) == 0)
+ return PA_FORMAT_PNG;
+
+ if (_tcsicmp(_T(".jpg"), &filename[len-4]) == 0 || _tcsicmp(_T(".jpeg"), &filename[len-4]) == 0)
+ return PA_FORMAT_JPEG;
+
+ if (_tcsicmp(_T(".ico"), &filename[len-4]) == 0)
+ return PA_FORMAT_ICON;
+
+ if (_tcsicmp(_T(".bmp"), &filename[len-4]) == 0 || _tcsicmp(_T(".rle"), &filename[len-4]) == 0)
+ return PA_FORMAT_BMP;
+
+ if (_tcsicmp(_T(".gif"), &filename[len-4]) == 0)
+ return PA_FORMAT_GIF;
+
+ if (_tcsicmp(_T(".swf"), &filename[len-4]) == 0)
+ return PA_FORMAT_SWF;
+
+ if (_tcsicmp(_T(".xml"), &filename[len-4]) == 0)
+ return PA_FORMAT_XML;
+
+ return PA_FORMAT_UNKNOWN;
+}
+
//////////////////////////////////////////////////////////
// gets avatar information
// registered as ProtoService PS_GETAVATARINFOT
@@ -195,24 +226,28 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam) return GAIR_NOAVATAR;
}
- //directly check if contact has static locked avatar setted by AVS
- if (!db_get_s(pai->hContact, "ContactPhoto", "File", &dbv, DBVT_TCHAR)) {
- if ((_tcslen(dbv.ptszVal)>0) && DBGetContactSettingByte(pai->hContact, "ContactPhoto", "Locked", 0)){
- netlog("getavatarinfo(): Incoming request for avatar information. Contact has assigned Locked ContactPhoto. return GAIR_NOAVATAR");
+
+ //directly check if contact has protected user avatar set by AVS, and if yes return it as protocol avatar
+ if (!db_get_s(pai->hContact, "ContactPhoto", "Backup", &dbv, DBVT_TCHAR)) {
+ if ((_tcslen(dbv.ptszVal)>0) && db_get_b(pai->hContact, "ContactPhoto", "Locked", 0)){
+ netlog("getavatarinfo(): Incoming request for avatar information. Contact has assigned Locked ContactPhoto. return GAIR_SUCCESS");
+ _tcscpy_s(pai->filename, SIZEOF(pai->filename) ,dbv.ptszVal);
+ pai->format = GetImageFormat(pai->filename);
DBFreeVariant(&dbv);
- return GAIR_NOAVATAR;
+ return GAIR_SUCCESS;
} else {
DBFreeVariant(&dbv);
}
}
+
if (!db_get_b(pai->hContact, m_szModuleName, GG_KEY_AVATARREQUESTED, GG_KEYDEF_AVATARREQUESTED)) {
- requestAvatar(pai->hContact, 1);
+ requestAvatarInfo(pai->hContact, 1);
if ((wParam & GAIF_FORCE) != 0) {
- netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. requestAvatar() fired. return GAIR_WAITFOR", uin);
+ netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. requestAvatarInfo() fired. return GAIR_WAITFOR", uin);
return GAIR_WAITFOR;
} else {
- netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. requestAvatar() fired. return GAIR_NOAVATAR", uin);
+ netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. requestAvatarInfo() fired. return GAIR_NOAVATAR", uin);
return GAIR_NOAVATAR;
}
}
@@ -249,8 +284,8 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam) netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. Avatar hash unchanged. return GAIR_SUCCESS", uin);
result = GAIR_SUCCESS;
} else {
- getAvatar(pai->hContact, AvatarURL);
- netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. Avatar hash unchanged but file %S does not exist. errno=%d: %s. getAvatar() fired. return GAIR_WAITFOR", uin, pai->filename, errno, strerror(errno));
+ requestAvatarTransfer(pai->hContact, AvatarURL);
+ netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. Avatar hash unchanged but file %S does not exist. errno=%d: %s. requestAvatarTransfer() fired. return GAIR_WAITFOR", uin, pai->filename, errno, strerror(errno));
result = GAIR_WAITFOR;
}
} else if ((wParam & GAIF_FORCE) != 0) {
@@ -261,8 +296,8 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam) showpopup(m_tszUserName, error, GG_POPUP_ERROR);
}
db_set_s(pai->hContact, m_szModuleName, GG_KEY_AVATARHASH, AvatarHash);
- getAvatar(pai->hContact, AvatarURL);
- netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. Avatar hash changed, getAvatar() fired. return GAIR_SUCCESS", uin);
+ requestAvatarTransfer(pai->hContact, AvatarURL);
+ netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. Avatar hash changed, requestAvatarTransfer() fired. return GAIR_WAITFOR", uin);
result = GAIR_WAITFOR;
} else {
netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. Avatar hash changed, but no GAIF_FORCE param. return GAIR_NOAVATAR", uin);
@@ -284,9 +319,9 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam) netlog("getavatarinfo(): Incoming request for avatar information. Contact %d deleted avatar. return GAIR_NOAVATAR", uin);
} else if (AvatarHash != NULL && AvatarSavedHash == NULL) {
db_set_s(pai->hContact, m_szModuleName, GG_KEY_AVATARHASH, AvatarHash);
- getAvatar(pai->hContact, AvatarURL);
+ requestAvatarTransfer(pai->hContact, AvatarURL);
result = GAIR_WAITFOR;
- netlog("getavatarinfo(): Incoming request for avatar information. Contact %d set avatar. getAvatar() fired. return GAIR_WAITFOR", uin);
+ netlog("getavatarinfo(): Incoming request for avatar information. Contact %d set avatar. requestAvatarTransfer() fired. return GAIR_WAITFOR", uin);
} else {
netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. AvatarHash==AvatarSavedHash==NULL, with GAIF_FORCE param. return GAIR_NOAVATAR", uin);
}
|