diff options
| author | Josh Bell <josh@lindenlab.com> | 2007-12-21 06:44:41 +0000 | 
|---|---|---|
| committer | Josh Bell <josh@lindenlab.com> | 2007-12-21 06:44:41 +0000 | 
| commit | df4d167cd13fd89a85e4d30dca94e40c934707d7 (patch) | |
| tree | cde9373bce657013bf04c83ab60b4a4aa826fc76 /indra/llcommon | |
| parent | 8fde5f0d3241205067e5d7bf5380757e764eff31 (diff) | |
svn merge -r74200:76302 svn+ssh://svn.lindenlab.com/svn/linden/branches/Branch_1-18-6-Viewer --> release
Wheee, this was fun. Um, let's back-port fixes a little more rapidly next time. Reviewed by CG until alexandria died, did the rest by my lonesome.
Diffstat (limited to 'indra/llcommon')
| -rw-r--r-- | indra/llcommon/indra_constants.h | 2 | ||||
| -rw-r--r-- | indra/llcommon/llstring.cpp | 58 | ||||
| -rw-r--r-- | indra/llcommon/llstring.h | 32 | ||||
| -rw-r--r-- | indra/llcommon/llsys.cpp | 77 | ||||
| -rw-r--r-- | indra/llcommon/llsys.h | 2 | ||||
| -rw-r--r-- | indra/llcommon/llversionviewer.h | 2 | 
6 files changed, 133 insertions, 40 deletions
| diff --git a/indra/llcommon/indra_constants.h b/indra/llcommon/indra_constants.h index b7d35780ae..0195893b16 100644 --- a/indra/llcommon/indra_constants.h +++ b/indra/llcommon/indra_constants.h @@ -336,7 +336,7 @@ const U32 MAP_ITEM_CLASSIFIED = 0x08;  // Crash reporter behavior  const char* const CRASH_SETTINGS_FILE = "crash_settings.xml"; -const char* const CRASH_BEHAVIOR_SETTING = "CrashBehavior"; +const char* const CRASH_BEHAVIOR_SETTING = "CrashLogBehavior";  const S32 CRASH_BEHAVIOR_ASK = 0;  const S32 CRASH_BEHAVIOR_ALWAYS_SEND = 1;  const S32 CRASH_BEHAVIOR_NEVER_SEND = 2; diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index 9895a684b2..a688bc1c6f 100644 --- a/indra/llcommon/llstring.cpp +++ b/indra/llcommon/llstring.cpp @@ -34,6 +34,13 @@  #include "llstring.h"  #include "llerror.h" +#if LL_WINDOWS +#define WIN32_LEAN_AND_MEAN +#include <winsock2.h> +#include <windows.h> +#include <winnls.h> // for WideCharToMultiByte +#endif +  std::string ll_safe_string(const char* in)  {  	if(in) return std::string(in); @@ -796,19 +803,7 @@ std::string utf8str_removeCRLF(const std::string& utf8str)  }  #if LL_WINDOWS -/* If the size of the passed in buffer is not large enough to hold the string, - * two bad things happen: - * 1. resulting formatted string is NOT null terminated - * 2. Depending on the platform, the return value could be a) the required - *    size of the buffer to copy the entire formatted string or b) -1. - *    On Windows with VS.Net 2003, it returns -1 e.g.  - * - * safe_snprintf always adds a NULL terminator so that the caller does not - * need to check for return value or need to add the NULL terminator. - * It does not, however change the return value - to let the caller know - * that the passed in buffer size was not large enough to hold the formatted string. - * - */ +// documentation moved to header. Phoenix 2007-11-27  int safe_snprintf(char *str, size_t size, const char *format, ...)  {  	va_list args; @@ -820,6 +815,43 @@ int safe_snprintf(char *str, size_t size, const char *format, ...)  	str[size-1] = '\0'; // always null terminate  	return num_written;  } + +std::string ll_convert_wide_to_string(const wchar_t* in) +{ +	std::string out; +	if(in) +	{ +		int len_in = wcslen(in); +		int len_out = WideCharToMultiByte( +			CP_ACP, +			0, +			in, +			len_in, +			NULL, +			0, +			0, +			0); +		// We will need two more bytes for the double NULL ending +		// created in WideCharToMultiByte(). +		char* pout = new char [len_out + 2]; +		memset(pout, 0, len_out + 2); +		if(pout) +		{ +			WideCharToMultiByte( +				CP_ACP, +				0, +				in, +				len_in, +				pout, +				len_out, +				0, +				0); +			out.assign(pout); +			delete[] pout; +		} +	} +	return out; +}  #endif // LL_WINDOWS  S32	LLStringOps::collate(const llwchar* a, const llwchar* b) diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h index e2f605db4f..88d7e88edc 100644 --- a/indra/llcommon/llstring.h +++ b/indra/llcommon/llstring.h @@ -494,7 +494,37 @@ std::ostream& operator<<(std::ostream &s, const LLStringBase<T> &str)  std::ostream& operator<<(std::ostream &s, const LLWString &wstr);  #if LL_WINDOWS -int safe_snprintf(char *str, size_t size, const char *format, ...); +/* @name Windows string helpers + */ +//@{ + +/** + * @brief Implementation the expected snprintf interface. + * + * If the size of the passed in buffer is not large enough to hold the string, + * two bad things happen: + * 1. resulting formatted string is NOT null terminated + * 2. Depending on the platform, the return value could be a) the required + *    size of the buffer to copy the entire formatted string or b) -1. + *    On Windows with VS.Net 2003, it returns -1 e.g.  + * + * safe_snprintf always adds a NULL terminator so that the caller does not + * need to check for return value or need to add the NULL terminator. + * It does not, however change the return value - to let the caller know + * that the passed in buffer size was not large enough to hold the + * formatted string. + * + */ +int safe_snprintf(char* str, size_t size, const char* format, ...); + +/** + * @brief Convert a wide string to std::string + * + * This replaces the unsafe W2A macro from ATL. + */ +std::string ll_convert_wide_to_string(const wchar_t* in); + +//@}  #endif // LL_WINDOWS  /** diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp index 3b57db772c..7346b29fb1 100644 --- a/indra/llcommon/llsys.cpp +++ b/indra/llcommon/llsys.cpp @@ -65,8 +65,7 @@ static const S32 CPUINFO_BUFFER_SIZE = 16383;  LLCPUInfo gSysCPU;  LLOSInfo::LLOSInfo() : -	mMajorVer(0), mMinorVer(0), mBuild(0), -	mOSString("") +	mMajorVer(0), mMinorVer(0), mBuild(0)  {  #if LL_WINDOWS @@ -94,27 +93,28 @@ LLOSInfo::LLOSInfo() :  			// Test for the product.  			if(osvi.dwMajorVersion <= 4)  			{ -				mOSString = "Microsoft Windows NT "; +				mOSStringSimple = "Microsoft Windows NT ";  			}  			else if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)  			{ -				mOSString = "Microsoft Windows 2000 "; +				mOSStringSimple = "Microsoft Windows 2000 ";  			}  			else if(osvi.dwMajorVersion ==5 && osvi.dwMinorVersion == 1)  			{ -				mOSString = "Microsoft Windows XP "; +				mOSStringSimple = "Microsoft Windows XP ";  			}  			else if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)  			{  				 if(osvi.wProductType == VER_NT_WORKSTATION) -					mOSString = "Microsoft Windows XP x64 Edition "; -				 else mOSString = "Microsoft Windows Server 2003 "; +					mOSStringSimple = "Microsoft Windows XP x64 Edition "; +				 else +					 mOSStringSimple = "Microsoft Windows Server 2003 ";  			}  			else if(osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0)  			{  				 if(osvi.wProductType == VER_NT_WORKSTATION) -					mOSString = "Microsoft Windows Vista "; -				 else mOSString = "Microsoft Windows Vista Server "; +					mOSStringSimple = "Microsoft Windows Vista "; +				 else mOSStringSimple = "Microsoft Windows Vista Server ";  			}  			else   // Use the registry on early versions of Windows NT.  			{ @@ -129,15 +129,15 @@ LLOSInfo::LLOSInfo() :  				RegCloseKey( hKey );  				if ( lstrcmpi( L"WINNT", szProductType) == 0 )  				{ -					mOSString += "Professional "; +					mOSStringSimple += "Professional ";  				}  				else if ( lstrcmpi( L"LANMANNT", szProductType) == 0 )  				{ -					mOSString += "Server "; +					mOSStringSimple += "Server ";  				}  				else if ( lstrcmpi( L"SERVERNT", szProductType) == 0 )  				{ -					mOSString += "Advanced Server "; +					mOSStringSimple += "Advanced Server ";  				}  			} @@ -164,7 +164,7 @@ LLOSInfo::LLOSInfo() :  					csdversion.c_str(),  					(osvi.dwBuildNumber & 0xffff));	   			} -			mOSString += tmp; +			mOSString = mOSStringSimple + tmp;  		}  		break; @@ -172,41 +172,65 @@ LLOSInfo::LLOSInfo() :  		// Test for the Windows 95 product family.  		if(osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)  		{ -			mOSString = "Microsoft Windows 95 "; +			mOSStringSimple = "Microsoft Windows 95 ";  			if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )  			{ -                mOSString += "OSR2 "; +                mOSStringSimple += "OSR2 ";  			}  		}   		if(osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)  		{ -			mOSString = "Microsoft Windows 98 "; +			mOSStringSimple = "Microsoft Windows 98 ";  			if ( osvi.szCSDVersion[1] == 'A' )  			{ -                mOSString += "SE "; +                mOSStringSimple += "SE ";  			}  		}   		if(osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)  		{ -			mOSString = "Microsoft Windows Millennium Edition "; -		}  +			mOSStringSimple = "Microsoft Windows Millennium Edition "; +		} +		mOSString = mOSStringSimple;  		break;  	}  #else  	struct utsname un; -        if(uname(&un) != -1) +	if(uname(&un) != -1)  	{ -		mOSString.append(un.sysname); -		mOSString.append(" "); -		mOSString.append(un.release); +		mOSStringSimple.append(un.sysname); +		mOSStringSimple.append(" "); +		mOSStringSimple.append(un.release); + +		mOSString = mOSStringSimple;  		mOSString.append(" ");  		mOSString.append(un.version);  		mOSString.append(" ");  		mOSString.append(un.machine); + +		// Simplify 'Simple' +		std::string ostype = mOSStringSimple.substr(0, mOSStringSimple.find_first_of(" ", 0)); +		if (ostype == "Darwin") +		{ +			// Only care about major Darwin versions, truncate at first '.' +			S32 idx1 = mOSStringSimple.find_first_of(".", 0); +			std::string simple = mOSStringSimple.substr(0, idx1); +			if (simple.length() > 0) +				mOSStringSimple = simple; +		} +		else if (ostype == "Linux") +		{ +			// Only care about major and minor Linux versions, truncate at second '.' +			S32 idx1 = mOSStringSimple.find_first_of(".", 0); +			S32 idx2 = (idx1 != std::string::npos) ? mOSStringSimple.find_first_of(".", idx1+1) : std::string::npos; +			std::string simple = mOSStringSimple.substr(0, idx2); +			if (simple.length() > 0) +				mOSStringSimple = simple; +		}  	}  	else  	{ -		mOSString.append("Unable to collect OS info"); +		mOSStringSimple.append("Unable to collect OS info"); +		mOSString = mOSStringSimple;  	}  #endif @@ -255,6 +279,11 @@ const std::string& LLOSInfo::getOSString() const  	return mOSString;  } +const std::string& LLOSInfo::getOSStringSimple() const +{ +	return mOSStringSimple; +} +  const S32 STATUS_SIZE = 8192;  //static diff --git a/indra/llcommon/llsys.h b/indra/llcommon/llsys.h index fc4e02763c..332d62c186 100644 --- a/indra/llcommon/llsys.h +++ b/indra/llcommon/llsys.h @@ -51,6 +51,7 @@ public:  	void stream(std::ostream& s) const;  	const std::string& getOSString() const; +	const std::string& getOSStringSimple() const;  	S32 mMajorVer;  	S32 mMinorVer; @@ -64,6 +65,7 @@ public:  	static U32 getProcessResidentSizeKB();  private:  	std::string mOSString; +	std::string mOSStringSimple;  }; diff --git a/indra/llcommon/llversionviewer.h b/indra/llcommon/llversionviewer.h index f9f3bf2087..e041bc52a9 100644 --- a/indra/llcommon/llversionviewer.h +++ b/indra/llcommon/llversionviewer.h @@ -35,7 +35,7 @@  const S32 LL_VERSION_MAJOR = 1;  const S32 LL_VERSION_MINOR = 18;  const S32 LL_VERSION_PATCH = 6; -const S32 LL_VERSION_BUILD = 0; +const S32 LL_VERSION_BUILD = 2;  const char * const LL_CHANNEL = "Second Life Release"; | 
