diff options
author | Diva Canto | 2010-01-01 21:12:46 -0800 |
---|---|---|
committer | Diva Canto | 2010-01-01 21:12:46 -0800 |
commit | 8a9677a5319793ff630d0761e204ae8961f375aa (patch) | |
tree | 0b92d2c9258383df59866945ebad7ba8479563d0 /OpenSim/Services/InventoryService | |
parent | Forgotten modules in prior commit. (diff) | |
download | opensim-SC-8a9677a5319793ff630d0761e204ae8961f375aa.zip opensim-SC-8a9677a5319793ff630d0761e204ae8961f375aa.tar.gz opensim-SC-8a9677a5319793ff630d0761e204ae8961f375aa.tar.bz2 opensim-SC-8a9677a5319793ff630d0761e204ae8961f375aa.tar.xz |
The Library Service is now working. UserProfileCacheService.LibraryRoot is obsolete. Didn't delete it yet to avoid merge conflicts later -- want to stay out of core as much as possible.
Diffstat (limited to 'OpenSim/Services/InventoryService')
-rw-r--r-- | OpenSim/Services/InventoryService/LibraryService.cs | 283 |
1 files changed, 283 insertions, 0 deletions
diff --git a/OpenSim/Services/InventoryService/LibraryService.cs b/OpenSim/Services/InventoryService/LibraryService.cs new file mode 100644 index 0000000..383f311 --- /dev/null +++ b/OpenSim/Services/InventoryService/LibraryService.cs | |||
@@ -0,0 +1,283 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Xml; | ||
33 | |||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Services.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | |||
38 | using log4net; | ||
39 | using Nini.Config; | ||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace OpenSim.Services.InventoryService | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// Basically a hack to give us a Inventory library while we don't have a inventory server | ||
46 | /// once the server is fully implemented then should read the data from that | ||
47 | /// </summary> | ||
48 | public class LibraryService : ServiceBase, ILibraryService | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private InventoryFolderImpl m_LibraryRootFolder; | ||
53 | |||
54 | public InventoryFolderImpl LibraryRootFolder | ||
55 | { | ||
56 | get { return m_LibraryRootFolder; } | ||
57 | } | ||
58 | |||
59 | private UUID libOwner = new UUID("11111111-1111-0000-0000-000100bba000"); | ||
60 | |||
61 | /// <summary> | ||
62 | /// Holds the root library folder and all its descendents. This is really only used during inventory | ||
63 | /// setup so that we don't have to repeatedly search the tree of library folders. | ||
64 | /// </summary> | ||
65 | protected Dictionary<UUID, InventoryFolderImpl> libraryFolders | ||
66 | = new Dictionary<UUID, InventoryFolderImpl>(); | ||
67 | |||
68 | public LibraryService(IConfigSource config) | ||
69 | : base(config) | ||
70 | { | ||
71 | string pLibrariesLocation = Path.Combine("inventory", "Libraries.xml"); | ||
72 | string pLibName = "OpenSim Library"; | ||
73 | |||
74 | IConfig libConfig = config.Configs["LibraryService"]; | ||
75 | if (libConfig != null) | ||
76 | { | ||
77 | pLibrariesLocation = libConfig.GetString("DefaultLibrary", pLibrariesLocation); | ||
78 | pLibName = libConfig.GetString("LibraryName", pLibName); | ||
79 | } | ||
80 | |||
81 | m_log.Debug("[LIBRARY]: Starting library service..."); | ||
82 | |||
83 | m_LibraryRootFolder = new InventoryFolderImpl(); | ||
84 | m_LibraryRootFolder.Owner = libOwner; | ||
85 | m_LibraryRootFolder.ID = new UUID("00000112-000f-0000-0000-000100bba000"); | ||
86 | m_LibraryRootFolder.Name = pLibName; | ||
87 | m_LibraryRootFolder.ParentID = UUID.Zero; | ||
88 | m_LibraryRootFolder.Type = (short)8; | ||
89 | m_LibraryRootFolder.Version = (ushort)1; | ||
90 | |||
91 | libraryFolders.Add(m_LibraryRootFolder.ID, m_LibraryRootFolder); | ||
92 | |||
93 | LoadLibraries(pLibrariesLocation); | ||
94 | } | ||
95 | |||
96 | public InventoryItemBase CreateItem(UUID inventoryID, UUID assetID, string name, string description, | ||
97 | int assetType, int invType, UUID parentFolderID) | ||
98 | { | ||
99 | InventoryItemBase item = new InventoryItemBase(); | ||
100 | item.Owner = libOwner; | ||
101 | item.CreatorId = libOwner.ToString(); | ||
102 | item.ID = inventoryID; | ||
103 | item.AssetID = assetID; | ||
104 | item.Description = description; | ||
105 | item.Name = name; | ||
106 | item.AssetType = assetType; | ||
107 | item.InvType = invType; | ||
108 | item.Folder = parentFolderID; | ||
109 | item.BasePermissions = 0x7FFFFFFF; | ||
110 | item.EveryOnePermissions = 0x7FFFFFFF; | ||
111 | item.CurrentPermissions = 0x7FFFFFFF; | ||
112 | item.NextPermissions = 0x7FFFFFFF; | ||
113 | return item; | ||
114 | } | ||
115 | |||
116 | /// <summary> | ||
117 | /// Use the asset set information at path to load assets | ||
118 | /// </summary> | ||
119 | /// <param name="path"></param> | ||
120 | /// <param name="assets"></param> | ||
121 | protected void LoadLibraries(string librariesControlPath) | ||
122 | { | ||
123 | m_log.InfoFormat("[LIBRARY INVENTORY]: Loading library control file {0}", librariesControlPath); | ||
124 | LoadFromFile(librariesControlPath, "Libraries control", ReadLibraryFromConfig); | ||
125 | } | ||
126 | |||
127 | /// <summary> | ||
128 | /// Read a library set from config | ||
129 | /// </summary> | ||
130 | /// <param name="config"></param> | ||
131 | protected void ReadLibraryFromConfig(IConfig config, string path) | ||
132 | { | ||
133 | string basePath = Path.GetDirectoryName(path); | ||
134 | string foldersPath | ||
135 | = Path.Combine( | ||
136 | basePath, config.GetString("foldersFile", String.Empty)); | ||
137 | |||
138 | LoadFromFile(foldersPath, "Library folders", ReadFolderFromConfig); | ||
139 | |||
140 | string itemsPath | ||
141 | = Path.Combine( | ||
142 | basePath, config.GetString("itemsFile", String.Empty)); | ||
143 | |||
144 | LoadFromFile(itemsPath, "Library items", ReadItemFromConfig); | ||
145 | } | ||
146 | |||
147 | /// <summary> | ||
148 | /// Read a library inventory folder from a loaded configuration | ||
149 | /// </summary> | ||
150 | /// <param name="source"></param> | ||
151 | private void ReadFolderFromConfig(IConfig config, string path) | ||
152 | { | ||
153 | InventoryFolderImpl folderInfo = new InventoryFolderImpl(); | ||
154 | |||
155 | folderInfo.ID = new UUID(config.GetString("folderID", m_LibraryRootFolder.ID.ToString())); | ||
156 | folderInfo.Name = config.GetString("name", "unknown"); | ||
157 | folderInfo.ParentID = new UUID(config.GetString("parentFolderID", m_LibraryRootFolder.ID.ToString())); | ||
158 | folderInfo.Type = (short)config.GetInt("type", 8); | ||
159 | |||
160 | folderInfo.Owner = libOwner; | ||
161 | folderInfo.Version = 1; | ||
162 | |||
163 | if (libraryFolders.ContainsKey(folderInfo.ParentID)) | ||
164 | { | ||
165 | InventoryFolderImpl parentFolder = libraryFolders[folderInfo.ParentID]; | ||
166 | |||
167 | libraryFolders.Add(folderInfo.ID, folderInfo); | ||
168 | parentFolder.AddChildFolder(folderInfo); | ||
169 | |||
170 | // m_log.InfoFormat("[LIBRARY INVENTORY]: Adding folder {0} ({1})", folderInfo.name, folderInfo.folderID); | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | m_log.WarnFormat( | ||
175 | "[LIBRARY INVENTORY]: Couldn't add folder {0} ({1}) since parent folder with ID {2} does not exist!", | ||
176 | folderInfo.Name, folderInfo.ID, folderInfo.ParentID); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | /// <summary> | ||
181 | /// Read a library inventory item metadata from a loaded configuration | ||
182 | /// </summary> | ||
183 | /// <param name="source"></param> | ||
184 | private void ReadItemFromConfig(IConfig config, string path) | ||
185 | { | ||
186 | InventoryItemBase item = new InventoryItemBase(); | ||
187 | item.Owner = libOwner; | ||
188 | item.CreatorId = libOwner.ToString(); | ||
189 | item.ID = new UUID(config.GetString("inventoryID", m_LibraryRootFolder.ID.ToString())); | ||
190 | item.AssetID = new UUID(config.GetString("assetID", item.ID.ToString())); | ||
191 | item.Folder = new UUID(config.GetString("folderID", m_LibraryRootFolder.ID.ToString())); | ||
192 | item.Name = config.GetString("name", String.Empty); | ||
193 | item.Description = config.GetString("description", item.Name); | ||
194 | item.InvType = config.GetInt("inventoryType", 0); | ||
195 | item.AssetType = config.GetInt("assetType", item.InvType); | ||
196 | item.CurrentPermissions = (uint)config.GetLong("currentPermissions", 0x7FFFFFFF); | ||
197 | item.NextPermissions = (uint)config.GetLong("nextPermissions", 0x7FFFFFFF); | ||
198 | item.EveryOnePermissions = (uint)config.GetLong("everyonePermissions", 0x7FFFFFFF); | ||
199 | item.BasePermissions = (uint)config.GetLong("basePermissions", 0x7FFFFFFF); | ||
200 | item.Flags = (uint)config.GetInt("flags", 0); | ||
201 | |||
202 | if (libraryFolders.ContainsKey(item.Folder)) | ||
203 | { | ||
204 | InventoryFolderImpl parentFolder = libraryFolders[item.Folder]; | ||
205 | try | ||
206 | { | ||
207 | parentFolder.Items.Add(item.ID, item); | ||
208 | } | ||
209 | catch (Exception) | ||
210 | { | ||
211 | m_log.WarnFormat("[LIBRARY INVENTORY] Item {1} [{0}] not added, duplicate item", item.ID, item.Name); | ||
212 | } | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | m_log.WarnFormat( | ||
217 | "[LIBRARY INVENTORY]: Couldn't add item {0} ({1}) since parent folder with ID {2} does not exist!", | ||
218 | item.Name, item.ID, item.Folder); | ||
219 | } | ||
220 | } | ||
221 | |||
222 | private delegate void ConfigAction(IConfig config, string path); | ||
223 | |||
224 | /// <summary> | ||
225 | /// Load the given configuration at a path and perform an action on each Config contained within it | ||
226 | /// </summary> | ||
227 | /// <param name="path"></param> | ||
228 | /// <param name="fileDescription"></param> | ||
229 | /// <param name="action"></param> | ||
230 | private static void LoadFromFile(string path, string fileDescription, ConfigAction action) | ||
231 | { | ||
232 | if (File.Exists(path)) | ||
233 | { | ||
234 | try | ||
235 | { | ||
236 | XmlConfigSource source = new XmlConfigSource(path); | ||
237 | |||
238 | for (int i = 0; i < source.Configs.Count; i++) | ||
239 | { | ||
240 | action(source.Configs[i], path); | ||
241 | } | ||
242 | } | ||
243 | catch (XmlException e) | ||
244 | { | ||
245 | m_log.ErrorFormat("[LIBRARY INVENTORY]: Error loading {0} : {1}", path, e); | ||
246 | } | ||
247 | } | ||
248 | else | ||
249 | { | ||
250 | m_log.ErrorFormat("[LIBRARY INVENTORY]: {0} file {1} does not exist!", fileDescription, path); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | /// <summary> | ||
255 | /// Looks like a simple getter, but is written like this for some consistency with the other Request | ||
256 | /// methods in the superclass | ||
257 | /// </summary> | ||
258 | /// <returns></returns> | ||
259 | public Dictionary<UUID, InventoryFolderImpl> GetAllFolders() | ||
260 | { | ||
261 | Dictionary<UUID, InventoryFolderImpl> fs = new Dictionary<UUID, InventoryFolderImpl>(); | ||
262 | fs.Add(m_LibraryRootFolder.ID, m_LibraryRootFolder); | ||
263 | List<InventoryFolderImpl> fis = TraverseFolder(m_LibraryRootFolder); | ||
264 | foreach (InventoryFolderImpl f in fis) | ||
265 | { | ||
266 | fs.Add(f.ID, f); | ||
267 | } | ||
268 | //return libraryFolders; | ||
269 | return fs; | ||
270 | } | ||
271 | |||
272 | private List<InventoryFolderImpl> TraverseFolder(InventoryFolderImpl node) | ||
273 | { | ||
274 | List<InventoryFolderImpl> folders = node.RequestListOfFolderImpls(); | ||
275 | List<InventoryFolderImpl> subs = new List<InventoryFolderImpl>(); | ||
276 | foreach (InventoryFolderImpl f in folders) | ||
277 | subs.AddRange(TraverseFolder(f)); | ||
278 | |||
279 | folders.AddRange(subs); | ||
280 | return folders; | ||
281 | } | ||
282 | } | ||
283 | } | ||