Fixed loading of zipped IP filter (#1674)
[amule.git] / src / ClientRef.cpp
blobafd8d4a1ea4e29dc23d4e2bc8ffb1b3cf2989248
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.
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.
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.
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
26 #include "ClientRef.h"
27 #include "amule.h" // Needed fot theApp
29 #ifdef CLIENT_GUI
30 #include "UpDownClientEC.h" // Needed for CUpDownClient
31 #else
32 #include "updownclient.h" // Needed for CUpDownClient
33 #endif
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
44 CClientRef::CClientRef(const CClientRef& ref)
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);
54 CClientRef::CClientRef(CUpDownClient * client LINKED_FROM)
56 m_client = client;
57 ASSIGN_MFROM(from);
58 if (m_client) {
59 m_client->Link(MFROM);
64 void CClientRef::Link(CUpDownClient * client LINKED_FROM)
66 Unlink();
67 m_client = client;
68 ASSIGN_MFROM(from);
69 if (m_client) {
70 m_client->Link(MFROM);
75 void CClientRef::Unlink()
77 if (m_client) {
78 m_client->Unlink(MFROM);
79 m_client = NULL;
84 // in amulegui clients are never deleted except when they are marked as removed through EC
85 #ifndef CLIENT_GUI
87 CUpDownClient * CClientRef::GetClientChecked()
89 if (m_client && m_client->HasBeenDeleted()) {
90 m_client->Unlink(MFROM);
91 m_client = NULL;
93 return m_client;
97 CClientRef& CClientRef::GetRef()
99 if (m_client && m_client->HasBeenDeleted()) {
100 m_client->Unlink(MFROM);
101 m_client = NULL;
103 return *this;
107 void CClientRef::Safe_Delete()
109 CUpDownClient * client = m_client;
110 if (client) {
111 Unlink();
112 client->Safe_Delete();
115 #endif
118 #define WRAPC(func) CClientRef::func() const { return m_client->func(); }
120 uint32 WRAPC(ECID)
121 bool WRAPC(ExtProtocolAvailable)
122 uint16 WRAPC(GetAvailablePartCount)
123 const wxString& WRAPC(GetClientFilename)
124 const wxString& WRAPC(GetClientModString)
125 const wxString& WRAPC(GetClientOSInfo)
126 uint8 WRAPC(GetClientSoft)
127 const wxString& WRAPC(GetClientVerString)
128 uint64 WRAPC(GetDownloadedTotal)
129 uint8 WRAPC(GetDownloadState)
130 CFriend* WRAPC(GetFriend)
131 bool WRAPC(GetFriendSlot)
132 wxString WRAPC(GetFullIP)
133 uint32 WRAPC(GetIP)
134 uint16 WRAPC(GetKadPort)
135 float WRAPC(GetKBpsDown)
136 uint16 WRAPC(GetLastDownloadingPart)
137 uint16 WRAPC(GetNextRequestedPart)
138 uint8 WRAPC(GetObfuscationStatus)
139 uint16 WRAPC(GetOldRemoteQueueRank)
140 const BitVector& WRAPC(GetPartStatus)
141 uint16 WRAPC(GetRemoteQueueRank)
142 CPartFile* WRAPC(GetRequestFile)
143 uint32 WRAPC(GetScore)
144 double WRAPC(GetScoreRatio)
145 uint32 WRAPC(GetServerIP)
146 const wxString WRAPC(GetServerName)
147 uint16 WRAPC(GetServerPort)
148 const wxString& WRAPC(GetSoftStr)
149 const wxString& WRAPC(GetSoftVerStr)
150 int WRAPC(GetSourceFrom)
151 uint64 WRAPC(GetTransferredDown)
152 uint64 WRAPC(GetTransferredUp)
153 uint32 WRAPC(GetUploadDatarate)
154 uint64 WRAPC(GetUploadedTotal)
155 const CKnownFile* WRAPC(GetUploadFile)
156 uint16 WRAPC(GetUploadQueueWaitingPosition)
157 uint8 WRAPC(GetUploadState)
158 size_t WRAPC(GetUpPartCount)
159 uint32 WRAPC(GetUserIDHybrid)
160 const wxString& WRAPC(GetUserName)
161 uint16_t WRAPC(GetUserPort)
162 const CMD4Hash& WRAPC(GetUserHash)
163 uint32 WRAPC(GetVersion)
164 bool WRAPC(HasDisabledSharedFiles)
165 bool WRAPC(HasLowID)
166 bool WRAPC(IsBadGuy)
167 bool WRAPC(IsFriend)
168 bool WRAPC(IsIdentified)
169 bool WRAPC(IsRemoteQueueFull)
170 void WRAPC(RequestSharedFileList)
172 bool CClientRef::IsUpPartAvailable(uint16 iPart) const { return m_client->IsUpPartAvailable(iPart); }
173 void CClientRef::SetFriend(CFriend* newfriend) const { m_client->SetFriend(newfriend); }
174 void CClientRef::SetFriendSlot(bool bNV) const { m_client->SetFriendSlot(bNV); }
176 #ifndef CLIENT_GUI
177 void WRAPC(ClearUploadFileID)
178 uint16 WRAPC(GetUDPPort)
179 void CClientRef::SetCommentDirty(bool bDirty) const { m_client->SetCommentDirty(bDirty); }
180 #endif
182 bool CClientRef::SwapToAnotherFile(bool bIgnoreNoNeeded, bool ignoreSuspensions, bool bRemoveCompletely, CPartFile* toFile) const
184 return m_client->SwapToAnotherFile(bIgnoreNoNeeded, ignoreSuspensions, bRemoveCompletely, toFile);
187 wxString CClientRef::GetSecureIdentTextStatus() const
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");
202 } else {
203 ret = _("Not Available");
205 return ret;