aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-01-06 20:20:11 +0000
committerJustin Clark-Casey (justincc)2012-01-06 21:07:34 +0000
commit7661a0b2a913a7637cb8ba8310be370594901485 (patch)
treef1698bb15eef27766fe35c8dafba1092511eb17d
parentIf dragging a script that is no copy from prim inventory into agent (diff)
downloadopensim-SC_OLD-7661a0b2a913a7637cb8ba8310be370594901485.zip
opensim-SC_OLD-7661a0b2a913a7637cb8ba8310be370594901485.tar.gz
opensim-SC_OLD-7661a0b2a913a7637cb8ba8310be370594901485.tar.bz2
opensim-SC_OLD-7661a0b2a913a7637cb8ba8310be370594901485.tar.xz
Implement the FetchInventory2 capability. This accompanies the existing FetchInventoryDescendents2 capability.
Not yet enabled by default. You can enable this by setting Cap_FetchInventory2 = "localhost" in the [ClientStack.LindenCaps] section of OpenSim.ini Enabling both FetchInventory2 and FetchInventoryDescendents2 improves the situation with properly fetching attachments and hud objects Probably because viewers are never expecting the odd situation where FetchInventoryDescendents2 is present but not FetchInventory2 However, for some reason attachments and hud objects occasionally fail to appear, though their status is correct in inventory For attachments, focussing on the avatar makes them appear. Hud objects have to be reattached.
-rw-r--r--OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2Handler.cs148
-rw-r--r--OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2ServerConnector.cs70
-rw-r--r--OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs2
-rw-r--r--OpenSim/Capabilities/LLSDInventoryItem.cs9
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs151
5 files changed, 378 insertions, 2 deletions
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2Handler.cs b/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2Handler.cs
new file mode 100644
index 0000000..717a097
--- /dev/null
+++ b/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2Handler.cs
@@ -0,0 +1,148 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Reflection;
32using log4net;
33using Nini.Config;
34using OpenMetaverse;
35using OpenMetaverse.StructuredData;
36using OpenSim.Framework;
37using OpenSim.Framework.Capabilities;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Framework.Servers.HttpServer;
40using OpenSim.Services.Interfaces;
41using Caps = OpenSim.Framework.Capabilities.Caps;
42using OSDArray = OpenMetaverse.StructuredData.OSDArray;
43using OSDMap = OpenMetaverse.StructuredData.OSDMap;
44
45namespace OpenSim.Capabilities.Handlers
46{
47 public class FetchInventory2Handler
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IInventoryService m_inventoryService;
52
53 public FetchInventory2Handler(IInventoryService invService)
54 {
55 m_inventoryService = invService;
56 }
57
58 public string FetchInventoryRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
59 {
60// m_log.DebugFormat("[FETCH INVENTORY HANDLER]: Received FetchInventory capabilty request");
61
62 OSDMap requestmap = (OSDMap)OSDParser.DeserializeLLSDXml(Utils.StringToBytes(request));
63 OSDArray itemsRequested = (OSDArray)requestmap["items"];
64
65 string reply;
66 LLSDFetchInventory llsdReply = new LLSDFetchInventory();
67
68 foreach (OSDMap osdItemId in itemsRequested)
69 {
70 UUID itemId = osdItemId["item_id"].AsUUID();
71
72 InventoryItemBase item = m_inventoryService.GetItem(new InventoryItemBase(itemId));
73
74 if (item != null)
75 {
76 // We don't know the agent that this request belongs to so we'll use the agent id of the item
77 // which will be the same for all items.
78 llsdReply.agent_id = item.Owner;
79
80 llsdReply.items.Array.Add(ConvertInventoryItem(item));
81 }
82 }
83
84 reply = LLSDHelpers.SerialiseLLSDReply(llsdReply);
85
86 return reply;
87 }
88
89 /// <summary>
90 /// Convert an internal inventory item object into an LLSD object.
91 /// </summary>
92 /// <param name="invItem"></param>
93 /// <returns></returns>
94 private LLSDInventoryItem ConvertInventoryItem(InventoryItemBase invItem)
95 {
96 LLSDInventoryItem llsdItem = new LLSDInventoryItem();
97 llsdItem.asset_id = invItem.AssetID;
98 llsdItem.created_at = invItem.CreationDate;
99 llsdItem.desc = invItem.Description;
100 llsdItem.flags = (int)invItem.Flags;
101 llsdItem.item_id = invItem.ID;
102 llsdItem.name = invItem.Name;
103 llsdItem.parent_id = invItem.Folder;
104
105 try
106 {
107 llsdItem.type = Utils.AssetTypeToString((AssetType)invItem.AssetType);
108 llsdItem.inv_type = Utils.InventoryTypeToString((InventoryType)invItem.InvType);
109 }
110 catch (Exception e)
111 {
112 m_log.ErrorFormat(
113 "[WEB FETCH INV DESC HANDLER]: Problem setting asset {0} inventory {1} types while converting inventory item {2}: {3}",
114 invItem.AssetType, invItem.InvType, invItem.Name, e.Message);
115 }
116
117 llsdItem.permissions = new LLSDPermissions();
118 llsdItem.permissions.creator_id = invItem.CreatorIdAsUuid;
119 llsdItem.permissions.base_mask = (int)invItem.CurrentPermissions;
120 llsdItem.permissions.everyone_mask = (int)invItem.EveryOnePermissions;
121 llsdItem.permissions.group_id = invItem.GroupID;
122 llsdItem.permissions.group_mask = (int)invItem.GroupPermissions;
123 llsdItem.permissions.is_owner_group = invItem.GroupOwned;
124 llsdItem.permissions.next_owner_mask = (int)invItem.NextPermissions;
125 llsdItem.permissions.owner_id = invItem.Owner;
126 llsdItem.permissions.owner_mask = (int)invItem.CurrentPermissions;
127 llsdItem.sale_info = new LLSDSaleInfo();
128 llsdItem.sale_info.sale_price = invItem.SalePrice;
129 switch (invItem.SaleType)
130 {
131 default:
132 llsdItem.sale_info.sale_type = "not";
133 break;
134 case 1:
135 llsdItem.sale_info.sale_type = "original";
136 break;
137 case 2:
138 llsdItem.sale_info.sale_type = "copy";
139 break;
140 case 3:
141 llsdItem.sale_info.sale_type = "contents";
142 break;
143 }
144
145 return llsdItem;
146 }
147 }
148}
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2ServerConnector.cs b/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2ServerConnector.cs
new file mode 100644
index 0000000..0ba8931
--- /dev/null
+++ b/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2ServerConnector.cs
@@ -0,0 +1,70 @@
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
28using System;
29using Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base;
34using OpenMetaverse;
35
36namespace OpenSim.Capabilities.Handlers
37{
38 public class FetchInventory2ServerConnector : ServiceConnector
39 {
40 private IInventoryService m_InventoryService;
41 private string m_ConfigName = "CapsService";
42
43 public FetchInventory2ServerConnector(IConfigSource config, IHttpServer server, string configName)
44 : base(config, server, configName)
45 {
46 if (configName != String.Empty)
47 m_ConfigName = configName;
48
49 IConfig serverConfig = config.Configs[m_ConfigName];
50 if (serverConfig == null)
51 throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName));
52
53 string invService = serverConfig.GetString("InventoryService", String.Empty);
54
55 if (invService == String.Empty)
56 throw new Exception("No InventoryService in config file");
57
58 Object[] args = new Object[] { config };
59 m_InventoryService = ServerUtils.LoadPlugin<IInventoryService>(invService, args);
60
61 if (m_InventoryService == null)
62 throw new Exception(String.Format("Failed to load InventoryService from {0}; config is {1}", invService, m_ConfigName));
63
64 FetchInventory2Handler fiHandler = new FetchInventory2Handler(m_InventoryService);
65 IRequestHandler reqHandler
66 = new RestStreamHandler("POST", "/CAPS/FetchInventory/", fiHandler.FetchInventoryRequest);
67 server.AddStreamHandler(reqHandler);
68 }
69 }
70}
diff --git a/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs b/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs
index 3ce4e66..8b44f72 100644
--- a/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs
+++ b/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs
@@ -245,7 +245,7 @@ namespace OpenSim.Capabilities.Handlers
245// containingFolder.Name, containingFolder.ID, agentID); 245// containingFolder.Name, containingFolder.ID, agentID);
246 246
247 version = containingFolder.Version; 247 version = containingFolder.Version;
248// 248
249// if (fetchItems) 249// if (fetchItems)
250// { 250// {
251// List<InventoryItemBase> linkedItemsToAdd = new List<InventoryItemBase>(); 251// List<InventoryItemBase> linkedItemsToAdd = new List<InventoryItemBase>();
diff --git a/OpenSim/Capabilities/LLSDInventoryItem.cs b/OpenSim/Capabilities/LLSDInventoryItem.cs
index cce18d7..426a6cb 100644
--- a/OpenSim/Capabilities/LLSDInventoryItem.cs
+++ b/OpenSim/Capabilities/LLSDInventoryItem.cs
@@ -95,4 +95,11 @@ namespace OpenSim.Framework.Capabilities
95 public UUID owner_id; 95 public UUID owner_id;
96 public int version; 96 public int version;
97 } 97 }
98} 98
99 [OSDMap]
100 public class LLSDFetchInventory
101 {
102 public UUID agent_id;
103 public OSDArray items = new OSDArray();
104 }
105} \ No newline at end of file
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs b/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs
new file mode 100644
index 0000000..14501c7
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs
@@ -0,0 +1,151 @@
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
28using System;
29using System.Collections;
30using System.Reflection;
31using log4net;
32using Nini.Config;
33using Mono.Addins;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Services.Interfaces;
40using Caps = OpenSim.Framework.Capabilities.Caps;
41using OpenSim.Capabilities.Handlers;
42
43namespace OpenSim.Region.ClientStack.Linden
44{
45 /// <summary>
46 /// This module implements both WebFetchInventoryDescendents and FetchInventoryDescendents2 capabilities.
47 /// </summary>
48 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
49 public class FetchInventory2Module : INonSharedRegionModule
50 {
51// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52
53 public bool Enabled { get; private set; }
54
55 private Scene m_scene;
56
57 private IInventoryService m_inventoryService;
58
59 private string m_fetchInventory2Url;
60
61 private FetchInventory2Handler m_fetchHandler;
62
63 #region ISharedRegionModule Members
64
65 public void Initialise(IConfigSource source)
66 {
67 IConfig config = source.Configs["ClientStack.LindenCaps"];
68 if (config == null)
69 return;
70
71 m_fetchInventory2Url = config.GetString("Cap_FetchInventory2", string.Empty);
72
73 if (m_fetchInventory2Url != string.Empty)
74 Enabled = true;
75 }
76
77 public void AddRegion(Scene s)
78 {
79 if (!Enabled)
80 return;
81
82 m_scene = s;
83 }
84
85 public void RemoveRegion(Scene s)
86 {
87 if (!Enabled)
88 return;
89
90 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
91 m_scene = null;
92 }
93
94 public void RegionLoaded(Scene s)
95 {
96 if (!Enabled)
97 return;
98
99 m_inventoryService = m_scene.InventoryService;
100
101 // We'll reuse the same handler for all requests.
102 if (m_fetchInventory2Url == "localhost")
103 m_fetchHandler = new FetchInventory2Handler(m_inventoryService);
104
105 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
106 }
107
108 public void PostInitialise() {}
109
110 public void Close() {}
111
112 public string Name { get { return "FetchInventory2Module"; } }
113
114 public Type ReplaceableInterface
115 {
116 get { return null; }
117 }
118
119 #endregion
120
121 private void RegisterCaps(UUID agentID, Caps caps)
122 {
123 RegisterFetchCap(agentID, caps, "FetchInventory2", m_fetchInventory2Url);
124 }
125
126 private void RegisterFetchCap(UUID agentID, Caps caps, string capName, string url)
127 {
128 string capUrl;
129
130 if (url == "localhost")
131 {
132 capUrl = "/CAPS/" + UUID.Random();
133
134 IRequestHandler reqHandler
135 = new RestStreamHandler("POST", capUrl, m_fetchHandler.FetchInventoryRequest);
136
137 caps.RegisterHandler(capName, reqHandler);
138 }
139 else
140 {
141 capUrl = url;
142
143 caps.RegisterHandler(capName, capUrl);
144 }
145
146// m_log.DebugFormat(
147// "[FETCH INVENTORY2 MODULE]: Registered capability {0} at {1} in region {2} for {3}",
148// capName, capUrl, m_scene.RegionInfo.RegionName, agentID);
149 }
150 }
151}