diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Util.cs | 154 |
1 files changed, 137 insertions, 17 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index a3602e9..f520a01 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -516,19 +516,25 @@ namespace OpenSim.Framework | |||
516 | /// </summary> | 516 | /// </summary> |
517 | /// <param name="data"></param> | 517 | /// <param name="data"></param> |
518 | /// <returns></returns> | 518 | /// <returns></returns> |
519 | |||
519 | public static string Md5Hash(string data) | 520 | public static string Md5Hash(string data) |
520 | { | 521 | { |
521 | byte[] dataMd5 = ComputeMD5Hash(data); | 522 | return Md5Hash(data, Encoding.Default); |
523 | } | ||
524 | |||
525 | public static string Md5Hash(string data, Encoding encoding) | ||
526 | { | ||
527 | byte[] dataMd5 = ComputeMD5Hash(data, encoding); | ||
522 | StringBuilder sb = new StringBuilder(); | 528 | StringBuilder sb = new StringBuilder(); |
523 | for (int i = 0; i < dataMd5.Length; i++) | 529 | for (int i = 0; i < dataMd5.Length; i++) |
524 | sb.AppendFormat("{0:x2}", dataMd5[i]); | 530 | sb.AppendFormat("{0:x2}", dataMd5[i]); |
525 | return sb.ToString(); | 531 | return sb.ToString(); |
526 | } | 532 | } |
527 | 533 | ||
528 | private static byte[] ComputeMD5Hash(string data) | 534 | private static byte[] ComputeMD5Hash(string data, Encoding encoding) |
529 | { | 535 | { |
530 | MD5 md5 = MD5.Create(); | 536 | MD5 md5 = MD5.Create(); |
531 | return md5.ComputeHash(Encoding.Default.GetBytes(data)); | 537 | return md5.ComputeHash(encoding.GetBytes(data)); |
532 | } | 538 | } |
533 | 539 | ||
534 | /// <summary> | 540 | /// <summary> |
@@ -536,6 +542,12 @@ namespace OpenSim.Framework | |||
536 | /// </summary> | 542 | /// </summary> |
537 | /// <param name="data"></param> | 543 | /// <param name="data"></param> |
538 | /// <returns></returns> | 544 | /// <returns></returns> |
545 | |||
546 | public static string SHA1Hash(string data, Encoding enc) | ||
547 | { | ||
548 | return SHA1Hash(enc.GetBytes(data)); | ||
549 | } | ||
550 | |||
539 | public static string SHA1Hash(string data) | 551 | public static string SHA1Hash(string data) |
540 | { | 552 | { |
541 | return SHA1Hash(Encoding.Default.GetBytes(data)); | 553 | return SHA1Hash(Encoding.Default.GetBytes(data)); |
@@ -1277,19 +1289,19 @@ namespace OpenSim.Framework | |||
1277 | { | 1289 | { |
1278 | string os = String.Empty; | 1290 | string os = String.Empty; |
1279 | 1291 | ||
1280 | if (Environment.OSVersion.Platform != PlatformID.Unix) | 1292 | // if (Environment.OSVersion.Platform != PlatformID.Unix) |
1281 | { | 1293 | // { |
1282 | os = Environment.OSVersion.ToString(); | 1294 | // os = Environment.OSVersion.ToString(); |
1283 | } | 1295 | // } |
1284 | else | 1296 | // else |
1285 | { | 1297 | // { |
1286 | os = ReadEtcIssue(); | 1298 | // os = ReadEtcIssue(); |
1287 | } | 1299 | // } |
1288 | 1300 | // | |
1289 | if (os.Length > 45) | 1301 | // if (os.Length > 45) |
1290 | { | 1302 | // { |
1291 | os = os.Substring(0, 45); | 1303 | // os = os.Substring(0, 45); |
1292 | } | 1304 | // } |
1293 | 1305 | ||
1294 | return os; | 1306 | return os; |
1295 | } | 1307 | } |
@@ -1421,7 +1433,7 @@ namespace OpenSim.Framework | |||
1421 | 1433 | ||
1422 | public static Guid GetHashGuid(string data, string salt) | 1434 | public static Guid GetHashGuid(string data, string salt) |
1423 | { | 1435 | { |
1424 | byte[] hash = ComputeMD5Hash(data + salt); | 1436 | byte[] hash = ComputeMD5Hash(data + salt, Encoding.Default); |
1425 | 1437 | ||
1426 | //string s = BitConverter.ToString(hash); | 1438 | //string s = BitConverter.ToString(hash); |
1427 | 1439 | ||
@@ -2233,4 +2245,112 @@ namespace OpenSim.Framework | |||
2233 | return str.Replace("_", "\\_").Replace("%", "\\%"); | 2245 | return str.Replace("_", "\\_").Replace("%", "\\%"); |
2234 | } | 2246 | } |
2235 | } | 2247 | } |
2248 | |||
2249 | public class DoubleQueue<T> where T:class | ||
2250 | { | ||
2251 | private Queue<T> m_lowQueue = new Queue<T>(); | ||
2252 | private Queue<T> m_highQueue = new Queue<T>(); | ||
2253 | |||
2254 | private object m_syncRoot = new object(); | ||
2255 | private Semaphore m_s = new Semaphore(0, 1); | ||
2256 | |||
2257 | public DoubleQueue() | ||
2258 | { | ||
2259 | } | ||
2260 | |||
2261 | public virtual int Count | ||
2262 | { | ||
2263 | get { return m_highQueue.Count + m_lowQueue.Count; } | ||
2264 | } | ||
2265 | |||
2266 | public virtual void Enqueue(T data) | ||
2267 | { | ||
2268 | Enqueue(m_lowQueue, data); | ||
2269 | } | ||
2270 | |||
2271 | public virtual void EnqueueLow(T data) | ||
2272 | { | ||
2273 | Enqueue(m_lowQueue, data); | ||
2274 | } | ||
2275 | |||
2276 | public virtual void EnqueueHigh(T data) | ||
2277 | { | ||
2278 | Enqueue(m_highQueue, data); | ||
2279 | } | ||
2280 | |||
2281 | private void Enqueue(Queue<T> q, T data) | ||
2282 | { | ||
2283 | lock (m_syncRoot) | ||
2284 | { | ||
2285 | m_lowQueue.Enqueue(data); | ||
2286 | m_s.WaitOne(0); | ||
2287 | m_s.Release(); | ||
2288 | } | ||
2289 | } | ||
2290 | |||
2291 | public virtual T Dequeue() | ||
2292 | { | ||
2293 | return Dequeue(Timeout.Infinite); | ||
2294 | } | ||
2295 | |||
2296 | public virtual T Dequeue(int tmo) | ||
2297 | { | ||
2298 | return Dequeue(TimeSpan.FromMilliseconds(tmo)); | ||
2299 | } | ||
2300 | |||
2301 | public virtual T Dequeue(TimeSpan wait) | ||
2302 | { | ||
2303 | T res = null; | ||
2304 | |||
2305 | if (!Dequeue(wait, ref res)) | ||
2306 | return null; | ||
2307 | |||
2308 | return res; | ||
2309 | } | ||
2310 | |||
2311 | public bool Dequeue(int timeout, ref T res) | ||
2312 | { | ||
2313 | return Dequeue(TimeSpan.FromMilliseconds(timeout), ref res); | ||
2314 | } | ||
2315 | |||
2316 | public bool Dequeue(TimeSpan wait, ref T res) | ||
2317 | { | ||
2318 | if (!m_s.WaitOne(wait)) | ||
2319 | return false; | ||
2320 | |||
2321 | lock (m_syncRoot) | ||
2322 | { | ||
2323 | if (m_highQueue.Count > 0) | ||
2324 | res = m_highQueue.Dequeue(); | ||
2325 | else | ||
2326 | res = m_lowQueue.Dequeue(); | ||
2327 | |||
2328 | if (m_highQueue.Count == 0 && m_lowQueue.Count == 0) | ||
2329 | return true; | ||
2330 | |||
2331 | try | ||
2332 | { | ||
2333 | m_s.Release(); | ||
2334 | } | ||
2335 | catch | ||
2336 | { | ||
2337 | } | ||
2338 | |||
2339 | return true; | ||
2340 | } | ||
2341 | } | ||
2342 | |||
2343 | public virtual void Clear() | ||
2344 | { | ||
2345 | |||
2346 | lock (m_syncRoot) | ||
2347 | { | ||
2348 | // Make sure sem count is 0 | ||
2349 | m_s.WaitOne(0); | ||
2350 | |||
2351 | m_lowQueue.Clear(); | ||
2352 | m_highQueue.Clear(); | ||
2353 | } | ||
2354 | } | ||
2355 | } | ||
2236 | } | 2356 | } |