corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) 2006-2014, openmetaverse.org
3 * All rights reserved.
4 *
5 * - Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * - Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * - Neither the name of the openmetaverse.org nor the names
11 * of its contributors may be used to endorse or promote products derived from
12 * this software without specific prior written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
26  
27 using System;
28 using System.Collections.Generic;
29 using System.Net;
30 using OpenMetaverse.StructuredData;
31  
32 namespace OpenMetaverse.Messages
33 {
34 public static partial class MessageUtils
35 {
36 public static IPAddress ToIP(OSD osd)
37 {
38 byte[] binary = osd.AsBinary();
39 if (binary != null && binary.Length == 4)
40 return new IPAddress(binary);
41 else
42 return IPAddress.Any;
43 }
44  
45 public static OSD FromIP(IPAddress address)
46 {
47 if (address != null && address != IPAddress.Any)
48 return OSD.FromBinary(address.GetAddressBytes());
49 else
50 return new OSD();
51 }
52  
53 public static Dictionary<string, string> ToDictionaryString(OSD osd)
54 {
55 if (osd.Type == OSDType.Map)
56 {
57 OSDMap map = (OSDMap)osd;
58 Dictionary<string, string> dict = new Dictionary<string, string>(map.Count);
59 foreach (KeyValuePair<string, OSD> entry in map)
60 dict.Add(entry.Key, entry.Value.AsString());
61 return dict;
62 }
63  
64 return new Dictionary<string, string>(0);
65 }
66  
67 public static Dictionary<Uri, Uri> ToDictionaryUri(OSD osd)
68 {
69 if (osd.Type == OSDType.Map)
70 {
71 OSDMap map = (OSDMap)osd;
72 Dictionary<Uri, Uri> dict = new Dictionary<Uri, Uri>(map.Count);
73 foreach (KeyValuePair<string, OSD> entry in map)
74 dict.Add(new Uri(entry.Key), entry.Value.AsUri());
75 return dict;
76 }
77  
78 return new Dictionary<Uri, Uri>(0);
79 }
80  
81 public static OSDMap FromDictionaryString(Dictionary<string, string> dict)
82 {
83 if (dict != null)
84 {
85 OSDMap map = new OSDMap(dict.Count);
86 foreach (KeyValuePair<string, string> entry in dict)
87 map.Add(entry.Key, OSD.FromString(entry.Value));
88 return map;
89 }
90  
91 return new OSDMap(0);
92 }
93  
94 public static OSDMap FromDictionaryUri(Dictionary<Uri, Uri> dict)
95 {
96 if (dict != null)
97 {
98 OSDMap map = new OSDMap(dict.Count);
99 foreach (KeyValuePair<Uri, Uri> entry in dict)
100 map.Add(entry.Key.ToString(), OSD.FromUri(entry.Value));
101 return map;
102 }
103  
104 return new OSDMap(0);
105 }
106 }
107 }