29 using System.Collections;
30 using System.Collections.Generic;
32 using System.Reflection;
36 using OpenSim.Server.Base;
37 using OpenSim.Services.Interfaces;
38 using OpenSim.Framework;
39 using OpenSim.Framework.Servers.HttpServer;
40 using OpenSim.Server.Handlers.Base;
43 namespace OpenSim.Server.Handlers.Inventory
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 private bool m_doLookup =
false;
56 private string m_userserver_url;
57 protected string m_ConfigName =
"InventoryService";
60 base(config, server, configName)
62 if (configName !=
string.Empty)
63 m_ConfigName = configName;
65 IConfig serverConfig = config.Configs[m_ConfigName];
66 if (serverConfig == null)
67 throw new Exception(String.Format(
"No section '{0}' in config file", m_ConfigName));
69 string inventoryService = serverConfig.GetString(
"LocalServiceModule",
72 if (inventoryService == String.Empty)
73 throw new Exception(
"No LocalServiceModule in config file");
75 Object[] args =
new Object[] { config };
79 m_userserver_url = serverConfig.GetString(
"UserServerURI", String.Empty);
80 m_doLookup = serverConfig.GetBoolean(
"SessionAuthentication",
false);
82 AddHttpHandlers(server);
83 m_log.Debug(
"[INVENTORY HANDLER]: handlers initialized");
88 m_httpServer.AddStreamHandler(
89 new RestDeserialiseSecureHandler<Guid, List<InventoryFolderBase>>(
90 "POST",
"/SystemFolders/", GetSystemFolders, CheckAuthSession));
92 m_httpServer.AddStreamHandler(
93 new RestDeserialiseSecureHandler<Guid, InventoryCollection>(
94 "POST",
"/GetFolderContent/", GetFolderContent, CheckAuthSession));
96 m_httpServer.AddStreamHandler(
97 new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
98 "POST",
"/UpdateFolder/", m_InventoryService.UpdateFolder, CheckAuthSession));
100 m_httpServer.AddStreamHandler(
101 new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
102 "POST",
"/MoveFolder/", m_InventoryService.MoveFolder, CheckAuthSession));
104 m_httpServer.AddStreamHandler(
105 new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
106 "POST",
"/PurgeFolder/", m_InventoryService.PurgeFolder, CheckAuthSession));
108 m_httpServer.AddStreamHandler(
109 new RestDeserialiseSecureHandler<List<Guid>,
bool>(
110 "POST",
"/DeleteFolders/", DeleteFolders, CheckAuthSession));
112 m_httpServer.AddStreamHandler(
113 new RestDeserialiseSecureHandler<List<Guid>,
bool>(
114 "POST",
"/DeleteItem/", DeleteItems, CheckAuthSession));
116 m_httpServer.AddStreamHandler(
117 new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>(
118 "POST",
"/QueryItem/", m_InventoryService.GetItem, CheckAuthSession));
120 m_httpServer.AddStreamHandler(
121 new RestDeserialiseSecureHandler<InventoryFolderBase, InventoryFolderBase>(
122 "POST",
"/QueryFolder/", m_InventoryService.GetFolder, CheckAuthSession));
124 m_httpServer.AddStreamHandler(
125 new RestDeserialiseTrustedHandler<Guid, bool>(
126 "POST",
"/CreateInventory/", CreateUsersInventory, CheckTrustSource));
128 m_httpServer.AddStreamHandler(
129 new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
130 "POST",
"/NewFolder/", m_InventoryService.AddFolder, CheckAuthSession));
132 m_httpServer.AddStreamHandler(
133 new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
134 "POST",
"/CreateFolder/", m_InventoryService.AddFolder, CheckAuthSession));
136 m_httpServer.AddStreamHandler(
137 new RestDeserialiseSecureHandler<InventoryItemBase, bool>(
138 "POST",
"/NewItem/", m_InventoryService.AddItem, CheckAuthSession));
140 m_httpServer.AddStreamHandler(
141 new RestDeserialiseTrustedHandler<InventoryItemBase, bool>(
142 "POST",
"/AddNewItem/", m_InventoryService.AddItem, CheckTrustSource));
144 m_httpServer.AddStreamHandler(
145 new RestDeserialiseSecureHandler<Guid, List<InventoryItemBase>>(
146 "POST",
"/GetItems/", GetFolderItems, CheckAuthSession));
148 m_httpServer.AddStreamHandler(
149 new RestDeserialiseSecureHandler<List<InventoryItemBase>,
bool>(
150 "POST",
"/MoveItems/", MoveItems, CheckAuthSession));
156 m_httpServer.AddStreamHandler(
157 new RestDeserialiseTrustedHandler<Guid, List<InventoryItemBase>>
158 (
"POST",
"/ActiveGestures/", GetActiveGestures, CheckTrustSource));
165 m_httpServer.AddStreamHandler(
166 new RestDeserialiseTrustedHandler<Guid, List<InventoryFolderBase>>
167 (
"POST",
"/RootFolders/", GetInventorySkeleton, CheckTrustSource));
169 m_httpServer.AddStreamHandler(
170 new RestDeserialiseTrustedHandler<InventoryItemBase, int>
171 (
"POST",
"/AssetPermissions/", GetAssetPermissions, CheckTrustSource));
175 #region Wrappers for converting the Guid parameter
179 UUID userID =
new UUID(guid);
180 return new List<InventoryFolderBase>(GetSystemFolders(userID).Values);
185 private Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID)
193 Dictionary<AssetType, InventoryFolderBase> folders =
new Dictionary<AssetType, InventoryFolderBase>();
196 if ((folder.
Type != (
short)AssetType.Folder) && (folder.
Type != (
short)AssetType.Unknown))
197 folders[(AssetType)folder.
Type] = folder;
200 folders[AssetType.Folder] = root;
204 m_log.WarnFormat(
"[INVENTORY SERVICE]: System folders for {0} not found", userID);
205 return new Dictionary<AssetType, InventoryFolderBase>();
210 return m_InventoryService.GetFolderContent(UUID.Zero,
new UUID(guid));
215 List<InventoryItemBase> allItems =
new List<InventoryItemBase>();
221 List<InventoryItemBase> items = m_InventoryService.GetFolderItems(UUID.Zero,
new UUID(folderID));
225 allItems.InsertRange(0, items);
232 UUID userID =
new UUID(rawUserID);
235 return m_InventoryService.CreateUserInventory(userID);
240 UUID userID =
new UUID(rawUserID);
242 return m_InventoryService.GetActiveGestures(userID);
247 UUID userID =
new UUID(rawUserID);
248 return m_InventoryService.GetInventorySkeleton(userID);
253 return m_InventoryService.GetAssetPermissions(item.Owner, item.AssetID);
258 List<UUID> uuids =
new List<UUID>();
259 foreach (Guid g
in items)
260 uuids.Add(
new UUID(g));
262 return m_InventoryService.DeleteFolders(UUID.Zero, uuids);
267 List<UUID> uuids =
new List<UUID>();
268 foreach (Guid g
in items)
269 uuids.Add(
new UUID(g));
271 return m_InventoryService.DeleteItems(UUID.Zero, uuids);
278 UUID ownerID = UUID.Zero;
280 ownerID = items[0].Owner;
281 return m_InventoryService.MoveItems(ownerID, items);
294 m_log.InfoFormat(
"[INVENTORY IN CONNECTOR]: Checking trusted source {0}", peer);
295 UriBuilder ub =
new UriBuilder(m_userserver_url);
296 IPAddress[] uaddrs = Dns.GetHostAddresses(ub.Host);
297 foreach (IPAddress uaddr
in uaddrs)
299 if (uaddr.Equals(peer.Address))
306 "[INVENTORY IN CONNECTOR]: Rejecting request since source {0} was not in the list of trusted sources",
bool CheckTrustSource(IPEndPoint peer)
Check that the source of an inventory request is one that we trust.
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs.
bool CreateUsersInventory(Guid rawUserID)
virtual void AddHttpHandlers(IHttpServer m_httpServer)
virtual bool CheckAuthSession(string session_id, string avatar_id)
Check that the source of an inventory request for a particular agent is a current session belonging t...
List< InventoryFolderBase > GetInventorySkeleton(Guid rawUserID)
bool DeleteFolders(List< Guid > items)
IInventoryService m_InventoryService
Inventory Item - contains all the properties associated with an individual inventory piece...
bool MoveItems(List< InventoryItemBase > items)
List< InventoryFolderBase > GetSystemFolders(Guid guid)
List< InventoryItemBase > GetActiveGestures(Guid rawUserID)
Interactive OpenSim region server
InventoryCollection GetFolderContent(Guid guid)
int GetAssetPermissions(InventoryItemBase item)
List< InventoryItemBase > GetFolderItems(Guid folderID)
List< InventoryFolderBase > Folders
bool DeleteItems(List< Guid > items)
InventoryServiceInConnector(IConfigSource config, IHttpServer server, string configName)
Used to serialize a whole inventory for transfer over the network.