summaryrefslogtreecommitdiff
path: root/indra/llinventory/llsaleinfo.cpp
diff options
context:
space:
mode:
authorDon Kjer <don@lindenlab.com>2012-09-20 04:29:17 +0000
committerDon Kjer <don@lindenlab.com>2012-09-20 04:29:17 +0000
commit7153d1db11c00245a379fa9601f092020152ea73 (patch)
tree816eb5f9d965379ebc2a4c4b030c2f9f97549726 /indra/llinventory/llsaleinfo.cpp
parent7b75bd089834a84ab5062c96870edeee6fa22861 (diff)
Partial rewrite of llifstream and llofstream (Windows implementation pending). Moved more functionality from llviewerwearable to llwearable
Diffstat (limited to 'indra/llinventory/llsaleinfo.cpp')
-rw-r--r--indra/llinventory/llsaleinfo.cpp95
1 files changed, 26 insertions, 69 deletions
diff --git a/indra/llinventory/llsaleinfo.cpp b/indra/llinventory/llsaleinfo.cpp
index dd408a8efe..a829667933 100644
--- a/indra/llinventory/llsaleinfo.cpp
+++ b/indra/llinventory/llsaleinfo.cpp
@@ -81,15 +81,13 @@ U32 LLSaleInfo::getCRC32() const
BOOL LLSaleInfo::exportFile(LLFILE* fp) const
{
- 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;
+ llofstream ofs(fp);
+ return exportStream(ofs);
}
-BOOL LLSaleInfo::exportLegacyStream(std::ostream& output_stream) const
+BOOL LLSaleInfo::exportStream(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";
@@ -134,80 +132,39 @@ bool LLSaleInfo::fromLLSD(const LLSD& sd, BOOL& has_perm_mask, U32& perm_mask)
BOOL LLSaleInfo::importFile(LLFILE* fp, 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 && (!feof(fp)))
- {
- if (fgets(buffer, MAX_STRING, fp) == NULL)
- {
- buffer[0] = '\0';
- }
-
- 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))
- {
- //llinfos << "found deprecated keyword perm_mask" << llendl;
- has_perm_mask = TRUE;
- sscanf(valuestr, "%x", &perm_mask);
- }
- else
- {
- llwarns << "unknown keyword '" << keyword
- << "' in sale info import" << llendl;
- }
- }
- return success;
+ llifstream ifs(fp);
+ return importStream(ifs, has_perm_mask, perm_mask);
}
-BOOL LLSaleInfo::importLegacyStream(std::istream& input_stream, BOOL& has_perm_mask, U32& 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[MAX_STRING]; /* Flawfinder: ignore */
- char keyword[MAX_STRING]; /* Flawfinder: ignore */
- char valuestr[MAX_STRING]; /* Flawfinder: ignore */
- BOOL success = TRUE;
+ char buffer[BUFSIZE]; /* Flawfinder: ignore */
+ char keyword[255]; /* Flawfinder: ignore */
+ char valuestr[255]; /* Flawfinder: ignore */
keyword[0] = '\0';
valuestr[0] = '\0';
- while(success && input_stream.good())
+ while(input_stream.good())
{
input_stream.getline(buffer, MAX_STRING);
+ if (input_stream.eof())
+ {
+ llwarns << "Bad sale info: early end of input stream"
+ << llendl;
+ return FALSE;
+ }
+ if (input_stream.fail())
+ {
+ llwarns << "Bad sale info: failed to read from input stream"
+ << llendl;
+ return FALSE;
+ }
sscanf( /* Flawfinder: ignore */
buffer,
" %254s %254s",
@@ -245,7 +202,7 @@ BOOL LLSaleInfo::importLegacyStream(std::istream& input_stream, BOOL& has_perm_m
<< "' in sale info import" << llendl;
}
}
- return success;
+ return TRUE;
}
void LLSaleInfo::setSalePrice(S32 price)