// upload avatar data to server int CIcqProto::SetAvatarData(MCONTACT hContact, WORD wRef, const BYTE *data, size_t datalen) { mir_cslockfull alck(m_avatarsMutex); if (m_avatarsConnection && m_avatarsConnection->isReady()) { // check if we are ready mir_cslock l(m_avatarsConnection->getLock()); alck.unlock(); DWORD dwCookie = m_avatarsConnection->sendUploadAvatarRequest(hContact, wRef, data, datalen); if (dwCookie) // return now if the request was sent successfully return dwCookie; alck.lock(); } // we failed to send request, or avatar thread not ready // check if any request for this user is not already in the queue for (int i = 0; i < m_arAvatars.getCount(); i++) { avatars_request *ar = m_arAvatars[i]; if (ar->hContact == hContact && ar->type == ART_UPLOAD) { // we found it, return error alck.unlock(); debugLogA("Avatars: Ignoring duplicate upload avatar request."); // make sure avatar connection is in progress requestAvatarConnection(); return 0; } } // add request to queue, processed after successful login avatars_request *ar = new avatars_request(ART_UPLOAD); // upload avatar ar->hContact = hContact; ar->pData = (BYTE*)SAFE_MALLOC(datalen); if (!ar->pData) { // alloc failed delete ar; return 0; } memcpy(ar->pData, data, datalen); // copy the data ar->cbData = datalen; ar->wRef = wRef; m_arAvatars.insert(ar); alck.unlock(); debugLogA("Avatars: Request to upload image added to queue."); // make sure avatar connection is in progress requestAvatarConnection(); return -1; // we added to queue }
// upload avatar data to server int CIcqProto::SetAvatarData(HANDLE hContact, WORD wRef, const BYTE *data, unsigned int datalen) { m_avatarsMutex->Enter(); if (m_avatarsConnection && m_avatarsConnection->isReady()) // check if we are ready { avatars_server_connection *pConnection = m_avatarsConnection; pConnection->_Lock(); m_avatarsMutex->Leave(); DWORD dwCookie = pConnection->sendUploadAvatarRequest(hContact, wRef, data, datalen); m_avatarsMutex->Enter(); pConnection->_Release(); if (dwCookie) { // return now if the request was sent successfully m_avatarsMutex->Leave(); return dwCookie; } } // we failed to send request, or avatar thread not ready // check if any request for this user is not already in the queue avatars_request *ar = m_avatarsQueue; int bYet = 0; while (ar) { if (ar->hContact == hContact && ar->type == ART_UPLOAD) { // we found it, return error m_avatarsMutex->Leave(); debugLogA("Avatars: Ignoring duplicate upload avatar request."); // make sure avatar connection is in progress requestAvatarConnection(); return 0; } ar = ar->pNext; } // add request to queue, processed after successful login ar = new avatars_request(ART_UPLOAD); // upload avatar if (!ar) { // out of memory, go away m_avatarsMutex->Leave(); return 0; } ar->hContact = hContact; ar->pData = (BYTE*)SAFE_MALLOC(datalen); if (!ar->pData) { // alloc failed m_avatarsMutex->Leave(); delete ar; return 0; } memcpy(ar->pData, data, datalen); // copy the data ar->cbData = datalen; ar->wRef = wRef; ar->pNext = m_avatarsQueue; m_avatarsQueue = ar; m_avatarsMutex->Leave(); debugLogA("Avatars: Request to upload image added to queue."); // make sure avatar connection is in progress requestAvatarConnection(); return -1; // we added to queue }
// request avatar data from server int CIcqProto::GetAvatarData(MCONTACT hContact, DWORD dwUin, const char *szUid, const BYTE *hash, size_t hashlen, const TCHAR *file) { uid_str szUidData; char *pszUid = NULL; if (!dwUin && szUid) { // create a copy in local writable buffer mir_strcpy(szUidData, szUid); pszUid = szUidData; } mir_cslockfull alck(m_avatarsMutex); if (m_avatarsConnection && m_avatarsConnection->isReady()) { // check if we are ready // check if requests for this user are not blocked for (int i = 0; i < m_arAvatars.getCount();) { avatars_request *ar = m_arAvatars[i]; if (ar->hContact == hContact && ar->type == ART_BLOCK) { // found a block item if (GetTickCount() > ar->timeOut) { // remove timeouted block m_arAvatars.remove(i); delete ar; continue; } debugLogA("Avatars: Requests for %s avatar are blocked.", strUID(dwUin, pszUid)); return 0; } i++; } mir_cslock l(m_avatarsConnection->getLock()); alck.unlock(); DWORD dwCookie = m_avatarsConnection->sendGetAvatarRequest(hContact, dwUin, pszUid, hash, hashlen, file); if (dwCookie) // return now if the request was sent successfully return dwCookie; alck.lock(); } // we failed to send request, or avatar thread not ready // check if any request for this user is not already in the queue for (int i = 0; i < m_arAvatars.getCount();) { avatars_request *ar = m_arAvatars[i]; if (ar->hContact == hContact) { // we found it, return error if (ar->type == ART_BLOCK && GetTickCount() > ar->timeOut) { // remove timeouted block m_arAvatars.remove(i); delete ar; continue; } alck.unlock(); debugLogA("Avatars: Ignoring duplicate get %s avatar request.", strUID(dwUin, pszUid)); // make sure avatar connection is in progress requestAvatarConnection(); return 0; } i++; } // add request to queue, processed after successful login avatars_request *ar = new avatars_request(ART_GET); // get avatar ar->hContact = hContact; ar->dwUin = dwUin; if (!dwUin) mir_strcpy(ar->szUid, szUid); ar->hash = (BYTE*)SAFE_MALLOC(hashlen); if (!ar->hash) { // alloc failed delete ar; return 0; } memcpy(ar->hash, hash, hashlen); // copy the data ar->hashlen = hashlen; ar->szFile = null_strdup(file); // duplicate the string m_arAvatars.insert(ar); alck.unlock(); debugLogA("Avatars: Request to get %s image added to queue.", strUID(dwUin, pszUid)); // make sure avatar connection is in progress requestAvatarConnection(); return -1; // we added to queue }
// request avatar data from server int CIcqProto::GetAvatarData(HANDLE hContact, DWORD dwUin, const char *szUid, const BYTE *hash, unsigned int hashlen, const TCHAR *file) { uid_str szUidData; char *pszUid = NULL; if (!dwUin && szUid) { // create a copy in local writable buffer strcpy(szUidData, szUid); pszUid = szUidData; } m_avatarsMutex->Enter(); if (m_avatarsConnection && m_avatarsConnection->isReady()) // check if we are ready { // check if requests for this user are not blocked DWORD dwNow = GetTickCount(); avatars_request *ar = m_avatarsQueue; while (ar) { if (ar->hContact == hContact && ar->type == ART_BLOCK) { // found a block item if (GetTickCount() > ar->timeOut) { // remove timeouted block ar = ReleaseAvatarRequestInQueue(ar); continue; } m_avatarsMutex->Leave(); debugLogA("Avatars: Requests for %s avatar are blocked.", strUID(dwUin, pszUid)); return 0; } ar = ar->pNext; } avatars_server_connection *pConnection = m_avatarsConnection; pConnection->_Lock(); m_avatarsMutex->Leave(); DWORD dwCookie = pConnection->sendGetAvatarRequest(hContact, dwUin, pszUid, hash, hashlen, file); m_avatarsMutex->Enter(); pConnection->_Release(); if (dwCookie) { // return now if the request was sent successfully m_avatarsMutex->Leave(); return dwCookie; } } // we failed to send request, or avatar thread not ready // check if any request for this user is not already in the queue avatars_request *ar = m_avatarsQueue; while (ar) { if (ar->hContact == hContact) { // we found it, return error if (ar->type == ART_BLOCK && GetTickCount() > ar->timeOut) { // remove timeouted block ar = ReleaseAvatarRequestInQueue(ar); continue; } m_avatarsMutex->Leave(); debugLogA("Avatars: Ignoring duplicate get %s avatar request.", strUID(dwUin, pszUid)); // make sure avatar connection is in progress requestAvatarConnection(); return 0; } ar = ar->pNext; } // add request to queue, processed after successful login ar = new avatars_request(ART_GET); // get avatar if (!ar) { // out of memory, go away m_avatarsMutex->Leave(); return 0; } ar->hContact = hContact; ar->dwUin = dwUin; if (!dwUin) strcpy(ar->szUid, szUid); ar->hash = (BYTE*)SAFE_MALLOC(hashlen); if (!ar->hash) { // alloc failed m_avatarsMutex->Leave(); delete ar; return 0; } memcpy(ar->hash, hash, hashlen); // copy the data ar->hashlen = hashlen; ar->szFile = null_strdup(file); // duplicate the string ar->pNext = m_avatarsQueue; m_avatarsQueue = ar; m_avatarsMutex->Leave(); debugLogA("Avatars: Request to get %s image added to queue.", strUID(dwUin, pszUid)); // make sure avatar connection is in progress requestAvatarConnection(); return -1; // we added to queue }