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