/usr/include/eiskaltdcpp/dcpp/ClientManager.h is in libeiskaltdcpp-dev 2.2.9-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | /*
* Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include "TimerManager.h"
#include "Client.h"
#include "Singleton.h"
#include "SettingsManager.h"
#include "User.h"
#include "Socket.h"
#include "ClientManagerListener.h"
namespace dcpp {
class UserCommand;
class ClientManager : public Speaker<ClientManagerListener>,
private ClientListener, public Singleton<ClientManager>,
private TimerManagerListener
{
public:
Client* getClient(const string& aHubURL);
void putClient(Client* aClient);
size_t getUserCount() const;
int64_t getAvailable() const;
StringList getHubs(const CID& cid, const string& hintUrl);
StringList getHubNames(const CID& cid, const string& hintUrl);
StringList getNicks(const CID& cid, const string& hintUrl);
string getField(const CID& cid, const string& hintUrl, const char* field) const;
StringList getHubs(const CID& cid, const string& hintUrl, bool priv);
StringList getHubNames(const CID& cid, const string& hintUrl, bool priv);
StringList getNicks(const CID& cid, const string& hintUrl, bool priv);
StringList getNicks(const HintedUser& user) { return getNicks(user.user->getCID(), user.hint); }
StringList getHubNames(const HintedUser& user) { return getHubNames(user.user->getCID(), user.hint); }
StringList getHubs(const HintedUser& user) { return getHubs(user.user->getCID(), user.hint); }
string getConnection(const CID& cid) const;
uint8_t getSlots(const CID& cid) const;
bool isConnected(const string& aUrl) const;
void search(int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken, void* aOwner = 0);
uint64_t search(StringList& who, int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken, const StringList& aExtList, void* aOwner = 0);
void cancelSearch(void* aOwner);
void infoUpdated();
UserPtr getUser(const string& aNick, const string& aHubUrl) noexcept;
UserPtr getUser(const CID& cid) noexcept;
string findHub(const string& ipPort) const;
string findHubEncoding(const string& aUrl) const;
/**
* @param priv discard any user that doesn't match the hint.
* @return OnlineUser* found by CID and hint; might be only by CID if priv is false.
*/
OnlineUser* findOnlineUser(const HintedUser& user, bool priv);
OnlineUser* findOnlineUser(const CID& cid, const string& hintUrl, bool priv);
UserPtr findUser(const string& aNick, const string& aHubUrl) const noexcept { return findUser(makeCid(aNick, aHubUrl)); }
UserPtr findUser(const CID& cid) const noexcept;
UserPtr findLegacyUser(const string& aNick) const noexcept;
bool isOnline(const UserPtr& aUser) const {
Lock l(cs);
return onlineUsers.find(aUser->getCID()) != onlineUsers.end();
}
Identity getOnlineUserIdentity(const UserPtr& aUser) const {
Lock l(cs);
OnlineMap::const_iterator i;
i=onlineUsers.find(aUser->getCID());
if ( i != onlineUsers.end() )
{
return i->second->getIdentity();
}
return Identity();
}
int64_t getBytesShared(const UserPtr& p) const{
int64_t l_share = 0;
{
Lock l ( cs );
OnlineIterC i = onlineUsers.find ( *const_cast<CID*> ( &p->getCID() ) );
if ( i != onlineUsers.end() )
l_share = i->second->getIdentity().getBytesShared();
}
return l_share;
}
void setIPUser(const UserPtr& user, const string& IP, uint16_t udpPort = 0) {
if(IP.empty())
return;
Lock l(cs);
OnlineMap::const_iterator i = onlineUsers.find(user->getCID());
if ( i != onlineUsers.end() ) {
i->second->getIdentity().setIp(IP);
if(udpPort > 0)
i->second->getIdentity().setUdpPort(Util::toString(udpPort));
}
}
bool isOp(const UserPtr& aUser, const string& aHubUrl) const;
/** Constructs a synthetic, hopefully unique CID */
CID makeCid(const string& nick, const string& hubUrl) const noexcept;
void putOnline(OnlineUser* ou) noexcept;
void putOffline(OnlineUser* ou, bool disconnect = false) noexcept;
UserPtr& getMe();
void send(AdcCommand& c, const CID& to);
void connect(const HintedUser& user, const string& token);
void privateMessage(const HintedUser& user, const string& msg, bool thirdPerson);
void userCommand(const HintedUser& user, const UserCommand& uc, StringMap& params, bool compatibility);
int getMode(const string& aHubUrl) const;
bool isActive(const string& aHubUrl = Util::emptyString) const { return getMode(aHubUrl) != SettingsManager::INCOMING_FIREWALL_PASSIVE; }
static bool ucExecuteLua(const string& cmd, StringMap& params) noexcept;
#ifdef DO_NOT_USE_MUTEX
void lock() noexcept { cs.lock(); }
void unlock() noexcept { cs.unlock(); }
#else // DO_NOT_USE_MUTEX
Lock lock() { return Lock(cs); }
#endif // DO_NOT_USE_MUTEX
Client::List& getClients() { return clients; }
CID getMyCID();
const CID& getMyPID();
void loadUsers();
void saveUsers() const;
void saveUser(const CID& cid);
#ifdef WITH_DHT
OnlineUserPtr findDHTNode(const CID& cid) const;
#endif
private:
typedef unordered_map<string, UserPtr> LegacyMap;
typedef LegacyMap::iterator LegacyIter;
typedef unordered_map<CID, UserPtr> UserMap;
typedef UserMap::iterator UserIter;
typedef std::pair<std::string, bool> NickMapEntry; // the boolean being true means "save this".
typedef unordered_map<CID, NickMapEntry> NickMap;
typedef unordered_multimap<CID, OnlineUser*> OnlineMap;
typedef OnlineMap::iterator OnlineIter;
typedef OnlineMap::const_iterator OnlineIterC;
typedef pair<OnlineIter, OnlineIter> OnlinePair;
typedef pair<OnlineIterC, OnlineIterC> OnlinePairC;
Client::List clients;
mutable CriticalSection cs;
UserMap users;
OnlineMap onlineUsers;
NickMap nicks;
UserPtr me;
Socket udp;
CID pid;
friend class Singleton<ClientManager>;
ClientManager() {
TimerManager::getInstance()->addListener(this);
}
virtual ~ClientManager() {
TimerManager::getInstance()->removeListener(this);
}
void updateNick(const OnlineUser& user) noexcept;
/// @return OnlineUser* found by CID and hint; discard any user that doesn't match the hint.
OnlineUser* findOnlineUserHint(const CID& cid, const string& hintUrl) const {
OnlinePairC p;
return findOnlineUserHint(cid, hintUrl, p);
}
/**
* @param p OnlinePair of all the users found by CID, even those who don't match the hint.
* @return OnlineUser* found by CID and hint; discard any user that doesn't match the hint.
*/
OnlineUser* findOnlineUserHint(const CID& cid, const string& hintUrl, OnlinePairC& p) const;
string getUsersFile() const { return Util::getPath(Util::PATH_USER_LOCAL) + "Users.xml"; }
// ClientListener
virtual void on(Connected, Client* c) noexcept;
virtual void on(UserUpdated, Client*, const OnlineUser& user) noexcept;
virtual void on(UsersUpdated, Client* c, const OnlineUserList&) noexcept;
virtual void on(Failed, Client*, const string&) noexcept;
virtual void on(HubUpdated, Client* c) noexcept;
virtual void on(HubUserCommand, Client*, int, int, const string&, const string&) noexcept;
virtual void on(NmdcSearch, Client* aClient, const string& aSeeker, int aSearchType, int64_t aSize,
int aFileType, const string& aString) noexcept;
virtual void on(AdcSearch, Client* c, const AdcCommand& adc, const CID& from) noexcept;
// TimerManagerListener
virtual void on(TimerManagerListener::Minute, uint64_t aTick) noexcept;
};
} // namespace dcpp
|