aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins
diff options
context:
space:
mode:
authorSean Dague2008-05-15 11:32:28 +0000
committerSean Dague2008-05-15 11:32:28 +0000
commit0307ad11531efb2fe95dab5dc489e37cb5bbb542 (patch)
tree1ab2444d259661cb27f5922fd476c245d450214b /OpenSim/ApplicationPlugins
parent* Added about half of the planned ODE physics options to OpenSim.ini.example. (diff)
downloadopensim-SC-0307ad11531efb2fe95dab5dc489e37cb5bbb542.zip
opensim-SC-0307ad11531efb2fe95dab5dc489e37cb5bbb542.tar.gz
opensim-SC-0307ad11531efb2fe95dab5dc489e37cb5bbb542.tar.bz2
opensim-SC-0307ad11531efb2fe95dab5dc489e37cb5bbb542.tar.xz
Damn, forgot to manually add these as I keep forgetting that
svn patches don't do adds. :(
Diffstat (limited to 'OpenSim/ApplicationPlugins')
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs72
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs162
-rw-r--r--OpenSim/ApplicationPlugins/Rest/RestPlugin.cs246
3 files changed, 480 insertions, 0 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs b/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs
new file mode 100644
index 0000000..7fc1267
--- /dev/null
+++ b/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs
@@ -0,0 +1,72 @@
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 libsecondlife;
30using System;
31using System.Collections;
32using System.Collections.Generic;
33using System.Xml.Serialization;
34using OpenSim.Framework;
35using OpenSim.Region.Environment.Scenes;
36
37namespace OpenSim.ApplicationPlugins.Rest.Regions
38{
39 [XmlRoot(ElementName="region")]
40 public class RegionDetails
41 {
42 public string region_name;
43 public string region_id;
44 public uint region_x;
45 public uint region_y;
46 public string region_owner;
47 public string region_owner_id;
48 public uint region_http_port;
49 public string region_server_uri;
50 public string region_external_hostname;
51
52 public RegionDetails()
53 {
54 }
55
56 public RegionDetails(RegionInfo regInfo)
57 {
58 region_name = regInfo.RegionName;
59 region_id = regInfo.RegionID.ToString();
60 region_x = regInfo.RegionLocX;
61 region_y = regInfo.RegionLocY;
62 region_owner_id = regInfo.MasterAvatarAssignedUUID.ToString();
63 region_http_port = regInfo.HttpPort;
64 region_server_uri = regInfo.ServerURI;
65 region_external_hostname = regInfo.ExternalHostName;
66
67 if (!String.IsNullOrEmpty(regInfo.MasterAvatarFirstName))
68 region_owner = String.Format("{0} {1}", regInfo.MasterAvatarFirstName,
69 regInfo.MasterAvatarLastName);
70 }
71 }
72} \ No newline at end of file
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
new file mode 100644
index 0000000..8a6fb09
--- /dev/null
+++ b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
@@ -0,0 +1,162 @@
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
51[assembly : Addin]
52[assembly : AddinDependency("OpenSim", "0.5")]
53
54namespace OpenSim.ApplicationPlugins.Rest.Regions
55{
56
57 [Extension("/OpenSim/Startup")]
58 public class RestRegionPlugin : RestPlugin
59 {
60 private static readonly log4net.ILog _log =
61 log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
62
63 #region overriding properties
64 public override string Name
65 {
66 get { return "REGION"; }
67 }
68
69 public override string ConfigName
70 {
71 get { return "RestRegionPlugin"; }
72 }
73 #endregion overriding properties
74
75 #region overriding methods
76 /// <summary>
77 /// This method is called by OpenSimMain immediately after loading the
78 /// plugin and after basic server setup, but before running any server commands.
79 /// </summary>
80 /// <remarks>
81 /// Note that entries MUST be added to the active configuration files before
82 /// the plugin can be enabled.
83 /// </remarks>
84 public override void Initialise(OpenSimMain openSim)
85 {
86 try
87 {
88 base.Initialise(openSim);
89 if (IsEnabled)
90 m_log.InfoFormat("{0} Rest Plugins Enabled", MsgID);
91 else
92 m_log.WarnFormat("{0} Rest Plugins are disabled", MsgID);
93
94 // add REST method handlers
95 AddRestStreamHandler("GET", "/regions/", GetHandler);
96 }
97 catch (Exception e)
98 {
99 _log.WarnFormat("{0} Initialization failed: {1}", MsgID, e.Message);
100 _log.DebugFormat("{0} Initialization failed: {1}", MsgID, e.ToString());
101 }
102 }
103
104 public override void Close()
105 {
106 }
107 #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 }
162}
diff --git a/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs b/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
new file mode 100644
index 0000000..0e54f4d
--- /dev/null
+++ b/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
@@ -0,0 +1,246 @@
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.Net;
34using System.Reflection;
35using System.Timers;
36using libsecondlife;
37using Mono.Addins;
38using Nwc.XmlRpc;
39using Nini.Config;
40using OpenSim.Framework;
41using OpenSim.Framework.Console;
42using OpenSim.Framework.Servers;
43using OpenSim.Framework.Communications;
44using OpenSim.Region.Environment.Scenes;
45
46// [assembly : Addin]
47// [assembly : AddinDependency("OpenSim", "0.5")]
48
49namespace OpenSim.ApplicationPlugins.Rest
50{
51
52 // [Extension("/OpenSim/Startup")]
53 public abstract class RestPlugin : IApplicationPlugin
54 {
55 #region properties
56
57 protected static readonly log4net.ILog m_log =
58 log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
59
60 private IConfig _config; // Configuration source: Rest Plugins
61 private IConfig _pluginConfig; // Configuration source: Plugin specific
62 private OpenSimMain _app; // The 'server'
63 private BaseHttpServer _httpd; // The server's RPC interface
64 private string _prefix; // URL prefix below which all REST URLs are living
65
66 private string _godkey;
67 private int _reqk;
68
69 [ThreadStaticAttribute]
70 private static string _threadRequestID = String.Empty;
71
72 /// <summary>
73 /// Return an ever increasing request ID for logging
74 /// </summary>
75 protected string RequestID
76 {
77 get { return _reqk++.ToString(); }
78 set { _reqk = Convert.ToInt32(value); }
79 }
80
81 /// <summary>
82 /// Thread-constant message IDs for logging.
83 /// </summary>
84 protected string MsgID
85 {
86 get { return String.Format("[REST-{0}] #{1}", Name, _threadRequestID); }
87 set { _threadRequestID = value; }
88 }
89
90 /// <summary>
91 /// Returns true if Rest Plugins are enabled.
92 /// </summary>
93 public bool PluginsAreEnabled
94 {
95 get { return null != _config; }
96 }
97
98 /// <summary>
99 /// Returns true if specific Rest Plugin is enabled.
100 /// </summary>
101 public bool IsEnabled
102 {
103 get
104 {
105 return (null != _pluginConfig) && _pluginConfig.GetBoolean("enabled", false);
106 }
107 }
108
109 /// <summary>
110 /// OpenSimMain application
111 /// </summary>
112 public OpenSimMain App
113 {
114 get { return _app; }
115 }
116
117 /// <summary>
118 /// RPC server
119 /// </summary>
120 public BaseHttpServer HttpServer
121 {
122 get { return _httpd; }
123 }
124
125 /// <summary>
126 /// URL prefix to use for all REST handlers
127 /// </summary>
128 public string Prefix
129 {
130 get { return _prefix; }
131 }
132
133 /// <summary>
134 /// Configuration of the plugin
135 /// </summary>
136 public IConfig Config
137 {
138 get { return _pluginConfig; }
139 }
140
141 /// <summary>
142 /// Name of the plugin
143 /// </summary>
144 public abstract string Name { get; }
145
146 /// <summary>
147 /// Return the config section name
148 /// </summary>
149 public abstract string ConfigName { get; }
150 #endregion properties
151
152
153 #region methods
154 /// <summary>
155 /// This method is called by OpenSimMain immediately after loading the
156 /// plugin and after basic server setup, but before running any server commands.
157 /// </summary>
158 /// <remarks>
159 /// Note that entries MUST be added to the active configuration files before
160 /// the plugin can be enabled.
161 /// </remarks>
162 public virtual void Initialise(OpenSimMain openSim)
163 {
164 RequestID = "0";
165 MsgID = RequestID;
166
167 try
168 {
169 if ((_config = openSim.ConfigSource.Configs["RestPlugins"]) == null) {
170 m_log.WarnFormat("{0} Rest Plugins not configured", MsgID);
171 return;
172 }
173
174 if (!_config.GetBoolean("enabled", false))
175 {
176 m_log.WarnFormat("{0} Rest Plugins are disabled", MsgID);
177 return;
178 }
179
180 _app = openSim;
181 _httpd = openSim.HttpServer;
182
183 // Retrieve GOD key value, if any.
184 _godkey = _config.GetString("god_key", String.Empty);
185 // Retrive prefix if any.
186 _prefix = _config.GetString("prefix", "/admin");
187
188 // Get plugin specific config
189 _pluginConfig = openSim.ConfigSource.Configs[ConfigName];
190
191 m_log.InfoFormat("{0} Rest Plugins Enabled", MsgID);
192 }
193 catch (Exception e)
194 {
195 // we can safely ignore this, as it just means that
196 // the key lookup in Configs failed, which signals to
197 // us that noone is interested in our services...they
198 // don't know what they are missing out on...
199 // NOTE: Under the present OpenSim implementation it is
200 // not possible for the openSim pointer to be null. However
201 // were the implementation to be changed, this could
202 // result in a silent initialization failure. Harmless
203 // except for lack of function and lack of any
204 // diagnostic indication as to why. The same is true if
205 // the HTTP server reference is bad.
206 // We should at least issue a message...
207 m_log.WarnFormat("{0} Initialization failed: {1}", MsgID, e.Message);
208 m_log.DebugFormat("{0} Initialization failed: {1}", MsgID, e.ToString());
209 }
210 }
211
212
213 private List<RestStreamHandler> _handlers = new List<RestStreamHandler>();
214
215 public void AddRestStreamHandler(string httpMethod, string path, RestMethod method)
216 {
217 if (!path.StartsWith(_prefix))
218 {
219 path = String.Format("{0}{1}", _prefix, path);
220 }
221
222 RestStreamHandler h = new RestStreamHandler(httpMethod, path, method);
223 _httpd.AddStreamHandler(h);
224 _handlers.Add(h);
225
226 m_log.DebugFormat("{0} Added REST handler {1} {2}", MsgID, httpMethod, path);
227 }
228
229
230 public bool VerifyGod(string key)
231 {
232 if (String.IsNullOrEmpty(key)) return false;
233 return key == _godkey;
234 }
235
236 public virtual void Close()
237 {
238 foreach (RestStreamHandler h in _handlers)
239 {
240 _httpd.RemoveStreamHandler(h.HttpMethod, h.Path);
241 }
242 _handlers = null;
243 }
244 #endregion methods
245 }
246}