diff options
Diffstat (limited to 'indra/llcommon/llsdserialize.cpp')
| -rw-r--r-- | indra/llcommon/llsdserialize.cpp | 75 | 
1 files changed, 42 insertions, 33 deletions
| diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index 2183792bb1..10f460e8a6 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -4,36 +4,31 @@   * @date 2006-03-05   * @brief Implementation of LLSD parsers and formatters   * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - *  - * Copyright (c) 2006-2007, Linden Research, Inc. - *  + * $LicenseInfo:firstyear=2006&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://secondlife.com/developers/opensource/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://secondlife.com/developers/opensource/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 "llsdserialize.h" -#include "llmemory.h" +#include "llpointer.h"  #include "llstreamtools.h" // for fullread  #include <iostream> @@ -76,7 +71,7 @@ void LLSDSerialize::serialize(const LLSD& sd, std::ostream& str, ELLSD_Serialize  		break;  	default: -		llwarns << "serialize request for unkown ELLSD_Serialize" << llendl; +		llwarns << "serialize request for unknown ELLSD_Serialize" << llendl;  	}  	if (f.notNull()) @@ -146,12 +141,15 @@ bool LLSDSerialize::deserialize(LLSD& sd, std::istream& str, S32 max_bytes)  	 * Create the parser as appropriate  	 */  	if (legacy_no_header) -	{ -		LLSDXMLParser* x = new LLSDXMLParser; -		x->parsePart(hdr_buf, inbuf); -		p = x; +	{	// Create a LLSD XML parser, and parse the first chunk read above +		LLSDXMLParser* x = new LLSDXMLParser(); +		x->parsePart(hdr_buf, inbuf);	// Parse the first part that was already read +		x->parseLines(str, sd);			// Parse the rest of it +		delete x; +		return true;  	} -	else if (header == LLSD_BINARY_HEADER) + +	if (header == LLSD_BINARY_HEADER)  	{  		p = new LLSDBinaryParser;  	} @@ -300,7 +298,8 @@ static const char BINARY_FALSE_SERIAL = '0';  /**   * LLSDParser   */ -LLSDParser::LLSDParser() : mCheckLimits(true), mMaxBytesLeft(0) +LLSDParser::LLSDParser() +	: mCheckLimits(true), mMaxBytesLeft(0), mParseLines(false)  {  } @@ -316,6 +315,15 @@ S32 LLSDParser::parse(std::istream& istr, LLSD& data, S32 max_bytes)  } +// Parse using routine to get() lines, faster than parse() +S32 LLSDParser::parseLines(std::istream& istr, LLSD& data) +{ +	mCheckLimits = false; +	mParseLines = true; +	return doParse(istr, data); +} + +  int LLSDParser::get(std::istream& istr) const  {  	if(mCheckLimits) --mMaxBytesLeft; @@ -1217,8 +1225,7 @@ void LLSDFormatter::realFormat(const std::string& format)  void LLSDFormatter::formatReal(LLSD::Real real, std::ostream& ostr) const  { -	char buffer[MAX_STRING];		/* Flawfinder: ignore */ -	snprintf(buffer, MAX_STRING, mRealFormat.c_str(), real);	/* Flawfinder: ignore */ +	std::string buffer = llformat(mRealFormat.c_str(), real);  	ostr << buffer;  } @@ -1489,7 +1496,7 @@ void LLSDBinaryFormatter::formatString(   */  int deserialize_string(std::istream& istr, std::string& value, S32 max_bytes)  { -	char c = istr.get(); +	int c = istr.get();  	if(istr.fail())  	{  		// No data in stream, bail out but mention the character we @@ -1531,7 +1538,7 @@ int deserialize_string_delim(  	while (true)  	{ -		char next_char = istr.get(); +		int next_byte = istr.get();  		++count;  		if(istr.fail()) @@ -1540,6 +1547,8 @@ int deserialize_string_delim(  			value = write_buffer.str();  			return LLSDParser::PARSE_FAILURE;  		} + +		char next_char = (char)next_byte; // Now that we know it's not EOF  		if(found_escape)  		{ @@ -1628,7 +1637,7 @@ int deserialize_string_raw(  	char buf[BUF_LEN];		/* Flawfinder: ignore */  	istr.get(buf, BUF_LEN - 1, ')');  	count += istr.gcount(); -	char c = istr.get(); +	int c = istr.get();  	c = istr.get();  	count += 2;  	if(((c == '"') || (c == '\'')) && (buf[0] == '(')) | 
