aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Simulation
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Server/Handlers/Simulation/AgentHandlers.cs375
-rw-r--r--OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs246
-rw-r--r--OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs34
-rw-r--r--OpenSim/Server/Handlers/Simulation/Utils.cs (renamed from OpenSim/Data/MySQL/Tests/MySQLGridTest.cs)97
4 files changed, 580 insertions, 172 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
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,118 @@ 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;
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}
diff --git a/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs
new file mode 100644
index 0000000..33e5aa6
--- /dev/null
+++ b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs
@@ -0,0 +1,246 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.IO;
31using System.Reflection;
32using System.Net;
33using System.Text;
34
35using OpenSim.Server.Base;
36using OpenSim.Server.Handlers.Base;
37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenSim.Framework;
40using OpenSim.Framework.Servers.HttpServer;
41
42using OpenMetaverse;
43using OpenMetaverse.StructuredData;
44using Nini.Config;
45using log4net;
46
47
48namespace OpenSim.Server.Handlers.Simulation
49{
50 public class ObjectHandler
51 {
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 private ISimulationService m_SimulationService;
54
55 public ObjectHandler() { }
56
57 public ObjectHandler(ISimulationService sim)
58 {
59 m_SimulationService = sim;
60 }
61
62 public Hashtable Handler(Hashtable request)
63 {
64 //m_log.Debug("[CONNECTION DEBUGGING]: ObjectHandler Called");
65
66 //m_log.Debug("---------------------------");
67 //m_log.Debug(" >> uri=" + request["uri"]);
68 //m_log.Debug(" >> content-type=" + request["content-type"]);
69 //m_log.Debug(" >> http-method=" + request["http-method"]);
70 //m_log.Debug("---------------------------\n");
71
72 Hashtable responsedata = new Hashtable();
73 responsedata["content_type"] = "text/html";
74
75 UUID objectID;
76 UUID regionID;
77 string action;
78 if (!Utils.GetParams((string)request["uri"], out objectID, out regionID, out action))
79 {
80 m_log.InfoFormat("[OBJECT HANDLER]: Invalid parameters for object message {0}", request["uri"]);
81 responsedata["int_response_code"] = 404;
82 responsedata["str_response_string"] = "false";
83
84 return responsedata;
85 }
86
87 // Next, let's parse the verb
88 string method = (string)request["http-method"];
89 if (method.Equals("POST"))
90 {
91 DoObjectPost(request, responsedata, regionID);
92 return responsedata;
93 }
94 else if (method.Equals("PUT"))
95 {
96 DoObjectPut(request, responsedata, regionID);
97 return responsedata;
98 }
99 //else if (method.Equals("DELETE"))
100 //{
101 // DoObjectDelete(request, responsedata, agentID, action, regionHandle);
102 // return responsedata;
103 //}
104 else
105 {
106 m_log.InfoFormat("[OBJECT HANDLER]: method {0} not supported in object message", method);
107 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
108 responsedata["str_response_string"] = "Mthod not allowed";
109
110 return responsedata;
111 }
112
113 }
114
115 protected void DoObjectPost(Hashtable request, Hashtable responsedata, UUID regionID)
116 {
117 OSDMap args = Utils.GetOSDMap((string)request["body"]);
118 if (args == null)
119 {
120 responsedata["int_response_code"] = 400;
121 responsedata["str_response_string"] = "false";
122 return;
123 }
124 // retrieve the input arguments
125 int x = 0, y = 0;
126 UUID uuid = UUID.Zero;
127 string regionname = string.Empty;
128 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
129 Int32.TryParse(args["destination_x"].AsString(), out x);
130 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
131 Int32.TryParse(args["destination_y"].AsString(), out y);
132 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
133 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
134 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
135 regionname = args["destination_name"].ToString();
136
137 GridRegion destination = new GridRegion();
138 destination.RegionID = uuid;
139 destination.RegionLocX = x;
140 destination.RegionLocY = y;
141 destination.RegionName = regionname;
142
143 string sogXmlStr = "", extraStr = "", stateXmlStr = "";
144 if (args.ContainsKey("sog") && args["sog"] != null)
145 sogXmlStr = args["sog"].AsString();
146 if (args.ContainsKey("extra") && args["extra"] != null)
147 extraStr = args["extra"].AsString();
148
149 IScene s = m_SimulationService.GetScene(destination.RegionHandle);
150 ISceneObject sog = null;
151 try
152 {
153 //m_log.DebugFormat("[OBJECT HANDLER]: received {0}", sogXmlStr);
154 sog = s.DeserializeObject(sogXmlStr);
155 sog.ExtraFromXmlString(extraStr);
156 }
157 catch (Exception ex)
158 {
159 m_log.InfoFormat("[OBJECT HANDLER]: exception on deserializing scene object {0}", ex.Message);
160 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
161 responsedata["str_response_string"] = "Bad request";
162 return;
163 }
164
165 if ((args["state"] != null) && s.AllowScriptCrossings)
166 {
167 stateXmlStr = args["state"].AsString();
168 if (stateXmlStr != "")
169 {
170 try
171 {
172 sog.SetState(stateXmlStr, s);
173 }
174 catch (Exception ex)
175 {
176 m_log.InfoFormat("[OBJECT HANDLER]: exception on setting state for scene object {0}", ex.Message);
177 // ignore and continue
178 }
179 }
180 }
181
182 bool result = false;
183 try
184 {
185 // This is the meaning of POST object
186 result = CreateObject(destination, sog);
187 }
188 catch (Exception e)
189 {
190 m_log.DebugFormat("[OBJECT HANDLER]: Exception in CreateObject: {0}", e.StackTrace);
191 }
192
193 responsedata["int_response_code"] = HttpStatusCode.OK;
194 responsedata["str_response_string"] = result.ToString();
195 }
196
197 // subclasses can override this
198 protected virtual bool CreateObject(GridRegion destination, ISceneObject sog)
199 {
200 return m_SimulationService.CreateObject(destination, sog, false);
201 }
202
203 protected virtual void DoObjectPut(Hashtable request, Hashtable responsedata, UUID regionID)
204 {
205 OSDMap args = Utils.GetOSDMap((string)request["body"]);
206 if (args == null)
207 {
208 responsedata["int_response_code"] = 400;
209 responsedata["str_response_string"] = "false";
210 return;
211 }
212
213 // retrieve the input arguments
214 int x = 0, y = 0;
215 UUID uuid = UUID.Zero;
216 string regionname = string.Empty;
217 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
218 Int32.TryParse(args["destination_x"].AsString(), out x);
219 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
220 Int32.TryParse(args["destination_y"].AsString(), out y);
221 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
222 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
223 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
224 regionname = args["destination_name"].ToString();
225
226 GridRegion destination = new GridRegion();
227 destination.RegionID = uuid;
228 destination.RegionLocX = x;
229 destination.RegionLocY = y;
230 destination.RegionName = regionname;
231
232 UUID userID = UUID.Zero, itemID = UUID.Zero;
233 if (args.ContainsKey("userid") && args["userid"] != null)
234 userID = args["userid"].AsUUID();
235 if (args.ContainsKey("itemid") && args["itemid"] != null)
236 itemID = args["itemid"].AsUUID();
237
238 // This is the meaning of PUT object
239 bool result = m_SimulationService.CreateObject(destination, userID, itemID);
240
241 responsedata["int_response_code"] = 200;
242 responsedata["str_response_string"] = result.ToString();
243 }
244
245 }
246} \ No newline at end of file
diff --git a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs
index fe93fa5..50d6fb2 100644
--- a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs
+++ b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs
@@ -37,22 +37,15 @@ namespace OpenSim.Server.Handlers.Simulation
37{ 37{
38 public class SimulationServiceInConnector : ServiceConnector 38 public class SimulationServiceInConnector : ServiceConnector
39 { 39 {
40 private ISimulationService m_SimulationService; 40 private ISimulationService m_LocalSimulationService;
41 private IAuthenticationService m_AuthenticationService; 41 private IAuthenticationService m_AuthenticationService;
42 42
43 public SimulationServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) : 43 public SimulationServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) :
44 base(config, server, String.Empty) 44 base(config, server, String.Empty)
45 { 45 {
46 IConfig serverConfig = config.Configs["SimulationService"]; 46 //IConfig serverConfig = config.Configs["SimulationService"];
47 if (serverConfig == null) 47 //if (serverConfig == null)
48 throw new Exception("No section 'SimulationService' in config file"); 48 // throw new Exception("No section 'SimulationService' in config file");
49
50 bool authentication = serverConfig.GetBoolean("RequireAuthentication", false);
51
52 if (authentication)
53 m_AuthenticationService = scene.RequestModuleInterface<IAuthenticationService>();
54
55 bool foreignGuests = serverConfig.GetBoolean("AllowForeignGuests", false);
56 49
57 //string simService = serverConfig.GetString("LocalServiceModule", 50 //string simService = serverConfig.GetString("LocalServiceModule",
58 // String.Empty); 51 // String.Empty);
@@ -61,20 +54,19 @@ namespace OpenSim.Server.Handlers.Simulation
61 // throw new Exception("No SimulationService in config file"); 54 // throw new Exception("No SimulationService in config file");
62 55
63 //Object[] args = new Object[] { config }; 56 //Object[] args = new Object[] { config };
64 m_SimulationService = scene.RequestModuleInterface<ISimulationService>(); 57 m_LocalSimulationService = scene.RequestModuleInterface<ISimulationService>();
58 m_LocalSimulationService = m_LocalSimulationService.GetInnerService();
65 //ServerUtils.LoadPlugin<ISimulationService>(simService, args); 59 //ServerUtils.LoadPlugin<ISimulationService>(simService, args);
66 if (m_SimulationService == null)
67 throw new Exception("No Local ISimulationService Module");
68
69
70 60
71 //System.Console.WriteLine("XXXXXXXXXXXXXXXXXXX m_AssetSetvice == null? " + ((m_AssetService == null) ? "yes" : "no")); 61 //System.Console.WriteLine("XXXXXXXXXXXXXXXXXXX m_AssetSetvice == null? " + ((m_AssetService == null) ? "yes" : "no"));
72 server.AddStreamHandler(new AgentGetHandler(m_SimulationService, m_AuthenticationService)); 62 //server.AddStreamHandler(new AgentGetHandler(m_SimulationService, m_AuthenticationService));
73 server.AddStreamHandler(new AgentPostHandler(m_SimulationService, m_AuthenticationService, foreignGuests)); 63 //server.AddStreamHandler(new AgentPostHandler(m_SimulationService, m_AuthenticationService));
74 server.AddStreamHandler(new AgentPutHandler(m_SimulationService, m_AuthenticationService)); 64 //server.AddStreamHandler(new AgentPutHandler(m_SimulationService, m_AuthenticationService));
75 server.AddStreamHandler(new AgentDeleteHandler(m_SimulationService, m_AuthenticationService)); 65 //server.AddStreamHandler(new AgentDeleteHandler(m_SimulationService, m_AuthenticationService));
66 server.AddHTTPHandler("/agent/", new AgentHandler(m_LocalSimulationService).Handler);
67 server.AddHTTPHandler("/object/", new ObjectHandler(m_LocalSimulationService).Handler);
68
76 //server.AddStreamHandler(new ObjectPostHandler(m_SimulationService, authentication)); 69 //server.AddStreamHandler(new ObjectPostHandler(m_SimulationService, authentication));
77 //server.AddStreamHandler(new NeighborPostHandler(m_SimulationService, authentication));
78 } 70 }
79 } 71 }
80} 72}
diff --git a/OpenSim/Data/MySQL/Tests/MySQLGridTest.cs b/OpenSim/Server/Handlers/Simulation/Utils.cs
index 8272316..ed379da 100644
--- a/OpenSim/Data/MySQL/Tests/MySQLGridTest.cs
+++ b/OpenSim/Server/Handlers/Simulation/Utils.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -26,69 +26,78 @@
26 */ 26 */
27 27
28using System; 28using System;
29using NUnit.Framework; 29using System.Collections.Generic;
30using OpenSim.Data.Tests;
31using log4net;
32using System.Reflection; 30using System.Reflection;
33using OpenSim.Tests.Common;
34using MySql.Data.MySqlClient;
35 31
36namespace OpenSim.Data.MySQL.Tests 32using OpenMetaverse;
33using OpenMetaverse.StructuredData;
34
35using log4net;
36
37namespace OpenSim.Server.Handlers.Simulation
37{ 38{
38 [TestFixture, DatabaseTest] 39 public class Utils
39 public class MySQLGridTest : BasicGridTest
40 { 40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42 42
43 public string file; 43 /// <summary>
44 public MySQLManager database; 44 /// Extract the param from an uri.
45 public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; 45 /// </summary>
46 46 /// <param name="uri">Something like this: /agent/uuid/ or /agent/uuid/handle/release</param>
47 [TestFixtureSetUp] 47 /// <param name="uri">uuid on uuid field</param>
48 public void Init() 48 /// <param name="action">optional action</param>
49 public static bool GetParams(string uri, out UUID uuid, out UUID regionID, out string action)
49 { 50 {
50 SuperInit(); 51 uuid = UUID.Zero;
51 // If we manage to connect to the database with the user 52 regionID = UUID.Zero;
52 // and password above it is our test database, and run 53 action = "";
53 // these tests. If anything goes wrong, ignore these 54
54 // tests. 55 uri = uri.Trim(new char[] { '/' });
55 try 56 string[] parts = uri.Split('/');
57 if (parts.Length <= 1)
56 { 58 {
57 database = new MySQLManager(connect); 59 return false;
58 db = new MySQLGridData();
59 db.Initialise(connect);
60 } 60 }
61 catch (Exception e) 61 else
62 { 62 {
63 m_log.Error("Exception {0}", e); 63 if (!UUID.TryParse(parts[1], out uuid))
64 Assert.Ignore(); 64 return false;
65 }
66 65
67 // This actually does the roll forward assembly stuff 66 if (parts.Length >= 3)
68 Assembly assem = GetType().Assembly; 67 UUID.TryParse(parts[2], out regionID);
68 if (parts.Length >= 4)
69 action = parts[3];
69 70
70 using (MySqlConnection dbcon = new MySqlConnection(connect)) 71 return true;
71 {
72 dbcon.Open();
73 Migration m = new Migration(dbcon, assem, "AssetStore");
74 m.Update();
75 } 72 }
76 } 73 }
77 74
78 [TestFixtureTearDown] 75 public static OSDMap GetOSDMap(string data)
79 public void Cleanup()
80 { 76 {
81 m_log.Warn("Cleaning up."); 77 OSDMap args = null;
82 if (db != null) 78 try
83 { 79 {
84 db.Dispose(); 80 OSD buffer;
81 // We should pay attention to the content-type, but let's assume we know it's Json
82 buffer = OSDParser.DeserializeJson(data);
83 if (buffer.Type == OSDType.Map)
84 {
85 args = (OSDMap)buffer;
86 return args;
87 }
88 else
89 {
90 // uh?
91 m_log.Debug(("[REST COMMS]: Got OSD of unexpected type " + buffer.Type.ToString()));
92 return null;
93 }
85 } 94 }
86 // if a new table is added, it has to be dropped here 95 catch (Exception ex)
87 if (database != null)
88 { 96 {
89 database.ExecuteSql("drop table migrations"); 97 m_log.Debug("[REST COMMS]: exception on parse of REST message " + ex.Message);
90 database.ExecuteSql("drop table regions"); 98 return null;
91 } 99 }
92 } 100 }
101
93 } 102 }
94} 103}