diff options
Diffstat (limited to 'indra/llcommon')
| -rw-r--r-- | indra/llcommon/llkeythrottle.h | 11 | ||||
| -rw-r--r-- | indra/llcommon/llsecondlifeurls.cpp | 3 | ||||
| -rw-r--r-- | indra/llcommon/llsecondlifeurls.h | 3 | ||||
| -rw-r--r-- | indra/llcommon/lluri.cpp | 83 | ||||
| -rw-r--r-- | indra/llcommon/lluri.h | 46 | ||||
| -rw-r--r-- | indra/llcommon/u64.cpp | 4 | ||||
| -rw-r--r-- | indra/llcommon/u64.h | 30 | 
7 files changed, 155 insertions, 25 deletions
diff --git a/indra/llcommon/llkeythrottle.h b/indra/llcommon/llkeythrottle.h index 708f23f3b1..6ed1f26599 100644 --- a/indra/llcommon/llkeythrottle.h +++ b/indra/llcommon/llkeythrottle.h @@ -21,11 +21,16 @@  #include <map> +// forward declaration so LLKeyThrottleImpl can befriend it +template <class T> class LLKeyThrottle; + +  // Implementation utility class - use LLKeyThrottle, not this  template <class T>  class LLKeyThrottleImpl  { -public: +	friend class LLKeyThrottle<T>; +protected:  	struct Entry {  		U32		count;  		BOOL	blocked; @@ -47,7 +52,9 @@ public:  		// currMap started counting at this time  		// prevMap covers the previous interval -	LLKeyThrottleImpl() : prevMap(0), currMap(0) { } +	LLKeyThrottleImpl() : prevMap(0), currMap(0), +			      countLimit(0), interval_usec(0), +			      start_usec(0) { };  	static U64 getTime()  	{ diff --git a/indra/llcommon/llsecondlifeurls.cpp b/indra/llcommon/llsecondlifeurls.cpp index 4417b09723..bf09453c16 100644 --- a/indra/llcommon/llsecondlifeurls.cpp +++ b/indra/llcommon/llsecondlifeurls.cpp @@ -62,6 +62,9 @@ const char AMD_AGP_URL[] =  const char VIA_URL[] =   	"http://secondlife.com/support/"; +const char SUPPORT_URL[] =  +    "http://secondlife.com/support/"; +  const char INTEL_CHIPSET_URL[] =   	"http://secondlife.com/support/"; diff --git a/indra/llcommon/llsecondlifeurls.h b/indra/llcommon/llsecondlifeurls.h index 0eb3d647cb..b8d8aa2402 100644 --- a/indra/llcommon/llsecondlifeurls.h +++ b/indra/llcommon/llsecondlifeurls.h @@ -57,6 +57,9 @@ extern const char DIRECTX_9_URL[];  // Out of date VIA chipset  extern const char VIA_URL[]; +// Support URL +extern const char SUPPORT_URL[]; +  // Linden Blogs page  extern const char BLOGS_URL[]; diff --git a/indra/llcommon/lluri.cpp b/indra/llcommon/lluri.cpp index deeee3173d..0f6ddd9bc6 100644 --- a/indra/llcommon/lluri.cpp +++ b/indra/llcommon/lluri.cpp @@ -43,28 +43,68 @@  // system includes  #include <boost/tokenizer.hpp> +void encode_character(std::ostream& ostr, std::string::value_type val) +{ +	ostr << "%" << std::uppercase << std::hex << std::setw(2) << std::setfill('0')  +	     // VWR-4010 Cannot cast to U32 because sign-extension on  +	     // chars > 128 will result in FFFFFFC3 instead of F3. +	     << static_cast<S32>(static_cast<U8>(c)); +} +  // static -std::string LLURI::escape(const std::string& str, const std::string & allowed) +std::string LLURI::escape( +	const std::string& str, +	const std::string& allowed, +	bool is_allowed_sorted)  { -	std::ostringstream ostr; +	// *NOTE: This size determination feels like a good value to +	// me. If someone wante to come up with a more precise heuristic +	// with some data to back up the assertion that 'sort is good' +	// then feel free to change this test a bit. +	if(!is_allowed_sorted && (str.size() > 2 * allowed.size())) +	{ +		// if it's already sorted, or if the url is quite long, we +		// want to optimize this process. +		std::string sorted_allowed(allowed); +		std::sort(sorted_allowed.begin(), sorted_allowed.end()); +		return escape(str, sorted_allowed, true); +	} +	std::ostringstream ostr;  	std::string::const_iterator it = str.begin();  	std::string::const_iterator end = str.end(); -	for(; it != end; ++it) +	std::string::value_type c; +	if(is_allowed_sorted)  	{ -		std::string::value_type c = *it; -		if(allowed.find(c) == std::string::npos) -		  { -		    ostr << "%" -			 << std::uppercase << std::hex << std::setw(2) << std::setfill('0') -			 // VWR-4010 Cannot cast to U32 because sign-extension on  -			 // chars > 128 will result in FFFFFFC3 instead of F3. -			 << static_cast<S32>(static_cast<U8>(c)); -		  } -		else -		  { -		    ostr << c; -		  } +		std::string::const_iterator allowed_begin(allowed.begin()); +		std::string::const_iterator allowed_end(allowed.end()); +		for(; it != end; ++it) +		{ +			c = *it; +			if(std::binary_search(allowed_begin, allowed_end, c)) +			{ +				ostr << c; +			} +			else +			{ +				encode_character(ostr, c); +			} +		} +	} +	else +	{ +		for(; it != end; ++it) +		{ +			c = *it; +			if(allowed.find(c) == std::string::npos) +			{ +				encode_character(ostr, c); +			} +			else +			{ +				ostr << c; +			} +		}  	}  	return ostr.str();  } @@ -121,11 +161,18 @@ namespace  		{ return LLURI::escape(s, unreserved() + ":@!$'()*+,="); }	// sub_delims - "&;" + ":@"  } -// TODO: USE CURL!! After http textures gets merged everywhere. +// *TODO: Consider using curl. After http textures gets merged everywhere.  // static  std::string LLURI::escape(const std::string& str)  { -	return escape(str,unreserved()  + ":@!$'()*+,="); +	static std::string default_allowed(unreserved() + ":@!$'()*+,=/?&#;"); +	static bool initialized = false; +	if(!initialized) +	{ +		std::sort(default_allowed.begin(), default_allowed.end()); +		initialized = true; +	} +	return escape(str, default_allowed, true);  }  LLURI::LLURI() diff --git a/indra/llcommon/lluri.h b/indra/llcommon/lluri.h index bfe673c2f7..953e652704 100644 --- a/indra/llcommon/lluri.h +++ b/indra/llcommon/lluri.h @@ -125,12 +125,52 @@ public:  	/** @name Escaping Utilities */  	//@{ -	// Escape a string by urlencoding all the characters that aren't -	// in the allowed string. +	/** +	 * @brief Escape a raw url with a reasonable set of allowed characters. +	 * +	 * The default set was chosen to match HTTP urls and general +     *  guidelines for naming resources. Passing in a raw url does not +     *  produce well defined results because you really need to know +     *  which segments are path parts because path parts are supposed +     *  to be escaped individually. The default set chosen is: +	 * +	 *  ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +	 *  0123456789 +	 *  -._~ +	 *  :@!$'()*+,=/?&#; +	 * +	 * *NOTE: This API is basically broken because it does not +     *  allow you to specify significant path characters. For example, +     *  if the filename actually contained a /, then you cannot use +     *  this function to generate the serialized url for that +     *  resource. +	 * +	 * @param str The raw URI to escape. +	 * @return Returns the escaped uri or an empty string. +	 */  	static std::string escape(const std::string& str); + +	/** +	 * @brief Escape a string with a specified set of allowed characters. +	 * +	 * Escape a string by urlencoding all the characters that aren't +	 * in the allowed string. +	 * @param str The raw URI to escape. +	 * @param allowed Character array of allowed characters +	 * @param is_allowed_sorted Optimization hint if allowed array is sorted. +	 * @return Returns the escaped uri or an empty string. +	 */  	static std::string escape(  		const std::string& str, -		const std::string & allowed);  +		const std::string& allowed, +		bool is_allowed_sorted = false); + +	/** +	 * @brief unescape an escaped URI string. +	 * +	 * @param str The escped URI to unescape. +	 * @return Returns the unescaped uri or an empty string. +	 */  	static std::string unescape(const std::string& str);  	//@} diff --git a/indra/llcommon/u64.cpp b/indra/llcommon/u64.cpp index f2efef1c01..f3422770ae 100644 --- a/indra/llcommon/u64.cpp +++ b/indra/llcommon/u64.cpp @@ -107,8 +107,8 @@ F64 U64_to_F64(const U64 value)  U64	llstrtou64(const char* str, char** end, S32 base)  {  #ifdef LL_WINDOWS -				return _strtoui64(str,end,base); +	return _strtoui64(str,end,base);  #else -				return strtoull(str,end,base); +	return strtoull(str,end,base);  #endif  } diff --git a/indra/llcommon/u64.h b/indra/llcommon/u64.h index ad93ebffe7..f4580513bc 100644 --- a/indra/llcommon/u64.h +++ b/indra/llcommon/u64.h @@ -32,11 +32,41 @@  #ifndef LL_U64_H  #define LL_U64_H +/** + * @brief Forgivingly parse a null terminated character array. + * + * @param str The string to parse. + * @return Returns the first U64 value found in the string or 0 on failure. + */  U64 str_to_U64(const char* str); + +/** + * @brief Given a U64 value, return a printable representation. + * + * The client of this function is expected to provide an allocated + * buffer. The function then snprintf() into that buffer, so providing + * NULL has undefined behavior. Providing a buffer which is too small + * will truncate the printable value, so usually you want to declare + * the buffer: + * + *  char result[U64_BUF]; + *  std::cout << "value: " << U64_to_str(value, result, U64_BUF); + * + * @param value The U64 to turn into a printable character array. + * @param result The buffer to use + * @param result_size The size of the buffer allocated. Use U64_BUF. + * @return Returns the result pointer. + */  char* U64_to_str(U64 value, char* result, S32 result_size); +/** + * @brief Convert a U64 to the closest F64 value. + */  F64 U64_to_F64(const U64 value); +/** + * @brief Helper function to wrap strtoull() which is not available on windows. + */  U64 llstrtou64(const char* str, char** end, S32 base);  #endif  | 
