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.cs142
1 files changed, 141 insertions, 1 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
index 8add4bb..f6dd5af 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;
@@ -38,6 +39,13 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
38{ 39{
39 public class AssetXferUploader 40 public class AssetXferUploader
40 { 41 {
42 // Viewer's notion of the default texture
43 private List<UUID> defaultIDs = new List<UUID> {
44 new UUID("5748decc-f629-461c-9a36-a35a221fe21f"),
45 new UUID("7ca39b4c-bd19-4699-aff7-f93fd03d3e7b"),
46 new UUID("6522e74d-1660-4e7f-b601-6f48c1659a77"),
47 new UUID("c228d1cf-4b5d-4ba8-84f4-899a0796aa97")
48 };
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42 50
43 /// <summary> 51 /// <summary>
@@ -85,6 +93,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
85 93
86 private sbyte type = 0; 94 private sbyte type = 0;
87 private byte wearableType = 0; 95 private byte wearableType = 0;
96 private byte[] m_oldData = null;
88 public ulong XferID; 97 public ulong XferID;
89 private Scene m_Scene; 98 private Scene m_Scene;
90 99
@@ -393,6 +402,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
393 402
394 private void CompleteCreateItem(uint callbackID) 403 private void CompleteCreateItem(uint callbackID)
395 { 404 {
405 ValidateAssets();
396 m_Scene.AssetService.Store(m_asset); 406 m_Scene.AssetService.Store(m_asset);
397 407
398 InventoryItemBase item = new InventoryItemBase(); 408 InventoryItemBase item = new InventoryItemBase();
@@ -413,6 +423,9 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
413 item.Flags = (uint) wearableType; 423 item.Flags = (uint) wearableType;
414 item.CreationDate = Util.UnixTimeSinceEpoch(); 424 item.CreationDate = Util.UnixTimeSinceEpoch();
415 425
426 m_log.DebugFormat("[XFER]: Created item {0} with asset {1}",
427 item.ID, item.AssetID);
428
416 if (m_Scene.AddInventoryItem(item)) 429 if (m_Scene.AddInventoryItem(item))
417 ourClient.SendInventoryItemCreateUpdate(item, callbackID); 430 ourClient.SendInventoryItemCreateUpdate(item, callbackID);
418 else 431 else
@@ -420,5 +433,132 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
420 433
421 m_transactions.RemoveXferUploader(m_transactionID); 434 m_transactions.RemoveXferUploader(m_transactionID);
422 } 435 }
436
437 private void ValidateAssets()
438 {
439 if (m_asset.Type == (sbyte)AssetType.Clothing ||
440 m_asset.Type == (sbyte)AssetType.Bodypart)
441 {
442 string content = System.Text.Encoding.ASCII.GetString(m_asset.Data);
443 string[] lines = content.Split(new char[] {'\n'});
444
445 List<string> validated = new List<string>();
446
447 Dictionary<int, UUID> allowed = ExtractTexturesFromOldData();
448
449 int textures = 0;
450
451 foreach (string line in lines)
452 {
453 try
454 {
455 if (line.StartsWith("textures "))
456 {
457 textures = Convert.ToInt32(line.Substring(9));
458 validated.Add(line);
459 }
460 else if (textures > 0)
461 {
462 string[] parts = line.Split(new char[] {' '});
463
464 UUID tx = new UUID(parts[1]);
465 int id = Convert.ToInt32(parts[0]);
466
467 if (defaultIDs.Contains(tx) || tx == UUID.Zero ||
468 (allowed.ContainsKey(id) && allowed[id] == tx))
469 {
470 validated.Add(parts[0] + " " + tx.ToString());
471 }
472 else
473 {
474 int perms = m_Scene.InventoryService.GetAssetPermissions(ourClient.AgentId, tx);
475 int full = (int)(PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Copy);
476
477 if ((perms & full) != full)
478 {
479 m_log.ErrorFormat("[ASSET UPLOADER]: REJECTED update with texture {0} from {1} because they do not own the texture", tx, ourClient.AgentId);
480 validated.Add(parts[0] + " " + UUID.Zero.ToString());
481 }
482 else
483 {
484 validated.Add(line);
485 }
486 }
487 textures--;
488 }
489 else
490 {
491 validated.Add(line);
492 }
493 }
494 catch
495 {
496 // If it's malformed, skip it
497 }
498 }
499
500 string final = String.Join("\n", validated.ToArray());
501
502 m_asset.Data = System.Text.Encoding.ASCII.GetBytes(final);
503 }
504 }
505
506 /// <summary>
507 /// Get the asset data uploaded in this transfer.
508 /// </summary>
509 /// <returns>null if the asset has not finished uploading</returns>
510 public AssetBase GetAssetData()
511 {
512 if (m_uploadState == UploadState.Complete)
513 {
514 ValidateAssets();
515 return m_asset;
516 }
517
518 return null;
519 }
520
521 public void SetOldData(byte[] d)
522 {
523 m_oldData = d;
524 }
525
526 private Dictionary<int,UUID> ExtractTexturesFromOldData()
527 {
528 Dictionary<int,UUID> result = new Dictionary<int,UUID>();
529 if (m_oldData == null)
530 return result;
531
532 string content = System.Text.Encoding.ASCII.GetString(m_oldData);
533 string[] lines = content.Split(new char[] {'\n'});
534
535 int textures = 0;
536
537 foreach (string line in lines)
538 {
539 try
540 {
541 if (line.StartsWith("textures "))
542 {
543 textures = Convert.ToInt32(line.Substring(9));
544 }
545 else if (textures > 0)
546 {
547 string[] parts = line.Split(new char[] {' '});
548
549 UUID tx = new UUID(parts[1]);
550 int id = Convert.ToInt32(parts[0]);
551 result[id] = tx;
552 textures--;
553 }
554 }
555 catch
556 {
557 // If it's malformed, skip it
558 }
559 }
560
561 return result;
562 }
423 } 563 }
424} \ No newline at end of file 564}