Largely rework llfile*
This commit is contained in:
@@ -831,7 +831,7 @@ BOOL LLInventoryItem::importLegacyStream(std::istream& input_stream)
|
||||
}
|
||||
else if(0 == strcmp("permissions", keyword))
|
||||
{
|
||||
success = mPermissions.importStream(input_stream);
|
||||
success = mPermissions.importLegacyStream(input_stream);
|
||||
}
|
||||
else if(0 == strcmp("sale_info", keyword))
|
||||
{
|
||||
@@ -841,7 +841,7 @@ BOOL LLInventoryItem::importLegacyStream(std::istream& input_stream)
|
||||
// should pick up the vast majority of the tasks.
|
||||
BOOL has_perm_mask = FALSE;
|
||||
U32 perm_mask = 0;
|
||||
success = mSaleInfo.importStream(input_stream, has_perm_mask, perm_mask);
|
||||
success = mSaleInfo.importLegacyStream(input_stream, has_perm_mask, perm_mask);
|
||||
if(has_perm_mask)
|
||||
{
|
||||
if(perm_mask == PERM_NONE)
|
||||
@@ -957,7 +957,7 @@ BOOL LLInventoryItem::exportLegacyStream(std::ostream& output_stream, BOOL inclu
|
||||
output_stream << "\t\titem_id\t" << uuid_str << "\n";
|
||||
mParentUUID.toString(uuid_str);
|
||||
output_stream << "\t\tparent_id\t" << uuid_str << "\n";
|
||||
mPermissions.exportStream(output_stream);
|
||||
mPermissions.exportLegacyStream(output_stream);
|
||||
|
||||
// Check for permissions to see the asset id, and if so write it
|
||||
// out as an asset id. Otherwise, apply our cheesy encryption.
|
||||
@@ -991,7 +991,7 @@ BOOL LLInventoryItem::exportLegacyStream(std::ostream& output_stream, BOOL inclu
|
||||
std::string buffer;
|
||||
buffer = llformat( "\t\tflags\t%08x\n", mFlags);
|
||||
output_stream << buffer;
|
||||
mSaleInfo.exportStream(output_stream);
|
||||
mSaleInfo.exportLegacyStream(output_stream);
|
||||
output_stream << "\t\tname\t" << mName.c_str() << "|\n";
|
||||
output_stream << "\t\tdesc\t" << mDescription.c_str() << "|\n";
|
||||
output_stream << "\t\tcreation_date\t" << mCreationDate << "\n";
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
// library includes
|
||||
#include "message.h"
|
||||
#include "metapropertyt.h"
|
||||
#include "llsd.h"
|
||||
|
||||
///----------------------------------------------------------------------------
|
||||
@@ -572,17 +571,143 @@ void LLPermissions::unpackMessage(LLMessageSystem* msg, const char* block, S32 b
|
||||
|
||||
BOOL LLPermissions::importFile(LLFILE* fp)
|
||||
{
|
||||
llifstream ifs(fp);
|
||||
return importStream(ifs);
|
||||
init(LLUUID::null, LLUUID::null, LLUUID::null, LLUUID::null);
|
||||
const S32 BUFSIZE = 16384;
|
||||
|
||||
// *NOTE: Changing the buffer size will require changing the scanf
|
||||
// calls below.
|
||||
char buffer[BUFSIZE]; /* Flawfinder: ignore */
|
||||
char keyword[256]; /* Flawfinder: ignore */
|
||||
char valuestr[256]; /* Flawfinder: ignore */
|
||||
char uuid_str[256]; /* Flawfinder: ignore */
|
||||
U32 mask;
|
||||
|
||||
keyword[0] = '\0';
|
||||
valuestr[0] = '\0';
|
||||
|
||||
while (!feof(fp))
|
||||
{
|
||||
if (fgets(buffer, BUFSIZE, fp) == NULL)
|
||||
{
|
||||
buffer[0] = '\0';
|
||||
}
|
||||
|
||||
sscanf( /* Flawfinder: ignore */
|
||||
buffer,
|
||||
" %255s %255s",
|
||||
keyword, valuestr);
|
||||
if (!strcmp("{", keyword))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!strcmp("}",keyword))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (!strcmp("creator_mask", keyword))
|
||||
{
|
||||
// legacy support for "creator" masks
|
||||
sscanf(valuestr, "%x", &mask);
|
||||
mMaskBase = mask;
|
||||
fixFairUse();
|
||||
}
|
||||
else if (!strcmp("base_mask", keyword))
|
||||
{
|
||||
sscanf(valuestr, "%x", &mask);
|
||||
mMaskBase = mask;
|
||||
//fixFairUse();
|
||||
}
|
||||
else if (!strcmp("owner_mask", keyword))
|
||||
{
|
||||
sscanf(valuestr, "%x", &mask);
|
||||
mMaskOwner = mask;
|
||||
}
|
||||
else if (!strcmp("group_mask", keyword))
|
||||
{
|
||||
sscanf(valuestr, "%x", &mask);
|
||||
mMaskGroup = mask;
|
||||
}
|
||||
else if (!strcmp("everyone_mask", keyword))
|
||||
{
|
||||
sscanf(valuestr, "%x", &mask);
|
||||
mMaskEveryone = mask;
|
||||
}
|
||||
else if (!strcmp("next_owner_mask", keyword))
|
||||
{
|
||||
sscanf(valuestr, "%x", &mask);
|
||||
mMaskNextOwner = mask;
|
||||
}
|
||||
else if (!strcmp("creator_id", keyword))
|
||||
{
|
||||
sscanf(valuestr, "%255s", uuid_str); /* Flawfinder: ignore */
|
||||
mCreator.set(uuid_str);
|
||||
}
|
||||
else if (!strcmp("owner_id", keyword))
|
||||
{
|
||||
sscanf(valuestr, "%255s", uuid_str); /* Flawfinder: ignore */
|
||||
mOwner.set(uuid_str);
|
||||
}
|
||||
else if (!strcmp("last_owner_id", keyword))
|
||||
{
|
||||
sscanf(valuestr, "%255s", uuid_str); /* Flawfinder: ignore */
|
||||
mLastOwner.set(uuid_str);
|
||||
}
|
||||
else if (!strcmp("group_id", keyword))
|
||||
{
|
||||
sscanf(valuestr, "%255s", uuid_str); /* Flawfinder: ignore */
|
||||
mGroup.set(uuid_str);
|
||||
}
|
||||
else if (!strcmp("group_owned", keyword))
|
||||
{
|
||||
sscanf(valuestr, "%d", &mask);
|
||||
if(mask) mIsGroupOwned = true;
|
||||
else mIsGroupOwned = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_INFOS() << "unknown keyword " << keyword << " in permissions import" << LL_ENDL;
|
||||
}
|
||||
}
|
||||
fix();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL LLPermissions::exportFile(LLFILE* fp) const
|
||||
{
|
||||
llofstream ofs(fp);
|
||||
return exportStream(ofs);
|
||||
std::string uuid_str;
|
||||
|
||||
fprintf(fp, "\tpermissions 0\n");
|
||||
fprintf(fp, "\t{\n");
|
||||
|
||||
fprintf(fp, "\t\tbase_mask\t%08x\n", mMaskBase);
|
||||
fprintf(fp, "\t\towner_mask\t%08x\n", mMaskOwner);
|
||||
fprintf(fp, "\t\tgroup_mask\t%08x\n", mMaskGroup);
|
||||
fprintf(fp, "\t\teveryone_mask\t%08x\n", mMaskEveryone);
|
||||
fprintf(fp, "\t\tnext_owner_mask\t%08x\n", mMaskNextOwner);
|
||||
|
||||
mCreator.toString(uuid_str);
|
||||
fprintf(fp, "\t\tcreator_id\t%s\n", uuid_str.c_str());
|
||||
|
||||
mOwner.toString(uuid_str);
|
||||
fprintf(fp, "\t\towner_id\t%s\n", uuid_str.c_str());
|
||||
|
||||
mLastOwner.toString(uuid_str);
|
||||
fprintf(fp, "\t\tlast_owner_id\t%s\n", uuid_str.c_str());
|
||||
|
||||
mGroup.toString(uuid_str);
|
||||
fprintf(fp, "\t\tgroup_id\t%s\n", uuid_str.c_str());
|
||||
|
||||
if(mIsGroupOwned)
|
||||
{
|
||||
fprintf(fp, "\t\tgroup_owned\t1\n");
|
||||
}
|
||||
fprintf(fp,"\t}\n");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL LLPermissions::importStream(std::istream& input_stream)
|
||||
|
||||
BOOL LLPermissions::importLegacyStream(std::istream& input_stream)
|
||||
{
|
||||
init(LLUUID::null, LLUUID::null, LLUUID::null, LLUUID::null);
|
||||
const S32 BUFSIZE = 16384;
|
||||
@@ -601,18 +726,6 @@ BOOL LLPermissions::importStream(std::istream& input_stream)
|
||||
while (input_stream.good())
|
||||
{
|
||||
input_stream.getline(buffer, BUFSIZE);
|
||||
if (input_stream.eof())
|
||||
{
|
||||
LL_WARNS() << "Bad permissions: early end of input stream"
|
||||
<< LL_ENDL;
|
||||
return FALSE;
|
||||
}
|
||||
if (input_stream.fail())
|
||||
{
|
||||
LL_WARNS() << "Bad permissions: failed to read from input stream"
|
||||
<< LL_ENDL;
|
||||
return FALSE;
|
||||
}
|
||||
sscanf( /* Flawfinder: ignore */
|
||||
buffer,
|
||||
" %255s %255s",
|
||||
@@ -695,26 +808,36 @@ BOOL LLPermissions::importStream(std::istream& input_stream)
|
||||
}
|
||||
|
||||
|
||||
BOOL LLPermissions::exportStream(std::ostream& output_stream) const
|
||||
BOOL LLPermissions::exportLegacyStream(std::ostream& output_stream) const
|
||||
{
|
||||
if (!output_stream.good()) return FALSE;
|
||||
std::string uuid_str;
|
||||
|
||||
output_stream << "\tpermissions 0\n";
|
||||
output_stream << "\t{\n";
|
||||
|
||||
char prev_fill = output_stream.fill('0');
|
||||
output_stream << std::hex;
|
||||
output_stream << "\t\tbase_mask\t" << std::setw(8) << mMaskBase << "\n";
|
||||
output_stream << "\t\towner_mask\t" << std::setw(8) << mMaskOwner << "\n";
|
||||
output_stream << "\t\tgroup_mask\t" << std::setw(8) << mMaskGroup << "\n";
|
||||
output_stream << "\t\teveryone_mask\t" << std::setw(8) << mMaskEveryone << "\n";
|
||||
output_stream << "\t\tnext_owner_mask\t" << std::setw(8) << mMaskNextOwner << "\n";
|
||||
output_stream << std::dec;
|
||||
output_stream.fill(prev_fill);
|
||||
std::string buffer;
|
||||
buffer = llformat( "\t\tbase_mask\t%08x\n", mMaskBase);
|
||||
output_stream << buffer;
|
||||
buffer = llformat( "\t\towner_mask\t%08x\n", mMaskOwner);
|
||||
output_stream << buffer;
|
||||
buffer = llformat( "\t\tgroup_mask\t%08x\n", mMaskGroup);
|
||||
output_stream << buffer;
|
||||
buffer = llformat( "\t\teveryone_mask\t%08x\n", mMaskEveryone);
|
||||
output_stream << buffer;
|
||||
buffer = llformat( "\t\tnext_owner_mask\t%08x\n", mMaskNextOwner);
|
||||
output_stream << buffer;
|
||||
|
||||
output_stream << "\t\tcreator_id\t" << mCreator << "\n";
|
||||
output_stream << "\t\towner_id\t" << mOwner << "\n";
|
||||
output_stream << "\t\tlast_owner_id\t" << mLastOwner << "\n";
|
||||
output_stream << "\t\tgroup_id\t" << mGroup << "\n";
|
||||
mCreator.toString(uuid_str);
|
||||
output_stream << "\t\tcreator_id\t" << uuid_str << "\n";
|
||||
|
||||
mOwner.toString(uuid_str);
|
||||
output_stream << "\t\towner_id\t" << uuid_str << "\n";
|
||||
|
||||
mLastOwner.toString(uuid_str);
|
||||
output_stream << "\t\tlast_owner_id\t" << uuid_str << "\n";
|
||||
|
||||
mGroup.toString(uuid_str);
|
||||
output_stream << "\t\tgroup_id\t" << uuid_str << "\n";
|
||||
|
||||
if(mIsGroupOwned)
|
||||
{
|
||||
@@ -772,21 +895,6 @@ std::ostream& operator<<(std::ostream &s, const LLPermissions &perm)
|
||||
return s;
|
||||
}
|
||||
|
||||
template <>
|
||||
void LLMetaClassT<LLPermissions>::reflectProperties(LLMetaClass& meta_class)
|
||||
{
|
||||
reflectProperty(meta_class, "mCreator", &LLPermissions::mCreator);
|
||||
reflectProperty(meta_class, "mOwner", &LLPermissions::mOwner);
|
||||
reflectProperty(meta_class, "mGroup", &LLPermissions::mGroup);
|
||||
reflectProperty(meta_class, "mIsGroupOwned", &LLPermissions::mIsGroupOwned);
|
||||
}
|
||||
|
||||
// virtual
|
||||
const LLMetaClass& LLPermissions::getMetaClass() const
|
||||
{
|
||||
return LLMetaClassT<LLPermissions>::instance();
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------
|
||||
/// Class LLAggregatePermissions
|
||||
///----------------------------------------------------------------------------
|
||||
@@ -1021,7 +1129,7 @@ void mask_to_string(U32 mask, char* str)
|
||||
else
|
||||
{
|
||||
*str = ' ';
|
||||
}
|
||||
}
|
||||
str++;
|
||||
|
||||
if (mask & PERM_EXPORT)
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "llsd.h"
|
||||
#include "lluuid.h"
|
||||
#include "llxmlnode.h"
|
||||
#include "reflective.h"
|
||||
#include "llinventorytype.h"
|
||||
|
||||
// prototypes
|
||||
@@ -89,7 +88,7 @@ enum ExportPolicy {
|
||||
// logical consistency.
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
class LLPermissions : public LLReflective
|
||||
class LLPermissions
|
||||
{
|
||||
private:
|
||||
LLUUID mCreator; // null if object created by system
|
||||
@@ -329,17 +328,14 @@ public:
|
||||
BOOL importFile(LLFILE* fp);
|
||||
BOOL exportFile(LLFILE* fp) const;
|
||||
|
||||
BOOL importStream(std::istream& input_stream);
|
||||
BOOL exportStream(std::ostream& output_stream) const;
|
||||
BOOL importLegacyStream(std::istream& input_stream);
|
||||
BOOL exportLegacyStream(std::ostream& output_stream) const;
|
||||
|
||||
bool operator==(const LLPermissions &rhs) const;
|
||||
bool operator!=(const LLPermissions &rhs) const;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream &s, const LLPermissions &perm);
|
||||
|
||||
// Reflection.
|
||||
friend class LLMetaClassT<LLPermissions>;
|
||||
virtual const LLMetaClass& getMetaClass() const;
|
||||
};
|
||||
|
||||
// Inlines
|
||||
|
||||
@@ -87,13 +87,15 @@ U32 LLSaleInfo::getCRC32() const
|
||||
|
||||
BOOL LLSaleInfo::exportFile(LLFILE* fp) const
|
||||
{
|
||||
llofstream ofs(fp);
|
||||
return exportStream(ofs);
|
||||
fprintf(fp, "\tsale_info\t0\n\t{\n");
|
||||
fprintf(fp, "\t\tsale_type\t%s\n", lookup(mSaleType));
|
||||
fprintf(fp, "\t\tsale_price\t%d\n", mSalePrice);
|
||||
fprintf(fp,"\t}\n");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL LLSaleInfo::exportStream(std::ostream& output_stream) const
|
||||
BOOL LLSaleInfo::exportLegacyStream(std::ostream& output_stream) const
|
||||
{
|
||||
if (!output_stream.good()) return FALSE;
|
||||
output_stream << "\tsale_info\t0\n\t{\n";
|
||||
output_stream << "\t\tsale_type\t" << lookup(mSaleType) << "\n";
|
||||
output_stream << "\t\tsale_price\t" << mSalePrice << "\n";
|
||||
@@ -137,40 +139,25 @@ bool LLSaleInfo::fromLLSD(const LLSD& sd, BOOL& has_perm_mask, U32& perm_mask)
|
||||
// because I can't find any non-test code references to it. 2009-05-04 JC
|
||||
|
||||
BOOL LLSaleInfo::importFile(LLFILE* fp, BOOL& has_perm_mask, U32& perm_mask)
|
||||
{
|
||||
llifstream ifs(fp);
|
||||
return importStream(ifs, has_perm_mask, perm_mask);
|
||||
}
|
||||
|
||||
BOOL LLSaleInfo::importStream(std::istream& input_stream, BOOL& has_perm_mask, U32& perm_mask)
|
||||
{
|
||||
has_perm_mask = FALSE;
|
||||
|
||||
const S32 BUFSIZE = 16384;
|
||||
|
||||
// *NOTE: Changing the buffer size will require changing the scanf
|
||||
// calls below.
|
||||
char buffer[BUFSIZE]; /* Flawfinder: ignore */
|
||||
char keyword[255]; /* Flawfinder: ignore */
|
||||
char valuestr[255]; /* Flawfinder: ignore */
|
||||
char buffer[MAX_STRING]; /* Flawfinder: ignore */
|
||||
char keyword[MAX_STRING]; /* Flawfinder: ignore */
|
||||
char valuestr[MAX_STRING]; /* Flawfinder: ignore */
|
||||
BOOL success = TRUE;
|
||||
|
||||
keyword[0] = '\0';
|
||||
valuestr[0] = '\0';
|
||||
while(input_stream.good())
|
||||
while(success && (!feof(fp)))
|
||||
{
|
||||
input_stream.getline(buffer, MAX_STRING);
|
||||
if (input_stream.eof())
|
||||
if (fgets(buffer, MAX_STRING, fp) == NULL)
|
||||
{
|
||||
LL_WARNS() << "Bad sale info: early end of input stream"
|
||||
<< LL_ENDL;
|
||||
return FALSE;
|
||||
}
|
||||
if (input_stream.fail())
|
||||
{
|
||||
LL_WARNS() << "Bad sale info: failed to read from input stream"
|
||||
<< LL_ENDL;
|
||||
return FALSE;
|
||||
buffer[0] = '\0';
|
||||
}
|
||||
|
||||
sscanf( /* Flawfinder: ignore */
|
||||
buffer,
|
||||
" %254s %254s",
|
||||
@@ -208,7 +195,63 @@ BOOL LLSaleInfo::importStream(std::istream& input_stream, BOOL& has_perm_mask, U
|
||||
<< "' in sale info import" << LL_ENDL;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
return success;
|
||||
}
|
||||
|
||||
BOOL LLSaleInfo::importLegacyStream(std::istream& input_stream, BOOL& has_perm_mask, U32& perm_mask)
|
||||
{
|
||||
has_perm_mask = FALSE;
|
||||
|
||||
// *NOTE: Changing the buffer size will require changing the scanf
|
||||
// calls below.
|
||||
char buffer[MAX_STRING]; /* Flawfinder: ignore */
|
||||
char keyword[MAX_STRING]; /* Flawfinder: ignore */
|
||||
char valuestr[MAX_STRING]; /* Flawfinder: ignore */
|
||||
BOOL success = TRUE;
|
||||
|
||||
keyword[0] = '\0';
|
||||
valuestr[0] = '\0';
|
||||
while(success && input_stream.good())
|
||||
{
|
||||
input_stream.getline(buffer, MAX_STRING);
|
||||
sscanf( /* Flawfinder: ignore */
|
||||
buffer,
|
||||
" %254s %254s",
|
||||
keyword, valuestr);
|
||||
if(!keyword[0])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(0 == strcmp("{",keyword))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(0 == strcmp("}", keyword))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if(0 == strcmp("sale_type", keyword))
|
||||
{
|
||||
mSaleType = lookup(valuestr);
|
||||
}
|
||||
else if(0 == strcmp("sale_price", keyword))
|
||||
{
|
||||
sscanf(valuestr, "%d", &mSalePrice);
|
||||
mSalePrice = llclamp(mSalePrice, 0, S32_MAX);
|
||||
}
|
||||
else if (!strcmp("perm_mask", keyword))
|
||||
{
|
||||
//LL_INFOS() << "found deprecated keyword perm_mask" << LL_ENDL;
|
||||
has_perm_mask = TRUE;
|
||||
sscanf(valuestr, "%x", &perm_mask);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_WARNS() << "unknown keyword '" << keyword
|
||||
<< "' in sale info import" << LL_ENDL;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
void LLSaleInfo::setSalePrice(S32 price)
|
||||
|
||||
@@ -95,11 +95,11 @@ public:
|
||||
BOOL exportFile(LLFILE* fp) const;
|
||||
BOOL importFile(LLFILE* fp, BOOL& has_perm_mask, U32& perm_mask);
|
||||
|
||||
BOOL exportStream(std::ostream& output_stream) const;
|
||||
BOOL exportLegacyStream(std::ostream& output_stream) const;
|
||||
LLSD asLLSD() const;
|
||||
operator LLSD() const { return asLLSD(); }
|
||||
bool fromLLSD(const LLSD& sd, BOOL& has_perm_mask, U32& perm_mask);
|
||||
BOOL importStream(std::istream& input_stream, BOOL& has_perm_mask, U32& perm_mask);
|
||||
BOOL importLegacyStream(std::istream& input_stream, BOOL& has_perm_mask, U32& perm_mask);
|
||||
|
||||
LLSD packMessage() const;
|
||||
void unpackMessage(const LLSD& sales);
|
||||
|
||||
Reference in New Issue
Block a user