diff options
author | Diva Canto | 2009-09-18 19:17:02 -0700 |
---|---|---|
committer | Diva Canto | 2009-09-18 19:17:02 -0700 |
commit | 4a55ff88c088ac0019a1106d97a8b8dd173c8cff (patch) | |
tree | aa91fe204048d6f050cffca83168aec61f76a9a2 /OpenSim/Grid/InventoryServer/GridInventoryService.cs | |
parent | First pass at the grid service. (diff) | |
parent | correct off-by-one error in save iar command handling (diff) | |
download | opensim-SC_OLD-4a55ff88c088ac0019a1106d97a8b8dd173c8cff.zip opensim-SC_OLD-4a55ff88c088ac0019a1106d97a8b8dd173c8cff.tar.gz opensim-SC_OLD-4a55ff88c088ac0019a1106d97a8b8dd173c8cff.tar.bz2 opensim-SC_OLD-4a55ff88c088ac0019a1106d97a8b8dd173c8cff.tar.xz |
Merge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Grid/InventoryServer/GridInventoryService.cs')
-rw-r--r-- | OpenSim/Grid/InventoryServer/GridInventoryService.cs | 256 |
1 files changed, 0 insertions, 256 deletions
diff --git a/OpenSim/Grid/InventoryServer/GridInventoryService.cs b/OpenSim/Grid/InventoryServer/GridInventoryService.cs deleted file mode 100644 index 0704faa..0000000 --- a/OpenSim/Grid/InventoryServer/GridInventoryService.cs +++ /dev/null | |||
@@ -1,256 +0,0 @@ | |||
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; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using log4net; | ||
34 | using Nwc.XmlRpc; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Communications; | ||
38 | using OpenSim.Framework.Communications.Cache; | ||
39 | |||
40 | namespace OpenSim.Grid.InventoryServer | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// Used on a grid server to satisfy external inventory requests | ||
44 | /// </summary> | ||
45 | public class GridInventoryService : InventoryServiceBase | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private bool m_doLookup = false; | ||
50 | |||
51 | public bool DoLookup | ||
52 | { | ||
53 | get { return m_doLookup; } | ||
54 | set { m_doLookup = value; } | ||
55 | } | ||
56 | |||
57 | private static readonly int INVENTORY_DEFAULT_SESSION_TIME = 30; // secs | ||
58 | |||
59 | private string m_userserver_url; | ||
60 | private AuthedSessionCache m_session_cache = new AuthedSessionCache(INVENTORY_DEFAULT_SESSION_TIME); | ||
61 | |||
62 | public GridInventoryService(string userserver_url) | ||
63 | { | ||
64 | m_userserver_url = userserver_url; | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// Check that the source of an inventory request is one that we trust. | ||
69 | /// </summary> | ||
70 | /// <param name="peer"></param> | ||
71 | /// <returns></returns> | ||
72 | public bool CheckTrustSource(IPEndPoint peer) | ||
73 | { | ||
74 | if (m_doLookup) | ||
75 | { | ||
76 | m_log.InfoFormat("[GRID AGENT INVENTORY]: Checking trusted source {0}", peer); | ||
77 | UriBuilder ub = new UriBuilder(m_userserver_url); | ||
78 | IPAddress[] uaddrs = Dns.GetHostAddresses(ub.Host); | ||
79 | foreach (IPAddress uaddr in uaddrs) | ||
80 | { | ||
81 | if (uaddr.Equals(peer.Address)) | ||
82 | { | ||
83 | return true; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | m_log.WarnFormat( | ||
88 | "[GRID AGENT INVENTORY]: Rejecting request since source {0} was not in the list of trusted sources", | ||
89 | peer); | ||
90 | |||
91 | return false; | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | return true; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | /// <summary> | ||
100 | /// Check that the source of an inventory request for a particular agent is a current session belonging to | ||
101 | /// that agent. | ||
102 | /// </summary> | ||
103 | /// <param name="session_id"></param> | ||
104 | /// <param name="avatar_id"></param> | ||
105 | /// <returns></returns> | ||
106 | public bool CheckAuthSession(string session_id, string avatar_id) | ||
107 | { | ||
108 | if (m_doLookup) | ||
109 | { | ||
110 | m_log.InfoFormat("[GRID AGENT INVENTORY]: checking authed session {0} {1}", session_id, avatar_id); | ||
111 | |||
112 | if (m_session_cache.getCachedSession(session_id, avatar_id) == null) | ||
113 | { | ||
114 | // cache miss, ask userserver | ||
115 | Hashtable requestData = new Hashtable(); | ||
116 | requestData["avatar_uuid"] = avatar_id; | ||
117 | requestData["session_id"] = session_id; | ||
118 | ArrayList SendParams = new ArrayList(); | ||
119 | SendParams.Add(requestData); | ||
120 | XmlRpcRequest UserReq = new XmlRpcRequest("check_auth_session", SendParams); | ||
121 | XmlRpcResponse UserResp = UserReq.Send(m_userserver_url, 3000); | ||
122 | |||
123 | Hashtable responseData = (Hashtable)UserResp.Value; | ||
124 | if (responseData.ContainsKey("auth_session") && responseData["auth_session"].ToString() == "TRUE") | ||
125 | { | ||
126 | m_log.Info("[GRID AGENT INVENTORY]: got authed session from userserver"); | ||
127 | // add to cache; the session time will be automatically renewed | ||
128 | m_session_cache.Add(session_id, avatar_id); | ||
129 | return true; | ||
130 | } | ||
131 | } | ||
132 | else | ||
133 | { | ||
134 | // cache hits | ||
135 | m_log.Info("[GRID AGENT INVENTORY]: got authed session from cache"); | ||
136 | return true; | ||
137 | } | ||
138 | |||
139 | m_log.Warn("[GRID AGENT INVENTORY]: unknown session_id, request rejected"); | ||
140 | return false; | ||
141 | } | ||
142 | else | ||
143 | { | ||
144 | return true; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | /// <summary> | ||
149 | /// Return a user's entire inventory | ||
150 | /// </summary> | ||
151 | /// <param name="rawUserID"></param> | ||
152 | /// <returns>The user's inventory. If an inventory cannot be found then an empty collection is returned.</returns> | ||
153 | public InventoryCollection GetUserInventory(Guid rawUserID) | ||
154 | { | ||
155 | UUID userID = new UUID(rawUserID); | ||
156 | |||
157 | m_log.InfoFormat("[GRID AGENT INVENTORY]: Processing request for inventory of {0}", userID); | ||
158 | |||
159 | // Uncomment me to simulate a slow responding inventory server | ||
160 | //Thread.Sleep(16000); | ||
161 | |||
162 | InventoryCollection invCollection = new InventoryCollection(); | ||
163 | |||
164 | List<InventoryFolderBase> allFolders = GetInventorySkeleton(userID); | ||
165 | |||
166 | if (null == allFolders) | ||
167 | { | ||
168 | m_log.WarnFormat("[GRID AGENT INVENTORY]: No inventory found for user {0}", rawUserID); | ||
169 | |||
170 | return invCollection; | ||
171 | } | ||
172 | |||
173 | List<InventoryItemBase> allItems = new List<InventoryItemBase>(); | ||
174 | |||
175 | foreach (InventoryFolderBase folder in allFolders) | ||
176 | { | ||
177 | List<InventoryItemBase> items = RequestFolderItems(folder.ID); | ||
178 | |||
179 | if (items != null) | ||
180 | { | ||
181 | allItems.InsertRange(0, items); | ||
182 | } | ||
183 | } | ||
184 | |||
185 | invCollection.UserID = userID; | ||
186 | invCollection.Folders = allFolders; | ||
187 | invCollection.Items = allItems; | ||
188 | |||
189 | // foreach (InventoryFolderBase folder in invCollection.Folders) | ||
190 | // { | ||
191 | // m_log.DebugFormat("[GRID AGENT INVENTORY]: Sending back folder {0} {1}", folder.Name, folder.ID); | ||
192 | // } | ||
193 | // | ||
194 | // foreach (InventoryItemBase item in invCollection.Items) | ||
195 | // { | ||
196 | // m_log.DebugFormat("[GRID AGENT INVENTORY]: Sending back item {0} {1}, folder {2}", item.Name, item.ID, item.Folder); | ||
197 | // } | ||
198 | |||
199 | m_log.InfoFormat( | ||
200 | "[GRID AGENT INVENTORY]: Sending back inventory response to user {0} containing {1} folders and {2} items", | ||
201 | invCollection.UserID, invCollection.Folders.Count, invCollection.Items.Count); | ||
202 | |||
203 | return invCollection; | ||
204 | } | ||
205 | |||
206 | public List<InventoryItemBase> GetFolderItems(Guid folderID) | ||
207 | { | ||
208 | List<InventoryItemBase> allItems = new List<InventoryItemBase>(); | ||
209 | |||
210 | |||
211 | List<InventoryItemBase> items = RequestFolderItems(new UUID(folderID)); | ||
212 | |||
213 | if (items != null) | ||
214 | { | ||
215 | allItems.InsertRange(0, items); | ||
216 | } | ||
217 | m_log.InfoFormat( | ||
218 | "[GRID AGENT INVENTORY]: Sending back inventory response containing {0} items", allItems.Count.ToString()); | ||
219 | return allItems; | ||
220 | } | ||
221 | |||
222 | /// <summary> | ||
223 | /// Guid to UUID wrapper for same name IInventoryServices method | ||
224 | /// </summary> | ||
225 | /// <param name="rawUserID"></param> | ||
226 | /// <returns></returns> | ||
227 | public List<InventoryFolderBase> GetInventorySkeleton(Guid rawUserID) | ||
228 | { | ||
229 | UUID userID = new UUID(rawUserID); | ||
230 | return GetInventorySkeleton(userID); | ||
231 | } | ||
232 | |||
233 | /// <summary> | ||
234 | /// Create an inventory for the given user. | ||
235 | /// </summary> | ||
236 | /// <param name="rawUserID"></param> | ||
237 | /// <returns></returns> | ||
238 | public bool CreateUsersInventory(Guid rawUserID) | ||
239 | { | ||
240 | UUID userID = new UUID(rawUserID); | ||
241 | |||
242 | m_log.InfoFormat("[GRID AGENT INVENTORY]: Creating new set of inventory folders for user {0}", userID); | ||
243 | |||
244 | return CreateNewUserInventory(userID); | ||
245 | } | ||
246 | |||
247 | public List<InventoryItemBase> GetActiveGestures(Guid rawUserID) | ||
248 | { | ||
249 | UUID userID = new UUID(rawUserID); | ||
250 | |||
251 | m_log.InfoFormat("[GRID AGENT INVENTORY]: fetching active gestures for user {0}", userID); | ||
252 | |||
253 | return GetActiveGestures(userID); | ||
254 | } | ||
255 | } | ||
256 | } | ||