llinventory.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /**
  2. * @file llinventory.h
  3. * @brief LLInventoryItem and LLInventoryCategory class declaration.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLINVENTORY_H
  33. #define LL_LLINVENTORY_H
  34. #include <functional>
  35. #include <vector>
  36. #include "llassetstorage.h"
  37. #include "llerror.h"
  38. #include "llfoldertype.h"
  39. #include "llinventorytype.h"
  40. #include "llpermissions.h"
  41. #include "llpreprocessor.h"
  42. #include "llrefcount.h"
  43. #include "llsaleinfo.h"
  44. #include "llsd.h"
  45. #include "lluuid.h"
  46. #include "llxmlnode.h"
  47. class LLMessageSystem;
  48. class LLInventoryCategory;
  49. class LLInventoryItem;
  50. class LLViewerInventoryItem;
  51. class LLViewerInventoryCategory;
  52. // Constants for Key field in the task inventory update message
  53. constexpr U8 TASK_INVENTORY_ITEM_KEY = 0;
  54. #if 0 // Not used. HB
  55. constexpr U8 TASK_INVENTORY_ASSET_KEY = 1;
  56. #endif
  57. // Anonymous enumeration to specify a max inventory buffer size for use in
  58. // packBinaryBucket()
  59. enum
  60. {
  61. MAX_INVENTORY_BUFFER_SIZE = 1024
  62. };
  63. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64. // Base class for anything in the user's inventory. Handles the common code
  65. // between items and categories.
  66. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67. class LLInventoryObject : public LLRefCount
  68. {
  69. protected:
  70. LOG_CLASS(LLInventoryObject);
  71. ~LLInventoryObject() override = default;
  72. public:
  73. typedef std::list<LLPointer<LLInventoryObject> > object_list_t;
  74. LLInventoryObject();
  75. LLInventoryObject(const LLUUID& uuid, const LLUUID& parent_uuid,
  76. LLAssetType::EType type, const std::string& name);
  77. LL_INLINE virtual LLInventoryItem* asInventoryItem()
  78. {
  79. return NULL;
  80. }
  81. LL_INLINE virtual const LLInventoryItem* asInventoryItem() const
  82. {
  83. return NULL;
  84. }
  85. LL_INLINE virtual LLInventoryCategory* asInventoryCategory()
  86. {
  87. return NULL;
  88. }
  89. LL_INLINE virtual const LLInventoryCategory* asInventoryCategory() const
  90. {
  91. return NULL;
  92. }
  93. LL_INLINE virtual LLViewerInventoryItem* asViewerInventoryItem()
  94. {
  95. return NULL;
  96. }
  97. LL_INLINE virtual const LLViewerInventoryItem* asViewerInventoryItem() const
  98. {
  99. return NULL;
  100. }
  101. LL_INLINE virtual LLViewerInventoryCategory* asViewerInventoryCategory()
  102. {
  103. return NULL;
  104. }
  105. LL_INLINE virtual const LLViewerInventoryCategory* asViewerInventoryCategory() const
  106. {
  107. return NULL;
  108. }
  109. // LLRefCount requires custom copy:
  110. void copyObject(const LLInventoryObject* otherp);
  111. // File support. Implemented here so that a minimal information set can be
  112. // transmitted between simulator and viewer.
  113. virtual bool importLegacyStream(std::istream& input_stream);
  114. virtual bool exportLegacyStream(std::ostream& output_stream,
  115. bool include_asset_key = true) const;
  116. virtual void updateParentOnServer(bool) const;
  117. virtual void updateServer(bool) const;
  118. // Inventory Id that this item points to
  119. LL_INLINE virtual const LLUUID& getUUID() const { return mUUID; }
  120. // Inventory Id that this item points to, else this item's inventory Id
  121. // See LLInventoryItem override.
  122. LL_INLINE virtual const LLUUID& getLinkedUUID() const { return mUUID; }
  123. LL_INLINE const LLUUID& getParentUUID() const { return mParentUUID; }
  124. LL_INLINE virtual const LLUUID& getThumbnailUUID() const
  125. {
  126. return mThumbnailUUID;
  127. }
  128. LL_INLINE void setThumbnailUUID(const LLUUID& id) { mThumbnailUUID = id; }
  129. LL_INLINE virtual const std::string& getName() const { return mName; }
  130. LL_INLINE virtual LLAssetType::EType getType() const { return mType; }
  131. // To bypass linked items, since llviewerinventory's getType() will return
  132. // the linked-to item's type instead of this object's type:
  133. LL_INLINE LLAssetType::EType getActualType() const { return mType; }
  134. LL_INLINE bool getIsLinkType() const
  135. {
  136. return LLAssetType::lookupIsLinkType(mType);
  137. }
  138. LL_INLINE virtual time_t getCreationDate() const { return mCreationDate; }
  139. // Mutators not calling updateServer()
  140. LL_INLINE void setUUID(const LLUUID& new_uuid) { mUUID = new_uuid; }
  141. LL_INLINE void setParent(const LLUUID& new_parent) { mParentUUID = new_parent; }
  142. LL_INLINE void setType(LLAssetType::EType type) { mType = type; }
  143. virtual void rename(const std::string& new_name);
  144. // Only stored for items
  145. LL_INLINE virtual void setCreationDate(time_t utc) { mCreationDate = utc; }
  146. // In-place correction for inventory name string
  147. static void correctInventoryName(std::string& name);
  148. protected:
  149. // Note: the first member variable is 32 bits in order to align on 64 bits
  150. // for the next variables, counting the 32 bits counter from LLRefCount. HB
  151. LLAssetType::EType mType;
  152. std::string mName;
  153. LLUUID mUUID;
  154. // Parent category. Root categories have LLUUID::NULL.
  155. LLUUID mParentUUID;
  156. LLUUID mThumbnailUUID;
  157. time_t mCreationDate; // Seconds since 1970-01-01, UTC
  158. };
  159. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  160. // A class for an item in the current user's inventory.
  161. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  162. class LLInventoryItem : public LLInventoryObject
  163. {
  164. protected:
  165. LOG_CLASS(LLInventoryItem);
  166. ~LLInventoryItem() override = default;
  167. public:
  168. typedef std::vector<LLPointer<LLInventoryItem> > item_array_t;
  169. enum
  170. {
  171. // The shared flags at the top are shared among all inventory types.
  172. // After that section, all values of flags are type dependent. The
  173. //shared flags will start at 2^30 and work down while item type
  174. // specific flags will start at 2^0 and work up.
  175. II_FLAGS_NONE = 0,
  176. //
  177. // Shared flags
  178. //
  179. //
  180. // This value means that the asset has only one reference in the
  181. // system. If the inventory item is deleted, or the asset Id updated,
  182. // then we can remove the old reference.
  183. II_FLAGS_SHARED_SINGLE_REFERENCE = 0x40000000,
  184. //
  185. // Landmark flags
  186. //
  187. II_FLAGS_LANDMARK_VISITED = 1,
  188. //
  189. // Object flags
  190. //
  191. // flag to indicate that object permissions should have next owner perm
  192. // be more restrictive on rez. We bump this into the second byte of the
  193. // flags since the low byte is used to track attachment points.
  194. II_FLAGS_OBJECT_SLAM_PERM = 0x100,
  195. // flag to indicate that the object sale information has been changed.
  196. II_FLAGS_OBJECT_SLAM_SALE = 0x1000,
  197. // These flags specify which permissions masks to overwrite upon rez.
  198. // Normally, if no permissions slam (above) or overwrite flags are set,
  199. // the asset's permissions are used and the inventory's permissions are
  200. // ignored. If any of these flags are set, the inventory's permissions
  201. // take precedence.
  202. II_FLAGS_OBJECT_PERM_OVERWRITE_BASE = 0x010000,
  203. II_FLAGS_OBJECT_PERM_OVERWRITE_OWNER = 0x020000,
  204. II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP = 0x040000,
  205. II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE = 0x080000,
  206. II_FLAGS_OBJECT_PERM_OVERWRITE_NEXT_OWNER = 0x100000,
  207. // flag to indicate whether an object that is returned is composed
  208. // of multiple items or not.
  209. II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS = 0x200000,
  210. // Some items like Wearables and Settings use the low order byte of
  211. // flags to store the sub type of the inventory item. EWearableType
  212. // enumeration found in llappearance/llwearable.h
  213. II_FLAGS_SUBTYPE_MASK = 0x0000ff,
  214. II_FLAGS_PERM_OVERWRITE_MASK = (II_FLAGS_OBJECT_SLAM_PERM |
  215. II_FLAGS_OBJECT_SLAM_SALE |
  216. II_FLAGS_OBJECT_PERM_OVERWRITE_BASE |
  217. II_FLAGS_OBJECT_PERM_OVERWRITE_OWNER |
  218. II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP |
  219. II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE |
  220. II_FLAGS_OBJECT_PERM_OVERWRITE_NEXT_OWNER),
  221. // These bits need to be cleared whenever the asset_id is updated
  222. // on a pre-existing inventory item (DEV-28098 and DEV-30997)
  223. };
  224. LLInventoryItem(const LLUUID& uuid, const LLUUID& parent_uuid,
  225. const LLPermissions& permissions, const LLUUID& asset_uuid,
  226. LLAssetType::EType type, LLInventoryType::EType inv_type,
  227. const std::string& name, const std::string& desc,
  228. const LLSaleInfo& sale_info, U32 flags, S32 creation_date);
  229. LLInventoryItem();
  230. // Create a copy of an inventory item from a pointer to another item
  231. // Note: because InventoryItems are ref counted, reference copy (a = b) is
  232. // prohibited
  233. LLInventoryItem(const LLInventoryItem* otherp);
  234. LL_INLINE LLInventoryItem* asInventoryItem() override
  235. {
  236. return this;
  237. }
  238. LL_INLINE const LLInventoryItem* asInventoryItem() const override
  239. {
  240. return this;
  241. }
  242. // LLRefCount requires custom copy:
  243. virtual void copyItem(const LLInventoryItem* otherp);
  244. LL_INLINE void generateUUID() { mUUID.generate(); }
  245. const LLUUID& getLinkedUUID() const override;
  246. LL_INLINE virtual const LLPermissions& getPermissions() const
  247. {
  248. return mPermissions;
  249. }
  250. LL_INLINE virtual const LLUUID& getCreatorUUID() const
  251. {
  252. return mPermissions.getCreator();
  253. }
  254. LL_INLINE virtual const LLUUID& getAssetUUID() const { return mAssetUUID; }
  255. LL_INLINE virtual const std::string& getDescription() const
  256. {
  257. return mDescription;
  258. }
  259. // Does not follow links
  260. LL_INLINE virtual const std::string& getActualDescription() const
  261. {
  262. return mDescription;
  263. }
  264. LL_INLINE virtual const LLSaleInfo& getSaleInfo() const
  265. {
  266. return mSaleInfo;
  267. }
  268. LL_INLINE virtual LLInventoryType::EType getInventoryType() const
  269. {
  270. return mInventoryType;
  271. }
  272. LL_INLINE virtual U32 getFlags() const { return mFlags; }
  273. LL_INLINE time_t getCreationDate() const override { return mCreationDate; }
  274. virtual U32 getCRC32() const; // really more of a checksum.
  275. LL_INLINE void setAssetUUID(const LLUUID& id) { mAssetUUID = id; }
  276. static void correctInventoryDescription(std::string& name);
  277. void setDescription(const std::string& new_desc);
  278. LL_INLINE void setSaleInfo(const LLSaleInfo& info) { mSaleInfo = info; }
  279. void setPermissions(const LLPermissions& perm);
  280. LL_INLINE void setInventoryType(LLInventoryType::EType inv_type)
  281. {
  282. mInventoryType = inv_type;
  283. }
  284. LL_INLINE void setFlags(U32 flags) { mFlags = flags; }
  285. // Currently only used in the Viewer to handle calling cards where the
  286. // creator is actually used to store the target.
  287. LL_INLINE void setCreator(const LLUUID& creator)
  288. {
  289. mPermissions.setCreator(creator);
  290. }
  291. // Checks for changes in permissions masks and sale info and sets the
  292. // corresponding bits in mFlags.
  293. void accumulatePermissionSlamBits(const LLInventoryItem& old_item);
  294. // Puts this inventory item onto the current outgoing mesage.
  295. // Assumes you have already called nextBlock().
  296. virtual void packMessage(LLMessageSystem* msg) const;
  297. // Returns true if the inventory item came through the network correctly.
  298. // Uses a simple crc check which is defeatable, but we want to detect
  299. // network mangling somehow.
  300. virtual bool unpackMessage(LLMessageSystem* msg, const char* block,
  301. S32 block_num = 0);
  302. // File support
  303. bool importLegacyStream(std::istream& input_stream) override;
  304. bool exportLegacyStream(std::ostream& output_stream,
  305. bool include_asset_key = true) const override;
  306. // Helper methods
  307. LLSD asLLSD() const;
  308. void asLLSD(LLSD& sd) const;
  309. bool fromLLSD(const LLSD& sd, bool is_new = true);
  310. // Used to compare two inventory items independently of their current UUID,
  311. // parent folder, and creation date: when their hashContents() is the same,
  312. // they are just copies. HB
  313. LLUUID hashContents() const;
  314. protected:
  315. LLUUID mAssetUUID;
  316. std::string mDescription;
  317. LLSaleInfo mSaleInfo;
  318. LLPermissions mPermissions;
  319. U32 mFlags;
  320. LLInventoryType::EType mInventoryType;
  321. };
  322. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  323. // A class for category/folder of inventory items. Users come with a set of
  324. // default categories, and can create new ones as needed.
  325. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  326. class LLInventoryCategory : public LLInventoryObject
  327. {
  328. protected:
  329. LOG_CLASS(LLInventoryCategory);
  330. ~LLInventoryCategory() override = default;
  331. public:
  332. typedef std::vector<LLPointer<LLInventoryCategory> > cat_array_t;
  333. LLInventoryCategory(const LLUUID& uuid, const LLUUID& parent_uuid,
  334. LLFolderType::EType preferred_type,
  335. const std::string& name);
  336. LLInventoryCategory();
  337. LLInventoryCategory(const LLInventoryCategory* otherp);
  338. LL_INLINE LLInventoryCategory* asInventoryCategory() override
  339. {
  340. return this;
  341. }
  342. LL_INLINE const LLInventoryCategory* asInventoryCategory() const override
  343. {
  344. return this;
  345. }
  346. // LLRefCount requires custom copy
  347. void copyCategory(const LLInventoryCategory* otherp);
  348. LL_INLINE LLFolderType::EType getPreferredType() const { return mPreferredType; }
  349. LL_INLINE void setPreferredType(LLFolderType::EType t) { mPreferredType = t; }
  350. LLSD asLLSD() const;
  351. LLSD asAISCreateCatLLSD() const;
  352. bool fromLLSD(const LLSD& sd);
  353. // Messaging
  354. virtual void packMessage(LLMessageSystem* msg) const;
  355. virtual void unpackMessage(LLMessageSystem* msg, const char* block,
  356. S32 block_num = 0);
  357. // File support
  358. bool importLegacyStream(std::istream& input_stream) override;
  359. bool exportLegacyStream(std::ostream& output_stream,
  360. bool include_asset_key = true) const override;
  361. protected:
  362. // Type that this category was "meant" to hold (although it may hold any
  363. // type)
  364. LLFolderType::EType mPreferredType;
  365. };
  366. #endif // LL_LLINVENTORY_H