aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs')
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs186
1 files changed, 170 insertions, 16 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
index 5e772e6..ffff37d 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Reflection; 30using System.Reflection;
31using System.Collections.Generic;
31using log4net; 32using log4net;
32using OpenMetaverse; 33using OpenMetaverse;
33using OpenSim.Framework; 34using OpenSim.Framework;
@@ -39,6 +40,13 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
39{ 40{
40 public class AssetXferUploader 41 public class AssetXferUploader
41 { 42 {
43 // Viewer's notion of the default texture
44 private List<UUID> defaultIDs = new List<UUID> {
45 new UUID("5748decc-f629-461c-9a36-a35a221fe21f"),
46 new UUID("7ca39b4c-bd19-4699-aff7-f93fd03d3e7b"),
47 new UUID("6522e74d-1660-4e7f-b601-6f48c1659a77"),
48 new UUID("c228d1cf-4b5d-4ba8-84f4-899a0796aa97")
49 };
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 51
44 /// <summary> 52 /// <summary>
@@ -86,6 +94,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
86 94
87 private sbyte type = 0; 95 private sbyte type = 0;
88 private byte wearableType = 0; 96 private byte wearableType = 0;
97 private byte[] m_oldData = null;
89 public ulong XferID; 98 public ulong XferID;
90 private Scene m_Scene; 99 private Scene m_Scene;
91 100
@@ -128,18 +137,27 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
128 137
129 if (XferID == xferID) 138 if (XferID == xferID)
130 { 139 {
131 if (m_asset.Data.Length > 1) 140 lock (this)
132 { 141 {
133 byte[] destinationArray = new byte[m_asset.Data.Length + data.Length]; 142 int assetLength = m_asset.Data.Length;
134 Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length); 143 int dataLength = data.Length;
135 Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length); 144
136 m_asset.Data = destinationArray; 145 if (m_asset.Data.Length > 1)
137 } 146 {
138 else 147 byte[] destinationArray = new byte[assetLength + dataLength];
139 { 148 Array.Copy(m_asset.Data, 0, destinationArray, 0, assetLength);
140 byte[] buffer2 = new byte[data.Length - 4]; 149 Array.Copy(data, 0, destinationArray, assetLength, dataLength);
141 Array.Copy(data, 4, buffer2, 0, data.Length - 4); 150 m_asset.Data = destinationArray;
142 m_asset.Data = buffer2; 151 }
152 else
153 {
154 if (dataLength > 4)
155 {
156 byte[] buffer2 = new byte[dataLength - 4];
157 Array.Copy(data, 4, buffer2, 0, dataLength - 4);
158 m_asset.Data = buffer2;
159 }
160 }
143 } 161 }
144 162
145 ourClient.SendConfirmXfer(xferID, packetID); 163 ourClient.SendConfirmXfer(xferID, packetID);
@@ -243,10 +261,10 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
243 { 261 {
244 CompleteTaskItemUpdate(m_updateTaskItemData); 262 CompleteTaskItemUpdate(m_updateTaskItemData);
245 } 263 }
246// else if (m_storeLocal) 264 else if (m_asset.Local)
247// { 265 {
248// m_Scene.AssetService.Store(m_asset); 266 m_Scene.AssetService.Store(m_asset);
249// } 267 }
250 } 268 }
251 269
252 m_log.DebugFormat( 270 m_log.DebugFormat(
@@ -374,6 +392,11 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
374// m_asset.FullID, item.Name, ourClient.Name); 392// m_asset.FullID, item.Name, ourClient.Name);
375 393
376 m_Scene.AssetService.Store(m_asset); 394 m_Scene.AssetService.Store(m_asset);
395 if (m_asset.FullID != UUID.Zero)
396 {
397 item.AssetID = m_asset.FullID;
398 m_Scene.InventoryService.UpdateItem(item);
399 }
377 400
378 m_transactions.RemoveXferUploader(m_transactionID); 401 m_transactions.RemoveXferUploader(m_transactionID);
379 } 402 }
@@ -395,6 +418,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
395 418
396 private void CompleteCreateItem(uint callbackID) 419 private void CompleteCreateItem(uint callbackID)
397 { 420 {
421 ValidateAssets();
398 m_Scene.AssetService.Store(m_asset); 422 m_Scene.AssetService.Store(m_asset);
399 423
400 InventoryItemBase item = new InventoryItemBase(); 424 InventoryItemBase item = new InventoryItemBase();
@@ -415,6 +439,9 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
415 item.Flags = (uint) wearableType; 439 item.Flags = (uint) wearableType;
416 item.CreationDate = Util.UnixTimeSinceEpoch(); 440 item.CreationDate = Util.UnixTimeSinceEpoch();
417 441
442 m_log.DebugFormat("[XFER]: Created item {0} with asset {1}",
443 item.ID, item.AssetID);
444
418 if (m_Scene.AddInventoryItem(item)) 445 if (m_Scene.AddInventoryItem(item))
419 ourClient.SendInventoryItemCreateUpdate(item, callbackID); 446 ourClient.SendInventoryItemCreateUpdate(item, callbackID);
420 else 447 else
@@ -422,5 +449,132 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
422 449
423 m_transactions.RemoveXferUploader(m_transactionID); 450 m_transactions.RemoveXferUploader(m_transactionID);
424 } 451 }
452
453 private void ValidateAssets()
454 {
455 if (m_asset.Type == (sbyte)AssetType.Clothing ||
456 m_asset.Type == (sbyte)AssetType.Bodypart)
457 {
458 string content = System.Text.Encoding.ASCII.GetString(m_asset.Data);
459 string[] lines = content.Split(new char[] {'\n'});
460
461 List<string> validated = new List<string>();
462
463 Dictionary<int, UUID> allowed = ExtractTexturesFromOldData();
464
465 int textures = 0;
466
467 foreach (string line in lines)
468 {
469 try
470 {
471 if (line.StartsWith("textures "))
472 {
473 textures = Convert.ToInt32(line.Substring(9));
474 validated.Add(line);
475 }
476 else if (textures > 0)
477 {
478 string[] parts = line.Split(new char[] {' '});
479
480 UUID tx = new UUID(parts[1]);
481 int id = Convert.ToInt32(parts[0]);
482
483 if (defaultIDs.Contains(tx) || tx == UUID.Zero ||
484 (allowed.ContainsKey(id) && allowed[id] == tx))
485 {
486 validated.Add(parts[0] + " " + tx.ToString());
487 }
488 else
489 {
490 int perms = m_Scene.InventoryService.GetAssetPermissions(ourClient.AgentId, tx);
491 int full = (int)(PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Copy);
492
493 if ((perms & full) != full)
494 {
495 m_log.ErrorFormat("[ASSET UPLOADER]: REJECTED update with texture {0} from {1} because they do not own the texture", tx, ourClient.AgentId);
496 validated.Add(parts[0] + " " + UUID.Zero.ToString());
497 }
498 else
499 {
500 validated.Add(line);
501 }
502 }
503 textures--;
504 }
505 else
506 {
507 validated.Add(line);
508 }
509 }
510 catch
511 {
512 // If it's malformed, skip it
513 }
514 }
515
516 string final = String.Join("\n", validated.ToArray());
517
518 m_asset.Data = System.Text.Encoding.ASCII.GetBytes(final);
519 }
520 }
521
522 /// <summary>
523 /// Get the asset data uploaded in this transfer.
524 /// </summary>
525 /// <returns>null if the asset has not finished uploading</returns>
526 public AssetBase GetAssetData()
527 {
528 if (m_uploadState == UploadState.Complete)
529 {
530 ValidateAssets();
531 return m_asset;
532 }
533
534 return null;
535 }
536
537 public void SetOldData(byte[] d)
538 {
539 m_oldData = d;
540 }
541
542 private Dictionary<int,UUID> ExtractTexturesFromOldData()
543 {
544 Dictionary<int,UUID> result = new Dictionary<int,UUID>();
545 if (m_oldData == null)
546 return result;
547
548 string content = System.Text.Encoding.ASCII.GetString(m_oldData);
549 string[] lines = content.Split(new char[] {'\n'});
550
551 int textures = 0;
552
553 foreach (string line in lines)
554 {
555 try
556 {
557 if (line.StartsWith("textures "))
558 {
559 textures = Convert.ToInt32(line.Substring(9));
560 }
561 else if (textures > 0)
562 {
563 string[] parts = line.Split(new char[] {' '});
564
565 UUID tx = new UUID(parts[1]);
566 int id = Convert.ToInt32(parts[0]);
567 result[id] = tx;
568 textures--;
569 }
570 }
571 catch
572 {
573 // If it's malformed, skip it
574 }
575 }
576
577 return result;
578 }
425 } 579 }
426} \ No newline at end of file 580}