void SDTestObject::test<14>()
		// make sure that assignment of char* NULL in a string does not crash.
	{
		LLSD v;
		v = (const char*)NULL;
		ensure("type is a string", v.isString());
	}
Esempio n. 2
0
// virtual
// value might be a string or a UUID
void LLIconCtrl::setValue(const LLSD& value )
{
	LLSD tvalue(value);
	if (value.isString() && LLUUID::validate(value.asString()))
	{
		//RN: support UUIDs masquerading as strings
		tvalue = LLSD(LLUUID(value.asString()));
	}
	LLUICtrl::setValue(tvalue);
	if (tvalue.isUUID())
	{
		mImagep = LLUI::getUIImageByID(tvalue.asUUID(), mPriority);
	}
	else
	{
		mImagep = LLUI::getUIImage(tvalue.asString(), mPriority);
	}

	if (mImagep.notNull()
		&& mImagep->getImage().notNull()
		&& mMinWidth
		&& mMinHeight)
	{
		mImagep->getImage()->setKnownDrawSize(llmax(mMinWidth, mImagep->getWidth()), llmax(mMinHeight, mImagep->getHeight()));
	}
}
Esempio n. 3
0
LLSD LLControlVariable::getComparableValue(const LLSD& value)
{
    // *FIX:MEP - The following is needed to make the LLSD::ImplString
    // work with boolean controls...
    LLSD storable_value;
    if(TYPE_BOOLEAN == type() && value.isString())
    {
        BOOL temp;
        if(LLStringUtil::convertToBOOL(value.asString(), temp))
        {
            storable_value = (bool)temp;
        }
        else
        {
            storable_value = false;
        }
    }
    else if (TYPE_LLSD == type() && value.isString())
    {
        LLPointer<LLSDNotationParser> parser = new LLSDNotationParser;
        LLSD result;
        std::stringstream value_stream(value.asString());
        if (parser->parse(value_stream, result, LLSDSerialize::SIZE_UNLIMITED) != LLSDParser::PARSE_FAILURE)
        {
            storable_value = result;
        }
        else
        {
            storable_value = value;
        }
    }
    else
    {
        storable_value = value;
    }

    return storable_value;
}
bool LLFloaterAutoReplaceSettings::selectedListIsFirst()
{
	bool isFirst = false;
	
	if (!mSelectedListName.empty())
	{
		LLSD lists = mSettings.getListNames(); // an Array of Strings
		LLSD first = lists.get(0);
		if ( first.isString() && first.asString() == mSelectedListName )
		{
			isFirst = true;
		}
	}
	return isFirst;
}
Esempio n. 5
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;
}
Esempio n. 6
0
// virtual
// value might be a string or a UUID
void LLIconCtrl::setValue(const LLSD& value )
{
	LLSD tvalue(value);
	if (value.isString() && LLUUID::validate(value.asString()))
	{
		//RN: support UUIDs masquerading as strings
		tvalue = LLSD(LLUUID(value.asString()));
	}
	LLUICtrl::setValue(tvalue);
	if (tvalue.isUUID())
	{
		mImagep = LLUI::getUIImageByID(tvalue.asUUID(), mPriority);
	}
	else
	{
		mImagep = LLUI::getUIImage(tvalue.asString(), mPriority);
	}

	setIconImageDrawSize();
}
void LLServiceBuilder::createServiceDefinition(
	const std::string& service_name,
	LLSD& service_llsd)
{
	if(service_llsd.isString())
	{
		mServiceMap[ service_name ] = service_llsd.asString();
	}			
	else if(service_llsd.isMap())
	{
		for(LLSD::map_iterator map_itr = service_llsd.beginMap();
			map_itr != service_llsd.endMap();
			++map_itr)
		{
			std::string compound_builder_name = service_name;
			compound_builder_name.append("-");
			compound_builder_name.append((*map_itr).first);
			mServiceMap[ compound_builder_name ] = (*map_itr).second.asString();
		}
	}
}
bool LLFloaterAutoReplaceSettings::selectedListIsLast()
{
	bool isLast = false;
	
	if (!mSelectedListName.empty())
	{
		LLSD last;
		LLSD lists = mSettings.getListNames(); // an Array of Strings
		for ( LLSD::array_const_iterator list = lists.beginArray(), listEnd = lists.endArray();
			  list != listEnd;
			  list++
			 )
		{
			last = *list;
		}
		if ( last.isString() && last.asString() == mSelectedListName )
		{
			isLast = true;
		}
	}
	return isLast;
}
Esempio n. 9
0
LLSD LLControlVariable::getComparableValue(const LLSD& value)
{
	// *FIX:MEP - The following is needed to make the LLSD::ImplString 
	// work with boolean controls...
	LLSD storable_value;
	if(TYPE_BOOLEAN == type() && value.isString())
	{
		BOOL temp;
		if(LLStringUtil::convertToBOOL(value.asString(), temp)) 
		{
			storable_value = (bool)temp;
		}
		else
		{
			storable_value = false;
		}
	}
	else
	{
		storable_value = value;
	}

	return storable_value;
}
// see docstring in .h file
std::string llsd_matches(const LLSD& prototype, const LLSD& data, const std::string& pfx)
{
    // An undefined prototype means that any data is valid.
    // An undefined slot in an array or map prototype means that any data
    // may fill that slot.
    if (prototype.isUndefined())
        return "";
    // A prototype array must match a data array with at least as many
    // entries. Moreover, every prototype entry must match the
    // corresponding data entry.
    if (prototype.isArray())
    {
        if (! data.isArray())
        {
            return STRINGIZE(colon(pfx) << "Array" << op << sTypes.lookup(data.type()));
        }
        if (data.size() < prototype.size())
        {
            return STRINGIZE(colon(pfx) << "Array size " << prototype.size() << op
                             << "Array size " << data.size());
        }
        for (LLSD::Integer i = 0; i < prototype.size(); ++i)
        {
            std::string match(llsd_matches(prototype[i], data[i], STRINGIZE('[' << i << ']')));
            if (! match.empty())
            {
                return match;
            }
        }
        return "";
    }
    // A prototype map must match a data map. Every key in the prototype
    // must have a corresponding key in the data map; every value in the
    // prototype must match the corresponding key's value in the data.
    if (prototype.isMap())
    {
        if (! data.isMap())
        {
            return STRINGIZE(colon(pfx) << "Map" << op << sTypes.lookup(data.type()));
        }
        // If there are a number of keys missing from the data, it would be
        // frustrating to a coder to discover them one at a time, with a big
        // build each time. Enumerate all missing keys.
        std::ostringstream out;
        out << colon(pfx);
        const char* init = "Map missing keys: ";
        const char* sep = init;
        for (LLSD::map_const_iterator mi = prototype.beginMap(); mi != prototype.endMap(); ++mi)
        {
            if (! data.has(mi->first))
            {
                out << sep << mi->first;
                sep = ", ";
            }
        }
        // So... are we missing any keys?
        if (sep != init)
        {
            return out.str();
        }
        // Good, the data block contains all the keys required by the
        // prototype. Now match the prototype entries.
        for (LLSD::map_const_iterator mi2 = prototype.beginMap(); mi2 != prototype.endMap(); ++mi2)
        {
            std::string match(llsd_matches(mi2->second, data[mi2->first],
                                           STRINGIZE("['" << mi2->first << "']")));
            if (! match.empty())
            {
                return match;
            }
        }
        return "";
    }
    // A String prototype can match String, Boolean, Integer, Real, UUID,
    // Date and URI, because any of these can be converted to String.
    if (prototype.isString())
    {
        static LLSD::Type accept[] =
        {
            LLSD::TypeBoolean,
            LLSD::TypeInteger,
            LLSD::TypeReal,
            LLSD::TypeUUID,
            LLSD::TypeDate,
            LLSD::TypeURI
        };
        return match_types(prototype.type(),
                           TypeVector(boost::begin(accept), boost::end(accept)),
                           data.type(),
                           pfx);
    }
    // Boolean, Integer, Real match each other or String. TBD: ensure that
    // a String value is numeric.
    if (prototype.isBoolean() || prototype.isInteger() || prototype.isReal())
    {
        static LLSD::Type all[] =
        {
            LLSD::TypeBoolean,
            LLSD::TypeInteger,
            LLSD::TypeReal,
            LLSD::TypeString
        };
        // Funny business: shuffle the set of acceptable types to include all
        // but the prototype's type. Get the acceptable types in a set.
        std::set<LLSD::Type> rest(boost::begin(all), boost::end(all));
        // Remove the prototype's type because we pass that separately.
        rest.erase(prototype.type());
        return match_types(prototype.type(),
                           TypeVector(rest.begin(), rest.end()),
                           data.type(),
                           pfx);
    }
    // UUID, Date and URI match themselves or String.
    if (prototype.isUUID() || prototype.isDate() || prototype.isURI())
    {
        static LLSD::Type accept[] =
        {
            LLSD::TypeString
        };
        return match_types(prototype.type(),
                           TypeVector(boost::begin(accept), boost::end(accept)),
                           data.type(),
                           pfx);
    }
    // We don't yet know the conversion semantics associated with any new LLSD
    // data type that might be added, so until we've been extended to handle
    // them, assume it's strict: the new type matches only itself. (This is
    // true of Binary, which is why we don't handle that case separately.) Too
    // bad LLSD doesn't define isConvertible(Type to, Type from).
    return match_types(prototype.type(), TypeVector(), data.type(), pfx);
}
// 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)
        {
            LL_DEBUGS() << "PATH: inserting " << it->asString() << LL_ENDL;
            result.mEscapedPath += "/" + escapePathComponent(it->asString());
        }
    }
    else if (path.isString())
    {
        std::string pathstr(path);
        // Trailing slash is significant in HTTP land. If caller specified,
        // make a point of preserving.
        std::string last_slash;
        std::string::size_type len(pathstr.length());
        if (len && pathstr[len-1] == '/')
        {
            last_slash = "/";
        }

        // Escape every individual path component, recombining with slashes.
        for (boost::split_iterator<std::string::const_iterator>
                ti(pathstr, boost::first_finder("/")), tend;
                ti != tend; ++ti)
        {
            // Eliminate a leading slash or duplicate slashes anywhere. (Extra
            // slashes show up here as empty components.) This test also
            // eliminates a trailing slash, hence last_slash above.
            if (! ti->empty())
            {
                result.mEscapedPath
                += "/" + escapePathComponent(std::string(ti->begin(), ti->end()));
            }
        }

        // Reinstate trailing slash, if any.
        result.mEscapedPath += last_slash;
    }
    else if(path.isUndefined())
    {
        // do nothing
    }
    else
    {
        LL_WARNS() << "Valid path arguments to buildHTTP are array, string, or undef, you passed type"
                   << path.type() << LL_ENDL;
    }
    result.mEscapedOpaque = "//" + result.mEscapedAuthority +
                            result.mEscapedPath;
    return result;
}