diff options
Diffstat (limited to 'OpenSim/ApplicationPlugins/Rest/Regions')
3 files changed, 227 insertions, 67 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 | } | ||
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs b/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs index 5102e3f..c86c67f 100644 --- a/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs +++ b/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs | |||
@@ -23,7 +23,7 @@ | |||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using libsecondlife; | 29 | using libsecondlife; |
@@ -65,8 +65,38 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions | |||
65 | region_external_hostname = regInfo.ExternalHostName; | 65 | region_external_hostname = regInfo.ExternalHostName; |
66 | 66 | ||
67 | if (!String.IsNullOrEmpty(regInfo.MasterAvatarFirstName)) | 67 | if (!String.IsNullOrEmpty(regInfo.MasterAvatarFirstName)) |
68 | region_owner = String.Format("{0} {1}", regInfo.MasterAvatarFirstName, | 68 | region_owner = String.Format("{0} {1}", regInfo.MasterAvatarFirstName, |
69 | regInfo.MasterAvatarLastName); | 69 | regInfo.MasterAvatarLastName); |
70 | } | 70 | } |
71 | |||
72 | public string this[string idx] | ||
73 | { | ||
74 | get | ||
75 | { | ||
76 | switch(idx.ToLower()) | ||
77 | { | ||
78 | case "name": | ||
79 | return region_name; | ||
80 | case "id": | ||
81 | return region_id; | ||
82 | case "location": | ||
83 | return String.Format("<x>{0}</x><y>{1}</y>", region_x, region_y); | ||
84 | case "owner": | ||
85 | return region_owner; | ||
86 | case "owner_id": | ||
87 | return region_owner_id; | ||
88 | case "http_port": | ||
89 | return region_http_port.ToString(); | ||
90 | case "server_uri": | ||
91 | return region_server_uri; | ||
92 | case "external_hostname": | ||
93 | case "hostname": | ||
94 | return region_external_hostname; | ||
95 | |||
96 | default: | ||
97 | return null; | ||
98 | } | ||
99 | } | ||
100 | } | ||
71 | } | 101 | } |
72 | } \ No newline at end of file | 102 | } \ No newline at end of file |
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs index 0716cf6..9b888fa 100644 --- a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs +++ b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs | |||
@@ -23,7 +23,7 @@ | |||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
@@ -55,14 +55,11 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions | |||
55 | { | 55 | { |
56 | 56 | ||
57 | [Extension("/OpenSim/Startup")] | 57 | [Extension("/OpenSim/Startup")] |
58 | public class RestRegionPlugin : RestPlugin | 58 | public partial class RestRegionPlugin : RestPlugin |
59 | { | 59 | { |
60 | private static readonly log4net.ILog _log = | ||
61 | log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
62 | |||
63 | #region overriding properties | 60 | #region overriding properties |
64 | public override string Name | 61 | public override string Name |
65 | { | 62 | { |
66 | get { return "REGION"; } | 63 | get { return "REGION"; } |
67 | } | 64 | } |
68 | 65 | ||
@@ -86,18 +83,20 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions | |||
86 | try | 83 | try |
87 | { | 84 | { |
88 | base.Initialise(openSim); | 85 | base.Initialise(openSim); |
89 | if (IsEnabled) | 86 | if (!IsEnabled) |
90 | m_log.InfoFormat("{0} Rest Plugins Enabled", MsgID); | 87 | { |
91 | else | ||
92 | m_log.WarnFormat("{0} Rest Plugins are disabled", MsgID); | 88 | m_log.WarnFormat("{0} Rest Plugins are disabled", MsgID); |
89 | return; | ||
90 | } | ||
91 | m_log.InfoFormat("{0} REST region plugin enabled", MsgID); | ||
93 | 92 | ||
94 | // add REST method handlers | 93 | // add REST method handlers |
95 | AddRestStreamHandler("GET", "/regions/", GetHandler); | 94 | AddRestStreamHandler("GET", "/regions/", GetHandler); |
96 | } | 95 | } |
97 | catch (Exception e) | 96 | catch (Exception e) |
98 | { | 97 | { |
99 | _log.WarnFormat("{0} Initialization failed: {1}", MsgID, e.Message); | 98 | m_log.WarnFormat("{0} Initialization failed: {1}", MsgID, e.Message); |
100 | _log.DebugFormat("{0} Initialization failed: {1}", MsgID, e.ToString()); | 99 | m_log.DebugFormat("{0} Initialization failed: {1}", MsgID, e.ToString()); |
101 | } | 100 | } |
102 | } | 101 | } |
103 | 102 | ||
@@ -105,58 +104,5 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions | |||
105 | { | 104 | { |
106 | } | 105 | } |
107 | #endregion overriding methods | 106 | #endregion overriding methods |
108 | |||
109 | #region methods | ||
110 | public string GetHandler(string request, string path, string param) | ||
111 | { | ||
112 | m_log.DebugFormat("{0} GET path {1} param {2}", MsgID, path, param); | ||
113 | |||
114 | // param empty: regions list | ||
115 | if (String.IsNullOrEmpty(param)) return GetHandlerRegions(); | ||
116 | |||
117 | return GetHandlerRegion(param); | ||
118 | } | ||
119 | |||
120 | public string GetHandlerRegions() | ||
121 | { | ||
122 | StringWriter sw = new StringWriter(); | ||
123 | XmlTextWriter xw = new XmlTextWriter(sw); | ||
124 | xw.Formatting = Formatting.Indented; | ||
125 | |||
126 | xw.WriteStartElement(String.Empty, "regions", String.Empty); | ||
127 | foreach (Scene s in App.SceneManager.Scenes) | ||
128 | { | ||
129 | xw.WriteStartElement(String.Empty, "uuid", String.Empty); | ||
130 | xw.WriteString(s.RegionInfo.RegionID.ToString()); | ||
131 | xw.WriteEndElement(); | ||
132 | } | ||
133 | xw.WriteEndElement(); | ||
134 | xw.Close(); | ||
135 | |||
136 | return sw.ToString(); | ||
137 | } | ||
138 | |||
139 | public string GetHandlerRegion(string param) | ||
140 | { | ||
141 | string[] comps = param.Split('/'); | ||
142 | LLUUID regionID = (LLUUID)comps[0]; | ||
143 | _log.DebugFormat("{0} region UUID {1}", MsgID, regionID.ToString()); | ||
144 | |||
145 | if (LLUUID.Zero == regionID) throw new Exception("missing region ID"); | ||
146 | |||
147 | Scene scene = null; | ||
148 | App.SceneManager.TryGetScene(regionID, out scene); | ||
149 | |||
150 | XmlSerializer xs = new XmlSerializer(typeof(RegionDetails)); | ||
151 | StringWriter sw = new StringWriter(); | ||
152 | XmlTextWriter xw = new XmlTextWriter(sw); | ||
153 | xw.Formatting = Formatting.Indented; | ||
154 | |||
155 | xs.Serialize(xw, new RegionDetails(scene.RegionInfo)); | ||
156 | xw.Close(); | ||
157 | |||
158 | return sw.ToString(); | ||
159 | } | ||
160 | #endregion methods | ||
161 | } | 107 | } |
162 | } | 108 | } |