Beispiel #1
0
            public PollServiceInventoryEventArgs(WebFetchInvDescModule module, string url, UUID pId) :
                base(null, url, null, null, null, null, pId, int.MaxValue)
            {
                m_module = module;

                HasEvents = (requestID, y) =>
                {
                    lock (responses)
                        return(responses.ContainsKey(requestID));
                };

                Drop = (requestID, y) =>
                {
                    lock (responses)
                    {
                        responses.Remove(requestID);
                        lock (dropedResponses)
                            dropedResponses.Add(requestID);
                    }
                };

                GetEvents = (requestID, y) =>
                {
                    lock (responses)
                    {
                        try
                        {
                            return(responses[requestID]);
                        }
                        finally
                        {
                            responses.Remove(requestID);
                        }
                    }
                };

                Request = (requestID, request) =>
                {
                    APollRequest reqinfo = new APollRequest();
                    reqinfo.thepoll = this;
                    reqinfo.reqID   = requestID;
                    reqinfo.request = request;
                    m_workerpool.Enqueue(reqinfo);
                    return(null);
                };

                NoEvents = (x, y) =>
                {
                    Hashtable response = new Hashtable();
                    response["int_response_code"]   = 500;
                    response["str_response_string"] = "Script timeout";
                    response["content_type"]        = "text/plain";
                    response["keepalive"]           = false;

                    return(response);
                };
            }
Beispiel #2
0
            public PollServiceInventoryEventArgs(WebFetchInvDescModule module, string url, UUID pId) :
                base(null, url, null, null, null, pId, int.MaxValue)
            {
                m_module = module;

                HasEvents = (x, y) => { lock (responses) return(responses.ContainsKey(x)); };
                GetEvents = (x, y) =>
                {
                    lock (responses)
                    {
                        try
                        {
                            return(responses[x]);
                        }
                        finally
                        {
                            responses.Remove(x);
                        }
                    }
                };

                Request = (x, y) =>
                {
                    ScenePresence sp = m_module.Scene.GetScenePresence(Id);

                    aPollRequest reqinfo = new aPollRequest();
                    reqinfo.thepoll  = this;
                    reqinfo.reqID    = x;
                    reqinfo.request  = y;
                    reqinfo.presence = sp;
                    reqinfo.folders  = new List <UUID>();

                    // Decode the request here
                    string request = y["body"].ToString();

                    request = request.Replace("<string>00000000-0000-0000-0000-000000000000</string>", "<uuid>00000000-0000-0000-0000-000000000000</uuid>");

                    request = request.Replace("<key>fetch_folders</key><integer>0</integer>", "<key>fetch_folders</key><boolean>0</boolean>");
                    request = request.Replace("<key>fetch_folders</key><integer>1</integer>", "<key>fetch_folders</key><boolean>1</boolean>");

                    Hashtable hash = new Hashtable();
                    try
                    {
                        hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
                    }
                    catch (LLSD.LLSDParseException e)
                    {
                        m_log.ErrorFormat("[INVENTORY]: Fetch error: {0}{1}" + e.Message, e.StackTrace);
                        m_log.Error("Request: " + request);
                        return;
                    }
                    catch (System.Xml.XmlException)
                    {
                        m_log.ErrorFormat("[INVENTORY]: XML Format error");
                    }

                    ArrayList foldersrequested = (ArrayList)hash["folders"];

                    bool highPriority = false;

                    for (int i = 0; i < foldersrequested.Count; i++)
                    {
                        Hashtable inventoryhash = (Hashtable)foldersrequested[i];
                        string    folder        = inventoryhash["folder_id"].ToString();
                        UUID      folderID;
                        if (UUID.TryParse(folder, out folderID))
                        {
                            if (!reqinfo.folders.Contains(folderID))
                            {
                                if (sp.COF != UUID.Zero && sp.COF == folderID)
                                {
                                    highPriority = true;
                                }
                                reqinfo.folders.Add(folderID);
                            }
                        }
                    }

                    if (highPriority)
                    {
                        m_queue.PriorityEnqueue(reqinfo);
                    }
                    else
                    {
                        m_queue.Enqueue(reqinfo);
                    }
                };

                NoEvents = (x, y) =>
                {
/*
 *                  lock (requests)
 *                  {
 *                      Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString());
 *                      requests.Remove(request);
 *                  }
 */
                    Hashtable response = new Hashtable();

                    response["int_response_code"]   = 500;
                    response["str_response_string"] = "Script timeout";
                    response["content_type"]        = "text/plain";
                    response["keepalive"]           = false;
                    response["reusecontext"]        = false;

                    return(response);
                };
            }
            public PollServiceInventoryEventArgs(WebFetchInvDescModule module, string url, UUID pId) :
                base(null, url, null, null, null, pId, int.MaxValue)
            {
                m_module = module;

                HasEvents = (x, y) => { lock (responses) return responses.ContainsKey(x); };
                GetEvents = (x, y) =>
                {
                    lock (responses)
                    {
                        try
                        {
                            return responses[x];
                        }
                        finally
                        {
                            responses.Remove(x);
                        }
                    }
                };

                Request = (x, y) =>
                {
                    ScenePresence sp = m_module.Scene.GetScenePresence(Id);

                    aPollRequest reqinfo = new aPollRequest();
                    reqinfo.thepoll = this;
                    reqinfo.reqID = x;
                    reqinfo.request = y;
                    reqinfo.presence = sp;
                    reqinfo.folders = new List<UUID>();

                    // Decode the request here
                    string request = y["body"].ToString();

                    request = request.Replace("<string>00000000-0000-0000-0000-000000000000</string>", "<uuid>00000000-0000-0000-0000-000000000000</uuid>");

                    request = request.Replace("<key>fetch_folders</key><integer>0</integer>", "<key>fetch_folders</key><boolean>0</boolean>");
                    request = request.Replace("<key>fetch_folders</key><integer>1</integer>", "<key>fetch_folders</key><boolean>1</boolean>");

                    Hashtable hash = new Hashtable();
                    try
                    {
                        hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
                    }
                    catch (LLSD.LLSDParseException e)
                    {
                        m_log.ErrorFormat("[INVENTORY]: Fetch error: {0}{1}" + e.Message, e.StackTrace);
                        m_log.Error("Request: " + request);
                        return;
                    }
                    catch (System.Xml.XmlException)
                    {
                        m_log.ErrorFormat("[INVENTORY]: XML Format error");
                    }

                    ArrayList foldersrequested = (ArrayList)hash["folders"];

                    bool highPriority = false;

                    for (int i = 0; i < foldersrequested.Count; i++)
                    {
                        Hashtable inventoryhash = (Hashtable)foldersrequested[i];
                        string folder = inventoryhash["folder_id"].ToString();
                        UUID folderID;
                        if (UUID.TryParse(folder, out folderID))
                        {
                            if (!reqinfo.folders.Contains(folderID))
                            {
                                //TODO: Port COF handling from Avination
                                reqinfo.folders.Add(folderID);
                            }
                        }
                    }

                    if (highPriority)
                        m_queue.EnqueueHigh(reqinfo);
                    else
                        m_queue.EnqueueLow(reqinfo);
                };

                NoEvents = (x, y) =>
                {
/*
                    lock (requests)
                    {
                        Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString());
                        requests.Remove(request);
                    }
*/
                    Hashtable response = new Hashtable();

                    response["int_response_code"] = 500;
                    response["str_response_string"] = "Script timeout";
                    response["content_type"] = "text/plain";
                    response["keepalive"] = false;
                    response["reusecontext"] = false;

                    return response;
                };
            }
        public void TestInventoryDescendentsFetch()
        {
            TestHelpers.InMethod();
            TestHelpers.EnableLogging();

            BaseHttpServer httpServer = MainServer.Instance;
            Scene scene = new SceneHelpers().SetupScene();

            CapabilitiesModule capsModule = new CapabilitiesModule();
            WebFetchInvDescModule wfidModule = new WebFetchInvDescModule(false);

            IConfigSource config = new IniConfigSource();
            config.AddConfig("ClientStack.LindenCaps");
            config.Configs["ClientStack.LindenCaps"].Set("Cap_FetchInventoryDescendents2", "localhost");

            SceneHelpers.SetupSceneModules(scene, config, capsModule, wfidModule);

            UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1));

            // We need a user present to have any capabilities set up
            SceneHelpers.AddScenePresence(scene, ua.PrincipalID);

            TestHttpRequest req = new TestHttpRequest();
            OpenSim.Framework.Capabilities.Caps userCaps = capsModule.GetCapsForUser(ua.PrincipalID);
            PollServiceEventArgs pseArgs;
            userCaps.TryGetPollHandler("FetchInventoryDescendents2", out pseArgs);
            req.UriPath = pseArgs.Url;
            req.Uri = new Uri(req.UriPath);

            // Retrieve root folder details directly so that we can request
            InventoryFolderBase folder = scene.InventoryService.GetRootFolder(ua.PrincipalID);

            OSDMap osdFolder = new OSDMap();
            osdFolder["folder_id"] = folder.ID;
            osdFolder["owner_id"] = ua.PrincipalID;
            osdFolder["fetch_folders"] = true;
            osdFolder["fetch_items"] = true;
            osdFolder["sort_order"] = 0;

            OSDArray osdFoldersArray = new OSDArray();
            osdFoldersArray.Add(osdFolder);

            OSDMap osdReqMap = new OSDMap();
            osdReqMap["folders"] = osdFoldersArray;

            req.Body = new MemoryStream(OSDParser.SerializeLLSDXmlBytes(osdReqMap));

            TestHttpClientContext context = new TestHttpClientContext(false);
            MainServer.Instance.OnRequest(context, new RequestEventArgs(req));

            // Drive processing of the queued inventory request synchronously.
            wfidModule.WaitProcessQueuedInventoryRequest();
            MainServer.Instance.PollServiceRequestManager.WaitPerformResponse();

//            System.Threading.Thread.Sleep(10000);

            OSDMap responseOsd = (OSDMap)OSDParser.DeserializeLLSDXml(context.ResponseBody);
            OSDArray foldersOsd = (OSDArray)responseOsd["folders"];
            OSDMap folderOsd = (OSDMap)foldersOsd[0];
           
            // A sanity check that the response has the expected number of descendents for a default inventory
            // TODO: Need a more thorough check.
            Assert.That((int)folderOsd["descendents"], Is.EqualTo(14));
        }