aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Services/HGInventoryService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications/Services/HGInventoryService.cs')
-rw-r--r--OpenSim/Framework/Communications/Services/HGInventoryService.cs1429
1 files changed, 714 insertions, 715 deletions
diff --git a/OpenSim/Framework/Communications/Services/HGInventoryService.cs b/OpenSim/Framework/Communications/Services/HGInventoryService.cs
index b01c30e..7eaed89 100644
--- a/OpenSim/Framework/Communications/Services/HGInventoryService.cs
+++ b/OpenSim/Framework/Communications/Services/HGInventoryService.cs
@@ -1,715 +1,714 @@
1/** 1/**
2 * Copyright (c) 2008, Contributors. All rights reserved. 2 * Copyright (c) 2008, Contributors. All rights reserved.
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without modification, 5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met: 6 * are permitted provided that the following conditions are met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright notice, 8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice, 10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation 11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution. 12 * and/or other materials provided with the distribution.
13 * * Neither the name of the Organizations nor the names of Individual 13 * * Neither the name of the Organizations nor the names of Individual
14 * Contributors may be used to endorse or promote products derived from 14 * Contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission. 15 * this software without specific prior written permission.
16 * 16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25 * OF THE POSSIBILITY OF SUCH DAMAGE. 25 * OF THE POSSIBILITY OF SUCH DAMAGE.
26 * 26 *
27 */ 27 */
28 28
29using System; 29using System;
30using System.Collections; 30using System.Collections;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Reflection; 32using System.Reflection;
33using log4net; 33using log4net;
34using Nini.Config; 34using Nini.Config;
35using OpenMetaverse; 35using OpenMetaverse;
36using OpenSim.Data; 36using OpenSim.Data;
37using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Framework.Communications.Clients; 38using OpenSim.Framework.Communications.Clients;
39using OpenSim.Framework.Communications.Cache; 39using OpenSim.Framework.Communications.Cache;
40using Caps = OpenSim.Framework.Communications.Capabilities.Caps; 40using Caps = OpenSim.Framework.Communications.Capabilities.Caps;
41using LLSDHelpers = OpenSim.Framework.Communications.Capabilities.LLSDHelpers; 41using LLSDHelpers = OpenSim.Framework.Communications.Capabilities.LLSDHelpers;
42using OpenSim.Framework.Servers; 42using OpenSim.Framework.Servers;
43using OpenSim.Framework.Servers.Interfaces; 43using OpenSim.Framework.Servers.Interfaces;
44 44
45using OpenMetaverse.StructuredData; 45using OpenMetaverse.StructuredData;
46 46
47namespace OpenSim.Framework.Communications.Services 47namespace OpenSim.Framework.Communications.Services
48{ 48{
49 public class HGInventoryService 49 public class HGInventoryService
50 { 50 {
51 private static readonly ILog m_log 51 private static readonly ILog m_log
52 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 52 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 53
54 private InventoryServiceBase m_inventoryService; 54 private InventoryServiceBase m_inventoryService;
55 IHttpServer httpServer; 55 IHttpServer httpServer;
56 private string m_thisInventoryUrl = "http://localhost:9000"; 56 private string m_thisInventoryUrl = "http://localhost:9000";
57 private string m_thisHostname = "127.0.0.1"; 57 private string m_thisHostname = "127.0.0.1";
58 private uint m_thisPort = 9000; 58 private uint m_thisPort = 9000;
59 59
60 // These two used for local access, standalone mode 60 // These two used for local access, standalone mode
61 private UserManagerBase m_userService = null; 61 private UserManagerBase m_userService = null;
62 IAssetDataPlugin m_assetProvider = null; 62 IAssetDataPlugin m_assetProvider = null;
63 63
64 // These two used for remote access 64 // These two used for remote access
65 string m_UserServerURL = string.Empty; 65 string m_UserServerURL = string.Empty;
66 string m_AssetServerURL = string.Empty; 66 string m_AssetServerURL = string.Empty;
67 SynchronousGridAssetClient m_AssetClient = null; 67 SynchronousGridAssetClient m_AssetClient = null;
68 68
69 // Constructor for grid inventory server 69 // Constructor for grid inventory server
70 public HGInventoryService(InventoryServiceBase invService, string assetServiceURL, string userServiceURL, IHttpServer httpserver, string thisurl) 70 public HGInventoryService(InventoryServiceBase invService, string assetServiceURL, string userServiceURL, IHttpServer httpserver, string thisurl)
71 { 71 {
72 m_UserServerURL = userServiceURL; 72 m_UserServerURL = userServiceURL;
73 m_AssetServerURL = assetServiceURL; 73 m_AssetServerURL = assetServiceURL;
74 74
75 m_AssetClient = new SynchronousGridAssetClient(m_AssetServerURL); 75 m_AssetClient = new SynchronousGridAssetClient(m_AssetServerURL);
76 76
77 Init(invService, thisurl, httpserver); 77 Init(invService, thisurl, httpserver);
78 } 78 }
79 79
80 // Constructor for standalone mode 80 // Constructor for standalone mode
81 public HGInventoryService(InventoryServiceBase invService, IAssetDataPlugin assetService, UserManagerBase userService, IHttpServer httpserver, string thisurl) 81 public HGInventoryService(InventoryServiceBase invService, IAssetDataPlugin assetService, UserManagerBase userService, IHttpServer httpserver, string thisurl)
82 { 82 {
83 m_userService = userService; 83 m_userService = userService;
84 m_assetProvider = assetService; 84 m_assetProvider = assetService;
85 85
86 Init(invService, thisurl, httpserver); 86 Init(invService, thisurl, httpserver);
87 } 87 }
88 88
89 private void Init(InventoryServiceBase invService, string thisurl, IHttpServer httpserver) 89 private void Init(InventoryServiceBase invService, string thisurl, IHttpServer httpserver)
90 { 90 {
91 m_inventoryService = invService; 91 m_inventoryService = invService;
92 m_thisInventoryUrl = thisurl; 92 m_thisInventoryUrl = thisurl;
93 if (!m_thisInventoryUrl.EndsWith("/")) 93 if (!m_thisInventoryUrl.EndsWith("/"))
94 m_thisInventoryUrl += "/"; 94 m_thisInventoryUrl += "/";
95 95
96 Uri uri = new Uri(m_thisInventoryUrl); 96 Uri uri = new Uri(m_thisInventoryUrl);
97 if (uri != null) 97 if (uri != null)
98 { 98 {
99 m_thisHostname = uri.Host; 99 m_thisHostname = uri.Host;
100 m_thisPort = (uint)uri.Port; 100 m_thisPort = (uint)uri.Port;
101 } 101 }
102 102
103 httpServer = httpserver; 103 httpServer = httpserver;
104 104
105 AddHttpHandlers(); 105 AddHttpHandlers();
106 } 106 }
107 107
108 public virtual void AddHttpHandlers() 108 public virtual void AddHttpHandlers()
109 { 109 {
110 httpServer.AddHTTPHandler("/InvCap/", CapHandler); 110 httpServer.AddHTTPHandler("/InvCap/", CapHandler);
111 } 111 }
112 112
113 public bool CheckAuthSession(string session_id, string avatar_id) 113 public bool CheckAuthSession(string session_id, string avatar_id)
114 { 114 {
115 return true; 115 return true;
116 } 116 }
117 117
118 118
119 // In truth, this is not called from the outside, for standalones. I'm just making it 119 // In truth, this is not called from the outside, for standalones. I'm just making it
120 // a handler already so that this can be reused for the InventoryServer. 120 // a handler already so that this can be reused for the InventoryServer.
121 public string CreateCapUrl(Guid _userid) 121 public string CreateCapUrl(Guid _userid)
122 { 122 {
123 UUID userID = new UUID(_userid); 123 UUID userID = new UUID(_userid);
124 UUID random = UUID.Random(); 124 UUID random = UUID.Random();
125 string url = m_thisInventoryUrl + random.ToString() + "/"; 125 string url = m_thisInventoryUrl + random.ToString() + "/";
126 m_log.InfoFormat("[HGStandaloneInvService] Creating Cap URL {0} for user {1}", url, userID.ToString()); 126 m_log.InfoFormat("[HGStandaloneInvService] Creating Cap URL {0} for user {1}", url, userID.ToString());
127 return url; 127 return url;
128 } 128 }
129 129
130 /// <summary> 130 /// <summary>
131 /// Return a user's entire inventory 131 /// Return a user's entire inventory
132 /// </summary> 132 /// </summary>
133 /// <param name="rawUserID"></param> 133 /// <param name="rawUserID"></param>
134 /// <returns>The user's inventory. If an inventory cannot be found then an empty collection is returned.</returns> 134 /// <returns>The user's inventory. If an inventory cannot be found then an empty collection is returned.</returns>
135 public InventoryCollection GetUserInventory(Guid rawUserID) 135 public InventoryCollection GetUserInventory(Guid rawUserID)
136 { 136 {
137 UUID userID = new UUID(rawUserID); 137 UUID userID = new UUID(rawUserID);
138 138
139 m_log.Info("[HGStandaloneInvModule]: Processing request for inventory of " + userID); 139 m_log.Info("[HGStandaloneInvModule]: Processing request for inventory of " + userID);
140 140
141 // Uncomment me to simulate a slow responding inventory server 141 // Uncomment me to simulate a slow responding inventory server
142 //Thread.Sleep(16000); 142 //Thread.Sleep(16000);
143 143
144 InventoryCollection invCollection = new InventoryCollection(); 144 InventoryCollection invCollection = new InventoryCollection();
145 145
146 List<InventoryFolderBase> allFolders = m_inventoryService.GetInventorySkeleton(userID); 146 List<InventoryFolderBase> allFolders = m_inventoryService.GetInventorySkeleton(userID);
147 147
148 if (null == allFolders) 148 if (null == allFolders)
149 { 149 {
150 m_log.WarnFormat("[HGStandaloneInvModule]: No inventory found for user {0}", rawUserID); 150 m_log.WarnFormat("[HGStandaloneInvModule]: No inventory found for user {0}", rawUserID);
151 151
152 return invCollection; 152 return invCollection;
153 } 153 }
154 154
155 List<InventoryItemBase> allItems = new List<InventoryItemBase>(); 155 List<InventoryItemBase> allItems = new List<InventoryItemBase>();
156 156
157 foreach (InventoryFolderBase folder in allFolders) 157 foreach (InventoryFolderBase folder in allFolders)
158 { 158 {
159 List<InventoryItemBase> items = m_inventoryService.RequestFolderItems(folder.ID); 159 List<InventoryItemBase> items = m_inventoryService.RequestFolderItems(folder.ID);
160 160
161 if (items != null) 161 if (items != null)
162 { 162 {
163 allItems.InsertRange(0, items); 163 allItems.InsertRange(0, items);
164 } 164 }
165 } 165 }
166 166
167 invCollection.UserID = userID; 167 invCollection.UserID = userID;
168 invCollection.Folders = allFolders; 168 invCollection.Folders = allFolders;
169 invCollection.Items = allItems; 169 invCollection.Items = allItems;
170 170
171 // foreach (InventoryFolderBase folder in invCollection.Folders) 171 // foreach (InventoryFolderBase folder in invCollection.Folders)
172 // { 172 // {
173 // m_log.DebugFormat("[GRID AGENT INVENTORY]: Sending back folder {0} {1}", folder.Name, folder.ID); 173 // m_log.DebugFormat("[GRID AGENT INVENTORY]: Sending back folder {0} {1}", folder.Name, folder.ID);
174 // } 174 // }
175 // 175 //
176 // foreach (InventoryItemBase item in invCollection.Items) 176 // foreach (InventoryItemBase item in invCollection.Items)
177 // { 177 // {
178 // m_log.DebugFormat("[GRID AGENT INVENTORY]: Sending back item {0} {1}, folder {2}", item.Name, item.ID, item.Folder); 178 // m_log.DebugFormat("[GRID AGENT INVENTORY]: Sending back item {0} {1}, folder {2}", item.Name, item.ID, item.Folder);
179 // } 179 // }
180 180
181 m_log.InfoFormat( 181 m_log.InfoFormat(
182 "[HGStandaloneInvModule]: Sending back inventory response to user {0} containing {1} folders and {2} items", 182 "[HGStandaloneInvModule]: Sending back inventory response to user {0} containing {1} folders and {2} items",
183 invCollection.UserID, invCollection.Folders.Count, invCollection.Items.Count); 183 invCollection.UserID, invCollection.Folders.Count, invCollection.Items.Count);
184 184
185 return invCollection; 185 return invCollection;
186 } 186 }
187 187
188 public InventoryCollection FetchDescendants(InventoryFolderBase fb) 188 public InventoryCollection FetchDescendants(InventoryFolderBase fb)
189 { 189 {
190 m_log.Info("[HGStandaloneInvService]: Processing request for folder " + fb.ID); 190 m_log.Info("[HGStandaloneInvService]: Processing request for folder " + fb.ID);
191 191
192 // Uncomment me to simulate a slow responding inventory server 192 // Uncomment me to simulate a slow responding inventory server
193 //Thread.Sleep(16000); 193 //Thread.Sleep(16000);
194 194
195 InventoryCollection invCollection = new InventoryCollection(); 195 InventoryCollection invCollection = new InventoryCollection();
196 196
197 List<InventoryItemBase> items = m_inventoryService.RequestFolderItems(fb.ID); 197 List<InventoryItemBase> items = m_inventoryService.RequestFolderItems(fb.ID);
198 List<InventoryFolderBase> folders = m_inventoryService.RequestSubFolders(fb.ID); 198 List<InventoryFolderBase> folders = m_inventoryService.RequestSubFolders(fb.ID);
199 199
200 invCollection.UserID = fb.Owner; 200 invCollection.UserID = fb.Owner;
201 invCollection.Folders = folders; 201 invCollection.Folders = folders;
202 invCollection.Items = items; 202 invCollection.Items = items;
203 203
204 m_log.DebugFormat("[HGStandaloneInvService]: Found {0} items and {1} folders", items.Count, folders.Count); 204 m_log.DebugFormat("[HGStandaloneInvService]: Found {0} items and {1} folders", items.Count, folders.Count);
205 205
206 return invCollection; 206 return invCollection;
207 } 207 }
208 208
209 public bool RemoveFolder(InventoryFolderBase folder) 209 public bool RemoveFolder(InventoryFolderBase folder)
210 { 210 {
211 m_log.Debug("[HGStandaloneInvService]: Removefolder: Operation not implemented yet."); 211 m_log.Debug("[HGStandaloneInvService]: Removefolder: Operation not implemented yet.");
212 return false; 212 return false;
213 } 213 }
214 214
215 public InventoryItemBase GetInventoryItem(InventoryItemBase item) 215 public InventoryItemBase GetInventoryItem(InventoryItemBase item)
216 { 216 {
217 m_log.Info("[HGStandaloneInvService]: Get item " + item.ID); 217 m_log.Info("[HGStandaloneInvService]: Get item " + item.ID);
218 218
219 item = m_inventoryService.GetInventoryItem(item.ID); 219 item = m_inventoryService.GetInventoryItem(item.ID);
220 if (item == null) 220 if (item == null)
221 m_log.Debug("[HGStandaloneInvService]: null item"); 221 m_log.Debug("[HGStandaloneInvService]: null item");
222 return item; 222 return item;
223 } 223 }
224 224
225 public InventoryItemBase AddItem(InventoryItemBase item) 225 public InventoryItemBase AddItem(InventoryItemBase item)
226 { 226 {
227 m_log.DebugFormat("[HGStandaloneInvService]: Add item {0} from {1}", item.ID, item.Owner); 227 m_log.DebugFormat("[HGStandaloneInvService]: Add item {0} from {1}", item.ID, item.Owner);
228 if (m_inventoryService.AddItem(item)) 228 if (m_inventoryService.AddItem(item))
229 return item; 229 return item;
230 else 230 else
231 { 231 {
232 item.ID = UUID.Zero; 232 item.ID = UUID.Zero;
233 return item; 233 return item;
234 } 234 }
235 } 235 }
236 236
237 public InventoryItemBase UpdateItem(InventoryItemBase item) 237 public InventoryItemBase UpdateItem(InventoryItemBase item)
238 { 238 {
239 m_log.DebugFormat("[HGStandaloneInvService]: Update item {0} from {1}", item.ID, item.Owner); 239 m_log.DebugFormat("[HGStandaloneInvService]: Update item {0} from {1}", item.ID, item.Owner);
240 InventoryItemBase it = m_inventoryService.GetInventoryItem(item.ID); 240 InventoryItemBase it = m_inventoryService.GetInventoryItem(item.ID);
241 item.CurrentPermissions = it.CurrentPermissions; 241 item.CurrentPermissions = it.CurrentPermissions;
242 item.AssetID = it.AssetID; 242 item.AssetID = it.AssetID;
243 if (m_inventoryService.UpdateItem(item)) 243 if (m_inventoryService.UpdateItem(item))
244 return item; 244 return item;
245 else 245 else
246 { 246 {
247 item.ID = UUID.Zero; 247 item.ID = UUID.Zero;
248 return item; 248 return item;
249 } 249 }
250 } 250 }
251 251
252 public InventoryItemBase MoveItem(InventoryItemBase newitem) 252 public InventoryItemBase MoveItem(InventoryItemBase newitem)
253 { 253 {
254 m_log.DebugFormat("[HGStandaloneInvService]: Move item {0} from {1}", newitem.ID, newitem.Owner); 254 m_log.DebugFormat("[HGStandaloneInvService]: Move item {0} from {1}", newitem.ID, newitem.Owner);
255 InventoryItemBase Item = m_inventoryService.GetInventoryItem(newitem.ID); 255 InventoryItemBase Item = m_inventoryService.GetInventoryItem(newitem.ID);
256 if (Item != null) 256 if (Item != null)
257 { 257 {
258 if (newitem.Name != String.Empty) 258 if (newitem.Name != String.Empty)
259 { 259 {
260 Item.Name = newitem.Name; 260 Item.Name = newitem.Name;
261 } 261 }
262 Item.Folder = newitem.Folder; 262 Item.Folder = newitem.Folder;
263 m_inventoryService.UpdateItem(Item); 263 m_inventoryService.UpdateItem(Item);
264 return Item; 264 return Item;
265 } 265 }
266 else 266 else
267 { 267 {
268 m_log.Debug("[HGStandaloneInvService]: Failed to find item " + newitem.ID); 268 m_log.Debug("[HGStandaloneInvService]: Failed to find item " + newitem.ID);
269 newitem.ID = UUID.Zero; 269 newitem.ID = UUID.Zero;
270 return newitem; 270 return newitem;
271 } 271 }
272 272
273 } 273 }
274 274
275 public InventoryItemBase DeleteItem(InventoryItemBase item) 275 public InventoryItemBase DeleteItem(InventoryItemBase item)
276 { 276 {
277 item = m_inventoryService.GetInventoryItem(item.ID); 277 item = m_inventoryService.GetInventoryItem(item.ID);
278 if (m_inventoryService.DeleteItem(item)) 278 if (m_inventoryService.DeleteItem(item))
279 return item; 279 return item;
280 else 280 else
281 { 281 {
282 item.ID = UUID.Zero; 282 item.ID = UUID.Zero;
283 return item; 283 return item;
284 } 284 }
285 } 285 }
286 286
287 public InventoryItemBase CopyItem(InventoryItemBase olditem) 287 public InventoryItemBase CopyItem(InventoryItemBase olditem)
288 { 288 {
289 m_log.DebugFormat("[HGStandaloneInvService]: Copy item {0} from {1}", olditem.ID, olditem.Owner); 289 m_log.DebugFormat("[HGStandaloneInvService]: Copy item {0} from {1}", olditem.ID, olditem.Owner);
290 InventoryItemBase Item = m_inventoryService.GetInventoryItem(olditem.ID); // this is the old item id 290 InventoryItemBase Item = m_inventoryService.GetInventoryItem(olditem.ID); // this is the old item id
291 // BIG HACK here 291 // BIG HACK here
292 UUID newID = olditem.AssetID; 292 UUID newID = olditem.AssetID;
293 if (Item != null) 293 if (Item != null)
294 { 294 {
295 if (olditem.Name != String.Empty) 295 if (olditem.Name != String.Empty)
296 { 296 {
297 Item.Name = olditem.Name; 297 Item.Name = olditem.Name;
298 } 298 }
299 Item.ID = newID; 299 Item.ID = newID;
300 Item.Folder = olditem.Folder; 300 Item.Folder = olditem.Folder;
301 Item.Owner = olditem.Owner; 301 Item.Owner = olditem.Owner;
302 // There should be some tests here about the owner, etc but I'm going to ignore that 302 // There should be some tests here about the owner, etc but I'm going to ignore that
303 // because I'm not sure it makes any sense 303 // because I'm not sure it makes any sense
304 // Also I should probably clone the asset... 304 // Also I should probably clone the asset...
305 m_inventoryService.AddItem(Item); 305 m_inventoryService.AddItem(Item);
306 return Item; 306 return Item;
307 } 307 }
308 else 308 else
309 { 309 {
310 m_log.Debug("[HGStandaloneInvService]: Failed to find item " + olditem.ID); 310 m_log.Debug("[HGStandaloneInvService]: Failed to find item " + olditem.ID);
311 olditem.ID = UUID.Zero; 311 olditem.ID = UUID.Zero;
312 return olditem; 312 return olditem;
313 } 313 }
314 314
315 } 315 }
316 316
317 /// <summary> 317 /// <summary>
318 /// Guid to UUID wrapper for same name IInventoryServices method 318 /// Guid to UUID wrapper for same name IInventoryServices method
319 /// </summary> 319 /// </summary>
320 /// <param name="rawUserID"></param> 320 /// <param name="rawUserID"></param>
321 /// <returns></returns> 321 /// <returns></returns>
322 public List<InventoryFolderBase> GetInventorySkeleton(Guid rawUserID) 322 public List<InventoryFolderBase> GetInventorySkeleton(Guid rawUserID)
323 { 323 {
324 UUID userID = new UUID(rawUserID); 324 UUID userID = new UUID(rawUserID);
325 return m_inventoryService.GetInventorySkeleton(userID); 325 return m_inventoryService.GetInventorySkeleton(userID);
326 } 326 }
327 327
328 public List<InventoryItemBase> GetActiveGestures(Guid rawUserID) 328 public List<InventoryItemBase> GetActiveGestures(Guid rawUserID)
329 { 329 {
330 UUID userID = new UUID(rawUserID); 330 UUID userID = new UUID(rawUserID);
331 331
332 m_log.InfoFormat("[HGStandaloneInvService]: fetching active gestures for user {0}", userID); 332 m_log.InfoFormat("[HGStandaloneInvService]: fetching active gestures for user {0}", userID);
333 333
334 return m_inventoryService.GetActiveGestures(userID); 334 return m_inventoryService.GetActiveGestures(userID);
335 } 335 }
336 336
337 public AssetBase GetAsset(InventoryItemBase item) 337 public AssetBase GetAsset(InventoryItemBase item)
338 { 338 {
339 m_log.Info("[HGStandaloneInvService]: Get asset " + item.AssetID + " for item " + item.ID); 339 m_log.Info("[HGStandaloneInvService]: Get asset " + item.AssetID + " for item " + item.ID);
340 AssetBase asset = new AssetBase(item.AssetID, "NULL"); // send an asset with no data 340 AssetBase asset = new AssetBase(item.AssetID, "NULL"); // send an asset with no data
341 InventoryItemBase item2 = m_inventoryService.GetInventoryItem(item.ID); 341 InventoryItemBase item2 = m_inventoryService.GetInventoryItem(item.ID);
342 if (item2 == null) 342 if (item2 == null)
343 { 343 {
344 m_log.Debug("[HGStandaloneInvService]: null item"); 344 m_log.Debug("[HGStandaloneInvService]: null item");
345 return asset; 345 return asset;
346 } 346 }
347 if (item2.Owner != item.Owner) 347 if (item2.Owner != item.Owner)
348 { 348 {
349 m_log.DebugFormat("[HGStandaloneInvService]: client with uuid {0} is trying to get an item of owner {1}", item.Owner, item2.Owner); 349 m_log.DebugFormat("[HGStandaloneInvService]: client with uuid {0} is trying to get an item of owner {1}", item.Owner, item2.Owner);
350 return asset; 350 return asset;
351 } 351 }
352 352
353 // All good, get the asset 353 // All good, get the asset
354 //AssetBase theasset = m_assetProvider.FetchAsset(item.AssetID); 354 //AssetBase theasset = m_assetProvider.FetchAsset(item.AssetID);
355 AssetBase theasset = FetchAsset(item.AssetID, (item.InvType == (int)InventoryType.Texture)); 355 AssetBase theasset = FetchAsset(item.AssetID, (item.InvType == (int)InventoryType.Texture));
356 356
357 m_log.Debug("[HGStandaloneInvService] Found asset " + ((theasset == null) ? "NULL" : "Not Null")); 357 m_log.Debug("[HGStandaloneInvService] Found asset " + ((theasset == null) ? "NULL" : "Not Null"));
358 if (theasset != null) 358 if (theasset != null)
359 { 359 {
360 asset = theasset; 360 asset = theasset;
361 //m_log.Debug(" >> Sending assetID " + item.AssetID); 361 //m_log.Debug(" >> Sending assetID " + item.AssetID);
362 } 362 }
363 return asset; 363 return asset;
364 } 364 }
365 365
366 public bool PostAsset(AssetBase asset) 366 public bool PostAsset(AssetBase asset)
367 { 367 {
368 m_log.Info("[HGStandaloneInvService]: Post asset " + asset.FullID); 368 m_log.Info("[HGStandaloneInvService]: Post asset " + asset.FullID);
369 //m_assetProvider.CreateAsset(asset); 369 //m_assetProvider.CreateAsset(asset);
370 StoreAsset(asset); 370 StoreAsset(asset);
371 371
372 return true; 372 return true;
373 } 373 }
374 374
375 /// <summary> 375 /// <summary>
376 /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, UUID, byte[])</see> 376 /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, UUID, byte[])</see>
377 /// </summary> 377 /// </summary>
378 public UUID UpdateInventoryItemAsset(UUID userID, UUID itemID, byte[] data) 378 public UUID UpdateInventoryItemAsset(UUID userID, UUID itemID, byte[] data)
379 { 379 {
380 m_log.Debug("[HGStandaloneInvService]: UpdateInventoryitemAsset for user " + userID + " item " + itemID); 380 m_log.Debug("[HGStandaloneInvService]: UpdateInventoryitemAsset for user " + userID + " item " + itemID);
381 InventoryItemBase item = m_inventoryService.GetInventoryItem(itemID); 381 InventoryItemBase item = m_inventoryService.GetInventoryItem(itemID);
382 382
383 if (item != null) 383 if (item != null)
384 { 384 {
385 // We're still not dealing with permissions 385 // We're still not dealing with permissions
386 //if ((InventoryType)item.InvType == InventoryType.Notecard) 386 //if ((InventoryType)item.InvType == InventoryType.Notecard)
387 //{ 387 //{
388 // if (!Permissions.CanEditNotecard(itemID, UUID.Zero, userID)) 388 // if (!Permissions.CanEditNotecard(itemID, UUID.Zero, userID))
389 // { 389 // {
390 // //remoteClient.SendAgentAlertMessage("Insufficient permissions to edit notecard", false); 390 // //remoteClient.SendAgentAlertMessage("Insufficient permissions to edit notecard", false);
391 // return UUID.Zero; 391 // return UUID.Zero;
392 // } 392 // }
393 393
394 // //remoteClient.SendAgentAlertMessage("Notecard saved", false); 394 // //remoteClient.SendAgentAlertMessage("Notecard saved", false);
395 //} 395 //}
396 //else if ((InventoryType)item.InvType == InventoryType.LSL) 396 //else if ((InventoryType)item.InvType == InventoryType.LSL)
397 //{ 397 //{
398 // if (!Permissions.CanEditScript(itemID, UUID.Zero, remoteClient.AgentId)) 398 // if (!Permissions.CanEditScript(itemID, UUID.Zero, remoteClient.AgentId))
399 // { 399 // {
400 // //remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false); 400 // //remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false);
401 // return UUID.Zero; 401 // return UUID.Zero;
402 // } 402 // }
403 403
404 // //remoteClient.SendAgentAlertMessage("Script saved", false); 404 // //remoteClient.SendAgentAlertMessage("Script saved", false);
405 //} 405 //}
406 406
407 AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data); 407 AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data);
408 PostAsset(asset); 408 PostAsset(asset);
409 409
410 item.AssetID = asset.FullID; 410 item.AssetID = asset.FullID;
411 item.Owner = userID; 411 item.Owner = userID;
412 m_inventoryService.UpdateItem(item); 412 m_inventoryService.UpdateItem(item);
413 413
414 return (asset.FullID); 414 return (asset.FullID);
415 } 415 }
416 return UUID.Zero; 416 return UUID.Zero;
417 } 417 }
418 418
419 private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data) 419 private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data)
420 { 420 {
421 AssetBase asset = new AssetBase(); 421 AssetBase asset = new AssetBase();
422 asset.Name = name; 422 asset.Name = name;
423 asset.Description = description; 423 asset.Description = description;
424 asset.Type = assetType; 424 asset.Type = assetType;
425 asset.FullID = UUID.Random(); 425 asset.FullID = UUID.Random();
426 asset.Data = (data == null) ? new byte[1] : data; 426 asset.Data = (data == null) ? new byte[1] : data;
427 427
428 return asset; 428 return asset;
429 } 429 }
430 430
431 #region Caps 431 #region Caps
432 432
433 Dictionary<UUID, Hashtable> invCaps = new Dictionary<UUID, Hashtable>(); 433 Dictionary<UUID, Hashtable> invCaps = new Dictionary<UUID, Hashtable>();
434 434
435 public Hashtable CapHandler(Hashtable request) 435 public Hashtable CapHandler(Hashtable request)
436 { 436 {
437 m_log.Debug("[CONNECTION DEBUGGING]: InvCapHandler Called"); 437 m_log.Debug("[CONNECTION DEBUGGING]: InvCapHandler Called");
438 438
439 m_log.Debug("---------------------------"); 439 m_log.Debug("---------------------------");
440 m_log.Debug(" >> uri=" + request["uri"]); 440 m_log.Debug(" >> uri=" + request["uri"]);
441 m_log.Debug(" >> content-type=" + request["content-type"]); 441 m_log.Debug(" >> content-type=" + request["content-type"]);
442 m_log.Debug(" >> http-method=" + request["http-method"]); 442 m_log.Debug(" >> http-method=" + request["http-method"]);
443 m_log.Debug("---------------------------\n"); 443 m_log.Debug("---------------------------\n");
444 444
445 // these are requests if the type 445 // these are requests if the type
446 // http://inventoryserver/InvCap/uuuuuuuu-uuuu-uuuu-uuuu-uuuuuuuuuuuu/kkkkkkkk-kkkk-kkkk-kkkk-kkkkkkkkkkkk/ 446 // http://inventoryserver/InvCap/uuuuuuuu-uuuu-uuuu-uuuu-uuuuuuuuuuuu/kkkkkkkk-kkkk-kkkk-kkkk-kkkkkkkkkkkk/
447 447
448 Hashtable responsedata = new Hashtable(); 448 Hashtable responsedata = new Hashtable();
449 responsedata["content_type"] = "text/plain"; 449 responsedata["content_type"] = "text/plain";
450 450
451 UUID userID; 451 UUID userID;
452 string authToken = string.Empty; 452 string authToken = string.Empty;
453 string authority = string.Empty; 453 string authority = string.Empty;
454 if (!GetParams(request, out userID, out authority, out authToken)) 454 if (!GetParams(request, out userID, out authority, out authToken))
455 { 455 {
456 m_log.InfoFormat("[HGStandaloneInvService]: Invalid parameters for InvCap message {0}", request["uri"]); 456 m_log.InfoFormat("[HGStandaloneInvService]: Invalid parameters for InvCap message {0}", request["uri"]);
457 responsedata["int_response_code"] = 404; 457 responsedata["int_response_code"] = 404;
458 responsedata["str_response_string"] = "Not found"; 458 responsedata["str_response_string"] = "Not found";
459 459
460 return responsedata; 460 return responsedata;
461 } 461 }
462 462
463 // Next, let's parse the verb 463 // Next, let's parse the verb
464 string method = (string)request["http-method"]; 464 string method = (string)request["http-method"];
465 if (method.Equals("GET")) 465 if (method.Equals("GET"))
466 { 466 {
467 DoInvCapPost(request, responsedata, userID, authToken); 467 DoInvCapPost(request, responsedata, userID, authority, authToken);
468 return responsedata; 468 return responsedata;
469 } 469 }
470 //else if (method.Equals("DELETE")) 470 //else if (method.Equals("DELETE"))
471 //{ 471 //{
472 // DoAgentDelete(request, responsedata, agentID, action, regionHandle); 472 // DoAgentDelete(request, responsedata, agentID, action, regionHandle);
473 473
474 // return responsedata; 474 // return responsedata;
475 //} 475 //}
476 else 476 else
477 { 477 {
478 m_log.InfoFormat("[HGStandaloneInvService]: method {0} not supported in agent message", method); 478 m_log.InfoFormat("[HGStandaloneInvService]: method {0} not supported in agent message", method);
479 responsedata["int_response_code"] = 405; 479 responsedata["int_response_code"] = 405;
480 responsedata["str_response_string"] = "Method not allowed"; 480 responsedata["str_response_string"] = "Method not allowed";
481 481
482 return responsedata; 482 return responsedata;
483 } 483 }
484 484
485 } 485 }
486 486
487 public virtual void DoInvCapPost(Hashtable request, Hashtable responsedata, UUID userID, string authToken) 487 public virtual void DoInvCapPost(Hashtable request, Hashtable responsedata, UUID userID, string authority, string authToken)
488 { 488 {
489 489
490 // This is the meaning of POST agent 490 // This is the meaning of POST agent
491 491
492 // Check Auth Token 492 // Check Auth Token
493 if ((m_userService != null) && !(m_userService is IAuthentication)) 493 if ((m_userService != null) && !(m_userService is IAuthentication))
494 { 494 {
495 m_log.Debug("[HGStandaloneInvService]: UserService is not IAuthentication. Denying access to inventory."); 495 m_log.Debug("[HGStandaloneInvService]: UserService is not IAuthentication. Denying access to inventory.");
496 responsedata["int_response_code"] = 501; 496 responsedata["int_response_code"] = 501;
497 responsedata["str_response_string"] = "Not implemented"; 497 responsedata["str_response_string"] = "Not implemented";
498 return; 498 return;
499 } 499 }
500 500
501 bool success = VerifyKey(userID, authToken); 501 bool success = VerifyKey(userID, authority, authToken);
502 m_log.Debug("[HGStandaloneInvService]: Key verification returned " + success); 502
503 503 if (success)
504 if (success) 504 {
505 { 505
506 506 m_log.DebugFormat("[HGStandaloneInvService]: User has been authorized. Creating service handlers.");
507 m_log.DebugFormat("[HGStandaloneInvService]: User has been authorized. Creating service handlers."); 507
508 508 // Then establish secret service handlers
509 // Then establish secret service handlers 509
510 510 Hashtable usercaps = RegisterCaps(userID, authToken);
511 Hashtable usercaps = RegisterCaps(userID, authToken); 511
512 512 responsedata["int_response_code"] = 200;
513 responsedata["int_response_code"] = 200; 513 //responsedata["str_response_string"] = "OK";
514 //responsedata["str_response_string"] = "OK"; 514 responsedata["str_response_string"] = SerializeHashtable(usercaps);
515 responsedata["str_response_string"] = SerializeHashtable(usercaps); 515 }
516 } 516 else
517 else 517 {
518 { 518 m_log.DebugFormat("[HGStandaloneInvService]: User has is unauthorized. Denying service handlers.");
519 m_log.DebugFormat("[HGStandaloneInvService]: User has is unauthorized. Denying service handlers."); 519 responsedata["int_response_code"] = 403;
520 responsedata["int_response_code"] = 403; 520 responsedata["str_response_string"] = "Forbidden";
521 responsedata["str_response_string"] = "Forbidden"; 521 }
522 } 522 }
523 } 523
524 524
525 525 /// <summary>
526 /// <summary> 526 /// Extract the params from a request.
527 /// Extract the params from a request. 527 /// </summary>
528 /// </summary> 528 public static bool GetParams(Hashtable request, out UUID uuid, out string authority, out string authKey)
529 public static bool GetParams(Hashtable request, out UUID uuid, out string authority, out string authKey) 529 {
530 { 530 uuid = UUID.Zero;
531 uuid = UUID.Zero; 531 authority = string.Empty;
532 authority = string.Empty; 532 authKey = string.Empty;
533 authKey = string.Empty; 533
534 534 string uri = (string)request["uri"];
535 string uri = (string)request["uri"]; 535 uri = uri.Trim(new char[] { '/' });
536 uri = uri.Trim(new char[] { '/' }); 536 string[] parts = uri.Split('/');
537 string[] parts = uri.Split('/'); 537 if (parts.Length <= 1)
538 if (parts.Length <= 1) 538 {
539 { 539 return false;
540 return false; 540 }
541 } 541 else
542 else 542 {
543 { 543 if (!UUID.TryParse(parts[1], out uuid))
544 if (!UUID.TryParse(parts[1], out uuid)) 544 return false;
545 return false; 545
546 546 if (parts.Length >= 3)
547 if (parts.Length >= 3) 547 {
548 { 548 authKey = parts[2];
549 authKey = parts[2]; 549 return true;
550 return true; 550 }
551 } 551 }
552 } 552
553 553 Uri authUri;
554 Uri authUri; 554 Hashtable headers = (Hashtable)request["headers"];
555 Hashtable headers = (Hashtable)request["headers"]; 555
556 556 // Authorization keys look like this:
557 // Authorization keys look like this: 557 // http://orgrid.org:8002/<uuid>
558 // http://orgrid.org:8002/<uuid> 558 if (headers.ContainsKey("authorization"))
559 if (headers.ContainsKey("authorization")) 559 {
560 { 560 if (Uri.TryCreate((string)headers["authorization"], UriKind.Absolute, out authUri))
561 if (Uri.TryCreate((string)headers["authorization"], UriKind.Absolute, out authUri)) 561 {
562 { 562 authority = authUri.Authority;
563 authority = authUri.Authority; 563 authKey = authUri.PathAndQuery.Trim('/');
564 authKey = authUri.PathAndQuery.Trim('/'); 564 m_log.DebugFormat("[HGStandaloneInvService]: Got authority {0} and key {1}", authority, authKey);
565 m_log.DebugFormat("[HGStandaloneInvService]: Got authority {0} and key {1}", authority, authKey); 565 return true;
566 return true; 566 }
567 } 567 else
568 else 568 m_log.Debug("[HGStandaloneInvService]: Wrong format for Authorization header: " + (string)headers["authorization"]);
569 m_log.Debug("[HGStandaloneInvService]: Wrong format for Authorization header: " + (string)headers["authorization"]); 569 }
570 } 570 else
571 else 571 m_log.Debug("[HGStandaloneInvService]: Authorization header not found");
572 m_log.Debug("[HGStandaloneInvService]: Authorization header not found"); 572
573 573 return false;
574 return false; 574 }
575 } 575
576 576 string SerializeHashtable(Hashtable hash)
577 string SerializeHashtable(Hashtable hash) 577 {
578 { 578 string result = string.Empty;
579 string result = string.Empty; 579 foreach (object key in hash.Keys)
580 foreach (object key in hash.Keys) 580 {
581 { 581 result += key.ToString() + "," + hash[key].ToString() + ";";
582 result += key.ToString() + "," + hash[key].ToString() + ";"; 582 }
583 } 583 return result;
584 return result; 584 }
585 } 585
586 586 Hashtable RegisterCaps(UUID userID, string authToken)
587 Hashtable RegisterCaps(UUID userID, string authToken) 587 {
588 { 588 lock (invCaps)
589 lock (invCaps) 589 {
590 { 590 if (invCaps.ContainsKey(userID))
591 if (invCaps.ContainsKey(userID)) 591 {
592 { 592 // Remove the old ones
593 // Remove the old ones 593 DeregisterCaps(httpServer, invCaps[userID]);
594 DeregisterCaps(httpServer, invCaps[userID]); 594 invCaps.Remove(userID);
595 invCaps.Remove(userID); 595 }
596 } 596 }
597 } 597
598 598 Caps caps = new Caps(null, httpServer, m_thisHostname, m_thisPort, authToken, userID, false, "Inventory");
599 Caps caps = new Caps(null, httpServer, m_thisHostname, m_thisPort, authToken, userID, false, "Inventory"); 599 caps.RegisterInventoryServiceHandlers("/" + authToken + "/InventoryCap/");
600 caps.RegisterInventoryServiceHandlers("/" + authToken + "/InventoryCap/"); 600 caps.ItemUpdatedCall = UpdateInventoryItemAsset;
601 caps.ItemUpdatedCall = UpdateInventoryItemAsset; 601 Hashtable capsHandlers = caps.CapsHandlers.CapsDetails;
602 Hashtable capsHandlers = caps.CapsHandlers.CapsDetails; 602
603 603 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<Guid, InventoryCollection>(
604 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<Guid, InventoryCollection>( 604 "POST", AddAndGetCapUrl(authToken, "GetInventory", capsHandlers), GetUserInventory, CheckAuthSession));
605 "POST", AddAndGetCapUrl(authToken, "GetInventory", capsHandlers), GetUserInventory, CheckAuthSession)); 605
606 606 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryFolderBase, InventoryCollection>(
607 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryFolderBase, InventoryCollection>( 607 "POST", AddAndGetCapUrl(authToken, "FetchDescendants", capsHandlers), FetchDescendants, CheckAuthSession));
608 "POST", AddAndGetCapUrl(authToken, "FetchDescendants", capsHandlers), FetchDescendants, CheckAuthSession)); 608 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
609 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( 609 "POST", AddAndGetCapUrl(authToken, "NewFolder", capsHandlers), m_inventoryService.AddFolder, CheckAuthSession));
610 "POST", AddAndGetCapUrl(authToken, "NewFolder", capsHandlers), m_inventoryService.AddFolder, CheckAuthSession)); 610 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
611 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( 611 "POST", AddAndGetCapUrl(authToken, "UpdateFolder", capsHandlers), m_inventoryService.UpdateFolder, CheckAuthSession));
612 "POST", AddAndGetCapUrl(authToken, "UpdateFolder", capsHandlers), m_inventoryService.UpdateFolder, CheckAuthSession)); 612 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
613 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( 613 "POST", AddAndGetCapUrl(authToken, "MoveFolder", capsHandlers), m_inventoryService.MoveFolder, CheckAuthSession));
614 "POST", AddAndGetCapUrl(authToken, "MoveFolder", capsHandlers), m_inventoryService.MoveFolder, CheckAuthSession)); 614 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
615 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( 615 "POST", AddAndGetCapUrl(authToken, "PurgeFolder", capsHandlers), m_inventoryService.PurgeFolder, CheckAuthSession));
616 "POST", AddAndGetCapUrl(authToken, "PurgeFolder", capsHandlers), m_inventoryService.PurgeFolder, CheckAuthSession)); 616 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
617 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( 617 "POST", AddAndGetCapUrl(authToken, "RemoveFolder", capsHandlers), RemoveFolder, CheckAuthSession));
618 "POST", AddAndGetCapUrl(authToken, "RemoveFolder", capsHandlers), RemoveFolder, CheckAuthSession)); 618
619 619 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>(
620 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>( 620 "POST", AddAndGetCapUrl(authToken, "GetItem", capsHandlers), GetInventoryItem, CheckAuthSession));
621 "POST", AddAndGetCapUrl(authToken, "GetItem", capsHandlers), GetInventoryItem, CheckAuthSession)); 621 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>(
622 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>( 622 "POST", AddAndGetCapUrl(authToken, "NewItem", capsHandlers), AddItem, CheckAuthSession));
623 "POST", AddAndGetCapUrl(authToken, "NewItem", capsHandlers), AddItem, CheckAuthSession)); 623 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>(
624 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>( 624 "POST", AddAndGetCapUrl(authToken, "UpdateItem", capsHandlers), UpdateItem, CheckAuthSession));
625 "POST", AddAndGetCapUrl(authToken, "UpdateItem", capsHandlers), UpdateItem, CheckAuthSession)); 625 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>(
626 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>( 626 "POST", AddAndGetCapUrl(authToken, "MoveItem", capsHandlers), MoveItem, CheckAuthSession));
627 "POST", AddAndGetCapUrl(authToken, "MoveItem", capsHandlers), MoveItem, CheckAuthSession)); 627 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>(
628 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>( 628 "POST", AddAndGetCapUrl(authToken, "DeleteItem", capsHandlers), DeleteItem, CheckAuthSession));
629 "POST", AddAndGetCapUrl(authToken, "DeleteItem", capsHandlers), DeleteItem, CheckAuthSession)); 629 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>(
630 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>( 630 "POST", AddAndGetCapUrl(authToken, "CopyItem", capsHandlers), CopyItem, CheckAuthSession));
631 "POST", AddAndGetCapUrl(authToken, "CopyItem", capsHandlers), CopyItem, CheckAuthSession)); 631
632 632 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, AssetBase>(
633 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<InventoryItemBase, AssetBase>( 633 "POST", AddAndGetCapUrl(authToken, "GetAsset", capsHandlers), GetAsset, CheckAuthSession));
634 "POST", AddAndGetCapUrl(authToken, "GetAsset", capsHandlers), GetAsset, CheckAuthSession)); 634 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<AssetBase, bool>(
635 httpServer.AddStreamHandler(new RestDeserialiseSecureHandler<AssetBase, bool>( 635 "POST", AddAndGetCapUrl(authToken, "PostAsset", capsHandlers), PostAsset, CheckAuthSession));
636 "POST", AddAndGetCapUrl(authToken, "PostAsset", capsHandlers), PostAsset, CheckAuthSession)); 636
637 637 lock (invCaps)
638 lock (invCaps) 638 invCaps.Add(userID, capsHandlers);
639 invCaps.Add(userID, capsHandlers); 639
640 640 return capsHandlers;
641 return capsHandlers; 641 }
642 } 642
643 643 string AddAndGetCapUrl(string authToken, string capType, Hashtable caps)
644 string AddAndGetCapUrl(string authToken, string capType, Hashtable caps) 644 {
645 { 645 string capUrl = "/" + authToken + "/" + capType + "/";
646 string capUrl = "/" + authToken + "/" + capType + "/"; 646
647 647 m_log.Debug("[HGStandaloneInvService] Adding inventory cap " + capUrl);
648 m_log.Debug("[HGStandaloneInvService] Adding inventory cap " + capUrl); 648 caps.Add(capType, capUrl);
649 caps.Add(capType, capUrl); 649 return capUrl;
650 return capUrl; 650 }
651 } 651
652 652 void DeregisterCaps(IHttpServer httpServer, Hashtable caps)
653 void DeregisterCaps(IHttpServer httpServer, Hashtable caps) 653 {
654 { 654 foreach (string capUrl in caps.Values)
655 foreach (string capUrl in caps.Values) 655 {
656 { 656 m_log.Debug("[HGStandaloneInvService] Removing inventory cap " + capUrl);
657 m_log.Debug("[HGStandaloneInvService] Removing inventory cap " + capUrl); 657 httpServer.RemoveStreamHandler("POST", capUrl);
658 httpServer.RemoveStreamHandler("POST", capUrl); 658 }
659 } 659 }
660 } 660
661 661 #endregion Caps
662 #endregion Caps 662
663 663 #region Local vs Remote
664 #region Local vs Remote 664
665 665 bool VerifyKey(UUID userID, string authority, string key)
666 bool VerifyKey(UUID userID, string key) 666 {
667 { 667 // Remote call to the Authorization server
668 // Remote call to the Authorization server 668 if (m_userService == null)
669 if (m_userService == null) 669 return AuthClient.VerifyKey("http://" + authority, userID, key);
670 return AuthClient.VerifyKey(m_UserServerURL, userID, key); 670 // local call
671 // local call 671 else
672 else 672 return ((IAuthentication)m_userService).VerifyKey(userID, key);
673 return ((IAuthentication)m_userService).VerifyKey(userID, key); 673 }
674 } 674
675 675 AssetBase FetchAsset(UUID assetID, bool isTexture)
676 AssetBase FetchAsset(UUID assetID, bool isTexture) 676 {
677 { 677 // Remote call to the Asset server
678 // Remote call to the Asset server 678 if (m_assetProvider == null)
679 if (m_assetProvider == null) 679 return m_AssetClient.SyncGetAsset(assetID, isTexture);
680 return m_AssetClient.SyncGetAsset(assetID, isTexture); 680 // local call
681 // local call 681 else
682 else 682 return m_assetProvider.FetchAsset(assetID);
683 return m_assetProvider.FetchAsset(assetID); 683 }
684 } 684
685 685 void StoreAsset(AssetBase asset)
686 void StoreAsset(AssetBase asset) 686 {
687 { 687 // Remote call to the Asset server
688 // Remote call to the Asset server 688 if (m_assetProvider == null)
689 if (m_assetProvider == null) 689 m_AssetClient.StoreAsset(asset);
690 m_AssetClient.StoreAsset(asset); 690 // local call
691 // local call 691 else
692 else 692 m_assetProvider.CreateAsset(asset);
693 m_assetProvider.CreateAsset(asset); 693 }
694 } 694
695 695 #endregion Local vs Remote
696 #endregion Local vs Remote 696 }
697 } 697
698 698 class SynchronousGridAssetClient : GridAssetClient
699 class SynchronousGridAssetClient : GridAssetClient 699 {
700 { 700 public SynchronousGridAssetClient(string url)
701 public SynchronousGridAssetClient(string url) 701 : base(url)
702 : base(url) 702 {
703 { 703 }
704 } 704
705 705 public AssetBase SyncGetAsset(UUID assetID, bool isTexture)
706 public AssetBase SyncGetAsset(UUID assetID, bool isTexture) 706 {
707 { 707 AssetRequest assReq = new AssetRequest();
708 AssetRequest assReq = new AssetRequest(); 708 assReq.AssetID = assetID;
709 assReq.AssetID = assetID; 709 assReq.IsTexture = isTexture;
710 assReq.IsTexture = isTexture; 710 return base.GetAsset(assReq);
711 return base.GetAsset(assReq); 711 }
712 } 712
713 713 }
714 } 714}
715}