diff options
-rw-r--r-- | protocols/JabberG/src/jabber_chat.cpp | 13 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_iq.cpp | 3 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_iq.h | 8 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_proto.h | 3 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_vcard.cpp | 112 |
5 files changed, 77 insertions, 62 deletions
diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index 16483bcb9b..34f062c80f 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -466,9 +466,9 @@ static gc_item sttListItems[] = { LPGENW("Copy in-room JID"), IDM_CPY_INROOMJID, MENU_ITEM }
};
-static uint32_t sttModeratorItems[] = { IDM_LST_PARTICIPANT, IDM_AVATAR, 0 };
+static uint32_t sttModeratorItems[] = { IDM_LST_PARTICIPANT, 0 };
static uint32_t sttAdminItems[] = { IDM_LST_MODERATOR, IDM_LST_MEMBER, IDM_LST_ADMIN, IDM_LST_OWNER, IDM_LST_BAN, 0 };
-static uint32_t sttOwnerItems[] = { IDM_CONFIG, IDM_DESTROY, 0 };
+static uint32_t sttOwnerItems[] = { IDM_CONFIG, IDM_DESTROY, IDM_AVATAR, 0 };
int CJabberProto::JabberGcMenuHook(WPARAM, LPARAM lParam)
{
@@ -1196,7 +1196,14 @@ static void sttLogListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK *g break;
case IDM_AVATAR:
- CallService(MS_AV_CONTACTOPTIONS, gch->si->hContact, LPARAM(gch->si->pDlg ? gch->si->pDlg->GetHwnd() : nullptr));
+ if (CallService(MS_AV_SETAVATARW, gch->si->hContact, 0) == 1) {
+ CMStringW wszAvaPath(db_get_wsm(gch->si->hContact, "ContactPhoto", "File"));
+ XmlNodeIq iq(ppro->AddIQ(nullptr, JABBER_IQ_TYPE_SET, roomJid));
+
+ TiXmlElement *v = iq << XCHILDNS("vCard", JABBER_FEAT_VCARD_TEMP);
+ ppro->AppendPhotoToVcard(v, true, wszAvaPath.GetBuffer(), gch->si->hContact);
+ ppro->m_ThreadInfo->send(iq);
+ }
break;
case IDM_TOPIC:
diff --git a/protocols/JabberG/src/jabber_iq.cpp b/protocols/JabberG/src/jabber_iq.cpp index bd3048b432..9e1dc7dc20 100644 --- a/protocols/JabberG/src/jabber_iq.cpp +++ b/protocols/JabberG/src/jabber_iq.cpp @@ -230,7 +230,8 @@ bool CJabberIqManager::HandleIq(int nIqId, const TiXmlElement *pNode) if (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_ID_STR)
pInfo->m_szId = XmlGetAttr(pNode, "id");
- (ppro->*(pInfo->m_pHandler))(pNode, pInfo);
+ if (pInfo->m_pHandler)
+ (ppro->*(pInfo->m_pHandler))(pNode, pInfo);
delete pInfo;
}
while ((pInfo = DetachInfo(nIqId)) != nullptr);
diff --git a/protocols/JabberG/src/jabber_iq.h b/protocols/JabberG/src/jabber_iq.h index c92ead65d9..50694fc73e 100644 --- a/protocols/JabberG/src/jabber_iq.h +++ b/protocols/JabberG/src/jabber_iq.h @@ -56,9 +56,9 @@ protected: JABBER_IQ_HANDLER m_pHandler;
int m_nIqId;
- uint32_t m_dwParamsToParse;
- uint32_t m_dwRequestTime;
- uint32_t m_dwTimeout;
+ uint32_t m_dwParamsToParse;
+ uint32_t m_dwRequestTime;
+ uint32_t m_dwTimeout;
char* m_szReceiver;
int m_iPriority;
void* m_pUserData;
@@ -84,7 +84,7 @@ public: __forceinline void SetTimeout(uint32_t dwTimeout) { m_dwTimeout = dwTimeout; }
__forceinline int GetIqId() const { return m_nIqId; }
- __forceinline uint32_t GetRequestTime() const { return m_dwRequestTime; }
+ __forceinline uint32_t GetRequestTime() const { return m_dwRequestTime; }
__forceinline int GetIqType() const { return m_nIqType; }
__forceinline void* GetUserData() const { return m_pUserData; }
__forceinline const char* GetFrom() const { return m_szFrom; }
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index d01ed55d6b..ba0fc9cce5 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -889,7 +889,8 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface int SendGetVcard(MCONTACT hContact);
void AppendVcardFromDB(TiXmlElement *n, char* tag, char* key);
- void SetServerVcard(BOOL bPhotoChanged, wchar_t* szPhotoFileName);
+ void AppendPhotoToVcard(TiXmlElement *n, bool bPhotoChanged, wchar_t *szPhotoFileName, MCONTACT hContact = 0);
+ void SetServerVcard(bool bPhotoChanged, wchar_t* szPhotoFileName);
void SaveVcardToDB(HWND hwndPage, int iPage);
//---- jabber_voip.c -----------------------------------------------------------------
diff --git a/protocols/JabberG/src/jabber_vcard.cpp b/protocols/JabberG/src/jabber_vcard.cpp index d8754b240b..5465e05c26 100644 --- a/protocols/JabberG/src/jabber_vcard.cpp +++ b/protocols/JabberG/src/jabber_vcard.cpp @@ -878,11 +878,10 @@ void CJabberProto::AppendVcardFromDB(TiXmlElement *n, char *tag, char *key) n << XCHILD(tag, tszValue);
}
-void CJabberProto::SetServerVcard(BOOL bPhotoChanged, wchar_t *szPhotoFileName)
+void CJabberProto::SetServerVcard(bool bPhotoChanged, wchar_t *szPhotoFileName)
{
if (!m_bJabberOnline) return;
- int i;
char idstr[33];
XmlNodeIq iq(AddIQ(&CJabberProto::OnIqResultSetVcard, JABBER_IQ_TYPE_SET));
@@ -899,7 +898,7 @@ void CJabberProto::SetServerVcard(BOOL bPhotoChanged, wchar_t *szPhotoFileName) AppendVcardFromDB(v, "BDAY", "BirthDate");
AppendVcardFromDB(v, "GENDER", "GenderString");
- for (i = 0;; i++) {
+ for (int i = 0;; i++) {
mir_snprintf(idstr, "e-mail%d", i);
ptrA email(getUStringA(idstr));
if (email == nullptr)
@@ -947,7 +946,7 @@ void CJabberProto::SetServerVcard(BOOL bPhotoChanged, wchar_t *szPhotoFileName) AppendVcardFromDB(v, "URL", "Homepage");
AppendVcardFromDB(v, "DESC", "About");
- for (i = 0;; i++) {
+ for (int i = 0;; i++) {
mir_snprintf(idstr, "Phone%d", i);
ptrW phone(getWStringA(idstr));
if (phone == nullptr)
@@ -972,8 +971,19 @@ void CJabberProto::SetServerVcard(BOOL bPhotoChanged, wchar_t *szPhotoFileName) if (nFlag & JABBER_VCTEL_PCS) n << XCHILD("PCS");
}
+ AppendPhotoToVcard(v, bPhotoChanged, szPhotoFileName);
+
+ XmlNodeHash hasher;
+ v->Accept(&hasher);
+ setString("VCardHash", hasher.getResult());
+
+ m_ThreadInfo->send(iq);
+}
+
+void CJabberProto::AppendPhotoToVcard(TiXmlElement *v, bool bPhotoChanged, wchar_t *szPhotoFileName, MCONTACT hContact)
+{
wchar_t szAvatarName[MAX_PATH], *szFileName;
- GetAvatarFileName(0, szAvatarName, _countof(szAvatarName));
+ GetAvatarFileName(hContact, szAvatarName, _countof(szAvatarName));
if (bPhotoChanged)
szFileName = szPhotoFileName;
else
@@ -983,59 +993,55 @@ void CJabberProto::SetServerVcard(BOOL bPhotoChanged, wchar_t *szPhotoFileName) debugLogW(L"Before update, file name = %s", szFileName);
if (szFileName == nullptr || szFileName[0] == 0) {
v << XCHILD("PHOTO");
- DeleteFile(szAvatarName);
- delSetting("AvatarHash");
+ DeleteFileW(szAvatarName);
+ delSetting(hContact, "AvatarHash");
+ return;
}
- else {
- debugLogW(L"Saving picture from %s", szFileName);
-
- struct _stat st;
- if (_wstat(szFileName, &st) >= 0) {
- // Note the FILE_SHARE_READ attribute so that the CopyFile can succeed
- HANDLE hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
- if (hFile != INVALID_HANDLE_VALUE) {
- ptrA buffer((char*)mir_alloc(st.st_size));
- if (buffer != nullptr) {
- DWORD nRead;
- if (ReadFile(hFile, buffer, st.st_size, &nRead, nullptr)) {
- ptrA str(mir_base64_encode(buffer, nRead));
- const char *szFileType = ProtoGetAvatarMimeType(ProtoGetBufferFormat(buffer));
- if (str != nullptr && szFileType != nullptr) {
- n = v << XCHILD("PHOTO");
- n << XCHILD("TYPE", szFileType);
- n << XCHILD("BINVAL", str);
-
- // NEED TO UPDATE OUR AVATAR HASH:
- uint8_t digest[MIR_SHA1_HASH_SIZE];
- mir_sha1_ctx sha1ctx;
- mir_sha1_init(&sha1ctx);
- mir_sha1_append(&sha1ctx, (uint8_t*)(LPSTR)buffer, nRead);
- mir_sha1_finish(&sha1ctx, digest);
-
- char buf[MIR_SHA1_HASH_SIZE * 2 + 1];
- bin2hex(digest, sizeof(digest), buf);
-
- if (bPhotoChanged) {
- DeleteFile(szAvatarName);
-
- GetAvatarFileName(0, szAvatarName, _countof(szAvatarName));
- CopyFile(szFileName, szAvatarName, FALSE);
- }
-
- setString("AvatarHash", buf);
- }
- }
+
+ debugLogW(L"Saving picture from %s", szFileName);
+
+ struct _stat st;
+ if (_wstat(szFileName, &st) < 0)
+ return;
+
+ // Note the FILE_SHARE_READ attribute so that the CopyFile can succeed
+ HANDLE hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (hFile == INVALID_HANDLE_VALUE)
+ return;
+
+ ptrA buffer((char*)mir_alloc(st.st_size));
+ if (buffer != nullptr) {
+ DWORD nRead;
+ if (ReadFile(hFile, buffer, st.st_size, &nRead, nullptr)) {
+ ptrA str(mir_base64_encode(buffer, nRead));
+ const char *szFileType = ProtoGetAvatarMimeType(ProtoGetBufferFormat(buffer));
+ if (str != nullptr && szFileType != nullptr) {
+ auto *n = v << XCHILD("PHOTO");
+ n << XCHILD("TYPE", szFileType);
+ n << XCHILD("BINVAL", str);
+
+ // NEED TO UPDATE OUR AVATAR HASH:
+ uint8_t digest[MIR_SHA1_HASH_SIZE];
+ mir_sha1_ctx sha1ctx;
+ mir_sha1_init(&sha1ctx);
+ mir_sha1_append(&sha1ctx, (uint8_t *)(LPSTR)buffer, nRead);
+ mir_sha1_finish(&sha1ctx, digest);
+
+ char buf[MIR_SHA1_HASH_SIZE * 2 + 1];
+ bin2hex(digest, sizeof(digest), buf);
+
+ if (bPhotoChanged) {
+ DeleteFileW(szAvatarName);
+
+ GetAvatarFileName(hContact, szAvatarName, _countof(szAvatarName));
+ CopyFileW(szFileName, szAvatarName, FALSE);
}
- CloseHandle(hFile);
+
+ setString(hContact, "AvatarHash", buf);
}
}
}
-
- XmlNodeHash hasher;
- v->Accept(&hasher);
- setString("VCardHash", hasher.getResult());
-
- m_ThreadInfo->send(iq);
+ CloseHandle(hFile);
}
/////////////////////////////////////////////////////////////////////////////////////////
|