private LLSDInventoryDescendents ToLLSD(InventoryCollection inv, int descendents)
        {
            LLSDInventoryDescendents    reply    = new LLSDInventoryDescendents();
            LLSDInventoryFolderContents contents = new LLSDInventoryFolderContents();

            contents.agent_id  = inv.OwnerID;
            contents.owner_id  = inv.OwnerID;
            contents.folder_id = inv.FolderID;

            reply.folders.Array.Add(contents);

            if (inv.Folders != null)
            {
                foreach (InventoryFolderBase invFolder in inv.Folders)
                {
                    contents.categories.Array.Add(ConvertInventoryFolder(invFolder));
                }

                descendents += inv.Folders.Count;
            }

            if (inv.Items != null)
            {
                foreach (InventoryItemBase invItem in inv.Items)
                {
                    contents.items.Array.Add(ConvertInventoryItem(invItem));
                }
            }

            contents.descendents = descendents;
            contents.version     = inv.Version;

            return(reply);
        }
        /// <summary>
        /// Construct an LLSD reply packet to a CAPS inventory request
        /// </summary>
        /// <param name="invFetch"></param>
        /// <returns></returns>
        private LLSDInventoryDescendents FetchInventoryReply(LLSDFetchInventoryDescendents invFetch)
        {
            LLSDInventoryDescendents    reply    = new LLSDInventoryDescendents();
            LLSDInventoryFolderContents contents = new LLSDInventoryFolderContents();

            contents.agent_id  = invFetch.owner_id;
            contents.owner_id  = invFetch.owner_id;
            contents.folder_id = invFetch.folder_id;

            reply.folders.Array.Add(contents);
            InventoryCollection inv = new InventoryCollection();

            inv.Folders = new List <InventoryFolderBase>();
            inv.Items   = new List <InventoryItemBase>();
            int version     = 0;
            int descendents = 0;

#pragma warning disable 0612
            inv = Fetch(
                invFetch.owner_id, invFetch.folder_id, invFetch.owner_id,
                invFetch.fetch_folders, invFetch.fetch_items, invFetch.sort_order, out version, out descendents);
#pragma warning restore 0612

            if (inv != null && inv.Folders != null)
            {
                foreach (InventoryFolderBase invFolder in inv.Folders)
                {
                    contents.categories.Array.Add(ConvertInventoryFolder(invFolder));
                }

                descendents += inv.Folders.Count;
            }

            if (inv != null && inv.Items != null)
            {
                foreach (InventoryItemBase invItem in inv.Items)
                {
                    contents.items.Array.Add(ConvertInventoryItem(invItem));
                }
            }

            contents.descendents = descendents;
            contents.version     = version;

            //m_log.DebugFormat(
            //    "[WEB FETCH INV DESC HANDLER]: Replying to request for folder {0} (fetch items {1}, fetch folders {2}) with {3} items and {4} folders for agent {5}",
            //    invFetch.folder_id,
            //    invFetch.fetch_items,
            //    invFetch.fetch_folders,
            //    contents.items.Array.Count,
            //    contents.categories.Array.Count,
            //    invFetch.owner_id);

            return(reply);
        }
예제 #3
0
        public string FetchInventoryDescendentsRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            //m_log.DebugFormat("[XXX]: FetchInventoryDescendentsRequest in {0}, {1}", (m_Scene == null) ? "none" : m_Scene.Name, request);

            Hashtable hash = new Hashtable();

            try
            {
                hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
            }
            catch (LLSD.LLSDParseException e)
            {
                m_log.ErrorFormat("[WEB FETCH INV DESC HANDLER]: Fetch error: {0}{1}" + e.Message, e.StackTrace);
                m_log.Error("Request: " + request);
            }

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

            List <LLSDFetchInventoryDescendents> folders = new List <LLSDFetchInventoryDescendents>();

            for (int i = 0; i < foldersrequested.Count; i++)
            {
                Hashtable inventoryhash = (Hashtable)foldersrequested[i];

                LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents();

                try
                {
                    LLSDHelpers.DeserialiseOSDMap(inventoryhash, llsdRequest);
                }
                catch (Exception e)
                {
                    m_log.Debug("[WEB FETCH INV DESC HANDLER]: caught exception doing OSD deserialize" + e);
                    continue;
                }

                folders.Add(llsdRequest);
            }

            if (folders.Count == 0)
            {
                return("<llsd><map><key>folders</key><array /></map></llsd>");
            }

            List <UUID> bad_folders = new List <UUID>();

            List <InventoryCollectionWithDescendents> invcollSet = Fetch(folders, bad_folders);

            //m_log.DebugFormat("[XXX]: Got {0} folders from a request of {1}", invcollSet.Count, folders.Count);

            if (invcollSet == null)
            {
                m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Multiple folder fetch failed. Trying old protocol.");
#pragma warning disable 0612
                return(FetchInventoryDescendentsRequest(foldersrequested, httpRequest, httpResponse));

#pragma warning restore 0612
            }

            StringBuilder lastresponse = new StringBuilder(1024);
            lastresponse.Append("<llsd>");

            if (invcollSet.Count > 0)
            {
                lastresponse.Append("<map><key>folders</key><array>");
                foreach (InventoryCollectionWithDescendents icoll in invcollSet)
                {
                    LLSDInventoryFolderContents thiscontents = contentsToLLSD(icoll.Collection, icoll.Descendents);
                    lastresponse.Append(LLSDHelpers.SerialiseLLSDReplyNoHeader(thiscontents));
                }
                lastresponse.Append("</array></map>");
            }
            else
            {
                lastresponse.Append("<map><key>folders</key><array /></map>");
            }

            //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Bad folders {0}", string.Join(", ", bad_folders));
            if (bad_folders.Count > 0)
            {
                lastresponse.Append("<map><key>bad_folders</key><array>");
                foreach (UUID bad in bad_folders)
                {
                    lastresponse.Append("<map><key>folder_id</key><uuid>");
                    lastresponse.Append(bad.ToString());
                    lastresponse.Append("</uuid><key>error</key><string>Unknown</string></map>");
                }
                lastresponse.Append("</array></map>");
            }
            lastresponse.Append("</llsd>");

            return(lastresponse.ToString());;
        }
예제 #4
0
        public string FetchInventoryDescendentsRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            //m_log.DebugFormat("[XXX]: FetchInventoryDescendentsRequest in {0}, {1}", (m_Scene == null) ? "none" : m_Scene.Name, request);

            // nasty temporary hack here, the linden client falsely
            // identifies the uuid 00000000-0000-0000-0000-000000000000
            // as a string which breaks us
            //
            // correctly mark it as a uuid
            //
            request = request.Replace("<string>00000000-0000-0000-0000-000000000000</string>", "<uuid>00000000-0000-0000-0000-000000000000</uuid>");

            // another hack <integer>1</integer> results in a
            // System.ArgumentException: Object type System.Int32 cannot
            // be converted to target type: System.Boolean
            //
            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("[WEB FETCH INV DESC HANDLER]: Fetch error: {0}{1}" + e.Message, e.StackTrace);
                m_log.Error("Request: " + request);
            }

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

            StringBuilder tmpresponse   = new StringBuilder(1024);
            StringBuilder tmpbadfolders = new StringBuilder(1024);

            List <LLSDFetchInventoryDescendents> folders = new List <LLSDFetchInventoryDescendents>();

            for (int i = 0; i < foldersrequested.Count; i++)
            {
                Hashtable inventoryhash = (Hashtable)foldersrequested[i];

                LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents();

                try
                {
                    LLSDHelpers.DeserialiseOSDMap(inventoryhash, llsdRequest);
                }
                catch (Exception e)
                {
                    m_log.Debug("[WEB FETCH INV DESC HANDLER]: caught exception doing OSD deserialize" + e);
                    continue;
                }

                folders.Add(llsdRequest);
            }

            if (folders.Count > 0)
            {
                List <UUID> bad_folders = new List <UUID>();
                List <InventoryCollectionWithDescendents> invcollSet = Fetch(folders, bad_folders);
                //m_log.DebugFormat("[XXX]: Got {0} folders from a request of {1}", invcollSet.Count, folders.Count);

                if (invcollSet == null)
                {
                    m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Multiple folder fetch failed. Trying old protocol.");
#pragma warning disable 0612
                    return(FetchInventoryDescendentsRequest(foldersrequested, httpRequest, httpResponse));

#pragma warning restore 0612
                }

                string inventoryitemstr = string.Empty;
                foreach (InventoryCollectionWithDescendents icoll in invcollSet)
                {
                    LLSDInventoryFolderContents thiscontents = contentsToLLSD(icoll.Collection, icoll.Descendents);
                    inventoryitemstr = LLSDHelpers.SerialiseLLSDReply(thiscontents);
//                    inventoryitemstr = inventoryitemstr.Replace("<llsd>", "");
//                    inventoryitemstr = inventoryitemstr.Replace("</llsd>", "");
//                    inventoryitemstr = inventoryitemstr.Substring(6,inventoryitemstr.Length - 13);
//                    tmpresponse.Append(inventoryitemstr);
                    tmpresponse.Append(inventoryitemstr.Substring(6, inventoryitemstr.Length - 13));
                }

                //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Bad folders {0}", string.Join(", ", bad_folders));
                foreach (UUID bad in bad_folders)
                {
                    tmpbadfolders.Append("<map><key>folder_id</key><uuid>");
                    tmpbadfolders.Append(bad.ToString());
                    tmpbadfolders.Append("</uuid><key>error</key><string>Unknown</string></map>");
                }
            }

            StringBuilder lastresponse = new StringBuilder(1024);
            lastresponse.Append("<llsd>");
            if (tmpresponse.Length > 0)
            {
                lastresponse.Append("<map><key>folders</key><array>");
                lastresponse.Append(tmpresponse.ToString());
                lastresponse.Append("</array></map>");
            }
            else
            {
                lastresponse.Append("<map><key>folders</key><array /></map>");
            }

            if (tmpbadfolders.Length > 0)
            {
                lastresponse.Append("<map><key>bad_folders</key><array>");
                lastresponse.Append(tmpbadfolders.ToString());
                lastresponse.Append("</array></map>");
            }
            lastresponse.Append("</llsd>");

            return(lastresponse.ToString());
        }