aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Capabilities/Caps.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Communications/Capabilities/Caps.cs724
1 files changed, 362 insertions, 362 deletions
diff --git a/OpenSim/Framework/Communications/Capabilities/Caps.cs b/OpenSim/Framework/Communications/Capabilities/Caps.cs
index 5aacecb..05fa963 100644
--- a/OpenSim/Framework/Communications/Capabilities/Caps.cs
+++ b/OpenSim/Framework/Communications/Capabilities/Caps.cs
@@ -1,362 +1,362 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32using System.IO; 32using System.IO;
33using libsecondlife; 33using libsecondlife;
34using OpenSim.Framework.Servers; 34using OpenSim.Framework.Servers;
35using OpenSim.Framework.Types; 35using OpenSim.Framework.Types;
36using OpenSim.Framework.Utilities; 36using OpenSim.Framework.Utilities;
37using OpenSim.Framework.Communications.Caches; 37using OpenSim.Framework.Communications.Caches;
38 38
39namespace OpenSim.Region.Capabilities 39namespace OpenSim.Region.Capabilities
40{ 40{
41 public delegate void UpLoadedTexture(string assetName, LLUUID assetID, LLUUID inventoryItem, byte[] data); 41 public delegate void UpLoadedTexture(string assetName, LLUUID assetID, LLUUID inventoryItem, byte[] data);
42 42
43 public class Caps 43 public class Caps
44 { 44 {
45 private string m_httpListenerHostName; 45 private string m_httpListenerHostName;
46 private int m_httpListenPort; 46 private int m_httpListenPort;
47 private string m_capsObjectPath = "00001-"; 47 private string m_capsObjectPath = "00001-";
48 private string m_requestPath = "0000/"; 48 private string m_requestPath = "0000/";
49 private string m_mapLayerPath = "0001/"; 49 private string m_mapLayerPath = "0001/";
50 private string m_newInventory = "0002/"; 50 private string m_newInventory = "0002/";
51 // private string m_requestTexture = "0003/"; 51 // private string m_requestTexture = "0003/";
52 private string m_notecardUpdatePath = "0004/"; 52 private string m_notecardUpdatePath = "0004/";
53 //private string eventQueue = "0100/"; 53 //private string eventQueue = "0100/";
54 private BaseHttpServer httpListener; 54 private BaseHttpServer httpListener;
55 private LLUUID agentID; 55 private LLUUID agentID;
56 private AssetCache assetCache; 56 private AssetCache assetCache;
57 private int eventQueueCount = 1; 57 private int eventQueueCount = 1;
58 private Queue<string> CapsEventQueue = new Queue<string>(); 58 private Queue<string> CapsEventQueue = new Queue<string>();
59 59
60 public Caps(AssetCache assetCach, BaseHttpServer httpServer, string httpListen, int httpPort, string capsPath, LLUUID agent) 60 public Caps(AssetCache assetCach, BaseHttpServer httpServer, string httpListen, int httpPort, string capsPath, LLUUID agent)
61 { 61 {
62 assetCache = assetCach; 62 assetCache = assetCach;
63 m_capsObjectPath = capsPath; 63 m_capsObjectPath = capsPath;
64 httpListener = httpServer; 64 httpListener = httpServer;
65 m_httpListenerHostName = httpListen; 65 m_httpListenerHostName = httpListen;
66 m_httpListenPort = httpPort; 66 m_httpListenPort = httpPort;
67 agentID = agent; 67 agentID = agent;
68 } 68 }
69 69
70 /// <summary> 70 /// <summary>
71 /// 71 ///
72 /// </summary> 72 /// </summary>
73 public void RegisterHandlers() 73 public void RegisterHandlers()
74 { 74 {
75 Console.WriteLine("registering CAPS handlers"); 75 Console.WriteLine("registering CAPS handlers");
76 string capsBase = "/CAPS/" + m_capsObjectPath; 76 string capsBase = "/CAPS/" + m_capsObjectPath;
77 77
78 httpListener.AddStreamHandler(new LLSDStreamhandler<LLSDMapRequest, LLSDMapLayerResponse>("POST", capsBase + m_mapLayerPath, this.GetMapLayer )); 78 httpListener.AddStreamHandler(new LLSDStreamhandler<LLSDMapRequest, LLSDMapLayerResponse>("POST", capsBase + m_mapLayerPath, this.GetMapLayer ));
79 httpListener.AddStreamHandler( new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>("POST", capsBase + m_newInventory, this.NewAgentInventoryRequest)); 79 httpListener.AddStreamHandler( new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>("POST", capsBase + m_newInventory, this.NewAgentInventoryRequest));
80 80
81 AddLegacyCapsHandler(httpListener, m_requestPath, CapsRequest); 81 AddLegacyCapsHandler(httpListener, m_requestPath, CapsRequest);
82 AddLegacyCapsHandler(httpListener, m_notecardUpdatePath, NoteCardAgentInventory); 82 AddLegacyCapsHandler(httpListener, m_notecardUpdatePath, NoteCardAgentInventory);
83 } 83 }
84 84
85 85
86 //[Obsolete("Use BaseHttpServer.AddStreamHandler(new LLSDStreamHandler( LLSDMethod delegate )) instead.")] 86 //[Obsolete("Use BaseHttpServer.AddStreamHandler(new LLSDStreamHandler( LLSDMethod delegate )) instead.")]
87 //Commented out the obsolete as at this time the first caps request can not use the new Caps method 87 //Commented out the obsolete as at this time the first caps request can not use the new Caps method
88 //as the sent type is a array and not a map and the deserialising doesn't deal properly with arrays. 88 //as the sent type is a array and not a map and the deserialising doesn't deal properly with arrays.
89 private void AddLegacyCapsHandler(BaseHttpServer httpListener, string path, RestMethod restMethod) 89 private void AddLegacyCapsHandler(BaseHttpServer httpListener, string path, RestMethod restMethod)
90 { 90 {
91 string capsBase = "/CAPS/" + m_capsObjectPath; 91 string capsBase = "/CAPS/" + m_capsObjectPath;
92 httpListener.AddStreamHandler(new RestStreamHandler("POST", capsBase + path, restMethod)); 92 httpListener.AddStreamHandler(new RestStreamHandler("POST", capsBase + path, restMethod));
93 } 93 }
94 94
95 /// <summary> 95 /// <summary>
96 /// 96 ///
97 /// </summary> 97 /// </summary>
98 /// <param name="request"></param> 98 /// <param name="request"></param>
99 /// <param name="path"></param> 99 /// <param name="path"></param>
100 /// <param name="param"></param> 100 /// <param name="param"></param>
101 /// <returns></returns> 101 /// <returns></returns>
102 public string CapsRequest(string request, string path, string param) 102 public string CapsRequest(string request, string path, string param)
103 { 103 {
104 //Console.WriteLine("caps request " + request); 104 //Console.WriteLine("caps request " + request);
105 string result = LLSDHelpers.SerialiseLLSDReply(this.GetCapabilities()); 105 string result = LLSDHelpers.SerialiseLLSDReply(this.GetCapabilities());
106 return result; 106 return result;
107 } 107 }
108 108
109 /// <summary> 109 /// <summary>
110 /// 110 ///
111 /// </summary> 111 /// </summary>
112 /// <returns></returns> 112 /// <returns></returns>
113 protected LLSDCapsDetails GetCapabilities() 113 protected LLSDCapsDetails GetCapabilities()
114 { 114 {
115 LLSDCapsDetails caps = new LLSDCapsDetails(); 115 LLSDCapsDetails caps = new LLSDCapsDetails();
116 string capsBaseUrl = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + m_capsObjectPath; 116 string capsBaseUrl = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + m_capsObjectPath;
117 caps.MapLayer = capsBaseUrl + m_mapLayerPath; 117 caps.MapLayer = capsBaseUrl + m_mapLayerPath;
118 caps.NewFileAgentInventory = capsBaseUrl + m_newInventory; 118 caps.NewFileAgentInventory = capsBaseUrl + m_newInventory;
119 //caps.RequestTextureDownload = capsBaseUrl + m_requestTexture; 119 //caps.RequestTextureDownload = capsBaseUrl + m_requestTexture;
120 caps.UpdateNotecardAgentInventory = capsBaseUrl + m_notecardUpdatePath; 120 caps.UpdateNotecardAgentInventory = capsBaseUrl + m_notecardUpdatePath;
121 return caps; 121 return caps;
122 } 122 }
123 123
124 /// <summary> 124 /// <summary>
125 /// 125 ///
126 /// </summary> 126 /// </summary>
127 /// <param name="mapReq"></param> 127 /// <param name="mapReq"></param>
128 /// <returns></returns> 128 /// <returns></returns>
129 public LLSDMapLayerResponse GetMapLayer(LLSDMapRequest mapReq) 129 public LLSDMapLayerResponse GetMapLayer(LLSDMapRequest mapReq)
130 { 130 {
131 LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse(); 131 LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse();
132 mapResponse.LayerData.Array.Add(this.GetLLSDMapLayerResponse()); 132 mapResponse.LayerData.Array.Add(this.GetLLSDMapLayerResponse());
133 return mapResponse; 133 return mapResponse;
134 } 134 }
135 135
136 /// <summary> 136 /// <summary>
137 /// 137 ///
138 /// </summary> 138 /// </summary>
139 /// <returns></returns> 139 /// <returns></returns>
140 protected LLSDMapLayer GetLLSDMapLayerResponse() 140 protected LLSDMapLayer GetLLSDMapLayerResponse()
141 { 141 {
142 LLSDMapLayer mapLayer = new LLSDMapLayer(); 142 LLSDMapLayer mapLayer = new LLSDMapLayer();
143 mapLayer.Right = 5000; 143 mapLayer.Right = 5000;
144 mapLayer.Top = 5000; 144 mapLayer.Top = 5000;
145 mapLayer.ImageID = new LLUUID("00000000-0000-0000-9999-000000000006"); 145 mapLayer.ImageID = new LLUUID("00000000-0000-0000-9999-000000000006");
146 return mapLayer; 146 return mapLayer;
147 } 147 }
148 148
149 /// <summary> 149 /// <summary>
150 /// 150 ///
151 /// </summary> 151 /// </summary>
152 /// <param name="request"></param> 152 /// <param name="request"></param>
153 /// <param name="path"></param> 153 /// <param name="path"></param>
154 /// <param name="param"></param> 154 /// <param name="param"></param>
155 /// <returns></returns> 155 /// <returns></returns>
156 public string RequestTexture(string request, string path, string param) 156 public string RequestTexture(string request, string path, string param)
157 { 157 {
158 Console.WriteLine("texture request " + request); 158 Console.WriteLine("texture request " + request);
159 // Needs implementing (added to remove compiler warning) 159 // Needs implementing (added to remove compiler warning)
160 return ""; 160 return "";
161 } 161 }
162 162
163 #region EventQueue (Currently not enabled) 163 #region EventQueue (Currently not enabled)
164 /// <summary> 164 /// <summary>
165 /// 165 ///
166 /// </summary> 166 /// </summary>
167 /// <param name="request"></param> 167 /// <param name="request"></param>
168 /// <param name="path"></param> 168 /// <param name="path"></param>
169 /// <param name="param"></param> 169 /// <param name="param"></param>
170 /// <returns></returns> 170 /// <returns></returns>
171 public string ProcessEventQueue(string request, string path, string param) 171 public string ProcessEventQueue(string request, string path, string param)
172 { 172 {
173 string res = ""; 173 string res = "";
174 174
175 if (this.CapsEventQueue.Count > 0) 175 if (this.CapsEventQueue.Count > 0)
176 { 176 {
177 lock (this.CapsEventQueue) 177 lock (this.CapsEventQueue)
178 { 178 {
179 string item = CapsEventQueue.Dequeue(); 179 string item = CapsEventQueue.Dequeue();
180 res = item; 180 res = item;
181 } 181 }
182 } 182 }
183 else 183 else
184 { 184 {
185 res = this.CreateEmptyEventResponse(); 185 res = this.CreateEmptyEventResponse();
186 } 186 }
187 return res; 187 return res;
188 } 188 }
189 189
190 /// <summary> 190 /// <summary>
191 /// 191 ///
192 /// </summary> 192 /// </summary>
193 /// <param name="caps"></param> 193 /// <param name="caps"></param>
194 /// <param name="ipAddressPort"></param> 194 /// <param name="ipAddressPort"></param>
195 /// <returns></returns> 195 /// <returns></returns>
196 public string CreateEstablishAgentComms(string caps, string ipAddressPort) 196 public string CreateEstablishAgentComms(string caps, string ipAddressPort)
197 { 197 {
198 LLSDCapEvent eventItem = new LLSDCapEvent(); 198 LLSDCapEvent eventItem = new LLSDCapEvent();
199 eventItem.id = eventQueueCount; 199 eventItem.id = eventQueueCount;
200 //should be creating a EstablishAgentComms item, but there isn't a class for it yet 200 //should be creating a EstablishAgentComms item, but there isn't a class for it yet
201 eventItem.events.Array.Add(new LLSDEmpty()); 201 eventItem.events.Array.Add(new LLSDEmpty());
202 string res = LLSDHelpers.SerialiseLLSDReply(eventItem); 202 string res = LLSDHelpers.SerialiseLLSDReply(eventItem);
203 eventQueueCount++; 203 eventQueueCount++;
204 204
205 this.CapsEventQueue.Enqueue(res); 205 this.CapsEventQueue.Enqueue(res);
206 return res; 206 return res;
207 } 207 }
208 208
209 /// <summary> 209 /// <summary>
210 /// 210 ///
211 /// </summary> 211 /// </summary>
212 /// <returns></returns> 212 /// <returns></returns>
213 public string CreateEmptyEventResponse() 213 public string CreateEmptyEventResponse()
214 { 214 {
215 LLSDCapEvent eventItem = new LLSDCapEvent(); 215 LLSDCapEvent eventItem = new LLSDCapEvent();
216 eventItem.id = eventQueueCount; 216 eventItem.id = eventQueueCount;
217 eventItem.events.Array.Add(new LLSDEmpty()); 217 eventItem.events.Array.Add(new LLSDEmpty());
218 string res = LLSDHelpers.SerialiseLLSDReply(eventItem); 218 string res = LLSDHelpers.SerialiseLLSDReply(eventItem);
219 eventQueueCount++; 219 eventQueueCount++;
220 return res; 220 return res;
221 } 221 }
222 #endregion 222 #endregion
223 223
224 /// <summary> 224 /// <summary>
225 /// 225 ///
226 /// </summary> 226 /// </summary>
227 /// <param name="request"></param> 227 /// <param name="request"></param>
228 /// <param name="path"></param> 228 /// <param name="path"></param>
229 /// <param name="param"></param> 229 /// <param name="param"></param>
230 /// <returns></returns> 230 /// <returns></returns>
231 public string NoteCardAgentInventory(string request, string path, string param) 231 public string NoteCardAgentInventory(string request, string path, string param)
232 { 232 {
233 Console.WriteLine("notecard update request " + request); 233 Console.WriteLine("notecard update request " + request);
234 string assetName = "notecardupdate"; 234 string assetName = "notecardupdate";
235 string capsBase = "/CAPS/" + m_capsObjectPath; 235 string capsBase = "/CAPS/" + m_capsObjectPath;
236 LLUUID newAsset = LLUUID.Random(); 236 LLUUID newAsset = LLUUID.Random();
237 LLUUID newInvItem = LLUUID.Random(); 237 LLUUID newInvItem = LLUUID.Random();
238 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); 238 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
239 239
240 AssetUploader uploader = new AssetUploader(assetName, newAsset, newInvItem, capsBase + uploaderPath, this.httpListener); 240 AssetUploader uploader = new AssetUploader(assetName, newAsset, newInvItem, capsBase + uploaderPath, this.httpListener);
241 httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); 241 httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps));
242 string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath; 242 string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath;
243 243
244 LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); 244 LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
245 uploadResponse.uploader = uploaderURL; 245 uploadResponse.uploader = uploaderURL;
246 uploadResponse.state = "upload"; 246 uploadResponse.state = "upload";
247 // uploader.OnUpLoad += this.UploadCompleteHandler; 247 // uploader.OnUpLoad += this.UploadCompleteHandler;
248 return LLSDHelpers.SerialiseLLSDReply(uploadResponse); 248 return LLSDHelpers.SerialiseLLSDReply(uploadResponse);
249 } 249 }
250 250
251 /// <summary> 251 /// <summary>
252 /// 252 ///
253 /// </summary> 253 /// </summary>
254 /// <param name="llsdRequest"></param> 254 /// <param name="llsdRequest"></param>
255 /// <returns></returns> 255 /// <returns></returns>
256 public LLSDAssetUploadResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest) 256 public LLSDAssetUploadResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest)
257 { 257 {
258 // Console.WriteLine("asset upload request via CAPS"); 258 // Console.WriteLine("asset upload request via CAPS");
259 string assetName = llsdRequest.name; 259 string assetName = llsdRequest.name;
260 string capsBase = "/CAPS/" + m_capsObjectPath; 260 string capsBase = "/CAPS/" + m_capsObjectPath;
261 LLUUID newAsset = LLUUID.Random(); 261 LLUUID newAsset = LLUUID.Random();
262 LLUUID newInvItem = LLUUID.Random(); 262 LLUUID newInvItem = LLUUID.Random();
263 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); 263 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
264 264
265 AssetUploader uploader = new AssetUploader(assetName, newAsset, newInvItem, capsBase + uploaderPath, this.httpListener); 265 AssetUploader uploader = new AssetUploader(assetName, newAsset, newInvItem, capsBase + uploaderPath, this.httpListener);
266 httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); 266 httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps));
267 string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath; 267 string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath;
268 268
269 LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); 269 LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
270 uploadResponse.uploader = uploaderURL; 270 uploadResponse.uploader = uploaderURL;
271 uploadResponse.state = "upload"; 271 uploadResponse.state = "upload";
272 uploader.OnUpLoad += this.UploadCompleteHandler; 272 uploader.OnUpLoad += this.UploadCompleteHandler;
273 return uploadResponse; 273 return uploadResponse;
274 } 274 }
275 275
276 /// <summary> 276 /// <summary>
277 /// 277 ///
278 /// </summary> 278 /// </summary>
279 /// <param name="assetID"></param> 279 /// <param name="assetID"></param>
280 /// <param name="inventoryItem"></param> 280 /// <param name="inventoryItem"></param>
281 /// <param name="data"></param> 281 /// <param name="data"></param>
282 public void UploadCompleteHandler(string assetName, LLUUID assetID, LLUUID inventoryItem, byte[] data) 282 public void UploadCompleteHandler(string assetName, LLUUID assetID, LLUUID inventoryItem, byte[] data)
283 { 283 {
284 AssetBase asset; 284 AssetBase asset;
285 asset = new AssetBase(); 285 asset = new AssetBase();
286 asset.FullID = assetID; 286 asset.FullID = assetID;
287 asset.Type = 0; 287 asset.Type = 0;
288 asset.InvType = 0; 288 asset.InvType = 0;
289 asset.Name = assetName; 289 asset.Name = assetName;
290 asset.Data = data; 290 asset.Data = data;
291 this.assetCache.AddAsset(asset); 291 this.assetCache.AddAsset(asset);
292 } 292 }
293 293
294 public class AssetUploader 294 public class AssetUploader
295 { 295 {
296 public event UpLoadedTexture OnUpLoad; 296 public event UpLoadedTexture OnUpLoad;
297 297
298 private string uploaderPath = ""; 298 private string uploaderPath = "";
299 private LLUUID newAssetID; 299 private LLUUID newAssetID;
300 private LLUUID inventoryItemID; 300 private LLUUID inventoryItemID;
301 private BaseHttpServer httpListener; 301 private BaseHttpServer httpListener;
302 private bool SaveImages = false; 302 private bool SaveImages = false;
303 private string m_assetName = ""; 303 private string m_assetName = "";
304 304
305 /// <summary> 305 /// <summary>
306 /// 306 ///
307 /// </summary> 307 /// </summary>
308 /// <param name="assetID"></param> 308 /// <param name="assetID"></param>
309 /// <param name="inventoryItem"></param> 309 /// <param name="inventoryItem"></param>
310 /// <param name="path"></param> 310 /// <param name="path"></param>
311 /// <param name="httpServer"></param> 311 /// <param name="httpServer"></param>
312 public AssetUploader(string assetName, LLUUID assetID, LLUUID inventoryItem, string path, BaseHttpServer httpServer) 312 public AssetUploader(string assetName, LLUUID assetID, LLUUID inventoryItem, string path, BaseHttpServer httpServer)
313 { 313 {
314 m_assetName = assetName; 314 m_assetName = assetName;
315 newAssetID = assetID; 315 newAssetID = assetID;
316 inventoryItemID = inventoryItem; 316 inventoryItemID = inventoryItem;
317 uploaderPath = path; 317 uploaderPath = path;
318 httpListener = httpServer; 318 httpListener = httpServer;
319 } 319 }
320 320
321 /// <summary> 321 /// <summary>
322 /// 322 ///
323 /// </summary> 323 /// </summary>
324 /// <param name="data"></param> 324 /// <param name="data"></param>
325 /// <param name="path"></param> 325 /// <param name="path"></param>
326 /// <param name="param"></param> 326 /// <param name="param"></param>
327 /// <returns></returns> 327 /// <returns></returns>
328 public string uploaderCaps(byte[] data, string path, string param) 328 public string uploaderCaps(byte[] data, string path, string param)
329 { 329 {
330 LLUUID inv = this.inventoryItemID; 330 LLUUID inv = this.inventoryItemID;
331 string res = ""; 331 string res = "";
332 LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); 332 LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
333 uploadComplete.new_asset = newAssetID.ToStringHyphenated(); 333 uploadComplete.new_asset = newAssetID.ToStringHyphenated();
334 uploadComplete.new_inventory_item = inv; 334 uploadComplete.new_inventory_item = inv;
335 uploadComplete.state = "complete"; 335 uploadComplete.state = "complete";
336 336
337 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); 337 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
338 338
339 httpListener.RemoveStreamHandler("POST", uploaderPath); 339 httpListener.RemoveStreamHandler("POST", uploaderPath);
340 340
341 if(this.SaveImages) 341 if(this.SaveImages)
342 this.SaveImageToFile(m_assetName + ".jp2", data); 342 this.SaveImageToFile(m_assetName + ".jp2", data);
343 343
344 if (OnUpLoad != null) 344 if (OnUpLoad != null)
345 { 345 {
346 OnUpLoad(m_assetName, newAssetID, inv, data); 346 OnUpLoad(m_assetName, newAssetID, inv, data);
347 } 347 }
348 348
349 return res; 349 return res;
350 } 350 }
351 351
352 private void SaveImageToFile(string filename, byte[] data) 352 private void SaveImageToFile(string filename, byte[] data)
353 { 353 {
354 FileStream fs = File.Create(filename); 354 FileStream fs = File.Create(filename);
355 BinaryWriter bw = new BinaryWriter(fs); 355 BinaryWriter bw = new BinaryWriter(fs);
356 bw.Write(data); 356 bw.Write(data);
357 bw.Close(); 357 bw.Close();
358 fs.Close(); 358 fs.Close();
359 } 359 }
360 } 360 }
361 } 361 }
362} 362}