00001 
00032 #ifndef LL_LLINVENTORY_H
00033 #define LL_LLINVENTORY_H
00034 
00035 #include <functional>
00036 
00037 #include "llassetstorage.h"
00038 #include "lldarray.h"
00039 #include "llinventorytype.h"
00040 #include "llmemtype.h"
00041 #include "llpermissions.h"
00042 #include "llsaleinfo.h"
00043 #include "llsd.h"
00044 #include "lluuid.h"
00045 #include "llxmlnode.h"
00046 
00047 
00048 extern const U8 TASK_INVENTORY_ITEM_KEY;
00049 extern const U8 TASK_INVENTORY_ASSET_KEY;
00050 
00051 
00052 
00053 enum
00054 {
00055         MAX_INVENTORY_BUFFER_SIZE = 1024
00056 };
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 class LLMessageSystem;
00071 
00072 class LLInventoryObject : public LLRefCount
00073 {
00074 protected:
00075         LLUUID mUUID;
00076         LLUUID mParentUUID;
00077         LLAssetType::EType mType;
00078         LLString mName;
00079 
00080 protected:
00081         virtual ~LLInventoryObject( void );
00082         
00083 public:
00084         MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
00085         LLInventoryObject(const LLUUID& uuid, const LLUUID& parent_uuid,
00086                                           LLAssetType::EType type, const LLString& name);
00087         LLInventoryObject();
00088         virtual void copy(const LLInventoryObject* other); 
00089 
00090         
00091         const LLUUID& getUUID() const;
00092         const LLUUID& getParentUUID() const;
00093         const LLString& getName() const;
00094         LLAssetType::EType getType() const;
00095 
00096         
00097         void setUUID(const LLUUID& new_uuid);
00098         void rename(const LLString& new_name);
00099         void setParent(const LLUUID& new_parent);
00100         void setType(LLAssetType::EType type);
00101 
00102         
00103         
00104 
00105         virtual BOOL exportFile(FILE* fp, BOOL include_asset_key = TRUE) const;
00106 
00107         virtual BOOL importLegacyStream(std::istream& input_stream);
00108         virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
00109 
00110         
00111         virtual void removeFromServer();
00112         virtual void updateParentOnServer(BOOL) const;
00113         virtual void updateServer(BOOL) const;
00114 };
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 class LLInventoryItem : public LLInventoryObject
00124 {
00125 public:
00126         typedef LLDynamicArray<LLPointer<LLInventoryItem> > item_array_t;
00127         
00128 protected:
00129         LLPermissions mPermissions;
00130         LLUUID mAssetUUID;
00131         LLString mDescription;
00132         LLSaleInfo mSaleInfo;
00133         LLInventoryType::EType mInventoryType;
00134         U32 mFlags;
00135         S32 mCreationDate;      
00136 
00137 public:
00138         enum
00139         {
00140                 
00141                 
00142                 II_FLAGS_NONE = 0,
00143 
00144                 
00145                 II_FLAGS_LANDMARK_VISITED = 1,
00146 
00147                 
00148                 
00149                 
00150                 
00151                 II_FLAGS_OBJECT_SLAM_PERM = 0x100,
00152 
00153                 
00154                 
00155                 
00156                 
00157                 
00158                 
00159                 II_FLAGS_OBJECT_PERM_OVERWRITE_BASE                     = 0x010000,
00160                 II_FLAGS_OBJECT_PERM_OVERWRITE_OWNER            = 0x020000,
00161                 II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP            = 0x040000,
00162                 II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE         = 0x080000,
00163                 II_FLAGS_OBJECT_PERM_OVERWRITE_NEXT_OWNER       = 0x100000,
00164 
00165                 
00166                 
00167                 II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS                      = 0x200000,
00168 
00169                 
00170                 
00171         };
00172 
00173 protected:
00174         ~LLInventoryItem(); 
00175 
00176 public:
00177         MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
00178         LLInventoryItem(const LLUUID& uuid,
00179                                         const LLUUID& parent_uuid,
00180                                         const LLPermissions& permissions,
00181                                         const LLUUID& asset_uuid,
00182                                         LLAssetType::EType type,
00183                                         LLInventoryType::EType inv_type,
00184                                         const LLString& name, 
00185                                         const LLString& desc,
00186                                         const LLSaleInfo& sale_info,
00187                                         U32 flags,
00188                                         S32 creation_date_utc);
00189         LLInventoryItem();
00190         
00191         
00192         
00193         LLInventoryItem(const LLInventoryItem* other);
00194         virtual void copy(const LLInventoryItem* other); 
00195 
00196         
00197         
00198         
00199         virtual void clone(LLPointer<LLInventoryItem>& newitem) const;
00200         
00201         
00202         const LLPermissions& getPermissions() const;
00203         const LLUUID& getCreatorUUID() const;
00204         const LLUUID& getAssetUUID() const;
00205         const LLString& getDescription() const;
00206         const LLSaleInfo& getSaleInfo() const;
00207         LLInventoryType::EType getInventoryType() const;
00208         U32 getFlags() const;
00209         S32 getCreationDate() const;
00210         U32 getCRC32() const; 
00211         
00212         
00213         
00214         void setAssetUUID(const LLUUID& asset_id);
00215         void setDescription(const LLString& new_desc);
00216         void setSaleInfo(const LLSaleInfo& sale_info);
00217         void setPermissions(const LLPermissions& perm);
00218         void setInventoryType(LLInventoryType::EType inv_type);
00219         void setFlags(U32 flags);
00220         void setCreationDate(S32 creation_date_utc);
00221 
00222         
00223         
00224         virtual void packMessage(LLMessageSystem* msg) const;
00225 
00226         
00227         
00228         
00229         virtual BOOL unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
00230 
00231         
00232         virtual BOOL importFile(FILE* fp);
00233         virtual BOOL exportFile(FILE* fp, BOOL include_asset_key = TRUE) const;
00234 
00235         virtual BOOL importLegacyStream(std::istream& input_stream);
00236         virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
00237 
00238         virtual LLXMLNode *exportFileXML(BOOL include_asset_key = TRUE) const;
00239         BOOL importXML(LLXMLNode* node);
00240 
00241         
00242 
00243         
00244         
00245         S32 packBinaryBucket(U8* bin_bucket, LLPermissions* perm_override = NULL) const;
00246         void unpackBinaryBucket(U8* bin_bucket, S32 bin_bucket_size);
00247         LLSD asLLSD() const;
00248         bool fromLLSD(LLSD& sd);
00249 
00250 };
00251 
00252 BOOL item_dictionary_sort(LLInventoryItem* a,LLInventoryItem* b);
00253 BOOL item_date_sort(LLInventoryItem* a, LLInventoryItem* b);
00254 
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 
00264 class LLInventoryCategory : public LLInventoryObject
00265 {
00266 public:
00267         typedef LLDynamicArray<LLPointer<LLInventoryCategory> > cat_array_t;
00268 
00269 protected:
00270         ~LLInventoryCategory();
00271         
00272 public:
00273         MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
00274         LLInventoryCategory(const LLUUID& uuid, const LLUUID& parent_uuid,
00275                                                 LLAssetType::EType preferred_type,
00276                                                 const LLString& name);
00277         LLInventoryCategory();
00278         LLInventoryCategory(const LLInventoryCategory* other);
00279         virtual void copy(const LLInventoryCategory* other); 
00280 
00281         
00282         LLAssetType::EType getPreferredType() const;
00283         void setPreferredType(LLAssetType::EType type);
00284         
00285         virtual void packMessage(LLMessageSystem* msg) const;
00286         virtual void unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
00287 
00288         
00289         virtual BOOL importFile(FILE* fp);
00290         virtual BOOL exportFile(FILE* fp, BOOL include_asset_key = TRUE) const;
00291 
00292         virtual BOOL importLegacyStream(std::istream& input_stream);
00293         virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
00294 
00295 protected:
00296         
00297         
00298         LLAssetType::EType      mPreferredType;         
00299 
00300 };
00301 
00302 
00303 
00304 
00305 
00306 
00307 
00308 
00309 
00310 
00311 struct IsItemTransferable : public std::unary_function<LLInventoryItem*, bool>
00312 {
00313         LLUUID mDestID;
00314         IsItemTransferable(const LLUUID& dest_id) : mDestID(dest_id) {}
00315         bool operator()(const LLInventoryItem* item) const
00316         {
00317                 return (item->getPermissions().allowTransferTo(mDestID)) ? true:false;
00318         }
00319 };
00320 
00321 
00322 
00323 
00324 struct SetItemOwnerAndGroup
00325 {
00326         LLUUID mAuthorityID;
00327         LLUUID mOwnerID;
00328         LLUUID mGroupID;
00329         SetItemOwnerAndGroup(const LLUUID& authority_id,
00330                                                  const LLUUID& owner_id,
00331                                                  const LLUUID& group_id) :
00332                 mAuthorityID(authority_id), mOwnerID(owner_id), mGroupID(group_id) {}
00333         void operator()(LLInventoryItem* item) const
00334         {
00335                 LLPermissions perm = item->getPermissions();
00336                 bool is_atomic = (LLAssetType::AT_OBJECT == item->getType()) ? false : true;
00337                 perm.setOwnerAndGroup(mAuthorityID, mOwnerID, mGroupID, is_atomic);
00338                 
00339                 
00340                 if (mOwnerID.isNull())
00341                 {
00342                         perm.setMaskGroup(PERM_NONE);
00343                 }
00344                 item->setPermissions(perm);
00345         }
00346 };
00347 
00348 
00349 
00350 struct SetNotForSale
00351 {
00352         LLUUID mAgentID;
00353         LLUUID mGroupID;
00354         SetNotForSale(const LLUUID& agent_id,
00355                                   const LLUUID& group_id) :
00356                         mAgentID(agent_id), mGroupID(group_id) {}
00357         void operator()(LLInventoryItem* item) const
00358         {
00359                 
00360                 LLPermissions perm = item->getPermissions();
00361                 perm.setGroupBits(mAgentID, mGroupID, FALSE, PERM_MODIFY | PERM_MOVE | PERM_COPY);
00362                 perm.setEveryoneBits(mAgentID, mGroupID, FALSE, PERM_MOVE | PERM_COPY);
00363                 item->setPermissions(perm);
00364 
00365                 
00366                 
00367                 if(LLAssetType::AT_OBJECT == item->getType())
00368                 {
00369                         U32 flags = item->getFlags();
00370                         flags |= LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP;
00371                         flags |= LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE;
00372                         item->setFlags(flags);
00373                 }
00374 
00375                 
00376                 item->setSaleInfo(LLSaleInfo::DEFAULT);
00377         }
00378 };
00379 
00380 typedef std::list<LLPointer<LLInventoryObject> > InventoryObjectList;
00381 
00382 
00383 
00384 LLSD ll_create_sd_from_inventory_item(LLPointer<LLInventoryItem> item);
00385 LLPointer<LLInventoryItem> ll_create_item_from_sd(const LLSD& sd_item);
00386 LLSD ll_create_sd_from_inventory_category(LLPointer<LLInventoryCategory> cat);
00387 LLPointer<LLInventoryCategory> ll_create_category_from_sd(const LLSD& sd_cat);
00388 
00389 #endif // LL_LLINVENTORY_H