aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneAssetService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Hypergrid/HGStandaloneAssetService.cs')
-rw-r--r--OpenSim/Region/CoreModules/Hypergrid/HGStandaloneAssetService.cs201
1 files changed, 201 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneAssetService.cs b/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneAssetService.cs
new file mode 100644
index 0000000..13efe6b
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneAssetService.cs
@@ -0,0 +1,201 @@
1/**
2 * Copyright (c) 2008, Contributors. All rights reserved.
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the Organizations nor the names of Individual
14 * Contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
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
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,
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
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
25 * OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29using System;
30using System.Collections.Generic;
31using System.Net;
32using System.Reflection;
33
34using log4net;
35using Nini.Config;
36
37using OpenMetaverse;
38
39using OpenSim.Framework;
40using OpenSim.Framework.Communications;
41using OpenSim.Framework.Communications.Cache;
42using OpenSim.Framework.Servers;
43using OpenSim.Region.Framework.Interfaces;
44using OpenSim.Region.Framework.Scenes;
45using OpenSim.Grid.AssetServer;
46using OpenSim.Data;
47
48namespace OpenSim.Region.CoreModules.Hypergrid
49{
50 public class HGStandaloneAssetService : IRegionModule
51 {
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 private static bool initialized = false;
54 private static bool enabled = false;
55
56 Scene m_scene;
57 //AssetService m_assetService;
58
59 #region IRegionModule interface
60
61 public void Initialise(Scene scene, IConfigSource config)
62 {
63 if (!initialized)
64 {
65 initialized = true;
66 m_scene = scene;
67
68 // This module is only on for standalones in hypergrid mode
69 enabled = !config.Configs["Startup"].GetBoolean("gridmode", true) && config.Configs["Startup"].GetBoolean("hypergrid", false);
70 }
71 }
72
73 public void PostInitialise()
74 {
75 if (enabled)
76 {
77 m_log.Info("[HGStandaloneAssetService]: Starting...");
78
79 //m_assetService = new AssetService(m_scene);
80 new AssetService(m_scene);
81 }
82 }
83
84 public void Close()
85 {
86 }
87
88 public string Name
89 {
90 get { return "HGStandaloneAssetService"; }
91 }
92
93 public bool IsSharedModule
94 {
95 get { return true; }
96 }
97
98 #endregion
99
100 }
101
102 public class AssetService
103 {
104 private IUserService m_userService;
105 private bool m_doLookup = false;
106
107 public bool DoLookup
108 {
109 get { return m_doLookup; }
110 set { m_doLookup = value; }
111 }
112 private static readonly ILog m_log
113 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
114
115 public AssetService(Scene m_scene)
116 {
117 AddHttpHandlers(m_scene);
118 m_userService = m_scene.CommsManager.UserService;
119 }
120
121 protected void AddHttpHandlers(Scene m_scene)
122 {
123 IAssetDataPlugin m_assetProvider = ((AssetServerBase)m_scene.AssetCache.AssetServer).AssetProviderPlugin;
124
125 BaseHttpServer httpServer = m_scene.CommsManager.HttpServer;
126 httpServer.AddStreamHandler(new GetAssetStreamHandler(m_assetProvider));
127 httpServer.AddStreamHandler(new PostAssetStreamHandler(m_assetProvider));
128
129 }
130
131 ///// <summary>
132 ///// Check that the source of an inventory request is one that we trust.
133 ///// </summary>
134 ///// <param name="peer"></param>
135 ///// <returns></returns>
136 //public bool CheckTrustSource(IPEndPoint peer)
137 //{
138 // if (m_doLookup)
139 // {
140 // m_log.InfoFormat("[GRID AGENT INVENTORY]: Checking trusted source {0}", peer);
141 // UriBuilder ub = new UriBuilder(m_userserver_url);
142 // IPAddress[] uaddrs = Dns.GetHostAddresses(ub.Host);
143 // foreach (IPAddress uaddr in uaddrs)
144 // {
145 // if (uaddr.Equals(peer.Address))
146 // {
147 // return true;
148 // }
149 // }
150
151 // m_log.WarnFormat(
152 // "[GRID AGENT INVENTORY]: Rejecting request since source {0} was not in the list of trusted sources",
153 // peer);
154
155 // return false;
156 // }
157 // else
158 // {
159 // return true;
160 // }
161 //}
162
163 /// <summary>
164 /// Check that the source of an inventory request for a particular agent is a current session belonging to
165 /// that agent.
166 /// </summary>
167 /// <param name="session_id"></param>
168 /// <param name="avatar_id"></param>
169 /// <returns></returns>
170 public bool CheckAuthSession(string session_id, string avatar_id)
171 {
172 if (m_doLookup)
173 {
174 m_log.InfoFormat("[HGStandaloneInvService]: checking authed session {0} {1}", session_id, avatar_id);
175 UUID userID = UUID.Zero;
176 UUID sessionID = UUID.Zero;
177 UUID.TryParse(avatar_id, out userID);
178 UUID.TryParse(session_id, out sessionID);
179 if (userID.Equals(UUID.Zero) || sessionID.Equals(UUID.Zero))
180 {
181 m_log.Info("[HGStandaloneInvService]: Invalid user or session id " + avatar_id + "; " + session_id);
182 return false;
183 }
184 UserProfileData userProfile = m_userService.GetUserProfile(userID);
185 if (userProfile != null && userProfile.CurrentAgent != null &&
186 userProfile.CurrentAgent.SessionID == sessionID)
187 {
188 m_log.Info("[HGStandaloneInvService]: user is logged in and session is valid. Authorizing access.");
189 return true;
190 }
191
192 m_log.Warn("[HGStandaloneInvService]: unknown user or session_id, request rejected");
193 return false;
194 }
195 else
196 {
197 return true;
198 }
199 }
200 }
201}