diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | 375 |
1 files changed, 268 insertions, 107 deletions
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs index 3da72c7..b648e12 100644 --- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs +++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | ||
29 | using System.IO; | 30 | using System.IO; |
30 | using System.Reflection; | 31 | using System.Reflection; |
31 | using System.Net; | 32 | using System.Net; |
@@ -34,6 +35,7 @@ using System.Text; | |||
34 | using OpenSim.Server.Base; | 35 | using OpenSim.Server.Base; |
35 | using OpenSim.Server.Handlers.Base; | 36 | using OpenSim.Server.Handlers.Base; |
36 | using OpenSim.Services.Interfaces; | 37 | using OpenSim.Services.Interfaces; |
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
37 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
38 | using OpenSim.Framework.Servers.HttpServer; | 40 | using OpenSim.Framework.Servers.HttpServer; |
39 | 41 | ||
@@ -45,93 +47,118 @@ using log4net; | |||
45 | 47 | ||
46 | namespace OpenSim.Server.Handlers.Simulation | 48 | namespace OpenSim.Server.Handlers.Simulation |
47 | { | 49 | { |
48 | public class AgentGetHandler : BaseStreamHandler | 50 | public class AgentHandler |
49 | { | 51 | { |
50 | // TODO: unused: private ISimulationService m_SimulationService; | 52 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
51 | // TODO: unused: private IAuthenticationService m_AuthenticationService; | 53 | private ISimulationService m_SimulationService; |
54 | |||
55 | public AgentHandler() { } | ||
52 | 56 | ||
53 | public AgentGetHandler(ISimulationService service, IAuthenticationService authentication) : | 57 | public AgentHandler(ISimulationService sim) |
54 | base("GET", "/agent") | ||
55 | { | 58 | { |
56 | // TODO: unused: m_SimulationService = service; | 59 | m_SimulationService = sim; |
57 | // TODO: unused: m_AuthenticationService = authentication; | ||
58 | } | 60 | } |
59 | 61 | ||
60 | public override byte[] Handle(string path, Stream request, | 62 | public Hashtable Handler(Hashtable request) |
61 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
62 | { | 63 | { |
63 | // Not implemented yet | 64 | m_log.Debug("[CONNECTION DEBUGGING]: AgentHandler Called"); |
64 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
65 | return new byte[] { }; | ||
66 | } | ||
67 | } | ||
68 | 65 | ||
69 | public class AgentPostHandler : BaseStreamHandler | 66 | m_log.Debug("---------------------------"); |
70 | { | 67 | m_log.Debug(" >> uri=" + request["uri"]); |
71 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 68 | m_log.Debug(" >> content-type=" + request["content-type"]); |
72 | private ISimulationService m_SimulationService; | 69 | m_log.Debug(" >> http-method=" + request["http-method"]); |
73 | private IAuthenticationService m_AuthenticationService; | 70 | m_log.Debug("---------------------------\n"); |
74 | // TODO: unused: private bool m_AllowForeignGuests; | ||
75 | 71 | ||
76 | public AgentPostHandler(ISimulationService service, IAuthenticationService authentication, bool foreignGuests) : | 72 | Hashtable responsedata = new Hashtable(); |
77 | base("POST", "/agent") | 73 | responsedata["content_type"] = "text/html"; |
78 | { | 74 | responsedata["keepalive"] = false; |
79 | m_SimulationService = service; | ||
80 | m_AuthenticationService = authentication; | ||
81 | // TODO: unused: m_AllowForeignGuests = foreignGuests; | ||
82 | } | ||
83 | 75 | ||
84 | public override byte[] Handle(string path, Stream request, | ||
85 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
86 | { | ||
87 | byte[] result = new byte[0]; | ||
88 | 76 | ||
89 | UUID agentID; | 77 | UUID agentID; |
78 | UUID regionID; | ||
90 | string action; | 79 | string action; |
91 | ulong regionHandle; | 80 | if (!Utils.GetParams((string)request["uri"], out agentID, out regionID, out action)) |
92 | if (!RestHandlerUtils.GetParams(path, out agentID, out regionHandle, out action)) | ||
93 | { | 81 | { |
94 | m_log.InfoFormat("[AgentPostHandler]: Invalid parameters for agent message {0}", path); | 82 | m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]); |
95 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | 83 | responsedata["int_response_code"] = 404; |
96 | httpResponse.StatusDescription = "Invalid parameters for agent message " + path; | 84 | responsedata["str_response_string"] = "false"; |
97 | 85 | ||
98 | return result; | 86 | return responsedata; |
99 | } | 87 | } |
100 | 88 | ||
101 | if (m_AuthenticationService != null) | 89 | // Next, let's parse the verb |
90 | string method = (string)request["http-method"]; | ||
91 | if (method.Equals("PUT")) | ||
102 | { | 92 | { |
103 | // Authentication | 93 | DoAgentPut(request, responsedata); |
104 | string authority = string.Empty; | 94 | return responsedata; |
105 | string authToken = string.Empty; | 95 | } |
106 | if (!RestHandlerUtils.GetAuthentication(httpRequest, out authority, out authToken)) | 96 | else if (method.Equals("POST")) |
107 | { | 97 | { |
108 | m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path); | 98 | DoAgentPost(request, responsedata, agentID); |
109 | httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized; | 99 | return responsedata; |
110 | return result; | 100 | } |
111 | } | 101 | else if (method.Equals("GET")) |
112 | // TODO: Rethink this | 102 | { |
113 | //if (!m_AuthenticationService.VerifyKey(agentID, authToken)) | 103 | DoAgentGet(request, responsedata, agentID, regionID); |
114 | //{ | 104 | return responsedata; |
115 | // m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path); | 105 | } |
116 | // httpResponse.StatusCode = (int)HttpStatusCode.Forbidden; | 106 | else if (method.Equals("DELETE")) |
117 | // return result; | 107 | { |
118 | //} | 108 | DoAgentDelete(request, responsedata, agentID, action, regionID); |
119 | m_log.DebugFormat("[AgentPostHandler]: Authentication succeeded for {0}", agentID); | 109 | return responsedata; |
110 | } | ||
111 | else if (method.Equals("DELETECHILD")) | ||
112 | { | ||
113 | DoChildAgentDelete(request, responsedata, agentID, action, regionID); | ||
114 | return responsedata; | ||
120 | } | 115 | } |
116 | else | ||
117 | { | ||
118 | m_log.InfoFormat("[AGENT HANDLER]: method {0} not supported in agent message", method); | ||
119 | responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; | ||
120 | responsedata["str_response_string"] = "Method not allowed"; | ||
121 | |||
122 | return responsedata; | ||
123 | } | ||
124 | |||
125 | } | ||
121 | 126 | ||
122 | OSDMap args = Util.GetOSDMap(request, (int)httpRequest.ContentLength); | 127 | protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) |
128 | { | ||
129 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
123 | if (args == null) | 130 | if (args == null) |
124 | { | 131 | { |
125 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | 132 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; |
126 | httpResponse.StatusDescription = "Unable to retrieve data"; | 133 | responsedata["str_response_string"] = "Bad request"; |
127 | m_log.DebugFormat("[AgentPostHandler]: Unable to retrieve data for post {0}", path); | 134 | return; |
128 | return result; | ||
129 | } | 135 | } |
130 | 136 | ||
131 | // retrieve the regionhandle | 137 | // retrieve the input arguments |
132 | ulong regionhandle = 0; | 138 | int x = 0, y = 0; |
133 | if (args["destination_handle"] != null) | 139 | UUID uuid = UUID.Zero; |
134 | UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); | 140 | string regionname = string.Empty; |
141 | uint teleportFlags = 0; | ||
142 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
143 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
144 | else | ||
145 | m_log.WarnFormat(" -- request didn't have destination_x"); | ||
146 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
147 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
148 | else | ||
149 | m_log.WarnFormat(" -- request didn't have destination_y"); | ||
150 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
151 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
152 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
153 | regionname = args["destination_name"].ToString(); | ||
154 | if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null) | ||
155 | teleportFlags = args["teleport_flags"].AsUInteger(); | ||
156 | |||
157 | GridRegion destination = new GridRegion(); | ||
158 | destination.RegionID = uuid; | ||
159 | destination.RegionLocX = x; | ||
160 | destination.RegionLocY = y; | ||
161 | destination.RegionName = regionname; | ||
135 | 162 | ||
136 | AgentCircuitData aCircuit = new AgentCircuitData(); | 163 | AgentCircuitData aCircuit = new AgentCircuitData(); |
137 | try | 164 | try |
@@ -140,70 +167,204 @@ namespace OpenSim.Server.Handlers.Simulation | |||
140 | } | 167 | } |
141 | catch (Exception ex) | 168 | catch (Exception ex) |
142 | { | 169 | { |
143 | m_log.InfoFormat("[AgentPostHandler]: exception on unpacking CreateAgent message {0}", ex.Message); | 170 | m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message); |
144 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | 171 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; |
145 | httpResponse.StatusDescription = "Problems with data deserialization"; | 172 | responsedata["str_response_string"] = "Bad request"; |
146 | return result; | 173 | return; |
147 | } | 174 | } |
148 | 175 | ||
149 | string reason = string.Empty; | 176 | OSDMap resp = new OSDMap(2); |
177 | string reason = String.Empty; | ||
150 | 178 | ||
151 | // We need to clean up a few things in the user service before I can do this | 179 | // This is the meaning of POST agent |
152 | //if (m_AllowForeignGuests) | 180 | //m_regionClient.AdjustUserInformation(aCircuit); |
153 | // m_regionClient.AdjustUserInformation(aCircuit); | 181 | //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); |
182 | bool result = CreateAgent(destination, aCircuit, teleportFlags, out reason); | ||
154 | 183 | ||
155 | // Finally! | 184 | resp["reason"] = OSD.FromString(reason); |
156 | bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, out reason); | 185 | resp["success"] = OSD.FromBoolean(result); |
157 | 186 | ||
158 | OSDMap resp = new OSDMap(1); | 187 | // TODO: add reason if not String.Empty? |
188 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
189 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); | ||
190 | } | ||
191 | |||
192 | // subclasses can override this | ||
193 | protected virtual bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) | ||
194 | { | ||
195 | return m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); | ||
196 | } | ||
159 | 197 | ||
160 | resp["success"] = OSD.FromBoolean(success); | 198 | protected void DoAgentPut(Hashtable request, Hashtable responsedata) |
199 | { | ||
200 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
201 | if (args == null) | ||
202 | { | ||
203 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
204 | responsedata["str_response_string"] = "Bad request"; | ||
205 | return; | ||
206 | } | ||
161 | 207 | ||
162 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | 208 | // retrieve the input arguments |
209 | int x = 0, y = 0; | ||
210 | UUID uuid = UUID.Zero; | ||
211 | string regionname = string.Empty; | ||
212 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
213 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
214 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
215 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
216 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
217 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
218 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
219 | regionname = args["destination_name"].ToString(); | ||
163 | 220 | ||
164 | return Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp)); | 221 | GridRegion destination = new GridRegion(); |
165 | } | 222 | destination.RegionID = uuid; |
166 | } | 223 | destination.RegionLocX = x; |
224 | destination.RegionLocY = y; | ||
225 | destination.RegionName = regionname; | ||
167 | 226 | ||
168 | public class AgentPutHandler : BaseStreamHandler | 227 | string messageType; |
169 | { | 228 | if (args["message_type"] != null) |
170 | // TODO: unused: private ISimulationService m_SimulationService; | 229 | messageType = args["message_type"].AsString(); |
171 | // TODO: unused: private IAuthenticationService m_AuthenticationService; | 230 | else |
231 | { | ||
232 | m_log.Warn("[AGENT HANDLER]: Agent Put Message Type not found. "); | ||
233 | messageType = "AgentData"; | ||
234 | } | ||
172 | 235 | ||
173 | public AgentPutHandler(ISimulationService service, IAuthenticationService authentication) : | 236 | bool result = true; |
174 | base("PUT", "/agent") | 237 | if ("AgentData".Equals(messageType)) |
238 | { | ||
239 | AgentData agent = new AgentData(); | ||
240 | try | ||
241 | { | ||
242 | agent.Unpack(args); | ||
243 | } | ||
244 | catch (Exception ex) | ||
245 | { | ||
246 | m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); | ||
247 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
248 | responsedata["str_response_string"] = "Bad request"; | ||
249 | return; | ||
250 | } | ||
251 | |||
252 | //agent.Dump(); | ||
253 | // This is one of the meanings of PUT agent | ||
254 | result = UpdateAgent(destination, agent); | ||
255 | |||
256 | } | ||
257 | else if ("AgentPosition".Equals(messageType)) | ||
258 | { | ||
259 | AgentPosition agent = new AgentPosition(); | ||
260 | try | ||
261 | { | ||
262 | agent.Unpack(args); | ||
263 | } | ||
264 | catch (Exception ex) | ||
265 | { | ||
266 | m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); | ||
267 | return; | ||
268 | } | ||
269 | //agent.Dump(); | ||
270 | // This is one of the meanings of PUT agent | ||
271 | result = m_SimulationService.UpdateAgent(destination, agent); | ||
272 | |||
273 | } | ||
274 | |||
275 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
276 | responsedata["str_response_string"] = result.ToString(); | ||
277 | //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead | ||
278 | } | ||
279 | |||
280 | // subclasses cab override this | ||
281 | protected virtual bool UpdateAgent(GridRegion destination, AgentData agent) | ||
175 | { | 282 | { |
176 | // TODO: unused: m_SimulationService = service; | 283 | return m_SimulationService.UpdateAgent(destination, agent); |
177 | // TODO: unused: m_AuthenticationService = authentication; | ||
178 | } | 284 | } |
179 | 285 | ||
180 | public override byte[] Handle(string path, Stream request, | 286 | protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, UUID regionID) |
181 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
182 | { | 287 | { |
183 | // Not implemented yet | 288 | GridRegion destination = new GridRegion(); |
184 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | 289 | destination.RegionID = regionID; |
185 | return new byte[] { }; | 290 | |
291 | IAgentData agent = null; | ||
292 | bool result = m_SimulationService.RetrieveAgent(destination, id, out agent); | ||
293 | OSDMap map = null; | ||
294 | if (result) | ||
295 | { | ||
296 | if (agent != null) // just to make sure | ||
297 | { | ||
298 | map = agent.Pack(); | ||
299 | string strBuffer = ""; | ||
300 | try | ||
301 | { | ||
302 | strBuffer = OSDParser.SerializeJsonString(map); | ||
303 | } | ||
304 | catch (Exception e) | ||
305 | { | ||
306 | m_log.WarnFormat("[AGENT HANDLER]: Exception thrown on serialization of DoAgentGet: {0}", e.Message); | ||
307 | responsedata["int_response_code"] = HttpStatusCode.InternalServerError; | ||
308 | // ignore. buffer will be empty, caller should check. | ||
309 | } | ||
310 | |||
311 | responsedata["content_type"] = "application/json"; | ||
312 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
313 | responsedata["str_response_string"] = strBuffer; | ||
314 | } | ||
315 | else | ||
316 | { | ||
317 | responsedata["int_response_code"] = HttpStatusCode.InternalServerError; | ||
318 | responsedata["str_response_string"] = "Internal error"; | ||
319 | } | ||
320 | } | ||
321 | else | ||
322 | { | ||
323 | responsedata["int_response_code"] = HttpStatusCode.NotFound; | ||
324 | responsedata["str_response_string"] = "Not Found"; | ||
325 | } | ||
186 | } | 326 | } |
187 | } | ||
188 | 327 | ||
189 | public class AgentDeleteHandler : BaseStreamHandler | 328 | protected void DoChildAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID) |
190 | { | 329 | { |
191 | // TODO: unused: private ISimulationService m_SimulationService; | 330 | m_log.Debug(" >>> DoChildAgentDelete action:" + action + "; RegionID:" + regionID); |
192 | // TODO: unused: private IAuthenticationService m_AuthenticationService; | ||
193 | 331 | ||
194 | public AgentDeleteHandler(ISimulationService service, IAuthenticationService authentication) : | 332 | GridRegion destination = new GridRegion(); |
195 | base("DELETE", "/agent") | 333 | destination.RegionID = regionID; |
334 | |||
335 | if (action.Equals("release")) | ||
336 | ReleaseAgent(regionID, id); | ||
337 | else | ||
338 | m_SimulationService.CloseChildAgent(destination, id); | ||
339 | |||
340 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
341 | responsedata["str_response_string"] = "OpenSim agent " + id.ToString(); | ||
342 | |||
343 | m_log.Debug("[AGENT HANDLER]: Child Agent Released/Deleted."); | ||
344 | } | ||
345 | |||
346 | protected void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID) | ||
196 | { | 347 | { |
197 | // TODO: unused: m_SimulationService = service; | 348 | m_log.Debug(" >>> DoDelete action:" + action + "; RegionID:" + regionID); |
198 | // TODO: unused: m_AuthenticationService = authentication; | 349 | |
350 | GridRegion destination = new GridRegion(); | ||
351 | destination.RegionID = regionID; | ||
352 | |||
353 | if (action.Equals("release")) | ||
354 | ReleaseAgent(regionID, id); | ||
355 | else | ||
356 | m_SimulationService.CloseAgent(destination, id); | ||
357 | |||
358 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
359 | responsedata["str_response_string"] = "OpenSim agent " + id.ToString(); | ||
360 | |||
361 | m_log.Debug("[AGENT HANDLER]: Agent Released/Deleted."); | ||
199 | } | 362 | } |
200 | 363 | ||
201 | public override byte[] Handle(string path, Stream request, | 364 | protected virtual void ReleaseAgent(UUID regionID, UUID id) |
202 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
203 | { | 365 | { |
204 | // Not implemented yet | 366 | m_SimulationService.ReleaseAgent(regionID, id, ""); |
205 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
206 | return new byte[] { }; | ||
207 | } | 367 | } |
208 | } | 368 | } |
369 | |||
209 | } | 370 | } |