aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Capabilities
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Capabilities')
-rw-r--r--OpenSim/Region/Capabilities/Caps.cs336
-rw-r--r--OpenSim/Region/Capabilities/LLSDArray.cs42
-rw-r--r--OpenSim/Region/Capabilities/LLSDCapEvent.cs41
-rw-r--r--OpenSim/Region/Capabilities/LLSDCapsDetails.cs15
-rw-r--r--OpenSim/Region/Capabilities/LLSDEmpty.cs38
-rw-r--r--OpenSim/Region/Capabilities/LLSDHelpers.cs164
-rw-r--r--OpenSim/Region/Capabilities/LLSDMapLayer.cs46
-rw-r--r--OpenSim/Region/Capabilities/LLSDMapLayerResponse.cs41
-rw-r--r--OpenSim/Region/Capabilities/LLSDMapRequest.cs13
-rw-r--r--OpenSim/Region/Capabilities/LLSDMethod.cs8
-rw-r--r--OpenSim/Region/Capabilities/LLSDStreamHandler.cs42
-rw-r--r--OpenSim/Region/Capabilities/LLSDTest.cs41
-rw-r--r--OpenSim/Region/Capabilities/LLSDType.cs59
-rw-r--r--OpenSim/Region/Capabilities/LLSDUploadReply.cs44
14 files changed, 930 insertions, 0 deletions
diff --git a/OpenSim/Region/Capabilities/Caps.cs b/OpenSim/Region/Capabilities/Caps.cs
new file mode 100644
index 0000000..6068076
--- /dev/null
+++ b/OpenSim/Region/Capabilities/Caps.cs
@@ -0,0 +1,336 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
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* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Text;
32using libsecondlife;
33using OpenSim.Framework.Servers;
34using OpenSim.Framework.Types;
35using OpenSim.Framework.Utilities;
36using OpenSim.Region.Caches;
37
38namespace OpenSim.Region.Capabilities
39{
40 public delegate void UpLoadedTexture(LLUUID assetID, LLUUID inventoryItem, byte[] data);
41
42 public class Caps
43 {
44 private string m_httpListenerHostName;
45 private int m_httpListenPort;
46 private string m_capsObjectPath = "00001-";
47 private string m_requestPath = "0000/";
48 private string m_mapLayerPath = "0001/";
49 private string m_newInventory = "0002/";
50 private string m_requestTexture = "0003/";
51 private string eventQueue = "0100/";
52 private BaseHttpServer httpListener;
53 private LLUUID agentID;
54 private AssetCache assetCache;
55 private int eventQueueCount = 1;
56 private Queue<string> CapsEventQueue = new Queue<string>();
57
58 public Caps(AssetCache assetCach, BaseHttpServer httpServer, string httpListen, int httpPort, string capsPath, LLUUID agent)
59 {
60 assetCache = assetCach;
61 m_capsObjectPath = capsPath;
62 httpListener = httpServer;
63 m_httpListenerHostName = httpListen;
64 m_httpListenPort = httpPort;
65 agentID = agent;
66 }
67
68 /// <summary>
69 ///
70 /// </summary>
71 public void RegisterHandlers()
72 {
73 Console.WriteLine("registering CAPS handlers");
74 string capsBase = "/CAPS/" + m_capsObjectPath;
75
76
77 //AddLegacyCapsHandler( httpListener, m_mapLayerPath, MapLayer);
78
79 httpListener.AddStreamHandler(
80 new LLSDStreamhandler<LLSDMapRequest, LLSDMapLayerResponse>("POST", capsBase + m_mapLayerPath, this.GetMapLayer ));
81
82 AddLegacyCapsHandler(httpListener, m_requestPath, CapsRequest);
83 AddLegacyCapsHandler(httpListener, m_newInventory, NewAgentInventory);
84 AddLegacyCapsHandler( httpListener, eventQueue, ProcessEventQueue);
85 AddLegacyCapsHandler( httpListener, m_requestTexture, RequestTexture);
86
87 }
88
89 [Obsolete("Use BaseHttpServer.AddStreamHandler(new LLSDStreamHandler( LLSDMethod delegate )) instead.")]
90 private void AddLegacyCapsHandler(BaseHttpServer httpListener, string path, RestMethod restMethod)
91 {
92 string capsBase = "/CAPS/" + m_capsObjectPath;
93 httpListener.AddStreamHandler(new RestStreamHandler("POST", capsBase + path, restMethod));
94 }
95
96 /// <summary>
97 ///
98 /// </summary>
99 /// <param name="request"></param>
100 /// <param name="path"></param>
101 /// <param name="param"></param>
102 /// <returns></returns>
103 public string CapsRequest(string request, string path, string param)
104 {
105 // Console.WriteLine("Caps Request " + request);
106 string result = "";
107 result = LLSDHelpers.SerialiseLLSDReply(this.GetCapabilities());
108 return result;
109 }
110
111 /// <summary>
112 ///
113 /// </summary>
114 /// <returns></returns>
115 protected LLSDCapsDetails GetCapabilities()
116 {
117 LLSDCapsDetails caps = new LLSDCapsDetails();
118 string capsBaseUrl = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + m_capsObjectPath;
119
120 caps.MapLayer = capsBaseUrl + m_mapLayerPath;
121 // caps.NewFileAgentInventory = capsBaseUrl + m_newInventory;
122
123 return caps;
124 }
125
126 /// <summary>
127 ///
128 /// </summary>
129 /// <param name="request"></param>
130 /// <param name="path"></param>
131 /// <param name="param"></param>
132 /// <returns></returns>
133 public string MapLayer(string request, string path, string param)
134 {
135 Encoding _enc = Encoding.UTF8;
136 Hashtable hash = (Hashtable)LLSD.LLSDDeserialize(_enc.GetBytes(request));
137 LLSDMapRequest mapReq = new LLSDMapRequest();
138 LLSDHelpers.DeserialiseLLSDMap(hash, mapReq);
139
140 LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse();
141 mapResponse.LayerData.Array.Add(this.BuildLLSDMapLayerResponse());
142 string res = LLSDHelpers.SerialiseLLSDReply(mapResponse);
143
144 return res;
145 }
146
147 public LLSDMapLayerResponse GetMapLayer(LLSDMapRequest mapReq)
148 {
149 LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse();
150 mapResponse.LayerData.Array.Add(this.BuildLLSDMapLayerResponse());
151 return mapResponse;
152 }
153
154
155 /// <summary>
156 ///
157 /// </summary>
158 /// <returns></returns>
159 protected LLSDMapLayer BuildLLSDMapLayerResponse()
160 {
161 LLSDMapLayer mapLayer = new LLSDMapLayer();
162 mapLayer.Right = 5000;
163 mapLayer.Top = 5000;
164 mapLayer.ImageID = new LLUUID("00000000-0000-0000-9999-000000000006");
165
166 return mapLayer;
167 }
168
169 /// <summary>
170 ///
171 /// </summary>
172 /// <param name="request"></param>
173 /// <param name="path"></param>
174 /// <param name="param"></param>
175 /// <returns></returns>
176 public string RequestTexture(string request, string path, string param)
177 {
178 // Needs implementing (added to remove compiler warning)
179 return "";
180 }
181
182 /// <summary>
183 ///
184 /// </summary>
185 /// <param name="request"></param>
186 /// <param name="path"></param>
187 /// <param name="param"></param>
188 /// <returns></returns>
189 public string ProcessEventQueue(string request, string path, string param)
190 {
191 string res = "";
192
193 if (this.CapsEventQueue.Count > 0)
194 {
195 lock (this.CapsEventQueue)
196 {
197 string item = CapsEventQueue.Dequeue();
198 res = item;
199 }
200 }
201 else
202 {
203 res = this.CreateEmptyEventResponse();
204 }
205 return res;
206 }
207
208 /// <summary>
209 ///
210 /// </summary>
211 /// <param name="caps"></param>
212 /// <param name="ipAddressPort"></param>
213 /// <returns></returns>
214 public string CreateEstablishAgentComms(string caps, string ipAddressPort)
215 {
216 LLSDCapEvent eventItem = new LLSDCapEvent();
217 eventItem.id = eventQueueCount;
218 //should be creating a EstablishAgentComms item, but there isn't a class for it yet
219 eventItem.events.Array.Add(new LLSDEmpty());
220 string res = LLSDHelpers.SerialiseLLSDReply(eventItem);
221 eventQueueCount++;
222
223 this.CapsEventQueue.Enqueue(res);
224 return res;
225 }
226
227 /// <summary>
228 ///
229 /// </summary>
230 /// <returns></returns>
231 public string CreateEmptyEventResponse()
232 {
233 LLSDCapEvent eventItem = new LLSDCapEvent();
234 eventItem.id = eventQueueCount;
235 eventItem.events.Array.Add(new LLSDEmpty());
236 string res = LLSDHelpers.SerialiseLLSDReply(eventItem);
237 eventQueueCount++;
238 return res;
239 }
240
241 /// <summary>
242 ///
243 /// </summary>
244 /// <param name="request"></param>
245 /// <param name="path"></param>
246 /// <param name="param"></param>
247 /// <returns></returns>
248 public string NewAgentInventory(string request, string path, string param)
249 {
250 //Console.WriteLine("received upload request:"+ request);
251 string res = "";
252 LLUUID newAsset = LLUUID.Random();
253 LLUUID newInvItem = LLUUID.Random();
254 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
255 AssetUploader uploader = new AssetUploader(newAsset, newInvItem, uploaderPath, this.httpListener);
256
257 AddLegacyCapsHandler( httpListener, uploaderPath, uploader.uploaderCaps);
258
259 string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + uploaderPath;
260 //Console.WriteLine("uploader url is " + uploaderURL);
261 res += "<llsd><map>";
262 res += "<key>uploader</key><string>" + uploaderURL + "</string>";
263 //res += "<key>success</key><boolean>true</boolean>";
264 res += "<key>state</key><string>upload</string>";
265 res += "</map></llsd>";
266 uploader.OnUpLoad += this.UploadHandler;
267 return res;
268 }
269
270 /// <summary>
271 ///
272 /// </summary>
273 /// <param name="assetID"></param>
274 /// <param name="inventoryItem"></param>
275 /// <param name="data"></param>
276 public void UploadHandler(LLUUID assetID, LLUUID inventoryItem, byte[] data)
277 {
278 // Console.WriteLine("upload handler called");
279 AssetBase asset;
280 asset = new AssetBase();
281 asset.FullID = assetID;
282 asset.Type = 0;
283 asset.InvType = 0;
284 asset.Name = "UploadedTexture" + Util.RandomClass.Next(1, 1000).ToString("000");
285 asset.Data = data;
286 this.assetCache.AddAsset(asset);
287 }
288
289 public class AssetUploader
290 {
291 public event UpLoadedTexture OnUpLoad;
292
293 private string uploaderPath = "";
294 private LLUUID newAssetID;
295 private LLUUID inventoryItemID;
296 private BaseHttpServer httpListener;
297 public AssetUploader(LLUUID assetID, LLUUID inventoryItem, string path, BaseHttpServer httpServer)
298 {
299 newAssetID = assetID;
300 inventoryItemID = inventoryItem;
301 uploaderPath = path;
302 httpListener = httpServer;
303
304 }
305
306 public string uploaderCaps(string request, string path, string param)
307 {
308 Encoding _enc = Encoding.UTF8;
309 byte[] data = _enc.GetBytes(request);
310 //Console.WriteLine("recieved upload " + Util.FieldToString(data));
311 LLUUID inv = this.inventoryItemID;
312 string res = "";
313 res += "<llsd><map>";
314 res += "<key>new_asset</key><string>" + newAssetID.ToStringHyphenated() + "</string>";
315 res += "<key>new_inventory_item</key><uuid>" + inv.ToStringHyphenated() + "</uuid>";
316 res += "<key>state</key><string>complete</string>";
317 res += "</map></llsd>";
318
319 // Console.WriteLine("asset " + newAssetID.ToStringHyphenated() + " , inventory item " + inv.ToStringHyphenated());
320 httpListener.RemoveStreamHandler("POST", "/CAPS/" + uploaderPath);
321
322 if (OnUpLoad != null)
323 {
324 OnUpLoad(newAssetID, inv, data);
325 }
326
327 /*FileStream fs = File.Create("upload.jp2");
328 BinaryWriter bw = new BinaryWriter(fs);
329 bw.Write(data);
330 bw.Close();
331 fs.Close();*/
332 return res;
333 }
334 }
335 }
336}
diff --git a/OpenSim/Region/Capabilities/LLSDArray.cs b/OpenSim/Region/Capabilities/LLSDArray.cs
new file mode 100644
index 0000000..e04849f
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDArray.cs
@@ -0,0 +1,42 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
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* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System.Collections;
29
30namespace OpenSim.Region.Capabilities
31{
32 [LLSDType("ARRAY")]
33 public class LLSDArray
34 {
35 public ArrayList Array = new ArrayList();
36
37 public LLSDArray()
38 {
39
40 }
41 }
42}
diff --git a/OpenSim/Region/Capabilities/LLSDCapEvent.cs b/OpenSim/Region/Capabilities/LLSDCapEvent.cs
new file mode 100644
index 0000000..51b4fe0
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDCapEvent.cs
@@ -0,0 +1,41 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
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* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28namespace OpenSim.Region.Capabilities
29{
30 [LLSDType("MAP")]
31 public class LLSDCapEvent
32 {
33 public int id = 0;
34 public LLSDArray events = new LLSDArray();
35
36 public LLSDCapEvent()
37 {
38
39 }
40 }
41}
diff --git a/OpenSim/Region/Capabilities/LLSDCapsDetails.cs b/OpenSim/Region/Capabilities/LLSDCapsDetails.cs
new file mode 100644
index 0000000..1f8b242
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDCapsDetails.cs
@@ -0,0 +1,15 @@
1namespace OpenSim.Region.Capabilities
2{
3 [LLSDType("MAP")]
4 public class LLSDCapsDetails
5 {
6 public string MapLayer = "";
7 //public string NewFileAgentInventory = "";
8 //public string EventQueueGet = "";
9
10 public LLSDCapsDetails()
11 {
12
13 }
14 }
15}
diff --git a/OpenSim/Region/Capabilities/LLSDEmpty.cs b/OpenSim/Region/Capabilities/LLSDEmpty.cs
new file mode 100644
index 0000000..d79c09e
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDEmpty.cs
@@ -0,0 +1,38 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
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* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28namespace OpenSim.Region.Capabilities
29{
30 [LLSDType("MAP")]
31 public class LLSDEmpty
32 {
33 public LLSDEmpty()
34 {
35
36 }
37 }
38}
diff --git a/OpenSim/Region/Capabilities/LLSDHelpers.cs b/OpenSim/Region/Capabilities/LLSDHelpers.cs
new file mode 100644
index 0000000..19ef0c9
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDHelpers.cs
@@ -0,0 +1,164 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
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* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections;
30using System.IO;
31using System.Reflection;
32using System.Xml;
33using libsecondlife;
34
35namespace OpenSim.Region.Capabilities
36{
37 public class LLSDHelpers
38 {
39 public static string SerialiseLLSDReply(object obj)
40 {
41 StringWriter sw = new StringWriter();
42 XmlTextWriter writer = new XmlTextWriter(sw);
43 writer.Formatting = Formatting.None;
44 writer.WriteStartElement(String.Empty, "llsd", String.Empty);
45 SerializeLLSDType(writer, obj);
46 writer.WriteEndElement();
47 writer.Close();
48 return sw.ToString();
49 }
50
51 public static void SerializeLLSDType(XmlTextWriter writer, object obj)
52 {
53 Type myType = obj.GetType();
54 LLSDType[] llsdattributes = (LLSDType[])myType.GetCustomAttributes(typeof(LLSDType), false);
55 if (llsdattributes.Length > 0)
56 {
57 switch (llsdattributes[0].ObjectType)
58 {
59 case "MAP":
60 writer.WriteStartElement(String.Empty, "map", String.Empty);
61 FieldInfo[] fields = myType.GetFields();
62 for (int i = 0; i < fields.Length; i++)
63 {
64 object fieldValue = fields[i].GetValue(obj);
65 LLSDType[] fieldAttributes = (LLSDType[])fieldValue.GetType().GetCustomAttributes(typeof(LLSDType), false);
66 if (fieldAttributes.Length > 0)
67 {
68 writer.WriteStartElement(String.Empty, "key", String.Empty);
69 writer.WriteString(fields[i].Name);
70 writer.WriteEndElement();
71 SerializeLLSDType(writer, fieldValue);
72 }
73 else
74 {
75 writer.WriteStartElement(String.Empty, "key", String.Empty);
76 writer.WriteString(fields[i].Name);
77 writer.WriteEndElement();
78 LLSD.LLSDWriteOne(writer, fieldValue);
79 }
80 }
81 writer.WriteEndElement();
82 break;
83 case "ARRAY":
84 // LLSDArray arrayObject = obj as LLSDArray;
85 // ArrayList a = arrayObject.Array;
86 ArrayList a = (ArrayList)obj.GetType().GetField("Array").GetValue(obj);
87 if (a != null)
88 {
89 writer.WriteStartElement(String.Empty, "array", String.Empty);
90 foreach (object item in a)
91 {
92 SerializeLLSDType(writer, item);
93 }
94 writer.WriteEndElement();
95 }
96 break;
97 }
98 }
99 else
100 {
101 LLSD.LLSDWriteOne(writer, obj);
102 }
103 }
104
105 public static object DeserialiseLLSDMap(Hashtable llsd, object obj)
106 {
107 Type myType = obj.GetType();
108 LLSDType[] llsdattributes = (LLSDType[])myType.GetCustomAttributes(typeof(LLSDType), false);
109 if (llsdattributes.Length > 0)
110 {
111 switch (llsdattributes[0].ObjectType)
112 {
113 case "MAP":
114 IDictionaryEnumerator enumerator = llsd.GetEnumerator();
115 while (enumerator.MoveNext())
116 {
117 FieldInfo field = myType.GetField((string)enumerator.Key);
118 if (field != null)
119 {
120 if (enumerator.Value is Hashtable)
121 {
122 object fieldValue = field.GetValue(obj);
123 DeserialiseLLSDMap((Hashtable) enumerator.Value, fieldValue);
124 }
125 else if (enumerator.Value is ArrayList)
126 {
127 object fieldValue = field.GetValue(obj);
128 fieldValue.GetType().GetField("Array").SetValue(fieldValue, enumerator.Value);
129 //TODO
130 // the LLSD map/array types in the array need to be deserialised
131 // but first we need to know the right class to deserialise them into.
132 }
133 else
134 {
135 field.SetValue(obj, enumerator.Value);
136 }
137 }
138 }
139 break;
140 }
141 }
142 return obj;
143 }
144 }
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164}
diff --git a/OpenSim/Region/Capabilities/LLSDMapLayer.cs b/OpenSim/Region/Capabilities/LLSDMapLayer.cs
new file mode 100644
index 0000000..566d0e9
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDMapLayer.cs
@@ -0,0 +1,46 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
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* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using libsecondlife;
29
30namespace OpenSim.Region.Capabilities
31{
32 [LLSDType("MAP")]
33 public class LLSDMapLayer
34 {
35 public int Left = 0;
36 public int Right = 0;
37 public int Top = 0;
38 public int Bottom = 0;
39 public LLUUID ImageID = LLUUID.Zero;
40
41 public LLSDMapLayer()
42 {
43
44 }
45 }
46}
diff --git a/OpenSim/Region/Capabilities/LLSDMapLayerResponse.cs b/OpenSim/Region/Capabilities/LLSDMapLayerResponse.cs
new file mode 100644
index 0000000..ce746ae
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDMapLayerResponse.cs
@@ -0,0 +1,41 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
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* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28namespace OpenSim.Region.Capabilities
29{
30 [LLSDType("MAP")]
31 public class LLSDMapLayerResponse
32 {
33 public LLSDMapRequest AgentData = new LLSDMapRequest();
34 public LLSDArray LayerData = new LLSDArray();
35
36 public LLSDMapLayerResponse()
37 {
38
39 }
40 }
41}
diff --git a/OpenSim/Region/Capabilities/LLSDMapRequest.cs b/OpenSim/Region/Capabilities/LLSDMapRequest.cs
new file mode 100644
index 0000000..fb739cd
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDMapRequest.cs
@@ -0,0 +1,13 @@
1namespace OpenSim.Region.Capabilities
2{
3 [LLSDType("MAP")]
4 public class LLSDMapRequest
5 {
6 public int Flags = 0;
7
8 public LLSDMapRequest()
9 {
10
11 }
12 }
13}
diff --git a/OpenSim/Region/Capabilities/LLSDMethod.cs b/OpenSim/Region/Capabilities/LLSDMethod.cs
new file mode 100644
index 0000000..5f42f44
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDMethod.cs
@@ -0,0 +1,8 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.Capabilities
6{
7 public delegate TResponse LLSDMethod<TRequest, TResponse>(TRequest request);
8}
diff --git a/OpenSim/Region/Capabilities/LLSDStreamHandler.cs b/OpenSim/Region/Capabilities/LLSDStreamHandler.cs
new file mode 100644
index 0000000..7d99b6e
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDStreamHandler.cs
@@ -0,0 +1,42 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenSim.Framework.Servers;
5using System.IO;
6using System.Collections;
7using libsecondlife;
8
9namespace OpenSim.Region.Capabilities
10{
11 public class LLSDStreamhandler<TRequest, TResponse> : BaseStreamHandler
12 where TRequest : new()
13 {
14 private LLSDMethod<TRequest, TResponse> m_method;
15
16 public LLSDStreamhandler(string httpMethod, string path, LLSDMethod<TRequest, TResponse> method)
17 : base(httpMethod, path )
18 {
19 m_method = method;
20 }
21
22 public override byte[] Handle(string path, Stream request)
23 {
24 //Encoding encoding = Encoding.UTF8;
25 //StreamReader streamReader = new StreamReader(request, false);
26
27 //string requestBody = streamReader.ReadToEnd();
28 //streamReader.Close();
29
30 Hashtable hash = (Hashtable)LLSD.LLSDDeserialize( request );
31 TRequest llsdRequest = new TRequest();
32 LLSDHelpers.DeserialiseLLSDMap(hash, llsdRequest);
33
34 TResponse response = m_method(llsdRequest);
35
36 Encoding encoding = new UTF8Encoding(false);
37
38 return encoding.GetBytes( LLSDHelpers.SerialiseLLSDReply(response) );
39
40 }
41 }
42}
diff --git a/OpenSim/Region/Capabilities/LLSDTest.cs b/OpenSim/Region/Capabilities/LLSDTest.cs
new file mode 100644
index 0000000..f23e327
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDTest.cs
@@ -0,0 +1,41 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
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* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28namespace OpenSim.Region.Capabilities
29{
30 [LLSDType("MAP")]
31 public class LLSDTest
32 {
33 public int Test1 = 20;
34 public int Test2 = 10;
35
36 public LLSDTest()
37 {
38
39 }
40 }
41}
diff --git a/OpenSim/Region/Capabilities/LLSDType.cs b/OpenSim/Region/Capabilities/LLSDType.cs
new file mode 100644
index 0000000..c58a937
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDType.cs
@@ -0,0 +1,59 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
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* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29
30namespace OpenSim.Region.Capabilities
31{
32 [AttributeUsage(AttributeTargets.Class)]
33 public class LLSDType : Attribute
34 {
35 protected string myType;
36
37 public LLSDType(string type)
38 {
39 myType = type;
40
41 }
42
43 public string ObjectType
44 {
45 get
46 {
47 return myType;
48 }
49 }
50 }
51
52 [AttributeUsage(AttributeTargets.Class)]
53 public class LLSDMap : LLSDType
54 {
55 public LLSDMap() : base( "MAP" )
56 {
57 }
58 }
59}
diff --git a/OpenSim/Region/Capabilities/LLSDUploadReply.cs b/OpenSim/Region/Capabilities/LLSDUploadReply.cs
new file mode 100644
index 0000000..023a056
--- /dev/null
+++ b/OpenSim/Region/Capabilities/LLSDUploadReply.cs
@@ -0,0 +1,44 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
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* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using libsecondlife;
29
30namespace OpenSim.Region.Capabilities
31{
32 [LLSDType("MAP")]
33 public class LLSDUploadReply
34 {
35 public string new_asset = "";
36 public LLUUID new_inventory_item = LLUUID.Zero;
37 public string state = "";
38
39 public LLSDUploadReply()
40 {
41
42 }
43 }
44}