예제 #1
0
        public FetchInvDescServerConnector(IConfigSource config, IHttpServer server, string configName) :
            base(config, server, configName)
        {
            if (configName != String.Empty)
            {
                m_ConfigName = configName;
            }

            IConfig serverConfig = config.Configs[m_ConfigName];

            if (serverConfig == null)
            {
                throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName));
            }

            string invService = serverConfig.GetString("InventoryService", String.Empty);

            if (invService == String.Empty)
            {
                throw new Exception("No InventoryService in config file");
            }

            Object[] args = new Object[] { config };
            m_InventoryService =
                ServerUtils.LoadPlugin <IInventoryService>(invService, args);

            if (m_InventoryService == null)
            {
                throw new Exception(String.Format("Failed to load InventoryService from {0}; config is {1}", invService, m_ConfigName));
            }

            string libService = serverConfig.GetString("LibraryService", String.Empty);

            m_LibraryService =
                ServerUtils.LoadPlugin <ILibraryService>(libService, args);

            FetchInvDescHandler webFetchHandler = new FetchInvDescHandler(m_InventoryService, m_LibraryService, null);
            IRequestHandler     reqHandler
                = new RestStreamHandler(
                      "POST",
                      "/CAPS/WebFetchInvDesc/" /*+ UUID.Random()*/,
                      webFetchHandler.FetchInventoryDescendentsRequest,
                      "FetchInvDescendents",
                      null);

            server.AddStreamHandler(reqHandler);
        }
예제 #2
0
        public FetchInvDescServerConnector(IConfigSource config, IHttpServer server, string configName) :
            base(config, server, configName)
        {
            if (configName != String.Empty)
            {
                m_ConfigName = configName;
            }

            IConfig serverConfig = config.Configs[m_ConfigName];

            if (serverConfig == null)
            {
                throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName));
            }

            string invService = serverConfig.GetString("InventoryService", String.Empty);

            if (invService == String.Empty)
            {
                throw new Exception("No InventoryService in config file");
            }

            Object[] args = new Object[] { config };
            m_InventoryService =
                ServerUtils.LoadPlugin <IInventoryService>(invService, args);

            if (m_InventoryService == null)
            {
                throw new Exception(String.Format("Failed to load InventoryService from {0}; config is {1}", invService, m_ConfigName));
            }

            string libService = serverConfig.GetString("LibraryService", String.Empty);

            m_LibraryService =
                ServerUtils.LoadPlugin <ILibraryService>(libService, args);

            ExpiringKey <UUID> m_badRequests = new ExpiringKey <UUID>(30000);

            FetchInvDescHandler  webFetchHandler = new FetchInvDescHandler(m_InventoryService, m_LibraryService, null);
            ISimpleStreamHandler reqHandler
                = new SimpleStreamHandler("/CAPS/WebFetchInvDesc/", delegate(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
            {
                webFetchHandler.FetchInventoryDescendentsRequest(httpRequest, httpResponse, m_badRequests);
            });

            server.AddSimpleStreamHandler(reqHandler);
        }
        public FetchInvDescServerConnector(IConfigSource config, IHttpServer server, string configName) :
                base(config, server, configName)
        {
            if (configName != String.Empty)
                m_ConfigName = configName;

            IConfig serverConfig = config.Configs[m_ConfigName];
            if (serverConfig == null)
                throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName));

            string invService = serverConfig.GetString("InventoryService", String.Empty);

            if (invService == String.Empty)
                throw new Exception("No InventoryService in config file");

            Object[] args = new Object[] { config };
            m_InventoryService =
                    ServerUtils.LoadPlugin<IInventoryService>(invService, args);

            if (m_InventoryService == null)
                throw new Exception(String.Format("Failed to load InventoryService from {0}; config is {1}", invService, m_ConfigName));

            string libService = serverConfig.GetString("LibraryService", String.Empty);
            m_LibraryService =
                    ServerUtils.LoadPlugin<ILibraryService>(libService, args);

            FetchInvDescHandler webFetchHandler = new FetchInvDescHandler(m_InventoryService, m_LibraryService);
            IRequestHandler reqHandler
                = new RestStreamHandler(
                    "POST",
                    "/CAPS/WebFetchInvDesc/" /*+ UUID.Random()*/,
                    webFetchHandler.FetchInventoryDescendentsRequest,
                    "FetchInvDescendents",
                    null);
            server.AddStreamHandler(reqHandler);
        }
예제 #4
0
        public void RegionLoaded(Scene s)
        {
            if (!m_Enabled)
                return;

            if (s_processedRequestsStat == null)
                s_processedRequestsStat =
                    new Stat(
                        "ProcessedFetchInventoryRequests",
                        "Number of processed fetch inventory requests",
                        "These have not necessarily yet been dispatched back to the requester.",
                        "",
                        "inventory",
                        "httpfetch",
                        StatType.Pull,
                        MeasuresOfInterest.AverageChangeOverTime,
                        stat => { stat.Value = ProcessedRequestsCount; },
                        StatVerbosity.Debug);

            if (s_queuedRequestsStat == null)
                s_queuedRequestsStat =
                    new Stat(
                        "QueuedFetchInventoryRequests",
                        "Number of fetch inventory requests queued for processing",
                        "",
                        "",
                        "inventory",
                        "httpfetch",
                        StatType.Pull,
                        MeasuresOfInterest.AverageChangeOverTime,
                        stat => { stat.Value = m_queue.Count; },
                        StatVerbosity.Debug);

            StatsManager.RegisterStat(s_processedRequestsStat);
            StatsManager.RegisterStat(s_queuedRequestsStat);

            m_InventoryService = Scene.InventoryService;
            m_LibraryService = Scene.LibraryService;

            // We'll reuse the same handler for all requests.
            m_webFetchHandler = new FetchInvDescHandler(m_InventoryService, m_LibraryService, Scene);

            Scene.EventManager.OnRegisterCaps += RegisterCaps;

            int nworkers = 2; // was 2
            if (ProcessQueuedRequestsAsync && m_workerThreads == null)
            {
                m_workerThreads = new Thread[nworkers];

                for (uint i = 0; i < nworkers; i++)
                {
                    m_workerThreads[i] = WorkManager.StartThread(DoInventoryRequests,
                            String.Format("InventoryWorkerThread{0}", i),
                            ThreadPriority.Normal,
                            false,
                            true,
                            null,
                            int.MaxValue);
                }
            }
        }
        public void Test_005_FolderZero()
        {
            TestHelpers.InMethod();

            Init();

            FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene);
            TestOSHttpRequest req = new TestOSHttpRequest();
            TestOSHttpResponse resp = new TestOSHttpResponse();

            string request = "<llsd><map><key>folders</key><array><map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>";
            request += UUID.Zero;
            request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map></array></map></llsd>";

            string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp);

            Assert.That(llsdresponse != null, Is.True, "Incorrect null response");
            Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response");
            Assert.That(llsdresponse.Contains("bad_folders</key><array><uuid>00000000-0000-0000-0000-000000000000"), Is.True, "Folder Zero should be a bad folder");

            Console.WriteLine(llsdresponse);
        }
        public void Test_004_DuplicateFolders()
        {
            TestHelpers.InMethod();

            FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene);
            TestOSHttpRequest req = new TestOSHttpRequest();
            TestOSHttpResponse resp = new TestOSHttpResponse();

            string request = "<llsd><map><key>folders</key><array>";
            request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>";
            request += m_rootFolderID;
            request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>";
            request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>";
            request += m_notecardsFolder;
            request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>";
            request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>";
            request += m_rootFolderID;
            request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>";
            request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>";
            request += m_notecardsFolder;
            request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>";
            request += "</array></map></llsd>";

            string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp);
            Console.WriteLine(llsdresponse);

            string root_folder = "<key>folder_id</key><uuid>" + m_rootFolderID + "</uuid>";
            string notecards_folder = "<key>folder_id</key><uuid>" + m_notecardsFolder + "</uuid>";

            Assert.That(llsdresponse.Contains(root_folder), "Missing root folder");
            Assert.That(llsdresponse.Contains(notecards_folder), "Missing notecards folder");
            int count = Regex.Matches(llsdresponse, root_folder).Count;
            Assert.AreEqual(1, count, "More than 1 root folder in response");
            count = Regex.Matches(llsdresponse, notecards_folder).Count;
            Assert.AreEqual(2, count, "More than 1 notecards folder in response"); // Notecards will also be under root, so 2
        }
        public void Test_003_Links()
        {
            TestHelpers.InMethod();

            FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene);
            TestOSHttpRequest req = new TestOSHttpRequest();
            TestOSHttpResponse resp = new TestOSHttpResponse();

            string request = "<llsd><map><key>folders</key><array><map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>";
            request += "f0000000-0000-0000-0000-00000000000f";
            request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map></array></map></llsd>";

            string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp);
            Console.WriteLine(llsdresponse);

            string descendents = "descendents</key><integer>2</integer>";
            Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents for Test Folder");

            // Make sure that the note card link is included
            Assert.That(llsdresponse.Contains("Link to notecard"), Is.True, "Link to notecard is missing");
            
            //Make sure the notecard item itself is included
            Assert.That(llsdresponse.Contains("Test Notecard 2"), Is.True, "Notecard 2 item (the source) is missing");

            // Make sure that the source item is before the link item
            int pos1 = llsdresponse.IndexOf("Test Notecard 2");
            int pos2 = llsdresponse.IndexOf("Link to notecard");
            Assert.Less(pos1, pos2, "Source of link is after link");

            // Make sure the folder link is included
            Assert.That(llsdresponse.Contains("Link to Objects folder"), Is.True, "Link to Objects folder is missing");

            // Make sure the objects inside the Objects folder are included
            // Note: I'm not entirely sure this is needed, but that's what I found in the implementation
            Assert.That(llsdresponse.Contains("Some Object"), Is.True, "Some Object item (contents of the source) is missing");

            // Make sure that the source item is before the link item
            pos1 = llsdresponse.IndexOf("Some Object");
            pos2 = llsdresponse.IndexOf("Link to Objects folder");
            Assert.Less(pos1, pos2, "Contents of source of folder link is after folder link");
        }
        public void Test_002_MultipleFolders()
        {
            TestHelpers.InMethod();

            FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene);
            TestOSHttpRequest req = new TestOSHttpRequest();
            TestOSHttpResponse resp = new TestOSHttpResponse();

            string request = "<llsd><map><key>folders</key><array>";
            request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>";
            request += m_rootFolderID;
            request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>";
            request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>";
            request += m_notecardsFolder;
            request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>";
            request += "</array></map></llsd>";

            string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp);
            Console.WriteLine(llsdresponse);

            string descendents = "descendents</key><integer>" + m_rootDescendents + "</integer>";
            Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents for root folder");
            descendents = "descendents</key><integer>2</integer>";
            Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents for Notecard folder");

            Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000001"), Is.True, "Notecard 1 is missing from response");
            Assert.That(llsdresponse.Contains("20000000-0000-0000-0000-000000000002"), Is.True, "Notecard 2 is missing from response");
        }
        public void Test_001_SimpleFolder()
        {
            TestHelpers.InMethod();

            Init();

            FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene);
            TestOSHttpRequest req = new TestOSHttpRequest();
            TestOSHttpResponse resp = new TestOSHttpResponse();

            string request = "<llsd><map><key>folders</key><array><map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>";
            request += m_rootFolderID;
            request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map></array></map></llsd>";
            
            string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp);

            Assert.That(llsdresponse != null, Is.True, "Incorrect null response");
            Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response");
            Assert.That(llsdresponse.Contains("00000000-0000-0000-0000-000000000000"), Is.True, "Response should contain userID");

            string descendents = "descendents</key><integer>" + m_rootDescendents + "</integer>";
            Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents");
            Console.WriteLine(llsdresponse);
        }