Esempio n. 1
0
	// Set the value from xml. The chars at *offset into valueXml
	// should be the start of a <value> tag. Destroys any existing value.
	bool XmlRpcValue::fromXml(std::string const& valueXml, int* offset)
	{
		int savedOffset = *offset;

		invalidate();
		if ( ! XmlRpcUtil::nextTagIs(VALUE_TAG, valueXml, offset))
			return false;		 // Not a value, offset not updated

		int afterValueOffset = *offset;
		std::string typeTag = XmlRpcUtil::getNextTag(valueXml, offset);
		bool result = false;
		if (typeTag == BOOLEAN_TAG)
			result = boolFromXml(valueXml, offset);
		else if (typeTag == I4_TAG || typeTag == INT_TAG)
			result = intFromXml(valueXml, offset);
		else if (typeTag == DOUBLE_TAG)
			result = doubleFromXml(valueXml, offset);
		else if (typeTag.empty() || typeTag == STRING_TAG)
			result = stringFromXml(valueXml, offset);
		else if (typeTag == DATETIME_TAG)
			result = timeFromXml(valueXml, offset);
		else if (typeTag == BASE64_TAG)
			result = binaryFromXml(valueXml, offset);
		else if (typeTag == ARRAY_TAG)
			result = arrayFromXml(valueXml, offset);
		else if (typeTag == STRUCT_TAG)
			result = structFromXml(valueXml, offset);
		// Watch for empty/blank strings with no <string>tag
		else if (typeTag == VALUE_ETAG)
		{
								 // back up & try again
			*offset = afterValueOffset;
			result = stringFromXml(valueXml, offset);
		}

		if (result)				 // Skip over the </value> tag
			XmlRpcUtil::findTag(VALUE_ETAG, valueXml, offset);
		else					 // Unrecognized tag after <value>
			*offset = savedOffset;

		return result;
	}
Esempio n. 2
0
  // Set the value from xml. The chars at *offset into valueXml 
  // should be the start of a <value> tag. Destroys any existing value.
  bool XmlRpcValue::fromXml(std::string const& valueXml, int* offset)
  {
    int savedOffset = *offset;

    invalidate();
    bool emptyTag;
    if ( ! XmlRpcUtil::nextTagIs(VALUE_TAG, valueXml, offset, &emptyTag))
      return false;       // Not a value, offset not updated

    // No value? Pretend its an empty string...
    if (emptyTag)
    {
      *this = "";
      return true;
    }

    // No type tag? Assume string
    bool result = true;
    int valueOffset = *offset;
    if (XmlRpcUtil::nextTagIsEnd(VALUE_TAG, valueXml, offset))
    {
      return stringFromXml(valueXml, &valueOffset);
    }
    else if (XmlRpcUtil::nextTagIs(NIL_TAG, valueXml, offset, &emptyTag))
    {
      _type = TypeNil;
      result = true;
    }
    else if (XmlRpcUtil::nextTagIs(BOOLEAN_TAG, valueXml, offset, &emptyTag))
    {
      if (emptyTag)
        *this = false;
      else
        result = boolFromXml(valueXml, offset) && 
                 XmlRpcUtil::nextTagIsEnd(BOOLEAN_TAG, valueXml, offset);
    }
    else if (XmlRpcUtil::nextTagIs(I4_TAG, valueXml, offset, &emptyTag))
    {
      if (emptyTag)
        *this = 0;
      else
        result = intFromXml(valueXml, offset) && 
                 XmlRpcUtil::nextTagIsEnd(I4_TAG, valueXml, offset);
    }
    else if (XmlRpcUtil::nextTagIs(INT_TAG, valueXml, offset, &emptyTag))
    {
      if (emptyTag)
        *this = 0;
      else
        result = intFromXml(valueXml, offset) && 
                 XmlRpcUtil::nextTagIsEnd(INT_TAG, valueXml, offset);
    }
    else if (XmlRpcUtil::nextTagIs(DOUBLE_TAG, valueXml, offset, &emptyTag))
    {
      if (emptyTag)
        *this = 0.0;
      else
        result = doubleFromXml(valueXml, offset) && 
                 XmlRpcUtil::nextTagIsEnd(DOUBLE_TAG, valueXml, offset);
    }
    else if (XmlRpcUtil::nextTagIs(STRING_TAG, valueXml, offset, &emptyTag))
    {
      if (emptyTag)
        *this = "";
      else
        result = stringFromXml(valueXml, offset) && 
                 XmlRpcUtil::nextTagIsEnd(STRING_TAG, valueXml, offset);
    }
    else if (XmlRpcUtil::nextTagIs(DATETIME_TAG, valueXml, offset, &emptyTag))
    {
      if (emptyTag)
        result = false;
      else
        result = timeFromXml(valueXml, offset) && 
                 XmlRpcUtil::nextTagIsEnd(DATETIME_TAG, valueXml, offset);
    }
    else if (XmlRpcUtil::nextTagIs(BASE64_TAG, valueXml, offset, &emptyTag))
    {
      if (emptyTag)
        result = binaryFromXml("", 0);
      else
        result = binaryFromXml(valueXml, offset) && 
                 XmlRpcUtil::nextTagIsEnd(BASE64_TAG, valueXml, offset);
    }
    else if (XmlRpcUtil::nextTagIs(ARRAY_TAG, valueXml, offset, &emptyTag))
    {
      if (emptyTag)
        result = false;
      else
        result = arrayFromXml(valueXml, offset) && 
                 XmlRpcUtil::nextTagIsEnd(ARRAY_TAG, valueXml, offset);
    }
    else if (XmlRpcUtil::nextTagIs(STRUCT_TAG, valueXml, offset, &emptyTag))
    {
      if (emptyTag)
        result = false;
      else
        result = structFromXml(valueXml, offset) && 
                 XmlRpcUtil::nextTagIsEnd(STRUCT_TAG, valueXml, offset);
    }

    // Unrecognized tag after <value> or no </value>
    if ( ! result || ! XmlRpcUtil::nextTagIsEnd(VALUE_TAG, valueXml, offset))
    {
      *offset = savedOffset;
      return false;
    }

    return true;
  }