diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Capabilities/Caps.cs | 1239 |
1 files changed, 0 insertions, 1239 deletions
diff --git a/OpenSim/Framework/Capabilities/Caps.cs b/OpenSim/Framework/Capabilities/Caps.cs deleted file mode 100644 index 74c6ab0..0000000 --- a/OpenSim/Framework/Capabilities/Caps.cs +++ /dev/null | |||
@@ -1,1239 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.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 OpenSimulator 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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using log4net; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework.Servers; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | |||
39 | // using OpenSim.Region.Framework.Interfaces; | ||
40 | |||
41 | namespace OpenSim.Framework.Capabilities | ||
42 | { | ||
43 | public delegate void UpLoadedAsset( | ||
44 | string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder, | ||
45 | byte[] data, string inventoryType, string assetType); | ||
46 | |||
47 | public delegate UUID UpdateItem(UUID itemID, byte[] data); | ||
48 | |||
49 | public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors); | ||
50 | |||
51 | public delegate void NewInventoryItem(UUID userID, InventoryItemBase item); | ||
52 | |||
53 | public delegate void NewAsset(AssetBase asset); | ||
54 | |||
55 | public delegate UUID ItemUpdatedCallback(UUID userID, UUID itemID, byte[] data); | ||
56 | |||
57 | public delegate ArrayList TaskScriptUpdatedCallback(UUID userID, UUID itemID, UUID primID, | ||
58 | bool isScriptRunning, byte[] data); | ||
59 | |||
60 | public delegate InventoryCollection FetchInventoryDescendentsCAPS(UUID agentID, UUID folderID, UUID ownerID, | ||
61 | bool fetchFolders, bool fetchItems, int sortOrder, out int version); | ||
62 | |||
63 | /// <summary> | ||
64 | /// XXX Probably not a particularly nice way of allow us to get the scene presence from the scene (chiefly so that | ||
65 | /// we can popup a message on the user's client if the inventory service has permanently failed). But I didn't want | ||
66 | /// to just pass the whole Scene into CAPS. | ||
67 | /// </summary> | ||
68 | public delegate IClientAPI GetClientDelegate(UUID agentID); | ||
69 | |||
70 | public class Caps | ||
71 | { | ||
72 | private static readonly ILog m_log = | ||
73 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
74 | |||
75 | private string m_httpListenerHostName; | ||
76 | private uint m_httpListenPort; | ||
77 | |||
78 | /// <summary> | ||
79 | /// This is the uuid portion of every CAPS path. It is used to make capability urls private to the requester. | ||
80 | /// </summary> | ||
81 | private string m_capsObjectPath; | ||
82 | public string CapsObjectPath { get { return m_capsObjectPath; } } | ||
83 | |||
84 | private CapsHandlers m_capsHandlers; | ||
85 | |||
86 | private static readonly string m_requestPath = "0000/"; | ||
87 | // private static readonly string m_mapLayerPath = "0001/"; | ||
88 | private static readonly string m_newInventory = "0002/"; | ||
89 | //private static readonly string m_requestTexture = "0003/"; | ||
90 | private static readonly string m_notecardUpdatePath = "0004/"; | ||
91 | private static readonly string m_notecardTaskUpdatePath = "0005/"; | ||
92 | // private static readonly string m_fetchInventoryPath = "0006/"; | ||
93 | |||
94 | // The following entries are in a module, however, they are also here so that we don't re-assign | ||
95 | // the path to another cap by mistake. | ||
96 | // private static readonly string m_parcelVoiceInfoRequestPath = "0007/"; // This is in a module. | ||
97 | // private static readonly string m_provisionVoiceAccountRequestPath = "0008/";// This is in a module. | ||
98 | |||
99 | // private static readonly string m_remoteParcelRequestPath = "0009/";// This is in the LandManagementModule. | ||
100 | |||
101 | //private string eventQueue = "0100/"; | ||
102 | private IHttpServer m_httpListener; | ||
103 | private UUID m_agentID; | ||
104 | private IAssetService m_assetCache; | ||
105 | private int m_eventQueueCount = 1; | ||
106 | private Queue<string> m_capsEventQueue = new Queue<string>(); | ||
107 | private bool m_dumpAssetsToFile; | ||
108 | private string m_regionName; | ||
109 | private object m_fetchLock = new Object(); | ||
110 | |||
111 | public bool SSLCaps | ||
112 | { | ||
113 | get { return m_httpListener.UseSSL; } | ||
114 | } | ||
115 | public string SSLCommonName | ||
116 | { | ||
117 | get { return m_httpListener.SSLCommonName; } | ||
118 | } | ||
119 | public CapsHandlers CapsHandlers | ||
120 | { | ||
121 | get { return m_capsHandlers; } | ||
122 | } | ||
123 | |||
124 | // These are callbacks which will be setup by the scene so that we can update scene data when we | ||
125 | // receive capability calls | ||
126 | public NewInventoryItem AddNewInventoryItem = null; | ||
127 | public NewAsset AddNewAsset = null; | ||
128 | public ItemUpdatedCallback ItemUpdatedCall = null; | ||
129 | public TaskScriptUpdatedCallback TaskScriptUpdatedCall = null; | ||
130 | public FetchInventoryDescendentsCAPS CAPSFetchInventoryDescendents = null; | ||
131 | public GetClientDelegate GetClient = null; | ||
132 | |||
133 | public Caps(IAssetService assetCache, IHttpServer httpServer, string httpListen, uint httpPort, string capsPath, | ||
134 | UUID agent, bool dumpAssetsToFile, string regionName) | ||
135 | { | ||
136 | m_assetCache = assetCache; | ||
137 | m_capsObjectPath = capsPath; | ||
138 | m_httpListener = httpServer; | ||
139 | m_httpListenerHostName = httpListen; | ||
140 | |||
141 | m_httpListenPort = httpPort; | ||
142 | |||
143 | if (httpServer.UseSSL) | ||
144 | { | ||
145 | m_httpListenPort = httpServer.SSLPort; | ||
146 | httpListen = httpServer.SSLCommonName; | ||
147 | httpPort = httpServer.SSLPort; | ||
148 | } | ||
149 | |||
150 | m_agentID = agent; | ||
151 | m_dumpAssetsToFile = dumpAssetsToFile; | ||
152 | m_capsHandlers = new CapsHandlers(httpServer, httpListen, httpPort, httpServer.UseSSL); | ||
153 | m_regionName = regionName; | ||
154 | } | ||
155 | |||
156 | /// <summary> | ||
157 | /// Register all CAPS http service handlers | ||
158 | /// </summary> | ||
159 | public void RegisterHandlers() | ||
160 | { | ||
161 | DeregisterHandlers(); | ||
162 | |||
163 | string capsBase = "/CAPS/" + m_capsObjectPath; | ||
164 | |||
165 | RegisterRegionServiceHandlers(capsBase); | ||
166 | RegisterInventoryServiceHandlers(capsBase); | ||
167 | |||
168 | } | ||
169 | |||
170 | public void RegisterRegionServiceHandlers(string capsBase) | ||
171 | { | ||
172 | try | ||
173 | { | ||
174 | // the root of all evil | ||
175 | m_capsHandlers["SEED"] = new RestStreamHandler("POST", capsBase + m_requestPath, CapsRequest); | ||
176 | m_log.DebugFormat( | ||
177 | "[CAPS]: Registered seed capability {0} for {1}", capsBase + m_requestPath, m_agentID); | ||
178 | |||
179 | //m_capsHandlers["MapLayer"] = | ||
180 | // new LLSDStreamhandler<OSDMapRequest, OSDMapLayerResponse>("POST", | ||
181 | // capsBase + m_mapLayerPath, | ||
182 | // GetMapLayer); | ||
183 | m_capsHandlers["UpdateScriptTaskInventory"] = | ||
184 | new RestStreamHandler("POST", capsBase + m_notecardTaskUpdatePath, ScriptTaskInventory); | ||
185 | m_capsHandlers["UpdateScriptTask"] = m_capsHandlers["UpdateScriptTaskInventory"]; | ||
186 | |||
187 | } | ||
188 | catch (Exception e) | ||
189 | { | ||
190 | m_log.Error("[CAPS]: " + e.ToString()); | ||
191 | } | ||
192 | } | ||
193 | |||
194 | public void RegisterInventoryServiceHandlers(string capsBase) | ||
195 | { | ||
196 | try | ||
197 | { | ||
198 | // I don't think this one works... | ||
199 | m_capsHandlers["NewFileAgentInventory"] = | ||
200 | new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>("POST", | ||
201 | capsBase + m_newInventory, | ||
202 | NewAgentInventoryRequest); | ||
203 | m_capsHandlers["UpdateNotecardAgentInventory"] = | ||
204 | new RestStreamHandler("POST", capsBase + m_notecardUpdatePath, NoteCardAgentInventory); | ||
205 | m_capsHandlers["UpdateScriptAgentInventory"] = m_capsHandlers["UpdateNotecardAgentInventory"]; | ||
206 | m_capsHandlers["UpdateScriptAgent"] = m_capsHandlers["UpdateScriptAgentInventory"]; | ||
207 | |||
208 | // As of RC 1.22.9 of the Linden client this is | ||
209 | // supported | ||
210 | |||
211 | //m_capsHandlers["WebFetchInventoryDescendents"] =new RestStreamHandler("POST", capsBase + m_fetchInventoryPath, FetchInventoryDescendentsRequest); | ||
212 | |||
213 | // justincc: I've disabled the CAPS service for now to fix problems with selecting textures, and | ||
214 | // subsequent inventory breakage, in the edit object pane (such as mantis 1085). This requires | ||
215 | // enhancements (probably filling out the folder part of the LLSD reply) to our CAPS service, | ||
216 | // but when I went on the Linden grid, the | ||
217 | // simulators I visited (version 1.21) were, surprisingly, no longer supplying this capability. Instead, | ||
218 | // the 1.19.1.4 client appeared to be happily flowing inventory data over UDP | ||
219 | // | ||
220 | // This is very probably just a temporary measure - once the CAPS service appears again on the Linden grid | ||
221 | // we will be | ||
222 | // able to get the data we need to implement the necessary part of the protocol to fix the issue above. | ||
223 | // m_capsHandlers["FetchInventoryDescendents"] = | ||
224 | // new RestStreamHandler("POST", capsBase + m_fetchInventoryPath, FetchInventoryRequest); | ||
225 | |||
226 | // m_capsHandlers["FetchInventoryDescendents"] = | ||
227 | // new LLSDStreamhandler<LLSDFetchInventoryDescendents, LLSDInventoryDescendents>("POST", | ||
228 | // capsBase + m_fetchInventory, | ||
229 | // FetchInventory)); | ||
230 | // m_capsHandlers["RequestTextureDownload"] = new RestStreamHandler("POST", | ||
231 | // capsBase + m_requestTexture, | ||
232 | // RequestTexture); | ||
233 | } | ||
234 | catch (Exception e) | ||
235 | { | ||
236 | m_log.Error("[CAPS]: " + e.ToString()); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | /// <summary> | ||
241 | /// Register a handler. This allows modules to register handlers. | ||
242 | /// </summary> | ||
243 | /// <param name="capName"></param> | ||
244 | /// <param name="handler"></param> | ||
245 | public void RegisterHandler(string capName, IRequestHandler handler) | ||
246 | { | ||
247 | m_capsHandlers[capName] = handler; | ||
248 | //m_log.DebugFormat("[CAPS]: Registering handler for \"{0}\": path {1}", capName, handler.Path); | ||
249 | } | ||
250 | |||
251 | /// <summary> | ||
252 | /// Remove all CAPS service handlers. | ||
253 | /// | ||
254 | /// </summary> | ||
255 | /// <param name="httpListener"></param> | ||
256 | /// <param name="path"></param> | ||
257 | /// <param name="restMethod"></param> | ||
258 | public void DeregisterHandlers() | ||
259 | { | ||
260 | if (m_capsHandlers != null) | ||
261 | { | ||
262 | foreach (string capsName in m_capsHandlers.Caps) | ||
263 | { | ||
264 | m_capsHandlers.Remove(capsName); | ||
265 | } | ||
266 | } | ||
267 | } | ||
268 | |||
269 | /// <summary> | ||
270 | /// Construct a client response detailing all the capabilities this server can provide. | ||
271 | /// </summary> | ||
272 | /// <param name="request"></param> | ||
273 | /// <param name="path"></param> | ||
274 | /// <param name="param"></param> | ||
275 | /// <param name="httpRequest">HTTP request header object</param> | ||
276 | /// <param name="httpResponse">HTTP response header object</param> | ||
277 | /// <returns></returns> | ||
278 | public string CapsRequest(string request, string path, string param, | ||
279 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
280 | { | ||
281 | //m_log.Debug("[CAPS]: Seed Caps Request in region: " + m_regionName); | ||
282 | |||
283 | string result = LLSDHelpers.SerialiseLLSDReply(m_capsHandlers.CapsDetails); | ||
284 | |||
285 | //m_log.DebugFormat("[CAPS] CapsRequest {0}", result); | ||
286 | |||
287 | return result; | ||
288 | } | ||
289 | |||
290 | // FIXME: these all should probably go into the respective region | ||
291 | // modules | ||
292 | |||
293 | /// <summary> | ||
294 | /// Processes a fetch inventory request and sends the reply | ||
295 | |||
296 | /// </summary> | ||
297 | /// <param name="request"></param> | ||
298 | /// <param name="path"></param> | ||
299 | /// <param name="param"></param> | ||
300 | /// <returns></returns> | ||
301 | // Request is like: | ||
302 | //<llsd> | ||
303 | // <map><key>folders</key> | ||
304 | // <array> | ||
305 | // <map> | ||
306 | // <key>fetch-folders</key><boolean>1</boolean><key>fetch-items</key><boolean>1</boolean><key>folder-id</key><uuid>8e1e3a30-b9bf-11dc-95ff-0800200c9a66</uuid><key>owner-id</key><uuid>11111111-1111-0000-0000-000100bba000</uuid><key>sort-order</key><integer>1</integer> | ||
307 | // </map> | ||
308 | // </array> | ||
309 | // </map> | ||
310 | //</llsd> | ||
311 | // | ||
312 | // multiple fetch-folder maps are allowed within the larger folders map. | ||
313 | public string FetchInventoryRequest(string request, string path, string param) | ||
314 | { | ||
315 | // string unmodifiedRequest = request.ToString(); | ||
316 | |||
317 | //m_log.DebugFormat("[AGENT INVENTORY]: Received CAPS fetch inventory request {0}", unmodifiedRequest); | ||
318 | m_log.Debug("[CAPS]: Inventory Request in region: " + m_regionName); | ||
319 | |||
320 | Hashtable hash = new Hashtable(); | ||
321 | try | ||
322 | { | ||
323 | hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request)); | ||
324 | } | ||
325 | catch (LLSD.LLSDParseException pe) | ||
326 | { | ||
327 | m_log.Error("[AGENT INVENTORY]: Fetch error: " + pe.Message); | ||
328 | m_log.Error("Request: " + request.ToString()); | ||
329 | } | ||
330 | |||
331 | ArrayList foldersrequested = (ArrayList)hash["folders"]; | ||
332 | |||
333 | string response = ""; | ||
334 | |||
335 | for (int i = 0; i < foldersrequested.Count; i++) | ||
336 | { | ||
337 | string inventoryitemstr = ""; | ||
338 | Hashtable inventoryhash = (Hashtable)foldersrequested[i]; | ||
339 | |||
340 | LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents(); | ||
341 | LLSDHelpers.DeserialiseOSDMap(inventoryhash, llsdRequest); | ||
342 | LLSDInventoryDescendents reply = FetchInventoryReply(llsdRequest); | ||
343 | |||
344 | inventoryitemstr = LLSDHelpers.SerialiseLLSDReply(reply); | ||
345 | inventoryitemstr = inventoryitemstr.Replace("<llsd><map><key>folders</key><array>", ""); | ||
346 | inventoryitemstr = inventoryitemstr.Replace("</array></map></llsd>", ""); | ||
347 | |||
348 | response += inventoryitemstr; | ||
349 | } | ||
350 | |||
351 | if (response.Length == 0) | ||
352 | { | ||
353 | // Ter-guess: If requests fail a lot, the client seems to stop requesting descendants. | ||
354 | // Therefore, I'm concluding that the client only has so many threads available to do requests | ||
355 | // and when a thread stalls.. is stays stalled. | ||
356 | // Therefore we need to return something valid | ||
357 | response = "<llsd><map><key>folders</key><array /></map></llsd>"; | ||
358 | } | ||
359 | else | ||
360 | { | ||
361 | response = "<llsd><map><key>folders</key><array>" + response + "</array></map></llsd>"; | ||
362 | } | ||
363 | |||
364 | //m_log.DebugFormat("[AGENT INVENTORY]: Replying to CAPS fetch inventory request with following xml"); | ||
365 | //m_log.Debug(Util.GetFormattedXml(response)); | ||
366 | |||
367 | return response; | ||
368 | } | ||
369 | |||
370 | public string FetchInventoryDescendentsRequest(string request, string path, string param,OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
371 | { | ||
372 | // nasty temporary hack here, the linden client falsely | ||
373 | // identifies the uuid 00000000-0000-0000-0000-000000000000 | ||
374 | // as a string which breaks us | ||
375 | // | ||
376 | // correctly mark it as a uuid | ||
377 | // | ||
378 | request = request.Replace("<string>00000000-0000-0000-0000-000000000000</string>", "<uuid>00000000-0000-0000-0000-000000000000</uuid>"); | ||
379 | |||
380 | // another hack <integer>1</integer> results in a | ||
381 | // System.ArgumentException: Object type System.Int32 cannot | ||
382 | // be converted to target type: System.Boolean | ||
383 | // | ||
384 | request = request.Replace("<key>fetch_folders</key><integer>0</integer>", "<key>fetch_folders</key><boolean>0</boolean>"); | ||
385 | request = request.Replace("<key>fetch_folders</key><integer>1</integer>", "<key>fetch_folders</key><boolean>1</boolean>"); | ||
386 | |||
387 | Hashtable hash = new Hashtable(); | ||
388 | try | ||
389 | { | ||
390 | hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request)); | ||
391 | } | ||
392 | catch (LLSD.LLSDParseException pe) | ||
393 | { | ||
394 | m_log.Error("[AGENT INVENTORY]: Fetch error: " + pe.Message); | ||
395 | m_log.Error("Request: " + request.ToString()); | ||
396 | } | ||
397 | |||
398 | ArrayList foldersrequested = (ArrayList)hash["folders"]; | ||
399 | |||
400 | string response = ""; | ||
401 | lock (m_fetchLock) | ||
402 | { | ||
403 | for (int i = 0; i < foldersrequested.Count; i++) | ||
404 | { | ||
405 | string inventoryitemstr = ""; | ||
406 | Hashtable inventoryhash = (Hashtable)foldersrequested[i]; | ||
407 | |||
408 | LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents(); | ||
409 | |||
410 | try{ | ||
411 | LLSDHelpers.DeserialiseOSDMap(inventoryhash, llsdRequest); | ||
412 | } | ||
413 | catch(Exception e) | ||
414 | { | ||
415 | m_log.Debug("[CAPS]: caught exception doing OSD deserialize" + e); | ||
416 | } | ||
417 | LLSDInventoryDescendents reply = FetchInventoryReply(llsdRequest); | ||
418 | |||
419 | inventoryitemstr = LLSDHelpers.SerialiseLLSDReply(reply); | ||
420 | inventoryitemstr = inventoryitemstr.Replace("<llsd><map><key>folders</key><array>", ""); | ||
421 | inventoryitemstr = inventoryitemstr.Replace("</array></map></llsd>", ""); | ||
422 | |||
423 | response += inventoryitemstr; | ||
424 | } | ||
425 | |||
426 | |||
427 | if (response.Length == 0) | ||
428 | { | ||
429 | // Ter-guess: If requests fail a lot, the client seems to stop requesting descendants. | ||
430 | // Therefore, I'm concluding that the client only has so many threads available to do requests | ||
431 | // and when a thread stalls.. is stays stalled. | ||
432 | // Therefore we need to return something valid | ||
433 | response = "<llsd><map><key>folders</key><array /></map></llsd>"; | ||
434 | } | ||
435 | else | ||
436 | { | ||
437 | response = "<llsd><map><key>folders</key><array>" + response + "</array></map></llsd>"; | ||
438 | } | ||
439 | |||
440 | //m_log.DebugFormat("[CAPS]: Replying to CAPS fetch inventory request with following xml"); | ||
441 | //m_log.Debug("[CAPS] "+response); | ||
442 | |||
443 | } | ||
444 | return response; | ||
445 | } | ||
446 | |||
447 | |||
448 | |||
449 | /// <summary> | ||
450 | /// Construct an LLSD reply packet to a CAPS inventory request | ||
451 | /// </summary> | ||
452 | /// <param name="invFetch"></param> | ||
453 | /// <returns></returns> | ||
454 | private LLSDInventoryDescendents FetchInventoryReply(LLSDFetchInventoryDescendents invFetch) | ||
455 | { | ||
456 | LLSDInventoryDescendents reply = new LLSDInventoryDescendents(); | ||
457 | LLSDInventoryFolderContents contents = new LLSDInventoryFolderContents(); | ||
458 | contents.agent_id = m_agentID; | ||
459 | contents.owner_id = invFetch.owner_id; | ||
460 | contents.folder_id = invFetch.folder_id; | ||
461 | |||
462 | reply.folders.Array.Add(contents); | ||
463 | InventoryCollection inv = new InventoryCollection(); | ||
464 | inv.Folders = new List<InventoryFolderBase>(); | ||
465 | inv.Items = new List<InventoryItemBase>(); | ||
466 | int version = 0; | ||
467 | if (CAPSFetchInventoryDescendents != null) | ||
468 | { | ||
469 | inv = CAPSFetchInventoryDescendents(m_agentID, invFetch.folder_id, invFetch.owner_id, invFetch.fetch_folders, invFetch.fetch_items, invFetch.sort_order, out version); | ||
470 | } | ||
471 | |||
472 | if (inv.Folders != null) | ||
473 | { | ||
474 | foreach (InventoryFolderBase invFolder in inv.Folders) | ||
475 | { | ||
476 | contents.categories.Array.Add(ConvertInventoryFolder(invFolder)); | ||
477 | } | ||
478 | } | ||
479 | |||
480 | if (inv.Items != null) | ||
481 | { | ||
482 | foreach (InventoryItemBase invItem in inv.Items) | ||
483 | { | ||
484 | contents.items.Array.Add(ConvertInventoryItem(invItem)); | ||
485 | } | ||
486 | } | ||
487 | |||
488 | contents.descendents = contents.items.Array.Count + contents.categories.Array.Count; | ||
489 | contents.version = version; | ||
490 | |||
491 | return reply; | ||
492 | } | ||
493 | |||
494 | /// <summary> | ||
495 | /// Convert an internal inventory folder object into an LLSD object. | ||
496 | /// </summary> | ||
497 | /// <param name="invFolder"></param> | ||
498 | /// <returns></returns> | ||
499 | private LLSDInventoryFolder ConvertInventoryFolder(InventoryFolderBase invFolder) | ||
500 | { | ||
501 | LLSDInventoryFolder llsdFolder = new LLSDInventoryFolder(); | ||
502 | llsdFolder.folder_id = invFolder.ID; | ||
503 | llsdFolder.parent_id = invFolder.ParentID; | ||
504 | llsdFolder.name = invFolder.Name; | ||
505 | if (invFolder.Type < 0 || invFolder.Type >= TaskInventoryItem.Types.Length) | ||
506 | llsdFolder.type = "-1"; | ||
507 | else | ||
508 | llsdFolder.type = TaskInventoryItem.Types[invFolder.Type]; | ||
509 | llsdFolder.preferred_type = "-1"; | ||
510 | |||
511 | return llsdFolder; | ||
512 | } | ||
513 | |||
514 | /// <summary> | ||
515 | /// Convert an internal inventory item object into an LLSD object. | ||
516 | /// </summary> | ||
517 | /// <param name="invItem"></param> | ||
518 | /// <returns></returns> | ||
519 | private LLSDInventoryItem ConvertInventoryItem(InventoryItemBase invItem) | ||
520 | { | ||
521 | LLSDInventoryItem llsdItem = new LLSDInventoryItem(); | ||
522 | llsdItem.asset_id = invItem.AssetID; | ||
523 | llsdItem.created_at = invItem.CreationDate; | ||
524 | llsdItem.desc = invItem.Description; | ||
525 | llsdItem.flags = (int)invItem.Flags; | ||
526 | llsdItem.item_id = invItem.ID; | ||
527 | llsdItem.name = invItem.Name; | ||
528 | llsdItem.parent_id = invItem.Folder; | ||
529 | try | ||
530 | { | ||
531 | // TODO reevaluate after upgrade to libomv >= r2566. Probably should use UtilsConversions. | ||
532 | llsdItem.type = TaskInventoryItem.Types[invItem.AssetType]; | ||
533 | llsdItem.inv_type = TaskInventoryItem.InvTypes[invItem.InvType]; | ||
534 | } | ||
535 | catch (Exception e) | ||
536 | { | ||
537 | m_log.Error("[CAPS]: Problem setting asset/inventory type while converting inventory item " + invItem.Name + " to LLSD:", e); | ||
538 | } | ||
539 | llsdItem.permissions = new LLSDPermissions(); | ||
540 | llsdItem.permissions.creator_id = invItem.CreatorIdAsUuid; | ||
541 | llsdItem.permissions.base_mask = (int)invItem.CurrentPermissions; | ||
542 | llsdItem.permissions.everyone_mask = (int)invItem.EveryOnePermissions; | ||
543 | llsdItem.permissions.group_id = invItem.GroupID; | ||
544 | llsdItem.permissions.group_mask = (int)invItem.GroupPermissions; | ||
545 | llsdItem.permissions.is_owner_group = invItem.GroupOwned; | ||
546 | llsdItem.permissions.next_owner_mask = (int)invItem.NextPermissions; | ||
547 | llsdItem.permissions.owner_id = m_agentID; | ||
548 | llsdItem.permissions.owner_mask = (int)invItem.CurrentPermissions; | ||
549 | llsdItem.sale_info = new LLSDSaleInfo(); | ||
550 | llsdItem.sale_info.sale_price = invItem.SalePrice; | ||
551 | switch (invItem.SaleType) | ||
552 | { | ||
553 | default: | ||
554 | llsdItem.sale_info.sale_type = "not"; | ||
555 | break; | ||
556 | case 1: | ||
557 | llsdItem.sale_info.sale_type = "original"; | ||
558 | break; | ||
559 | case 2: | ||
560 | llsdItem.sale_info.sale_type = "copy"; | ||
561 | break; | ||
562 | case 3: | ||
563 | llsdItem.sale_info.sale_type = "contents"; | ||
564 | break; | ||
565 | } | ||
566 | |||
567 | return llsdItem; | ||
568 | } | ||
569 | |||
570 | /// <summary> | ||
571 | /// | ||
572 | /// </summary> | ||
573 | /// <param name="mapReq"></param> | ||
574 | /// <returns></returns> | ||
575 | public LLSDMapLayerResponse GetMapLayer(LLSDMapRequest mapReq) | ||
576 | { | ||
577 | m_log.Debug("[CAPS]: MapLayer Request in region: " + m_regionName); | ||
578 | LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse(); | ||
579 | mapResponse.LayerData.Array.Add(GetOSDMapLayerResponse()); | ||
580 | return mapResponse; | ||
581 | } | ||
582 | |||
583 | /// <summary> | ||
584 | /// | ||
585 | /// </summary> | ||
586 | /// <returns></returns> | ||
587 | protected static OSDMapLayer GetOSDMapLayerResponse() | ||
588 | { | ||
589 | OSDMapLayer mapLayer = new OSDMapLayer(); | ||
590 | mapLayer.Right = 5000; | ||
591 | mapLayer.Top = 5000; | ||
592 | mapLayer.ImageID = new UUID("00000000-0000-1111-9999-000000000006"); | ||
593 | |||
594 | return mapLayer; | ||
595 | } | ||
596 | |||
597 | /// <summary> | ||
598 | /// | ||
599 | /// </summary> | ||
600 | /// <param name="request"></param> | ||
601 | /// <param name="path"></param> | ||
602 | /// <param name="param"></param> | ||
603 | /// <returns></returns> | ||
604 | public string RequestTexture(string request, string path, string param) | ||
605 | { | ||
606 | m_log.Debug("texture request " + request); | ||
607 | // Needs implementing (added to remove compiler warning) | ||
608 | return String.Empty; | ||
609 | } | ||
610 | |||
611 | #region EventQueue (Currently not enabled) | ||
612 | |||
613 | /// <summary> | ||
614 | /// | ||
615 | /// </summary> | ||
616 | /// <param name="request"></param> | ||
617 | /// <param name="path"></param> | ||
618 | /// <param name="param"></param> | ||
619 | /// <returns></returns> | ||
620 | public string ProcessEventQueue(string request, string path, string param) | ||
621 | { | ||
622 | string res = String.Empty; | ||
623 | |||
624 | if (m_capsEventQueue.Count > 0) | ||
625 | { | ||
626 | lock (m_capsEventQueue) | ||
627 | { | ||
628 | string item = m_capsEventQueue.Dequeue(); | ||
629 | res = item; | ||
630 | } | ||
631 | } | ||
632 | else | ||
633 | { | ||
634 | res = CreateEmptyEventResponse(); | ||
635 | } | ||
636 | return res; | ||
637 | } | ||
638 | |||
639 | /// <summary> | ||
640 | /// | ||
641 | /// </summary> | ||
642 | /// <param name="caps"></param> | ||
643 | /// <param name="ipAddressPort"></param> | ||
644 | /// <returns></returns> | ||
645 | public string CreateEstablishAgentComms(string caps, string ipAddressPort) | ||
646 | { | ||
647 | LLSDCapEvent eventItem = new LLSDCapEvent(); | ||
648 | eventItem.id = m_eventQueueCount; | ||
649 | //should be creating a EstablishAgentComms item, but there isn't a class for it yet | ||
650 | eventItem.events.Array.Add(new LLSDEmpty()); | ||
651 | string res = LLSDHelpers.SerialiseLLSDReply(eventItem); | ||
652 | m_eventQueueCount++; | ||
653 | |||
654 | m_capsEventQueue.Enqueue(res); | ||
655 | return res; | ||
656 | } | ||
657 | |||
658 | /// <summary> | ||
659 | /// | ||
660 | /// </summary> | ||
661 | /// <returns></returns> | ||
662 | public string CreateEmptyEventResponse() | ||
663 | { | ||
664 | LLSDCapEvent eventItem = new LLSDCapEvent(); | ||
665 | eventItem.id = m_eventQueueCount; | ||
666 | eventItem.events.Array.Add(new LLSDEmpty()); | ||
667 | string res = LLSDHelpers.SerialiseLLSDReply(eventItem); | ||
668 | m_eventQueueCount++; | ||
669 | return res; | ||
670 | } | ||
671 | |||
672 | #endregion | ||
673 | |||
674 | /// <summary> | ||
675 | /// Called by the script task update handler. Provides a URL to which the client can upload a new asset. | ||
676 | /// </summary> | ||
677 | /// <param name="request"></param> | ||
678 | /// <param name="path"></param> | ||
679 | /// <param name="param"></param> | ||
680 | /// <param name="httpRequest">HTTP request header object</param> | ||
681 | /// <param name="httpResponse">HTTP response header object</param> | ||
682 | /// <returns></returns> | ||
683 | public string ScriptTaskInventory(string request, string path, string param, | ||
684 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
685 | { | ||
686 | try | ||
687 | { | ||
688 | m_log.Debug("[CAPS]: ScriptTaskInventory Request in region: " + m_regionName); | ||
689 | //m_log.DebugFormat("[CAPS]: request: {0}, path: {1}, param: {2}", request, path, param); | ||
690 | |||
691 | Hashtable hash = (Hashtable) LLSD.LLSDDeserialize(Utils.StringToBytes(request)); | ||
692 | LLSDTaskScriptUpdate llsdUpdateRequest = new LLSDTaskScriptUpdate(); | ||
693 | LLSDHelpers.DeserialiseOSDMap(hash, llsdUpdateRequest); | ||
694 | |||
695 | string capsBase = "/CAPS/" + m_capsObjectPath; | ||
696 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | ||
697 | |||
698 | TaskInventoryScriptUpdater uploader = | ||
699 | new TaskInventoryScriptUpdater( | ||
700 | llsdUpdateRequest.item_id, | ||
701 | llsdUpdateRequest.task_id, | ||
702 | llsdUpdateRequest.is_script_running, | ||
703 | capsBase + uploaderPath, | ||
704 | m_httpListener, | ||
705 | m_dumpAssetsToFile); | ||
706 | uploader.OnUpLoad += TaskScriptUpdated; | ||
707 | |||
708 | m_httpListener.AddStreamHandler( | ||
709 | new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); | ||
710 | |||
711 | string protocol = "http://"; | ||
712 | |||
713 | if (m_httpListener.UseSSL) | ||
714 | protocol = "https://"; | ||
715 | |||
716 | string uploaderURL = protocol + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + | ||
717 | uploaderPath; | ||
718 | |||
719 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); | ||
720 | uploadResponse.uploader = uploaderURL; | ||
721 | uploadResponse.state = "upload"; | ||
722 | |||
723 | // m_log.InfoFormat("[CAPS]: " + | ||
724 | // "ScriptTaskInventory response: {0}", | ||
725 | // LLSDHelpers.SerialiseLLSDReply(uploadResponse))); | ||
726 | |||
727 | return LLSDHelpers.SerialiseLLSDReply(uploadResponse); | ||
728 | } | ||
729 | catch (Exception e) | ||
730 | { | ||
731 | m_log.Error("[CAPS]: " + e.ToString()); | ||
732 | } | ||
733 | |||
734 | return null; | ||
735 | } | ||
736 | |||
737 | /// <summary> | ||
738 | /// Called by the notecard update handler. Provides a URL to which the client can upload a new asset. | ||
739 | /// </summary> | ||
740 | /// <param name="request"></param> | ||
741 | /// <param name="path"></param> | ||
742 | /// <param name="param"></param> | ||
743 | /// <returns></returns> | ||
744 | public string NoteCardAgentInventory(string request, string path, string param, | ||
745 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
746 | { | ||
747 | //m_log.Debug("[CAPS]: NoteCardAgentInventory Request in region: " + m_regionName + "\n" + request); | ||
748 | //m_log.Debug("[CAPS]: NoteCardAgentInventory Request is: " + request); | ||
749 | |||
750 | //OpenMetaverse.StructuredData.OSDMap hash = (OpenMetaverse.StructuredData.OSDMap)OpenMetaverse.StructuredData.LLSDParser.DeserializeBinary(Utils.StringToBytes(request)); | ||
751 | Hashtable hash = (Hashtable) LLSD.LLSDDeserialize(Utils.StringToBytes(request)); | ||
752 | LLSDItemUpdate llsdRequest = new LLSDItemUpdate(); | ||
753 | LLSDHelpers.DeserialiseOSDMap(hash, llsdRequest); | ||
754 | |||
755 | string capsBase = "/CAPS/" + m_capsObjectPath; | ||
756 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | ||
757 | |||
758 | ItemUpdater uploader = | ||
759 | new ItemUpdater(llsdRequest.item_id, capsBase + uploaderPath, m_httpListener, m_dumpAssetsToFile); | ||
760 | uploader.OnUpLoad += ItemUpdated; | ||
761 | |||
762 | m_httpListener.AddStreamHandler( | ||
763 | new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); | ||
764 | |||
765 | string protocol = "http://"; | ||
766 | |||
767 | if (m_httpListener.UseSSL) | ||
768 | protocol = "https://"; | ||
769 | |||
770 | string uploaderURL = protocol + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + | ||
771 | uploaderPath; | ||
772 | |||
773 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); | ||
774 | uploadResponse.uploader = uploaderURL; | ||
775 | uploadResponse.state = "upload"; | ||
776 | |||
777 | // m_log.InfoFormat("[CAPS]: " + | ||
778 | // "NoteCardAgentInventory response: {0}", | ||
779 | // LLSDHelpers.SerialiseLLSDReply(uploadResponse))); | ||
780 | |||
781 | return LLSDHelpers.SerialiseLLSDReply(uploadResponse); | ||
782 | } | ||
783 | |||
784 | /// <summary> | ||
785 | /// | ||
786 | /// </summary> | ||
787 | /// <param name="llsdRequest"></param> | ||
788 | /// <returns></returns> | ||
789 | public LLSDAssetUploadResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest) | ||
790 | { | ||
791 | //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString()); | ||
792 | //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type); | ||
793 | |||
794 | if (llsdRequest.asset_type == "texture" || | ||
795 | llsdRequest.asset_type == "animation" || | ||
796 | llsdRequest.asset_type == "sound") | ||
797 | { | ||
798 | IClientAPI client = null; | ||
799 | IScene scene = null; | ||
800 | if (GetClient != null) | ||
801 | { | ||
802 | client = GetClient(m_agentID); | ||
803 | scene = client.Scene; | ||
804 | |||
805 | IMoneyModule mm = scene.RequestModuleInterface<IMoneyModule>(); | ||
806 | |||
807 | if (mm != null) | ||
808 | { | ||
809 | if (!mm.UploadCovered(client)) | ||
810 | { | ||
811 | if (client != null) | ||
812 | client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); | ||
813 | |||
814 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); | ||
815 | errorResponse.uploader = ""; | ||
816 | errorResponse.state = "error"; | ||
817 | return errorResponse; | ||
818 | } | ||
819 | } | ||
820 | } | ||
821 | } | ||
822 | |||
823 | |||
824 | string assetName = llsdRequest.name; | ||
825 | string assetDes = llsdRequest.description; | ||
826 | string capsBase = "/CAPS/" + m_capsObjectPath; | ||
827 | UUID newAsset = UUID.Random(); | ||
828 | UUID newInvItem = UUID.Random(); | ||
829 | UUID parentFolder = llsdRequest.folder_id; | ||
830 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | ||
831 | |||
832 | AssetUploader uploader = | ||
833 | new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, | ||
834 | llsdRequest.asset_type, capsBase + uploaderPath, m_httpListener, m_dumpAssetsToFile); | ||
835 | m_httpListener.AddStreamHandler( | ||
836 | new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); | ||
837 | |||
838 | string protocol = "http://"; | ||
839 | |||
840 | if (m_httpListener.UseSSL) | ||
841 | protocol = "https://"; | ||
842 | |||
843 | string uploaderURL = protocol + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + | ||
844 | uploaderPath; | ||
845 | |||
846 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); | ||
847 | uploadResponse.uploader = uploaderURL; | ||
848 | uploadResponse.state = "upload"; | ||
849 | uploader.OnUpLoad += UploadCompleteHandler; | ||
850 | return uploadResponse; | ||
851 | } | ||
852 | |||
853 | /// <summary> | ||
854 | /// | ||
855 | /// </summary> | ||
856 | /// <param name="assetID"></param> | ||
857 | /// <param name="inventoryItem"></param> | ||
858 | /// <param name="data"></param> | ||
859 | public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, | ||
860 | UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, | ||
861 | string assetType) | ||
862 | { | ||
863 | sbyte assType = 0; | ||
864 | sbyte inType = 0; | ||
865 | |||
866 | if (inventoryType == "sound") | ||
867 | { | ||
868 | inType = 1; | ||
869 | assType = 1; | ||
870 | } | ||
871 | else if (inventoryType == "animation") | ||
872 | { | ||
873 | inType = 19; | ||
874 | assType = 20; | ||
875 | } | ||
876 | else if (inventoryType == "wearable") | ||
877 | { | ||
878 | inType = 18; | ||
879 | switch (assetType) | ||
880 | { | ||
881 | case "bodypart": | ||
882 | assType = 13; | ||
883 | break; | ||
884 | case "clothing": | ||
885 | assType = 5; | ||
886 | break; | ||
887 | } | ||
888 | } | ||
889 | |||
890 | AssetBase asset; | ||
891 | asset = new AssetBase(assetID, assetName, assType); | ||
892 | asset.Data = data; | ||
893 | if (AddNewAsset != null) | ||
894 | AddNewAsset(asset); | ||
895 | else if (m_assetCache != null) | ||
896 | m_assetCache.Store(asset); | ||
897 | |||
898 | InventoryItemBase item = new InventoryItemBase(); | ||
899 | item.Owner = m_agentID; | ||
900 | item.CreatorId = m_agentID.ToString(); | ||
901 | item.ID = inventoryItem; | ||
902 | item.AssetID = asset.FullID; | ||
903 | item.Description = assetDescription; | ||
904 | item.Name = assetName; | ||
905 | item.AssetType = assType; | ||
906 | item.InvType = inType; | ||
907 | item.Folder = parentFolder; | ||
908 | item.CurrentPermissions = 2147483647; | ||
909 | item.BasePermissions = 2147483647; | ||
910 | item.EveryOnePermissions = 0; | ||
911 | item.NextPermissions = 2147483647; | ||
912 | item.CreationDate = Util.UnixTimeSinceEpoch(); | ||
913 | |||
914 | if (AddNewInventoryItem != null) | ||
915 | { | ||
916 | AddNewInventoryItem(m_agentID, item); | ||
917 | } | ||
918 | } | ||
919 | |||
920 | /// <summary> | ||
921 | /// Called when new asset data for an agent inventory item update has been uploaded. | ||
922 | /// </summary> | ||
923 | /// <param name="itemID">Item to update</param> | ||
924 | /// <param name="data">New asset data</param> | ||
925 | /// <returns></returns> | ||
926 | public UUID ItemUpdated(UUID itemID, byte[] data) | ||
927 | { | ||
928 | if (ItemUpdatedCall != null) | ||
929 | { | ||
930 | return ItemUpdatedCall(m_agentID, itemID, data); | ||
931 | } | ||
932 | |||
933 | return UUID.Zero; | ||
934 | } | ||
935 | |||
936 | /// <summary> | ||
937 | /// Called when new asset data for an agent inventory item update has been uploaded. | ||
938 | /// </summary> | ||
939 | /// <param name="itemID">Item to update</param> | ||
940 | /// <param name="primID">Prim containing item to update</param> | ||
941 | /// <param name="isScriptRunning">Signals whether the script to update is currently running</param> | ||
942 | /// <param name="data">New asset data</param> | ||
943 | public void TaskScriptUpdated(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors) | ||
944 | { | ||
945 | if (TaskScriptUpdatedCall != null) | ||
946 | { | ||
947 | ArrayList e = TaskScriptUpdatedCall(m_agentID, itemID, primID, isScriptRunning, data); | ||
948 | foreach (Object item in e) | ||
949 | errors.Add(item); | ||
950 | } | ||
951 | } | ||
952 | |||
953 | public class AssetUploader | ||
954 | { | ||
955 | public event UpLoadedAsset OnUpLoad; | ||
956 | private UpLoadedAsset handlerUpLoad = null; | ||
957 | |||
958 | private string uploaderPath = String.Empty; | ||
959 | private UUID newAssetID; | ||
960 | private UUID inventoryItemID; | ||
961 | private UUID parentFolder; | ||
962 | private IHttpServer httpListener; | ||
963 | private bool m_dumpAssetsToFile; | ||
964 | private string m_assetName = String.Empty; | ||
965 | private string m_assetDes = String.Empty; | ||
966 | |||
967 | private string m_invType = String.Empty; | ||
968 | private string m_assetType = String.Empty; | ||
969 | |||
970 | public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem, | ||
971 | UUID parentFolderID, string invType, string assetType, string path, | ||
972 | IHttpServer httpServer, bool dumpAssetsToFile) | ||
973 | { | ||
974 | m_assetName = assetName; | ||
975 | m_assetDes = description; | ||
976 | newAssetID = assetID; | ||
977 | inventoryItemID = inventoryItem; | ||
978 | uploaderPath = path; | ||
979 | httpListener = httpServer; | ||
980 | parentFolder = parentFolderID; | ||
981 | m_assetType = assetType; | ||
982 | m_invType = invType; | ||
983 | m_dumpAssetsToFile = dumpAssetsToFile; | ||
984 | } | ||
985 | |||
986 | /// <summary> | ||
987 | /// | ||
988 | /// </summary> | ||
989 | /// <param name="data"></param> | ||
990 | /// <param name="path"></param> | ||
991 | /// <param name="param"></param> | ||
992 | /// <returns></returns> | ||
993 | public string uploaderCaps(byte[] data, string path, string param) | ||
994 | { | ||
995 | UUID inv = inventoryItemID; | ||
996 | string res = String.Empty; | ||
997 | LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); | ||
998 | uploadComplete.new_asset = newAssetID.ToString(); | ||
999 | uploadComplete.new_inventory_item = inv; | ||
1000 | uploadComplete.state = "complete"; | ||
1001 | |||
1002 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | ||
1003 | |||
1004 | httpListener.RemoveStreamHandler("POST", uploaderPath); | ||
1005 | |||
1006 | // TODO: probably make this a better set of extensions here | ||
1007 | string extension = ".jp2"; | ||
1008 | if (m_invType != "image") | ||
1009 | { | ||
1010 | extension = ".dat"; | ||
1011 | } | ||
1012 | |||
1013 | if (m_dumpAssetsToFile) | ||
1014 | { | ||
1015 | SaveAssetToFile(m_assetName + extension, data); | ||
1016 | } | ||
1017 | handlerUpLoad = OnUpLoad; | ||
1018 | if (handlerUpLoad != null) | ||
1019 | { | ||
1020 | handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType); | ||
1021 | } | ||
1022 | |||
1023 | return res; | ||
1024 | } | ||
1025 | ///Left this in and commented in case there are unforseen issues | ||
1026 | //private void SaveAssetToFile(string filename, byte[] data) | ||
1027 | //{ | ||
1028 | // FileStream fs = File.Create(filename); | ||
1029 | // BinaryWriter bw = new BinaryWriter(fs); | ||
1030 | // bw.Write(data); | ||
1031 | // bw.Close(); | ||
1032 | // fs.Close(); | ||
1033 | //} | ||
1034 | private static void SaveAssetToFile(string filename, byte[] data) | ||
1035 | { | ||
1036 | string assetPath = "UserAssets"; | ||
1037 | if (!Directory.Exists(assetPath)) | ||
1038 | { | ||
1039 | Directory.CreateDirectory(assetPath); | ||
1040 | } | ||
1041 | FileStream fs = File.Create(Path.Combine(assetPath, Util.safeFileName(filename))); | ||
1042 | BinaryWriter bw = new BinaryWriter(fs); | ||
1043 | bw.Write(data); | ||
1044 | bw.Close(); | ||
1045 | fs.Close(); | ||
1046 | } | ||
1047 | } | ||
1048 | |||
1049 | /// <summary> | ||
1050 | /// This class is a callback invoked when a client sends asset data to | ||
1051 | /// an agent inventory notecard update url | ||
1052 | /// </summary> | ||
1053 | public class ItemUpdater | ||
1054 | { | ||
1055 | public event UpdateItem OnUpLoad; | ||
1056 | |||
1057 | private UpdateItem handlerUpdateItem = null; | ||
1058 | |||
1059 | private string uploaderPath = String.Empty; | ||
1060 | private UUID inventoryItemID; | ||
1061 | private IHttpServer httpListener; | ||
1062 | private bool m_dumpAssetToFile; | ||
1063 | |||
1064 | public ItemUpdater(UUID inventoryItem, string path, IHttpServer httpServer, bool dumpAssetToFile) | ||
1065 | { | ||
1066 | m_dumpAssetToFile = dumpAssetToFile; | ||
1067 | |||
1068 | inventoryItemID = inventoryItem; | ||
1069 | uploaderPath = path; | ||
1070 | httpListener = httpServer; | ||
1071 | } | ||
1072 | |||
1073 | /// <summary> | ||
1074 | /// | ||
1075 | /// </summary> | ||
1076 | /// <param name="data"></param> | ||
1077 | /// <param name="path"></param> | ||
1078 | /// <param name="param"></param> | ||
1079 | /// <returns></returns> | ||
1080 | public string uploaderCaps(byte[] data, string path, string param) | ||
1081 | { | ||
1082 | UUID inv = inventoryItemID; | ||
1083 | string res = String.Empty; | ||
1084 | LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); | ||
1085 | UUID assetID = UUID.Zero; | ||
1086 | handlerUpdateItem = OnUpLoad; | ||
1087 | if (handlerUpdateItem != null) | ||
1088 | { | ||
1089 | assetID = handlerUpdateItem(inv, data); | ||
1090 | } | ||
1091 | |||
1092 | uploadComplete.new_asset = assetID.ToString(); | ||
1093 | uploadComplete.new_inventory_item = inv; | ||
1094 | uploadComplete.state = "complete"; | ||
1095 | |||
1096 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | ||
1097 | |||
1098 | httpListener.RemoveStreamHandler("POST", uploaderPath); | ||
1099 | |||
1100 | if (m_dumpAssetToFile) | ||
1101 | { | ||
1102 | SaveAssetToFile("updateditem" + Util.RandomClass.Next(1, 1000) + ".dat", data); | ||
1103 | } | ||
1104 | |||
1105 | return res; | ||
1106 | } | ||
1107 | ///Left this in and commented in case there are unforseen issues | ||
1108 | //private void SaveAssetToFile(string filename, byte[] data) | ||
1109 | //{ | ||
1110 | // FileStream fs = File.Create(filename); | ||
1111 | // BinaryWriter bw = new BinaryWriter(fs); | ||
1112 | // bw.Write(data); | ||
1113 | // bw.Close(); | ||
1114 | // fs.Close(); | ||
1115 | //} | ||
1116 | private static void SaveAssetToFile(string filename, byte[] data) | ||
1117 | { | ||
1118 | string assetPath = "UserAssets"; | ||
1119 | if (!Directory.Exists(assetPath)) | ||
1120 | { | ||
1121 | Directory.CreateDirectory(assetPath); | ||
1122 | } | ||
1123 | FileStream fs = File.Create(Path.Combine(assetPath, filename)); | ||
1124 | BinaryWriter bw = new BinaryWriter(fs); | ||
1125 | bw.Write(data); | ||
1126 | bw.Close(); | ||
1127 | fs.Close(); | ||
1128 | } | ||
1129 | } | ||
1130 | |||
1131 | /// <summary> | ||
1132 | /// This class is a callback invoked when a client sends asset data to | ||
1133 | /// a task inventory script update url | ||
1134 | /// </summary> | ||
1135 | public class TaskInventoryScriptUpdater | ||
1136 | { | ||
1137 | public event UpdateTaskScript OnUpLoad; | ||
1138 | |||
1139 | private UpdateTaskScript handlerUpdateTaskScript = null; | ||
1140 | |||
1141 | private string uploaderPath = String.Empty; | ||
1142 | private UUID inventoryItemID; | ||
1143 | private UUID primID; | ||
1144 | private bool isScriptRunning; | ||
1145 | private IHttpServer httpListener; | ||
1146 | private bool m_dumpAssetToFile; | ||
1147 | |||
1148 | public TaskInventoryScriptUpdater(UUID inventoryItemID, UUID primID, int isScriptRunning, | ||
1149 | string path, IHttpServer httpServer, bool dumpAssetToFile) | ||
1150 | { | ||
1151 | m_dumpAssetToFile = dumpAssetToFile; | ||
1152 | |||
1153 | this.inventoryItemID = inventoryItemID; | ||
1154 | this.primID = primID; | ||
1155 | |||
1156 | // This comes in over the packet as an integer, but actually appears to be treated as a bool | ||
1157 | this.isScriptRunning = (0 == isScriptRunning ? false : true); | ||
1158 | |||
1159 | uploaderPath = path; | ||
1160 | httpListener = httpServer; | ||
1161 | } | ||
1162 | |||
1163 | /// <summary> | ||
1164 | /// | ||
1165 | /// </summary> | ||
1166 | /// <param name="data"></param> | ||
1167 | /// <param name="path"></param> | ||
1168 | /// <param name="param"></param> | ||
1169 | /// <returns></returns> | ||
1170 | public string uploaderCaps(byte[] data, string path, string param) | ||
1171 | { | ||
1172 | try | ||
1173 | { | ||
1174 | // m_log.InfoFormat("[CAPS]: " + | ||
1175 | // "TaskInventoryScriptUpdater received data: {0}, path: {1}, param: {2}", | ||
1176 | // data, path, param)); | ||
1177 | |||
1178 | string res = String.Empty; | ||
1179 | LLSDTaskScriptUploadComplete uploadComplete = new LLSDTaskScriptUploadComplete(); | ||
1180 | |||
1181 | ArrayList errors = new ArrayList(); | ||
1182 | handlerUpdateTaskScript = OnUpLoad; | ||
1183 | if (handlerUpdateTaskScript != null) | ||
1184 | { | ||
1185 | handlerUpdateTaskScript(inventoryItemID, primID, isScriptRunning, data, ref errors); | ||
1186 | } | ||
1187 | |||
1188 | uploadComplete.new_asset = inventoryItemID; | ||
1189 | uploadComplete.compiled = errors.Count > 0 ? false : true; | ||
1190 | uploadComplete.state = "complete"; | ||
1191 | uploadComplete.errors = new OSDArray(); | ||
1192 | uploadComplete.errors.Array = errors; | ||
1193 | |||
1194 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | ||
1195 | |||
1196 | httpListener.RemoveStreamHandler("POST", uploaderPath); | ||
1197 | |||
1198 | if (m_dumpAssetToFile) | ||
1199 | { | ||
1200 | SaveAssetToFile("updatedtaskscript" + Util.RandomClass.Next(1, 1000) + ".dat", data); | ||
1201 | } | ||
1202 | |||
1203 | // m_log.InfoFormat("[CAPS]: TaskInventoryScriptUpdater.uploaderCaps res: {0}", res); | ||
1204 | |||
1205 | return res; | ||
1206 | } | ||
1207 | catch (Exception e) | ||
1208 | { | ||
1209 | m_log.Error("[CAPS]: " + e.ToString()); | ||
1210 | } | ||
1211 | |||
1212 | // XXX Maybe this should be some meaningful error packet | ||
1213 | return null; | ||
1214 | } | ||
1215 | ///Left this in and commented in case there are unforseen issues | ||
1216 | //private void SaveAssetToFile(string filename, byte[] data) | ||
1217 | //{ | ||
1218 | // FileStream fs = File.Create(filename); | ||
1219 | // BinaryWriter bw = new BinaryWriter(fs); | ||
1220 | // bw.Write(data); | ||
1221 | // bw.Close(); | ||
1222 | // fs.Close(); | ||
1223 | //} | ||
1224 | private static void SaveAssetToFile(string filename, byte[] data) | ||
1225 | { | ||
1226 | string assetPath = "UserAssets"; | ||
1227 | if (!Directory.Exists(assetPath)) | ||
1228 | { | ||
1229 | Directory.CreateDirectory(assetPath); | ||
1230 | } | ||
1231 | FileStream fs = File.Create(Path.Combine(assetPath, filename)); | ||
1232 | BinaryWriter bw = new BinaryWriter(fs); | ||
1233 | bw.Write(data); | ||
1234 | bw.Close(); | ||
1235 | fs.Close(); | ||
1236 | } | ||
1237 | } | ||
1238 | } | ||
1239 | } | ||