aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs')
-rw-r--r--OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs229
1 files changed, 229 insertions, 0 deletions
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