diff options
Diffstat (limited to 'OpenSim/Server')
-rw-r--r-- | OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | 182 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs | 53 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Simulation/Utils.cs | 70 |
3 files changed, 305 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs new file mode 100644 index 0000000..1d455c6 --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | |||
@@ -0,0 +1,182 @@ | |||
1 | using System; | ||
2 | using System.IO; | ||
3 | using System.Reflection; | ||
4 | using System.Net; | ||
5 | using System.Text; | ||
6 | |||
7 | using OpenSim.Server.Base; | ||
8 | using OpenSim.Services.Interfaces; | ||
9 | using OpenSim.Framework; | ||
10 | using OpenSim.Framework.Servers.HttpServer; | ||
11 | |||
12 | using OpenMetaverse; | ||
13 | using OpenMetaverse.StructuredData; | ||
14 | using Nini.Config; | ||
15 | using log4net; | ||
16 | |||
17 | |||
18 | namespace OpenSim.Server.Handlers.Simulation | ||
19 | { | ||
20 | public class AgentGetHandler : BaseStreamHandler | ||
21 | { | ||
22 | private ISimulationService m_SimulationService; | ||
23 | private IAuthenticationService m_AuthenticationService; | ||
24 | |||
25 | public AgentGetHandler(ISimulationService service, IAuthenticationService authentication) : | ||
26 | base("GET", "/agent") | ||
27 | { | ||
28 | m_SimulationService = service; | ||
29 | m_AuthenticationService = authentication; | ||
30 | } | ||
31 | |||
32 | public override byte[] Handle(string path, Stream request, | ||
33 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
34 | { | ||
35 | // Not implemented yet | ||
36 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
37 | return new byte[] { }; | ||
38 | } | ||
39 | } | ||
40 | |||
41 | public class AgentPostHandler : BaseStreamHandler | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | private ISimulationService m_SimulationService; | ||
45 | private IAuthenticationService m_AuthenticationService; | ||
46 | private bool m_AllowForeignGuests; | ||
47 | |||
48 | public AgentPostHandler(ISimulationService service, IAuthenticationService authentication, bool foreignGuests) : | ||
49 | base("POST", "/agent") | ||
50 | { | ||
51 | m_SimulationService = service; | ||
52 | m_AuthenticationService = authentication; | ||
53 | m_AllowForeignGuests = foreignGuests; | ||
54 | } | ||
55 | |||
56 | public override byte[] Handle(string path, Stream request, | ||
57 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
58 | { | ||
59 | byte[] result = new byte[0]; | ||
60 | |||
61 | UUID agentID; | ||
62 | string action; | ||
63 | ulong regionHandle; | ||
64 | if (!Utils.GetParams(path, out agentID, out regionHandle, out action)) | ||
65 | { | ||
66 | m_log.InfoFormat("[AgentPostHandler]: Invalid parameters for agent message {0}", path); | ||
67 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
68 | httpResponse.StatusDescription = "Invalid parameters for agent message " + path; | ||
69 | |||
70 | return result; | ||
71 | } | ||
72 | |||
73 | if (m_AuthenticationService != null) | ||
74 | { | ||
75 | // Authentication | ||
76 | string authority = string.Empty; | ||
77 | string authToken = string.Empty; | ||
78 | if (!Utils.GetAuthentication(httpRequest, out authority, out authToken)) | ||
79 | { | ||
80 | m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path); | ||
81 | httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized; | ||
82 | return result; | ||
83 | } | ||
84 | if (!m_AuthenticationService.VerifyKey(agentID, authToken)) | ||
85 | { | ||
86 | m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path); | ||
87 | httpResponse.StatusCode = (int)HttpStatusCode.Forbidden; | ||
88 | return result; | ||
89 | } | ||
90 | m_log.DebugFormat("[AgentPostHandler]: Authentication succeeded for {0}", agentID); | ||
91 | } | ||
92 | |||
93 | OSDMap args = Util.GetOSDMap(request, (int)httpRequest.ContentLength); | ||
94 | if (args == null) | ||
95 | { | ||
96 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
97 | httpResponse.StatusDescription = "Unable to retrieve data"; | ||
98 | m_log.DebugFormat("[AgentPostHandler]: Unable to retrieve data for post {0}", path); | ||
99 | return result; | ||
100 | } | ||
101 | |||
102 | // retrieve the regionhandle | ||
103 | ulong regionhandle = 0; | ||
104 | if (args["destination_handle"] != null) | ||
105 | UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); | ||
106 | |||
107 | AgentCircuitData aCircuit = new AgentCircuitData(); | ||
108 | try | ||
109 | { | ||
110 | aCircuit.UnpackAgentCircuitData(args); | ||
111 | } | ||
112 | catch (Exception ex) | ||
113 | { | ||
114 | m_log.InfoFormat("[AgentPostHandler]: exception on unpacking CreateAgent message {0}", ex.Message); | ||
115 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
116 | httpResponse.StatusDescription = "Problems with data deserialization"; | ||
117 | return result; | ||
118 | } | ||
119 | |||
120 | string reason = string.Empty; | ||
121 | |||
122 | // We need to clean up a few things in the user service before I can do this | ||
123 | //if (m_AllowForeignGuests) | ||
124 | // m_regionClient.AdjustUserInformation(aCircuit); | ||
125 | |||
126 | // Finally! | ||
127 | bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, out reason); | ||
128 | |||
129 | OSDMap resp = new OSDMap(1); | ||
130 | |||
131 | resp["success"] = OSD.FromBoolean(success); | ||
132 | |||
133 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
134 | |||
135 | return Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(resp)); | ||
136 | |||
137 | } | ||
138 | } | ||
139 | |||
140 | public class AgentPutHandler : BaseStreamHandler | ||
141 | { | ||
142 | private ISimulationService m_SimulationService; | ||
143 | private IAuthenticationService m_AuthenticationService; | ||
144 | |||
145 | public AgentPutHandler(ISimulationService service, IAuthenticationService authentication) : | ||
146 | base("PUT", "/agent") | ||
147 | { | ||
148 | m_SimulationService = service; | ||
149 | m_AuthenticationService = authentication; | ||
150 | } | ||
151 | |||
152 | public override byte[] Handle(string path, Stream request, | ||
153 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
154 | { | ||
155 | // Not implemented yet | ||
156 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
157 | return new byte[] { }; | ||
158 | } | ||
159 | } | ||
160 | |||
161 | public class AgentDeleteHandler : BaseStreamHandler | ||
162 | { | ||
163 | private ISimulationService m_SimulationService; | ||
164 | private IAuthenticationService m_AuthenticationService; | ||
165 | |||
166 | public AgentDeleteHandler(ISimulationService service, IAuthenticationService authentication) : | ||
167 | base("DELETE", "/agent") | ||
168 | { | ||
169 | m_SimulationService = service; | ||
170 | m_AuthenticationService = authentication; | ||
171 | } | ||
172 | |||
173 | public override byte[] Handle(string path, Stream request, | ||
174 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
175 | { | ||
176 | // Not implemented yet | ||
177 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
178 | return new byte[] { }; | ||
179 | } | ||
180 | } | ||
181 | |||
182 | } | ||
diff --git a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs new file mode 100644 index 0000000..80b22b0 --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs | |||
@@ -0,0 +1,53 @@ | |||
1 | using System; | ||
2 | using Nini.Config; | ||
3 | using OpenSim.Server.Base; | ||
4 | using OpenSim.Services.Interfaces; | ||
5 | using OpenSim.Framework; | ||
6 | using OpenSim.Framework.Servers.HttpServer; | ||
7 | using OpenSim.Server.Handlers.Base; | ||
8 | |||
9 | namespace OpenSim.Server.Handlers.Simulation | ||
10 | { | ||
11 | public class SimulationServiceInConnector : ServiceConnector | ||
12 | { | ||
13 | private ISimulationService m_SimulationService; | ||
14 | private IAuthenticationService m_AuthenticationService; | ||
15 | |||
16 | public SimulationServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) : | ||
17 | base(config, server) | ||
18 | { | ||
19 | IConfig serverConfig = config.Configs["SimulationService"]; | ||
20 | if (serverConfig == null) | ||
21 | throw new Exception("No section 'SimulationService' in config file"); | ||
22 | |||
23 | bool authentication = serverConfig.GetBoolean("RequireAuthentication", false); | ||
24 | |||
25 | if (authentication) | ||
26 | m_AuthenticationService = scene.RequestModuleInterface<IAuthenticationService>(); | ||
27 | |||
28 | bool foreignGuests = serverConfig.GetBoolean("AllowForeignGuests", false); | ||
29 | |||
30 | //string simService = serverConfig.GetString("LocalServiceModule", | ||
31 | // String.Empty); | ||
32 | |||
33 | //if (simService == String.Empty) | ||
34 | // throw new Exception("No SimulationService in config file"); | ||
35 | |||
36 | //Object[] args = new Object[] { config }; | ||
37 | m_SimulationService = scene.RequestModuleInterface<ISimulationService>(); | ||
38 | //ServerUtils.LoadPlugin<ISimulationService>(simService, args); | ||
39 | if (m_SimulationService == null) | ||
40 | throw new Exception("No Local ISimulationService Module"); | ||
41 | |||
42 | |||
43 | |||
44 | //System.Console.WriteLine("XXXXXXXXXXXXXXXXXXX m_AssetSetvice == null? " + ((m_AssetService == null) ? "yes" : "no")); | ||
45 | server.AddStreamHandler(new AgentGetHandler(m_SimulationService, m_AuthenticationService)); | ||
46 | server.AddStreamHandler(new AgentPostHandler(m_SimulationService, m_AuthenticationService, foreignGuests)); | ||
47 | server.AddStreamHandler(new AgentPutHandler(m_SimulationService, m_AuthenticationService)); | ||
48 | server.AddStreamHandler(new AgentDeleteHandler(m_SimulationService, m_AuthenticationService)); | ||
49 | //server.AddStreamHandler(new ObjectPostHandler(m_SimulationService, authentication)); | ||
50 | //server.AddStreamHandler(new NeighborPostHandler(m_SimulationService, authentication)); | ||
51 | } | ||
52 | } | ||
53 | } | ||
diff --git a/OpenSim/Server/Handlers/Simulation/Utils.cs b/OpenSim/Server/Handlers/Simulation/Utils.cs new file mode 100644 index 0000000..581622c --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/Utils.cs | |||
@@ -0,0 +1,70 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Net; | ||
4 | |||
5 | using OpenSim.Framework; | ||
6 | using OpenSim.Framework.Servers.HttpServer; | ||
7 | using OpenSim.Services.Interfaces; | ||
8 | using OpenMetaverse; | ||
9 | |||
10 | namespace OpenSim.Server.Handlers.Simulation | ||
11 | { | ||
12 | public class Utils | ||
13 | { | ||
14 | /// <summary> | ||
15 | /// Extract the param from an uri. | ||
16 | /// </summary> | ||
17 | /// <param name="uri">Something like this: /uuid/ or /uuid/handle/release</param> | ||
18 | /// <param name="uri">uuid on uuid field</param> | ||
19 | /// <param name="action">optional action</param> | ||
20 | public static bool GetParams(string path, out UUID uuid, out ulong regionHandle, out string action) | ||
21 | { | ||
22 | uuid = UUID.Zero; | ||
23 | action = ""; | ||
24 | regionHandle = 0; | ||
25 | |||
26 | path = path.Trim(new char[] { '/' }); | ||
27 | string[] parts = path.Split('/'); | ||
28 | if (parts.Length <= 1) | ||
29 | { | ||
30 | return false; | ||
31 | } | ||
32 | else | ||
33 | { | ||
34 | if (!UUID.TryParse(parts[0], out uuid)) | ||
35 | return false; | ||
36 | |||
37 | if (parts.Length >= 2) | ||
38 | UInt64.TryParse(parts[1], out regionHandle); | ||
39 | if (parts.Length >= 3) | ||
40 | action = parts[2]; | ||
41 | |||
42 | return true; | ||
43 | } | ||
44 | } | ||
45 | |||
46 | public static bool GetAuthentication(OSHttpRequest httpRequest, out string authority, out string authKey) | ||
47 | { | ||
48 | authority = string.Empty; | ||
49 | authKey = string.Empty; | ||
50 | |||
51 | Uri authUri; | ||
52 | |||
53 | string auth = httpRequest.Headers["authentication"]; | ||
54 | // Authentication keys look like this: | ||
55 | // http://orgrid.org:8002/<uuid> | ||
56 | if ((auth != null) && (!string.Empty.Equals(auth)) && auth != "None") | ||
57 | { | ||
58 | if (Uri.TryCreate(auth, UriKind.Absolute, out authUri)) | ||
59 | { | ||
60 | authority = authUri.Authority; | ||
61 | authKey = authUri.PathAndQuery.Trim('/'); | ||
62 | return true; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | return false; | ||
67 | } | ||
68 | |||
69 | } | ||
70 | } | ||