aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Cache/AssetTransactions.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-02-12 18:15:54 +0000
committerJustin Clarke Casey2008-02-12 18:15:54 +0000
commit6a3455a98cb3b7c910dd2d8d09f69d1c3acf7d2d (patch)
treefc05f0a0f1bc94ff4330358aab81f4c49fbdb0f6 /OpenSim/Framework/Communications/Cache/AssetTransactions.cs
parent* This fixes the object edit box's flipping checkboxes when you modify one of... (diff)
downloadopensim-SC_OLD-6a3455a98cb3b7c910dd2d8d09f69d1c3acf7d2d.zip
opensim-SC_OLD-6a3455a98cb3b7c910dd2d8d09f69d1c3acf7d2d.tar.gz
opensim-SC_OLD-6a3455a98cb3b7c910dd2d8d09f69d1c3acf7d2d.tar.bz2
opensim-SC_OLD-6a3455a98cb3b7c910dd2d8d09f69d1c3acf7d2d.tar.xz
* Refactoring: Rename AssetTransactions.cs and AssetTransactionsManager and align classes with file names
* Small amount of ndoc * This will probably require a prebuild and nant clean
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/AssetTransactions.cs')
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetTransactions.cs506
1 files changed, 0 insertions, 506 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs
deleted file mode 100644
index 996e5ba..0000000
--- a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs
+++ /dev/null
@@ -1,506 +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 OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.IO;
31using libsecondlife;
32using libsecondlife.Packets;
33using OpenSim.Framework.Servers;
34using OpenSim.Region.Capabilities;
35
36namespace OpenSim.Framework.Communications.Cache
37{
38 public class AgentAssetTransactions
39 {
40 private static readonly log4net.ILog m_log
41 = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
42
43 // Fields
44 public List<AssetCapsUploader> CapsUploaders = new List<AssetCapsUploader>();
45 public List<NoteCardCapsUpdate> NotecardUpdaters = new List<NoteCardCapsUpdate>();
46 public LLUUID UserID;
47 public Dictionary<LLUUID, AssetXferUploader> XferUploaders = new Dictionary<LLUUID, AssetXferUploader>();
48 public AssetTransactionManager Manager;
49 private bool m_dumpAssetsToFile;
50
51 // Methods
52 public AgentAssetTransactions(LLUUID agentID, AssetTransactionManager manager, bool dumpAssetsToFile)
53 {
54 UserID = agentID;
55 Manager = manager;
56 m_dumpAssetsToFile = dumpAssetsToFile;
57 }
58
59 public AssetCapsUploader RequestCapsUploader()
60 {
61 AssetCapsUploader uploader = new AssetCapsUploader();
62 CapsUploaders.Add(uploader);
63 return uploader;
64 }
65
66 public NoteCardCapsUpdate RequestNoteCardUpdater()
67 {
68 NoteCardCapsUpdate update = new NoteCardCapsUpdate();
69 NotecardUpdaters.Add(update);
70 return update;
71 }
72
73 public AssetXferUploader RequestXferUploader(LLUUID transactionID)
74 {
75 if (!XferUploaders.ContainsKey(transactionID))
76 {
77 AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile);
78
79 lock (XferUploaders)
80 {
81 XferUploaders.Add(transactionID, uploader);
82 }
83
84 return uploader;
85 }
86 return null;
87 }
88
89 public void HandleXfer(ulong xferID, uint packetID, byte[] data)
90 {
91 AssetXferUploader uploaderFound = null;
92
93 lock (XferUploaders)
94 {
95 foreach (AssetXferUploader uploader in XferUploaders.Values)
96 {
97 if (uploader.XferID == xferID)
98 {
99 if (uploader.HandleXferPacket(xferID, packetID, data))
100 {
101 uploaderFound = uploader;
102 }
103
104 break;
105 }
106 }
107
108 // Remove the uploader once the uploader is complete
109 //[don't think we can be sure a upload has finished from here, uploads are multi part things]
110 // [or maybe we can if we do more checking like data lenght checks]
111 if (uploaderFound != null)
112 {
113// m_log.Info(
114// String.Format(
115// "[ASSET TRANSACTIONS] Removing asset xfer uploader with transfer id {0}, transaction {1}",
116// xferID, uploaderFound.TransactionID));
117
118 // XferUploaders.Remove(uploaderFound.TransactionID);
119
120 //m_log.InfoFormat("[ASSET TRANSACTIONS] Current uploaders: {0}", XferUploaders.Count);
121 }
122 }
123 }
124
125 public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
126 uint callbackID, string description, string name, sbyte invType,
127 sbyte type, byte wearableType, uint nextOwnerMask)
128 {
129 if (XferUploaders.ContainsKey(transactionID))
130 {
131 XferUploaders[transactionID].RequestCreateInventoryItem(remoteClient, transactionID, folderID,
132 callbackID, description, name, invType, type,
133 wearableType, nextOwnerMask);
134 }
135 }
136
137 /// <summary>
138 /// Get an uploaded asset. If the data is successfully retrieved, the transaction will be removed.
139 /// </summary>
140 /// <param name="transactionID"></param>
141 /// <returns>The asset if the upload has completed, null if it has not.</returns>
142 public AssetBase GetTransactionAsset(LLUUID transactionID)
143 {
144 if (XferUploaders.ContainsKey(transactionID))
145 {
146 AssetXferUploader uploader = XferUploaders[transactionID];
147 AssetBase asset = uploader.GetAssetData();
148
149 lock (XferUploaders)
150 {
151 XferUploaders.Remove(transactionID);
152 }
153
154 return asset;
155 }
156
157 return null;
158 }
159
160 // Nested Types
161 public class AssetXferUploader
162 {
163 // Fields
164 public bool AddToInventory;
165 public AssetBase Asset;
166 public LLUUID InventFolder = LLUUID.Zero;
167 private IClientAPI ourClient;
168 public LLUUID TransactionID = LLUUID.Zero;
169 public bool UploadComplete;
170 public ulong XferID;
171 private string m_name = String.Empty;
172 private string m_description = String.Empty;
173 private sbyte type = 0;
174 private sbyte invType = 0;
175 private uint nextPerm = 0;
176 private bool m_finished = false;
177 private bool m_createItem = false;
178 private AgentAssetTransactions m_userTransactions;
179 private bool m_storeLocal;
180 private bool m_dumpAssetToFile;
181
182 public AssetXferUploader(AgentAssetTransactions transactions, bool dumpAssetToFile)
183 {
184 m_userTransactions = transactions;
185 m_dumpAssetToFile = dumpAssetToFile;
186 }
187
188 /// <summary>
189 /// Process transfer data received from the client.
190 /// </summary>
191 /// <param name="xferID"></param>
192 /// <param name="packetID"></param>
193 /// <param name="data"></param>
194 /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns>
195 public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data)
196 {
197 if (XferID == xferID)
198 {
199 if (Asset.Data.Length > 1)
200 {
201 byte[] destinationArray = new byte[Asset.Data.Length + data.Length];
202 Array.Copy(Asset.Data, 0, destinationArray, 0, Asset.Data.Length);
203 Array.Copy(data, 0, destinationArray, Asset.Data.Length, data.Length);
204 Asset.Data = destinationArray;
205 }
206 else
207 {
208 byte[] buffer2 = new byte[data.Length - 4];
209 Array.Copy(data, 4, buffer2, 0, data.Length - 4);
210 Asset.Data = buffer2;
211 }
212 ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket();
213 newPack.XferID.ID = xferID;
214 newPack.XferID.Packet = packetID;
215 ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset);
216 if ((packetID & 0x80000000) != 0)
217 {
218 SendCompleteMessage();
219 return true;
220 }
221 }
222
223 return false;
224 }
225
226 /// <summary>
227 /// Initialise asset transfer from the client
228 /// </summary>
229 /// <param name="xferID"></param>
230 /// <param name="packetID"></param>
231 /// <param name="data"></param>
232 /// <returns>True if the transfer is complete, false otherwise</returns>
233 public bool Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data,
234 bool storeLocal, bool tempFile)
235 {
236 ourClient = remoteClient;
237 Asset = new AssetBase();
238 Asset.FullID = assetID;
239 Asset.InvType = type;
240 Asset.Type = type;
241 Asset.Data = data;
242 Asset.Name = "blank";
243 Asset.Description = "empty";
244 Asset.Local = storeLocal;
245 Asset.Temporary = tempFile;
246
247 TransactionID = transaction;
248 m_storeLocal = storeLocal;
249 if (Asset.Data.Length > 2)
250 {
251 SendCompleteMessage();
252 return true;
253 }
254 else
255 {
256 ReqestStartXfer();
257 }
258
259 return false;
260 }
261
262 protected void ReqestStartXfer()
263 {
264 UploadComplete = false;
265 XferID = Util.GetNextXferID();
266 RequestXferPacket newPack = new RequestXferPacket();
267 newPack.XferID.ID = XferID;
268 newPack.XferID.VFileType = Asset.Type;
269 newPack.XferID.VFileID = Asset.FullID;
270 newPack.XferID.FilePath = 0;
271 newPack.XferID.Filename = new byte[0];
272 ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset);
273 }
274
275 protected void SendCompleteMessage()
276 {
277 UploadComplete = true;
278 AssetUploadCompletePacket newPack = new AssetUploadCompletePacket();
279 newPack.AssetBlock.Type = Asset.Type;
280 newPack.AssetBlock.Success = true;
281 newPack.AssetBlock.UUID = Asset.FullID;
282 ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset);
283 m_finished = true;
284 if (m_createItem)
285 {
286 DoCreateItem();
287 }
288 else if (m_storeLocal)
289 {
290 m_userTransactions.Manager.CommsManager.AssetCache.AddAsset(Asset);
291 }
292
293 // Console.WriteLine("upload complete "+ this.TransactionID);
294
295 if (m_dumpAssetToFile)
296 {
297 DateTime now = DateTime.Now;
298 string filename =
299 String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day,
300 now.Hour, now.Minute, now.Second, Asset.Name, Asset.Type);
301 SaveAssetToFile(filename, Asset.Data);
302 }
303 }
304
305 ///Left this in and commented in case there are unforseen issues
306 //private void SaveAssetToFile(string filename, byte[] data)
307 //{
308 // FileStream fs = File.Create(filename);
309 // BinaryWriter bw = new BinaryWriter(fs);
310 // bw.Write(data);
311 // bw.Close();
312 // fs.Close();
313 //}
314 private void SaveAssetToFile(string filename, byte[] data)
315 {
316 string assetPath = "UserAssets";
317 if (!Directory.Exists(assetPath))
318 {
319 Directory.CreateDirectory(assetPath);
320 }
321 FileStream fs = File.Create(Path.Combine(assetPath, filename));
322 BinaryWriter bw = new BinaryWriter(fs);
323 bw.Write(data);
324 bw.Close();
325 fs.Close();
326 }
327
328 public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
329 uint callbackID, string description, string name, sbyte invType,
330 sbyte type, byte wearableType, uint nextOwnerMask)
331 {
332 if (TransactionID == transactionID)
333 {
334 InventFolder = folderID;
335 m_name = name;
336 m_description = description;
337 this.type = type;
338 this.invType = invType;
339 nextPerm = nextOwnerMask;
340 Asset.Name = name;
341 Asset.Description = description;
342 Asset.Type = type;
343 Asset.InvType = invType;
344 m_createItem = true;
345 if (m_finished)
346 {
347 DoCreateItem();
348 }
349 }
350 }
351
352 private void DoCreateItem()
353 {
354 //really need to fix this call, if lbsa71 saw this he would die.
355 m_userTransactions.Manager.CommsManager.AssetCache.AddAsset(Asset);
356 CachedUserInfo userInfo =
357 m_userTransactions.Manager.CommsManager.UserProfileCacheService.GetUserDetails(ourClient.AgentId);
358 if (userInfo != null)
359 {
360 InventoryItemBase item = new InventoryItemBase();
361 item.avatarID = ourClient.AgentId;
362 item.creatorsID = ourClient.AgentId;
363 item.inventoryID = LLUUID.Random();
364 item.assetID = Asset.FullID;
365 item.inventoryDescription = m_description;
366 item.inventoryName = m_name;
367 item.assetType = type;
368 item.invType = invType;
369 item.parentFolderID = InventFolder;
370 item.inventoryBasePermissions = 2147483647;
371 item.inventoryCurrentPermissions = 2147483647;
372 item.inventoryNextPermissions = nextPerm;
373
374 userInfo.AddItem(ourClient.AgentId, item);
375 ourClient.SendInventoryItemCreateUpdate(item);
376 }
377 }
378
379 public AssetBase GetAssetData()
380 {
381 if (m_finished)
382 {
383 return Asset;
384 }
385 return null;
386 }
387 }
388
389 #region Nested Classes currently not in use (waiting for them to be enabled)
390
391 public class AssetCapsUploader
392 {
393 // Fields
394 private BaseHttpServer httpListener;
395 private LLUUID inventoryItemID;
396 private string m_assetDescription = String.Empty;
397 private string m_assetName = String.Empty;
398 private LLUUID m_folderID;
399 private LLUUID newAssetID;
400 private bool m_dumpImageToFile;
401 private string uploaderPath = String.Empty;
402
403 // Events
404 public event UpLoadedAsset OnUpLoad;
405
406 // Methods
407 public void Initialise(string assetName, string assetDescription, LLUUID assetID, LLUUID inventoryItem,
408 LLUUID folderID, string path, BaseHttpServer httpServer, bool dumpImageToFile)
409 {
410 m_assetName = assetName;
411 m_assetDescription = assetDescription;
412 m_folderID = folderID;
413 newAssetID = assetID;
414 inventoryItemID = inventoryItem;
415 uploaderPath = path;
416 httpListener = httpServer;
417 m_dumpImageToFile = dumpImageToFile;
418 }
419
420 private void SaveImageToFile(string filename, byte[] data)
421 {
422 FileStream output = File.Create(filename);
423 BinaryWriter writer = new BinaryWriter(output);
424 writer.Write(data);
425 writer.Close();
426 output.Close();
427 }
428
429 public string uploaderCaps(byte[] data, string path, string param)
430 {
431 LLUUID inventoryItemID = this.inventoryItemID;
432 string text = String.Empty;
433 LLSDAssetUploadComplete complete = new LLSDAssetUploadComplete();
434 complete.new_asset = newAssetID.ToString();
435 complete.new_inventory_item = inventoryItemID;
436 complete.state = "complete";
437 text = LLSDHelpers.SerialiseLLSDReply(complete);
438 httpListener.RemoveStreamHandler("POST", uploaderPath);
439 if (m_dumpImageToFile)
440 {
441 SaveImageToFile(m_assetName + ".jp2", data);
442 }
443 if (OnUpLoad != null)
444 {
445 OnUpLoad(m_assetName, "description", newAssetID, inventoryItemID, LLUUID.Zero, data, String.Empty, String.Empty);
446 }
447 return text;
448 }
449 }
450
451 public class NoteCardCapsUpdate
452 {
453 // Fields
454 private BaseHttpServer httpListener;
455 private LLUUID inventoryItemID;
456 private string m_assetName = String.Empty;
457 private LLUUID newAssetID;
458 private bool SaveImages = false;
459 private string uploaderPath = String.Empty;
460
461 // Events
462 public event UpLoadedAsset OnUpLoad;
463
464 // Methods
465 public void Initialise(LLUUID inventoryItem, string path, BaseHttpServer httpServer)
466 {
467 inventoryItemID = inventoryItem;
468 uploaderPath = path;
469 httpListener = httpServer;
470 newAssetID = LLUUID.Random();
471 }
472
473 private void SaveImageToFile(string filename, byte[] data)
474 {
475 FileStream output = File.Create(filename);
476 BinaryWriter writer = new BinaryWriter(output);
477 writer.Write(data);
478 writer.Close();
479 output.Close();
480 }
481
482 public string uploaderCaps(byte[] data, string path, string param)
483 {
484 LLUUID inventoryItemID = this.inventoryItemID;
485 string text = String.Empty;
486 LLSDAssetUploadComplete complete = new LLSDAssetUploadComplete();
487 complete.new_asset = newAssetID.ToString();
488 complete.new_inventory_item = inventoryItemID;
489 complete.state = "complete";
490 text = LLSDHelpers.SerialiseLLSDReply(complete);
491 httpListener.RemoveStreamHandler("POST", uploaderPath);
492 if (SaveImages)
493 {
494 SaveImageToFile(m_assetName + "notecard.txt", data);
495 }
496 if (OnUpLoad != null)
497 {
498 OnUpLoad(m_assetName, "description", newAssetID, inventoryItemID, LLUUID.Zero, data, String.Empty, String.Empty);
499 }
500 return text;
501 }
502 }
503
504 #endregion
505 }
506}