diff options
author | Melanie | 2013-03-19 00:54:23 +0000 |
---|---|---|
committer | Melanie | 2013-03-19 00:54:23 +0000 |
commit | 5b950ca36aa6596cdd7a35f23654544e303635c2 (patch) | |
tree | 30999d20ac5abf29b65a25c85e392d3fec38f80b /OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs | |
parent | Merge branch 'master' into careminster (diff) | |
parent | BulletSim: add INI parameter for angular banking timescale fudge parameter. (diff) | |
download | opensim-SC-5b950ca36aa6596cdd7a35f23654544e303635c2.zip opensim-SC-5b950ca36aa6596cdd7a35f23654544e303635c2.tar.gz opensim-SC-5b950ca36aa6596cdd7a35f23654544e303635c2.tar.bz2 opensim-SC-5b950ca36aa6596cdd7a35f23654544e303635c2.tar.xz |
Merge commit '464201b41d5f5fdd7c88ab5e95dd7b6fbae6d766' into careminster
Diffstat (limited to 'OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs')
-rw-r--r-- | OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs | 228 |
1 files changed, 0 insertions, 228 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs b/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs deleted file mode 100644 index d99ba57..0000000 --- a/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs +++ /dev/null | |||
@@ -1,228 +0,0 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Xml.Serialization; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Framework.Servers; | ||
34 | using OpenSim.Framework.Servers.HttpServer; | ||
35 | using OpenSim.Region.Framework.Interfaces; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | |||
38 | namespace OpenSim.ApplicationPlugins.Rest.Regions | ||
39 | { | ||
40 | public partial class RestRegionPlugin : RestPlugin | ||
41 | { | ||
42 | #region GET methods | ||
43 | public string GetHandler(string request, string path, string param, | ||
44 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
45 | { | ||
46 | // foreach (string h in httpRequest.Headers.AllKeys) | ||
47 | // foreach (string v in httpRequest.Headers.GetValues(h)) | ||
48 | // m_log.DebugFormat("{0} IsGod: {1} -> {2}", MsgID, h, v); | ||
49 | |||
50 | MsgID = RequestID; | ||
51 | m_log.DebugFormat("{0} GET path {1} param {2}", MsgID, path, param); | ||
52 | |||
53 | try | ||
54 | { | ||
55 | // param empty: regions list | ||
56 | if (String.IsNullOrEmpty(param)) return GetHandlerRegions(httpResponse); | ||
57 | |||
58 | // param not empty: specific region | ||
59 | return GetHandlerRegion(httpResponse, param); | ||
60 | } | ||
61 | catch (Exception e) | ||
62 | { | ||
63 | return Failure(httpResponse, OSHttpStatusCode.ServerErrorInternalError, "GET", e); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | public string GetHandlerRegions(IOSHttpResponse httpResponse) | ||
68 | { | ||
69 | RestXmlWriter rxw = new RestXmlWriter(new StringWriter()); | ||
70 | |||
71 | rxw.WriteStartElement(String.Empty, "regions", String.Empty); | ||
72 | foreach (Scene s in App.SceneManager.Scenes) | ||
73 | { | ||
74 | rxw.WriteStartElement(String.Empty, "uuid", String.Empty); | ||
75 | rxw.WriteString(s.RegionInfo.RegionID.ToString()); | ||
76 | rxw.WriteEndElement(); | ||
77 | } | ||
78 | rxw.WriteEndElement(); | ||
79 | |||
80 | return rxw.ToString(); | ||
81 | } | ||
82 | |||
83 | protected string ShortRegionInfo(string key, string value) | ||
84 | { | ||
85 | RestXmlWriter rxw = new RestXmlWriter(new StringWriter()); | ||
86 | |||
87 | if (String.IsNullOrEmpty(value) || | ||
88 | String.IsNullOrEmpty(key)) return null; | ||
89 | |||
90 | rxw.WriteStartElement(String.Empty, "region", String.Empty); | ||
91 | rxw.WriteStartElement(String.Empty, key, String.Empty); | ||
92 | rxw.WriteString(value); | ||
93 | rxw.WriteEndDocument(); | ||
94 | |||
95 | return rxw.ToString(); | ||
96 | } | ||
97 | |||
98 | public string GetHandlerRegion(IOSHttpResponse httpResponse, string param) | ||
99 | { | ||
100 | // be resilient and don't get confused by a terminating '/' | ||
101 | param = param.TrimEnd(new char[]{'/'}); | ||
102 | string[] comps = param.Split('/'); | ||
103 | UUID regionID = (UUID)comps[0]; | ||
104 | |||
105 | m_log.DebugFormat("{0} GET region UUID {1}", MsgID, regionID.ToString()); | ||
106 | |||
107 | if (UUID.Zero == regionID) throw new Exception("missing region ID"); | ||
108 | |||
109 | Scene scene = null; | ||
110 | App.SceneManager.TryGetScene(regionID, out scene); | ||
111 | if (null == scene) return Failure(httpResponse, OSHttpStatusCode.ClientErrorNotFound, | ||
112 | "GET", "cannot find region {0}", regionID.ToString()); | ||
113 | |||
114 | RegionDetails details = new RegionDetails(scene.RegionInfo); | ||
115 | |||
116 | // m_log.DebugFormat("{0} GET comps {1}", MsgID, comps.Length); | ||
117 | // for (int i = 0; i < comps.Length; i++) m_log.DebugFormat("{0} GET comps[{1}] >{2}<", MsgID, i, comps[i]); | ||
118 | |||
119 | if (1 == comps.Length) | ||
120 | { | ||
121 | // complete region details requested | ||
122 | RestXmlWriter rxw = new RestXmlWriter(new StringWriter()); | ||
123 | XmlSerializer xs = new XmlSerializer(typeof(RegionDetails)); | ||
124 | xs.Serialize(rxw, details, _xmlNs); | ||
125 | return rxw.ToString(); | ||
126 | } | ||
127 | |||
128 | if (2 == comps.Length) | ||
129 | { | ||
130 | string resp = ShortRegionInfo(comps[1], details[comps[1]]); | ||
131 | if (null != resp) return resp; | ||
132 | |||
133 | // m_log.DebugFormat("{0} GET comps advanced: >{1}<", MsgID, comps[1]); | ||
134 | |||
135 | // check for {terrain,stats,prims} | ||
136 | switch (comps[1].ToLower()) | ||
137 | { | ||
138 | case "terrain": | ||
139 | return RegionTerrain(httpResponse, scene); | ||
140 | |||
141 | case "stats": | ||
142 | return RegionStats(httpResponse, scene); | ||
143 | |||
144 | case "prims": | ||
145 | return RegionPrims(httpResponse, scene, Vector3.Zero, Vector3.Zero); | ||
146 | } | ||
147 | } | ||
148 | |||
149 | if (3 == comps.Length) | ||
150 | { | ||
151 | switch (comps[1].ToLower()) | ||
152 | { | ||
153 | case "prims": | ||
154 | string[] subregion = comps[2].Split(','); | ||
155 | if (subregion.Length == 6) | ||
156 | { | ||
157 | Vector3 min, max; | ||
158 | try | ||
159 | { | ||
160 | min = new Vector3((float)Double.Parse(subregion[0], Culture.NumberFormatInfo), (float)Double.Parse(subregion[1], Culture.NumberFormatInfo), (float)Double.Parse(subregion[2], Culture.NumberFormatInfo)); | ||
161 | max = new Vector3((float)Double.Parse(subregion[3], Culture.NumberFormatInfo), (float)Double.Parse(subregion[4], Culture.NumberFormatInfo), (float)Double.Parse(subregion[5], Culture.NumberFormatInfo)); | ||
162 | } | ||
163 | catch (Exception) | ||
164 | { | ||
165 | return Failure(httpResponse, OSHttpStatusCode.ClientErrorBadRequest, | ||
166 | "GET", "invalid subregion parameter"); | ||
167 | } | ||
168 | return RegionPrims(httpResponse, scene, min, max); | ||
169 | } | ||
170 | else | ||
171 | { | ||
172 | return Failure(httpResponse, OSHttpStatusCode.ClientErrorBadRequest, | ||
173 | "GET", "invalid subregion parameter"); | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | |||
178 | return Failure(httpResponse, OSHttpStatusCode.ClientErrorBadRequest, | ||
179 | "GET", "too many parameters {0}", param); | ||
180 | } | ||
181 | #endregion GET methods | ||
182 | |||
183 | protected string RegionTerrain(IOSHttpResponse httpResponse, Scene scene) | ||
184 | { | ||
185 | httpResponse.SendChunked = true; | ||
186 | httpResponse.ContentType = "text/xml"; | ||
187 | |||
188 | return scene.Heightmap.SaveToXmlString(); | ||
189 | //return Failure(httpResponse, OSHttpStatusCode.ServerErrorNotImplemented, | ||
190 | // "GET", "terrain not implemented"); | ||
191 | } | ||
192 | |||
193 | protected string RegionStats(IOSHttpResponse httpResponse, Scene scene) | ||
194 | { | ||
195 | int users = scene.GetRootAgentCount(); | ||
196 | int objects = scene.Entities.Count - users; | ||
197 | |||
198 | RestXmlWriter rxw = new RestXmlWriter(new StringWriter()); | ||
199 | |||
200 | rxw.WriteStartElement(String.Empty, "region", String.Empty); | ||
201 | rxw.WriteStartElement(String.Empty, "stats", String.Empty); | ||
202 | |||
203 | rxw.WriteStartElement(String.Empty, "users", String.Empty); | ||
204 | rxw.WriteString(users.ToString()); | ||
205 | rxw.WriteEndElement(); | ||
206 | |||
207 | rxw.WriteStartElement(String.Empty, "objects", String.Empty); | ||
208 | rxw.WriteString(objects.ToString()); | ||
209 | rxw.WriteEndElement(); | ||
210 | |||
211 | rxw.WriteEndDocument(); | ||
212 | |||
213 | return rxw.ToString(); | ||
214 | } | ||
215 | |||
216 | protected string RegionPrims(IOSHttpResponse httpResponse, Scene scene, Vector3 min, Vector3 max) | ||
217 | { | ||
218 | httpResponse.SendChunked = true; | ||
219 | httpResponse.ContentType = "text/xml"; | ||
220 | |||
221 | IRegionSerialiserModule serialiser = scene.RequestModuleInterface<IRegionSerialiserModule>(); | ||
222 | if (serialiser != null) | ||
223 | serialiser.SavePrimsToXml2(scene, new StreamWriter(httpResponse.OutputStream), min, max); | ||
224 | |||
225 | return ""; | ||
226 | } | ||
227 | } | ||
228 | } | ||