aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Capabilities/Caps.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2007-12-24 22:35:01 +0000
committerJustin Clarke Casey2007-12-24 22:35:01 +0000
commit280a5cba8b6ab1566b1f5d2dae96e2f8402c8ab4 (patch)
tree961f90ecf615e01e2263dacafec293ee66f1f1d0 /OpenSim/Framework/Communications/Capabilities/Caps.cs
parentAgain, great thanks to Alondria for: (diff)
downloadopensim-SC_OLD-280a5cba8b6ab1566b1f5d2dae96e2f8402c8ab4.zip
opensim-SC_OLD-280a5cba8b6ab1566b1f5d2dae96e2f8402c8ab4.tar.gz
opensim-SC_OLD-280a5cba8b6ab1566b1f5d2dae96e2f8402c8ab4.tar.bz2
opensim-SC_OLD-280a5cba8b6ab1566b1f5d2dae96e2f8402c8ab4.tar.xz
Prim inventory script saving phase 1. Create necessary CAPS structures for correctly accepting prim inventory script updates.
No user functionality yet. Refactoring to follow.
Diffstat (limited to 'OpenSim/Framework/Communications/Capabilities/Caps.cs')
-rw-r--r--OpenSim/Framework/Communications/Capabilities/Caps.cs203
1 files changed, 196 insertions, 7 deletions
diff --git a/OpenSim/Framework/Communications/Capabilities/Caps.cs b/OpenSim/Framework/Communications/Capabilities/Caps.cs
index eb678a0..a72abbe 100644
--- a/OpenSim/Framework/Communications/Capabilities/Caps.cs
+++ b/OpenSim/Framework/Communications/Capabilities/Caps.cs
@@ -42,21 +42,29 @@ namespace OpenSim.Region.Capabilities
42 string inventoryType, string assetType); 42 string inventoryType, string assetType);
43 43
44 public delegate LLUUID UpdateItem(LLUUID itemID, byte[] data); 44 public delegate LLUUID UpdateItem(LLUUID itemID, byte[] data);
45
46 public delegate LLUUID UpdateTaskScript(LLUUID itemID, LLUUID primID, bool isScriptRunning, byte[] data);
45 47
46 public delegate void NewInventoryItem(LLUUID userID, InventoryItemBase item); 48 public delegate void NewInventoryItem(LLUUID userID, InventoryItemBase item);
47 49
48 public delegate LLUUID ItemUpdatedCallback(LLUUID userID, LLUUID itemID, byte[] data); 50 public delegate LLUUID ItemUpdatedCallback(LLUUID userID, LLUUID itemID, byte[] data);
51
52 public delegate LLUUID TaskScriptUpdatedCallback(LLUUID userID, LLUUID itemID, LLUUID primID,
53 bool isScriptRunning, byte[] data);
49 54
50 public class Caps 55 public class Caps
51 { 56 {
52 private string m_httpListenerHostName; 57 private string m_httpListenerHostName;
53 private uint m_httpListenPort; 58 private uint m_httpListenPort;
59
54 private string m_capsObjectPath = "00001-"; 60 private string m_capsObjectPath = "00001-";
55 private string m_requestPath = "0000/"; 61 private string m_requestPath = "0000/";
56 private string m_mapLayerPath = "0001/"; 62 private string m_mapLayerPath = "0001/";
57 private string m_newInventory = "0002/"; 63 private string m_newInventory = "0002/";
58 //private string m_requestTexture = "0003/"; 64 //private string m_requestTexture = "0003/";
59 private string m_notecardUpdatePath = "0004/"; 65 private string m_notecardUpdatePath = "0004/";
66 private string m_notecardTaskUpdatePath = "0005/";
67
60 //private string eventQueue = "0100/"; 68 //private string eventQueue = "0100/";
61 private BaseHttpServer m_httpListener; 69 private BaseHttpServer m_httpListener;
62 private LLUUID m_agentID; 70 private LLUUID m_agentID;
@@ -65,8 +73,11 @@ namespace OpenSim.Region.Capabilities
65 private Queue<string> m_capsEventQueue = new Queue<string>(); 73 private Queue<string> m_capsEventQueue = new Queue<string>();
66 private bool m_dumpAssetsToFile; 74 private bool m_dumpAssetsToFile;
67 75
76 // These are callbacks which will be setup by the scene so that we can update scene data when we
77 // receive capability calls
68 public NewInventoryItem AddNewInventoryItem = null; 78 public NewInventoryItem AddNewInventoryItem = null;
69 public ItemUpdatedCallback ItemUpdatedCall = null; 79 public ItemUpdatedCallback ItemUpdatedCall = null;
80 public TaskScriptUpdatedCallback TaskScriptUpdatedCall = null;
70 81
71 public Caps(AssetCache assetCache, BaseHttpServer httpServer, string httpListen, uint httpPort, string capsPath, 82 public Caps(AssetCache assetCache, BaseHttpServer httpServer, string httpListen, uint httpPort, string capsPath,
72 LLUUID agent, bool dumpAssetsToFile) 83 LLUUID agent, bool dumpAssetsToFile)
@@ -100,9 +111,11 @@ namespace OpenSim.Region.Capabilities
100 AddLegacyCapsHandler(m_httpListener, m_requestPath, CapsRequest); 111 AddLegacyCapsHandler(m_httpListener, m_requestPath, CapsRequest);
101 //AddLegacyCapsHandler(m_httpListener, m_requestTexture , RequestTexture); 112 //AddLegacyCapsHandler(m_httpListener, m_requestTexture , RequestTexture);
102 AddLegacyCapsHandler(m_httpListener, m_notecardUpdatePath, NoteCardAgentInventory); 113 AddLegacyCapsHandler(m_httpListener, m_notecardUpdatePath, NoteCardAgentInventory);
114 AddLegacyCapsHandler(m_httpListener, m_notecardTaskUpdatePath, ScriptTaskInventory);
103 } 115 }
104 catch 116 catch (Exception e)
105 { 117 {
118 MainLog.Instance.Error("CAPS", e.ToString());
106 } 119 }
107 } 120 }
108 121
@@ -117,7 +130,7 @@ namespace OpenSim.Region.Capabilities
117 } 130 }
118 131
119 /// <summary> 132 /// <summary>
120 /// 133 /// Construct a client response detailing all the capabilities this server can provide.
121 /// </summary> 134 /// </summary>
122 /// <param name="request"></param> 135 /// <param name="request"></param>
123 /// <param name="path"></param> 136 /// <param name="path"></param>
@@ -131,7 +144,7 @@ namespace OpenSim.Region.Capabilities
131 } 144 }
132 145
133 /// <summary> 146 /// <summary>
134 /// 147 /// Return an LLSDCapsDetails listing all the capabilities this server can provide
135 /// </summary> 148 /// </summary>
136 /// <returns></returns> 149 /// <returns></returns>
137 protected LLSDCapsDetails GetCapabilities() 150 protected LLSDCapsDetails GetCapabilities()
@@ -144,7 +157,7 @@ namespace OpenSim.Region.Capabilities
144 caps.NewFileAgentInventory = capsBaseUrl + m_newInventory; 157 caps.NewFileAgentInventory = capsBaseUrl + m_newInventory;
145 caps.UpdateNotecardAgentInventory = capsBaseUrl + m_notecardUpdatePath; 158 caps.UpdateNotecardAgentInventory = capsBaseUrl + m_notecardUpdatePath;
146 caps.UpdateScriptAgentInventory = capsBaseUrl + m_notecardUpdatePath; 159 caps.UpdateScriptAgentInventory = capsBaseUrl + m_notecardUpdatePath;
147 // caps.UpdateScriptTaskInventory = capsBaseUrl + m_requestTexture; 160 caps.UpdateScriptTaskInventory = capsBaseUrl + m_notecardTaskUpdatePath;
148 return caps; 161 return caps;
149 } 162 }
150 163
@@ -249,9 +262,65 @@ namespace OpenSim.Region.Capabilities
249 } 262 }
250 263
251 #endregion 264 #endregion
265
266 /// <summary>
267 /// Callback for a client request for an upload url for a script task
268 /// inventory update
269 /// </summary>
270 /// <param name="request"></param>
271 /// <param name="path"></param>
272 /// <param name="param"></param>
273 /// <returns></returns>
274 public string ScriptTaskInventory(string request, string path, string param)
275 {
276 try
277 {
278// MainLog.Instance.Debug("CAPS", "request: {0}, path: {1}, param: {2}", request, path, param);
279
280 Hashtable hash = (Hashtable)LLSD.LLSDDeserialize(Helpers.StringToField(request));
281 LLSDTaskScriptUpdate llsdUpdateRequest = new LLSDTaskScriptUpdate();
282 LLSDHelpers.DeserialiseLLSDMap(hash, llsdUpdateRequest);
283
284 string capsBase = "/CAPS/" + m_capsObjectPath;
285 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
286
287 TaskInventoryScriptUpdater uploader =
288 new TaskInventoryScriptUpdater(
289 llsdUpdateRequest.item_id,
290 llsdUpdateRequest.task_id,
291 llsdUpdateRequest.is_script_running,
292 capsBase + uploaderPath,
293 m_httpListener,
294 m_dumpAssetsToFile);
295 uploader.OnUpLoad += TaskScriptUpdated;
296
297 m_httpListener.AddStreamHandler(
298 new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps));
299 string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase +
300 uploaderPath;
301
302 LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
303 uploadResponse.uploader = uploaderURL;
304 uploadResponse.state = "upload";
305
306// MainLog.Instance.Verbose(
307// "CAPS",
308// "ScriptTaskInventory response: {0}",
309// LLSDHelpers.SerialiseLLSDReply(uploadResponse));
310
311 return LLSDHelpers.SerialiseLLSDReply(uploadResponse);
312 }
313 catch (Exception e)
314 {
315 MainLog.Instance.Error("CAPS", e.ToString());
316 }
317
318 return null;
319 }
252 320
253 /// <summary> 321 /// <summary>
254 /// 322 /// Callback for a client request for an upload url for a notecard (or script)
323 /// agent inventory update
255 /// </summary> 324 /// </summary>
256 /// <param name="request"></param> 325 /// <param name="request"></param>
257 /// <param name="path"></param> 326 /// <param name="path"></param>
@@ -265,11 +334,10 @@ namespace OpenSim.Region.Capabilities
265 LLSDHelpers.DeserialiseLLSDMap(hash, llsdRequest); 334 LLSDHelpers.DeserialiseLLSDMap(hash, llsdRequest);
266 335
267 string capsBase = "/CAPS/" + m_capsObjectPath; 336 string capsBase = "/CAPS/" + m_capsObjectPath;
268 LLUUID newInvItem = llsdRequest.item_id;
269 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); 337 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
270 338
271 ItemUpdater uploader = 339 ItemUpdater uploader =
272 new ItemUpdater(newInvItem, capsBase + uploaderPath, m_httpListener, m_dumpAssetsToFile); 340 new ItemUpdater(llsdRequest.item_id, capsBase + uploaderPath, m_httpListener, m_dumpAssetsToFile);
273 uploader.OnUpLoad += ItemUpdated; 341 uploader.OnUpLoad += ItemUpdated;
274 342
275 m_httpListener.AddStreamHandler( 343 m_httpListener.AddStreamHandler(
@@ -281,6 +349,8 @@ namespace OpenSim.Region.Capabilities
281 uploadResponse.uploader = uploaderURL; 349 uploadResponse.uploader = uploaderURL;
282 uploadResponse.state = "upload"; 350 uploadResponse.state = "upload";
283 351
352 MainLog.Instance.Verbose("CAPS", "NoteCardAgentInventory response: {0}", LLSDHelpers.SerialiseLLSDReply(uploadResponse));
353
284 return LLSDHelpers.SerialiseLLSDReply(uploadResponse); 354 return LLSDHelpers.SerialiseLLSDReply(uploadResponse);
285 } 355 }
286 356
@@ -368,12 +438,36 @@ namespace OpenSim.Region.Capabilities
368 } 438 }
369 } 439 }
370 440
441 /// <summary>
442 /// Called when new asset data for an agent inventory item update has been uploaded.
443 /// </summary>
444 /// <param name="itemID">Item to update</param>
445 /// <param name="data">New asset data</param>
446 /// <returns></returns>
371 public LLUUID ItemUpdated(LLUUID itemID, byte[] data) 447 public LLUUID ItemUpdated(LLUUID itemID, byte[] data)
372 { 448 {
373 if (ItemUpdatedCall != null) 449 if (ItemUpdatedCall != null)
374 { 450 {
375 return ItemUpdatedCall(m_agentID, itemID, data); 451 return ItemUpdatedCall(m_agentID, itemID, data);
376 } 452 }
453
454 return LLUUID.Zero;
455 }
456
457 /// <summary>
458 /// Called when new asset data for an agent inventory item update has been uploaded.
459 /// </summary>
460 /// <param name="itemID">Item to update</param>
461 /// <param name="primID">Prim containing item to update</param>
462 /// <param name="isScriptRunning">Signals whether the script to update is currently running</param>
463 /// <param name="data">New asset data</param>
464 public LLUUID TaskScriptUpdated(LLUUID itemID, LLUUID primID, bool isScriptRunning, byte[] data)
465 {
466 if (TaskScriptUpdatedCall != null)
467 {
468 return TaskScriptUpdatedCall(m_agentID, itemID, primID, isScriptRunning, data);
469 }
470
377 return LLUUID.Zero; 471 return LLUUID.Zero;
378 } 472 }
379 473
@@ -452,6 +546,10 @@ namespace OpenSim.Region.Capabilities
452 } 546 }
453 } 547 }
454 548
549 /// <summary>
550 /// This class is a callback invoked when a client sends asset data to
551 /// an agent inventory notecard update url
552 /// </summary>
455 public class ItemUpdater 553 public class ItemUpdater
456 { 554 {
457 public event UpdateItem OnUpLoad; 555 public event UpdateItem OnUpLoad;
@@ -514,5 +612,96 @@ namespace OpenSim.Region.Capabilities
514 fs.Close(); 612 fs.Close();
515 } 613 }
516 } 614 }
615
616 /// <summary>
617 /// This class is a callback invoked when a client sends asset data to
618 /// a task inventory script update url
619 /// </summary>
620 public class TaskInventoryScriptUpdater
621 {
622 public event UpdateTaskScript OnUpLoad;
623
624 private string uploaderPath = "";
625 private LLUUID inventoryItemID;
626 private LLUUID primID;
627 private bool isScriptRunning;
628 private BaseHttpServer httpListener;
629 private bool m_dumpAssetToFile;
630
631 public TaskInventoryScriptUpdater(LLUUID inventoryItemID, LLUUID primID, int isScriptRunning,
632 string path, BaseHttpServer httpServer, bool dumpAssetToFile)
633 {
634 m_dumpAssetToFile = dumpAssetToFile;
635
636 this.inventoryItemID = inventoryItemID;
637 this.primID = primID;
638
639 // This comes in over the packet as an integer, but actually appears to be treated as a bool
640 this.isScriptRunning = (0 == isScriptRunning ? false : true);
641
642 uploaderPath = path;
643 httpListener = httpServer;
644 }
645
646 /// <summary>
647 ///
648 /// </summary>
649 /// <param name="data"></param>
650 /// <param name="path"></param>
651 /// <param name="param"></param>
652 /// <returns></returns>
653 public string uploaderCaps(byte[] data, string path, string param)
654 {
655 try
656 {
657// MainLog.Instance.Verbose(
658// "CAPS",
659// "TaskInventoryScriptUpdater received data: {0}, path: {1}, param: {2}",
660// data, path, param);
661
662 string res = "";
663 LLSDTaskInventoryUploadComplete uploadComplete = new LLSDTaskInventoryUploadComplete();
664 LLUUID assetID = LLUUID.Zero;
665
666 if (OnUpLoad != null)
667 {
668 assetID = OnUpLoad(inventoryItemID, primID, isScriptRunning, data);
669 }
670
671 uploadComplete.item_id = inventoryItemID;
672 uploadComplete.task_id = primID;
673 uploadComplete.state = "complete";
674
675 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
676
677 httpListener.RemoveStreamHandler("POST", uploaderPath);
678
679 if (m_dumpAssetToFile)
680 {
681 SaveAssetToFile("updatedtaskscript" + Util.RandomClass.Next(1, 1000) + ".dat", data);
682 }
683
684// MainLog.Instance.Verbose("CAPS", "TaskInventoryScriptUpdater.uploaderCaps res: {0}", res);
685
686 return res;
687 }
688 catch (Exception e)
689 {
690 MainLog.Instance.Error("CAPS", e.ToString());
691 }
692
693 // XXX Maybe this should be some meaningful error packet
694 return null;
695 }
696
697 private void SaveAssetToFile(string filename, byte[] data)
698 {
699 FileStream fs = File.Create(filename);
700 BinaryWriter bw = new BinaryWriter(fs);
701 bw.Write(data);
702 bw.Close();
703 fs.Close();
704 }
705 }
517 } 706 }
518} 707}