aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
diff options
context:
space:
mode:
authorMelanie2009-09-21 18:12:12 +0100
committerMelanie2009-09-21 18:12:12 +0100
commit5511c62580c09cf98a1f2d717b478cc0f1881a6d (patch)
tree95a5d36141ee39d25eba76105a4780a9536f0e8d /OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
parentAdd a RequestID (UUID.Random()) to the PollRequest and pass it to all (diff)
parentMerge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-5511c62580c09cf98a1f2d717b478cc0f1881a6d.zip
opensim-SC_OLD-5511c62580c09cf98a1f2d717b478cc0f1881a6d.tar.gz
opensim-SC_OLD-5511c62580c09cf98a1f2d717b478cc0f1881a6d.tar.bz2
opensim-SC_OLD-5511c62580c09cf98a1f2d717b478cc0f1881a6d.tar.xz
Merge branch 'master' of ssh://melanie@opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs')
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs269
1 files changed, 269 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
new file mode 100644
index 0000000..39c0584
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
@@ -0,0 +1,269 @@
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 Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using System.Collections.Generic;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Framework;
42using OpenSim.Framework.Servers.HttpServer;
43using OpenMetaverse;
44
45namespace OpenSim.Server.Handlers.Grid
46{
47 public class GridServerPostHandler : BaseStreamHandler
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IGridService m_GridService;
52
53 public GridServerPostHandler(IGridService service) :
54 base("POST", "/grid")
55 {
56 m_GridService = service;
57 }
58
59 public override byte[] Handle(string path, Stream requestData,
60 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
61 {
62 StreamReader sr = new StreamReader(requestData);
63 string body = sr.ReadToEnd();
64 sr.Close();
65
66 Dictionary<string, string> request =
67 ServerUtils.ParseQueryString(body);
68
69 if (!request.ContainsKey("METHOD"))
70 return FailureResult();
71
72 string method = request["METHOD"];
73
74 switch (method)
75 {
76 case "register":
77 return Register(request);
78
79 case "deregister":
80 return Deregister(request);
81
82 case "get_neighbours":
83 return GetNeighbours(request);
84
85 case "get_region_by_uuid":
86 return GetRegionByUUID(request);
87
88 case "get_region_by_position":
89 return GetRegionByPosition(request);
90
91 case "get_region_by_name":
92 return GetRegionByName(request);
93
94 case "get_regions_by_name":
95 return GetRegionsByName(request);
96
97 case "get_region_range":
98 return GetRegionRange(request);
99
100 default:
101 m_log.DebugFormat("[GRID HANDLER]: unknown method request {0}", method);
102 return FailureResult();
103 }
104
105 }
106
107 #region Method-specific handlers
108
109 byte[] Register(Dictionary<string, string> request)
110 {
111 UUID scopeID = UUID.Zero;
112 if (request["SCOPEID"] != null)
113 UUID.TryParse(request["SCOPEID"], out scopeID);
114 else
115 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region");
116
117 Dictionary<string, object> rinfoData = new Dictionary<string, object>();
118 foreach (KeyValuePair<string, string> kvp in request)
119 rinfoData[kvp.Key] = kvp.Value;
120 SimpleRegionInfo rinfo = new SimpleRegionInfo(rinfoData);
121
122 bool result = m_GridService.RegisterRegion(scopeID, rinfo);
123
124 if (result)
125 return SuccessResult();
126 else
127 return FailureResult();
128 }
129
130 byte[] Deregister(Dictionary<string, string> request)
131 {
132 UUID regionID = UUID.Zero;
133 if (request["REGIONID"] != null)
134 UUID.TryParse(request["REGIONID"], out regionID);
135 else
136 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region");
137
138 bool result = m_GridService.DeregisterRegion(regionID);
139
140 if (result)
141 return SuccessResult();
142 else
143 return FailureResult();
144
145 }
146
147 byte[] GetNeighbours(Dictionary<string, string> request)
148 {
149 UUID scopeID = UUID.Zero;
150 if (request["SCOPEID"] != null)
151 UUID.TryParse(request["SCOPEID"], out scopeID);
152 else
153 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
154
155 UUID regionID = UUID.Zero;
156 if (request["REGIONID"] != null)
157 UUID.TryParse(request["REGIONID"], out scopeID);
158 else
159 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
160
161 List<SimpleRegionInfo> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
162
163 Dictionary<string, object> result = new Dictionary<string, object>();
164 int i = 0;
165 foreach (SimpleRegionInfo rinfo in rinfos)
166 {
167 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
168 result["region" + i] = rinfoDict;
169 i++;
170 }
171
172 string xmlString = ServerUtils.BuildXmlResponse(result);
173 UTF8Encoding encoding = new UTF8Encoding();
174 return encoding.GetBytes(xmlString);
175
176 }
177
178 byte[] GetRegionByUUID(Dictionary<string, string> request)
179 {
180 // TODO
181 return new byte[0];
182 }
183
184 byte[] GetRegionByPosition(Dictionary<string, string> request)
185 {
186 // TODO
187 return new byte[0];
188 }
189
190 byte[] GetRegionByName(Dictionary<string, string> request)
191 {
192 // TODO
193 return new byte[0];
194 }
195
196 byte[] GetRegionsByName(Dictionary<string, string> request)
197 {
198 // TODO
199 return new byte[0];
200 }
201
202 byte[] GetRegionRange(Dictionary<string, string> request)
203 {
204 // TODO
205 return new byte[0];
206 }
207
208 #endregion
209
210 #region Misc
211
212 private byte[] SuccessResult()
213 {
214 XmlDocument doc = new XmlDocument();
215
216 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
217 "", "");
218
219 doc.AppendChild(xmlnode);
220
221 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
222 "");
223
224 doc.AppendChild(rootElement);
225
226 XmlElement result = doc.CreateElement("", "Result", "");
227 result.AppendChild(doc.CreateTextNode("Success"));
228
229 rootElement.AppendChild(result);
230
231 return DocToBytes(doc);
232 }
233
234 private byte[] FailureResult()
235 {
236 XmlDocument doc = new XmlDocument();
237
238 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
239 "", "");
240
241 doc.AppendChild(xmlnode);
242
243 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
244 "");
245
246 doc.AppendChild(rootElement);
247
248 XmlElement result = doc.CreateElement("", "Result", "");
249 result.AppendChild(doc.CreateTextNode("Failure"));
250
251 rootElement.AppendChild(result);
252
253 return DocToBytes(doc);
254 }
255
256 private byte[] DocToBytes(XmlDocument doc)
257 {
258 MemoryStream ms = new MemoryStream();
259 XmlTextWriter xw = new XmlTextWriter(ms, null);
260 xw.Formatting = Formatting.Indented;
261 doc.WriteTo(xw);
262 xw.Flush();
263
264 return ms.GetBuffer();
265 }
266
267 #endregion
268 }
269}