Esempio n. 1
0
        private string Store(AssetBase asset, bool force)
        {
            int    tickCount = Environment.TickCount;
            string hash      = GetSHA256Hash(asset.Data);

            if (!AssetExists(hash))
            {
                string tempFile  = Path.Combine(Path.Combine(m_SpoolDirectory, "spool"), hash + ".asset");
                string finalFile = Path.Combine(m_SpoolDirectory, hash + ".asset");

                if (!File.Exists(finalFile))
                {
                    // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
                    // Fix bad assets before storing on this server
                    if (asset.Type == (int)AssetType.Object && asset.Data != null)
                    {
                        string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
                        asset.Data = Utils.StringToBytes(xml);
                    }

                    FileStream fs = File.Create(tempFile);

                    fs.Write(asset.Data, 0, asset.Data.Length);

                    fs.Close();

                    File.Move(tempFile, finalFile);
                }
            }

            if (asset.ID == string.Empty)
            {
                if (asset.FullID == UUID.Zero)
                {
                    asset.FullID = UUID.Random();
                }
                asset.ID = asset.FullID.ToString();
            }
            else if (asset.FullID == UUID.Zero)
            {
                UUID uuid = UUID.Zero;
                if (UUID.TryParse(asset.ID, out uuid))
                {
                    asset.FullID = uuid;
                }
                else
                {
                    asset.FullID = UUID.Random();
                }
            }

            if (!m_DataConnector.Store(asset.Metadata, hash))
            {
                return(UUID.Zero.ToString());
            }
            else
            {
                return(asset.ID);
            }
        }
Esempio n. 2
0
 protected AssetBase PostProcess(AssetBase asset)
 {
     if (asset.Type == (sbyte)AssetType.Object && asset.Data != null && m_options.ContainsKey("home"))
     {
         //m_log.DebugFormat("[ARCHIVER]: Rewriting object data for {0}", asset.ID);
         string xml = ExternalRepresentationUtils.RewriteSOP(Utils.BytesToString(asset.Data), m_options["home"].ToString(), m_userAccountService, m_scopeID);
         asset.Data = Utils.StringToBytes(xml);
     }
     return(asset);
 }
Esempio n. 3
0
        // Only for Object
        protected byte[] AdjustIdentifiers(byte[] data)
        {
            string xml = Utils.BytesToString(data);

            // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
            // Fix bad assets before sending them elsewhere
            xml = ExternalRepresentationUtils.SanitizeXml(xml);

            return(Utils.StringToBytes(ExternalRepresentationUtils.RewriteSOP(xml, "HGAssetService", m_HomeURL, m_Cache, UUID.Zero)));
        }
        public void TestNamespaceAttribute()
        {
            TestHelpers.InMethod();

            Scene       scene   = new SceneHelpers().SetupScene();
            UserAccount account = new UserAccount(UUID.Zero, UUID.Random(), "Test", "User", string.Empty);

            scene.UserAccountService.StoreUserAccount(account);
            int partsToTestCount = 1;

            SceneObjectGroup so
                = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10);

            SceneObjectPart[] parts = so.Parts;
            so.Name               = "obj1";
            so.Description        = "xpto";
            so.OwnerID            = account.PrincipalID;
            so.RootPart.CreatorID = so.OwnerID;

            string xml = SceneObjectSerializer.ToXml2Format(so);

            Assert.That(!string.IsNullOrEmpty(xml), "SOG serialization resulted in empty or null string");

            xml = ExternalRepresentationUtils.RewriteSOP(xml, "Test Scene", "http://localhost", scene.UserAccountService, UUID.Zero);
            //Console.WriteLine(xml);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            XmlNodeList nodes = doc.GetElementsByTagName("SceneObjectPart");

            Assert.That(nodes.Count, Is.GreaterThan(0), "SOG serialization resulted in no SOPs");
            foreach (XmlAttribute a in nodes[0].Attributes)
            {
                int count = a.Name.Count(c => c == ':');
                Assert.That(count, Is.EqualTo(1), "Cannot have multiple ':' in attribute name in SOP");
            }
            nodes = doc.GetElementsByTagName("CreatorData");
            Assert.That(nodes.Count, Is.GreaterThan(0), "SOG serialization resulted in no CreatorData");
            foreach (XmlAttribute a in nodes[0].Attributes)
            {
                int count = a.Name.Count(c => c == ':');
                Assert.That(count, Is.EqualTo(1), "Cannot have multiple ':' in attribute name in CreatorData");
            }

            SceneObjectGroup so2 = SceneObjectSerializer.FromXml2Format(xml);

            Assert.IsNotNull(so2, "SOG deserialization resulted in null object");
            Assert.AreNotEqual(so.RootPart.CreatorIdentification, so2.RootPart.CreatorIdentification, "RewriteSOP failed to transform CreatorData.");
            Assert.That(so2.RootPart.CreatorIdentification.Contains("http://"), "RewriteSOP failed to add the homeURL to CreatorData");
        }
        //public virtual bool Get(string id, Object sender, AssetRetrieved handler)

        public string Store(AssetBase asset)
        {
            if (!m_AssetPerms.AllowedImport(asset.Type))
                return string.Empty;

            // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
            // Fix bad assets before storing on this server
            if (asset.Type == (int)AssetType.Object && asset.Data != null)
            {
                string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
                asset.Data = Utils.StringToBytes(xml);
            }

            return m_assetService.Store(asset);
        }
        public byte[] GetData(string id)
        {
            AssetBase asset = Get(id);

            if (asset == null)
                return null;

            if (!m_AssetPerms.AllowedExport(asset.Type))
                return null;

            // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
            // Fix bad assets before sending them elsewhere
            if (asset.Type == (int)AssetType.Object && asset.Data != null)
            {
                string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
                asset.Data = Utils.StringToBytes(xml);
            }

            return asset.Data;
        }
Esempio n. 7
0
        private AssetBase Get(string id, out string sha)
        {
            string hash = string.Empty;

            int           startTime = System.Environment.TickCount;
            AssetMetadata metadata;

            lock (m_readLock)
            {
                metadata = m_DataConnector.Get(id, out hash);
            }

            sha = hash;

            if (metadata == null)
            {
                AssetBase asset = null;
                if (m_FallbackService != null)
                {
                    asset = m_FallbackService.Get(id);
                    if (asset != null)
                    {
                        asset.Metadata.ContentType =
                            SLUtil.SLAssetTypeToContentType((int)asset.Type);
                        sha = GetSHA256Hash(asset.Data);
                        m_log.InfoFormat("[FSASSETS]: Added asset {0} from fallback to local store", id);
                        Store(asset);
                    }
                }
                if (asset == null)
                {
                    // m_log.InfoFormat("[FSASSETS]: Asset {0} not found", id);
                    m_missingAssets++;
                }
                return(asset);
            }
            AssetBase newAsset = new AssetBase();

            newAsset.Metadata = metadata;
            try
            {
                newAsset.Data = GetFsData(hash);
                if (newAsset.Data.Length == 0)
                {
                    AssetBase asset = null;
                    if (m_FallbackService != null)
                    {
                        asset = m_FallbackService.Get(id);
                        if (asset != null)
                        {
                            asset.Metadata.ContentType =
                                SLUtil.SLAssetTypeToContentType((int)asset.Type);
                            sha = GetSHA256Hash(asset.Data);
                            m_log.InfoFormat("[FSASSETS]: Added asset {0} from fallback to local store", id);
                            Store(asset);
                        }
                    }
                    if (asset == null)
                    {
                        m_missingAssetsFS++;
                    }
                    // m_log.InfoFormat("[FSASSETS]: Asset {0}, hash {1} not found in FS", id, hash);
                    else
                    {
                        // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
                        // Fix bad assets before sending them elsewhere
                        if (asset.Type == (int)AssetType.Object && asset.Data != null)
                        {
                            string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
                            asset.Data = Utils.StringToBytes(xml);
                        }
                        return(asset);
                    }
                }

                lock (m_statsLock)
                {
                    m_readTicks += Environment.TickCount - startTime;
                    m_readCount++;
                }

                // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
                // Fix bad assets before sending them elsewhere
                if (newAsset.Type == (int)AssetType.Object && newAsset.Data != null)
                {
                    string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(newAsset.Data));
                    newAsset.Data = Utils.StringToBytes(xml);
                }

                return(newAsset);
            }
            catch (Exception exception)
            {
                m_log.Error(exception.ToString());
                Thread.Sleep(5000);
                Environment.Exit(1);
                return(null);
            }
        }
Esempio n. 8
0
        protected byte[] AdjustIdentifiers(byte[] data)
        {
            string xml = Utils.BytesToString(data);

            return(Utils.StringToBytes(ExternalRepresentationUtils.RewriteSOP(xml, m_ProfileServiceURL, m_Cache, UUID.Zero)));
        }
Esempio n. 9
0
        protected string RewriteSOP(string xmlData)
        {
//            Console.WriteLine("Input XML [{0}]", xmlData);
            return(ExternalRepresentationUtils.RewriteSOP(xmlData, m_scene.Name, m_HomeURI, m_scene.UserAccountService, m_scene.RegionInfo.ScopeID));
        }
Esempio n. 10
0
        private string Store(AssetBase asset, bool force)
        {
            int    tickCount = Environment.TickCount;
            string hash      = GetSHA256Hash(asset.Data);

            if (asset.Name.Length > AssetBase.MAX_ASSET_NAME)
            {
                string assetName = asset.Name.Substring(0, AssetBase.MAX_ASSET_NAME);
                m_log.WarnFormat(
                    "[FSASSETS]: Name '{0}' for asset {1} truncated from {2} to {3} characters on add",
                    asset.Name, asset.ID, asset.Name.Length, assetName.Length);
                asset.Name = assetName;
            }

            if (asset.Description.Length > AssetBase.MAX_ASSET_DESC)
            {
                string assetDescription = asset.Description.Substring(0, AssetBase.MAX_ASSET_DESC);
                m_log.WarnFormat(
                    "[FSASSETS]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add",
                    asset.Description, asset.ID, asset.Description.Length, assetDescription.Length);
                asset.Description = assetDescription;
            }

            if (!AssetExists(hash))
            {
                string tempFile  = Path.Combine(Path.Combine(m_SpoolDirectory, "spool"), hash + ".asset");
                string finalFile = Path.Combine(m_SpoolDirectory, hash + ".asset");

                if (!File.Exists(finalFile))
                {
                    // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
                    // Fix bad assets before storing on this server
                    if (asset.Type == (int)AssetType.Object && asset.Data != null)
                    {
                        string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
                        asset.Data = Utils.StringToBytes(xml);
                    }

                    FileStream fs = File.Create(tempFile);

                    fs.Write(asset.Data, 0, asset.Data.Length);

                    fs.Close();

                    File.Move(tempFile, finalFile);
                }
            }

            if (asset.ID == string.Empty)
            {
                if (asset.FullID == UUID.Zero)
                {
                    asset.FullID = UUID.Random();
                }
                asset.ID = asset.FullID.ToString();
            }
            else if (asset.FullID == UUID.Zero)
            {
                UUID uuid = UUID.Zero;
                if (UUID.TryParse(asset.ID, out uuid))
                {
                    asset.FullID = uuid;
                }
                else
                {
                    asset.FullID = UUID.Random();
                }
            }

            if (!m_DataConnector.Store(asset.Metadata, hash))
            {
                if (asset.Metadata.Type == -2)
                {
                    return(asset.ID);
                }

                return(UUID.Zero.ToString());
            }
            else
            {
                return(asset.ID);
            }
        }