aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Simulation
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/Simulation')
-rw-r--r--OpenSim/Server/Handlers/Simulation/AgentHandlers.cs354
-rw-r--r--OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs246
-rw-r--r--OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs33
-rw-r--r--OpenSim/Server/Handlers/Simulation/Utils.cs103
4 files changed, 607 insertions, 129 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
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,113 @@ 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;
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}
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..55a575c 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,18 @@ 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>();
65 //ServerUtils.LoadPlugin<ISimulationService>(simService, args); 58 //ServerUtils.LoadPlugin<ISimulationService>(simService, args);
66 if (m_SimulationService == null)
67 throw new Exception("No Local ISimulationService Module");
68
69
70 59
71 //System.Console.WriteLine("XXXXXXXXXXXXXXXXXXX m_AssetSetvice == null? " + ((m_AssetService == null) ? "yes" : "no")); 60 //System.Console.WriteLine("XXXXXXXXXXXXXXXXXXX m_AssetSetvice == null? " + ((m_AssetService == null) ? "yes" : "no"));
72 server.AddStreamHandler(new AgentGetHandler(m_SimulationService, m_AuthenticationService)); 61 //server.AddStreamHandler(new AgentGetHandler(m_SimulationService, m_AuthenticationService));
73 server.AddStreamHandler(new AgentPostHandler(m_SimulationService, m_AuthenticationService, foreignGuests)); 62 //server.AddStreamHandler(new AgentPostHandler(m_SimulationService, m_AuthenticationService));
74 server.AddStreamHandler(new AgentPutHandler(m_SimulationService, m_AuthenticationService)); 63 //server.AddStreamHandler(new AgentPutHandler(m_SimulationService, m_AuthenticationService));
75 server.AddStreamHandler(new AgentDeleteHandler(m_SimulationService, m_AuthenticationService)); 64 //server.AddStreamHandler(new AgentDeleteHandler(m_SimulationService, m_AuthenticationService));
65 server.AddHTTPHandler("/agent/", new AgentHandler(m_LocalSimulationService).Handler);
66 server.AddHTTPHandler("/object/", new ObjectHandler(m_LocalSimulationService).Handler);
67
76 //server.AddStreamHandler(new ObjectPostHandler(m_SimulationService, authentication)); 68 //server.AddStreamHandler(new ObjectPostHandler(m_SimulationService, authentication));
77 //server.AddStreamHandler(new NeighborPostHandler(m_SimulationService, authentication));
78 } 69 }
79 } 70 }
80} 71}
diff --git a/OpenSim/Server/Handlers/Simulation/Utils.cs b/OpenSim/Server/Handlers/Simulation/Utils.cs
new file mode 100644
index 0000000..ed379da
--- /dev/null
+++ b/OpenSim/Server/Handlers/Simulation/Utils.cs
@@ -0,0 +1,103 @@
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.Generic;
30using System.Reflection;
31
32using OpenMetaverse;
33using OpenMetaverse.StructuredData;
34
35using log4net;
36
37namespace OpenSim.Server.Handlers.Simulation
38{
39 public class Utils
40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 /// <summary>
44 /// Extract the param from an uri.
45 /// </summary>
46 /// <param name="uri">Something like this: /agent/uuid/ or /agent/uuid/handle/release</param>
47 /// <param name="uri">uuid on uuid field</param>
48 /// <param name="action">optional action</param>
49 public static bool GetParams(string uri, out UUID uuid, out UUID regionID, out string action)
50 {
51 uuid = UUID.Zero;
52 regionID = UUID.Zero;
53 action = "";
54
55 uri = uri.Trim(new char[] { '/' });
56 string[] parts = uri.Split('/');
57 if (parts.Length <= 1)
58 {
59 return false;
60 }
61 else
62 {
63 if (!UUID.TryParse(parts[1], out uuid))
64 return false;
65
66 if (parts.Length >= 3)
67 UUID.TryParse(parts[2], out regionID);
68 if (parts.Length >= 4)
69 action = parts[3];
70
71 return true;
72 }
73 }
74
75 public static OSDMap GetOSDMap(string data)
76 {
77 OSDMap args = null;
78 try
79 {
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 }
94 }
95 catch (Exception ex)
96 {
97 m_log.Debug("[REST COMMS]: exception on parse of REST message " + ex.Message);
98 return null;
99 }
100 }
101
102 }
103}