diff options
Diffstat (limited to 'OpenSim/Server/Handlers/Simulation/AgentHandlers.cs')
-rw-r--r-- | OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | 354 |
1 files changed, 246 insertions, 108 deletions
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs index 3da72c7..ab3250d 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,113 @@ 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; |
120 | } | 110 | } |
111 | else | ||
112 | { | ||
113 | m_log.InfoFormat("[AGENT HANDLER]: method {0} not supported in agent message", method); | ||
114 | responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; | ||
115 | responsedata["str_response_string"] = "Method not allowed"; | ||
116 | |||
117 | return responsedata; | ||
118 | } | ||
119 | |||
120 | } | ||
121 | 121 | ||
122 | OSDMap args = Util.GetOSDMap(request, (int)httpRequest.ContentLength); | 122 | protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) |
123 | { | ||
124 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
123 | if (args == null) | 125 | if (args == null) |
124 | { | 126 | { |
125 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | 127 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; |
126 | httpResponse.StatusDescription = "Unable to retrieve data"; | 128 | responsedata["str_response_string"] = "Bad request"; |
127 | m_log.DebugFormat("[AgentPostHandler]: Unable to retrieve data for post {0}", path); | 129 | return; |
128 | return result; | ||
129 | } | 130 | } |
130 | 131 | ||
131 | // retrieve the regionhandle | 132 | // retrieve the input arguments |
132 | ulong regionhandle = 0; | 133 | int x = 0, y = 0; |
133 | if (args["destination_handle"] != null) | 134 | UUID uuid = UUID.Zero; |
134 | UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); | 135 | string regionname = string.Empty; |
136 | uint teleportFlags = 0; | ||
137 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
138 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
139 | else | ||
140 | m_log.WarnFormat(" -- request didn't have destination_x"); | ||
141 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
142 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
143 | else | ||
144 | m_log.WarnFormat(" -- request didn't have destination_y"); | ||
145 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
146 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
147 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
148 | regionname = args["destination_name"].ToString(); | ||
149 | if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null) | ||
150 | teleportFlags = args["teleport_flags"].AsUInteger(); | ||
151 | |||
152 | GridRegion destination = new GridRegion(); | ||
153 | destination.RegionID = uuid; | ||
154 | destination.RegionLocX = x; | ||
155 | destination.RegionLocY = y; | ||
156 | destination.RegionName = regionname; | ||
135 | 157 | ||
136 | AgentCircuitData aCircuit = new AgentCircuitData(); | 158 | AgentCircuitData aCircuit = new AgentCircuitData(); |
137 | try | 159 | try |
@@ -140,70 +162,186 @@ namespace OpenSim.Server.Handlers.Simulation | |||
140 | } | 162 | } |
141 | catch (Exception ex) | 163 | catch (Exception ex) |
142 | { | 164 | { |
143 | m_log.InfoFormat("[AgentPostHandler]: exception on unpacking CreateAgent message {0}", ex.Message); | 165 | m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message); |
144 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | 166 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; |
145 | httpResponse.StatusDescription = "Problems with data deserialization"; | 167 | responsedata["str_response_string"] = "Bad request"; |
146 | return result; | 168 | return; |
147 | } | 169 | } |
148 | 170 | ||
149 | string reason = string.Empty; | 171 | OSDMap resp = new OSDMap(2); |
172 | string reason = String.Empty; | ||
150 | 173 | ||
151 | // We need to clean up a few things in the user service before I can do this | 174 | // This is the meaning of POST agent |
152 | //if (m_AllowForeignGuests) | 175 | //m_regionClient.AdjustUserInformation(aCircuit); |
153 | // m_regionClient.AdjustUserInformation(aCircuit); | 176 | //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); |
177 | bool result = CreateAgent(destination, aCircuit, teleportFlags, out reason); | ||
154 | 178 | ||
155 | // Finally! | 179 | resp["reason"] = OSD.FromString(reason); |
156 | bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, out reason); | 180 | resp["success"] = OSD.FromBoolean(result); |
157 | 181 | ||
158 | OSDMap resp = new OSDMap(1); | 182 | // TODO: add reason if not String.Empty? |
183 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
184 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); | ||
185 | } | ||
159 | 186 | ||
160 | resp["success"] = OSD.FromBoolean(success); | 187 | // subclasses can override this |
188 | protected virtual bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) | ||
189 | { | ||
190 | return m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); | ||
191 | } | ||
161 | 192 | ||
162 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | 193 | protected void DoAgentPut(Hashtable request, Hashtable responsedata) |
194 | { | ||
195 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
196 | if (args == null) | ||
197 | { | ||
198 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
199 | responsedata["str_response_string"] = "Bad request"; | ||
200 | return; | ||
201 | } | ||
163 | 202 | ||
164 | return Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp)); | 203 | // retrieve the input arguments |
165 | } | 204 | int x = 0, y = 0; |
166 | } | 205 | UUID uuid = UUID.Zero; |
206 | string regionname = string.Empty; | ||
207 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
208 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
209 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
210 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
211 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
212 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
213 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
214 | regionname = args["destination_name"].ToString(); | ||
167 | 215 | ||
168 | public class AgentPutHandler : BaseStreamHandler | 216 | GridRegion destination = new GridRegion(); |
169 | { | 217 | destination.RegionID = uuid; |
170 | // TODO: unused: private ISimulationService m_SimulationService; | 218 | destination.RegionLocX = x; |
171 | // TODO: unused: private IAuthenticationService m_AuthenticationService; | 219 | destination.RegionLocY = y; |
220 | destination.RegionName = regionname; | ||
172 | 221 | ||
173 | public AgentPutHandler(ISimulationService service, IAuthenticationService authentication) : | 222 | string messageType; |
174 | base("PUT", "/agent") | 223 | if (args["message_type"] != null) |
175 | { | 224 | messageType = args["message_type"].AsString(); |
176 | // TODO: unused: m_SimulationService = service; | 225 | else |
177 | // TODO: unused: m_AuthenticationService = authentication; | 226 | { |
227 | m_log.Warn("[AGENT HANDLER]: Agent Put Message Type not found. "); | ||
228 | messageType = "AgentData"; | ||
229 | } | ||
230 | |||
231 | bool result = true; | ||
232 | if ("AgentData".Equals(messageType)) | ||
233 | { | ||
234 | AgentData agent = new AgentData(); | ||
235 | try | ||
236 | { | ||
237 | agent.Unpack(args); | ||
238 | } | ||
239 | catch (Exception ex) | ||
240 | { | ||
241 | m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); | ||
242 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
243 | responsedata["str_response_string"] = "Bad request"; | ||
244 | return; | ||
245 | } | ||
246 | |||
247 | //agent.Dump(); | ||
248 | // This is one of the meanings of PUT agent | ||
249 | result = UpdateAgent(destination, agent); | ||
250 | |||
251 | } | ||
252 | else if ("AgentPosition".Equals(messageType)) | ||
253 | { | ||
254 | AgentPosition agent = new AgentPosition(); | ||
255 | try | ||
256 | { | ||
257 | agent.Unpack(args); | ||
258 | } | ||
259 | catch (Exception ex) | ||
260 | { | ||
261 | m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); | ||
262 | return; | ||
263 | } | ||
264 | //agent.Dump(); | ||
265 | // This is one of the meanings of PUT agent | ||
266 | result = m_SimulationService.UpdateAgent(destination, agent); | ||
267 | |||
268 | } | ||
269 | |||
270 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
271 | responsedata["str_response_string"] = result.ToString(); | ||
272 | //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead | ||
178 | } | 273 | } |
179 | 274 | ||
180 | public override byte[] Handle(string path, Stream request, | 275 | // subclasses cab override this |
181 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | 276 | protected virtual bool UpdateAgent(GridRegion destination, AgentData agent) |
182 | { | 277 | { |
183 | // Not implemented yet | 278 | return m_SimulationService.UpdateAgent(destination, agent); |
184 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
185 | return new byte[] { }; | ||
186 | } | 279 | } |
187 | } | ||
188 | 280 | ||
189 | public class AgentDeleteHandler : BaseStreamHandler | 281 | protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, UUID regionID) |
190 | { | 282 | { |
191 | // TODO: unused: private ISimulationService m_SimulationService; | 283 | GridRegion destination = new GridRegion(); |
192 | // TODO: unused: private IAuthenticationService m_AuthenticationService; | 284 | destination.RegionID = regionID; |
285 | |||
286 | IAgentData agent = null; | ||
287 | bool result = m_SimulationService.RetrieveAgent(destination, id, out agent); | ||
288 | OSDMap map = null; | ||
289 | if (result) | ||
290 | { | ||
291 | if (agent != null) // just to make sure | ||
292 | { | ||
293 | map = agent.Pack(); | ||
294 | string strBuffer = ""; | ||
295 | try | ||
296 | { | ||
297 | strBuffer = OSDParser.SerializeJsonString(map); | ||
298 | } | ||
299 | catch (Exception e) | ||
300 | { | ||
301 | m_log.WarnFormat("[AGENT HANDLER]: Exception thrown on serialization of DoAgentGet: {0}", e.Message); | ||
302 | responsedata["int_response_code"] = HttpStatusCode.InternalServerError; | ||
303 | // ignore. buffer will be empty, caller should check. | ||
304 | } | ||
305 | |||
306 | responsedata["content_type"] = "application/json"; | ||
307 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
308 | responsedata["str_response_string"] = strBuffer; | ||
309 | } | ||
310 | else | ||
311 | { | ||
312 | responsedata["int_response_code"] = HttpStatusCode.InternalServerError; | ||
313 | responsedata["str_response_string"] = "Internal error"; | ||
314 | } | ||
315 | } | ||
316 | else | ||
317 | { | ||
318 | responsedata["int_response_code"] = HttpStatusCode.NotFound; | ||
319 | responsedata["str_response_string"] = "Not Found"; | ||
320 | } | ||
321 | } | ||
193 | 322 | ||
194 | public AgentDeleteHandler(ISimulationService service, IAuthenticationService authentication) : | 323 | protected void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID) |
195 | base("DELETE", "/agent") | ||
196 | { | 324 | { |
197 | // TODO: unused: m_SimulationService = service; | 325 | m_log.Debug(" >>> DoDelete action:" + action + "; RegionID:" + regionID); |
198 | // TODO: unused: m_AuthenticationService = authentication; | 326 | |
327 | GridRegion destination = new GridRegion(); | ||
328 | destination.RegionID = regionID; | ||
329 | |||
330 | if (action.Equals("release")) | ||
331 | ReleaseAgent(regionID, id); | ||
332 | else | ||
333 | m_SimulationService.CloseAgent(destination, id); | ||
334 | |||
335 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
336 | responsedata["str_response_string"] = "OpenSim agent " + id.ToString(); | ||
337 | |||
338 | m_log.Debug("[AGENT HANDLER]: Agent Released/Deleted."); | ||
199 | } | 339 | } |
200 | 340 | ||
201 | public override byte[] Handle(string path, Stream request, | 341 | protected virtual void ReleaseAgent(UUID regionID, UUID id) |
202 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
203 | { | 342 | { |
204 | // Not implemented yet | 343 | m_SimulationService.ReleaseAgent(regionID, id, ""); |
205 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
206 | return new byte[] { }; | ||
207 | } | 344 | } |
208 | } | 345 | } |
346 | |||
209 | } | 347 | } |