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.cs338
-rw-r--r--OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs229
-rw-r--r--OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs33
-rw-r--r--OpenSim/Server/Handlers/Simulation/Utils.cs103
4 files changed, 572 insertions, 131 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}
diff --git a/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs
new file mode 100644
index 0000000..995a3c4
--- /dev/null
+++ b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs
@@ -0,0 +1,229 @@
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(ISimulationService sim)
56 {
57 m_SimulationService = sim;
58 }
59
60 public Hashtable Handler(Hashtable request)
61 {
62 m_log.Debug("[CONNECTION DEBUGGING]: ObjectHandler Called");
63
64 m_log.Debug("---------------------------");
65 m_log.Debug(" >> uri=" + request["uri"]);
66 m_log.Debug(" >> content-type=" + request["content-type"]);
67 m_log.Debug(" >> http-method=" + request["http-method"]);
68 m_log.Debug("---------------------------\n");
69
70 Hashtable responsedata = new Hashtable();
71 responsedata["content_type"] = "text/html";
72
73 UUID objectID;
74 UUID regionID;
75 string action;
76 if (!Utils.GetParams((string)request["uri"], out objectID, out regionID, out action))
77 {
78 m_log.InfoFormat("[REST COMMS]: Invalid parameters for object message {0}", request["uri"]);
79 responsedata["int_response_code"] = 404;
80 responsedata["str_response_string"] = "false";
81
82 return responsedata;
83 }
84
85 // Next, let's parse the verb
86 string method = (string)request["http-method"];
87 if (method.Equals("POST"))
88 {
89 DoObjectPost(request, responsedata, regionID);
90 return responsedata;
91 }
92 else if (method.Equals("PUT"))
93 {
94 DoObjectPut(request, responsedata, regionID);
95 return responsedata;
96 }
97 //else if (method.Equals("DELETE"))
98 //{
99 // DoObjectDelete(request, responsedata, agentID, action, regionHandle);
100 // return responsedata;
101 //}
102 else
103 {
104 m_log.InfoFormat("[REST COMMS]: method {0} not supported in object message", method);
105 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
106 responsedata["str_response_string"] = "Mthod not allowed";
107
108 return responsedata;
109 }
110
111 }
112
113 protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, UUID regionID)
114 {
115 OSDMap args = Utils.GetOSDMap((string)request["body"]);
116 if (args == null)
117 {
118 responsedata["int_response_code"] = 400;
119 responsedata["str_response_string"] = "false";
120 return;
121 }
122 // retrieve the input arguments
123 int x = 0, y = 0;
124 UUID uuid = UUID.Zero;
125 string regionname = string.Empty;
126 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
127 Int32.TryParse(args["destination_x"].AsString(), out x);
128 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
129 Int32.TryParse(args["destination_y"].AsString(), out y);
130 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
131 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
132 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
133 regionname = args["destination_name"].ToString();
134
135 GridRegion destination = new GridRegion();
136 destination.RegionID = uuid;
137 destination.RegionLocX = x;
138 destination.RegionLocY = y;
139 destination.RegionName = regionname;
140
141 string sogXmlStr = "", extraStr = "", stateXmlStr = "";
142 if (args.ContainsKey("sog") && args["sog"] != null)
143 sogXmlStr = args["sog"].AsString();
144 if (args.ContainsKey("extra") && args["extra"] != null)
145 extraStr = args["extra"].AsString();
146
147 IScene s = m_SimulationService.GetScene(destination.RegionHandle);
148 ISceneObject sog = null;
149 try
150 {
151 //sog = SceneObjectSerializer.FromXml2Format(sogXmlStr);
152 sog = s.DeserializeObject(sogXmlStr);
153 sog.ExtraFromXmlString(extraStr);
154 }
155 catch (Exception ex)
156 {
157 m_log.InfoFormat("[REST COMMS]: exception on deserializing scene object {0}", ex.Message);
158 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
159 responsedata["str_response_string"] = "Bad request";
160 return;
161 }
162
163 if ((args["state"] != null) && s.AllowScriptCrossings)
164 {
165 stateXmlStr = args["state"].AsString();
166 if (stateXmlStr != "")
167 {
168 try
169 {
170 sog.SetState(stateXmlStr, s);
171 }
172 catch (Exception ex)
173 {
174 m_log.InfoFormat("[REST COMMS]: exception on setting state for scene object {0}", ex.Message);
175 // ignore and continue
176 }
177 }
178 }
179 // This is the meaning of POST object
180 bool result = m_SimulationService.CreateObject(destination, sog, false);
181
182 responsedata["int_response_code"] = HttpStatusCode.OK;
183 responsedata["str_response_string"] = result.ToString();
184 }
185
186 protected virtual void DoObjectPut(Hashtable request, Hashtable responsedata, UUID regionID)
187 {
188 OSDMap args = Utils.GetOSDMap((string)request["body"]);
189 if (args == null)
190 {
191 responsedata["int_response_code"] = 400;
192 responsedata["str_response_string"] = "false";
193 return;
194 }
195
196 // retrieve the input arguments
197 int x = 0, y = 0;
198 UUID uuid = UUID.Zero;
199 string regionname = string.Empty;
200 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
201 Int32.TryParse(args["destination_x"].AsString(), out x);
202 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
203 Int32.TryParse(args["destination_y"].AsString(), out y);
204 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
205 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
206 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
207 regionname = args["destination_name"].ToString();
208
209 GridRegion destination = new GridRegion();
210 destination.RegionID = uuid;
211 destination.RegionLocX = x;
212 destination.RegionLocY = y;
213 destination.RegionName = regionname;
214
215 UUID userID = UUID.Zero, itemID = UUID.Zero;
216 if (args.ContainsKey("userid") && args["userid"] != null)
217 userID = args["userid"].AsUUID();
218 if (args.ContainsKey("itemid") && args["itemid"] != null)
219 itemID = args["itemid"].AsUUID();
220
221 // This is the meaning of PUT object
222 bool result = m_SimulationService.CreateObject(destination, userID, itemID);
223
224 responsedata["int_response_code"] = 200;
225 responsedata["str_response_string"] = result.ToString();
226 }
227
228 }
229} \ 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}