summaryrefslogtreecommitdiff
path: root/indra/llinventory/llinventory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llinventory/llinventory.cpp')
-rw-r--r--indra/llinventory/llinventory.cpp272
1 files changed, 150 insertions, 122 deletions
diff --git a/indra/llinventory/llinventory.cpp b/indra/llinventory/llinventory.cpp
index adc80b2ed3..bda76eac80 100644
--- a/indra/llinventory/llinventory.cpp
+++ b/indra/llinventory/llinventory.cpp
@@ -2,39 +2,33 @@
* @file llinventory.cpp
* @brief Implementation of the inventory system.
*
- * $LicenseInfo:firstyear=2001&license=viewergpl$
- *
- * Copyright (c) 2001-2009, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
*
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
-
#include "llinventory.h"
#include "lldbstrings.h"
+#include "llinventorydefines.h"
#include "llxorcipher.h"
#include "llsd.h"
#include "message.h"
@@ -43,9 +37,8 @@
#include "llsdutil.h"
///----------------------------------------------------------------------------
-/// exported functions
+/// Exported functions
///----------------------------------------------------------------------------
-
static const std::string INV_ITEM_ID_LABEL("item_id");
static const std::string INV_FOLDER_ID_LABEL("folder_id");
static const std::string INV_PARENT_ID_LABEL("parent_id");
@@ -64,34 +57,29 @@ static const std::string INV_CREATION_DATE_LABEL("created_at");
// key used by agent-inventory-service
static const std::string INV_ASSET_TYPE_LABEL_WS("type_default");
static const std::string INV_FOLDER_ID_LABEL_WS("category_id");
+
///----------------------------------------------------------------------------
/// Local function declarations, constants, enums, and typedefs
///----------------------------------------------------------------------------
-
const U8 TASK_INVENTORY_ITEM_KEY = 0;
const U8 TASK_INVENTORY_ASSET_KEY = 1;
const LLUUID MAGIC_ID("3c115e51-04f4-523c-9fa6-98aff1034730");
-
///----------------------------------------------------------------------------
/// Class LLInventoryObject
///----------------------------------------------------------------------------
-LLInventoryObject::LLInventoryObject(
- const LLUUID& uuid,
- const LLUUID& parent_uuid,
- LLAssetType::EType type,
- const std::string& name) :
+LLInventoryObject::LLInventoryObject(const LLUUID& uuid,
+ const LLUUID& parent_uuid,
+ LLAssetType::EType type,
+ const std::string& name) :
mUUID(uuid),
mParentUUID(parent_uuid),
mType(type),
mName(name)
{
- LLStringUtil::replaceNonstandardASCII(mName, ' ');
- LLStringUtil::replaceChar(mName, '|', ' ');
- LLStringUtil::trim(mName);
- LLStringUtil::truncate(mName, DB_INV_ITEM_NAME_STR_LEN);
+ correctInventoryName(mName);
}
LLInventoryObject::LLInventoryObject() :
@@ -99,7 +87,7 @@ LLInventoryObject::LLInventoryObject() :
{
}
-LLInventoryObject::~LLInventoryObject( void )
+LLInventoryObject::~LLInventoryObject()
{
}
@@ -126,6 +114,25 @@ const std::string& LLInventoryObject::getName() const
return mName;
}
+// To bypass linked items, since llviewerinventory's getType
+// will return the linked-to item's type instead of this object's type.
+LLAssetType::EType LLInventoryObject::getActualType() const
+{
+ return mType;
+}
+
+BOOL LLInventoryObject::getIsLinkType() const
+{
+ return LLAssetType::lookupIsLinkType(mType);
+}
+
+// See LLInventoryItem override.
+// virtual
+const LLUUID& LLInventoryObject::getLinkedUUID() const
+{
+ return mUUID;
+}
+
LLAssetType::EType LLInventoryObject::getType() const
{
return mType;
@@ -139,12 +146,8 @@ void LLInventoryObject::setUUID(const LLUUID& new_uuid)
void LLInventoryObject::rename(const std::string& n)
{
std::string new_name(n);
- LLStringUtil::replaceNonstandardASCII(new_name, ' ');
- LLStringUtil::replaceChar(new_name, '|', ' ');
- LLStringUtil::trim(new_name);
- LLStringUtil::truncate(new_name, DB_INV_ITEM_NAME_STR_LEN);
-
- if( new_name != mName )
+ correctInventoryName(new_name);
+ if( !new_name.empty() && new_name != mName )
{
mName = new_name;
}
@@ -205,10 +208,7 @@ BOOL LLInventoryObject::importLegacyStream(std::istream& input_stream)
" %254s %254[^|]",
keyword, valuestr);
mName.assign(valuestr);
- LLStringUtil::replaceNonstandardASCII(mName, ' ');
- LLStringUtil::replaceChar(mName, '|', ' ');
- LLStringUtil::trim(mName);
- LLStringUtil::truncate(mName, DB_INV_ITEM_NAME_STR_LEN);
+ correctInventoryName(mName);
}
else
{
@@ -268,23 +268,31 @@ void LLInventoryObject::updateServer(BOOL) const
llwarns << "LLInventoryObject::updateServer() called. Doesn't do anything." << llendl;
}
+inline
+void LLInventoryObject::correctInventoryName(std::string& name)
+{
+ LLStringUtil::replaceNonstandardASCII(name, ' ');
+ LLStringUtil::replaceChar(name, '|', ' ');
+ LLStringUtil::trim(name);
+ LLStringUtil::truncate(name, DB_INV_ITEM_NAME_STR_LEN);
+}
+
///----------------------------------------------------------------------------
/// Class LLInventoryItem
///----------------------------------------------------------------------------
-LLInventoryItem::LLInventoryItem(
- const LLUUID& uuid,
- const LLUUID& parent_uuid,
- const LLPermissions& permissions,
- const LLUUID& asset_uuid,
- LLAssetType::EType type,
- LLInventoryType::EType inv_type,
- const std::string& name,
- const std::string& desc,
- const LLSaleInfo& sale_info,
- U32 flags,
- S32 creation_date_utc) :
+LLInventoryItem::LLInventoryItem(const LLUUID& uuid,
+ const LLUUID& parent_uuid,
+ const LLPermissions& permissions,
+ const LLUUID& asset_uuid,
+ LLAssetType::EType type,
+ LLInventoryType::EType inv_type,
+ const std::string& name,
+ const std::string& desc,
+ const LLSaleInfo& sale_info,
+ U32 flags,
+ S32 creation_date_utc) :
LLInventoryObject(uuid, parent_uuid, type, name),
mPermissions(permissions),
mAssetUUID(asset_uuid),
@@ -296,6 +304,7 @@ LLInventoryItem::LLInventoryItem(
{
LLStringUtil::replaceNonstandardASCII(mDescription, ' ');
LLStringUtil::replaceChar(mDescription, '|', ' ');
+ mPermissions.initMasks(inv_type);
}
LLInventoryItem::LLInventoryItem() :
@@ -333,6 +342,19 @@ void LLInventoryItem::copyItem(const LLInventoryItem* other)
mCreationDate = other->mCreationDate;
}
+// If this is a linked item, then the UUID of the base object is
+// this item's assetID.
+// virtual
+const LLUUID& LLInventoryItem::getLinkedUUID() const
+{
+ if (LLAssetType::lookupIsLinkType(getActualType()))
+ {
+ return mAssetUUID;
+ }
+
+ return LLInventoryObject::getLinkedUUID();
+}
+
const LLPermissions& LLInventoryItem::getPermissions() const
{
return mPermissions;
@@ -405,6 +427,9 @@ void LLInventoryItem::setDescription(const std::string& d)
void LLInventoryItem::setPermissions(const LLPermissions& perm)
{
mPermissions = perm;
+
+ // Override permissions to unrestricted if this is a landmark
+ mPermissions.initMasks(mInventoryType);
}
void LLInventoryItem::setInventoryType(LLInventoryType::EType inv_type)
@@ -422,6 +447,46 @@ void LLInventoryItem::setCreationDate(time_t creation_date_utc)
mCreationDate = creation_date_utc;
}
+// Currently only used in the Viewer to handle calling cards
+// where the creator is actually used to store the target.
+void LLInventoryItem::setCreator(const LLUUID& creator)
+{
+ mPermissions.setCreator(creator);
+}
+
+void LLInventoryItem::accumulatePermissionSlamBits(const LLInventoryItem& old_item)
+{
+ // Remove any pre-existing II_FLAGS_PERM_OVERWRITE_MASK flags
+ // because we now detect when they should be set.
+ setFlags( old_item.getFlags() | (getFlags() & ~(LLInventoryItemFlags::II_FLAGS_PERM_OVERWRITE_MASK)) );
+
+ // Enforce the PERM_OVERWRITE flags for any masks that are different
+ // but only for AT_OBJECT's since that is the only asset type that can
+ // exist in-world (instead of only in-inventory or in-object-contents).
+ if (LLAssetType::AT_OBJECT == getType())
+ {
+ LLPermissions old_permissions = old_item.getPermissions();
+ U32 flags_to_be_set = 0;
+ if(old_permissions.getMaskNextOwner() != getPermissions().getMaskNextOwner())
+ {
+ flags_to_be_set |= LLInventoryItemFlags::II_FLAGS_OBJECT_SLAM_PERM;
+ }
+ if(old_permissions.getMaskEveryone() != getPermissions().getMaskEveryone())
+ {
+ flags_to_be_set |= LLInventoryItemFlags::II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE;
+ }
+ if(old_permissions.getMaskGroup() != getPermissions().getMaskGroup())
+ {
+ flags_to_be_set |= LLInventoryItemFlags::II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP;
+ }
+ LLSaleInfo old_sale_info = old_item.getSaleInfo();
+ if(old_sale_info != getSaleInfo())
+ {
+ flags_to_be_set |= LLInventoryItemFlags::II_FLAGS_OBJECT_SLAM_SALE;
+ }
+ setFlags(getFlags() | flags_to_be_set);
+ }
+}
const LLSaleInfo& LLInventoryItem::getSaleInfo() const
{
@@ -476,6 +541,7 @@ BOOL LLInventoryItem::unpackMessage(LLMessageSystem* msg, const char* block, S32
mType = static_cast<LLAssetType::EType>(type);
msg->getS8(block, "InvType", type, block_num);
mInventoryType = static_cast<LLInventoryType::EType>(type);
+ mPermissions.initMasks(mInventoryType);
msg->getU32Fast(block, _PREHASH_Flags, mFlags, block_num);
@@ -666,6 +732,9 @@ BOOL LLInventoryItem::importFile(LLFILE* fp)
lldebugs << "Resetting inventory type for " << mUUID << llendl;
mInventoryType = LLInventoryType::defaultForAssetType(mType);
}
+
+ mPermissions.initMasks(mInventoryType);
+
return success;
}
@@ -869,6 +938,9 @@ BOOL LLInventoryItem::importLegacyStream(std::istream& input_stream)
lldebugs << "Resetting inventory type for " << mUUID << llendl;
mInventoryType = LLInventoryType::defaultForAssetType(mType);
}
+
+ mPermissions.initMasks(mInventoryType);
+
return success;
}
@@ -1091,6 +1163,8 @@ bool LLInventoryItem::fromLLSD(const LLSD& sd)
mInventoryType = LLInventoryType::defaultForAssetType(mType);
}
+ mPermissions.initMasks(mInventoryType);
+
return true;
fail:
return false;
@@ -1226,35 +1300,21 @@ void LLInventoryItem::unpackBinaryBucket(U8* bin_bucket, S32 bin_bucket_size)
setCreationDate(now);
}
-// returns TRUE if a should appear before b
-BOOL item_dictionary_sort( LLInventoryItem* a, LLInventoryItem* b )
-{
- return (LLStringUtil::compareDict( a->getName().c_str(), b->getName().c_str() ) < 0);
-}
-
-// returns TRUE if a should appear before b
-BOOL item_date_sort( LLInventoryItem* a, LLInventoryItem* b )
-{
- return a->getCreationDate() < b->getCreationDate();
-}
-
-
///----------------------------------------------------------------------------
/// Class LLInventoryCategory
///----------------------------------------------------------------------------
-LLInventoryCategory::LLInventoryCategory(
- const LLUUID& uuid,
- const LLUUID& parent_uuid,
- LLAssetType::EType preferred_type,
- const std::string& name) :
+LLInventoryCategory::LLInventoryCategory(const LLUUID& uuid,
+ const LLUUID& parent_uuid,
+ LLFolderType::EType preferred_type,
+ const std::string& name) :
LLInventoryObject(uuid, parent_uuid, LLAssetType::AT_CATEGORY, name),
mPreferredType(preferred_type)
{
}
LLInventoryCategory::LLInventoryCategory() :
- mPreferredType(LLAssetType::AT_NONE)
+ mPreferredType(LLFolderType::FT_NONE)
{
mType = LLAssetType::AT_CATEGORY;
}
@@ -1276,12 +1336,12 @@ void LLInventoryCategory::copyCategory(const LLInventoryCategory* other)
mPreferredType = other->mPreferredType;
}
-LLAssetType::EType LLInventoryCategory::getPreferredType() const
+LLFolderType::EType LLInventoryCategory::getPreferredType() const
{
return mPreferredType;
}
-void LLInventoryCategory::setPreferredType(LLAssetType::EType type)
+void LLInventoryCategory::setPreferredType(LLFolderType::EType type)
{
mPreferredType = type;
}
@@ -1327,13 +1387,13 @@ bool LLInventoryCategory::fromLLSD(const LLSD& sd)
if (sd.has(w))
{
S8 type = (U8)sd[w].asInteger();
- mPreferredType = static_cast<LLAssetType::EType>(type);
+ mPreferredType = static_cast<LLFolderType::EType>(type);
}
w = INV_ASSET_TYPE_LABEL_WS;
if (sd.has(w))
{
S8 type = (U8)sd[w].asInteger();
- mPreferredType = static_cast<LLAssetType::EType>(type);
+ mPreferredType = static_cast<LLFolderType::EType>(type);
}
w = INV_NAME_LABEL;
@@ -1355,7 +1415,7 @@ void LLInventoryCategory::unpackMessage(LLMessageSystem* msg,
msg->getUUIDFast(block, _PREHASH_ParentID, mParentUUID, block_num);
S8 type;
msg->getS8Fast(block, _PREHASH_Type, type, block_num);
- mPreferredType = static_cast<LLAssetType::EType>(type);
+ mPreferredType = static_cast<LLFolderType::EType>(type);
msg->getStringFast(block, _PREHASH_Name, mName, block_num);
LLStringUtil::replaceNonstandardASCII(mName, ' ');
}
@@ -1404,7 +1464,7 @@ BOOL LLInventoryCategory::importFile(LLFILE* fp)
}
else if(0 == strcmp("pref_type", keyword))
{
- mPreferredType = LLAssetType::lookup(valuestr);
+ mPreferredType = LLFolderType::lookup(valuestr);
}
else if(0 == strcmp("name", keyword))
{
@@ -1436,7 +1496,7 @@ BOOL LLInventoryCategory::exportFile(LLFILE* fp, BOOL) const
mParentUUID.toString(uuid_str);
fprintf(fp, "\t\tparent_id\t%s\n", uuid_str.c_str());
fprintf(fp, "\t\ttype\t%s\n", LLAssetType::lookup(mType));
- fprintf(fp, "\t\tpref_type\t%s\n", LLAssetType::lookup(mPreferredType));
+ fprintf(fp, "\t\tpref_type\t%s\n", LLFolderType::lookup(mPreferredType).c_str());
fprintf(fp, "\t\tname\t%s|\n", mName.c_str());
fprintf(fp,"\t}\n");
return TRUE;
@@ -1483,7 +1543,7 @@ BOOL LLInventoryCategory::importLegacyStream(std::istream& input_stream)
}
else if(0 == strcmp("pref_type", keyword))
{
- mPreferredType = LLAssetType::lookup(valuestr);
+ mPreferredType = LLFolderType::lookup(valuestr);
}
else if(0 == strcmp("name", keyword))
{
@@ -1515,7 +1575,7 @@ BOOL LLInventoryCategory::exportLegacyStream(std::ostream& output_stream, BOOL)
mParentUUID.toString(uuid_str);
output_stream << "\t\tparent_id\t" << uuid_str << "\n";
output_stream << "\t\ttype\t" << LLAssetType::lookup(mType) << "\n";
- output_stream << "\t\tpref_type\t" << LLAssetType::lookup(mPreferredType) << "\n";
+ output_stream << "\t\tpref_type\t" << LLFolderType::lookup(mPreferredType) << "\n";
output_stream << "\t\tname\t" << mName.c_str() << "|\n";
output_stream << "\t}\n";
return TRUE;
@@ -1551,38 +1611,6 @@ LLSD ll_create_sd_from_inventory_item(LLPointer<LLInventoryItem> item)
return rv;
}
-/* deprecated, use LLInventoryItem::fromLLSD() instead
-LLPointer<LLInventoryItem> ll_create_item_from_sd(const LLSD& sd_item)
-{
- LLPointer<LLInventoryItem> rv = new LLInventoryItem;
- rv->setUUID(sd_item[INV_ITEM_ID_LABEL].asUUID());
- rv->setParent(sd_item[INV_PARENT_ID_LABEL].asUUID());
- rv->rename(sd_item[INV_NAME_LABEL].asString());
- rv->setType(
- LLAssetType::lookup(sd_item[INV_ASSET_TYPE_LABEL].asString()));
- if (sd_item.has("shadow_id"))
- {
- LLUUID asset_id = sd_item["shadow_id"];
- LLXORCipher cipher(MAGIC_ID.mData, UUID_BYTES);
- cipher.decrypt(asset_id.mData, UUID_BYTES);
- rv->setAssetUUID(asset_id);
- }
- if (sd_item.has(INV_ASSET_ID_LABEL))
- {
- rv->setAssetUUID(sd_item[INV_ASSET_ID_LABEL].asUUID());
- }
- rv->setDescription(sd_item[INV_DESC_LABEL].asString());
- rv->setSaleInfo(ll_sale_info_from_sd(sd_item[INV_SALE_INFO_LABEL]));
- rv->setPermissions(ll_permissions_from_sd(sd_item[INV_PERMISSIONS_LABEL]));
- rv->setInventoryType(
- LLInventoryType::lookup(
- sd_item[INV_INVENTORY_TYPE_LABEL].asString()));
- rv->setFlags((U32)(sd_item[INV_FLAGS_LABEL].asInteger()));
- rv->setCreationDate(sd_item[INV_CREATION_DATE_LABEL].asInteger());
- return rv;
-}
-*/
-
LLSD ll_create_sd_from_inventory_category(LLPointer<LLInventoryCategory> cat)
{
LLSD rv;
@@ -1597,10 +1625,10 @@ LLSD ll_create_sd_from_inventory_category(LLPointer<LLInventoryCategory> cat)
rv[INV_PARENT_ID_LABEL] = cat->getParentUUID();
rv[INV_NAME_LABEL] = cat->getName();
rv[INV_ASSET_TYPE_LABEL] = LLAssetType::lookup(cat->getType());
- if(LLAssetType::AT_NONE != cat->getPreferredType())
+ if(LLFolderType::lookupIsProtectedType(cat->getPreferredType()))
{
rv[INV_PREFERRED_TYPE_LABEL] =
- LLAssetType::lookup(cat->getPreferredType());
+ LLFolderType::lookup(cat->getPreferredType()).c_str();
}
return rv;
}
@@ -1614,7 +1642,7 @@ LLPointer<LLInventoryCategory> ll_create_category_from_sd(const LLSD& sd_cat)
rv->setType(
LLAssetType::lookup(sd_cat[INV_ASSET_TYPE_LABEL].asString()));
rv->setPreferredType(
- LLAssetType::lookup(
- sd_cat[INV_PREFERRED_TYPE_LABEL].asString()));
+ LLFolderType::lookup(
+ sd_cat[INV_PREFERRED_TYPE_LABEL].asString()));
return rv;
}