llassetstorage.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /**
  2. * @file llassetstorage.h
  3. * @brief definition of LLAssetStorage class which allows simple
  4. * up/downloads of uuid,type asets
  5. *
  6. * $LicenseInfo:firstyear=2001&license=viewergpl$
  7. *
  8. * Copyright (c) 2001-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_LLASSETSTORAGE_H
  34. #define LL_LLASSETSTORAGE_H
  35. #include "llassettype.h"
  36. #include "llextendedstatus.h"
  37. #include "hbfastmap.h"
  38. #include "llhost.h"
  39. #include "llnamevalue.h"
  40. #include "llpreprocessor.h"
  41. #include "llstring.h"
  42. #include "lltimer.h"
  43. #include "lltransfermanager.h" // For LLTSCode enum
  44. #include "lluuid.h"
  45. #include "llxfer.h"
  46. // Forward declarations
  47. class LLAssetStorage;
  48. class LLSD;
  49. class LLMessageSystem;
  50. class LLXferManager;
  51. // Anything that takes longer than this to download will abort. HTTP Uploads
  52. // also timeout if they take longer than this.
  53. constexpr F32 LL_ASSET_STORAGE_TIMEOUT = 5 * 60.0f;
  54. // Specific error codes
  55. constexpr int LL_ERR_ASSET_REQUEST_FAILED = -1;
  56. //constexpr int LL_ERR_ASSET_REQUEST_INVALID = -2;
  57. constexpr int LL_ERR_ASSET_REQUEST_NONEXISTENT_FILE = -3;
  58. constexpr int LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE = -4;
  59. constexpr int LL_ERR_INSUFFICIENT_PERMISSIONS = -5;
  60. constexpr int LL_ERR_PRICE_MISMATCH = -23018;
  61. class LLAssetInfo
  62. {
  63. protected:
  64. LOG_CLASS(LLAssetInfo);
  65. public:
  66. LLAssetInfo();
  67. LLAssetInfo(const LLUUID& object_id, const LLUUID& creator_id,
  68. LLAssetType::EType type, const char* name, const char* desc);
  69. LLAssetInfo(const LLNameValue& nv);
  70. LL_INLINE const std::string& getName() const { return mName; }
  71. LL_INLINE const std::string& getDescription() const { return mDescription; }
  72. void setName(const std::string& name);
  73. void setDescription(const std::string& desc);
  74. // Assets (aka potential inventory items) can be applied to an object in
  75. // the world. We'll store that as a string name value pair where the name
  76. // encodes part of asset info, and the value the rest. LLAssetInfo objects
  77. // will be responsible for parsing the meaning out froman LLNameValue
  78. // object. See the inventory design docs for details.
  79. void setFromNameValue(const LLNameValue& nv);
  80. public:
  81. LLUUID mUuid;
  82. LLTransactionID mTransactionID;
  83. LLUUID mCreatorID;
  84. LLAssetType::EType mType;
  85. protected:
  86. std::string mDescription;
  87. std::string mName;
  88. };
  89. class LLBaseDownloadRequest
  90. {
  91. public:
  92. LLBaseDownloadRequest(const LLUUID& uuid, const LLAssetType::EType at);
  93. virtual ~LLBaseDownloadRequest() = default;
  94. LL_INLINE LLUUID getUUID() const { return mUUID; }
  95. LL_INLINE LLAssetType::EType getType() const { return mType; }
  96. LL_INLINE void setUUID(const LLUUID& id) { mUUID = id; }
  97. LL_INLINE void setType(LLAssetType::EType type) { mType = type; }
  98. virtual LLBaseDownloadRequest* getCopy();
  99. void (*mDownCallback)(const LLUUID&, LLAssetType::EType, void*, S32,
  100. LLExtStat);
  101. protected:
  102. LLUUID mUUID;
  103. LLAssetType::EType mType;
  104. public:
  105. void* mUserData;
  106. LLHost mHost;
  107. F64 mTime; // Message system time
  108. bool mIsTemp;
  109. bool mIsPriority;
  110. bool mDataSentInFirstPacket;
  111. bool mDataIsInCache;
  112. };
  113. class LLAssetRequest final : public LLBaseDownloadRequest
  114. {
  115. public:
  116. LLAssetRequest(const LLUUID& uuid, const LLAssetType::EType at);
  117. LLBaseDownloadRequest* getCopy() override;
  118. virtual LLSD getTerseDetails() const;
  119. virtual LLSD getFullDetails() const;
  120. LL_INLINE void setTimeout(F64 timeout) { mTimeout = timeout; }
  121. void (*mUpCallback)(const LLUUID&, void*, S32, LLExtStat);
  122. void (*mInfoCallback)(LLAssetInfo*, void*, S32);
  123. public:
  124. LLUUID mRequestingAgentID; // Only valid for uploads from an agent
  125. F64 mTimeout; // Amount of time before timing out.
  126. bool mIsLocal;
  127. };
  128. template <class T>
  129. struct ll_asset_request_equal : public std::equal_to<T>
  130. {
  131. bool operator()(const T& x, const T& y) const
  132. {
  133. return x->getType() == y->getType() && x->getUUID() == y->getUUID();
  134. }
  135. };
  136. class LLInvItemRequest final : public LLBaseDownloadRequest
  137. {
  138. public:
  139. LLInvItemRequest(const LLUUID& uuid, const LLAssetType::EType at);
  140. LLBaseDownloadRequest* getCopy() override;
  141. };
  142. class LLEstateAssetRequest final : public LLBaseDownloadRequest
  143. {
  144. public:
  145. LLEstateAssetRequest(const LLUUID& uuid, const LLAssetType::EType at,
  146. EstateAssetType et);
  147. LLBaseDownloadRequest* getCopy() override;
  148. LL_INLINE LLAssetType::EType getAType() const { return mType; }
  149. protected:
  150. EstateAssetType mEstateAssetType;
  151. };
  152. // Map of known bad assets
  153. typedef fast_hmap<LLUUID, U64> toxic_asset_map_t;
  154. typedef void (*LLGetAssetCallback)(const LLUUID& asset_id,
  155. LLAssetType::EType type, void* user_data,
  156. S32 status, LLExtStat ext_status);
  157. class LLAssetStorage
  158. {
  159. protected:
  160. LOG_CLASS(LLAssetStorage);
  161. public:
  162. typedef void (*LLStoreAssetCallback)(const LLUUID& asset_id,
  163. void* user_data, S32 status,
  164. LLExtStat ext_status);
  165. typedef std::list<LLAssetRequest*> request_list_t;
  166. enum ERequestType
  167. {
  168. RT_INVALID = -1,
  169. RT_DOWNLOAD = 0,
  170. RT_UPLOAD = 1,
  171. RT_LOCALUPLOAD = 2,
  172. RT_COUNT = 3
  173. };
  174. LLAssetStorage(LLMessageSystem* msg, LLXferManager* xfer,
  175. const LLHost& upstream_host);
  176. LLAssetStorage(LLMessageSystem* msg, LLXferManager* xfer);
  177. virtual ~LLAssetStorage();
  178. void setUpstream(const LLHost& upstream_host);
  179. bool hasLocalAsset(const LLUUID& uuid, LLAssetType::EType type);
  180. // public interface methods
  181. // note that your callback may get called BEFORE the function returns
  182. void getAssetData(const LLUUID uuid, LLAssetType::EType atype,
  183. LLGetAssetCallback cb, void* user_data,
  184. bool is_priority = false);
  185. // TransactionID version. Viewer needs the store_local.
  186. virtual void storeAssetData(const LLTransactionID& tid,
  187. LLAssetType::EType atype,
  188. LLStoreAssetCallback callback, void* user_data,
  189. bool temp_file = false,
  190. bool is_priority = false,
  191. bool store_local = false,
  192. bool user_waiting = false,
  193. F64 timeout = LL_ASSET_STORAGE_TIMEOUT) = 0;
  194. virtual void checkForTimeouts();
  195. void getEstateAsset(const LLHost& object_sim, const LLUUID& agent_id,
  196. const LLUUID& session_id, const LLUUID& asset_id,
  197. LLAssetType::EType atype, EstateAssetType etype,
  198. LLGetAssetCallback callback, void* user_data,
  199. bool is_priority);
  200. // Get a particular inventory item.
  201. void getInvItemAsset(const LLHost& object_sim, const LLUUID& agent_id,
  202. const LLUUID& session_id, const LLUUID& owner_id,
  203. const LLUUID& task_id, const LLUUID& item_id,
  204. const LLUUID& asset_id, LLAssetType::EType atype,
  205. LLGetAssetCallback cb, void* user_data,
  206. bool is_priority = false);
  207. // Check if an asset is in the toxic map. If it is, the entry is updated.
  208. bool isAssetToxic(const LLUUID& uuid);
  209. // Clean the toxic asset list, remove old entries
  210. void flushOldToxicAssets(bool force_it);
  211. // Add an item to the toxic asset map
  212. void markAssetToxic(const LLUUID& uuid);
  213. protected:
  214. LLSD getPendingDetailsImpl(const request_list_t* requests,
  215. LLAssetType::EType asset_type,
  216. const std::string& detail_prefix) const;
  217. LLSD getPendingRequestImpl(const request_list_t* requests,
  218. LLAssetType::EType asset_type,
  219. const LLUUID& asset_id) const;
  220. bool deletePendingRequestImpl(request_list_t* requests,
  221. LLAssetType::EType asset_type,
  222. const LLUUID& asset_id);
  223. public:
  224. static const LLAssetRequest* findRequest(const request_list_t* requests,
  225. LLAssetType::EType asset_type,
  226. const LLUUID& asset_id);
  227. static LLAssetRequest* findRequest(request_list_t* requests,
  228. LLAssetType::EType asset_type,
  229. const LLUUID& asset_id);
  230. request_list_t* getRequestList(ERequestType rt);
  231. const request_list_t* getRequestList(ERequestType rt) const;
  232. static std::string getRequestName(ERequestType rt);
  233. S32 getNumPendingDownloads() const;
  234. S32 getNumPendingUploads() const;
  235. S32 getNumPendingLocalUploads();
  236. S32 getNumPending(ERequestType rt) const;
  237. LLSD getPendingDetails(ERequestType rt, LLAssetType::EType asset_type,
  238. const std::string& detail_prefix) const;
  239. LLSD getPendingRequest(ERequestType rt, LLAssetType::EType asset_type,
  240. const LLUUID& asset_id) const;
  241. bool deletePendingRequest(ERequestType rt, LLAssetType::EType asset_type,
  242. const LLUUID& asset_id);
  243. // download process callbacks
  244. static void downloadCompleteCallback(S32 result,
  245. const LLUUID& file_id,
  246. LLAssetType::EType file_type,
  247. LLBaseDownloadRequest* user_data,
  248. LLExtStat ext_status);
  249. static void downloadEstateAssetCompleteCallback(S32 result,
  250. const LLUUID& file_id,
  251. LLAssetType::EType file_type,
  252. LLBaseDownloadRequest* user_data,
  253. LLExtStat ext_status);
  254. static void downloadInvItemCompleteCallback(S32 result,
  255. const LLUUID& file_id,
  256. LLAssetType::EType file_type,
  257. LLBaseDownloadRequest* user_data,
  258. LLExtStat ext_status);
  259. static void removeAndCallbackPendingDownloads(const LLUUID& file_id,
  260. LLAssetType::EType file_type,
  261. const LLUUID& callback_id,
  262. LLAssetType::EType callback_type,
  263. S32 result_code,
  264. LLExtStat ext_status);
  265. // upload process callbacks
  266. static void uploadCompleteCallback(const LLUUID&, void* user_data,
  267. S32 result, LLExtStat ext_status);
  268. static void processUploadComplete(LLMessageSystem* msg,
  269. void** this_handle);
  270. // Debugging
  271. static const char* getErrorString(S32 status);
  272. // Deprecated file-based methods - Not overriden.
  273. void getAssetData(const LLUUID uuid, LLAssetType::EType type,
  274. void (*callback)(const char*, const LLUUID&, void*, S32,
  275. LLExtStat), void* user_data,
  276. bool is_priority = false);
  277. // TransactionID version
  278. virtual void storeAssetData(const std::string& filename,
  279. const LLTransactionID& transaction_id,
  280. LLAssetType::EType type,
  281. LLStoreAssetCallback callback,
  282. void* user_data,
  283. bool temp_file = false,
  284. bool is_priority = false,
  285. bool user_waiting = false,
  286. F64 timeout = LL_ASSET_STORAGE_TIMEOUT) = 0;
  287. static void legacyGetDataCallback(const LLUUID& uuid,
  288. LLAssetType::EType, void* user_data,
  289. S32 status, LLExtStat ext_status);
  290. static void legacyStoreDataCallback(const LLUUID& uuid, void* user_data,
  291. S32 status, LLExtStat ext_status);
  292. protected:
  293. void cleanupRequests(bool all, S32 error);
  294. void callUploadCallbacks(const LLUUID& uuid, LLAssetType::EType asset_type,
  295. bool success, LLExtStat ext_status);
  296. virtual void queueDataRequest(const LLUUID& uuid, LLAssetType::EType type,
  297. LLGetAssetCallback callback, void* user_data,
  298. bool duplicate, bool is_priority) = 0;
  299. private:
  300. void init(LLMessageSystem* msg, LLXferManager* xfer,
  301. const LLHost& upstream_host);
  302. protected:
  303. LLHost mUpstreamHost;
  304. LLMessageSystem* mMessageSys;
  305. LLXferManager* mXferManager;
  306. bool mShutDown;
  307. request_list_t mPendingDownloads;
  308. request_list_t mPendingUploads;
  309. request_list_t mPendingLocalUploads;
  310. // Map of toxic assets: these caused problems when recently rezzed, so
  311. // avoid loading them.
  312. toxic_asset_map_t mToxicAssetMap;
  313. };
  314. ////////////////////////////////////////////////////////////////////////
  315. // Wrappers to replicate deprecated API
  316. ////////////////////////////////////////////////////////////////////////
  317. class LLLegacyAssetRequest
  318. {
  319. public:
  320. void (*mDownCallback)(const char*, const LLUUID&, void*, S32, LLExtStat);
  321. LLAssetStorage::LLStoreAssetCallback mUpCallback;
  322. void* mUserData;
  323. };
  324. extern LLAssetStorage* gAssetStoragep;
  325. extern const LLUUID CATEGORIZE_LOST_AND_FOUND_ID;
  326. #endif