summaryrefslogtreecommitdiff
path: root/indra/llxml/llxmlnode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llxml/llxmlnode.cpp')
-rw-r--r--indra/llxml/llxmlnode.cpp476
1 files changed, 313 insertions, 163 deletions
diff --git a/indra/llxml/llxmlnode.cpp b/indra/llxml/llxmlnode.cpp
index 2298dc22e7..e695035461 100644
--- a/indra/llxml/llxmlnode.cpp
+++ b/indra/llxml/llxmlnode.cpp
@@ -38,19 +38,21 @@
#include "v3math.h"
#include "v3dmath.h"
#include "v4math.h"
+#include "llbase64.h"
#include "llquaternion.h"
+#include "llsd.h"
#include "llstring.h"
#include "lluuid.h"
#include "lldir.h"
// static
-BOOL LLXMLNode::sStripEscapedStrings = TRUE;
-BOOL LLXMLNode::sStripWhitespaceValues = FALSE;
+bool LLXMLNode::sStripEscapedStrings = true;
+bool LLXMLNode::sStripWhitespaceValues = false;
LLXMLNode::LLXMLNode() :
mID(""),
mParser(NULL),
- mIsAttribute(FALSE),
+ mIsAttribute(false),
mVersionMajor(0),
mVersionMinor(0),
mLength(0),
@@ -69,7 +71,7 @@ LLXMLNode::LLXMLNode() :
{
}
-LLXMLNode::LLXMLNode(const char* name, BOOL is_attribute) :
+LLXMLNode::LLXMLNode(const char* name, bool is_attribute) :
mID(""),
mParser(NULL),
mIsAttribute(is_attribute),
@@ -91,7 +93,7 @@ LLXMLNode::LLXMLNode(const char* name, BOOL is_attribute) :
mName = gStringTable.addStringEntry(name);
}
-LLXMLNode::LLXMLNode(LLStringTableEntry* name, BOOL is_attribute) :
+LLXMLNode::LLXMLNode(LLStringTableEntry* name, bool is_attribute) :
mID(""),
mParser(NULL),
mIsAttribute(is_attribute),
@@ -193,17 +195,17 @@ LLXMLNode::~LLXMLNode()
mDefault = NULL;
}
-BOOL LLXMLNode::isNull()
+bool LLXMLNode::isNull()
{
return (mName == NULL);
}
// protected
-BOOL LLXMLNode::removeChild(LLXMLNode *target_child)
+bool LLXMLNode::removeChild(LLXMLNode *target_child)
{
if (!target_child)
{
- return FALSE;
+ return false;
}
if (target_child->mIsAttribute)
{
@@ -212,7 +214,7 @@ BOOL LLXMLNode::removeChild(LLXMLNode *target_child)
{
target_child->mParent = NULL;
mAttributes.erase(children_itr);
- return TRUE;
+ return true;
}
}
else if (mChildren.notNull())
@@ -244,7 +246,7 @@ BOOL LLXMLNode::removeChild(LLXMLNode *target_child)
{
mChildren = NULL;
}
- return TRUE;
+ return true;
}
else if (children_itr->first != target_child->mName)
{
@@ -256,7 +258,7 @@ BOOL LLXMLNode::removeChild(LLXMLNode *target_child)
}
}
}
- return FALSE;
+ return false;
}
void LLXMLNode::addChild(LLXMLNodePtr& new_child)
@@ -302,13 +304,13 @@ void LLXMLNode::addChild(LLXMLNodePtr& new_child)
}
// virtual
-LLXMLNodePtr LLXMLNode::createChild(const char* name, BOOL is_attribute)
+LLXMLNodePtr LLXMLNode::createChild(const char* name, bool is_attribute)
{
return createChild(gStringTable.addStringEntry(name), is_attribute);
}
// virtual
-LLXMLNodePtr LLXMLNode::createChild(LLStringTableEntry* name, BOOL is_attribute)
+LLXMLNodePtr LLXMLNode::createChild(LLStringTableEntry* name, bool is_attribute)
{
LLXMLNodePtr ret(new LLXMLNode(name, is_attribute));
ret->mID.clear();
@@ -317,13 +319,13 @@ LLXMLNodePtr LLXMLNode::createChild(LLStringTableEntry* name, BOOL is_attribute)
return ret;
}
-BOOL LLXMLNode::deleteChild(LLXMLNode *child)
+bool LLXMLNode::deleteChild(LLXMLNode *child)
{
if (removeChild(child))
{
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
void LLXMLNode::setParent(LLXMLNodePtr& new_parent)
@@ -375,7 +377,7 @@ void XMLCALL StartXMLNode(void *userData,
const XML_Char **atts)
{
// Create a new node
- LLXMLNode *new_node_ptr = new LLXMLNode(name, FALSE);
+ LLXMLNode *new_node_ptr = new LLXMLNode(name, false);
LLXMLNodePtr new_node = new_node_ptr;
new_node->mID.clear();
@@ -480,9 +482,9 @@ void XMLCALL StartXMLNode(void *userData,
// only one attribute child per description
LLXMLNodePtr attr_node;
- if (!new_node->getAttribute(attr_name.c_str(), attr_node, FALSE))
+ if (!new_node->getAttribute(attr_name.c_str(), attr_node, false))
{
- attr_node = new LLXMLNode(attr_name.c_str(), TRUE);
+ attr_node = new LLXMLNode(attr_name.c_str(), true);
attr_node->setLineNumber(XML_GetCurrentLineNumber(*new_node_ptr->mParser));
}
attr_node->setValue(attr_value);
@@ -508,13 +510,13 @@ void XMLCALL EndXMLNode(void *userData,
if (LLXMLNode::sStripWhitespaceValues)
{
std::string value = node->getValue();
- BOOL is_empty = TRUE;
+ bool is_empty = true;
for (std::string::size_type s = 0; s < value.length(); s++)
{
char c = value[s];
if (c != ' ' && c != '\t' && c != '\n')
{
- is_empty = FALSE;
+ is_empty = false;
break;
}
}
@@ -575,7 +577,7 @@ bool LLXMLNode::updateNode(
if (!node || !update_node)
{
LL_WARNS() << "Node invalid" << LL_ENDL;
- return FALSE;
+ return false;
}
//update the node value
@@ -647,38 +649,30 @@ bool LLXMLNode::updateNode(
}
}
- return TRUE;
+ return true;
}
// static
bool LLXMLNode::parseFile(const std::string& filename, LLXMLNodePtr& node, LLXMLNode* defaults_tree)
{
- // Read file
- LL_DEBUGS("XMLNode") << "parsing XML file: " << filename << LL_ENDL;
- LLFILE* fp = LLFile::fopen(filename, "rb"); /* Flawfinder: ignore */
- if (fp == NULL)
+ std::string xml = LLFile::getContents(filename);
+ if (xml.empty())
{
- node = NULL ;
- return false;
+ LL_WARNS("XMLNode") << "no XML file: " << filename << LL_ENDL;
+ }
+ else if (parseBuffer(xml.data(), xml.size(), node, defaults_tree))
+ {
+ return true;
}
- fseek(fp, 0, SEEK_END);
- U32 length = ftell(fp);
- fseek(fp, 0, SEEK_SET);
-
- U8* buffer = new U8[length+1];
- size_t nread = fread(buffer, 1, length, fp);
- buffer[nread] = 0;
- fclose(fp);
- bool rv = parseBuffer(buffer, nread, node, defaults_tree);
- delete [] buffer;
- return rv;
+ node = nullptr;
+ return false;
}
// static
bool LLXMLNode::parseBuffer(
- U8* buffer,
- U32 length,
+ const char* buffer,
+ U64 length,
LLXMLNodePtr& node,
LLXMLNode* defaults)
{
@@ -688,25 +682,30 @@ bool LLXMLNode::parseBuffer(
XML_SetCharacterDataHandler(my_parser, XMLData);
// Create a root node
- LLXMLNode *file_node_ptr = new LLXMLNode("XML", FALSE);
+ LLXMLNode *file_node_ptr = new LLXMLNode("XML", false);
LLXMLNodePtr file_node = file_node_ptr;
file_node->mParser = &my_parser;
- XML_SetUserData(my_parser, (void *)file_node_ptr);
+ XML_SetUserData(my_parser, file_node_ptr);
// Do the parsing
- if (XML_Parse(my_parser, (const char *)buffer, length, TRUE) != XML_STATUS_OK)
+ bool success = XML_STATUS_OK == XML_Parse(my_parser, buffer, (int)length, true);
+ if (!success)
{
LL_WARNS() << "Error parsing xml error code: "
<< XML_ErrorString(XML_GetErrorCode(my_parser))
<< " on line " << XML_GetCurrentLineNumber(my_parser)
+ << ", column " << XML_GetCurrentColumnNumber(my_parser)
<< LL_ENDL;
}
// Deinit
XML_ParserFree(my_parser);
+ if (!success)
+ return false;
+
if (!file_node->mChildren || file_node->mChildren->map.size() != 1)
{
LL_WARNS() << "Parse failure - wrong number of top-level nodes xml."
@@ -736,7 +735,7 @@ bool LLXMLNode::parseStream(
XML_SetCharacterDataHandler(my_parser, XMLData);
// Create a root node
- LLXMLNode *file_node_ptr = new LLXMLNode("XML", FALSE);
+ LLXMLNode *file_node_ptr = new LLXMLNode("XML", false);
LLXMLNodePtr file_node = file_node_ptr;
file_node->mParser = &my_parser;
@@ -784,18 +783,18 @@ bool LLXMLNode::parseStream(
}
-BOOL LLXMLNode::isFullyDefault()
+bool LLXMLNode::isFullyDefault()
{
if (mDefault.isNull())
{
- return FALSE;
+ return false;
}
- BOOL has_default_value = (mValue == mDefault->mValue);
- BOOL has_default_attribute = (mIsAttribute == mDefault->mIsAttribute);
- BOOL has_default_type = mIsAttribute || (mType == mDefault->mType);
- BOOL has_default_encoding = mIsAttribute || (mEncoding == mDefault->mEncoding);
- BOOL has_default_precision = mIsAttribute || (mPrecision == mDefault->mPrecision);
- BOOL has_default_length = mIsAttribute || (mLength == mDefault->mLength);
+ bool has_default_value = (mValue == mDefault->mValue);
+ bool has_default_attribute = (mIsAttribute == mDefault->mIsAttribute);
+ bool has_default_type = mIsAttribute || (mType == mDefault->mType);
+ bool has_default_encoding = mIsAttribute || (mEncoding == mDefault->mEncoding);
+ bool has_default_precision = mIsAttribute || (mPrecision == mDefault->mPrecision);
+ bool has_default_length = mIsAttribute || (mLength == mDefault->mLength);
if (has_default_value
&& has_default_type
@@ -813,14 +812,14 @@ BOOL LLXMLNode::isFullyDefault()
LLXMLNodePtr child = (*children_itr).second;
if (!child->isFullyDefault())
{
- return FALSE;
+ return false;
}
}
}
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
// static
@@ -908,10 +907,10 @@ void LLXMLNode::writeToOstream(std::ostream& output_stream, const std::string& i
return;
}
- BOOL has_default_type = mDefault.isNull()?FALSE:(mType == mDefault->mType);
- BOOL has_default_encoding = mDefault.isNull()?FALSE:(mEncoding == mDefault->mEncoding);
- BOOL has_default_precision = mDefault.isNull()?FALSE:(mPrecision == mDefault->mPrecision);
- BOOL has_default_length = mDefault.isNull()?FALSE:(mLength == mDefault->mLength);
+ bool has_default_type = mDefault.isNull()?false:(mType == mDefault->mType);
+ bool has_default_encoding = mDefault.isNull()?false:(mEncoding == mDefault->mEncoding);
+ bool has_default_precision = mDefault.isNull()?false:(mPrecision == mDefault->mPrecision);
+ bool has_default_length = mDefault.isNull()?false:(mLength == mDefault->mLength);
// stream the name
output_stream << indent << "<" << mName->mString << "\n";
@@ -1153,12 +1152,12 @@ void LLXMLNode::scrubToTree(LLXMLNode *tree)
}
}
-bool LLXMLNode::getChild(const char* name, LLXMLNodePtr& node, BOOL use_default_if_missing)
+bool LLXMLNode::getChild(const char* name, LLXMLNodePtr& node, bool use_default_if_missing)
{
return getChild(gStringTable.checkStringEntry(name), node, use_default_if_missing);
}
-bool LLXMLNode::getChild(const LLStringTableEntry* name, LLXMLNodePtr& node, BOOL use_default_if_missing)
+bool LLXMLNode::getChild(const LLStringTableEntry* name, LLXMLNodePtr& node, bool use_default_if_missing)
{
if (mChildren.notNull())
{
@@ -1171,18 +1170,18 @@ bool LLXMLNode::getChild(const LLStringTableEntry* name, LLXMLNodePtr& node, BOO
}
if (use_default_if_missing && !mDefault.isNull())
{
- return mDefault->getChild(name, node, FALSE);
+ return mDefault->getChild(name, node, false);
}
node = NULL;
return false;
}
-void LLXMLNode::getChildren(const char* name, LLXMLNodeList &children, BOOL use_default_if_missing) const
+void LLXMLNode::getChildren(const char* name, LLXMLNodeList &children, bool use_default_if_missing) const
{
getChildren(gStringTable.checkStringEntry(name), children, use_default_if_missing);
}
-void LLXMLNode::getChildren(const LLStringTableEntry* name, LLXMLNodeList &children, BOOL use_default_if_missing) const
+void LLXMLNode::getChildren(const LLStringTableEntry* name, LLXMLNodeList &children, bool use_default_if_missing) const
{
if (mChildren.notNull())
{
@@ -1204,7 +1203,7 @@ void LLXMLNode::getChildren(const LLStringTableEntry* name, LLXMLNodeList &child
}
if (children.size() == 0 && use_default_if_missing && !mDefault.isNull())
{
- mDefault->getChildren(name, children, FALSE);
+ mDefault->getChildren(name, children, false);
}
}
@@ -1227,12 +1226,12 @@ void LLXMLNode::getDescendants(const LLStringTableEntry* name, LLXMLNodeList &ch
}
}
-bool LLXMLNode::getAttribute(const char* name, LLXMLNodePtr& node, BOOL use_default_if_missing)
+bool LLXMLNode::getAttribute(const char* name, LLXMLNodePtr& node, bool use_default_if_missing)
{
return getAttribute(gStringTable.checkStringEntry(name), node, use_default_if_missing);
}
-bool LLXMLNode::getAttribute(const LLStringTableEntry* name, LLXMLNodePtr& node, BOOL use_default_if_missing)
+bool LLXMLNode::getAttribute(const LLStringTableEntry* name, LLXMLNodePtr& node, bool use_default_if_missing)
{
LLXMLAttribList::const_iterator child_itr = mAttributes.find(name);
if (child_itr != mAttributes.end())
@@ -1242,7 +1241,7 @@ bool LLXMLNode::getAttribute(const LLStringTableEntry* name, LLXMLNodePtr& node,
}
if (use_default_if_missing && !mDefault.isNull())
{
- return mDefault->getAttribute(name, node, FALSE);
+ return mDefault->getAttribute(name, node, false);
}
return false;
@@ -1261,42 +1260,25 @@ bool LLXMLNode::setAttributeString(const char* attr, const std::string& value)
return false;
}
-BOOL LLXMLNode::hasAttribute(const char* name )
+bool LLXMLNode::hasAttribute(const char* name )
{
LLXMLNodePtr node;
return getAttribute(name, node);
}
-// the structure of these getAttribute_ functions is ugly, but it's because the
-// underlying system is based on BOOL and LLString; if we change
-// so that they're based on more generic mechanisms, these will be
-// simplified.
-bool LLXMLNode::getAttribute_bool(const char* name, bool& value )
-{
- LLXMLNodePtr node;
- if (!getAttribute(name, node))
- {
- return false;
- }
- BOOL temp;
- bool retval = node->getBoolValue(1, &temp);
- value = temp;
- return retval;
-}
-
-BOOL LLXMLNode::getAttributeBOOL(const char* name, BOOL& value )
+bool LLXMLNode::getAttributeBOOL(const char* name, bool& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getBoolValue(1, &value));
}
-BOOL LLXMLNode::getAttributeU8(const char* name, U8& value )
+bool LLXMLNode::getAttributeU8(const char* name, U8& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getByteValue(1, &value));
}
-BOOL LLXMLNode::getAttributeS8(const char* name, S8& value )
+bool LLXMLNode::getAttributeS8(const char* name, S8& value )
{
LLXMLNodePtr node;
S32 val;
@@ -1308,7 +1290,7 @@ BOOL LLXMLNode::getAttributeS8(const char* name, S8& value )
return true;
}
-BOOL LLXMLNode::getAttributeU16(const char* name, U16& value )
+bool LLXMLNode::getAttributeU16(const char* name, U16& value )
{
LLXMLNodePtr node;
U32 val;
@@ -1320,7 +1302,7 @@ BOOL LLXMLNode::getAttributeU16(const char* name, U16& value )
return true;
}
-BOOL LLXMLNode::getAttributeS16(const char* name, S16& value )
+bool LLXMLNode::getAttributeS16(const char* name, S16& value )
{
LLXMLNodePtr node;
S32 val;
@@ -1332,73 +1314,73 @@ BOOL LLXMLNode::getAttributeS16(const char* name, S16& value )
return true;
}
-BOOL LLXMLNode::getAttributeU32(const char* name, U32& value )
+bool LLXMLNode::getAttributeU32(const char* name, U32& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getUnsignedValue(1, &value));
}
-BOOL LLXMLNode::getAttributeS32(const char* name, S32& value )
+bool LLXMLNode::getAttributeS32(const char* name, S32& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getIntValue(1, &value));
}
-BOOL LLXMLNode::getAttributeF32(const char* name, F32& value )
+bool LLXMLNode::getAttributeF32(const char* name, F32& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getFloatValue(1, &value));
}
-BOOL LLXMLNode::getAttributeF64(const char* name, F64& value )
+bool LLXMLNode::getAttributeF64(const char* name, F64& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getDoubleValue(1, &value));
}
-BOOL LLXMLNode::getAttributeColor(const char* name, LLColor4& value )
+bool LLXMLNode::getAttributeColor(const char* name, LLColor4& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getFloatValue(4, value.mV));
}
-BOOL LLXMLNode::getAttributeColor4(const char* name, LLColor4& value )
+bool LLXMLNode::getAttributeColor4(const char* name, LLColor4& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getFloatValue(4, value.mV));
}
-BOOL LLXMLNode::getAttributeColor4U(const char* name, LLColor4U& value )
+bool LLXMLNode::getAttributeColor4U(const char* name, LLColor4U& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getByteValue(4, value.mV));
}
-BOOL LLXMLNode::getAttributeVector3(const char* name, LLVector3& value )
+bool LLXMLNode::getAttributeVector3(const char* name, LLVector3& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getFloatValue(3, value.mV));
}
-BOOL LLXMLNode::getAttributeVector3d(const char* name, LLVector3d& value )
+bool LLXMLNode::getAttributeVector3d(const char* name, LLVector3d& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getDoubleValue(3, value.mdV));
}
-BOOL LLXMLNode::getAttributeQuat(const char* name, LLQuaternion& value )
+bool LLXMLNode::getAttributeQuat(const char* name, LLQuaternion& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getFloatValue(4, value.mQ));
}
-BOOL LLXMLNode::getAttributeUUID(const char* name, LLUUID& value )
+bool LLXMLNode::getAttributeUUID(const char* name, LLUUID& value )
{
LLXMLNodePtr node;
return (getAttribute(name, node) && node->getUUIDValue(1, &value));
}
-BOOL LLXMLNode::getAttributeString(const char* name, std::string& value )
+bool LLXMLNode::getAttributeString(const char* name, std::string& value )
{
LLXMLNodePtr node;
if (!getAttribute(name, node))
@@ -1435,10 +1417,10 @@ const char *LLXMLNode::skipNonWhitespace(const char *str)
}
/*static */
-const char *LLXMLNode::parseInteger(const char *str, U64 *dest, BOOL *is_negative, U32 precision, Encoding encoding)
+const char *LLXMLNode::parseInteger(const char *str, U64 *dest, bool *is_negative, U32 precision, Encoding encoding)
{
*dest = 0;
- *is_negative = FALSE;
+ *is_negative = false;
str = skipWhitespace(str);
@@ -1452,7 +1434,7 @@ const char *LLXMLNode::parseInteger(const char *str, U64 *dest, BOOL *is_negativ
}
if (str[0] == '-')
{
- *is_negative = TRUE;
+ *is_negative = true;
++str;
}
@@ -1653,7 +1635,7 @@ const char *LLXMLNode::parseFloat(const char *str, F64 *dest, U32 precision, Enc
// Scientific notation!
++str;
U64 exp;
- BOOL is_negative;
+ bool is_negative;
str = parseInteger(str, &exp, &is_negative, 64, ENCODING_DECIMAL);
if (str == NULL)
{
@@ -1677,7 +1659,7 @@ const char *LLXMLNode::parseFloat(const char *str, F64 *dest, U32 precision, Enc
if (encoding == ENCODING_HEX)
{
U64 bytes_dest;
- BOOL is_negative;
+ bool is_negative;
str = parseInteger(str, (U64 *)&bytes_dest, &is_negative, precision, ENCODING_HEX);
// Upcast to F64
switch (precision)
@@ -1700,7 +1682,7 @@ const char *LLXMLNode::parseFloat(const char *str, F64 *dest, U32 precision, Enc
return NULL;
}
-U32 LLXMLNode::getBoolValue(U32 expected_length, BOOL *array)
+U32 LLXMLNode::getBoolValue(U32 expected_length, bool *array)
{
llassert(array);
@@ -1720,11 +1702,11 @@ U32 LLXMLNode::getBoolValue(U32 expected_length, BOOL *array)
LLStringUtil::toLower(str_array[i]);
if (str_array[i] == "false")
{
- array[ret_length++] = FALSE;
+ array[ret_length++] = false;
}
else if (str_array[i] == "true")
{
- array[ret_length++] = TRUE;
+ array[ret_length++] = true;
}
}
@@ -1770,7 +1752,7 @@ U32 LLXMLNode::getByteValue(U32 expected_length, U8 *array, Encoding encoding)
for (i=0; i<expected_length; ++i)
{
U64 value;
- BOOL is_negative;
+ bool is_negative;
value_string = parseInteger(value_string, &value, &is_negative, 8, encoding);
if (value_string == NULL)
{
@@ -1822,7 +1804,7 @@ U32 LLXMLNode::getIntValue(U32 expected_length, S32 *array, Encoding encoding)
for (i=0; i<expected_length; ++i)
{
U64 value;
- BOOL is_negative;
+ bool is_negative;
value_string = parseInteger(value_string, &value, &is_negative, 32, encoding);
if (value_string == NULL)
{
@@ -1876,7 +1858,7 @@ U32 LLXMLNode::getUnsignedValue(U32 expected_length, U32 *array, Encoding encodi
for (i=0; i<expected_length; ++i)
{
U64 value;
- BOOL is_negative;
+ bool is_negative;
value_string = parseInteger(value_string, &value, &is_negative, 32, encoding);
if (value_string == NULL)
{
@@ -1930,7 +1912,7 @@ U32 LLXMLNode::getLongValue(U32 expected_length, U64 *array, Encoding encoding)
for (i=0; i<expected_length; ++i)
{
U64 value;
- BOOL is_negative;
+ bool is_negative;
value_string = parseInteger(value_string, &value, &is_negative, 64, encoding);
if (value_string == NULL)
{
@@ -2185,7 +2167,7 @@ U32 LLXMLNode::getNodeRefValue(U32 expected_length, LLXMLNode **array)
return num_returned_refs;
}
-void LLXMLNode::setBoolValue(U32 length, const BOOL *array)
+void LLXMLNode::setBoolValue(U32 length, const bool *array)
{
if (length == 0) return;
@@ -2614,7 +2596,7 @@ void LLXMLNode::findDefault(LLXMLNode *defaults_list)
mDefault = NULL;
}
-BOOL LLXMLNode::deleteChildren(const std::string& name)
+bool LLXMLNode::deleteChildren(const std::string& name)
{
U32 removed_count = 0;
LLXMLNodeList node_list;
@@ -2633,10 +2615,10 @@ BOOL LLXMLNode::deleteChildren(const std::string& name)
}
}
}
- return removed_count > 0 ? TRUE : FALSE;
+ return removed_count > 0;
}
-BOOL LLXMLNode::deleteChildren(LLStringTableEntry* name)
+bool LLXMLNode::deleteChildren(LLStringTableEntry* name)
{
U32 removed_count = 0;
LLXMLNodeList node_list;
@@ -2655,7 +2637,7 @@ BOOL LLXMLNode::deleteChildren(LLStringTableEntry* name)
}
}
}
- return removed_count > 0 ? TRUE : FALSE;
+ return removed_count > 0;
}
void LLXMLNode::setAttributes(LLXMLNode::ValueType type, U32 precision, LLXMLNode::Encoding encoding, U32 length)
@@ -2698,7 +2680,7 @@ U32 LLXMLNode::getChildCount() const
{
if (mChildren.notNull())
{
- return mChildren->map.size();
+ return static_cast<U32>(mChildren->map.size());
}
return 0;
}
@@ -2717,7 +2699,7 @@ LLXMLNode *get_rand_node(LLXMLNode *node)
{
if (node->mChildren.notNull())
{
- U32 num_children = node->mChildren->map.size();
+ U32 num_children = static_cast<U32>(node->mChildren->map.size());
if (get_rand(2) == 0)
{
while (true)
@@ -2778,7 +2760,7 @@ void LLXMLNode::createUnitTest(S32 max_num_children)
child_name.append(1, c);
}
- LLXMLNode *new_child = createChild(child_name.c_str(), FALSE);
+ LLXMLNode *new_child = createChild(child_name.c_str(), false);
// Random ID
std::string child_id;
@@ -2805,7 +2787,7 @@ void LLXMLNode::createUnitTest(S32 max_num_children)
break;
case 1: // TYPE_BOOLEAN
{
- BOOL random_bool_values[30];
+ bool random_bool_values[30];
for (U32 value=0; value<array_size; ++value)
{
random_bool_values[value] = get_rand(2);
@@ -2913,20 +2895,20 @@ void LLXMLNode::createUnitTest(S32 max_num_children)
}
}
- createChild("integer_checksum", TRUE)->setUnsignedValue(1, &integer_checksum, LLXMLNode::ENCODING_HEX);
- createChild("long_checksum", TRUE)->setLongValue(1, &long_checksum, LLXMLNode::ENCODING_HEX);
- createChild("bool_true_count", TRUE)->setUnsignedValue(1, &bool_true_count, LLXMLNode::ENCODING_HEX);
- createChild("uuid_checksum", TRUE)->setUUIDValue(1, &uuid_checksum);
- createChild("noderef_checksum", TRUE)->setUnsignedValue(1, &noderef_checksum, LLXMLNode::ENCODING_HEX);
- createChild("float_checksum", TRUE)->setUnsignedValue(1, &float_checksum, LLXMLNode::ENCODING_HEX);
+ createChild("integer_checksum", true)->setUnsignedValue(1, &integer_checksum, LLXMLNode::ENCODING_HEX);
+ createChild("long_checksum", true)->setLongValue(1, &long_checksum, LLXMLNode::ENCODING_HEX);
+ createChild("bool_true_count", true)->setUnsignedValue(1, &bool_true_count, LLXMLNode::ENCODING_HEX);
+ createChild("uuid_checksum", true)->setUUIDValue(1, &uuid_checksum);
+ createChild("noderef_checksum", true)->setUnsignedValue(1, &noderef_checksum, LLXMLNode::ENCODING_HEX);
+ createChild("float_checksum", true)->setUnsignedValue(1, &float_checksum, LLXMLNode::ENCODING_HEX);
}
-BOOL LLXMLNode::performUnitTest(std::string &error_buffer)
+bool LLXMLNode::performUnitTest(std::string &error_buffer)
{
if (mChildren.isNull())
{
error_buffer.append(llformat("ERROR Node %s: No children found.\n", mName->mString));
- return FALSE;
+ return false;
}
// Checksums
@@ -2950,14 +2932,14 @@ BOOL LLXMLNode::performUnitTest(std::string &error_buffer)
if (!node->performUnitTest(error_buffer))
{
error_buffer.append(llformat("Child test failed for %s.\n", mName->mString));
- //return FALSE;
+ //return false;
}
continue;
}
if (node->mLength < 1 || node->mLength > 30)
{
error_buffer.append(llformat("ERROR Node %s: Invalid array length %d, child %s.\n", mName->mString, node->mLength, node->mName->mString));
- return FALSE;
+ return false;
}
switch (node->mType)
{
@@ -2966,11 +2948,11 @@ BOOL LLXMLNode::performUnitTest(std::string &error_buffer)
break;
case TYPE_BOOLEAN:
{
- BOOL bool_array[30];
+ bool bool_array[30];
if (node->getBoolValue(node->mLength, bool_array) < node->mLength)
{
error_buffer.append(llformat("ERROR Node %s: Could not read boolean array, child %s.\n", mName->mString, node->mName->mString));
- return FALSE;
+ return false;
}
for (U32 pos=0; pos<(U32)node->mLength; ++pos)
{
@@ -2989,7 +2971,7 @@ BOOL LLXMLNode::performUnitTest(std::string &error_buffer)
if (node->getUnsignedValue(node->mLength, integer_array, node->mEncoding) < node->mLength)
{
error_buffer.append(llformat("ERROR Node %s: Could not read integer array, child %s.\n", mName->mString, node->mName->mString));
- return FALSE;
+ return false;
}
for (U32 pos=0; pos<(U32)node->mLength; ++pos)
{
@@ -3002,7 +2984,7 @@ BOOL LLXMLNode::performUnitTest(std::string &error_buffer)
if (node->getLongValue(node->mLength, integer_array, node->mEncoding) < node->mLength)
{
error_buffer.append(llformat("ERROR Node %s: Could not read long integer array, child %s.\n", mName->mString, node->mName->mString));
- return FALSE;
+ return false;
}
for (U32 pos=0; pos<(U32)node->mLength; ++pos)
{
@@ -3019,7 +3001,7 @@ BOOL LLXMLNode::performUnitTest(std::string &error_buffer)
if (node->getFloatValue(node->mLength, float_array, node->mEncoding) < node->mLength)
{
error_buffer.append(llformat("ERROR Node %s: Could not read float array, child %s.\n", mName->mString, node->mName->mString));
- return FALSE;
+ return false;
}
for (U32 pos=0; pos<(U32)node->mLength; ++pos)
{
@@ -3033,7 +3015,7 @@ BOOL LLXMLNode::performUnitTest(std::string &error_buffer)
if (node->getDoubleValue(node->mLength, float_array, node->mEncoding) < node->mLength)
{
error_buffer.append(llformat("ERROR Node %s: Could not read float array, child %s.\n", mName->mString, node->mName->mString));
- return FALSE;
+ return false;
}
for (U32 pos=0; pos<(U32)node->mLength; ++pos)
{
@@ -3051,7 +3033,7 @@ BOOL LLXMLNode::performUnitTest(std::string &error_buffer)
if (node->getUUIDValue(node->mLength, uuid_array) < node->mLength)
{
error_buffer.append(llformat("ERROR Node %s: Could not read uuid array, child %s.\n", mName->mString, node->mName->mString));
- return FALSE;
+ return false;
}
for (U32 pos=0; pos<(U32)node->mLength; ++pos)
{
@@ -3068,7 +3050,7 @@ BOOL LLXMLNode::performUnitTest(std::string &error_buffer)
if (node->getNodeRefValue(node->mLength, node_array) < node->mLength)
{
error_buffer.append(llformat("ERROR Node %s: Could not read node ref array, child %s.\n", mName->mString, node->mName->mString));
- return FALSE;
+ return false;
}
for (U32 pos=0; pos<node->mLength; ++pos)
{
@@ -3089,97 +3071,97 @@ BOOL LLXMLNode::performUnitTest(std::string &error_buffer)
// Compare checksums
{
U32 node_integer_checksum = 0;
- if (!getAttribute("integer_checksum", checksum_node, FALSE) ||
+ if (!getAttribute("integer_checksum", checksum_node, false) ||
checksum_node->getUnsignedValue(1, &node_integer_checksum, ENCODING_HEX) != 1)
{
error_buffer.append(llformat("ERROR Node %s: Integer checksum missing.\n", mName->mString));
- return FALSE;
+ return false;
}
if (node_integer_checksum != integer_checksum)
{
error_buffer.append(llformat("ERROR Node %s: Integer checksum mismatch: read %X / calc %X.\n", mName->mString, node_integer_checksum, integer_checksum));
- return FALSE;
+ return false;
}
}
{
U64 node_long_checksum = 0;
- if (!getAttribute("long_checksum", checksum_node, FALSE) ||
+ if (!getAttribute("long_checksum", checksum_node, false) ||
checksum_node->getLongValue(1, &node_long_checksum, ENCODING_HEX) != 1)
{
error_buffer.append(llformat("ERROR Node %s: Long Integer checksum missing.\n", mName->mString));
- return FALSE;
+ return false;
}
if (node_long_checksum != long_checksum)
{
U32 *pp1 = (U32 *)&node_long_checksum;
U32 *pp2 = (U32 *)&long_checksum;
error_buffer.append(llformat("ERROR Node %s: Long Integer checksum mismatch: read %08X%08X / calc %08X%08X.\n", mName->mString, pp1[1], pp1[0], pp2[1], pp2[0]));
- return FALSE;
+ return false;
}
}
{
U32 node_bool_true_count = 0;
- if (!getAttribute("bool_true_count", checksum_node, FALSE) ||
+ if (!getAttribute("bool_true_count", checksum_node, false) ||
checksum_node->getUnsignedValue(1, &node_bool_true_count, ENCODING_HEX) != 1)
{
error_buffer.append(llformat("ERROR Node %s: Boolean checksum missing.\n", mName->mString));
- return FALSE;
+ return false;
}
if (node_bool_true_count != bool_true_count)
{
error_buffer.append(llformat("ERROR Node %s: Boolean checksum mismatch: read %X / calc %X.\n", mName->mString, node_bool_true_count, bool_true_count));
- return FALSE;
+ return false;
}
}
{
LLUUID node_uuid_checksum;
- if (!getAttribute("uuid_checksum", checksum_node, FALSE) ||
+ if (!getAttribute("uuid_checksum", checksum_node, false) ||
checksum_node->getUUIDValue(1, &node_uuid_checksum) != 1)
{
error_buffer.append(llformat("ERROR Node %s: UUID checksum missing.\n", mName->mString));
- return FALSE;
+ return false;
}
if (node_uuid_checksum != uuid_checksum)
{
error_buffer.append(llformat("ERROR Node %s: UUID checksum mismatch: read %s / calc %s.\n", mName->mString, node_uuid_checksum.asString().c_str(), uuid_checksum.asString().c_str()));
- return FALSE;
+ return false;
}
}
{
U32 node_noderef_checksum = 0;
- if (!getAttribute("noderef_checksum", checksum_node, FALSE) ||
+ if (!getAttribute("noderef_checksum", checksum_node, false) ||
checksum_node->getUnsignedValue(1, &node_noderef_checksum, ENCODING_HEX) != 1)
{
error_buffer.append(llformat("ERROR Node %s: Node Ref checksum missing.\n", mName->mString));
- return FALSE;
+ return false;
}
if (node_noderef_checksum != noderef_checksum)
{
error_buffer.append(llformat("ERROR Node %s: Node Ref checksum mismatch: read %X / calc %X.\n", mName->mString, node_noderef_checksum, noderef_checksum));
- return FALSE;
+ return false;
}
}
{
U32 node_float_checksum = 0;
- if (!getAttribute("float_checksum", checksum_node, FALSE) ||
+ if (!getAttribute("float_checksum", checksum_node, false) ||
checksum_node->getUnsignedValue(1, &node_float_checksum, ENCODING_HEX) != 1)
{
error_buffer.append(llformat("ERROR Node %s: Float checksum missing.\n", mName->mString));
- return FALSE;
+ return false;
}
if (node_float_checksum != float_checksum)
{
error_buffer.append(llformat("ERROR Node %s: Float checksum mismatch: read %X / calc %X.\n", mName->mString, node_float_checksum, float_checksum));
- return FALSE;
+ return false;
}
}
- return TRUE;
+ return true;
}
LLXMLNodePtr LLXMLNode::getFirstChild() const
@@ -3283,3 +3265,171 @@ S32 LLXMLNode::getLineNumber()
{
return mLineNumber;
}
+
+bool LLXMLNode::parseXmlRpcArrayValue(LLSD& target)
+{
+ LLXMLNode* datap = getFirstChild().get();
+ if (!datap)
+ {
+ LL_WARNS() << "No inner XML element." << LL_ENDL;
+ return false;
+ }
+ if (!datap->hasName("data"))
+ {
+ LL_WARNS() << "No inner XML element (<data> expected, got: "
+ << datap->mName->mString << ")" << LL_ENDL;
+ return false;
+ }
+ if (datap->getNextSibling().get())
+ {
+ LL_WARNS() << "Multiple inner XML elements (single <data> expected)"
+ << LL_ENDL;
+ return false;
+ }
+ for (LLXMLNode* itemp = datap->getFirstChild().get(); itemp;
+ itemp = itemp->getNextSibling().get())
+ {
+ LLSD value;
+ if (!itemp->fromXMLRPCValue(value))
+ {
+ return false;
+ }
+ target.append(value);
+ }
+ return true;
+}
+
+bool LLXMLNode::parseXmlRpcStructValue(LLSD& target)
+{
+ std::string name;
+ LLSD value;
+ for (LLXMLNode* itemp = getFirstChild().get(); itemp;
+ itemp = itemp->getNextSibling().get())
+ {
+ if (!itemp->hasName("member"))
+ {
+ LL_WARNS() << "Invalid inner XML element (<member> expected, got: <"
+ << itemp->mName->mString << ">" << LL_ENDL;
+ return false;
+ }
+ name.clear();
+ value.clear();
+ for (LLXMLNode* chilp = itemp->getFirstChild().get(); chilp;
+ chilp = chilp->getNextSibling().get())
+ {
+ if (chilp->hasName("name"))
+ {
+ name = LLStringFn::xml_decode(chilp->getTextContents());
+ }
+ else if (!chilp->fromXMLRPCValue(value))
+ {
+ return false;
+ }
+ }
+ if (name.empty())
+ {
+ LL_WARNS() << "Empty struct member name" << LL_ENDL;
+ return false;
+ }
+ target.insert(name, value);
+ }
+ return true;
+}
+
+bool LLXMLNode::fromXMLRPCValue(LLSD& target)
+{
+ target.clear();
+
+ if (!hasName("value"))
+ {
+ LL_WARNS() << "Invalid XML element (<value> expected), got: <"
+ << mName->mString << ">" << LL_ENDL;
+ return false;
+ }
+
+ LLXMLNode* childp = getFirstChild().get();
+ if (!childp)
+ {
+ LL_WARNS() << "No inner XML element (value type expected)" << LL_ENDL;
+ // Value with no type qualifier is treated as string
+ target.assign(LLStringFn::xml_decode(getTextContents()));
+ return true;
+ }
+
+ if (childp->getNextSibling())
+ {
+ LL_WARNS() << "Multiple inner XML elements (single expected)"
+ << LL_ENDL;
+ return false;
+ }
+
+ if (childp->hasName("string"))
+ {
+ target.assign(LLStringFn::xml_decode(childp->getTextContents()));
+ return true;
+ }
+
+ if (childp->hasName("int") || childp->hasName("i4"))
+ {
+ target.assign(std::stoi(childp->getTextContents()));
+ return true;
+ }
+
+ if (childp->hasName("double"))
+ {
+ target.assign(std::stod(childp->getTextContents()));
+ return true;
+ }
+
+ if (childp->hasName("boolean"))
+ {
+ target.assign(std::stoi(childp->getTextContents()) != 0);
+ return true;
+ }
+
+ if (childp->hasName("dateTime.iso8601"))
+ {
+ target.assign(LLSD::Date(childp->getTextContents()));
+ return true;
+ }
+
+ if (childp->hasName("base64"))
+ {
+ std::string decoded =
+ LLBase64::decodeAsString(childp->getTextContents());
+ size_t size = decoded.size();
+ LLSD::Binary binary(size);
+ if (size)
+ {
+ memcpy((void*)binary.data(), (void*)decoded.data(), size);
+ }
+ target.assign(binary);
+ return true;
+ }
+
+ if (childp->hasName("array"))
+ {
+ if (!childp->parseXmlRpcArrayValue(target))
+ {
+ target.clear();
+ return false;
+ }
+ return true;
+ }
+
+ if (childp->hasName("struct"))
+ {
+ if (!childp->parseXmlRpcStructValue(target))
+ {
+ target.clear();
+ return false;
+ }
+ return true;
+ }
+
+ LL_WARNS() << "Unknown inner XML element (known value type expected)"
+ << LL_ENDL;
+ // Value with unknown type qualifier is treated as string
+ target.assign(LLStringFn::xml_decode(childp->getTextContents()));
+ return true;
+}