public virtual byte[] FetchInventoryReply(OSDArray fetchRequest, UUID agentID, UUID forceOwnerID,
                                                  UUID libraryOwnerID)
        {
            LLSDSerializationDictionary contents = new LLSDSerializationDictionary();
            contents.WriteStartMap("llsd"); //Start llsd

            contents.WriteKey("folders"); //Start array items
            contents.WriteStartArray("folders"); //Start array folders

            foreach (OSD m in fetchRequest)
            {
                contents.WriteStartMap("internalContents"); //Start internalContents kvp
                OSDMap invFetch = (OSDMap) m;

                //UUID agent_id = invFetch["agent_id"].AsUUID();
                UUID owner_id = invFetch["owner_id"].AsUUID();
                UUID folder_id = invFetch["folder_id"].AsUUID();
                bool fetch_folders = invFetch["fetch_folders"].AsBoolean();
                bool fetch_items = invFetch["fetch_items"].AsBoolean();
                //int sort_order = invFetch["sort_order"].AsInteger();

                //Set the normal stuff
                contents["agent_id"] = agentID;
                contents["owner_id"] = owner_id;
                contents["folder_id"] = folder_id;

                int count = 0;
                string query = "";

                if (fetch_items)
                {
                    contents.WriteKey("items"); //Start array items
                    contents.WriteStartArray("items");
                    List<UUID> moreLinkedItems = new List<UUID>();
                    bool addToCount = true;
                    query = String.Format("where {0} = '{1}'", "parentFolderID", folder_id);
                    redoQuery:
                    using (DataReaderConnection retVal = GD.QueryData(query, m_itemsrealm, "*"))
                    {
                        try
                        {
                            while (retVal.DataReader.Read())
                            {
                                contents.WriteStartMap("item"); //Start item kvp
                                UUID assetID = UUID.Parse(retVal.DataReader["assetID"].ToString());
                                contents["asset_id"] = assetID;
                                contents["name"] = retVal.DataReader["inventoryName"].ToString();
                                contents["desc"] = retVal.DataReader["inventoryDescription"].ToString();

                                contents.WriteKey("permissions"); //Start permissions kvp
                                contents.WriteStartMap("permissions");
                                contents["group_id"] = UUID.Parse(retVal.DataReader["groupID"].ToString());
                                contents["is_owner_group"] = int.Parse(retVal.DataReader["groupOwned"].ToString()) == 1;
                                contents["group_mask"] =
                                    uint.Parse(retVal.DataReader["inventoryGroupPermissions"].ToString());
                                contents["owner_id"] = forceOwnerID == UUID.Zero
                                                           ? UUID.Parse(retVal.DataReader["avatarID"].ToString())
                                                           : forceOwnerID;
                                contents["last_owner_id"] = UUID.Parse(retVal.DataReader["avatarID"].ToString());
                                contents["next_owner_mask"] =
                                    uint.Parse(retVal.DataReader["inventoryNextPermissions"].ToString());
                                contents["owner_mask"] =
                                    uint.Parse(retVal.DataReader["inventoryCurrentPermissions"].ToString());
                                UUID creator;
                                if (UUID.TryParse(retVal.DataReader["creatorID"].ToString(), out creator))
                                    contents["creator_id"] = creator;
                                else
                                    contents["creator_id"] = UUID.Zero;
                                contents["base_mask"] =
                                    uint.Parse(retVal.DataReader["inventoryBasePermissions"].ToString());
                                contents["everyone_mask"] =
                                    uint.Parse(retVal.DataReader["inventoryEveryOnePermissions"].ToString());
                                contents.WriteEndMap( /*Permissions*/);

                                contents.WriteKey("sale_info"); //Start permissions kvp
                                contents.WriteStartMap("sale_info"); //Start sale_info kvp
                                contents["sale_price"] = int.Parse(retVal.DataReader["salePrice"].ToString());
                                switch (byte.Parse(retVal.DataReader["saleType"].ToString()))
                                {
                                    default:
                                        contents["sale_type"] = "not";
                                        break;
                                    case 1:
                                        contents["sale_type"] = "original";
                                        break;
                                    case 2:
                                        contents["sale_type"] = "copy";
                                        break;
                                    case 3:
                                        contents["sale_type"] = "contents";
                                        break;
                                }
                                contents.WriteEndMap( /*sale_info*/);

                                contents["created_at"] = int.Parse(retVal.DataReader["creationDate"].ToString());
                                contents["flags"] = uint.Parse(retVal.DataReader["flags"].ToString());
                                UUID inventoryID = UUID.Parse(retVal.DataReader["inventoryID"].ToString());
                                contents["item_id"] = inventoryID;
                                contents["parent_id"] = UUID.Parse(retVal.DataReader["parentFolderID"].ToString());
                                UUID avatarID = forceOwnerID == UUID.Zero
                                                    ? UUID.Parse(retVal.DataReader["avatarID"].ToString())
                                                    : forceOwnerID;
                                contents["agent_id"] = avatarID;

                                AssetType assetType = (AssetType) int.Parse(retVal.DataReader["assetType"].ToString());
                                if (assetType == AssetType.Link)
                                    moreLinkedItems.Add(assetID);
                                if (assetType == AssetType.Unknown)
                                    assetType = AssetType.Link;
                                contents["type"] =
                                    Utils.AssetTypeToString((AssetType) Util.CheckMeshType((sbyte) assetType));
                                InventoryType invType =
                                    (InventoryType) int.Parse(retVal.DataReader["invType"].ToString());
                                contents["inv_type"] = Utils.InventoryTypeToString(invType);

                                if ((int) invType == -1)
                                {
                                    //Asset problem, fix it, it's supposed to be 0
                                    List<InventoryItemBase> itms = GetItems(agentID,
                                                                            new string[2] {"inventoryID", "avatarID"},
                                                                            new string[2]
                                                                                {
                                                                                    inventoryID.ToString(),
                                                                                    avatarID.ToString()
                                                                                });
                                    itms[0].InvType = 0;
                                    StoreItem(itms[0]);
                                }

                                if (addToCount)
                                    count++;
                                contents.WriteEndMap( /*"item"*/); //end array items
                            }
                        }
                        catch
                        {
                        }
                        finally
                        {
                            GD.CloseDatabase(retVal);
                        }
                    }
                    if (moreLinkedItems.Count > 0)
                    {
                        addToCount = false;
                        query = "where (";

                        query = moreLinkedItems.Aggregate(query,
                                                          (current, t) =>
                                                          current + String.Format("{0} = '{1}' or ", "inventoryID", t));

                        query = query.Remove(query.Length - 4, 4);
                        query += ")";
                        moreLinkedItems.Clear();
                        goto redoQuery;
                    }
                    contents.WriteEndArray( /*"items"*/); //end array items
                }
                contents.WriteStartArray("categories"); //We don't send any folders
                int version = 0;
                QueryFilter filter = new QueryFilter();
                filter.andFilters["folderID"] = folder_id;
                List<string> versionRetVal = GD.Query(new[]
                                                          {
                                                              "version",
                                                              "type"
                                                          }, m_foldersrealm, filter, null, null, null);

                if (versionRetVal.Count > 0)
                {
                    version = int.Parse(versionRetVal[0]);

                    if (fetch_folders)
                    {
                        if (int.Parse(versionRetVal[1]) == (int) FolderType.Trash ||
                            int.Parse(versionRetVal[1]) == (int) FolderType.CurrentOutfit ||
                            int.Parse(versionRetVal[1]) == (int) AssetType.LinkFolder)
                        {
                            //If it is the trash folder, we need to send its descendents, because the viewer wants it
                            query = String.Format("where {0} = '{1}' and {2} = '{3}'", "parentFolderID", folder_id,
                                                  "agentID", agentID);
                            using (DataReaderConnection retVal = GD.QueryData(query, m_foldersrealm, "*"))
                            {
                                try
                                {
                                    while (retVal.DataReader.Read())
                                    {
                                        contents.WriteStartMap("folder"); //Start item kvp
                                        contents["folder_id"] = UUID.Parse(retVal.DataReader["folderID"].ToString());
                                        contents["parent_id"] =
                                            UUID.Parse(retVal.DataReader["parentFolderID"].ToString());
                                        contents["name"] = retVal.DataReader["folderName"].ToString();
                                        int type = int.Parse(retVal.DataReader["type"].ToString());
                                        contents["type"] = type;
                                        contents["preferred_type"] = type;

                                        count++;
                                        contents.WriteEndMap( /*"folder"*/); //end array items
                                    }
                                }
                                catch
                                {
                                }
                                finally
                                {
                                    GD.CloseDatabase(retVal);
                                }
                            }
                        }
                    }
                }

                contents.WriteEndArray( /*"categories"*/);
                contents["descendents"] = count;
                contents["version"] = version;

                //Now add it to the folder array
                contents.WriteEndMap(); //end array internalContents
            }

            contents.WriteEndArray(); //end array folders
            contents.WriteEndMap( /*"llsd"*/); //end llsd

            try
            {
                return contents.GetSerializer();
            }
            finally
            {
                contents = null;
            }
        }
Ejemplo n.º 2
0
        public override byte[] FetchInventoryReply(OSDArray fetchRequest, UUID AgentID, UUID forceOwnerID, UUID libraryOwnerID)
        {
            LLSDSerializationDictionary contents = new LLSDSerializationDictionary();

            contents.WriteStartMap("llsd");      //Start llsd

            contents.WriteKey("folders");        //Start array items
            contents.WriteStartArray("folders"); //Start array folders

            foreach (OSD m in fetchRequest)
            {
                contents.WriteStartMap("internalContents"); //Start internalContents kvp
                OSDMap invFetch = (OSDMap)m;

                //UUID agent_id = invFetch["agent_id"].AsUUID();
                UUID owner_id      = invFetch["owner_id"].AsUUID();
                UUID folder_id     = invFetch["folder_id"].AsUUID();
                bool fetch_folders = invFetch["fetch_folders"].AsBoolean();
                bool fetch_items   = invFetch["fetch_items"].AsBoolean();
                int  sort_order    = invFetch["sort_order"].AsInteger();

                //Set the normal stuff
                contents["agent_id"]  = forceOwnerID == UUID.Zero ? owner_id : forceOwnerID;
                contents["owner_id"]  = forceOwnerID == UUID.Zero ? owner_id : forceOwnerID;
                contents["folder_id"] = folder_id;

                contents.WriteKey("items"); //Start array items
                contents.WriteStartArray("items");
                List <UUID> moreLinkedItems = new List <UUID>();
                int         count           = 0;
                bool        addToCount      = true;
                string      invServer       = "";
                bool        isForeign       = GetIsForeign(AgentID, "InventoryServerURI", m_registry, out invServer);
                IDataReader fretVal         = null;
                if (isForeign)
                {
                    fretVal = GetForeignInventory(AgentID, folder_id, invServer);
                }
                string query = String.Format("where {0} = '{1}'", "parentFolderID", folder_id,
                                             "avatarID", AgentID, "avatarID", libraryOwnerID);
redoQuery:
                using (IDataReader retVal = isForeign ? fretVal : GD.QueryData(query, m_itemsrealm, "*"))
                {
                    try
                    {
                        while (retVal.Read())
                        {
                            contents.WriteStartMap("item"); //Start item kvp
                            UUID assetID = UUID.Parse(retVal["assetID"].ToString());
                            contents["asset_id"] = assetID;
                            contents["name"]     = retVal["inventoryName"].ToString();
                            contents["desc"]     = retVal["inventoryDescription"].ToString();


                            contents.WriteKey("permissions"); //Start permissions kvp
                            contents.WriteStartMap("permissions");
                            contents["group_id"]       = UUID.Parse(retVal["groupID"].ToString());
                            contents["is_owner_group"] = int.Parse(retVal["groupOwned"].ToString()) == 1;
                            contents["group_mask"]     = uint.Parse(retVal["inventoryGroupPermissions"].ToString());
                            contents["owner_id"]       = forceOwnerID == UUID.Zero
                                                       ? UUID.Parse(retVal["avatarID"].ToString())
                                                       : forceOwnerID;
                            contents["last_owner_id"]   = UUID.Parse(retVal["avatarID"].ToString());
                            contents["next_owner_mask"] = uint.Parse(retVal["inventoryNextPermissions"].ToString());
                            contents["owner_mask"]      = uint.Parse(retVal["inventoryCurrentPermissions"].ToString());
                            UUID creator;
                            if (UUID.TryParse(retVal["creatorID"].ToString(), out creator))
                            {
                                contents["creator_id"] = creator;
                            }
                            else
                            {
                                contents["creator_id"] = UUID.Zero;
                            }
                            contents["base_mask"]     = uint.Parse(retVal["inventoryBasePermissions"].ToString());
                            contents["everyone_mask"] = uint.Parse(retVal["inventoryEveryOnePermissions"].ToString());
                            contents.WriteEndMap(/*Permissions*/);

                            contents.WriteKey("sale_info");      //Start permissions kvp
                            contents.WriteStartMap("sale_info"); //Start sale_info kvp
                            contents["sale_price"] = int.Parse(retVal["salePrice"].ToString());
                            switch (byte.Parse(retVal["saleType"].ToString()))
                            {
                            default:
                                contents["sale_type"] = "not";
                                break;

                            case 1:
                                contents["sale_type"] = "original";
                                break;

                            case 2:
                                contents["sale_type"] = "copy";
                                break;

                            case 3:
                                contents["sale_type"] = "contents";
                                break;
                            }
                            contents.WriteEndMap(/*sale_info*/);


                            contents["created_at"] = int.Parse(retVal["creationDate"].ToString());
                            contents["flags"]      = uint.Parse(retVal["flags"].ToString());
                            UUID inventoryID = UUID.Parse(retVal["inventoryID"].ToString());
                            contents["item_id"]   = inventoryID;
                            contents["parent_id"] = UUID.Parse(retVal["parentFolderID"].ToString());
                            UUID avatarID = forceOwnerID == UUID.Zero
                                                ? UUID.Parse(retVal["avatarID"].ToString())
                                                : forceOwnerID;
                            contents["agent_id"] = avatarID;

                            AssetType assetType = (AssetType)int.Parse(retVal["assetType"].ToString());
                            if (assetType == AssetType.Link)
                            {
                                moreLinkedItems.Add(assetID);
                            }
                            contents["type"] = Utils.AssetTypeToString(assetType);
                            InventoryType invType = (InventoryType)int.Parse(retVal["invType"].ToString());
                            contents["inv_type"] = Utils.InventoryTypeToString(invType);

                            if (addToCount)
                            {
                                count++;
                            }
                            contents.WriteEndMap(/*"item"*/);  //end array items
                        }
                    }
                    catch
                    {
                    }
                    finally
                    {
                        try
                        {
                            //Slow, and doesn't help, plus they get called by the using statement
                            //if (retVal != null)
                            //{
                            //    retVal.Close ();
                            //    retVal.Dispose ();
                            //}
                        }
                        catch
                        {
                        }
                        GD.CloseDatabase();
                    }
                }
                if (moreLinkedItems.Count > 0)
                {
                    addToCount = false;
                    query      = String.Format("where {0} = '{1}' and (", "avatarID", AgentID);
#if (!ISWIN)
                    foreach (UUID item in moreLinkedItems)
                    {
                        query = query + String.Format("{0} = '{1}' or ", "inventoryID", item);
                    }
#else
                    query = moreLinkedItems.Aggregate(query, (current, t) => current + String.Format("{0} = '{1}' or ", "inventoryID", t));
#endif
                    query  = query.Remove(query.Length - 4, 4);
                    query += ")";
                    if (isForeign)
                    {
                        fretVal = new FakeDataReader();
                        IConfigurationService configService = m_registry.RequestModuleInterface <IConfigurationService>();
                        if (invServer == "" && configService != null)
                        {
                            List <string> urls = configService.FindValueOf("InventoryServerURI");
                            if (urls.Count > 0)
                            {
                                invServer = urls[0];
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        XInventoryServicesConnector xinv = new XInventoryServicesConnector(invServer + "xinventory");
                        foreach (UUID t in moreLinkedItems)
                        {
                            ((FakeDataReader)fretVal).items.Add(xinv.GetItem(new InventoryItemBase(t)));
                        }
                    }
                    moreLinkedItems.Clear();
                    goto redoQuery;
                }
                contents.WriteEndArray(/*"items"*/);    //end array items

                contents.WriteStartArray("categories"); //We don't send any folders
                int         version = 0;
                QueryFilter filter  = new QueryFilter();
                filter.andFilters["folderID"] = folder_id;
                List <string> versionRetVal = GD.Query(new string[2] {
                    "version", "type"
                }, m_foldersrealm, filter, null, null, null);
                List <InventoryFolderBase> foldersToAdd = new List <InventoryFolderBase>();
                if (versionRetVal.Count > 0)
                {
                    version = int.Parse(versionRetVal[0]);
                    if (int.Parse(versionRetVal[1]) == (int)AssetType.TrashFolder ||
                        int.Parse(versionRetVal[1]) == (int)AssetType.CurrentOutfitFolder ||
                        int.Parse(versionRetVal[1]) == (int)AssetType.LinkFolder)
                    {
                        //If it is the trash folder, we need to send its descendents, because the viewer wants it
                        query = String.Format("where {0} = '{1}' and {2} = '{3}'", "parentFolderID", folder_id,
                                              "agentID", AgentID);
                        using (IDataReader retVal = GD.QueryData(query, m_foldersrealm, "*"))
                        {
                            try
                            {
                                while (retVal.Read())
                                {
                                    contents.WriteStartMap("folder"); //Start item kvp
                                    contents["folder_id"] = UUID.Parse(retVal["folderID"].ToString());
                                    contents["parent_id"] = UUID.Parse(retVal["parentFolderID"].ToString());
                                    contents["name"]      = retVal["folderName"].ToString();
                                    int type = int.Parse(retVal["type"].ToString());
                                    contents["type"]           = type;
                                    contents["preferred_type"] = type;

                                    count++;
                                    contents.WriteEndMap(/*"folder"*/);  //end array items
                                }
                            }
                            catch
                            {
                            }
                            finally
                            {
                                try
                                {
                                    //if (retVal != null)
                                    //{
                                    //    retVal.Close ();
                                    //    retVal.Dispose ();
                                    //}
                                }
                                catch
                                {
                                }
                                GD.CloseDatabase();
                            }
                        }
                    }
                }

                contents.WriteEndArray(/*"categories"*/);
                contents["descendents"] = count;
                contents["version"]     = version;

                //Now add it to the folder array
                contents.WriteEndMap(); //end array internalContents
            }

            contents.WriteEndArray();         //end array folders
            contents.WriteEndMap(/*"llsd"*/); //end llsd

            try
            {
                return(contents.GetSerializer());
            }
            finally
            {
                contents = null;
            }
        }
Ejemplo n.º 3
0
        public override byte[] FetchInventoryReply(OSDArray fetchRequest, UUID AgentID, UUID forceOwnerID, UUID libraryOwnerID)
        {
            LLSDSerializationDictionary contents = new LLSDSerializationDictionary();
            contents.WriteStartMap("llsd"); //Start llsd

            contents.WriteKey("folders"); //Start array items
            contents.WriteStartArray("folders"); //Start array folders

            foreach (OSD m in fetchRequest)
            {
                contents.WriteStartMap("internalContents"); //Start internalContents kvp
                OSDMap invFetch = (OSDMap) m;

                //UUID agent_id = invFetch["agent_id"].AsUUID();
                UUID owner_id = invFetch["owner_id"].AsUUID();
                UUID folder_id = invFetch["folder_id"].AsUUID();
                bool fetch_folders = invFetch["fetch_folders"].AsBoolean();
                bool fetch_items = invFetch["fetch_items"].AsBoolean();
                int sort_order = invFetch["sort_order"].AsInteger();

                //Set the normal stuff
                contents["agent_id"] = forceOwnerID == UUID.Zero ? owner_id : forceOwnerID;
                contents["owner_id"] = forceOwnerID == UUID.Zero ? owner_id : forceOwnerID;
                contents["folder_id"] = folder_id;

                contents.WriteKey("items"); //Start array items
                contents.WriteStartArray("items");
                List<UUID> moreLinkedItems = new List<UUID>();
                int count = 0;
                bool addToCount = true;
                string invServer = "";
                bool isForeign = GetIsForeign(AgentID, "InventoryServerURI", m_registry, out invServer);
                IDataReader fretVal = null;
                if (isForeign)
                    fretVal = GetForeignInventory(AgentID, folder_id, invServer);
                string query = String.Format("where {0} = '{1}'", "parentFolderID", folder_id,
                                             "avatarID", AgentID, "avatarID", libraryOwnerID);
                redoQuery:
                using (DataReaderConnection retVal = isForeign ? new DataReaderConnection() { DataReader = fretVal } : GD.QueryData(query, m_itemsrealm, "*"))
                {
                    try
                    {
                        while (retVal.DataReader.Read())
                        {
                            contents.WriteStartMap("item"); //Start item kvp
                            UUID assetID = UUID.Parse(retVal.DataReader["assetID"].ToString());
                            contents["asset_id"] = assetID;
                            contents["name"] = retVal.DataReader["inventoryName"].ToString();
                            contents["desc"] = retVal.DataReader["inventoryDescription"].ToString();


                            contents.WriteKey("permissions"); //Start permissions kvp
                            contents.WriteStartMap("permissions");
                            contents["group_id"] = UUID.Parse(retVal.DataReader["groupID"].ToString());
                            contents["is_owner_group"] = int.Parse(retVal.DataReader["groupOwned"].ToString()) == 1;
                            contents["group_mask"] = uint.Parse(retVal.DataReader["inventoryGroupPermissions"].ToString());
                            contents["owner_id"] = forceOwnerID == UUID.Zero
                                                       ? UUID.Parse(retVal.DataReader["avatarID"].ToString())
                                                       : forceOwnerID;
                            contents["last_owner_id"] = UUID.Parse(retVal.DataReader["avatarID"].ToString());
                            contents["next_owner_mask"] = uint.Parse(retVal.DataReader["inventoryNextPermissions"].ToString());
                            contents["owner_mask"] = uint.Parse(retVal.DataReader["inventoryCurrentPermissions"].ToString());
                            UUID creator;
                            if (UUID.TryParse(retVal.DataReader["creatorID"].ToString(), out creator))
                                contents["creator_id"] = creator;
                            else
                                contents["creator_id"] = UUID.Zero;
                            contents["base_mask"] = uint.Parse(retVal.DataReader["inventoryBasePermissions"].ToString());
                            contents["everyone_mask"] = uint.Parse(retVal.DataReader["inventoryEveryOnePermissions"].ToString());
                            contents.WriteEndMap( /*Permissions*/);

                            contents.WriteKey("sale_info"); //Start permissions kvp
                            contents.WriteStartMap("sale_info"); //Start sale_info kvp
                            contents["sale_price"] = int.Parse(retVal.DataReader["salePrice"].ToString());
                            switch (byte.Parse(retVal.DataReader["saleType"].ToString()))
                            {
                                default:
                                    contents["sale_type"] = "not";
                                    break;
                                case 1:
                                    contents["sale_type"] = "original";
                                    break;
                                case 2:
                                    contents["sale_type"] = "copy";
                                    break;
                                case 3:
                                    contents["sale_type"] = "contents";
                                    break;
                            }
                            contents.WriteEndMap( /*sale_info*/);


                            contents["created_at"] = int.Parse(retVal.DataReader["creationDate"].ToString());
                            contents["flags"] = uint.Parse(retVal.DataReader["flags"].ToString());
                            UUID inventoryID = UUID.Parse(retVal.DataReader["inventoryID"].ToString());
                            contents["item_id"] = inventoryID;
                            contents["parent_id"] = UUID.Parse(retVal.DataReader["parentFolderID"].ToString());
                            UUID avatarID = forceOwnerID == UUID.Zero
                                                ? UUID.Parse(retVal.DataReader["avatarID"].ToString())
                                                : forceOwnerID;
                            contents["agent_id"] = avatarID;

                            AssetType assetType = (AssetType)int.Parse(retVal.DataReader["assetType"].ToString());
                            if (assetType == AssetType.Link)
                                moreLinkedItems.Add(assetID);
                            contents["type"] = Utils.AssetTypeToString(assetType);
                            InventoryType invType = (InventoryType)int.Parse(retVal.DataReader["invType"].ToString());
                            contents["inv_type"] = Utils.InventoryTypeToString(invType);

                            if (addToCount)
                                count++;
                            contents.WriteEndMap( /*"item"*/); //end array items
                        }
                    }
                    catch
                    {
                    }
                    finally
                    {
                        GD.CloseDatabase(retVal);
                    }
                }
                if (moreLinkedItems.Count > 0)
                {
                    addToCount = false;
                    query = String.Format("where {0} = '{1}' and (", "avatarID", AgentID);
#if (!ISWIN)
                    foreach (UUID item in moreLinkedItems)
                        query = query + String.Format("{0} = '{1}' or ", "inventoryID", item);
#else
                    query = moreLinkedItems.Aggregate(query, (current, t) => current + String.Format("{0} = '{1}' or ", "inventoryID", t));
#endif
                    query = query.Remove(query.Length - 4, 4);
                    query += ")";
                    if (isForeign)
                    {
                        fretVal = new FakeDataReader();
                        IConfigurationService configService = m_registry.RequestModuleInterface<IConfigurationService>();
                        if (invServer == "" && configService != null)
                        {
                            List<string> urls = configService.FindValueOf("InventoryServerURI");
                            if (urls.Count > 0)
                                invServer = urls[0];
                            else
                                return null;
                        }
                        XInventoryServicesConnector xinv = new XInventoryServicesConnector(invServer + "xinventory");
                        foreach (UUID t in moreLinkedItems)
                        {
                            ((FakeDataReader) fretVal).items.Add(xinv.GetItem(new InventoryItemBase(t)));
                        }
                    }
                    moreLinkedItems.Clear();
                    goto redoQuery;
                }
                contents.WriteEndArray( /*"items"*/); //end array items

                contents.WriteStartArray("categories"); //We don't send any folders
                int version = 0;
                QueryFilter filter = new QueryFilter();
                filter.andFilters["folderID"] = folder_id;
                List<string> versionRetVal = GD.Query(new string[2] { "version", "type" }, m_foldersrealm, filter, null, null, null);
                List<InventoryFolderBase> foldersToAdd = new List<InventoryFolderBase>();
                if (versionRetVal.Count > 0)
                {
                    version = int.Parse(versionRetVal[0]);
                    if (int.Parse(versionRetVal[1]) == (int) AssetType.TrashFolder ||
                        int.Parse(versionRetVal[1]) == (int) AssetType.CurrentOutfitFolder ||
                        int.Parse(versionRetVal[1]) == (int) AssetType.LinkFolder)
                    {
                        //If it is the trash folder, we need to send its descendents, because the viewer wants it
                        query = String.Format("where {0} = '{1}' and {2} = '{3}'", "parentFolderID", folder_id,
                                              "agentID", AgentID);
                        using (DataReaderConnection retVal = GD.QueryData(query, m_foldersrealm, "*"))
                        {
                            try
                            {
                                while (retVal.DataReader.Read())
                                {
                                    contents.WriteStartMap("folder"); //Start item kvp
                                    contents["folder_id"] = UUID.Parse(retVal.DataReader["folderID"].ToString());
                                    contents["parent_id"] = UUID.Parse(retVal.DataReader["parentFolderID"].ToString());
                                    contents["name"] = retVal.DataReader["folderName"].ToString();
                                    int type = int.Parse(retVal.DataReader["type"].ToString());
                                    contents["type"] = type;
                                    contents["preferred_type"] = type;

                                    count++;
                                    contents.WriteEndMap( /*"folder"*/); //end array items
                                }
                            }
                            catch
                            {
                            }
                            finally
                            {
                                GD.CloseDatabase(retVal);
                            }
                        }
                    }
                }

                contents.WriteEndArray( /*"categories"*/);
                contents["descendents"] = count;
                contents["version"] = version;

                //Now add it to the folder array
                contents.WriteEndMap(); //end array internalContents
            }

            contents.WriteEndArray(); //end array folders
            contents.WriteEndMap( /*"llsd"*/); //end llsd

            try
            {
                return contents.GetSerializer();
            }
            finally
            {
                contents = null;
            }
        }
Ejemplo n.º 4
0
        public virtual byte[] FetchInventoryReply(OSDArray fetchRequest, UUID AgentID, UUID forceOwnerID,
                                                  UUID libraryOwnerID)
        {
            LLSDSerializationDictionary contents = new LLSDSerializationDictionary();

            contents.WriteStartMap("llsd");      //Start llsd

            contents.WriteKey("folders");        //Start array items
            contents.WriteStartArray("folders"); //Start array folders

            foreach (OSD m in fetchRequest)
            {
                contents.WriteStartMap("internalContents"); //Start internalContents kvp
                OSDMap invFetch = (OSDMap)m;

                UUID owner_id      = invFetch["owner_id"].AsUUID();
                UUID folder_id     = invFetch["folder_id"].AsUUID();
                bool fetch_folders = invFetch["fetch_folders"].AsBoolean();
                bool fetch_items   = invFetch["fetch_items"].AsBoolean();

                //Set the normal stuff
                contents["agent_id"]  = AgentID;
                contents["owner_id"]  = owner_id;
                contents["folder_id"] = folder_id;

                int    count = 0;
                string query = "";

                if (fetch_items)
                {
                    contents.WriteKey("items"); //Start array items
                    contents.WriteStartArray("items");
                    List <UUID> moreLinkedItems = new List <UUID>();
                    bool        addToCount      = true;
                    query = String.Format("where {0} = '{1}'", "parentFolderID", folder_id);
redoQuery:
                    using (DataReaderConnection retVal = GD.QueryData(query, m_itemsrealm, "*"))
                    {
                        try
                        {
                            while (retVal.DataReader.Read())
                            {
                                contents.WriteStartMap("item"); //Start item kvp
                                UUID assetID = UUID.Parse(retVal.DataReader["assetID"].ToString());
                                contents["asset_id"] = assetID;
                                contents["name"]     = retVal.DataReader["inventoryName"].ToString();
                                contents["desc"]     = retVal.DataReader["inventoryDescription"].ToString();


                                contents.WriteKey("permissions"); //Start permissions kvp
                                contents.WriteStartMap("permissions");
                                contents["group_id"]       = UUID.Parse(retVal.DataReader["groupID"].ToString());
                                contents["is_owner_group"] = int.Parse(retVal.DataReader["groupOwned"].ToString()) == 1;
                                contents["group_mask"]     =
                                    uint.Parse(retVal.DataReader["inventoryGroupPermissions"].ToString());
                                contents["owner_id"] = forceOwnerID == UUID.Zero
                                                           ? UUID.Parse(retVal.DataReader["avatarID"].ToString())
                                                           : forceOwnerID;
                                contents["last_owner_id"]   = UUID.Parse(retVal.DataReader["avatarID"].ToString());
                                contents["next_owner_mask"] =
                                    uint.Parse(retVal.DataReader["inventoryNextPermissions"].ToString());
                                contents["owner_mask"] =
                                    uint.Parse(retVal.DataReader["inventoryCurrentPermissions"].ToString());
                                UUID creator;
                                if (UUID.TryParse(retVal.DataReader["creatorID"].ToString(), out creator))
                                {
                                    contents["creator_id"] = creator;
                                }
                                else
                                {
                                    contents["creator_id"] = UUID.Zero;
                                }
                                contents["base_mask"] =
                                    uint.Parse(retVal.DataReader["inventoryBasePermissions"].ToString());
                                contents["everyone_mask"] =
                                    uint.Parse(retVal.DataReader["inventoryEveryOnePermissions"].ToString());
                                contents.WriteEndMap(/*Permissions*/);

                                contents.WriteKey("sale_info");      //Start permissions kvp
                                contents.WriteStartMap("sale_info"); //Start sale_info kvp
                                contents["sale_price"] = int.Parse(retVal.DataReader["salePrice"].ToString());
                                switch (byte.Parse(retVal.DataReader["saleType"].ToString()))
                                {
                                default:
                                    contents["sale_type"] = "not";
                                    break;

                                case 1:
                                    contents["sale_type"] = "original";
                                    break;

                                case 2:
                                    contents["sale_type"] = "copy";
                                    break;

                                case 3:
                                    contents["sale_type"] = "contents";
                                    break;
                                }
                                contents.WriteEndMap(/*sale_info*/);


                                contents["created_at"] = int.Parse(retVal.DataReader["creationDate"].ToString());
                                contents["flags"]      = uint.Parse(retVal.DataReader["flags"].ToString());
                                UUID inventoryID = UUID.Parse(retVal.DataReader["inventoryID"].ToString());
                                contents["item_id"]   = inventoryID;
                                contents["parent_id"] = UUID.Parse(retVal.DataReader["parentFolderID"].ToString());
                                UUID avatarID = forceOwnerID == UUID.Zero
                                                    ? UUID.Parse(retVal.DataReader["avatarID"].ToString())
                                                    : forceOwnerID;
                                contents["agent_id"] = avatarID;

                                AssetType assetType = (AssetType)int.Parse(retVal.DataReader["assetType"].ToString());
                                if (assetType == AssetType.Link)
                                {
                                    moreLinkedItems.Add(assetID);
                                }
                                if (assetType == AssetType.Unknown)
                                {
                                    assetType = AssetType.Link;
                                }
                                contents["type"] =
                                    Utils.AssetTypeToString((AssetType)Util.CheckMeshType((sbyte)assetType));
                                InventoryType invType =
                                    (InventoryType)int.Parse(retVal.DataReader["invType"].ToString());
                                contents["inv_type"] = Utils.InventoryTypeToString(invType);

                                if ((int)invType == -1)
                                {
                                    //Asset problem, fix it, it's supposed to be 0
                                    List <InventoryItemBase> itms = GetItems(AgentID,
                                                                             new string[2] {
                                        "inventoryID", "avatarID"
                                    },
                                                                             new string[2]
                                    {
                                        inventoryID.ToString(),
                                        avatarID.ToString()
                                    });
                                    itms[0].InvType = 0;
                                    StoreItem(itms[0]);
                                }

                                if (addToCount)
                                {
                                    count++;
                                }
                                contents.WriteEndMap(/*"item"*/);  //end array items
                            }
                        }
                        catch
                        {
                        }
                        finally
                        {
                            GD.CloseDatabase(retVal);
                        }
                    }
                    if (moreLinkedItems.Count > 0)
                    {
                        addToCount = false;
                        query      = "where (";

                        query = moreLinkedItems.Aggregate(query,
                                                          (current, t) =>
                                                          current + String.Format("{0} = '{1}' or ", "inventoryID", t));

                        query  = query.Remove(query.Length - 4, 4);
                        query += ")";
                        moreLinkedItems.Clear();
                        goto redoQuery;
                    }
                    contents.WriteEndArray();           //end array items
                }
                contents.WriteStartArray("categories"); //We don't send any folders
                int         version = 0;
                QueryFilter filter  = new QueryFilter();
                filter.andFilters["folderID"] = folder_id;
                List <string> versionRetVal = GD.Query(new[]
                {
                    "version",
                    "type"
                }, m_foldersrealm, filter, null, null, null);

                if (versionRetVal.Count > 0)
                {
                    version = int.Parse(versionRetVal[0]);

                    if (fetch_folders)
                    {
                        if (int.Parse(versionRetVal[1]) == (int)AssetType.TrashFolder ||
                            int.Parse(versionRetVal[1]) == (int)AssetType.CurrentOutfitFolder ||
                            int.Parse(versionRetVal[1]) == (int)AssetType.LinkFolder)
                        {
                            //If it is the trash folder, we need to send its descendents, because the viewer wants it
                            query = String.Format("where {0} = '{1}' and {2} = '{3}'", "parentFolderID", folder_id,
                                                  "agentID", AgentID);
                            using (DataReaderConnection retVal = GD.QueryData(query, m_foldersrealm, "*"))
                            {
                                try
                                {
                                    while (retVal.DataReader.Read())
                                    {
                                        contents.WriteStartMap("folder"); //Start item kvp
                                        contents["folder_id"] = UUID.Parse(retVal.DataReader["folderID"].ToString());
                                        contents["parent_id"] =
                                            UUID.Parse(retVal.DataReader["parentFolderID"].ToString());
                                        contents["name"] = retVal.DataReader["folderName"].ToString();
                                        int type = int.Parse(retVal.DataReader["type"].ToString());
                                        contents["type"]           = type;
                                        contents["preferred_type"] = type;

                                        count++;
                                        contents.WriteEndMap(); //end array items
                                    }
                                }
                                catch
                                {
                                }
                                finally
                                {
                                    GD.CloseDatabase(retVal);
                                }
                            }
                        }
                    }
                }

                contents.WriteEndArray();
                contents["descendents"] = count;
                contents["version"]     = version;

                //Now add it to the folder array
                contents.WriteEndMap(); //end array internalContents
            }

            contents.WriteEndArray(); //end array folders
            contents.WriteEndMap();   //end llsd

            try
            {
                return(contents.GetSerializer());
            }
            finally
            {
                contents = null;
            }
        }
Ejemplo n.º 5
0
        public byte[] FetchInventoryReply(OSDArray fetchRequest, UUID AgentID)
        {
            LLSDSerializationDictionary contents = new LLSDSerializationDictionary();

            contents.WriteStartMap("llsd");      //Start llsd

            contents.WriteKey("folders");        //Start array items
            contents.WriteStartArray("folders"); //Start array folders

            foreach (OSD m in fetchRequest)
            {
                contents.WriteStartMap("internalContents"); //Start internalContents kvp
                OSDMap invFetch = (OSDMap)m;

                //UUID agent_id = invFetch["agent_id"].AsUUID();
                UUID owner_id      = invFetch["owner_id"].AsUUID();
                UUID folder_id     = invFetch["folder_id"].AsUUID();
                bool fetch_folders = invFetch["fetch_folders"].AsBoolean();
                bool fetch_items   = invFetch["fetch_items"].AsBoolean();
                int  sort_order    = invFetch["sort_order"].AsInteger();

                //Set the normal stuff
                contents["agent_id"]  = AgentID;
                contents["owner_id"]  = owner_id;
                contents["folder_id"] = folder_id;

                contents.WriteKey("items"); //Start array items
                contents.WriteStartArray("items");
                int    count = 0;
                string query = String.Format("where {0} = '{1}'", "parentFolderID", folder_id);
                using (IDataReader retVal = GD.QueryData(query, m_itemsrealm, "*"))
                {
                    try
                    {
                        while (retVal.Read())
                        {
                            contents.WriteStartMap("item");  //Start item kvp
                            contents["asset_id"] = UUID.Parse(retVal["assetID"].ToString());
                            contents["name"]     = retVal["inventoryName"].ToString();
                            contents["desc"]     = retVal["inventoryDescription"].ToString();


                            contents.WriteKey("permissions");  //Start permissions kvp
                            contents.WriteStartMap("permissions");
                            contents["group_id"]        = UUID.Parse(retVal["groupID"].ToString());
                            contents["is_owner_group"]  = int.Parse(retVal["groupOwned"].ToString()) == 1;
                            contents["group_mask"]      = uint.Parse(retVal["inventoryGroupPermissions"].ToString());
                            contents["owner_id"]        = UUID.Parse(retVal["avatarID"].ToString());
                            contents["last_owner_id"]   = UUID.Parse(retVal["avatarID"].ToString());
                            contents["next_owner_mask"] = uint.Parse(retVal["inventoryNextPermissions"].ToString());
                            contents["owner_mask"]      = uint.Parse(retVal["inventoryCurrentPermissions"].ToString());
                            UUID creator;
                            if (UUID.TryParse(retVal["creatorID"].ToString(), out creator))
                            {
                                contents["creator_id"] = creator;
                            }
                            else
                            {
                                contents["creator_id"] = UUID.Zero;
                            }
                            contents["base_mask"]     = uint.Parse(retVal["inventoryBasePermissions"].ToString());
                            contents["everyone_mask"] = uint.Parse(retVal["inventoryEveryOnePermissions"].ToString());
                            contents.WriteEndMap(/*Permissions*/);

                            contents.WriteKey("sale_info");      //Start permissions kvp
                            contents.WriteStartMap("sale_info"); //Start sale_info kvp
                            contents["sale_price"] = int.Parse(retVal["salePrice"].ToString());
                            switch (byte.Parse(retVal["saleType"].ToString()))
                            {
                            default:
                                contents["sale_type"] = "not";
                                break;

                            case 1:
                                contents["sale_type"] = "original";
                                break;

                            case 2:
                                contents["sale_type"] = "copy";
                                break;

                            case 3:
                                contents["sale_type"] = "contents";
                                break;
                            }
                            contents.WriteEndMap(/*sale_info*/);


                            contents["created_at"] = int.Parse(retVal["creationDate"].ToString());
                            contents["flags"]      = uint.Parse(retVal["flags"].ToString());
                            UUID inventoryID = UUID.Parse(retVal["inventoryID"].ToString());
                            contents["item_id"]   = inventoryID;
                            contents["parent_id"] = UUID.Parse(retVal["parentFolderID"].ToString());
                            contents["agent_id"]  = UUID.Parse(retVal["avatarID"].ToString());

                            contents["type"]     = Utils.AssetTypeToString((AssetType)int.Parse(retVal["assetType"].ToString()));
                            contents["inv_type"] = Utils.InventoryTypeToString((InventoryType)int.Parse(retVal["invType"].ToString()));

                            count++;
                            contents.WriteEndMap(/*"item"*/);  //end array items
                        }
                    }
                    catch
                    {
                    }
                    finally
                    {
                        try
                        {
                            if (retVal != null)
                            {
                                retVal.Close();
                                retVal.Dispose();
                            }
                        }
                        catch { }
                        GD.CloseDatabase();
                    }
                }
                contents.WriteEndArray(/*"items"*/); //end array items

                int           version       = 0;
                List <string> versionRetVal = GD.Query("folderID", folder_id, m_foldersrealm, "version");
                if (versionRetVal.Count > 0)
                {
                    version = int.Parse(versionRetVal[0]);
                }

                contents.WriteStartArray("categories"); //We don't send any folders
                contents.WriteEndArray(/*"categories"*/);
                contents["descendents"] = count;
                contents["version"]     = version;

                //Now add it to the folder array
                contents.WriteEndMap(); //end array internalContents
            }

            contents.WriteEndArray();         //end array folders
            contents.WriteEndMap(/*"llsd"*/); //end llsd

            return(contents.GetSerializer());
        }