Exemplo n.º 1
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;
}
Exemplo n.º 2
0
	void loadPersistentNotifications()
	{
		llinfos << "Loading open notifications from " << mFileName << llendl;

		llifstream notify_file(mFileName.c_str());
		if (!notify_file.is_open()) 
		{
			llwarns << "Failed to open " << mFileName << llendl;
			return;
		}

		LLSD input;
		LLPointer<LLSDParser> parser = new LLSDXMLParser();
		if (parser->parse(notify_file, input, LLSDSerialize::SIZE_UNLIMITED) < 0)
		{
			llwarns << "Failed to parse open notifications" << llendl;
			return;
		}

		if (input.isUndefined()) return;
		std::string version = input["version"];
		if (version != NOTIFICATION_PERSIST_VERSION)
		{
			llwarns << "Bad open notifications version: " << version << llendl;
			return;
		}
		LLSD& data = input["data"];
		if (data.isUndefined()) return;

		LLNotifications& instance = LLNotifications::instance();
		for (LLSD::array_const_iterator notification_it = data.beginArray();
			notification_it != data.endArray();
			++notification_it)
		{
			instance.add(LLNotificationPtr(new LLNotification(*notification_it)));
		}
	}
Exemplo n.º 3
0
// static
bool LLSDSerialize::deserialize(LLSD& sd, std::istream& str, S32 max_bytes)
{
	LLPointer<LLSDParser> p = NULL;
	char hdr_buf[MAX_HDR_LEN + 1] = ""; /* Flawfinder: ignore */
	int i;
	int inbuf = 0;
	bool legacy_no_header = false;
	bool fail_if_not_legacy = false;
	std::string header;

	/*
	 * Get the first line before anything.
	 */
	str.get(hdr_buf, MAX_HDR_LEN, '\n');
	if (str.fail())
	{
		str.clear();
		fail_if_not_legacy = true;
	}

	if (!strncasecmp(LEGACY_NON_HEADER, hdr_buf, strlen(LEGACY_NON_HEADER))) /* Flawfinder: ignore */
	{
		legacy_no_header = true;
		inbuf = str.gcount();
	}
	else
	{
		if (fail_if_not_legacy)
			goto fail;
		/*
		* Remove the newline chars
		*/
		for (i = 0; i < MAX_HDR_LEN; i++)
		{
			if (hdr_buf[i] == 0 || hdr_buf[i] == '\r' ||
				hdr_buf[i] == '\n')
			{
				hdr_buf[i] = 0;
				break;
			}
		}
		header = hdr_buf;

		std::string::size_type start = std::string::npos;
		std::string::size_type end = std::string::npos;
		start = header.find_first_not_of("<? ");
		if (start != std::string::npos)
		{
			end = header.find_first_of(" ?", start);
		}
		if ((start == std::string::npos) || (end == std::string::npos))
			goto fail;

		header = header.substr(start, end - start);
		ws(str);
	}
	/*
	 * Create the parser as appropriate
	 */
	if (legacy_no_header)
	{	// Create a LLSD XML parser, and parse the first chunk read above
		LLSDXMLParser* x = new LLSDXMLParser();
		x->parsePart(hdr_buf, inbuf);	// Parse the first part that was already read
		x->parseLines(str, sd);			// Parse the rest of it
		delete x;
		return true;
	}

	if (header == LLSD_BINARY_HEADER)
	{
		p = new LLSDBinaryParser;
	}
	else if (header == LLSD_XML_HEADER)
	{
		p = new LLSDXMLParser;
	}
	else
	{
		llwarns << "deserialize request for unknown ELLSD_Serialize" << llendl;
	}

	if (p.notNull())
	{
		p->parse(str, sd, max_bytes);
		return true;
	}

fail:
	llwarns << "deserialize LLSD parse failure" << llendl;
	return false;
}
Exemplo n.º 4
0
bool LLWLParamManager::loadPresetXML(const std::string& name, std::istream& preset_stream, bool propagate /* = false */, bool check_if_real /* = false */)
{
	LLSD paramsData(LLSD::emptyMap());
	
	LLPointer<LLSDParser> parser = new LLSDXMLParser();
	
	if(parser->parse(preset_stream, paramsData, LLSDSerialize::SIZE_UNLIMITED) == LLSDParser::PARSE_FAILURE)
	{
		return false;
	}
	
	if(check_if_real)
	{
		static const char* expected_windlight_settings[] = {
			"ambient",
			"blue_density",
			"blue_horizon",
			"cloud_color",
			"cloud_pos_density1",
			"cloud_pos_density2",
			"cloud_scale",
			"cloud_scroll_rate",
			"cloud_shadow",
			"density_multiplier",
			"distance_multiplier",
			"east_angle",
			"enable_cloud_scroll",
			"gamma",
			"glow",
			"haze_density",
			"haze_horizon",
			"lightnorm",
			"max_y",
			"star_brightness",
			"sun_angle",
			"sunlight_color"
		};
		static S32 expected_count = LL_ARRAY_SIZE(expected_windlight_settings);
		for(S32 i = 0; i < expected_count; ++i)
		{
			if(!paramsData.has(expected_windlight_settings[i]))
			{
				LL_WARNS("WindLight") << "Attempted to load WindLight param set without " << expected_windlight_settings[i] << LL_ENDL;
				return false;
			}
		}
	}
	
	std::map<std::string, LLWLParamSet>::iterator mIt = mParamList.find(name);
	if(mIt == mParamList.end())
	{
		addParamSet(name, paramsData);
	}
	else 
	{
		setParamSet(name, paramsData);
	}

	if(propagate)
	{
		getParamSet(name, mCurParams);
		propagateParameters();
	}
	return true;
}
Exemplo n.º 5
0
void LLWLDayCycle::loadDayCycle(const std::string & fileName)
{
	// clear the first few things
	mTimeMap.clear();

	// bugfix for SL-46920: preventing filenames that break stuff.
	char * curl_str = curl_escape(fileName.c_str(), fileName.size());
	std::string escaped_filename(curl_str);
	curl_free(curl_str);
	curl_str = NULL;

	escaped_filename += ".xml";

	std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/days", escaped_filename));
	llinfos << "Loading Day Cycle preset from " << pathName << llendl;

	llifstream day_cycle_xml;
	day_cycle_xml.open(pathName.c_str());

	// That failed, try loading from the users area instead.
	if(!day_cycle_xml)
	{
		pathName=gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/days", escaped_filename);
		llinfos << "Loading User Day Cycle preset from " << pathName << llendl;
		day_cycle_xml.open(pathName.c_str());
	}

	if (day_cycle_xml)
	{
		// load and parse it
		LLSD day_data(LLSD::emptyArray());
		LLPointer<LLSDParser> parser = new LLSDXMLParser();
		parser->parse(day_cycle_xml, day_data, LLSDSerialize::SIZE_UNLIMITED);
		llinfos << "Loading day cycle into timeline..." << llendl;
		// add each key
		for(S32 i = 0; i < day_data.size(); ++i)
		{
			llinfos << "Loading value" << i << llendl;
			// make sure it's a two array
			if(day_data[i].size() != 2)
			{
				continue;
			}
			
			// check each param name exists in param manager
			bool success;
			LLWLParamSet pset;
			success = LLWLParamManager::instance()->getParamSet(day_data[i][1].asString(), pset);
			if(!success)
			{
				// alert the user
				LLSD args;
				args["SKY"] = day_data[i][1].asString();
				LLNotifications::instance().add("WLMissingSky", args);
				continue;
			}
			
			// then add the key
			addKey((F32)day_data[i][0].asReal(), day_data[i][1].asString());
		}

		day_cycle_xml.close();
	}
	else 
	{
		llwarns << "Can't find " << fileName << llendl;
		return;
	}
}
Exemplo n.º 6
0
int LLQueryResponder::parseRR(const char *buf, size_t len, const char *&pos,
							  LLPointer<LLDnsRecord> &r)
{
	std::string rrname;
	size_t enclen;
	int ret;

	// RR name.

	ret = LLAres::expandName(pos, buf, len, rrname, enclen);
	if (ret != ARES_SUCCESS)
	{
		return ret;
	}
		
	pos += enclen;

	if (pos + NS_RRFIXEDSZ > buf + len)
	{
		return ARES_EBADRESP;
	}

	int rrtype = DNS_RR_TYPE(pos);
	int rrclass = DNS_RR_CLASS(pos);
	int rrttl = DNS_RR_TTL(pos);
	int rrlen = DNS_RR_LEN(pos);
		
	if (rrclass != ns_c_in)
	{
		return ARES_EBADRESP;
	}

	pos += NS_RRFIXEDSZ;

	if (pos + rrlen > buf + len)
	{
		return ARES_EBADRESP;
	}

	switch (rrtype)
	{
	case RES_A:
		r = new LLARecord(rrname, rrttl);
		break;
	case RES_NS:
		r = new LLNsRecord(rrname, rrttl);
		break;
	case RES_CNAME:
		r = new LLCnameRecord(rrname, rrttl);
		break;
	case RES_PTR:
		r = new LLPtrRecord(rrname, rrttl);
		break;
	case RES_AAAA:
		r = new LLAaaaRecord(rrname, rrttl);
		break;
	case RES_SRV:
		r = new LLSrvRecord(rrname, rrttl);
		break;
	default:
		LL_INFOS() << "LLQueryResponder::parseRR got unknown RR type " << rrtype
				<< LL_ENDL;
		return ARES_EBADRESP;
	}

	ret = r->parse(buf, len, pos, rrlen);

	if (ret == ARES_SUCCESS)
	{
		pos += rrlen;
	} else {
		r = NULL;
	}
		
	return ret;
}
Exemplo n.º 7
0
void LLSecAPIBasicHandler::_readProtectedData()
{	
	// attempt to load the file into our map
	LLPointer<LLSDParser> parser = new LLSDXMLParser();
	llifstream protected_data_stream(mProtectedDataFilename.c_str(), 
									llifstream::binary);

	if (!protected_data_stream.fail()) {
		int offset;
		U8 salt[STORE_SALT_SIZE];
		U8 buffer[BUFFER_READ_SIZE];
		U8 decrypted_buffer[BUFFER_READ_SIZE];
		int decrypted_length;	
		unsigned char unique_id[MAC_ADDRESS_BYTES];
        LLMachineID::getUniqueID(unique_id, sizeof(unique_id));
		LLXORCipher cipher(unique_id, sizeof(unique_id));

		// read in the salt and key
		protected_data_stream.read((char *)salt, STORE_SALT_SIZE);
		offset = 0;
		if (protected_data_stream.gcount() < STORE_SALT_SIZE)
		{
			throw LLProtectedDataException("Config file too short.");
		}

		cipher.decrypt(salt, STORE_SALT_SIZE);		

		// totally lame.  As we're not using the OS level protected data, we need to
		// at least obfuscate the data.  We do this by using a salt stored at the head of the file
		// to encrypt the data, therefore obfuscating it from someone using simple existing tools.
		// We do include the MAC address as part of the obfuscation, which would require an
		// attacker to get the MAC address as well as the protected store, which improves things
		// somewhat.  It would be better to use the password, but as this store
		// will be used to store the SL password when the user decides to have SL remember it, 
		// so we can't use that.  OS-dependent store implementations will use the OS password/storage 
		// mechanisms and are considered to be more secure.
		// We've a strong intent to move to OS dependent protected data stores.
		

		// read in the rest of the file.
		EVP_CIPHER_CTX ctx;
		EVP_CIPHER_CTX_init(&ctx);
		EVP_DecryptInit(&ctx, EVP_rc4(), salt, NULL);
		// allocate memory:
		std::string decrypted_data;	
		
		while(protected_data_stream.good()) {
			// read data as a block:
			protected_data_stream.read((char *)buffer, BUFFER_READ_SIZE);
			
			EVP_DecryptUpdate(&ctx, decrypted_buffer, &decrypted_length, 
							  buffer, protected_data_stream.gcount());
			decrypted_data.append((const char *)decrypted_buffer, protected_data_stream.gcount());
		}
		
		// RC4 is a stream cipher, so we don't bother to EVP_DecryptFinal, as there is
		// no block padding.
		EVP_CIPHER_CTX_cleanup(&ctx);
		std::istringstream parse_stream(decrypted_data);
		if (parser->parse(parse_stream, mProtectedDataMap, 
						  LLSDSerialize::SIZE_UNLIMITED) == LLSDParser::PARSE_FAILURE)
		{
			throw LLProtectedDataException("Config file cannot be decrypted.");
		}
	}
}
Exemplo n.º 8
0
void LLWLParamManager::loadPresets(const std::string& file_name)
{
	// if fileName exists, use legacy loading form the big file, otherwise, search the sky 
	// directory, and add the list
	if(file_name != "") 
	{
		std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight", file_name));
		LL_INFOS2("AppInit", "Shaders") << "Loading WindLight settings from " << path_name << LL_ENDL;

		llifstream presetsXML(path_name);
	
		if (presetsXML)
		{
			LLSD paramsData(LLSD::emptyMap());

			LLPointer<LLSDParser> parser = new LLSDXMLParser();

			parser->parse(presetsXML, paramsData, LLSDSerialize::SIZE_UNLIMITED);

			LLSD::map_const_iterator endParams = paramsData.endMap();
			for(LLSD::map_const_iterator curParams = paramsData.beginMap();
				curParams != endParams;
				++curParams)
			{
				addParamSet(curParams->first, curParams->second);
			}
		}
	}
	
	// otherwise, search the sky directory and find things there
	else
	{
		std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/skies", ""));
		LL_INFOS2("AppInit", "Shaders") << "Loading WindLight settings from " << path_name << LL_ENDL;
	
		//mParamList.clear();
		
		bool found = true;			
		while(found) 
		{
			std::string name;
			found = gDirUtilp->getNextFileInDir(path_name, "*.xml", name, false);

			LL_DEBUGS2("AppInit", "Shaders") << "name: " << name << LL_ENDL;
			
			// if we have one
			if(found) 
			{
				// bugfix for SL-46920: preventing filenames that break stuff.
				char * curl_str = curl_unescape(name.c_str(), name.size());
				std::string unescaped_name(curl_str);
				curl_free(curl_str);
				curl_str = NULL;

				// not much error checking here since we're getting rid of this
				std::string sky_name = unescaped_name.substr(0, unescaped_name.size() - 4);
			
				std::string cur_path(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/skies", name));
				LL_DEBUGS2("AppInit", "Shaders") << "Loading sky from " << cur_path << LL_ENDL;
				
				llifstream sky_xml(cur_path);
				if (sky_xml)
				{
					LLSD sky_data(LLSD::emptyMap());
					LLPointer<LLSDParser> parser = new LLSDXMLParser();
					parser->parse(sky_xml, sky_data, LLSDSerialize::SIZE_UNLIMITED);

					addParamSet(sky_name, sky_data);
					sky_xml.close();
				}
			}
		}
	}
}