From fb9a358b797418fbc4c38dd9ec67e12bb5b7c98a Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Tue, 31 Mar 2009 05:51:28 +0000 Subject: [PATCH] * Refactored out and de-duplicated Base64ToString(string) * Fixed minor typo --- .../ApplicationPlugins/Rest/Inventory/Rest.cs | 8 +----- .../Communications/Cache/AssetCache.cs | 7 ++--- OpenSim/Framework/Util.cs | 27 ++++++++++++++----- .../Shared/Api/Implementation/LSL_Api.cs | 10 ++----- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/Rest.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/Rest.cs index 62e18c4aa5..748f20a55d 100644 --- a/OpenSim/ApplicationPlugins/Rest/Inventory/Rest.cs +++ b/OpenSim/ApplicationPlugins/Rest/Inventory/Rest.cs @@ -444,15 +444,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory public static string Base64ToString(string str) { - UTF8Encoding encoder = new UTF8Encoding(); - Decoder utf8Decode = encoder.GetDecoder(); try { - byte[] todecode_byte = Convert.FromBase64String(str); - int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); - char[] decoded_char = new char[charCount]; - utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); - return new String(decoded_char); + return Util.Base64ToString(str); } catch { diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs index 73aa6ba689..e0d0bd7a30 100644 --- a/OpenSim/Framework/Communications/Cache/AssetCache.cs +++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs @@ -34,6 +34,7 @@ using log4net; using OpenMetaverse; using OpenMetaverse.Packets; using OpenSim.Framework.Statistics; +using System.Text; namespace OpenSim.Framework.Communications.Cache { @@ -334,7 +335,7 @@ namespace OpenSim.Framework.Communications.Cache { AssetInfo assetInf = new AssetInfo(asset); - ProcessRecievedAsset(IsTexture, assetInf); + ProcessReceivedAsset(IsTexture, assetInf); if (!m_memcache.Contains(assetInf.FullID)) { @@ -389,8 +390,8 @@ namespace OpenSim.Framework.Communications.Cache } } - protected void ProcessRecievedAsset(bool IsTexture, AssetInfo assetInf) - { + protected void ProcessReceivedAsset(bool IsTexture, AssetInfo assetInf) + { } // See IAssetReceiver diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index ba19dc61c2..cce2adbbe3 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -342,7 +342,7 @@ namespace OpenSim.Framework /// public static string Md5Hash(string pass) { - MD5 md5 = MD5CryptoServiceProvider.Create(); + MD5 md5 = MD5.Create(); byte[] dataMd5 = md5.ComputeHash(Encoding.Default.GetBytes(pass)); StringBuilder sb = new StringBuilder(); for (int i = 0; i < dataMd5.Length; i++) @@ -419,7 +419,7 @@ namespace OpenSim.Framework output.Append(": "); } - output.Append(CleanString(UTF8Encoding.UTF8.GetString(bytes, 0, bytes.Length - 1))); + output.Append(CleanString(Encoding.UTF8.GetString(bytes, 0, bytes.Length - 1))); } else { @@ -532,7 +532,7 @@ namespace OpenSim.Framework /// safe path public static string safePath(string path) { - return Regex.Replace(path, @regexInvalidPathChars, string.Empty); + return Regex.Replace(path, regexInvalidPathChars, String.Empty); } /// @@ -542,7 +542,7 @@ namespace OpenSim.Framework /// safe filename public static string safeFileName(string filename) { - return Regex.Replace(filename, @regexInvalidFileChars, string.Empty); + return Regex.Replace(filename, regexInvalidFileChars, String.Empty); ; } @@ -594,7 +594,7 @@ namespace OpenSim.Framework { FileInfo f = new FileInfo(FileName); - if (!string.IsNullOrEmpty(f.Extension)) + if (!String.IsNullOrEmpty(f.Extension)) { Name = f.FullName.Substring(0, f.FullName.LastIndexOf('.')); } @@ -959,7 +959,7 @@ namespace OpenSim.Framework } else if (fieldInfo.FieldType == typeof(System.UInt32)) { - fieldInfo.SetValue(settingsClass, System.Convert.ToUInt32(config.Get(fieldInfo.Name, ((uint)fieldInfo.GetValue(settingsClass)).ToString()))); + fieldInfo.SetValue(settingsClass, Convert.ToUInt32(config.Get(fieldInfo.Name, ((uint)fieldInfo.GetValue(settingsClass)).ToString()))); } } } @@ -987,12 +987,25 @@ namespace OpenSim.Framework } if (propInfo.PropertyType == typeof(System.UInt32)) { - propInfo.SetValue(settingsClass, System.Convert.ToUInt32(config.Get(propInfo.Name, ((uint)propInfo.GetValue(settingsClass, null)).ToString())), null); + propInfo.SetValue(settingsClass, Convert.ToUInt32(config.Get(propInfo.Name, ((uint)propInfo.GetValue(settingsClass, null)).ToString())), null); } } } return settingsClass; } + + public static string Base64ToString(string str) + { + UTF8Encoding encoder = new UTF8Encoding(); + Decoder utf8Decode = encoder.GetDecoder(); + + byte[] todecode_byte = Convert.FromBase64String(str); + int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); + char[] decoded_char = new char[charCount]; + utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); + string result = new String(decoded_char); + return result; + } } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index e32f1b4c22..b01a4aa4b7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -6824,16 +6824,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_String llBase64ToString(string str) { m_host.AddScriptLPS(1); - UTF8Encoding encoder = new UTF8Encoding(); - Decoder utf8Decode = encoder.GetDecoder(); try { - byte[] todecode_byte = Convert.FromBase64String(str); - int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); - char[] decoded_char = new char[charCount]; - utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); - string result = new String(decoded_char); - return result; + return Util.Base64ToString(str); } catch (Exception e) { @@ -6841,6 +6834,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } + public LSL_String llXorBase64Strings(string str1, string str2) { m_host.AddScriptLPS(1);