Example #1
0
S32 getElementSize(const LLSD& llsd)
{
	LLSD::Type type = llsd.type();
	switch(type)
	{
	case LLSD::TypeBoolean:
		return sizeof(bool);
	case LLSD::TypeInteger:
		return sizeof(S32);
	case LLSD::TypeReal:
		return sizeof(F64);
	case LLSD::TypeString:
		return llsd.asString().size();
	case LLSD::TypeUUID:
		return sizeof(LLUUID);
	case LLSD::TypeDate:
		return sizeof(LLDate);
	case LLSD::TypeURI:
		return sizeof(LLURI);
	case LLSD::TypeBinary:
	{
		std::vector<U8> data = llsd;
		return data.size() * sizeof(U8);
	}
	case LLSD::TypeMap:
	case LLSD::TypeArray:
	case LLSD::TypeUndefined:
		return 0;
	}
	return 0;
}
Example #2
0
void sd_object::test<15>()
{
    std::string val = "[{'failures':!,'successfuls':[u3c115e51-04f4-523c-9fa6-98aff1034730]}]";
    std::istringstream istr;
    istr.str(val);
    LLSD sd;
    LLSDSerialize::fromNotation(sd, istr, val.size());
    ensure_equals("parsed type", sd.type(), LLSD::TypeArray);
    ensure_equals("parsed size", sd.size(), 1);
    LLSD failures = sd[0]["failures"];
    ensure("no failures.", failures.isUndefined());
    LLSD success = sd[0]["successfuls"];
    ensure_equals("success type", success.type(), LLSD::TypeArray);
    ensure_equals("success size", success.size(), 1);
    ensure_equals("success instance type", success[0].type(), LLSD::TypeUUID);
}
Example #3
0
void sd_object::test<9>()
{
    std::ostringstream resp;
    resp << "{'label':'short binary test', 'singlebinary':b(1)\"A\", 'singlerawstring':s(1)\"A\", 'endoftest':'end' }";
    std::string str = resp.str();
    LLSD sd;
    LLMemoryStream mstr((U8*)str.c_str(), str.size());
    S32 count = LLSDSerialize::fromNotation(sd, mstr, str.size());
    ensure_equals("parse count", count, 5);
    ensure("sd created", sd.isDefined());
    ensure_equals("sd type", sd.type(), LLSD::TypeMap);
    ensure_equals("map element count", sd.size(), 4);
    ensure_equals(
        "label",
        sd["label"].asString(),
        "short binary test");
    std::vector<U8> bin =  sd["singlebinary"].asBinary();
    std::vector<U8> expected;
    expected.resize(1);
    expected[0] = 'A';
    ensure("single binary", (0 == memcmp(&bin[0], &expected[0], 1)));
    ensure_equals(
        "single string",
        sd["singlerawstring"].asString(),
        std::string("A"));
    ensure_equals("end", sd["endoftest"].asString(), "end");
}
Example #4
0
bool LLApp::setOptionData(OptionPriority level, LLSD data)
{
	if((level < 0)
	   || (level >= PRIORITY_COUNT)
	   || (data.type() != LLSD::TypeMap))
	{
		return false;
	}
	mOptions[level] = data;
	return true;
}
Example #5
0
void sd_object::test<16>()
{
    std::string val = "[f,t,0,1,{'foo':t,'bar':f}]";
    std::istringstream istr;
    istr.str(val);
    LLSD sd;
    LLSDSerialize::fromNotation(sd, istr, val.size());
    ensure_equals("parsed type", sd.type(), LLSD::TypeArray);
    ensure_equals("parsed size", sd.size(), 5);
    ensure_equals("element 0 false", sd[0].asBoolean(), false);
    ensure_equals("element 1 true", sd[1].asBoolean(), true);
    ensure_equals("element 2 false", sd[2].asBoolean(), false);
    ensure_equals("element 3 true", sd[3].asBoolean(), true);
    LLSD map = sd[4];
    ensure_equals("element 4 type", map.type(), LLSD::TypeMap);
    ensure_equals("map foo type", map["foo"].type(), LLSD::TypeBoolean);
    ensure_equals("map foo value", map["foo"].asBoolean(), true);
    ensure_equals("map bar type", map["bar"].type(), LLSD::TypeBoolean);
    ensure_equals("map bar value", map["bar"].asBoolean(), false);
}
Example #6
0
void sd_object::test<8>()
{
    std::stringstream resp;
    resp << "{'label':'short string test', 'singlechar':'a', 'empty':'', 'endoftest':'end' }";
    LLSD response;
    S32 count = LLSDSerialize::fromNotation(
                    response,
                    resp,
                    resp.str().size());
    ensure_equals("parse count", count, 5);
    ensure_equals("sd type", response.type(), LLSD::TypeMap);
    ensure_equals("map element count", response.size(), 4);
    ensure_equals("singlechar", response["singlechar"].asString(), "a");
    ensure_equals("empty", response["empty"].asString(), "");
}
Example #7
0
void sd_object::test<1>()
{
    std::ostringstream resp;
    resp << "{'connect':true,  'position':[r128,r128,r128], 'look_at':[r0,r1,r0], 'agent_access':'M', 'region_x':i8192, 'region_y':i8192}";
    std::string str = resp.str();
    LLMemoryStream mstr((U8*)str.c_str(), str.size());
    LLSD response;
    S32 count = LLSDSerialize::fromNotation(response, mstr, str.size());
    ensure("stream parsed", response.isDefined());
    ensure_equals("stream parse count", count, 13);
    ensure_equals("sd type", response.type(), LLSD::TypeMap);
    ensure_equals("map element count", response.size(), 6);
    ensure_equals("value connect", response["connect"].asBoolean(), true);
    ensure_equals("value region_x", response["region_x"].asInteger(),8192);
    ensure_equals("value region_y", response["region_y"].asInteger(),8192);
}
Example #8
0
// static
LLURI LLURI::buildHTTP(const std::string& prefix,
					   const LLSD& path)
{
	LLURI result;
	
	// TODO: deal with '/' '?' '#' in host_port
	if (prefix.find("://") != prefix.npos)
	{
		// it is a prefix
		result = LLURI(prefix);
	}
	else
	{
		// it is just a host and optional port
		result.mScheme = "http";
		result.mEscapedAuthority = escapeHostAndPort(prefix);
	}

	if (path.isArray())
	{
		// break out and escape each path component
		for (LLSD::array_const_iterator it = path.beginArray();
			 it != path.endArray();
			 ++it)
		{
			lldebugs << "PATH: inserting " << it->asString() << llendl;
			result.mEscapedPath += "/" + escapePathComponent(it->asString());
		}
	}
	else if(path.isString())
	{
		result.mEscapedPath += "/" + escapePathComponent(path.asString());
	} 
	else if(path.isUndefined())
	{
	  // do nothing
	}
    else
	{
	  llwarns << "Valid path arguments to buildHTTP are array, string, or undef, you passed type" 
			  << path.type() << llendl;
	}
	result.mEscapedOpaque = "//" + result.mEscapedAuthority +
		result.mEscapedPath;
	return result;
}
Example #9
0
void LLFilterSD2XMLRPC::streamOut(std::ostream& ostr, const LLSD& sd)
{
    ostr << "<value>";
    switch(sd.type())
    {
    case LLSD::TypeMap:
    {
#if LL_SPEW_STREAM_OUT_DEBUGGING
        llinfos << "streamOut(map) BEGIN" << llendl;
#endif
        ostr << "<struct>";
        if(ostr.fail())
        {
            llinfos << "STREAM FAILURE writing struct" << llendl;
        }
        LLSD::map_const_iterator it = sd.beginMap();
        LLSD::map_const_iterator end = sd.endMap();
        for(; it != end; ++it)
        {
            ostr << "<member><name>" << xml_escape_string((*it).first)
                 << "</name>";
            streamOut(ostr, (*it).second);
            if(ostr.fail())
            {
                llinfos << "STREAM FAILURE writing '" << (*it).first
                        << "' with sd type " << (*it).second.type() << llendl;
            }
            ostr << "</member>";
        }
        ostr << "</struct>";
#if LL_SPEW_STREAM_OUT_DEBUGGING
        llinfos << "streamOut(map) END" << llendl;
#endif
        break;
    }
    case LLSD::TypeArray:
    {
#if LL_SPEW_STREAM_OUT_DEBUGGING
        llinfos << "streamOut(array) BEGIN" << llendl;
#endif
        ostr << "<array><data>";
        LLSD::array_const_iterator it = sd.beginArray();
        LLSD::array_const_iterator end = sd.endArray();
        for(; it != end; ++it)
        {
            streamOut(ostr, *it);
            if(ostr.fail())
            {
                llinfos << "STREAM FAILURE writing array element sd type "
                        << (*it).type() << llendl;
            }
        }
#if LL_SPEW_STREAM_OUT_DEBUGGING
        llinfos << "streamOut(array) END" << llendl;
#endif
        ostr << "</data></array>";
        break;
    }
    case LLSD::TypeUndefined:
    // treat undefined as a bool with a false value.
    case LLSD::TypeBoolean:
#if LL_SPEW_STREAM_OUT_DEBUGGING
        llinfos << "streamOut(bool)" << llendl;
#endif
        ostr << "<boolean>" << (sd.asBoolean() ? "1" : "0") << "</boolean>";
        break;
    case LLSD::TypeInteger:
#if LL_SPEW_STREAM_OUT_DEBUGGING
        llinfos << "streamOut(int)" << llendl;
#endif
        ostr << "<i4>" << sd.asInteger() << "</i4>";
        break;
    case LLSD::TypeReal:
#if LL_SPEW_STREAM_OUT_DEBUGGING
        llinfos << "streamOut(real)" << llendl;
#endif
        ostr << "<double>" << sd.asReal() << "</double>";
        break;
    case LLSD::TypeString:
#if LL_SPEW_STREAM_OUT_DEBUGGING
        llinfos << "streamOut(string)" << llendl;
#endif
        ostr << "<string>" << xml_escape_string(sd.asString()) << "</string>";
        break;
    case LLSD::TypeUUID:
#if LL_SPEW_STREAM_OUT_DEBUGGING
        llinfos << "streamOut(uuid)" << llendl;
#endif
        // serialize it as a string
        ostr << "<string>" << sd.asString() << "</string>";
        break;
    case LLSD::TypeURI:
    {
#if LL_SPEW_STREAM_OUT_DEBUGGING
        llinfos << "streamOut(uri)" << llendl;
#endif
        // serialize it as a string
        ostr << "<string>" << xml_escape_string(sd.asString()) << "</string>";
        break;
    }
    case LLSD::TypeBinary:
    {
#if LL_SPEW_STREAM_OUT_DEBUGGING
        llinfos << "streamOut(binary)" << llendl;
#endif
        // this is pretty inefficient, but we'll deal with that
        // problem when it becomes one.
        ostr << "<base64>";
        LLSD::Binary buffer = sd.asBinary();
        if(!buffer.empty())
        {
            // *TODO: convert to LLBase64
            int b64_buffer_length = apr_base64_encode_len(buffer.size());
            char* b64_buffer = new char[b64_buffer_length];
            b64_buffer_length = apr_base64_encode_binary(
                                    b64_buffer,
                                    &buffer[0],
                                    buffer.size());
            ostr.write(b64_buffer, b64_buffer_length - 1);
            delete[] b64_buffer;
        }
        ostr << "</base64>";
        break;
    }
    case LLSD::TypeDate:
#if LL_SPEW_STREAM_OUT_DEBUGGING
        llinfos << "streamOut(date)" << llendl;
#endif
        // no need to escape this since it will be alpha-numeric.
        ostr << "<dateTime.iso8601>" << sd.asString() << "</dateTime.iso8601>";
        break;
    default:
        // unhandled type
        llwarns << "Unhandled structured data type: " << sd.type()
                << llendl;
        break;
    }
    ostr << "</value>";
}
S32 LLSDXMLFormatter::format_impl(const LLSD& data, std::ostream& ostr, U32 options, U32 level) const
{
	S32 format_count = 1;
	std::string pre;
	std::string post;

	if (options & LLSDFormatter::OPTIONS_PRETTY)
	{
		for (U32 i = 0; i < level; i++)
		{
			pre += "    ";
		}
		post = "\n";
	}

	switch(data.type())
	{
	case LLSD::TypeMap:
		if(0 == data.size())
		{
			ostr << pre << "<map />" << post;
		}
		else
		{
			ostr << pre << "<map>" << post;
			LLSD::map_const_iterator iter = data.beginMap();
			LLSD::map_const_iterator end = data.endMap();
			for(; iter != end; ++iter)
			{
				ostr << pre << "<key>" << escapeString((*iter).first) << "</key>" << post;
				format_count += format_impl((*iter).second, ostr, options, level + 1);
			}
			ostr << pre <<  "</map>" << post;
		}
		break;

	case LLSD::TypeArray:
		if(0 == data.size())
		{
			ostr << pre << "<array />" << post;
		}
		else
		{
			ostr << pre << "<array>" << post;
			LLSD::array_const_iterator iter = data.beginArray();
			LLSD::array_const_iterator end = data.endArray();
			for(; iter != end; ++iter)
			{
				format_count += format_impl(*iter, ostr, options, level + 1);
			}
			ostr << pre << "</array>" << post;
		}
		break;

	case LLSD::TypeUndefined:
		ostr << pre << "<undef />" << post;
		break;

	case LLSD::TypeBoolean:
		ostr << pre << "<boolean>";
		if(mBoolAlpha ||
#if( LL_WINDOWS || __GNUC__ > 2)
		   (ostr.flags() & std::ios::boolalpha)
#else
		   (ostr.flags() & 0x0100)
#endif
			)
		{
			ostr << (data.asBoolean() ? "true" : "false");
		}
		else
		{
			ostr << (data.asBoolean() ? 1 : 0);
		}
		ostr << "</boolean>" << post;
		break;

	case LLSD::TypeInteger:
		ostr << pre << "<integer>" << data.asInteger() << "</integer>" << post;
		break;

	case LLSD::TypeReal:
		ostr << pre << "<real>";
		if(mRealFormat.empty())
		{
			ostr << data.asReal();
		}
		else
		{
			formatReal(data.asReal(), ostr);
		}
		ostr << "</real>" << post;
		break;

	case LLSD::TypeUUID:
		if(data.asUUID().isNull()) ostr << pre << "<uuid />" << post;
		else ostr << pre << "<uuid>" << data.asUUID() << "</uuid>" << post;
		break;

	case LLSD::TypeString:
		if(data.asString().empty()) ostr << pre << "<string />" << post;
		else ostr << pre << "<string>" << escapeString(data.asString()) <<"</string>" << post;
		break;

	case LLSD::TypeDate:
		ostr << pre << "<date>" << data.asDate() << "</date>" << post;
		break;

	case LLSD::TypeURI:
		ostr << pre << "<uri>" << escapeString(data.asString()) << "</uri>" << post;
		break;

	case LLSD::TypeBinary:
	{
		LLSD::Binary buffer = data.asBinary();
		if(buffer.empty())
		{
			ostr << pre << "<binary />" << post;
		}
		else
		{
			// *FIX: memory inefficient.
			// *TODO: convert to use LLBase64
			ostr << pre << "<binary encoding=\"base64\">";
			int b64_buffer_length = apr_base64_encode_len(buffer.size());
			char* b64_buffer = new char[b64_buffer_length];
			b64_buffer_length = apr_base64_encode_binary(
				b64_buffer,
				&buffer[0],
				buffer.size());
			ostr.write(b64_buffer, b64_buffer_length - 1);
			delete[] b64_buffer;
			ostr << "</binary>" << post;
		}
		break;
	}
	default:
		// *NOTE: This should never happen.
		ostr << pre << "<undef />" << post;
		break;
	}
	return format_count;
}