summaryrefslogtreecommitdiff
path: root/protocols/Gadu-Gadu/src
diff options
context:
space:
mode:
authorSzymon Tokarz <wsx22@o2.pl>2012-11-23 01:00:25 +0000
committerSzymon Tokarz <wsx22@o2.pl>2012-11-23 01:00:25 +0000
commite1a932b1b5c6aaf73425dcf9a8312ecf6cff7d6c (patch)
tree4176819c3d595f02c2dc9ce6c7b31570f70a13e3 /protocols/Gadu-Gadu/src
parentf7e80ddad2316fe652eeaa5c908f8406239c6d4e (diff)
Gadu-Gadu protocol
- GG changed avatar API at http://api.gadu-gadu.pl/avatars/%d/0.xml file. Adapting our avatar code to that change. git-svn-id: http://svn.miranda-ng.org/main/trunk@2437 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Gadu-Gadu/src')
-rw-r--r--protocols/Gadu-Gadu/src/avatar.cpp69
-rw-r--r--protocols/Gadu-Gadu/src/gg.h2
-rw-r--r--protocols/Gadu-Gadu/src/gg_proto.h2
-rw-r--r--protocols/Gadu-Gadu/src/services.cpp12
4 files changed, 52 insertions, 33 deletions
diff --git a/protocols/Gadu-Gadu/src/avatar.cpp b/protocols/Gadu-Gadu/src/avatar.cpp
index bd41b80b10..c5c889e369 100644
--- a/protocols/Gadu-Gadu/src/avatar.cpp
+++ b/protocols/Gadu-Gadu/src/avatar.cpp
@@ -34,8 +34,7 @@ void GGPROTO::getAvatarFilename(HANDLE hContact, TCHAR *pszDest, int cbLen)
if (hAvatarsFolder == NULL || FoldersGetCustomPathT(hAvatarsFolder, path, cbLen, _T(""))) {
mir_ptr<TCHAR> tmpPath( Utils_ReplaceVarsT( _T("%miranda_avatarcache%")));
tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%s"), (TCHAR*)tmpPath, m_tszUserName);
- }
- else {
+ } else {
_tcscpy(pszDest, path);
tPathLen = (int)_tcslen(pszDest);
}
@@ -62,13 +61,13 @@ void GGPROTO::getAvatarFilename(HANDLE hContact, TCHAR *pszDest, int cbLen)
}
}
-void GGPROTO::getAvatarFileInfo(uin_t uin, char **avatarurl, int *type)
+void GGPROTO::getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts)
{
NETLIBHTTPREQUEST req = {0};
NETLIBHTTPREQUEST *resp;
char szUrl[128];
*avatarurl = NULL;
- *type = PA_FORMAT_UNKNOWN;
+ *avatarts = NULL;
req.cbSize = sizeof(req);
req.requestType = REQUEST_GET;
@@ -96,26 +95,18 @@ void GGPROTO::getAvatarFileInfo(uin_t uin, char **avatarurl, int *type)
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/bigAvatar");
+ 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/originBigAvatar");
+ mir_free(tag); tag = mir_a2t("users/user/avatars/avatar/timestamp");
node = xi.getChildByPath(hXml, tag, 0);
- if (node != NULL) {
- char *orgavurl = mir_t2a(xi.getText(node));
- char *avtype = strrchr(orgavurl, '.');
- avtype++;
- if (!_stricmp(avtype, "jpg"))
- *type = PA_FORMAT_JPEG;
- else if (!_stricmp(avtype, "gif"))
- *type = PA_FORMAT_GIF;
- else if (!_stricmp(avtype, "png"))
- *type = PA_FORMAT_PNG;
- mir_free(orgavurl);
- }
+ *avatarts = node != NULL ? mir_t2a(xi.getText(node)) : NULL;
+
+ } else {
+ *avatarurl = mir_strdup("");
+ *avatarts = mir_strdup("");
}
- else *avatarurl = mir_strdup("");
mir_free(blank);
xi.destroyNode(hXml);
}
@@ -199,19 +190,22 @@ void __cdecl GGPROTO::avatarrequestthread(void*)
if (avatar_requests) {
GGREQUESTAVATARDATA *data = (GGREQUESTAVATARDATA *)avatar_requests->data;
char *AvatarURL;
- int AvatarType, iWaitFor = data->iWaitFor;
+ char *AvatarTs;
+ int iWaitFor = data->iWaitFor;
HANDLE hContact = data->hContact;
list_remove(&avatar_requests, data, 0);
mir_free(data);
gg_LeaveCriticalSection(&avatar_mutex, "avatarrequestthread", 3, 1, "avatar_mutex", 1);
- getAvatarFileInfo( db_get_dw(hContact, m_szModuleName, GG_KEY_UIN, 0), &AvatarURL, &AvatarType);
- if (AvatarURL != NULL && strlen(AvatarURL) > 0)
+ getAvatarFileInfo( db_get_dw(hContact, m_szModuleName, GG_KEY_UIN, 0), &AvatarURL, &AvatarTs);
+ if (AvatarURL != NULL && strlen(AvatarURL) > 0 && AvatarTs != NULL && strlen(AvatarTs) > 0){
db_set_s(hContact, m_szModuleName, GG_KEY_AVATARURL, AvatarURL);
- else
+ db_set_s(hContact, m_szModuleName, GG_KEY_AVATARTS, AvatarTs);
+ } else {
db_unset(hContact, m_szModuleName, GG_KEY_AVATARURL);
- db_set_b(hContact, m_szModuleName, GG_KEY_AVATARTYPE, (BYTE)AvatarType);
+ db_unset(hContact, m_szModuleName, GG_KEY_AVATARTS);
+ }
db_set_b(hContact, m_szModuleName, GG_KEY_AVATARREQUESTED, 1);
if (iWaitFor) {
@@ -249,6 +243,21 @@ void __cdecl GGPROTO::avatarrequestthread(void*)
if (resp->resultCode == 200 && resp->dataLength > 0 && resp->pData) {
int file_fd;
+ int avatarType = PA_FORMAT_UNKNOWN;
+ for (int i=0; i < resp->headersCount; i++)
+ {
+ NETLIBHTTPHEADER& tHeader = resp->headers[i];
+ if (!_stricmp(tHeader.szName, "Content-Type")){
+ if (!_stricmp(tHeader.szValue, "image/jpeg"))
+ avatarType = PA_FORMAT_JPEG;
+ else if (!_stricmp(tHeader.szValue, "image/gif"))
+ avatarType = PA_FORMAT_GIF;
+ else if (!_stricmp(tHeader.szValue, "image/png"))
+ avatarType = PA_FORMAT_PNG;
+ }
+ }
+ db_set_b(data->hContact, m_szModuleName, GG_KEY_AVATARTYPE, (BYTE)avatarType);
+
getAvatarFilename(pai.hContact, pai.filename, sizeof(pai.filename));
file_fd = _topen(pai.filename, _O_WRONLY | _O_TRUNC | _O_BINARY | _O_CREAT, _S_IREAD | _S_IWRITE);
if (file_fd != -1) {
@@ -325,16 +334,18 @@ void GGPROTO::uninitavatarrequestthread()
void __cdecl GGPROTO::getuseravatarthread(void*)
{
char *AvatarURL;
- int AvatarType;
+ char *AvatarTs;
netlog("getuseravatarthread() started");
- getAvatarFileInfo( db_get_dw(NULL, m_szModuleName, GG_KEY_UIN, 0), &AvatarURL, &AvatarType);
- if (AvatarURL != NULL && strlen(AvatarURL) > 0)
+ 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);
- else
+ db_set_s(NULL, m_szModuleName, GG_KEY_AVATARTS, AvatarTs);
+ } else {
db_unset(NULL, m_szModuleName, GG_KEY_AVATARURL);
- db_set_b(NULL, m_szModuleName, GG_KEY_AVATARTYPE, (BYTE)AvatarType);
+ db_unset(NULL, m_szModuleName, GG_KEY_AVATARTS);
+ }
db_set_b(NULL, m_szModuleName, GG_KEY_AVATARREQUESTED, 1);
mir_free(AvatarURL);
diff --git a/protocols/Gadu-Gadu/src/gg.h b/protocols/Gadu-Gadu/src/gg.h
index df2cc86b58..cb1d44d3a5 100644
--- a/protocols/Gadu-Gadu/src/gg.h
+++ b/protocols/Gadu-Gadu/src/gg.h
@@ -191,6 +191,8 @@ typedef struct
#define GG_KEY_AVATARURL "AvatarURL" // Contact's avatar URL
+#define GG_KEY_AVATARTS "AvatarTs" // Contact's avatar Timestamp
+
#define GG_KEY_AVATARTYPE "AvatarType" // Contact's avatar format
#define GG_KEYDEF_AVATARTYPE PA_FORMAT_UNKNOWN
diff --git a/protocols/Gadu-Gadu/src/gg_proto.h b/protocols/Gadu-Gadu/src/gg_proto.h
index 615fea1976..e1be4c2cff 100644
--- a/protocols/Gadu-Gadu/src/gg_proto.h
+++ b/protocols/Gadu-Gadu/src/gg_proto.h
@@ -144,7 +144,7 @@ struct GGPROTO : public PROTO_INTERFACE, public MZeroedObject
void requestAvatar(HANDLE hContact, int iWaitFor);
void getUserAvatar();
void setAvatar(const TCHAR *szFilename);
- void getAvatarFileInfo(uin_t uin, char **avatarurl, int *type);
+ void getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts);
INT_PTR __cdecl getavatarcaps(WPARAM wParam, LPARAM lParam);
INT_PTR __cdecl getavatarinfo(WPARAM wParam, LPARAM lParam);
diff --git a/protocols/Gadu-Gadu/src/services.cpp b/protocols/Gadu-Gadu/src/services.cpp
index 11c8a25ac1..ce576aa214 100644
--- a/protocols/Gadu-Gadu/src/services.cpp
+++ b/protocols/Gadu-Gadu/src/services.cpp
@@ -174,6 +174,7 @@ 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);
@@ -198,11 +199,16 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
AvatarURL = mir_strdup(dbv.pszVal);
DBFreeVariant(&dbv);
}
-
- if (AvatarURL != NULL && strlen(AvatarURL) > 0) {
+ if (!db_get_s(pai->hContact, m_szModuleName, GG_KEY_AVATARTS, &dbv, DBVT_ASCIIZ)) {
+ AvatarTs = mir_strdup(dbv.pszVal);
+ DBFreeVariant(&dbv);
+ }
+ if (AvatarURL != NULL && strlen(AvatarURL) > 0 && AvatarTs != NULL && strlen(AvatarTs) > 0) {
char *AvatarName = strrchr(AvatarURL, '/');
AvatarName++;
- AvatarHash = gg_avatarhash(AvatarName);
+ char AvatarNameWithTS[128];
+ sprintf(AvatarNameWithTS, "%s%s", AvatarName, AvatarTs);
+ AvatarHash = gg_avatarhash(AvatarNameWithTS);
}
if (!db_get_s(pai->hContact, m_szModuleName, GG_KEY_AVATARHASH, &dbv, DBVT_ASCIIZ)) {