aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
diff options
context:
space:
mode:
authorMelanie2011-05-08 19:50:35 +0200
committerMelanie2011-05-08 19:50:35 +0200
commit763666e2d6e82dac4ae1514df8dcbe376c6f4cac (patch)
tree87a29b0a8985b73052a2a7a4f065b4eb586a97eb /OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
parentAllow attachments to track the user's camera (diff)
downloadopensim-SC_OLD-763666e2d6e82dac4ae1514df8dcbe376c6f4cac.zip
opensim-SC_OLD-763666e2d6e82dac4ae1514df8dcbe376c6f4cac.tar.gz
opensim-SC_OLD-763666e2d6e82dac4ae1514df8dcbe376c6f4cac.tar.bz2
opensim-SC_OLD-763666e2d6e82dac4ae1514df8dcbe376c6f4cac.tar.xz
Enable compressed (gzip) fatpack transfers.
Diffstat (limited to 'OpenSim/Server/Handlers/Simulation/AgentHandlers.cs')
-rw-r--r--OpenSim/Server/Handlers/Simulation/AgentHandlers.cs299
1 files changed, 187 insertions, 112 deletions
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
index b51290d..55f011a 100644
--- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.IO; 30using System.IO;
31using System.IO.Compression;
31using System.Reflection; 32using System.Reflection;
32using System.Net; 33using System.Net;
33using System.Text; 34using System.Text;
@@ -53,8 +54,6 @@ namespace OpenSim.Server.Handlers.Simulation
53 54
54 private ISimulationService m_SimulationService; 55 private ISimulationService m_SimulationService;
55 56
56 protected bool m_Proxy = false;
57
58 public AgentHandler() { } 57 public AgentHandler() { }
59 58
60 public AgentHandler(ISimulationService sim) 59 public AgentHandler(ISimulationService sim)
@@ -91,16 +90,12 @@ namespace OpenSim.Server.Handlers.Simulation
91 90
92 // Next, let's parse the verb 91 // Next, let's parse the verb
93 string method = (string)request["http-method"]; 92 string method = (string)request["http-method"];
93 m_log.DebugFormat("[SIMULATION]: Got verb {0} in HTTP handler", method);
94 if (method.Equals("PUT")) 94 if (method.Equals("PUT"))
95 { 95 {
96 DoAgentPut(request, responsedata); 96 DoAgentPut(request, responsedata);
97 return responsedata; 97 return responsedata;
98 } 98 }
99 else if (method.Equals("POST"))
100 {
101 DoAgentPost(request, responsedata, agentID);
102 return responsedata;
103 }
104 else if (method.Equals("GET")) 99 else if (method.Equals("GET"))
105 { 100 {
106 DoAgentGet(request, responsedata, agentID, regionID); 101 DoAgentGet(request, responsedata, agentID, regionID);
@@ -132,111 +127,6 @@ namespace OpenSim.Server.Handlers.Simulation
132 127
133 } 128 }
134 129
135 protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
136 {
137 OSDMap args = Utils.GetOSDMap((string)request["body"]);
138 if (args == null)
139 {
140 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
141 responsedata["str_response_string"] = "Bad request";
142 return;
143 }
144
145 // retrieve the input arguments
146 int x = 0, y = 0;
147 UUID uuid = UUID.Zero;
148 string regionname = string.Empty;
149 uint teleportFlags = 0;
150 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
151 Int32.TryParse(args["destination_x"].AsString(), out x);
152 else
153 m_log.WarnFormat(" -- request didn't have destination_x");
154 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
155 Int32.TryParse(args["destination_y"].AsString(), out y);
156 else
157 m_log.WarnFormat(" -- request didn't have destination_y");
158 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
159 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
160 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
161 regionname = args["destination_name"].ToString();
162 if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
163 teleportFlags = args["teleport_flags"].AsUInteger();
164
165 GridRegion destination = new GridRegion();
166 destination.RegionID = uuid;
167 destination.RegionLocX = x;
168 destination.RegionLocY = y;
169 destination.RegionName = regionname;
170
171 AgentCircuitData aCircuit = new AgentCircuitData();
172 try
173 {
174 aCircuit.UnpackAgentCircuitData(args);
175 }
176 catch (Exception ex)
177 {
178 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
179 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
180 responsedata["str_response_string"] = "Bad request";
181 return;
182 }
183
184 OSDMap resp = new OSDMap(2);
185 string reason = String.Empty;
186
187 // This is the meaning of POST agent
188 //m_regionClient.AdjustUserInformation(aCircuit);
189 //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
190 bool result = CreateAgent(destination, aCircuit, teleportFlags, out reason);
191
192 resp["reason"] = OSD.FromString(reason);
193 resp["success"] = OSD.FromBoolean(result);
194 // Let's also send out the IP address of the caller back to the caller (HG 1.5)
195 resp["your_ip"] = OSD.FromString(GetCallerIP(request));
196
197 // TODO: add reason if not String.Empty?
198 responsedata["int_response_code"] = HttpStatusCode.OK;
199 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
200 }
201
202 private string GetCallerIP(Hashtable request)
203 {
204 if (!m_Proxy)
205 return Util.GetCallerIP(request);
206
207 // We're behind a proxy
208 Hashtable headers = (Hashtable)request["headers"];
209
210 //// DEBUG
211 //foreach (object o in headers.Keys)
212 // m_log.DebugFormat("XXX {0} = {1}", o.ToString(), (headers[o] == null? "null" : headers[o].ToString()));
213
214 string xff = "X-Forwarded-For";
215 if (headers.ContainsKey(xff.ToLower()))
216 xff = xff.ToLower();
217
218 if (!headers.ContainsKey(xff) || headers[xff] == null)
219 {
220 m_log.WarnFormat("[AGENT HANDLER]: No XFF header");
221 return Util.GetCallerIP(request);
222 }
223
224 m_log.DebugFormat("[AGENT HANDLER]: XFF is {0}", headers[xff]);
225
226 IPEndPoint ep = Util.GetClientIPFromXFF((string)headers[xff]);
227 if (ep != null)
228 return ep.Address.ToString();
229
230 // Oops
231 return Util.GetCallerIP(request);
232 }
233
234 // subclasses can override this
235 protected virtual bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason)
236 {
237 return m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
238 }
239
240 protected void DoAgentPut(Hashtable request, Hashtable responsedata) 130 protected void DoAgentPut(Hashtable request, Hashtable responsedata)
241 { 131 {
242 OSDMap args = Utils.GetOSDMap((string)request["body"]); 132 OSDMap args = Utils.GetOSDMap((string)request["body"]);
@@ -457,4 +347,189 @@ namespace OpenSim.Server.Handlers.Simulation
457 347
458 } 348 }
459 349
350 public class AgentPostHandler : BaseStreamHandler
351 {
352 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
353
354 private ISimulationService m_SimulationService;
355 protected bool m_Proxy = false;
356
357 public AgentPostHandler(ISimulationService service) :
358 base("POST", "/agent")
359 {
360 m_SimulationService = service;
361 }
362
363 public AgentPostHandler(string path) :
364 base("POST", path)
365 {
366 m_SimulationService = null;
367 }
368
369 public override byte[] Handle(string path, Stream request,
370 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
371 {
372 m_log.DebugFormat("[SIMULATION]: Stream handler called");
373
374 Hashtable keysvals = new Hashtable();
375 Hashtable headervals = new Hashtable();
376
377 string[] querystringkeys = httpRequest.QueryString.AllKeys;
378 string[] rHeaders = httpRequest.Headers.AllKeys;
379
380 keysvals.Add("uri", httpRequest.RawUrl);
381 keysvals.Add("content-type", httpRequest.ContentType);
382 keysvals.Add("http-method", httpRequest.HttpMethod);
383
384 foreach (string queryname in querystringkeys)
385 keysvals.Add(queryname, httpRequest.QueryString[queryname]);
386
387 foreach (string headername in rHeaders)
388 headervals[headername] = httpRequest.Headers[headername];
389
390 keysvals.Add("headers", headervals);
391 keysvals.Add("querystringkeys", querystringkeys);
392
393 Stream inputStream;
394 if (httpRequest.ContentType == "application/x-gzip")
395 inputStream = new GZipStream(request, CompressionMode.Decompress);
396 else
397 inputStream = request;
398
399 Encoding encoding = Encoding.UTF8;
400 StreamReader reader = new StreamReader(inputStream, encoding);
401
402 string requestBody = reader.ReadToEnd();
403 keysvals.Add("body", requestBody);
404
405 httpResponse.StatusCode = 200;
406 httpResponse.ContentType = "text/html";
407 httpResponse.KeepAlive = false;
408
409 Hashtable responsedata = new Hashtable();
410
411 UUID agentID;
412 UUID regionID;
413 string action;
414
415 if (!Utils.GetParams((string)keysvals["uri"], out agentID, out regionID, out action))
416 {
417 m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", keysvals["uri"]);
418
419 httpResponse.StatusCode = 404;
420
421 return encoding.GetBytes("false");
422 }
423
424 DoAgentPost(keysvals, responsedata, agentID);
425
426 httpResponse.StatusCode = (int)responsedata["int_response_code"];
427 return encoding.GetBytes((string)responsedata["str_response_string"]);
428 }
429
430 protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
431 {
432 OSDMap args = Utils.GetOSDMap((string)request["body"]);
433 if (args == null)
434 {
435 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
436 responsedata["str_response_string"] = "Bad request";
437 return;
438 }
439
440 // retrieve the input arguments
441 int x = 0, y = 0;
442 UUID uuid = UUID.Zero;
443 string regionname = string.Empty;
444 uint teleportFlags = 0;
445 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
446 Int32.TryParse(args["destination_x"].AsString(), out x);
447 else
448 m_log.WarnFormat(" -- request didn't have destination_x");
449 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
450 Int32.TryParse(args["destination_y"].AsString(), out y);
451 else
452 m_log.WarnFormat(" -- request didn't have destination_y");
453 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
454 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
455 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
456 regionname = args["destination_name"].ToString();
457 if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
458 teleportFlags = args["teleport_flags"].AsUInteger();
459
460 GridRegion destination = new GridRegion();
461 destination.RegionID = uuid;
462 destination.RegionLocX = x;
463 destination.RegionLocY = y;
464 destination.RegionName = regionname;
465
466 AgentCircuitData aCircuit = new AgentCircuitData();
467 try
468 {
469 aCircuit.UnpackAgentCircuitData(args);
470 }
471 catch (Exception ex)
472 {
473 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
474 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
475 responsedata["str_response_string"] = "Bad request";
476 return;
477 }
478
479 OSDMap resp = new OSDMap(2);
480 string reason = String.Empty;
481
482 // This is the meaning of POST agent
483 //m_regionClient.AdjustUserInformation(aCircuit);
484 //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
485 bool result = CreateAgent(destination, aCircuit, teleportFlags, out reason);
486
487 resp["reason"] = OSD.FromString(reason);
488 resp["success"] = OSD.FromBoolean(result);
489 // Let's also send out the IP address of the caller back to the caller (HG 1.5)
490 resp["your_ip"] = OSD.FromString(GetCallerIP(request));
491
492 // TODO: add reason if not String.Empty?
493 responsedata["int_response_code"] = HttpStatusCode.OK;
494 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
495 }
496
497 private string GetCallerIP(Hashtable request)
498 {
499 if (!m_Proxy)
500 return Util.GetCallerIP(request);
501
502 // We're behind a proxy
503 Hashtable headers = (Hashtable)request["headers"];
504
505 //// DEBUG
506 //foreach (object o in headers.Keys)
507 // m_log.DebugFormat("XXX {0} = {1}", o.ToString(), (headers[o] == null? "null" : headers[o].ToString()));
508
509 string xff = "X-Forwarded-For";
510 if (headers.ContainsKey(xff.ToLower()))
511 xff = xff.ToLower();
512
513 if (!headers.ContainsKey(xff) || headers[xff] == null)
514 {
515 m_log.WarnFormat("[AGENT HANDLER]: No XFF header");
516 return Util.GetCallerIP(request);
517 }
518
519 m_log.DebugFormat("[AGENT HANDLER]: XFF is {0}", headers[xff]);
520
521 IPEndPoint ep = Util.GetClientIPFromXFF((string)headers[xff]);
522 if (ep != null)
523 return ep.Address.ToString();
524
525 // Oops
526 return Util.GetCallerIP(request);
527 }
528
529 // subclasses can override this
530 protected virtual bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason)
531 {
532 return m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
533 }
534 }
460} 535}