summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-06-30 20:10:41 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-06-30 20:10:41 +0000
commit916709315ea2044a31adfc0e5b2809fe712358f3 (patch)
treef9aa0dbe9507dd3a36b5167a83608ba9765ed5a4 /protocols
parent8d3522f82f331954a495275a0e23402906d9bb9a (diff)
- major cleanup of GG avatar code
- fix for hangup on exit git-svn-id: http://svn.miranda-ng.org/main/trunk@5198 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Gadu-Gadu/src/avatar.cpp334
-rw-r--r--protocols/Gadu-Gadu/src/core.cpp2
-rw-r--r--protocols/Gadu-Gadu/src/gg.cpp106
-rw-r--r--protocols/Gadu-Gadu/src/gg.h18
-rw-r--r--protocols/Gadu-Gadu/src/gg_proto.cpp18
-rw-r--r--protocols/Gadu-Gadu/src/gg_proto.h11
-rw-r--r--protocols/Gadu-Gadu/src/links.cpp16
-rw-r--r--protocols/Gadu-Gadu/src/services.cpp77
-rw-r--r--protocols/Gadu-Gadu/src/version.h6
9 files changed, 260 insertions, 328 deletions
diff --git a/protocols/Gadu-Gadu/src/avatar.cpp b/protocols/Gadu-Gadu/src/avatar.cpp
index d195d04ad2..307d0de7ae 100644
--- a/protocols/Gadu-Gadu/src/avatar.cpp
+++ b/protocols/Gadu-Gadu/src/avatar.cpp
@@ -41,9 +41,9 @@ void GGPROTO::getAvatarFilename(HANDLE hContact, TCHAR *pszDest, int cbLen)
if (_taccess(pszDest, 0)) {
int ret = CreateDirectoryTreeT(pszDest);
- if (ret == 0){
+ if (ret == 0)
netlog("getAvatarFilename(): Created new directory for avatar cache: %S.", pszDest);
- } else {
+ else {
netlog("getAvatarFilename(): Can not create directory for avatar cache: %S. errno=%d: %s", pszDest, errno, strerror(errno));
TCHAR error[512];
mir_sntprintf(error, SIZEOF(error), TranslateT("Can not create avatars cache directory. ERROR: %d: %s\n%s"), errno, _tcserror(errno), pszDest);
@@ -69,62 +69,47 @@ void GGPROTO::getAvatarFilename(HANDLE hContact, TCHAR *pszDest, int cbLen)
else mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%S avatar.%s"), m_szModuleName, avatartype);
}
-void GGPROTO::getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts)
+bool GGPROTO::getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts)
{
- NETLIBHTTPREQUEST req = {0};
- NETLIBHTTPREQUEST *resp;
+ *avatarurl = *avatarts = NULL;
+
char szUrl[128];
- *avatarurl = NULL;
- *avatarts = NULL;
+ mir_snprintf(szUrl, 128, "http://api.gadu-gadu.pl/avatars/%d/0.xml", uin);
- req.cbSize = sizeof(req);
+ NETLIBHTTPREQUEST req = { sizeof(req) };
req.requestType = REQUEST_GET;
req.szUrl = szUrl;
- mir_snprintf(szUrl, 128, "http://api.gadu-gadu.pl/avatars/%d/0.xml", uin);
req.flags = NLHRF_NODUMP | NLHRF_HTTP11 | NLHRF_REDIRECT;
- resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)netlib, (LPARAM)&req);
- if (resp) {
- if (resp->resultCode == 200 && resp->dataLength > 0 && resp->pData) {
- HXML hXml;
- TCHAR *xmlAction;
- TCHAR *tag;
-
- xmlAction = mir_a2t(resp->pData);
- tag = mir_a2t("result");
- hXml = xi.parseString(xmlAction, 0, tag);
-
- if (hXml != NULL) {
- HXML node;
- char *blank;
-
- mir_free(tag); tag = mir_a2t("users/user/avatars/avatar");
- node = xi.getChildByPath(hXml, tag, 0);
- mir_free(tag); tag = mir_a2t("blank");
- blank = (node != NULL) ? mir_t2a(xi.getAttrValue(node, tag)) : NULL;
-
- if (blank != NULL && strcmp(blank, "1")) {
- mir_free(tag); tag = mir_a2t("users/user/avatars/avatar/originBigAvatar");
- node = xi.getChildByPath(hXml, tag, 0);
- *avatarurl = node != NULL ? mir_t2a(xi.getText(node)) : NULL;
-
- mir_free(tag); tag = mir_a2t("users/user/avatars/avatar/timestamp");
- node = xi.getChildByPath(hXml, tag, 0);
- *avatarts = node != NULL ? mir_t2a(xi.getText(node)) : NULL;
-
- } else {
- *avatarurl = mir_strdup("");
- *avatarts = mir_strdup("");
- }
- mir_free(blank);
- xi.destroyNode(hXml);
- }
- mir_free(tag);
- mir_free(xmlAction);
- }
- else netlog("getAvatarFileInfo(): Invalid response code from HTTP request");
+
+ NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)netlib, (LPARAM)&req);
+ if (resp == NULL) {
+ netlog("getAvatarFileInfo(): No response from HTTP request");
+ return false;
+ }
+
+ if (resp->resultCode != 200 || !resp->dataLength || !resp->pData) {
+ netlog("getAvatarFileInfo(): Invalid response code from HTTP request");
CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp);
+ return false;
+ }
+
+ TCHAR *xmlAction = mir_a2t(resp->pData);
+ HXML hXml = xi.parseString(xmlAction, 0, _T("result"));
+ if (hXml != NULL) {
+ HXML node = xi.getChildByPath(hXml, _T("users/user/avatars/avatar"), 0);
+ const TCHAR *blank = (node != NULL) ? xi.getAttrValue(node, _T("blank")) : NULL;
+ if (blank != NULL && _tcscmp(blank, _T("1"))) {
+ node = xi.getChildByPath(hXml, _T("users/user/avatars/avatar/originBigAvatar"), 0);
+ *avatarurl = node != NULL ? mir_t2a(xi.getText(node)) : NULL;
+
+ node = xi.getChildByPath(hXml, _T("users/user/avatars/avatar/timestamp"), 0);
+ *avatarts = node != NULL ? mir_t2a(xi.getText(node)) : NULL;
+ }
+ xi.destroyNode(hXml);
}
- else netlog("getAvatarFileInfo(): No response from HTTP request");
+ mir_free(xmlAction);
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp);
+ return true;
}
char *gg_avatarhash(char *param)
@@ -143,125 +128,117 @@ char *gg_avatarhash(char *param)
return result;
}
-typedef struct
-{
- HANDLE hContact;
- char *AvatarURL;
-} GGGETAVATARDATA;
-
void GGPROTO::requestAvatarTransfer(HANDLE hContact, char *szAvatarURL)
{
-#ifdef DEBUGMODE
- netlog("requestAvatarTransfer(): start");
-#endif
+ if (pth_avatar.dwThreadId == NULL) {
+ netlog("requestAvatarTransfer(): Can not list_add element to avatar_transfers list. No pth_avatar.dwThreadId");
+ return;
+ }
- if (pth_avatar.dwThreadId) {
- GGGETAVATARDATA *data = (GGGETAVATARDATA*)mir_alloc(sizeof(GGGETAVATARDATA));
+ gg_EnterCriticalSection(&avatar_mutex, "requestAvatarTransfer", 1, "avatar_mutex", 1);
+ if (avatar_transfers.getIndex((GGGETAVATARDATA*)&hContact) == -1) {
+ GGGETAVATARDATA *data = (GGGETAVATARDATA*)mir_alloc(sizeof(GGGETAVATARDATA) + strlen(szAvatarURL)+1);
data->hContact = hContact;
- data->AvatarURL = mir_strdup(szAvatarURL);
- gg_EnterCriticalSection(&avatar_mutex, "requestAvatarTransfer", 1, "avatar_mutex", 1);
- list_add(&avatar_transfers, data, 0);
- gg_LeaveCriticalSection(&avatar_mutex, "requestAvatarTransfer", 1, 1, "avatar_mutex", 1);
- } else {
- netlog("requestAvatarTransfer(): Can not list_add element to avatar_transfers list. No pth_avatar.dwThreadId");
+ data->szAvatarURL = strcpy((char*)(data+1), szAvatarURL);
+ avatar_transfers.insert(data);
}
+ gg_LeaveCriticalSection(&avatar_mutex, "requestAvatarTransfer", 1, 1, "avatar_mutex", 1);
}
-typedef struct
-{
- HANDLE hContact;
- int iWaitFor;
-} GGREQUESTAVATARDATA;
-
void GGPROTO::requestAvatarInfo(HANDLE hContact, int iWaitFor)
{
-#ifdef DEBUGMODE
- netlog("requestAvatarInfo(): start");
-#endif
-
- if (pth_avatar.dwThreadId) {
- if (db_get_b(NULL, m_szModuleName, GG_KEY_ENABLEAVATARS, GG_KEYDEF_ENABLEAVATARS)) {
- GGREQUESTAVATARDATA *data = (GGREQUESTAVATARDATA*)mir_alloc(sizeof(GGREQUESTAVATARDATA));
- data->hContact = hContact;
- data->iWaitFor = iWaitFor;
- gg_EnterCriticalSection(&avatar_mutex, "requestAvatarInfo", 2, "avatar_mutex", 1);
- list_add(&avatar_requests, data, 0);
- gg_LeaveCriticalSection(&avatar_mutex, "requestAvatarInfo", 2, 1, "avatar_mutex", 1);
- }
- } else {
+ if (pth_avatar.dwThreadId == NULL) {
netlog("requestAvatarInfo(): Can not list_add element to avatar_requests list. No pth_avatar.dwThreadId");
+ return;
}
+
+ if (!db_get_b(NULL, m_szModuleName, GG_KEY_ENABLEAVATARS, GG_KEYDEF_ENABLEAVATARS))
+ return;
+
+ GGREQUESTAVATARDATA *data = NULL;
+ gg_EnterCriticalSection(&avatar_mutex, "requestAvatarInfo", 2, "avatar_mutex", 1);
+ if (avatar_requests.getIndex((GGREQUESTAVATARDATA*)&hContact) == -1) {
+ data = (GGREQUESTAVATARDATA*)mir_alloc(sizeof(GGREQUESTAVATARDATA));
+ data->hContact = hContact;
+ data->iWaitFor = iWaitFor;
+ avatar_requests.insert(data);
+ }
+ gg_LeaveCriticalSection(&avatar_mutex, "requestAvatarInfo", 2, 1, "avatar_mutex", 1);
+
+ if (data != NULL)
+ db_set_b(hContact, m_szModuleName, GG_KEY_AVATARREQUESTED, 1);
}
void __cdecl GGPROTO::avatarrequestthread(void*)
{
- list_t l;
-
netlog("avatarrequestthread() started. Avatar Request Thread Starting");
while (pth_avatar.dwThreadId)
{
gg_EnterCriticalSection(&avatar_mutex, "avatarrequestthread", 3, "avatar_mutex", 1);
- if (avatar_requests) {
- GGREQUESTAVATARDATA *data = (GGREQUESTAVATARDATA *)avatar_requests->data;
- char *AvatarURL;
- char *AvatarTs;
+ if (avatar_requests.getCount()) {
+ GGREQUESTAVATARDATA *data = avatar_requests[0];
int iWaitFor = data->iWaitFor;
HANDLE hContact = data->hContact;
-
- list_remove(&avatar_requests, data, 0);
+ avatar_requests.remove(0);
mir_free(data);
gg_LeaveCriticalSection(&avatar_mutex, "avatarrequestthread", 3, 1, "avatar_mutex", 1);
uin_t uin = (uin_t)db_get_dw(hContact, m_szModuleName, GG_KEY_UIN, 0);
netlog("avatarrequestthread() new avatar_requests item for uin=%d.", uin);
- getAvatarFileInfo( uin, &AvatarURL, &AvatarTs);
-
- if (AvatarURL != NULL && strlen(AvatarURL) > 0 && AvatarTs != NULL && strlen(AvatarTs) > 0){
- db_set_s(hContact, m_szModuleName, GG_KEY_AVATARURL, AvatarURL);
- db_set_s(hContact, m_szModuleName, GG_KEY_AVATARTS, AvatarTs);
- } else {
- db_unset(hContact, m_szModuleName, GG_KEY_AVATARURL);
- db_unset(hContact, m_szModuleName, GG_KEY_AVATARTS);
+
+ char *AvatarURL, *AvatarTs;
+ if (!getAvatarFileInfo(uin, &AvatarURL, &AvatarTs)) {
+ if (iWaitFor)
+ ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, NULL, 0);
}
- db_set_b(hContact, m_szModuleName, GG_KEY_AVATARREQUESTED, 1);
-
- if (iWaitFor) {
- PROTO_AVATAR_INFORMATIONT pai = {0};
- pai.cbSize = sizeof(pai);
- pai.hContact = hContact;
- INT_PTR res = getavatarinfo((WPARAM)GAIF_FORCE, (LPARAM)&pai);
- if (res == GAIR_NOAVATAR){
- ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, NULL, 0);
- } else if (res == GAIR_SUCCESS) {
- ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0);
- } //if GAIR_WAITFOR -> ignore
- } else {
- ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, 0, 0);
+ else {
+ if (AvatarURL == NULL && AvatarTs == NULL){
+ db_unset(hContact, m_szModuleName, GG_KEY_AVATARURL);
+ db_unset(hContact, m_szModuleName, GG_KEY_AVATARTS);
+ if (iWaitFor)
+ ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, NULL, 0);
+ }
+ else {
+ db_set_s(hContact, m_szModuleName, GG_KEY_AVATARURL, AvatarURL);
+ db_set_s(hContact, m_szModuleName, GG_KEY_AVATARTS, AvatarTs);
+ mir_free(AvatarURL); mir_free(AvatarTs);
+
+ if (iWaitFor) {
+ PROTO_AVATAR_INFORMATIONT pai = {0};
+ pai.cbSize = sizeof(pai);
+ pai.hContact = hContact;
+ INT_PTR res = getavatarinfo((WPARAM)GAIF_FORCE, (LPARAM)&pai);
+ if (res == GAIR_NOAVATAR)
+ ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, NULL, 0);
+ else if (res == GAIR_SUCCESS)
+ ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0);
+ }
+ else ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, 0, 0);
+ db_unset(hContact, m_szModuleName, GG_KEY_AVATARREQUESTED);
+ }
}
- } else {
- gg_LeaveCriticalSection(&avatar_mutex, "avatarrequestthread", 3, 2, "avatar_mutex", 1);
}
+ else gg_LeaveCriticalSection(&avatar_mutex, "avatarrequestthread", 3, 2, "avatar_mutex", 1);
gg_EnterCriticalSection(&avatar_mutex, "avatarrequestthread", 4, "avatar_mutex", 1);
- if (avatar_transfers) {
- GGGETAVATARDATA *data = (GGGETAVATARDATA *)avatar_transfers->data;
- NETLIBHTTPREQUEST req = {0};
- NETLIBHTTPREQUEST *resp;
- PROTO_AVATAR_INFORMATIONT pai = {0};
- int result = 0;
-
+ if (avatar_transfers.getCount()) {
+ GGGETAVATARDATA *data = avatar_transfers[0];
+ avatar_transfers.remove(0);
gg_LeaveCriticalSection(&avatar_mutex, "avatarrequestthread", 4, 1, "avatar_mutex", 1);
- netlog("avatarrequestthread() new avatar_transfers item for url=%s.", data->AvatarURL);
+ netlog("avatarrequestthread() new avatar_transfers item for url=%s.", data->szAvatarURL);
- pai.cbSize = sizeof(pai);
+ int result = 0;
+
+ PROTO_AVATAR_INFORMATIONT pai = { sizeof(pai) };
pai.hContact = data->hContact;
pai.format = db_get_b(pai.hContact, m_szModuleName, GG_KEY_AVATARTYPE, GG_KEYDEF_AVATARTYPE);
- req.cbSize = sizeof(req);
+ NETLIBHTTPREQUEST req = { sizeof(req) };
req.requestType = REQUEST_GET;
- req.szUrl = data->AvatarURL;
+ req.szUrl = data->szAvatarURL;
req.flags = NLHRF_NODUMP | NLHRF_HTTP11 | NLHRF_REDIRECT;
- resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)netlib, (LPARAM)&req);
+
+ NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)netlib, (LPARAM)&req);
if (resp) {
if (resp->resultCode == 200 && resp->dataLength > 0 && resp->pData) {
int file_fd;
@@ -287,7 +264,7 @@ void __cdecl GGPROTO::avatarrequestthread(void*)
_write(file_fd, resp->pData, resp->dataLength);
_close(file_fd);
result = 1;
- netlog("avatarrequestthread() new avatar_transfers item. Saved data from url=%s to file=%S.", data->AvatarURL, pai.filename);
+ netlog("avatarrequestthread() new avatar_transfers item. Saved data from url=%s to file=%S.", data->szAvatarURL, pai.filename);
} else {
netlog("avatarrequestthread(): _topen file %S error. errno=%d: %s", pai.filename, errno, strerror(errno));
TCHAR error[512];
@@ -300,37 +277,26 @@ void __cdecl GGPROTO::avatarrequestthread(void*)
}
else netlog("avatarrequestthread(): No response from HTTP request");
- ProtoBroadcastAck(pai.hContact, ACKTYPE_AVATAR,
- result ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)&pai, 0);
+ ProtoBroadcastAck(pai.hContact, ACKTYPE_AVATAR, result ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)&pai, 0);
if (!pai.hContact)
CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName, 0);
- gg_EnterCriticalSection(&avatar_mutex, "avatarrequestthread", 80, "avatar_mutex", 1);
- list_remove(&avatar_transfers, data, 0);
- gg_LeaveCriticalSection(&avatar_mutex, "avatarrequestthread", 80, 1, "avatar_mutex", 1);
-
- mir_free(data->AvatarURL);
mir_free(data);
- } else {
- gg_LeaveCriticalSection(&avatar_mutex, "avatarrequestthread", 4, 2, "avatar_mutex", 1);
}
+ else gg_LeaveCriticalSection(&avatar_mutex, "avatarrequestthread", 4, 2, "avatar_mutex", 1);
gg_sleep(100, FALSE, "avatarrequestthread", 101, 1);
-
}
- for (l = avatar_requests; l; l = l->next) {
- GGREQUESTAVATARDATA *data = (GGREQUESTAVATARDATA *)l->data;
- mir_free(data);
- }
- for (l = avatar_transfers; l; l = l->next) {
- GGGETAVATARDATA *data = (GGGETAVATARDATA *)l->data;
- mir_free(data->AvatarURL);
- mir_free(data);
- }
- list_destroy(avatar_requests, 0);
- list_destroy(avatar_transfers, 0);
+ for (int i=0; i < avatar_requests.getCount(); i++)
+ mir_free(avatar_requests[i]);
+
+ for (int k=0; k < avatar_transfers.getCount(); k++)
+ mir_free(avatar_transfers[k]);
+
+ avatar_requests.destroy();
+ avatar_transfers.destroy();
netlog("avatarrequestthread(): end. Avatar Request Thread Ending");
}
@@ -340,7 +306,8 @@ void GGPROTO::initavatarrequestthread()
GetExitCodeThread(pth_avatar.hThread, &exitCode);
if (exitCode != STILL_ACTIVE) {
- avatar_requests = avatar_transfers = NULL;
+ avatar_requests.destroy();
+ avatar_transfers.destroy();
#ifdef DEBUGMODE
netlog("initavatarrequestthread(): forkthreadex 1 GGPROTO::avatarrequestthread");
#endif
@@ -348,52 +315,39 @@ void GGPROTO::initavatarrequestthread()
}
}
-void GGPROTO::uninitavatarrequestthread()
-{
- pth_avatar.dwThreadId = 0;
-#ifdef DEBUGMODE
- netlog("initavatarrequestthread() Waiting pth_avatar thread. Waiting until Avatar Request Thread finished, if needed.");
-#endif
- threadwait(&pth_avatar);
-#ifdef DEBUGMODE
- netlog("initavatarrequestthread() Waiting pth_avatar thread - OK");
-#endif
-}
-
-void __cdecl GGPROTO::getuseravatarthread(void*)
+void __cdecl GGPROTO::getOwnAvatarThread(void*)
{
- char *AvatarURL;
- char *AvatarTs;
-
- netlog("getuseravatarthread() started");
+ netlog("getOwnAvatarThread() started");
+
+ char *AvatarURL, *AvatarTs;
+ if (getAvatarFileInfo( db_get_dw(NULL, m_szModuleName, GG_KEY_UIN, 0), &AvatarURL, &AvatarTs)) {
+ if (AvatarURL != NULL && AvatarTs != NULL > 0) {
+ db_set_s(NULL, m_szModuleName, GG_KEY_AVATARURL, AvatarURL);
+ db_set_s(NULL, m_szModuleName, GG_KEY_AVATARTS, AvatarTs);
+ mir_free(AvatarURL); mir_free(AvatarTs);
+ } else {
+ db_unset(NULL, m_szModuleName, GG_KEY_AVATARURL);
+ db_unset(NULL, m_szModuleName, GG_KEY_AVATARTS);
+ }
+ db_set_b(NULL, m_szModuleName, GG_KEY_AVATARREQUESTED, 1);
- getAvatarFileInfo( db_get_dw(NULL, m_szModuleName, GG_KEY_UIN, 0), &AvatarURL, &AvatarTs);
- if (AvatarURL != NULL && strlen(AvatarURL) > 0 && AvatarTs != NULL && strlen(AvatarTs) > 0){
- db_set_s(NULL, m_szModuleName, GG_KEY_AVATARURL, AvatarURL);
- db_set_s(NULL, m_szModuleName, GG_KEY_AVATARTS, AvatarTs);
- } else {
- db_unset(NULL, m_szModuleName, GG_KEY_AVATARURL);
- db_unset(NULL, m_szModuleName, GG_KEY_AVATARTS);
+ PROTO_AVATAR_INFORMATIONT pai = {0};
+ pai.cbSize = sizeof(pai);
+ getavatarinfo((WPARAM)GAIF_FORCE, (LPARAM)&pai);
}
- db_set_b(NULL, m_szModuleName, GG_KEY_AVATARREQUESTED, 1);
- mir_free(AvatarURL);
-
- PROTO_AVATAR_INFORMATIONT pai = {0};
- pai.cbSize = sizeof(pai);
- getavatarinfo((WPARAM)GAIF_FORCE, (LPARAM)&pai);
#ifdef DEBUGMODE
- netlog("getuseravatarthread(): end");
+ netlog("getOwnAvatarThread(): end");
#endif
}
-void GGPROTO::getUserAvatar()
+void GGPROTO::getOwnAvatar()
{
if (db_get_b(NULL, m_szModuleName, GG_KEY_ENABLEAVATARS, GG_KEYDEF_ENABLEAVATARS)
&& db_get_dw(NULL, m_szModuleName, GG_KEY_UIN, 0)){
#ifdef DEBUGMODE
- netlog("getUserAvatar(): forkthread 2 GGPROTO::getuseravatarthread");
+ netlog("getOwnAvatar(): forkthread 2 GGPROTO::getOwnAvatarThread");
#endif
- forkthread(&GGPROTO::getuseravatarthread, NULL);
+ forkthread(&GGPROTO::getOwnAvatarThread, NULL);
}
}
@@ -421,7 +375,7 @@ void __cdecl GGPROTO::setavatarthread(void *param)
if (prevType != -1)
db_set_b(NULL, m_szModuleName, GG_KEY_AVATARTYPE, prevType);
db_unset(NULL, m_szModuleName, GG_KEY_AVATARTYPEPREV);
- getUserAvatar();
+ getOwnAvatar();
#ifdef DEBUGMODE
netlog("setavatarthread(): end. err1");
#endif
@@ -539,7 +493,7 @@ void __cdecl GGPROTO::setavatarthread(void *param)
db_unset(NULL, m_szModuleName, GG_KEY_AVATARTYPEPREV);
mir_free(szFilename);
- getUserAvatar();
+ getOwnAvatar();
#ifdef DEBUGMODE
netlog("setavatarthread(): end.");
#endif
diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp
index b8835c9596..72385df3cf 100644
--- a/protocols/Gadu-Gadu/src/core.cpp
+++ b/protocols/Gadu-Gadu/src/core.cpp
@@ -502,7 +502,7 @@ retry:
// Start search for user data
GetInfo(NULL, 0);
// Fetch user avatar
- getUserAvatar();
+ getOwnAvatar();
check_first_conn = 0;
}
}
diff --git a/protocols/Gadu-Gadu/src/gg.cpp b/protocols/Gadu-Gadu/src/gg.cpp
index f532995637..4aa782a6b4 100644
--- a/protocols/Gadu-Gadu/src/gg.cpp
+++ b/protocols/Gadu-Gadu/src/gg.cpp
@@ -45,7 +45,7 @@ XML_API xi;
SSL_API si;
CLIST_INTERFACE *pcli;
int hLangpack;
-list_t g_Instances;
+LIST<GGPROTO> g_Instances(1, PtrKeySortT);
// Event hooks
static HANDLE hHookModulesLoaded = NULL;
@@ -212,17 +212,12 @@ static int gg_preshutdown(WPARAM wParam, LPARAM lParam)
static GGPROTO* gg_getprotoinstance(HANDLE hContact)
{
char* szProto = GetContactProto(hContact);
- list_t l = g_Instances;
-
if (szProto == NULL)
return NULL;
- for (; l; l = l->next)
- {
- GGPROTO* gg = (GGPROTO*)l->data;
- if (strcmp(szProto, gg->m_szModuleName) == 0)
- return gg;
- }
+ for (int i=0; i < g_Instances.getCount(); i++)
+ if (strcmp(szProto, g_Instances[i]->m_szModuleName) == 0)
+ return g_Instances[i];
return NULL;
}
@@ -333,7 +328,7 @@ void GGPROTO::menus_init()
static GGPROTO *gg_proto_init(const char* pszProtoName, const TCHAR* tszUserName)
{
GGPROTO *gg = new GGPROTO(pszProtoName, tszUserName);
- list_add(&g_Instances, gg, 0);
+ g_Instances.insert(gg);
return gg;
}
@@ -343,7 +338,7 @@ static GGPROTO *gg_proto_init(const char* pszProtoName, const TCHAR* tszUserName
static int gg_proto_uninit(PROTO_INTERFACE *proto)
{
GGPROTO *gg = (GGPROTO *)proto;
- list_remove(&g_Instances, gg, 0);
+ g_Instances.remove(gg);
delete gg;
return 0;
}
@@ -371,9 +366,6 @@ extern "C" int __declspec(dllexport) Load(void)
// Register module
CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM) &pd);
gg_links_instancemenu_init();
-
- // Instance list
- g_Instances = NULL;
return 0;
}
@@ -382,6 +374,8 @@ extern "C" int __declspec(dllexport) Load(void)
extern "C" int __declspec(dllexport) Unload()
{
+ g_Instances.destroy();
+
// Cleanup WinSock
WSACleanup();
return 0;
@@ -396,49 +390,49 @@ struct
}
static const ggdebug_eventype2string[] =
{
- {GG_EVENT_NONE, "GG_EVENT_NONE"},
- {GG_EVENT_MSG, "GG_EVENT_MSG"},
- {GG_EVENT_NOTIFY, "GG_EVENT_NOTIFY"},
- {GG_EVENT_NOTIFY_DESCR, "GG_EVENT_NOTIFY_DESCR"},
- {GG_EVENT_STATUS, "GG_EVENT_STATUS"},
- {GG_EVENT_ACK, "GG_EVENT_ACK"},
- {GG_EVENT_PONG, "GG_EVENT_PONG"},
- {GG_EVENT_CONN_FAILED, "GG_EVENT_CONN_FAILED"},
- {GG_EVENT_CONN_SUCCESS, "GG_EVENT_CONN_SUCCESS"},
- {GG_EVENT_DISCONNECT, "GG_EVENT_DISCONNECT"},
- {GG_EVENT_DCC_NEW, "GG_EVENT_DCC_NEW"},
- {GG_EVENT_DCC_ERROR, "GG_EVENT_DCC_ERROR"},
- {GG_EVENT_DCC_DONE, "GG_EVENT_DCC_DONE"},
- {GG_EVENT_DCC_CLIENT_ACCEPT, "GG_EVENT_DCC_CLIENT_ACCEPT"},
- {GG_EVENT_DCC_CALLBACK, "GG_EVENT_DCC_CALLBACK"},
- {GG_EVENT_DCC_NEED_FILE_INFO, "GG_EVENT_DCC_NEED_FILE_INFO"},
- {GG_EVENT_DCC_NEED_FILE_ACK, "GG_EVENT_DCC_NEED_FILE_ACK"},
- {GG_EVENT_DCC_NEED_VOICE_ACK, "GG_EVENT_DCC_NEED_VOICE_ACK"},
- {GG_EVENT_DCC_VOICE_DATA, "GG_EVENT_DCC_VOICE_DATA"},
+ {GG_EVENT_NONE, "GG_EVENT_NONE"},
+ {GG_EVENT_MSG, "GG_EVENT_MSG"},
+ {GG_EVENT_NOTIFY, "GG_EVENT_NOTIFY"},
+ {GG_EVENT_NOTIFY_DESCR, "GG_EVENT_NOTIFY_DESCR"},
+ {GG_EVENT_STATUS, "GG_EVENT_STATUS"},
+ {GG_EVENT_ACK, "GG_EVENT_ACK"},
+ {GG_EVENT_PONG, "GG_EVENT_PONG"},
+ {GG_EVENT_CONN_FAILED, "GG_EVENT_CONN_FAILED"},
+ {GG_EVENT_CONN_SUCCESS, "GG_EVENT_CONN_SUCCESS"},
+ {GG_EVENT_DISCONNECT, "GG_EVENT_DISCONNECT"},
+ {GG_EVENT_DCC_NEW, "GG_EVENT_DCC_NEW"},
+ {GG_EVENT_DCC_ERROR, "GG_EVENT_DCC_ERROR"},
+ {GG_EVENT_DCC_DONE, "GG_EVENT_DCC_DONE"},
+ {GG_EVENT_DCC_CLIENT_ACCEPT, "GG_EVENT_DCC_CLIENT_ACCEPT"},
+ {GG_EVENT_DCC_CALLBACK, "GG_EVENT_DCC_CALLBACK"},
+ {GG_EVENT_DCC_NEED_FILE_INFO, "GG_EVENT_DCC_NEED_FILE_INFO"},
+ {GG_EVENT_DCC_NEED_FILE_ACK, "GG_EVENT_DCC_NEED_FILE_ACK"},
+ {GG_EVENT_DCC_NEED_VOICE_ACK, "GG_EVENT_DCC_NEED_VOICE_ACK"},
+ {GG_EVENT_DCC_VOICE_DATA, "GG_EVENT_DCC_VOICE_DATA"},
{GG_EVENT_PUBDIR50_SEARCH_REPLY,"GG_EVENT_PUBDIR50_SEARCH_REPLY"},
- {GG_EVENT_PUBDIR50_READ, "GG_EVENT_PUBDIR50_READ"},
- {GG_EVENT_PUBDIR50_WRITE, "GG_EVENT_PUBDIR50_WRITE"},
- {GG_EVENT_STATUS60, "GG_EVENT_STATUS60"},
- {GG_EVENT_NOTIFY60, "GG_EVENT_NOTIFY60"},
- {GG_EVENT_USERLIST, "GG_EVENT_USERLIST"},
- {GG_EVENT_IMAGE_REQUEST, "GG_EVENT_IMAGE_REQUEST"},
- {GG_EVENT_IMAGE_REPLY, "GG_EVENT_IMAGE_REPLY"},
- {GG_EVENT_DCC_ACK, "GG_EVENT_DCC_ACK"},
- {GG_EVENT_DCC7_NEW, "GG_EVENT_DCC7_NEW"},
- {GG_EVENT_DCC7_ACCEPT, "GG_EVENT_DCC7_ACCEPT"},
- {GG_EVENT_DCC7_REJECT, "GG_EVENT_DCC7_REJECT"},
- {GG_EVENT_DCC7_CONNECTED, "GG_EVENT_DCC7_CONNECTED"},
- {GG_EVENT_DCC7_ERROR, "GG_EVENT_DCC7_ERROR"},
- {GG_EVENT_DCC7_DONE, "GG_EVENT_DCC7_DONE"},
- {GG_EVENT_DCC7_PENDING, "GG_EVENT_DCC7_PENDING"},
- {GG_EVENT_XML_EVENT, "GG_EVENT_XML_EVENT"},
- {GG_EVENT_DISCONNECT_ACK, "GG_EVENT_DISCONNECT_ACK"},
- {GG_EVENT_XML_ACTION, "GG_EVENT_XML_ACTION"},
- {GG_EVENT_TYPING_NOTIFICATION, "GG_EVENT_TYPING_NOTIFICATION"},
- {GG_EVENT_USER_DATA, "GG_EVENT_USER_DATA"},
- {GG_EVENT_MULTILOGON_MSG, "GG_EVENT_MULTILOGON_MSG"},
- {GG_EVENT_MULTILOGON_INFO, "GG_EVENT_MULTILOGON_INFO"},
- {-1, "<unknown event>"}
+ {GG_EVENT_PUBDIR50_READ, "GG_EVENT_PUBDIR50_READ"},
+ {GG_EVENT_PUBDIR50_WRITE, "GG_EVENT_PUBDIR50_WRITE"},
+ {GG_EVENT_STATUS60, "GG_EVENT_STATUS60"},
+ {GG_EVENT_NOTIFY60, "GG_EVENT_NOTIFY60"},
+ {GG_EVENT_USERLIST, "GG_EVENT_USERLIST"},
+ {GG_EVENT_IMAGE_REQUEST, "GG_EVENT_IMAGE_REQUEST"},
+ {GG_EVENT_IMAGE_REPLY, "GG_EVENT_IMAGE_REPLY"},
+ {GG_EVENT_DCC_ACK, "GG_EVENT_DCC_ACK"},
+ {GG_EVENT_DCC7_NEW, "GG_EVENT_DCC7_NEW"},
+ {GG_EVENT_DCC7_ACCEPT, "GG_EVENT_DCC7_ACCEPT"},
+ {GG_EVENT_DCC7_REJECT, "GG_EVENT_DCC7_REJECT"},
+ {GG_EVENT_DCC7_CONNECTED, "GG_EVENT_DCC7_CONNECTED"},
+ {GG_EVENT_DCC7_ERROR, "GG_EVENT_DCC7_ERROR"},
+ {GG_EVENT_DCC7_DONE, "GG_EVENT_DCC7_DONE"},
+ {GG_EVENT_DCC7_PENDING, "GG_EVENT_DCC7_PENDING"},
+ {GG_EVENT_XML_EVENT, "GG_EVENT_XML_EVENT"},
+ {GG_EVENT_DISCONNECT_ACK, "GG_EVENT_DISCONNECT_ACK"},
+ {GG_EVENT_XML_ACTION, "GG_EVENT_XML_ACTION"},
+ {GG_EVENT_TYPING_NOTIFICATION, "GG_EVENT_TYPING_NOTIFICATION"},
+ {GG_EVENT_USER_DATA, "GG_EVENT_USER_DATA"},
+ {GG_EVENT_MULTILOGON_MSG, "GG_EVENT_MULTILOGON_MSG"},
+ {GG_EVENT_MULTILOGON_INFO, "GG_EVENT_MULTILOGON_INFO"},
+ {-1, "<unknown event>"}
};
const char *ggdebug_eventtype(gg_event *e)
diff --git a/protocols/Gadu-Gadu/src/gg.h b/protocols/Gadu-Gadu/src/gg.h
index 0623f89e5e..ea98b0bc72 100644
--- a/protocols/Gadu-Gadu/src/gg.h
+++ b/protocols/Gadu-Gadu/src/gg.h
@@ -131,6 +131,18 @@ typedef struct
char val[256];
} GGTOKEN;
+struct GGREQUESTAVATARDATA
+{
+ HANDLE hContact;
+ int iWaitFor;
+};
+
+struct GGGETAVATARDATA
+{
+ HANDLE hContact;
+ char *szAvatarURL;
+};
+
// Wrappers of the old interface
#define GGDEF_PROTO "GG" // Default Proto
@@ -285,7 +297,7 @@ typedef struct
#define GG_USERUTIL_EMAIL 3
// popup flags
-#define GG_POPUP_ALLOW_MSGBOX 1
+#define GG_POPUP_ALLOW_MSGBOX 1
#define GG_POPUP_ONCE 2
#define GG_POPUP_ERROR 4
#define GG_POPUP_WARNING 8
@@ -304,9 +316,11 @@ typedef struct
// Global variables
/////////////////////////////////////////////////
+struct GGPROTO;
+
extern HINSTANCE hInstance;
extern CLIST_INTERFACE *pcli;
-extern list_t g_Instances;
+extern LIST<GGPROTO> g_Instances;
extern PLUGININFOEX pluginInfo;
extern IconItem iconList[];
diff --git a/protocols/Gadu-Gadu/src/gg_proto.cpp b/protocols/Gadu-Gadu/src/gg_proto.cpp
index b98bf1fda9..22b2a5e57d 100644
--- a/protocols/Gadu-Gadu/src/gg_proto.cpp
+++ b/protocols/Gadu-Gadu/src/gg_proto.cpp
@@ -21,7 +21,9 @@
#include "gg.h"
-GGPROTO::GGPROTO(const char* pszProtoName, const TCHAR* tszUserName)
+GGPROTO::GGPROTO(const char* pszProtoName, const TCHAR* tszUserName) :
+ avatar_requests(1, HandleKeySortT),
+ avatar_transfers(1, HandleKeySortT)
{
ProtoConstructor(this, pszProtoName, tszUserName);
@@ -65,6 +67,8 @@ GGPROTO::GGPROTO(const char* pszProtoName, const TCHAR* tszUserName)
setalloffline();
db_set_dw(NULL, m_szModuleName, GG_KEY_LOGONTIME, 0);
+ db_set_resident(m_szModuleName, GG_KEY_AVATARREQUESTED);
+
TCHAR szPath[MAX_PATH];
mir_sntprintf(szPath, MAX_PATH, _T("%s\\%s"), (TCHAR*)VARST( _T("%miranda_avatarcache%")), m_tszUserName);
hAvatarsFolder = FoldersRegisterCustomPathT(LPGEN("Avatars"), m_szModuleName, szPath, m_tszUserName);
@@ -804,21 +808,15 @@ int GGPROTO::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam)
block_init();
// Try to fetch user avatar
- getUserAvatar();
+ getOwnAvatar();
break;
}
case EV_PROTO_ONEXIT:
// Stop avatar request thread
- uninitavatarrequestthread();
+ pth_avatar.dwThreadId = 0;
// Stop main connection session thread
-#ifdef DEBUGMODE
- netlog("OnEvent(): EV_PROTO_ONEXIT: Waiting pth_sess thread.");
-#endif
- threadwait(&pth_sess);
-#ifdef DEBUGMODE
- netlog("OnEvent(): EV_PROTO_ONEXIT: Waiting pth_sess thread - OK");
-#endif
+ pth_sess.dwThreadId = 0;
img_shutdown();
sessions_closedlg();
diff --git a/protocols/Gadu-Gadu/src/gg_proto.h b/protocols/Gadu-Gadu/src/gg_proto.h
index baf396ad37..5660ce1713 100644
--- a/protocols/Gadu-Gadu/src/gg_proto.h
+++ b/protocols/Gadu-Gadu/src/gg_proto.h
@@ -144,9 +144,9 @@ struct GGPROTO : public PROTO_INTERFACE
void getAvatarFilename(HANDLE hContact, TCHAR *pszDest, int cbLen);
void requestAvatarTransfer(HANDLE hContact, char *szAvatarURL);
void requestAvatarInfo(HANDLE hContact, int iWaitFor);
- void getUserAvatar();
+ void getOwnAvatar();
void setAvatar(const TCHAR *szFilename);
- void getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts);
+ bool getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts);
INT_PTR __cdecl getavatarcaps(WPARAM wParam, LPARAM lParam);
INT_PTR __cdecl getavatarinfo(WPARAM wParam, LPARAM lParam);
@@ -154,10 +154,9 @@ struct GGPROTO : public PROTO_INTERFACE
INT_PTR __cdecl setmyavatar(WPARAM wParam, LPARAM lParam);
void initavatarrequestthread();
- void uninitavatarrequestthread();
void __cdecl avatarrequestthread(void*);
- void __cdecl getuseravatarthread(void*);
+ void __cdecl getOwnAvatarThread(void*);
void __cdecl setavatarthread(void*);
/* File transfer functions */
@@ -254,7 +253,9 @@ struct GGPROTO : public PROTO_INTERFACE
//////////////////////////////////////////////////////////////////////////////////////
CRITICAL_SECTION ft_mutex, sess_mutex, img_mutex, modemsg_mutex, avatar_mutex, sessions_mutex;
- list_t watches, transfers, requests, chats, imagedlgs, avatar_requests, avatar_transfers, sessions;
+ list_t watches, transfers, requests, chats, imagedlgs, sessions;
+ LIST<GGREQUESTAVATARDATA> avatar_requests;
+ LIST<GGGETAVATARDATA> avatar_transfers;
int gc_enabled, gc_id, is_list_remove, check_first_conn;
uin_t next_uin;
unsigned long last_crc;
diff --git a/protocols/Gadu-Gadu/src/links.cpp b/protocols/Gadu-Gadu/src/links.cpp
index 8b78eb73dc..fafaf05c48 100644
--- a/protocols/Gadu-Gadu/src/links.cpp
+++ b/protocols/Gadu-Gadu/src/links.cpp
@@ -41,12 +41,10 @@ static INT_PTR gg_menuchoose(WPARAM wParam, LPARAM lParam)
static INT_PTR gg_parselink(WPARAM wParam, LPARAM lParam)
{
char *arg = (char*)lParam;
- list_t l = g_Instances;
- GGPROTO *gg = NULL;
uin_t uin;
int items = 0;
- if (list_count(l) == 0)
+ if (g_Instances.getCount() == 0)
return 0;
if (arg == NULL)
@@ -63,20 +61,20 @@ static INT_PTR gg_parselink(WPARAM wParam, LPARAM lParam)
if (!uin)
return 1;
- for (; l; l = l->next) {
- GGPROTO *gginst = (GGPROTO*)l->data;
+ GGPROTO *gg = NULL;
+ for (int i=0; i < g_Instances.getCount(); i++) {
+ gg = g_Instances[i];
CLISTMENUITEM mi = { sizeof(mi) };
mi.flags = CMIM_FLAGS;
- if (gginst->m_iStatus > ID_STATUS_OFFLINE) {
+ if (gg->m_iStatus > ID_STATUS_OFFLINE) {
++items;
- gg = (GGPROTO*)l->data;
mi.flags |= CMIM_ICON;
mi.hIcon = LoadSkinnedProtoIcon(gg->m_szModuleName, gg->m_iStatus);
}
else mi.flags |= CMIF_HIDDEN;
- Menu_ModifyItem(gginst->hInstanceMenuItem, &mi);
+ Menu_ModifyItem(gg->hInstanceMenuItem, &mi);
if (mi.hIcon)
Skin_ReleaseIcon(mi.hIcon);
}
@@ -156,7 +154,7 @@ void GGPROTO::links_instance_init()
TMO_MenuItem tmi = { sizeof(tmi) };
tmi.flags = CMIF_TCHAR;
tmi.ownerdata = this;
- tmi.position = list_count(g_Instances);
+ tmi.position = g_Instances.getCount();
tmi.ptszName = m_tszUserName;
hInstanceMenuItem = (HGENMENU)CallService(MO_ADDNEWMENUITEM, (WPARAM)hInstanceMenu, (LPARAM)&tmi);
}
diff --git a/protocols/Gadu-Gadu/src/services.cpp b/protocols/Gadu-Gadu/src/services.cpp
index 93be5e73f3..a22dbb69e2 100644
--- a/protocols/Gadu-Gadu/src/services.cpp
+++ b/protocols/Gadu-Gadu/src/services.cpp
@@ -206,16 +206,10 @@ int GetImageFormat(TCHAR *filename)
INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
{
PROTO_AVATAR_INFORMATIONT *pai = (PROTO_AVATAR_INFORMATIONT *)lParam;
- char *AvatarHash = NULL, *AvatarSavedHash = NULL;
- char *AvatarURL = NULL;
- char *AvatarTs = NULL;
- INT_PTR result = GAIR_NOAVATAR;
- DBVARIANT dbv;
- uin_t uin = (uin_t)db_get_dw(pai->hContact, m_szModuleName, GG_KEY_UIN, 0);
-
pai->filename[0] = 0;
pai->format = PA_FORMAT_UNKNOWN;
+ uin_t uin = (uin_t)db_get_dw(pai->hContact, m_szModuleName, GG_KEY_UIN, 0);
if (!uin) {
netlog("getavatarinfo(): Incoming request for avatar information. No uin found. return GAIR_NOAVATAR");
return GAIR_NOAVATAR;
@@ -226,20 +220,18 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
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)) {
+ DBVARIANT dbv;
+ if (!db_get_ts(pai->hContact, "ContactPhoto", "Backup", &dbv)) {
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);
db_free(&dbv);
return GAIR_SUCCESS;
- } else {
- db_free(&dbv);
}
+ db_free(&dbv);
}
-
if (!db_get_b(pai->hContact, m_szModuleName, GG_KEY_AVATARREQUESTED, GG_KEYDEF_AVATARREQUESTED)) {
requestAvatarInfo(pai->hContact, 1);
@@ -251,19 +243,13 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
return GAIR_NOAVATAR;
}
}
- db_unset(pai->hContact, m_szModuleName, GG_KEY_AVATARREQUESTED);
pai->format = db_get_b(pai->hContact, m_szModuleName, GG_KEY_AVATARTYPE, GG_KEYDEF_AVATARTYPE);
- if (!db_get_s(pai->hContact, m_szModuleName, GG_KEY_AVATARURL, &dbv, DBVT_ASCIIZ)) {
- AvatarURL = mir_strdup(dbv.pszVal);
- db_free(&dbv);
- }
- if (!db_get_s(pai->hContact, m_szModuleName, GG_KEY_AVATARTS, &dbv, DBVT_ASCIIZ)) {
- AvatarTs = mir_strdup(dbv.pszVal);
- db_free(&dbv);
- }
- if (AvatarURL != NULL && strlen(AvatarURL) > 0 && AvatarTs != NULL && strlen(AvatarTs) > 0) {
+ ptrA AvatarHash(NULL);
+ ptrA AvatarURL( db_get_sa(pai->hContact, m_szModuleName, GG_KEY_AVATARURL));
+ ptrA AvatarTs( db_get_sa(pai->hContact, m_szModuleName, GG_KEY_AVATARTS));
+ if (AvatarURL != NULL && AvatarTs != NULL) {
char *AvatarName = strrchr(AvatarURL, '/');
AvatarName++;
char AvatarNameWithTS[128];
@@ -271,24 +257,20 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
AvatarHash = gg_avatarhash(AvatarNameWithTS);
}
- if (!db_get_s(pai->hContact, m_szModuleName, GG_KEY_AVATARHASH, &dbv, DBVT_ASCIIZ)) {
- AvatarSavedHash = mir_strdup(dbv.pszVal);
- db_free(&dbv);
- }
-
+ ptrA AvatarSavedHash( db_get_sa(pai->hContact, m_szModuleName, GG_KEY_AVATARHASH));
if (AvatarHash != NULL && AvatarSavedHash != NULL) {
-
getAvatarFilename(pai->hContact, pai->filename, SIZEOF(pai->filename));
if (!strcmp(AvatarHash, AvatarSavedHash)) {
if (_taccess(pai->filename, 0) == 0){
netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. Avatar hash unchanged. return GAIR_SUCCESS", uin);
- result = GAIR_SUCCESS;
- } else {
- 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;
+ return GAIR_SUCCESS;
}
- } else if ((wParam & GAIF_FORCE) != 0) {
+
+ 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));
+ return GAIR_WAITFOR;
+ }
+ if ((wParam & GAIF_FORCE) != 0) {
if (_tremove(pai->filename) != 0){
netlog("getavatarinfo(): refresh. _tremove 1 file %S error. errno=%d: %s", pai->filename, errno, strerror(errno));
TCHAR error[512];
@@ -298,13 +280,10 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
db_set_s(pai->hContact, m_szModuleName, GG_KEY_AVATARHASH, AvatarHash);
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);
+ return GAIR_WAITFOR;
}
-
- } else if ((wParam & GAIF_FORCE) != 0) {
-
+ }
+ else if ((wParam & GAIF_FORCE) != 0) {
if (AvatarHash == NULL && AvatarSavedHash != NULL) {
getAvatarFilename(pai->hContact, pai->filename, sizeof(pai->filename));
if (_tremove(pai->filename) != 0){
@@ -317,24 +296,18 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
db_unset(pai->hContact, m_szModuleName, GG_KEY_AVATARURL);
db_unset(pai->hContact, m_szModuleName, GG_KEY_AVATARTYPE);
netlog("getavatarinfo(): Incoming request for avatar information. Contact %d deleted avatar. return GAIR_NOAVATAR", uin);
- } else if (AvatarHash != NULL && AvatarSavedHash == NULL) {
+ }
+ else if (AvatarHash != NULL && AvatarSavedHash == NULL) {
db_set_s(pai->hContact, m_szModuleName, GG_KEY_AVATARHASH, AvatarHash);
requestAvatarTransfer(pai->hContact, AvatarURL);
- result = GAIR_WAITFOR;
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);
+ return GAIR_WAITFOR;
}
-
- } else {
- netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. AvatarHash==null or AvatarSavedHash==null, but no GAIF_FORCE param. return GAIR_NOAVATAR", uin);
+ else netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. AvatarHash==AvatarSavedHash==NULL, with GAIF_FORCE param. return GAIR_NOAVATAR", uin);
}
+ else netlog("getavatarinfo(): Incoming request for avatar information. uin=%d. AvatarHash==null or AvatarSavedHash==null, but no GAIF_FORCE param. return GAIR_NOAVATAR", uin);
- mir_free(AvatarHash);
- mir_free(AvatarSavedHash);
- mir_free(AvatarURL);
-
- return result;
+ return GAIR_NOAVATAR;
}
//////////////////////////////////////////////////////////
diff --git a/protocols/Gadu-Gadu/src/version.h b/protocols/Gadu-Gadu/src/version.h
index b904ca056b..c92524d8d3 100644
--- a/protocols/Gadu-Gadu/src/version.h
+++ b/protocols/Gadu-Gadu/src/version.h
@@ -18,6 +18,6 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
////////////////////////////////////////////////////////////////////////////////
-#define __FILEVERSION_STRING 0,11,0,2
-#define __VERSION_STRING "0.11.0.2"
-#define __VERSION_DWORD PLUGIN_MAKE_VERSION(0, 11, 0, 2)
+#define __FILEVERSION_STRING 0,11,0,3
+#define __VERSION_STRING "0.11.0.3"
+#define __VERSION_DWORD PLUGIN_MAKE_VERSION(0, 11, 0, 3)