1 /* 2 * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 19 #pragma once 20 21 #include "forward.h" 22 #include "FastAlloc.h" 23 #include "MerkleTree.h" 24 #include "AdcCommand.h" 25 #include "Pointer.h" 26 27 namespace dcpp { 28 29 class SearchManager; 30 31 class SearchResult : public FastAlloc<SearchResult>, public intrusive_ptr_base<SearchResult> { 32 public: 33 enum Types { 34 TYPE_FILE, 35 TYPE_DIRECTORY 36 }; 37 38 SearchResult(Types aType, int64_t aSize, const string& name, const TTHValue& aTTH); 39 40 SearchResult(const UserPtr& aUser, Types aType, int aSlots, int aFreeSlots, 41 int64_t aSize, const string& aFile, const string& aHubName, 42 const string& aHubURL, const string& ip, TTHValue aTTH, const string& aToken); 43 44 string getBaseName() const; 45 string toSR(const Client& client) const; 46 AdcCommand toRES(char type) const; 47 getUser()48 UserPtr& getUser() { return user; } getSlotString()49 string getSlotString() const { return Util::toString(getFreeSlots()) + '/' + Util::toString(getSlots()); } 50 getFile()51 const string& getFile() const { return file; } getHubURL()52 const string& getHubURL() const { return hubURL; } getHubName()53 const string& getHubName() const { return hubName; } getSize()54 int64_t getSize() const { return size; } getType()55 Types getType() const { return type; } getSlots()56 int getSlots() const { return aslots; } getFreeSlots()57 int getFreeSlots() const { return freeSlots; } getTTH()58 TTHValue getTTH() const { return tth; } getIP()59 const string& getIP() const { return IP; } getToken()60 const string& getToken() const { return token; } 61 #ifdef WITH_DHT 62 // for DHT use only setSlots(size_t _slots)63 void setSlots(size_t _slots) { aslots = _slots; } 64 #endif 65 private: 66 friend class SearchManager; 67 68 SearchResult(); 69 70 SearchResult(const SearchResult& rhs); 71 72 string file; 73 string hubName; 74 string hubURL; 75 UserPtr user; 76 int64_t size; 77 Types type; 78 int aslots; 79 int freeSlots; 80 string IP; 81 TTHValue tth; 82 string token; 83 }; 84 85 } 86