1// 2// This file is part of the aMule Project. 3// 4// Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org ) 5// Copyright (c) 2003-2011 Stu Redman ( sturedman@amule.org / http://www.amule.org ) 6// 7// Any parts of this program derived from the xMule, lMule or eMule project, 8// or contributed by third-party developers are copyrighted by their 9// respective authors. 10// 11// This program is free software; you can redistribute it and/or modify 12// it under the terms of the GNU General Public License as published by 13// the Free Software Foundation; either version 2 of the License, or 14// (at your option) any later version. 15// 16// This program is distributed in the hope that it will be useful, 17// but WITHOUT ANY WARRANTY; without even the implied warranty of 18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19// GNU General Public License for more details. 20// 21// You should have received a copy of the GNU General Public License 22// along with this program; if not, write to the Free Software 23// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 24// 25 26#include "ClientRef.h" 27#include "amule.h" // Needed fot theApp 28 29#ifdef CLIENT_GUI 30#include "UpDownClientEC.h" // Needed for CUpDownClient 31#else 32#include "updownclient.h" // Needed for CUpDownClient 33#endif 34 35#ifdef DEBUG_ZOMBIE_CLIENTS 36#define MFROM m_from 37#define ASSIGN_MFROM(a) m_from = a 38#else 39#define MFROM 40#define ASSIGN_MFROM(a) 41#endif 42 43 44CClientRef::CClientRef(const CClientRef& ref) 45{ 46 m_client = ref.m_client; 47 ASSIGN_MFROM(wxT("copy ctor of ") + ref.m_from); 48 if (m_client) { 49 m_client->Link(MFROM); 50 } 51} 52 53 54CClientRef::CClientRef(CUpDownClient * client LINKED_FROM) 55{ 56 m_client = client; 57 ASSIGN_MFROM(from); 58 if (m_client) { 59 m_client->Link(MFROM); 60 } 61} 62 63 64void CClientRef::Link(CUpDownClient * client LINKED_FROM) 65{ 66 Unlink(); 67 m_client = client; 68 ASSIGN_MFROM(from); 69 if (m_client) { 70 m_client->Link(MFROM); 71 } 72} 73 74 75void CClientRef::Unlink() 76{ 77 if (m_client) { 78 m_client->Unlink(MFROM); 79 m_client = NULL; 80 } 81} 82 83 84// in amulegui clients are never deleted except when they are marked as removed through EC 85#ifndef CLIENT_GUI 86 87CUpDownClient * CClientRef::GetClientChecked() 88{ 89 if (m_client && m_client->HasBeenDeleted()) { 90 m_client->Unlink(MFROM); 91 m_client = NULL; 92 } 93 return m_client; 94} 95 96 97CClientRef& CClientRef::GetRef() 98{ 99 if (m_client && m_client->HasBeenDeleted()) { 100 m_client->Unlink(MFROM); 101 m_client = NULL; 102 } 103 return *this; 104} 105 106 107void CClientRef::Safe_Delete() 108{ 109 CUpDownClient * client = m_client; 110 if (client) { 111 Unlink(); 112 client->Safe_Delete(); 113 } 114} 115#endif 116 117 118#define WRAPC(func) CClientRef::func() const { return m_client->func(); } 119 120uint32 WRAPC(ECID) 121bool WRAPC(ExtProtocolAvailable) 122uint16 WRAPC(GetAvailablePartCount) 123const wxString& WRAPC(GetClientFilename) 124const wxString& WRAPC(GetClientModString) 125const wxString& WRAPC(GetClientOSInfo) 126uint8 WRAPC(GetClientSoft) 127const wxString& WRAPC(GetClientVerString) 128uint64 WRAPC(GetDownloadedTotal) 129uint8 WRAPC(GetDownloadState) 130CFriend* WRAPC(GetFriend) 131bool WRAPC(GetFriendSlot) 132wxString WRAPC(GetFullIP) 133uint32 WRAPC(GetIP) 134uint16 WRAPC(GetKadPort) 135float WRAPC(GetKBpsDown) 136uint16 WRAPC(GetLastDownloadingPart) 137uint16 WRAPC(GetNextRequestedPart) 138uint8 WRAPC(GetObfuscationStatus) 139uint16 WRAPC(GetOldRemoteQueueRank) 140const BitVector& WRAPC(GetPartStatus) 141uint16 WRAPC(GetRemoteQueueRank) 142CPartFile* WRAPC(GetRequestFile) 143uint32 WRAPC(GetScore) 144double WRAPC(GetScoreRatio) 145uint32 WRAPC(GetServerIP) 146const wxString WRAPC(GetServerName) 147uint16 WRAPC(GetServerPort) 148const wxString& WRAPC(GetSoftStr) 149const wxString& WRAPC(GetSoftVerStr) 150int WRAPC(GetSourceFrom) 151uint64 WRAPC(GetTransferredDown) 152uint64 WRAPC(GetTransferredUp) 153uint32 WRAPC(GetUploadDatarate) 154uint64 WRAPC(GetUploadedTotal) 155const CKnownFile* WRAPC(GetUploadFile) 156uint16 WRAPC(GetUploadQueueWaitingPosition) 157uint8 WRAPC(GetUploadState) 158size_t WRAPC(GetUpPartCount) 159uint32 WRAPC(GetUserIDHybrid) 160const wxString& WRAPC(GetUserName) 161uint16_t WRAPC(GetUserPort) 162const CMD4Hash& WRAPC(GetUserHash) 163uint32 WRAPC(GetVersion) 164bool WRAPC(HasDisabledSharedFiles) 165bool WRAPC(HasLowID) 166bool WRAPC(IsBadGuy) 167bool WRAPC(IsFriend) 168bool WRAPC(IsIdentified) 169bool WRAPC(IsRemoteQueueFull) 170void WRAPC(RequestSharedFileList) 171 172bool CClientRef::IsUpPartAvailable(uint16 iPart) const { return m_client->IsUpPartAvailable(iPart); } 173void CClientRef::SetFriend(CFriend* newfriend) const { m_client->SetFriend(newfriend); } 174void CClientRef::SetFriendSlot(bool bNV) const { m_client->SetFriendSlot(bNV); } 175 176#ifndef CLIENT_GUI 177void WRAPC(ClearUploadFileID) 178uint16 WRAPC(GetUDPPort) 179void CClientRef::SetCommentDirty(bool bDirty) const { m_client->SetCommentDirty(bDirty); } 180#endif 181 182bool CClientRef::SwapToAnotherFile(bool bIgnoreNoNeeded, bool ignoreSuspensions, bool bRemoveCompletely, CPartFile* toFile) const 183{ 184 return m_client->SwapToAnotherFile(bIgnoreNoNeeded, ignoreSuspensions, bRemoveCompletely, toFile); 185} 186 187wxString CClientRef::GetSecureIdentTextStatus() const 188{ 189 wxString ret; 190 if (theApp->CryptoAvailable()) { 191 if (m_client->SUINotSupported()) { 192 ret = _("Not supported"); 193 } else if (m_client->SUIFailed()) { 194 ret = _("Failed"); 195 } else if (m_client->SUINeeded()) { 196 ret = _("Not complete"); 197 } else if (m_client->IsBadGuy()) { 198 ret = _("Bad Guy"); 199 } else if (m_client->IsIdentified()) { 200 ret = _("Verified - OK"); 201 } 202 } else { 203 ret = _("Not Available"); 204 } 205 return ret; 206} 207 208