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