diff options
Diffstat (limited to 'OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs')
-rw-r--r-- | OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs b/OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs new file mode 100644 index 0000000..2b006e0 --- /dev/null +++ b/OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs | |||
@@ -0,0 +1,184 @@ | |||
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 OpenSim 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 | |||
29 | using System; | ||
30 | using System.Threading; | ||
31 | using System.Collections; | ||
32 | using System.Collections.Generic; | ||
33 | using System.IO; | ||
34 | using System.Net; | ||
35 | using System.Reflection; | ||
36 | using System.Text.RegularExpressions; | ||
37 | using System.Timers; | ||
38 | using System.Xml; | ||
39 | using System.Xml.Serialization; | ||
40 | using libsecondlife; | ||
41 | using Mono.Addins; | ||
42 | using Nwc.XmlRpc; | ||
43 | using Nini.Config; | ||
44 | using OpenSim.Framework; | ||
45 | using OpenSim.Framework.Console; | ||
46 | using OpenSim.Framework.Servers; | ||
47 | using OpenSim.Framework.Communications; | ||
48 | using OpenSim.Region.Environment.Scenes; | ||
49 | using OpenSim.ApplicationPlugins.Rest; | ||
50 | |||
51 | namespace OpenSim.ApplicationPlugins.Rest.Regions | ||
52 | { | ||
53 | |||
54 | public partial class RestRegionPlugin : RestPlugin | ||
55 | { | ||
56 | #region GET methods | ||
57 | public string GetHandler(string request, string path, string param) | ||
58 | { | ||
59 | m_log.DebugFormat("{0} GET path {1} param {2}", MsgID, path, param); | ||
60 | |||
61 | try | ||
62 | { | ||
63 | // param empty: regions list | ||
64 | if (String.IsNullOrEmpty(param)) return GetHandlerRegions(); | ||
65 | |||
66 | // param not empty: specific region | ||
67 | return GetHandlerRegion(param); | ||
68 | } | ||
69 | catch (Exception e) | ||
70 | { | ||
71 | return Failure("GET", e); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | public string GetHandlerRegions() | ||
76 | { | ||
77 | XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty); | ||
78 | foreach (Scene s in App.SceneManager.Scenes) | ||
79 | { | ||
80 | XmlWriter.WriteStartElement(String.Empty, "uuid", String.Empty); | ||
81 | XmlWriter.WriteString(s.RegionInfo.RegionID.ToString()); | ||
82 | XmlWriter.WriteEndElement(); | ||
83 | } | ||
84 | XmlWriter.WriteEndElement(); | ||
85 | |||
86 | return XmlWriterResult; | ||
87 | } | ||
88 | |||
89 | protected string ShortRegionInfo(string key, string value) | ||
90 | { | ||
91 | if (String.IsNullOrEmpty(value) || | ||
92 | String.IsNullOrEmpty(key)) return null; | ||
93 | |||
94 | XmlWriter.WriteStartElement(String.Empty, "region", String.Empty); | ||
95 | XmlWriter.WriteStartElement(String.Empty, key, String.Empty); | ||
96 | XmlWriter.WriteString(value); | ||
97 | XmlWriter.WriteEndDocument(); | ||
98 | |||
99 | return XmlWriterResult; | ||
100 | } | ||
101 | |||
102 | public string GetHandlerRegion(string param) | ||
103 | { | ||
104 | // be resilient and don't get confused by a terminating '/' | ||
105 | param = param.TrimEnd(new char[]{'/'}); | ||
106 | string[] comps = param.Split('/'); | ||
107 | LLUUID regionID = (LLUUID)comps[0]; | ||
108 | |||
109 | m_log.DebugFormat("{0} GET region UUID {1}", MsgID, regionID.ToString()); | ||
110 | |||
111 | if (LLUUID.Zero == regionID) throw new Exception("missing region ID"); | ||
112 | |||
113 | Scene scene = null; | ||
114 | App.SceneManager.TryGetScene(regionID, out scene); | ||
115 | if (null == scene) return Failure("GET", "cannot find region"); | ||
116 | |||
117 | RegionDetails details = new RegionDetails(scene.RegionInfo); | ||
118 | |||
119 | // m_log.DebugFormat("{0} GET comps {1}", MsgID, comps.Length); | ||
120 | // for (int i = 0; i < comps.Length; i++) m_log.DebugFormat("{0} GET comps[{1}] >{2}<", MsgID, i, comps[i]); | ||
121 | |||
122 | if (1 == comps.Length) | ||
123 | { | ||
124 | // complete region details requested | ||
125 | XmlSerializer xs = new XmlSerializer(typeof(RegionDetails)); | ||
126 | xs.Serialize(XmlWriter, details); | ||
127 | return XmlWriterResult; | ||
128 | } | ||
129 | |||
130 | if (2 == comps.Length) { | ||
131 | string resp = ShortRegionInfo(comps[1], details[comps[1]]); | ||
132 | if (null != resp) return resp; | ||
133 | |||
134 | // m_log.DebugFormat("{0} GET comps advanced: >{1}<", MsgID, comps[1]); | ||
135 | |||
136 | // check for {terrain,stats,prims} | ||
137 | switch (comps[1].ToLower()) | ||
138 | { | ||
139 | case "terrain": | ||
140 | return RegionTerrain(scene); | ||
141 | |||
142 | case "stats": | ||
143 | return RegionStats(scene); | ||
144 | |||
145 | case "prims": | ||
146 | return RegionPrims(scene); | ||
147 | } | ||
148 | } | ||
149 | return Failure("GET", "too many parameters"); | ||
150 | } | ||
151 | #endregion GET methods | ||
152 | |||
153 | protected string RegionTerrain(Scene scene) | ||
154 | { | ||
155 | return Failure("GET", "terrain not implemented"); | ||
156 | } | ||
157 | |||
158 | protected string RegionStats(Scene scene) | ||
159 | { | ||
160 | int users = scene.GetAvatars().Count; | ||
161 | int objects = scene.Entities.Count - users; | ||
162 | |||
163 | XmlWriter.WriteStartElement(String.Empty, "region", String.Empty); | ||
164 | XmlWriter.WriteStartElement(String.Empty, "stats", String.Empty); | ||
165 | |||
166 | XmlWriter.WriteStartElement(String.Empty, "users", String.Empty); | ||
167 | XmlWriter.WriteString(users.ToString()); | ||
168 | XmlWriter.WriteEndElement(); | ||
169 | |||
170 | XmlWriter.WriteStartElement(String.Empty, "objects", String.Empty); | ||
171 | XmlWriter.WriteString(objects.ToString()); | ||
172 | XmlWriter.WriteEndElement(); | ||
173 | |||
174 | XmlWriter.WriteEndDocument(); | ||
175 | |||
176 | return XmlWriterResult; | ||
177 | } | ||
178 | |||
179 | protected string RegionPrims(Scene scene) | ||
180 | { | ||
181 | return Failure("GET", "prims not implemented"); | ||
182 | } | ||
183 | } | ||
184 | } | ||