* Refactored out and de-duplicated Base64ToString(string)

* Fixed minor typo
0.6.5-rc1
lbsa71 2009-03-31 05:51:28 +00:00
parent 20e1a8d7f6
commit fb9a358b79
4 changed files with 27 additions and 25 deletions

View File

@ -444,15 +444,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
public static string Base64ToString(string str) public static string Base64ToString(string str)
{ {
UTF8Encoding encoder = new UTF8Encoding();
Decoder utf8Decode = encoder.GetDecoder();
try try
{ {
byte[] todecode_byte = Convert.FromBase64String(str); return Util.Base64ToString(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);
} }
catch catch
{ {

View File

@ -34,6 +34,7 @@ using log4net;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.Packets; using OpenMetaverse.Packets;
using OpenSim.Framework.Statistics; using OpenSim.Framework.Statistics;
using System.Text;
namespace OpenSim.Framework.Communications.Cache namespace OpenSim.Framework.Communications.Cache
{ {
@ -334,7 +335,7 @@ namespace OpenSim.Framework.Communications.Cache
{ {
AssetInfo assetInf = new AssetInfo(asset); AssetInfo assetInf = new AssetInfo(asset);
ProcessRecievedAsset(IsTexture, assetInf); ProcessReceivedAsset(IsTexture, assetInf);
if (!m_memcache.Contains(assetInf.FullID)) 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 // See IAssetReceiver

View File

@ -342,7 +342,7 @@ namespace OpenSim.Framework
/// <returns></returns> /// <returns></returns>
public static string Md5Hash(string pass) public static string Md5Hash(string pass)
{ {
MD5 md5 = MD5CryptoServiceProvider.Create(); MD5 md5 = MD5.Create();
byte[] dataMd5 = md5.ComputeHash(Encoding.Default.GetBytes(pass)); byte[] dataMd5 = md5.ComputeHash(Encoding.Default.GetBytes(pass));
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < dataMd5.Length; i++) for (int i = 0; i < dataMd5.Length; i++)
@ -419,7 +419,7 @@ namespace OpenSim.Framework
output.Append(": "); 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 else
{ {
@ -532,7 +532,7 @@ namespace OpenSim.Framework
/// <returns>safe path</returns> /// <returns>safe path</returns>
public static string safePath(string path) public static string safePath(string path)
{ {
return Regex.Replace(path, @regexInvalidPathChars, string.Empty); return Regex.Replace(path, regexInvalidPathChars, String.Empty);
} }
/// <summary> /// <summary>
@ -542,7 +542,7 @@ namespace OpenSim.Framework
/// <returns>safe filename</returns> /// <returns>safe filename</returns>
public static string safeFileName(string 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); FileInfo f = new FileInfo(FileName);
if (!string.IsNullOrEmpty(f.Extension)) if (!String.IsNullOrEmpty(f.Extension))
{ {
Name = f.FullName.Substring(0, f.FullName.LastIndexOf('.')); Name = f.FullName.Substring(0, f.FullName.LastIndexOf('.'));
} }
@ -959,7 +959,7 @@ namespace OpenSim.Framework
} }
else if (fieldInfo.FieldType == typeof(System.UInt32)) 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)) 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; 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;
}
} }
} }

View File

@ -6824,16 +6824,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_String llBase64ToString(string str) public LSL_String llBase64ToString(string str)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
UTF8Encoding encoder = new UTF8Encoding();
Decoder utf8Decode = encoder.GetDecoder();
try try
{ {
byte[] todecode_byte = Convert.FromBase64String(str); return Util.Base64ToString(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;
} }
catch (Exception e) catch (Exception e)
{ {
@ -6841,6 +6834,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
} }
} }
public LSL_String llXorBase64Strings(string str1, string str2) public LSL_String llXorBase64Strings(string str1, string str2)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);