diff options
Diffstat (limited to 'indra/llinventory/llinventory.cpp')
-rw-r--r-- | indra/llinventory/llinventory.cpp | 616 |
1 files changed, 364 insertions, 252 deletions
diff --git a/indra/llinventory/llinventory.cpp b/indra/llinventory/llinventory.cpp index 81261f0767..6334a35fd0 100644 --- a/indra/llinventory/llinventory.cpp +++ b/indra/llinventory/llinventory.cpp @@ -32,6 +32,7 @@ #include "llinventorydefines.h" #include "llxorcipher.h" #include "llsd.h" +#include "llsdserialize.h" #include "message.h" #include <boost/tokenizer.hpp> @@ -40,9 +41,12 @@ ///---------------------------------------------------------------------------- /// Exported functions ///---------------------------------------------------------------------------- +// FIXME D567 - what's the point of these, especially if we don't even use them consistently? static const std::string INV_ITEM_ID_LABEL("item_id"); static const std::string INV_FOLDER_ID_LABEL("cat_id"); static const std::string INV_PARENT_ID_LABEL("parent_id"); +static const std::string INV_THUMBNAIL_LABEL("thumbnail"); +static const std::string INV_THUMBNAIL_ID_LABEL("thumbnail_id"); static const std::string INV_ASSET_TYPE_LABEL("type"); static const std::string INV_PREFERRED_TYPE_LABEL("preferred_type"); static const std::string INV_INVENTORY_TYPE_LABEL("inv_type"); @@ -99,6 +103,7 @@ void LLInventoryObject::copyObject(const LLInventoryObject* other) mParentUUID = other->mParentUUID; mType = other->mType; mName = other->mName; + mThumbnailUUID = other->mThumbnailUUID; } const LLUUID& LLInventoryObject::getUUID() const @@ -111,6 +116,11 @@ const LLUUID& LLInventoryObject::getParentUUID() const return mParentUUID; } +const LLUUID& LLInventoryObject::getThumbnailUUID() const +{ + return mThumbnailUUID; +} + const std::string& LLInventoryObject::getName() const { return mName; @@ -160,6 +170,11 @@ void LLInventoryObject::setParent(const LLUUID& new_parent) mParentUUID = new_parent; } +void LLInventoryObject::setThumbnailUUID(const LLUUID& thumbnail_uuid) +{ + mThumbnailUUID = thumbnail_uuid; +} + void LLInventoryObject::setType(LLAssetType::EType type) { mType = type; @@ -201,6 +216,38 @@ BOOL LLInventoryObject::importLegacyStream(std::istream& input_stream) { mType = LLAssetType::lookup(valuestr); } + else if (0 == strcmp("metadata", keyword)) + { + LLSD metadata; + if (strncmp("<llsd>", valuestr, 6) == 0) + { + std::istringstream stream(valuestr); + LLSDSerialize::fromXML(metadata, stream); + } + else + { + // next line likely contains metadata, but at the moment is not supported + // can do something like: + // LLSDSerialize::fromNotation(metadata, input_stream, -1); + } + + if (metadata.has("thumbnail")) + { + const LLSD& thumbnail = metadata["thumbnail"]; + if (thumbnail.has("asset_id")) + { + setThumbnailUUID(thumbnail["asset_id"].asUUID()); + } + else + { + setThumbnailUUID(LLUUID::null); + } + } + else + { + setThumbnailUUID(LLUUID::null); + } + } else if(0 == strcmp("name", keyword)) { //strcpy(valuestr, buffer + strlen(keyword) + 3); @@ -336,6 +383,7 @@ void LLInventoryItem::copyItem(const LLInventoryItem* other) copyObject(other); mPermissions = other->mPermissions; mAssetUUID = other->mAssetUUID; + mThumbnailUUID = other->mThumbnailUUID; mDescription = other->mDescription; mSaleInfo = other->mSaleInfo; mInventoryType = other->mInventoryType; @@ -400,6 +448,7 @@ U32 LLInventoryItem::getCRC32() const //LL_DEBUGS() << "8 crc: " << std::hex << crc << std::dec << LL_ENDL; crc += (U32)mCreationDate; //LL_DEBUGS() << "9 crc: " << std::hex << crc << std::dec << LL_ENDL; + crc += mThumbnailUUID.getCRC32(); return crc; } @@ -655,6 +704,38 @@ BOOL LLInventoryItem::importLegacyStream(std::istream& input_stream) { mType = LLAssetType::lookup(valuestr); } + else if (0 == strcmp("metadata", keyword)) + { + LLSD metadata; + if (strncmp("<llsd>", valuestr, 6) == 0) + { + std::istringstream stream(valuestr); + LLSDSerialize::fromXML(metadata, stream); + } + else + { + // next line likely contains metadata, but at the moment is not supported + // can do something like: + // LLSDSerialize::fromNotation(metadata, input_stream, -1); + } + + if (metadata.has("thumbnail")) + { + const LLSD& thumbnail = metadata["thumbnail"]; + if (thumbnail.has("asset_id")) + { + setThumbnailUUID(thumbnail["asset_id"].asUUID()); + } + else + { + setThumbnailUUID(LLUUID::null); + } + } + else + { + setThumbnailUUID(LLUUID::null); + } + } else if(0 == strcmp("inv_type", keyword)) { mInventoryType = LLInventoryType::lookup(std::string(valuestr)); @@ -744,6 +825,18 @@ BOOL LLInventoryItem::exportLegacyStream(std::ostream& output_stream, BOOL inclu output_stream << "\t\tparent_id\t" << uuid_str << "\n"; mPermissions.exportLegacyStream(output_stream); + if (mThumbnailUUID.notNull()) + { + // Max length is 255 chars, will have to export differently if it gets more data + // Ex: use newline and toNotation (uses {}) for unlimited size + LLSD metadata; + metadata["thumbnail"] = LLSD().with("asset_id", mThumbnailUUID); + + output_stream << "\t\tmetadata\t"; + LLSDSerialize::toXML(metadata, output_stream); + output_stream << "|\n"; + } + // Check for permissions to see the asset id, and if so write it // out as an asset id. Otherwise, apply our cheesy encryption. if(include_asset_key) @@ -797,6 +890,11 @@ void LLInventoryItem::asLLSD( LLSD& sd ) const sd[INV_PARENT_ID_LABEL] = mParentUUID; sd[INV_PERMISSIONS_LABEL] = ll_create_sd_from_permissions(mPermissions); + if (mThumbnailUUID.notNull()) + { + sd[INV_THUMBNAIL_LABEL] = LLSD().with(INV_ASSET_ID_LABEL, mThumbnailUUID); + } + U32 mask = mPermissions.getMaskBase(); if(((mask & PERM_ITEM_UNRESTRICTED) == PERM_ITEM_UNRESTRICTED) || (mAssetUUID.isNull())) @@ -836,123 +934,173 @@ bool LLInventoryItem::fromLLSD(const LLSD& sd, bool is_new) mInventoryType = LLInventoryType::IT_NONE; mAssetUUID.setNull(); } - std::string w; - w = INV_ITEM_ID_LABEL; - if (sd.has(w)) - { - mUUID = sd[w]; - } - w = INV_PARENT_ID_LABEL; - if (sd.has(w)) - { - mParentUUID = sd[w]; - } - w = INV_PERMISSIONS_LABEL; - if (sd.has(w)) - { - mPermissions = ll_permissions_from_sd(sd[w]); - } - w = INV_SALE_INFO_LABEL; - if (sd.has(w)) - { - // Sale info used to contain next owner perm. It is now in - // the permissions. Thus, we read that out, and fix legacy - // objects. It's possible this op would fail, but it - // should pick up the vast majority of the tasks. - BOOL has_perm_mask = FALSE; - U32 perm_mask = 0; - if (!mSaleInfo.fromLLSD(sd[w], has_perm_mask, perm_mask)) - { - goto fail; - } - if (has_perm_mask) - { - if(perm_mask == PERM_NONE) - { - perm_mask = mPermissions.getMaskOwner(); - } - // fair use fix. - if(!(perm_mask & PERM_COPY)) - { - perm_mask |= PERM_TRANSFER; - } - mPermissions.setMaskNext(perm_mask); - } - } - w = INV_SHADOW_ID_LABEL; - if (sd.has(w)) - { - mAssetUUID = sd[w]; - LLXORCipher cipher(MAGIC_ID.mData, UUID_BYTES); - cipher.decrypt(mAssetUUID.mData, UUID_BYTES); - } - w = INV_ASSET_ID_LABEL; - if (sd.has(w)) - { - mAssetUUID = sd[w]; - } - w = INV_LINKED_ID_LABEL; - if (sd.has(w)) - { - mAssetUUID = sd[w]; - } - w = INV_ASSET_TYPE_LABEL; - if (sd.has(w)) - { - if (sd[w].isString()) - { - mType = LLAssetType::lookup(sd[w].asString().c_str()); - } - else if (sd[w].isInteger()) - { - S8 type = (U8)sd[w].asInteger(); - mType = static_cast<LLAssetType::EType>(type); - } - } - w = INV_INVENTORY_TYPE_LABEL; - if (sd.has(w)) - { - if (sd[w].isString()) - { - mInventoryType = LLInventoryType::lookup(sd[w].asString().c_str()); - } - else if (sd[w].isInteger()) - { - S8 type = (U8)sd[w].asInteger(); - mInventoryType = static_cast<LLInventoryType::EType>(type); - } - } - w = INV_FLAGS_LABEL; - if (sd.has(w)) - { - if (sd[w].isBinary()) - { - mFlags = ll_U32_from_sd(sd[w]); - } - else if(sd[w].isInteger()) - { - mFlags = sd[w].asInteger(); - } - } - w = INV_NAME_LABEL; - if (sd.has(w)) - { - mName = sd[w].asString(); - LLStringUtil::replaceNonstandardASCII(mName, ' '); - LLStringUtil::replaceChar(mName, '|', ' '); - } - w = INV_DESC_LABEL; - if (sd.has(w)) - { - mDescription = sd[w].asString(); - LLStringUtil::replaceNonstandardASCII(mDescription, ' '); - } - w = INV_CREATION_DATE_LABEL; - if (sd.has(w)) - { - mCreationDate = sd[w].asInteger(); - } + // TODO - figure out if this should be moved into the noclobber fields above + mThumbnailUUID.setNull(); + + // iterate as map to avoid making unnecessary temp copies of everything + LLSD::map_const_iterator i, end; + end = sd.endMap(); + for (i = sd.beginMap(); i != end; ++i) + { + if (i->first == INV_ITEM_ID_LABEL) + { + mUUID = i->second; + continue; + } + + if (i->first == INV_PARENT_ID_LABEL) + { + mParentUUID = i->second; + continue; + } + + if (i->first == INV_THUMBNAIL_LABEL) + { + const LLSD &thumbnail_map = i->second; + const std::string w = INV_ASSET_ID_LABEL; + if (thumbnail_map.has(w)) + { + mThumbnailUUID = thumbnail_map[w]; + } + /* Example: + <key> asset_id </key> + <uuid> acc0ec86 - 17f2 - 4b92 - ab41 - 6718b1f755f7 </uuid> + <key> perms </key> + <integer> 8 </integer> + <key>service</key> + <integer> 3 </integer> + <key>version</key> + <integer> 1 </key> + */ + continue; + } + + if (i->first == INV_THUMBNAIL_ID_LABEL) + { + mThumbnailUUID = i->second.asUUID(); + continue; + } + + if (i->first == INV_PERMISSIONS_LABEL) + { + mPermissions = ll_permissions_from_sd(i->second); + continue; + } + + if (i->first == INV_SALE_INFO_LABEL) + { + // Sale info used to contain next owner perm. It is now in + // the permissions. Thus, we read that out, and fix legacy + // objects. It's possible this op would fail, but it + // should pick up the vast majority of the tasks. + BOOL has_perm_mask = FALSE; + U32 perm_mask = 0; + if (!mSaleInfo.fromLLSD(i->second, has_perm_mask, perm_mask)) + { + return false; + } + if (has_perm_mask) + { + if (perm_mask == PERM_NONE) + { + perm_mask = mPermissions.getMaskOwner(); + } + // fair use fix. + if (!(perm_mask & PERM_COPY)) + { + perm_mask |= PERM_TRANSFER; + } + mPermissions.setMaskNext(perm_mask); + } + continue; + } + + if (i->first == INV_SHADOW_ID_LABEL) + { + mAssetUUID = i->second; + LLXORCipher cipher(MAGIC_ID.mData, UUID_BYTES); + cipher.decrypt(mAssetUUID.mData, UUID_BYTES); + continue; + } + + if (i->first == INV_ASSET_ID_LABEL) + { + mAssetUUID = i->second; + continue; + } + + if (i->first == INV_LINKED_ID_LABEL) + { + mAssetUUID = i->second; + continue; + } + + if (i->first == INV_ASSET_TYPE_LABEL) + { + LLSD const &label = i->second; + if (label.isString()) + { + mType = LLAssetType::lookup(label.asString().c_str()); + } + else if (label.isInteger()) + { + S8 type = (U8) label.asInteger(); + mType = static_cast<LLAssetType::EType>(type); + } + continue; + } + + if (i->first == INV_INVENTORY_TYPE_LABEL) + { + LLSD const &label = i->second; + if (label.isString()) + { + mInventoryType = LLInventoryType::lookup(label.asString().c_str()); + } + else if (label.isInteger()) + { + S8 type = (U8) label.asInteger(); + mInventoryType = static_cast<LLInventoryType::EType>(type); + } + continue; + } + + if (i->first == INV_FLAGS_LABEL) + { + LLSD const &label = i->second; + if (label.isBinary()) + { + mFlags = ll_U32_from_sd(label); + } + else if (label.isInteger()) + { + mFlags = label.asInteger(); + } + continue; + } + + if (i->first == INV_NAME_LABEL) + { + mName = i->second.asString(); + LLStringUtil::replaceNonstandardASCII(mName, ' '); + LLStringUtil::replaceChar(mName, '|', ' '); + continue; + } + + if (i->first == INV_DESC_LABEL) + { + mDescription = i->second.asString(); + LLStringUtil::replaceNonstandardASCII(mDescription, ' '); + continue; + } + + if (i->first == INV_CREATION_DATE_LABEL) + { + mCreationDate = i->second.asInteger(); + continue; + } + } // Need to convert 1.0 simstate files to a useful inventory type // and potentially deal with bad inventory tyes eg, a landmark @@ -967,138 +1115,6 @@ bool LLInventoryItem::fromLLSD(const LLSD& sd, bool is_new) mPermissions.initMasks(mInventoryType); return true; -fail: - return false; - -} - -// Deleted LLInventoryItem::exportFileXML() and LLInventoryItem::importXML() -// because I can't find any non-test code references to it. 2009-05-04 JC - -S32 LLInventoryItem::packBinaryBucket(U8* bin_bucket, LLPermissions* perm_override) const -{ - // Figure out which permissions to use. - LLPermissions perm; - if (perm_override) - { - // Use the permissions override. - perm = *perm_override; - } - else - { - // Use the current permissions. - perm = getPermissions(); - } - - // describe the inventory item - char* buffer = (char*) bin_bucket; - std::string creator_id_str; - - perm.getCreator().toString(creator_id_str); - std::string owner_id_str; - perm.getOwner().toString(owner_id_str); - std::string last_owner_id_str; - perm.getLastOwner().toString(last_owner_id_str); - std::string group_id_str; - perm.getGroup().toString(group_id_str); - std::string asset_id_str; - getAssetUUID().toString(asset_id_str); - S32 size = sprintf(buffer, /* Flawfinder: ignore */ - "%d|%d|%s|%s|%s|%s|%s|%x|%x|%x|%x|%x|%s|%s|%d|%d|%x", - getType(), - getInventoryType(), - getName().c_str(), - creator_id_str.c_str(), - owner_id_str.c_str(), - last_owner_id_str.c_str(), - group_id_str.c_str(), - perm.getMaskBase(), - perm.getMaskOwner(), - perm.getMaskGroup(), - perm.getMaskEveryone(), - perm.getMaskNextOwner(), - asset_id_str.c_str(), - getDescription().c_str(), - getSaleInfo().getSaleType(), - getSaleInfo().getSalePrice(), - getFlags()) + 1; - - return size; -} - -void LLInventoryItem::unpackBinaryBucket(U8* bin_bucket, S32 bin_bucket_size) -{ - // Early exit on an empty binary bucket. - if (bin_bucket_size <= 1) return; - - if (NULL == bin_bucket) - { - LL_ERRS() << "unpackBinaryBucket failed. bin_bucket is NULL." << LL_ENDL; - return; - } - - // Convert the bin_bucket into a string. - std::vector<char> item_buffer(bin_bucket_size+1); - memcpy(&item_buffer[0], bin_bucket, bin_bucket_size); /* Flawfinder: ignore */ - item_buffer[bin_bucket_size] = '\0'; - std::string str(&item_buffer[0]); - - LL_DEBUGS() << "item buffer: " << str << LL_ENDL; - - // Tokenize the string. - typedef boost::tokenizer<boost::char_separator<char> > tokenizer; - boost::char_separator<char> sep("|", "", boost::keep_empty_tokens); - tokenizer tokens(str, sep); - tokenizer::iterator iter = tokens.begin(); - - // Extract all values. - LLUUID item_id; - item_id.generate(); - setUUID(item_id); - - LLAssetType::EType type; - type = (LLAssetType::EType)(atoi((*(iter++)).c_str())); - setType( type ); - - LLInventoryType::EType inv_type; - inv_type = (LLInventoryType::EType)(atoi((*(iter++)).c_str())); - setInventoryType( inv_type ); - - std::string name((*(iter++)).c_str()); - rename( name ); - - LLUUID creator_id((*(iter++)).c_str()); - LLUUID owner_id((*(iter++)).c_str()); - LLUUID last_owner_id((*(iter++)).c_str()); - LLUUID group_id((*(iter++)).c_str()); - PermissionMask mask_base = strtoul((*(iter++)).c_str(), NULL, 16); - PermissionMask mask_owner = strtoul((*(iter++)).c_str(), NULL, 16); - PermissionMask mask_group = strtoul((*(iter++)).c_str(), NULL, 16); - PermissionMask mask_every = strtoul((*(iter++)).c_str(), NULL, 16); - PermissionMask mask_next = strtoul((*(iter++)).c_str(), NULL, 16); - LLPermissions perm; - perm.init(creator_id, owner_id, last_owner_id, group_id); - perm.initMasks(mask_base, mask_owner, mask_group, mask_every, mask_next); - setPermissions(perm); - //LL_DEBUGS() << "perm: " << perm << LL_ENDL; - - LLUUID asset_id((*(iter++)).c_str()); - setAssetUUID(asset_id); - - std::string desc((*(iter++)).c_str()); - setDescription(desc); - - LLSaleInfo::EForSale sale_type; - sale_type = (LLSaleInfo::EForSale)(atoi((*(iter++)).c_str())); - S32 price = atoi((*(iter++)).c_str()); - LLSaleInfo sale_info(sale_type, price); - setSaleInfo(sale_info); - - U32 flags = strtoul((*(iter++)).c_str(), NULL, 16); - setFlags(flags); - - time_t now = time(NULL); - setCreationDate(now); } ///---------------------------------------------------------------------------- @@ -1150,11 +1166,32 @@ void LLInventoryCategory::setPreferredType(LLFolderType::EType type) LLSD LLInventoryCategory::asLLSD() const { LLSD sd = LLSD(); - sd["item_id"] = mUUID; - sd["parent_id"] = mParentUUID; + sd[INV_ITEM_ID_LABEL] = mUUID; + sd[INV_PARENT_ID_LABEL] = mParentUUID; S8 type = static_cast<S8>(mPreferredType); - sd["type"] = type; - sd["name"] = mName; + sd[INV_ASSET_TYPE_LABEL] = type; + sd[INV_NAME_LABEL] = mName; + + if (mThumbnailUUID.notNull()) + { + sd[INV_THUMBNAIL_LABEL] = LLSD().with(INV_ASSET_ID_LABEL, mThumbnailUUID); + } + + return sd; +} + +LLSD LLInventoryCategory::asAISCreateCatLLSD() const +{ + LLSD sd = LLSD(); + sd[INV_FOLDER_ID_LABEL_WS] = mUUID; + sd[INV_PARENT_ID_LABEL] = mParentUUID; + S8 type = static_cast<S8>(mPreferredType); + sd[INV_ASSET_TYPE_LABEL_WS] = type; + sd[INV_NAME_LABEL] = mName; + if (mThumbnailUUID.notNull()) + { + sd[INV_THUMBNAIL_LABEL] = LLSD().with(INV_ASSET_ID_LABEL, mThumbnailUUID); + } return sd; } @@ -1184,6 +1221,25 @@ bool LLInventoryCategory::fromLLSD(const LLSD& sd) { mParentUUID = sd[w]; } + mThumbnailUUID.setNull(); + w = INV_THUMBNAIL_LABEL; + if (sd.has(w)) + { + const LLSD &thumbnail_map = sd[w]; + w = INV_ASSET_ID_LABEL; + if (thumbnail_map.has(w)) + { + mThumbnailUUID = thumbnail_map[w]; + } + } + else + { + w = INV_THUMBNAIL_ID_LABEL; + if (sd.has(w)) + { + mThumbnailUUID = sd[w]; + } + } w = INV_ASSET_TYPE_LABEL; if (sd.has(w)) { @@ -1275,6 +1331,38 @@ BOOL LLInventoryCategory::importLegacyStream(std::istream& input_stream) LLStringUtil::replaceNonstandardASCII(mName, ' '); LLStringUtil::replaceChar(mName, '|', ' '); } + else if (0 == strcmp("metadata", keyword)) + { + LLSD metadata; + if (strncmp("<llsd>", valuestr, 6) == 0) + { + std::istringstream stream(valuestr); + LLSDSerialize::fromXML(metadata, stream); + } + else + { + // next line likely contains metadata, but at the moment is not supported + // can do something like: + // LLSDSerialize::fromNotation(metadata, input_stream, -1); + } + + if (metadata.has("thumbnail")) + { + const LLSD& thumbnail = metadata["thumbnail"]; + if (thumbnail.has("asset_id")) + { + setThumbnailUUID(thumbnail["asset_id"].asUUID()); + } + else + { + setThumbnailUUID(LLUUID::null); + } + } + else + { + setThumbnailUUID(LLUUID::null); + } + } else { LL_WARNS() << "unknown keyword '" << keyword @@ -1295,6 +1383,15 @@ BOOL LLInventoryCategory::exportLegacyStream(std::ostream& output_stream, BOOL) output_stream << "\t\ttype\t" << LLAssetType::lookup(mType) << "\n"; output_stream << "\t\tpref_type\t" << LLFolderType::lookup(mPreferredType) << "\n"; output_stream << "\t\tname\t" << mName.c_str() << "|\n"; + if (mThumbnailUUID.notNull()) + { + // Only up to 255 chars + LLSD metadata; + metadata["thumbnail"] = LLSD().with("asset_id", mThumbnailUUID); + output_stream << "\t\tmetadata\t"; + LLSDSerialize::toXML(metadata, output_stream); + output_stream << "|\n"; + } output_stream << "\t}\n"; return TRUE; } @@ -1308,6 +1405,11 @@ LLSD LLInventoryCategory::exportLLSD() const cat_data[INV_PREFERRED_TYPE_LABEL] = LLFolderType::lookup(mPreferredType); cat_data[INV_NAME_LABEL] = mName; + if (mThumbnailUUID.notNull()) + { + cat_data[INV_THUMBNAIL_LABEL] = LLSD().with(INV_ASSET_ID_LABEL, mThumbnailUUID); + } + return cat_data; } @@ -1329,6 +1431,16 @@ bool LLInventoryCategory::importLLSD(const LLSD& cat_data) { setPreferredType(LLFolderType::lookup(cat_data[INV_PREFERRED_TYPE_LABEL].asString())); } + if (cat_data.has(INV_THUMBNAIL_LABEL)) + { + LLUUID thumbnail_uuid; + const LLSD &thumbnail_data = cat_data[INV_THUMBNAIL_LABEL]; + if (thumbnail_data.has(INV_ASSET_ID_LABEL)) + { + thumbnail_uuid = thumbnail_data[INV_ASSET_ID_LABEL].asUUID(); + } + setThumbnailUUID(thumbnail_uuid); + } if (cat_data.has(INV_NAME_LABEL)) { mName = cat_data[INV_NAME_LABEL].asString(); |