Esempio n. 1
0
BOOL LLDataPackerAsciiBuffer::packF32(const F32 value, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	int numCopied = 0;
	if (mWriteEnabled)
	{
	    	numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%f\n", value);		/* Flawfinder: ignore */
	}
	else
	{
		numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%f\n", value);		/* Flawfinder: ignore */	
	}
	// snprintf returns number of bytes that would have been written
	// had the output not being truncated. In that case, it will
	// return either -1 or value >= passed in size value . So a check needs to be added
	// to detect truncation, and if there is any, only account for the
	// actual number of bytes written..and not what could have been
	// written.
	if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize())
	{
		numCopied = getBufferSize()-getCurrentSize();
		llwarns << "LLDataPackerAsciiBuffer::packF32: val truncated: " << llendl;
	}

	mCurBufferp += numCopied;
	return success;
}
Esempio n. 2
0
BOOL LLDataPackerAsciiFile::packBinaryDataFixed(const U8 *value, S32 size, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	
	if (mFP)
	{
		S32 i;
		for (i = 0; i < size; i++)
		{
			fprintf(mFP, "%02x ", value[i]);
		}
		fprintf(mFP, "\n");
	}
	else if (mOutputStream)
	{
		char buffer[32]; /*Flawfinder: ignore*/
		S32 i;
		for (i = 0; i < size; i++)
		{
			snprintf(buffer, sizeof(buffer), "%02x ", value[i]);	/* Flawfinder: ignore */
			*mOutputStream << buffer;
		}
		*mOutputStream << "\n";
	}
	return success;
}
Esempio n. 3
0
//---------------------------------------------------------------------------
// LLDataPackerAsciiBuffer implementation
//---------------------------------------------------------------------------
BOOL LLDataPackerAsciiBuffer::packString(const char *value, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	int numCopied = 0;
	if (mWriteEnabled) 
	{
		numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", value);		/* Flawfinder: ignore */
	}
	else
	{
		numCopied = (S32)strlen(value) + 1; /*Flawfinder: ignore*/
	}

	// snprintf returns number of bytes that would have been written
	// had the output not being truncated. In that case, it will
	// return either -1 or value >= passed in size value . So a check needs to be added
	// to detect truncation, and if there is any, only account for the
	// actual number of bytes written..and not what could have been
	// written.
	if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize())
	{
		// *NOTE: I believe we need to mark a failure bit at this point.
	    numCopied = getBufferSize()-getCurrentSize();
		llwarns << "LLDataPackerAsciiBuffer::packString: string truncated: " << value << llendl;
	}
	mCurBufferp += numCopied;
	return success;
}
Esempio n. 4
0
BOOL LLDataPackerAsciiBuffer::packUUID(const LLUUID &value, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);

	int numCopied = 0;
	if (mWriteEnabled)
	{
		char tmp_str[64]; /* Flawfinder: ignore */ 
		value.toString(tmp_str);
	    	numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", tmp_str);	/* Flawfinder: ignore */
	}
	else
	{
		numCopied = 64 + 1; // UUID + newline
	}
	// snprintf returns number of bytes that would have been written
	// had the output not being truncated. In that case, it will
	// return either -1 or value >= passed in size value . So a check needs to be added
	// to detect truncation, and if there is any, only account for the
	// actual number of bytes written..and not what could have been
	// written.
	if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize())
	{
	    numCopied = getBufferSize()-getCurrentSize();
		llwarns << "LLDataPackerAsciiBuffer::packUUID: truncated: " << llendl;
		success = FALSE;
	}
	mCurBufferp += numCopied;
	return success;
}
Esempio n. 5
0
BOOL LLDataPackerAsciiFile::packVector4(const LLVector4 &value, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	if (mFP)
	{
		fprintf(mFP,"%f %f %f %f\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]);	
	}
	else if (mOutputStream)
	{
		*mOutputStream << convertF32ToString(value.mV[0]) << " " << convertF32ToString(value.mV[1]) << " " << convertF32ToString(value.mV[2]) << " " << convertF32ToString(value.mV[3]) << "\n";
	}
	return success;
}
Esempio n. 6
0
BOOL LLDataPackerAsciiFile::packColor4U(const LLColor4U &value, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	if (mFP)
	{
		fprintf(mFP,"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]);	
	}
	else if (mOutputStream)
	{
		*mOutputStream << (S32)(value.mV[0]) << " " << (S32)(value.mV[1]) << " " << (S32)(value.mV[2]) << " " << (S32)(value.mV[3]) << "\n";
	}
	return success;
}
Esempio n. 7
0
BOOL LLDataPackerAsciiFile::packF32(const F32 value, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	if (mFP)
	{
		fprintf(mFP,"%f\n", value);	
	}
	else if (mOutputStream)
	{
		*mOutputStream <<"" << convertF32ToString(value) << "\n";
	}
	return success;
}
Esempio n. 8
0
BOOL LLDataPackerAsciiFile::packU16(const U16 value, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	if (mFP)
	{
		fprintf(mFP,"%d\n", value);	
	}
	else if (mOutputStream)
	{
		*mOutputStream <<"" << value << "\n";
	}
	return success;
}
Esempio n. 9
0
//---------------------------------------------------------------------------
// LLDataPackerAsciiFile implementation
//---------------------------------------------------------------------------
BOOL LLDataPackerAsciiFile::packString(const std::string& value, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	if (mFP)
	{
		fprintf(mFP,"%s\n", value.c_str());	
	}
	else if (mOutputStream)
	{
		*mOutputStream << value << "\n";
	}
	return success;
}
Esempio n. 10
0
BOOL LLDataPackerAsciiFile::packUUID(const LLUUID &value, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	char tmp_str[64]; /*Flawfinder: ignore */
	value.toString(tmp_str);
	if (mFP)
	{
		fprintf(mFP,"%s\n", tmp_str);
	}
	else if (mOutputStream)
	{
		*mOutputStream <<"" << tmp_str << "\n";
	}
	return success;
}
Esempio n. 11
0
BOOL LLDataPackerAsciiFile::packU8(const U8 value, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	if (mFP)
	{
		fprintf(mFP,"%d\n", value);	
	}
	else if (mOutputStream)
	{
		// We have to cast this to an integer because streams serialize
		// bytes as bytes - not as text.
		*mOutputStream << (S32)value << "\n";
	}
	return success;
}
Esempio n. 12
0
BOOL LLDataPackerAsciiFile::packUUID(const LLUUID &value, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	std::string tmp_str;
	value.toString(tmp_str);
	if (mFP)
	{
		fprintf(mFP,"%s\n", tmp_str.c_str());
	}
	else if (mOutputStream)
	{
		*mOutputStream <<"" << tmp_str << "\n";
	}
	return success;
}
Esempio n. 13
0
BOOL LLDataPackerAsciiBuffer::packBinaryDataFixed(const U8 *value, S32 size, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	
	if (mWriteEnabled)
	{
		S32 i;
		int numCopied = 0;
		BOOL bBufferFull = FALSE;
		for (i = 0; i < size && !bBufferFull; i++)
		{
			numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]);	/* Flawfinder: ignore */
			if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize())
			{
			    numCopied = getBufferSize()-getCurrentSize();
				llwarns << "LLDataPackerAsciiBuffer::packBinaryDataFixed: data truncated: " << llendl;
			    bBufferFull = TRUE;
			}
			mCurBufferp += numCopied;

		}
		if (!bBufferFull)
		{
			numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n");	/* Flawfinder: ignore */
			if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize())
			{
				numCopied = getBufferSize()-getCurrentSize();
				llwarns << "LLDataPackerAsciiBuffer::packBinaryDataFixed: newline truncated: " << llendl;
			}
			
			mCurBufferp += numCopied;
		}
	}
	else
	{
		int numCopied = 2 * size + 1; //hex bytes plus newline 
		if (numCopied > getBufferSize()-getCurrentSize())
		{
			numCopied = getBufferSize()-getCurrentSize();
		}   
		mCurBufferp += numCopied;
	}
	return success;
}
Esempio n. 14
0
BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const char *name)
{
	BOOL success = TRUE;
	writeIndentedName(name);
	
	int numCopied = 0;
	if (mWriteEnabled)
	{
		numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%010d ", size);	/* Flawfinder: ignore */

		// snprintf returns number of bytes that would have been
		// written had the output not being truncated. In that case,
		// it will retuen >= passed in size value.  so a check needs
		// to be added to detect truncation, and if there is any, only
		// account for the actual number of bytes written..and not
		// what could have been written.
		if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize())
		{
			numCopied = getBufferSize()-getCurrentSize();
			llwarns << "LLDataPackerAsciiBuffer::packBinaryData: number truncated: " << size << llendl;
		}
		mCurBufferp += numCopied;


		S32 i;
		BOOL bBufferFull = FALSE;
		for (i = 0; i < size && !bBufferFull; i++)
		{
			numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]);	/* Flawfinder: ignore */
			if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize())
			{
				numCopied = getBufferSize()-getCurrentSize();
				llwarns << "LLDataPackerAsciiBuffer::packBinaryData: data truncated: " << llendl;
				bBufferFull = TRUE;
			}
			mCurBufferp += numCopied;
		}

		if (!bBufferFull)
		{
			numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n");	/* Flawfinder: ignore */
			if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize())
		    	{
				numCopied = getBufferSize()-getCurrentSize();
				llwarns << "LLDataPackerAsciiBuffer::packBinaryData: newline truncated: " << llendl;
		    	}
		    	mCurBufferp += numCopied;
		}
	}
	else
	{
		// why +10 ?? XXXCHECK
		numCopied = 10 + 1; // size plus newline
		numCopied += size;
		if (numCopied > getBufferSize()-getCurrentSize())
		{
			numCopied = getBufferSize()-getCurrentSize();
		}   
		mCurBufferp += numCopied;
	}
	
	return success;
}