diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Hypergrid/HGStandaloneAssetService.cs | 398 |
1 files changed, 199 insertions, 199 deletions
diff --git a/OpenSim/Region/Environment/Modules/Hypergrid/HGStandaloneAssetService.cs b/OpenSim/Region/Environment/Modules/Hypergrid/HGStandaloneAssetService.cs index 192904c..d090052 100644 --- a/OpenSim/Region/Environment/Modules/Hypergrid/HGStandaloneAssetService.cs +++ b/OpenSim/Region/Environment/Modules/Hypergrid/HGStandaloneAssetService.cs | |||
@@ -1,200 +1,200 @@ | |||
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 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Net; | 31 | using System.Net; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | 33 | ||
34 | using log4net; | 34 | using log4net; |
35 | using Nini.Config; | 35 | using Nini.Config; |
36 | 36 | ||
37 | using OpenMetaverse; | 37 | using OpenMetaverse; |
38 | 38 | ||
39 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
40 | using OpenSim.Framework.Communications; | 40 | using OpenSim.Framework.Communications; |
41 | using OpenSim.Framework.Communications.Cache; | 41 | using OpenSim.Framework.Communications.Cache; |
42 | using OpenSim.Framework.Servers; | 42 | using OpenSim.Framework.Servers; |
43 | using OpenSim.Region.Environment.Interfaces; | 43 | using OpenSim.Region.Environment.Interfaces; |
44 | using OpenSim.Region.Environment.Scenes; | 44 | using OpenSim.Region.Environment.Scenes; |
45 | using OpenSim.Grid.AssetServer; | 45 | using OpenSim.Grid.AssetServer; |
46 | 46 | ||
47 | namespace OpenSim.Region.Environment.Modules.Hypergrid | 47 | namespace OpenSim.Region.Environment.Modules.Hypergrid |
48 | { | 48 | { |
49 | public class HGStandaloneAssetService : IRegionModule | 49 | public class HGStandaloneAssetService : IRegionModule |
50 | { | 50 | { |
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
52 | private static bool initialized = false; | 52 | private static bool initialized = false; |
53 | private static bool enabled = false; | 53 | private static bool enabled = false; |
54 | 54 | ||
55 | Scene m_scene; | 55 | Scene m_scene; |
56 | //AssetService m_assetService; | 56 | //AssetService m_assetService; |
57 | 57 | ||
58 | #region IRegionModule interface | 58 | #region IRegionModule interface |
59 | 59 | ||
60 | public void Initialise(Scene scene, IConfigSource config) | 60 | public void Initialise(Scene scene, IConfigSource config) |
61 | { | 61 | { |
62 | if (!initialized) | 62 | if (!initialized) |
63 | { | 63 | { |
64 | initialized = true; | 64 | initialized = true; |
65 | m_scene = scene; | 65 | m_scene = scene; |
66 | 66 | ||
67 | // This module is only on for standalones in hypergrid mode | 67 | // This module is only on for standalones in hypergrid mode |
68 | enabled = !config.Configs["Startup"].GetBoolean("gridmode", true) && config.Configs["Startup"].GetBoolean("hypergrid", false); | 68 | enabled = !config.Configs["Startup"].GetBoolean("gridmode", true) && config.Configs["Startup"].GetBoolean("hypergrid", false); |
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | public void PostInitialise() | 72 | public void PostInitialise() |
73 | { | 73 | { |
74 | if (enabled) | 74 | if (enabled) |
75 | { | 75 | { |
76 | m_log.Info("[HGStandaloneAssetService]: Starting..."); | 76 | m_log.Info("[HGStandaloneAssetService]: Starting..."); |
77 | 77 | ||
78 | //m_assetService = new AssetService(m_scene); | 78 | //m_assetService = new AssetService(m_scene); |
79 | new AssetService(m_scene); | 79 | new AssetService(m_scene); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | public void Close() | 83 | public void Close() |
84 | { | 84 | { |
85 | } | 85 | } |
86 | 86 | ||
87 | public string Name | 87 | public string Name |
88 | { | 88 | { |
89 | get { return "HGStandaloneAssetService"; } | 89 | get { return "HGStandaloneAssetService"; } |
90 | } | 90 | } |
91 | 91 | ||
92 | public bool IsSharedModule | 92 | public bool IsSharedModule |
93 | { | 93 | { |
94 | get { return true; } | 94 | get { return true; } |
95 | } | 95 | } |
96 | 96 | ||
97 | #endregion | 97 | #endregion |
98 | 98 | ||
99 | } | 99 | } |
100 | 100 | ||
101 | public class AssetService | 101 | public class AssetService |
102 | { | 102 | { |
103 | private IUserService m_userService; | 103 | private IUserService m_userService; |
104 | private bool m_doLookup = false; | 104 | private bool m_doLookup = false; |
105 | 105 | ||
106 | public bool DoLookup | 106 | public bool DoLookup |
107 | { | 107 | { |
108 | get { return m_doLookup; } | 108 | get { return m_doLookup; } |
109 | set { m_doLookup = value; } | 109 | set { m_doLookup = value; } |
110 | } | 110 | } |
111 | private static readonly ILog m_log | 111 | private static readonly ILog m_log |
112 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 112 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
113 | 113 | ||
114 | public AssetService(Scene m_scene) | 114 | public AssetService(Scene m_scene) |
115 | { | 115 | { |
116 | AddHttpHandlers(m_scene); | 116 | AddHttpHandlers(m_scene); |
117 | m_userService = m_scene.CommsManager.UserService; | 117 | m_userService = m_scene.CommsManager.UserService; |
118 | } | 118 | } |
119 | 119 | ||
120 | protected void AddHttpHandlers(Scene m_scene) | 120 | protected void AddHttpHandlers(Scene m_scene) |
121 | { | 121 | { |
122 | IAssetProviderPlugin m_assetProvider = ((AssetServerBase)m_scene.AssetCache.AssetServer).AssetProviderPlugin; | 122 | IAssetProviderPlugin m_assetProvider = ((AssetServerBase)m_scene.AssetCache.AssetServer).AssetProviderPlugin; |
123 | 123 | ||
124 | m_scene.AddStreamHandler(new GetAssetStreamHandler(m_assetProvider)); | 124 | m_scene.AddStreamHandler(new GetAssetStreamHandler(m_assetProvider)); |
125 | m_scene.AddStreamHandler(new PostAssetStreamHandler(m_assetProvider)); | 125 | m_scene.AddStreamHandler(new PostAssetStreamHandler(m_assetProvider)); |
126 | 126 | ||
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | ///// <summary> | 130 | ///// <summary> |
131 | ///// Check that the source of an inventory request is one that we trust. | 131 | ///// Check that the source of an inventory request is one that we trust. |
132 | ///// </summary> | 132 | ///// </summary> |
133 | ///// <param name="peer"></param> | 133 | ///// <param name="peer"></param> |
134 | ///// <returns></returns> | 134 | ///// <returns></returns> |
135 | //public bool CheckTrustSource(IPEndPoint peer) | 135 | //public bool CheckTrustSource(IPEndPoint peer) |
136 | //{ | 136 | //{ |
137 | // if (m_doLookup) | 137 | // if (m_doLookup) |
138 | // { | 138 | // { |
139 | // m_log.InfoFormat("[GRID AGENT INVENTORY]: Checking trusted source {0}", peer); | 139 | // m_log.InfoFormat("[GRID AGENT INVENTORY]: Checking trusted source {0}", peer); |
140 | // UriBuilder ub = new UriBuilder(m_userserver_url); | 140 | // UriBuilder ub = new UriBuilder(m_userserver_url); |
141 | // IPAddress[] uaddrs = Dns.GetHostAddresses(ub.Host); | 141 | // IPAddress[] uaddrs = Dns.GetHostAddresses(ub.Host); |
142 | // foreach (IPAddress uaddr in uaddrs) | 142 | // foreach (IPAddress uaddr in uaddrs) |
143 | // { | 143 | // { |
144 | // if (uaddr.Equals(peer.Address)) | 144 | // if (uaddr.Equals(peer.Address)) |
145 | // { | 145 | // { |
146 | // return true; | 146 | // return true; |
147 | // } | 147 | // } |
148 | // } | 148 | // } |
149 | 149 | ||
150 | // m_log.WarnFormat( | 150 | // m_log.WarnFormat( |
151 | // "[GRID AGENT INVENTORY]: Rejecting request since source {0} was not in the list of trusted sources", | 151 | // "[GRID AGENT INVENTORY]: Rejecting request since source {0} was not in the list of trusted sources", |
152 | // peer); | 152 | // peer); |
153 | 153 | ||
154 | // return false; | 154 | // return false; |
155 | // } | 155 | // } |
156 | // else | 156 | // else |
157 | // { | 157 | // { |
158 | // return true; | 158 | // return true; |
159 | // } | 159 | // } |
160 | //} | 160 | //} |
161 | 161 | ||
162 | /// <summary> | 162 | /// <summary> |
163 | /// Check that the source of an inventory request for a particular agent is a current session belonging to | 163 | /// Check that the source of an inventory request for a particular agent is a current session belonging to |
164 | /// that agent. | 164 | /// that agent. |
165 | /// </summary> | 165 | /// </summary> |
166 | /// <param name="session_id"></param> | 166 | /// <param name="session_id"></param> |
167 | /// <param name="avatar_id"></param> | 167 | /// <param name="avatar_id"></param> |
168 | /// <returns></returns> | 168 | /// <returns></returns> |
169 | public bool CheckAuthSession(string session_id, string avatar_id) | 169 | public bool CheckAuthSession(string session_id, string avatar_id) |
170 | { | 170 | { |
171 | if (m_doLookup) | 171 | if (m_doLookup) |
172 | { | 172 | { |
173 | m_log.InfoFormat("[HGStandaloneInvService]: checking authed session {0} {1}", session_id, avatar_id); | 173 | m_log.InfoFormat("[HGStandaloneInvService]: checking authed session {0} {1}", session_id, avatar_id); |
174 | UUID userID = UUID.Zero; | 174 | UUID userID = UUID.Zero; |
175 | UUID sessionID = UUID.Zero; | 175 | UUID sessionID = UUID.Zero; |
176 | UUID.TryParse(avatar_id, out userID); | 176 | UUID.TryParse(avatar_id, out userID); |
177 | UUID.TryParse(session_id, out sessionID); | 177 | UUID.TryParse(session_id, out sessionID); |
178 | if (userID.Equals(UUID.Zero) || sessionID.Equals(UUID.Zero)) | 178 | if (userID.Equals(UUID.Zero) || sessionID.Equals(UUID.Zero)) |
179 | { | 179 | { |
180 | m_log.Info("[HGStandaloneInvService]: Invalid user or session id " + avatar_id + "; " + session_id); | 180 | m_log.Info("[HGStandaloneInvService]: Invalid user or session id " + avatar_id + "; " + session_id); |
181 | return false; | 181 | return false; |
182 | } | 182 | } |
183 | UserProfileData userProfile = m_userService.GetUserProfile(userID); | 183 | UserProfileData userProfile = m_userService.GetUserProfile(userID); |
184 | if (userProfile != null && userProfile.CurrentAgent != null && | 184 | if (userProfile != null && userProfile.CurrentAgent != null && |
185 | userProfile.CurrentAgent.SessionID == sessionID) | 185 | userProfile.CurrentAgent.SessionID == sessionID) |
186 | { | 186 | { |
187 | m_log.Info("[HGStandaloneInvService]: user is logged in and session is valid. Authorizing access."); | 187 | m_log.Info("[HGStandaloneInvService]: user is logged in and session is valid. Authorizing access."); |
188 | return true; | 188 | return true; |
189 | } | 189 | } |
190 | 190 | ||
191 | m_log.Warn("[HGStandaloneInvService]: unknown user or session_id, request rejected"); | 191 | m_log.Warn("[HGStandaloneInvService]: unknown user or session_id, request rejected"); |
192 | return false; | 192 | return false; |
193 | } | 193 | } |
194 | else | 194 | else |
195 | { | 195 | { |
196 | return true; | 196 | return true; |
197 | } | 197 | } |
198 | } | 198 | } |
199 | } | 199 | } |
200 | } | 200 | } |