aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/Rest/Regions
diff options
context:
space:
mode:
authorDr Scofield2008-05-22 12:00:01 +0000
committerDr Scofield2008-05-22 12:00:01 +0000
commitbdc792d319601caa93790b21c33b3b623a4ac13c (patch)
tree040726c9a37edba4f1873a1f8d445b6c6fa1fd63 /OpenSim/ApplicationPlugins/Rest/Regions
parentAdded "show regions" to the CL help screen. Mantis 1123 (diff)
downloadopensim-SC_OLD-bdc792d319601caa93790b21c33b3b623a4ac13c.zip
opensim-SC_OLD-bdc792d319601caa93790b21c33b3b623a4ac13c.tar.gz
opensim-SC_OLD-bdc792d319601caa93790b21c33b3b623a4ac13c.tar.bz2
opensim-SC_OLD-bdc792d319601caa93790b21c33b3b623a4ac13c.tar.xz
here are further enhancements to the IHttpAgentHandler and to BaseHttpServer (from awebb)
i've added the OSHttpStatusCodes enumeration of HTTP status codes, have adapted BaseHttpServer to use those. then RestPlugin now has proper Failure handling returning proper HTTP status codes. Regions/POSTHandler is work-in-progress.
Diffstat (limited to 'OpenSim/ApplicationPlugins/Rest/Regions')
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs34
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Regions/POSTHandler.cs101
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs1
3 files changed, 121 insertions, 15 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs b/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs
index a319a8b..b89976f 100644
--- a/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs
+++ b/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs
@@ -67,18 +67,18 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
67 try 67 try
68 { 68 {
69 // param empty: regions list 69 // param empty: regions list
70 if (String.IsNullOrEmpty(param)) return GetHandlerRegions(); 70 if (String.IsNullOrEmpty(param)) return GetHandlerRegions(httpResponse);
71 71
72 // param not empty: specific region 72 // param not empty: specific region
73 return GetHandlerRegion(param); 73 return GetHandlerRegion(httpResponse, param);
74 } 74 }
75 catch (Exception e) 75 catch (Exception e)
76 { 76 {
77 return Failure("GET", e); 77 return Failure(httpResponse, OSHttpStatusCode.ServerErrorInternalError, "GET", e);
78 } 78 }
79 } 79 }
80 80
81 public string GetHandlerRegions() 81 public string GetHandlerRegions(OSHttpResponse httpResponse)
82 { 82 {
83 XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty); 83 XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty);
84 foreach (Scene s in App.SceneManager.Scenes) 84 foreach (Scene s in App.SceneManager.Scenes)
@@ -105,7 +105,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
105 return XmlWriterResult; 105 return XmlWriterResult;
106 } 106 }
107 107
108 public string GetHandlerRegion(string param) 108 public string GetHandlerRegion(OSHttpResponse httpResponse, string param)
109 { 109 {
110 // be resilient and don't get confused by a terminating '/' 110 // be resilient and don't get confused by a terminating '/'
111 param = param.TrimEnd(new char[]{'/'}); 111 param = param.TrimEnd(new char[]{'/'});
@@ -118,7 +118,8 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
118 118
119 Scene scene = null; 119 Scene scene = null;
120 App.SceneManager.TryGetScene(regionID, out scene); 120 App.SceneManager.TryGetScene(regionID, out scene);
121 if (null == scene) return Failure("GET", "cannot find region"); 121 if (null == scene) return Failure(httpResponse, OSHttpStatusCode.ClientErrorNotFound,
122 "GET", "cannot find region {0}", regionID.ToString());
122 123
123 RegionDetails details = new RegionDetails(scene.RegionInfo); 124 RegionDetails details = new RegionDetails(scene.RegionInfo);
124 125
@@ -143,25 +144,27 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
143 switch (comps[1].ToLower()) 144 switch (comps[1].ToLower())
144 { 145 {
145 case "terrain": 146 case "terrain":
146 return RegionTerrain(scene); 147 return RegionTerrain(httpResponse, scene);
147 148
148 case "stats": 149 case "stats":
149 return RegionStats(scene); 150 return RegionStats(httpResponse, scene);
150 151
151 case "prims": 152 case "prims":
152 return RegionPrims(scene); 153 return RegionPrims(httpResponse, scene);
153 } 154 }
154 } 155 }
155 return Failure("GET", "too many parameters"); 156 return Failure(httpResponse, OSHttpStatusCode.ClientErrorBadRequest,
157 "GET", "too many parameters {0}", param);
156 } 158 }
157 #endregion GET methods 159 #endregion GET methods
158 160
159 protected string RegionTerrain(Scene scene) 161 protected string RegionTerrain(OSHttpResponse httpResponse, Scene scene)
160 { 162 {
161 return Failure("GET", "terrain not implemented"); 163 return Failure(httpResponse, OSHttpStatusCode.ServerErrorNotImplemented,
164 "GET", "terrain not implemented");
162 } 165 }
163 166
164 protected string RegionStats(Scene scene) 167 protected string RegionStats(OSHttpResponse httpResponse, Scene scene)
165 { 168 {
166 int users = scene.GetAvatars().Count; 169 int users = scene.GetAvatars().Count;
167 int objects = scene.Entities.Count - users; 170 int objects = scene.Entities.Count - users;
@@ -182,9 +185,10 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
182 return XmlWriterResult; 185 return XmlWriterResult;
183 } 186 }
184 187
185 protected string RegionPrims(Scene scene) 188 protected string RegionPrims(OSHttpResponse httpResponse, Scene scene)
186 { 189 {
187 return Failure("GET", "prims not implemented"); 190 return Failure(httpResponse, OSHttpStatusCode.ServerErrorNotImplemented,
191 "GET", "prims not implemented");
188 } 192 }
189 } 193 }
190} 194}
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/POSTHandler.cs b/OpenSim/ApplicationPlugins/Rest/Regions/POSTHandler.cs
new file mode 100644
index 0000000..00fe0d2
--- /dev/null
+++ b/OpenSim/ApplicationPlugins/Rest/Regions/POSTHandler.cs
@@ -0,0 +1,101 @@
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 POST methods
57 public string PostHandler(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} POST path {1} param {2}", MsgID, path, param);
66
67 try
68 {
69 // param empty: new region post
70 if (!IsGod(httpRequest))
71 // XXX: this needs to be turned into a FailureUnauthorized(...)
72 return Failure(httpResponse, OSHttpStatusCode.ClientErrorUnauthorized,
73 "GET", "you are not god");
74
75 if (String.IsNullOrEmpty(param)) return CreateRegion(httpRequest, httpResponse);
76
77 return Failure(httpResponse, OSHttpStatusCode.ClientErrorNotFound,
78 "POST", "url {0} not supported", param);
79 }
80 catch (Exception e)
81 {
82 return Failure(httpResponse, OSHttpStatusCode.ServerErrorInternalError, "POST", e);
83 }
84 }
85
86 public string CreateRegion(OSHttpRequest request, OSHttpResponse response)
87 {
88 XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty);
89 foreach (Scene s in App.SceneManager.Scenes)
90 {
91 XmlWriter.WriteStartElement(String.Empty, "uuid", String.Empty);
92 XmlWriter.WriteString(s.RegionInfo.RegionID.ToString());
93 XmlWriter.WriteEndElement();
94 }
95 XmlWriter.WriteEndElement();
96
97 return XmlWriterResult;
98 }
99 #endregion POST methods
100 }
101}
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
index 9b888fa..6d585a4 100644
--- a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
+++ b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
@@ -92,6 +92,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
92 92
93 // add REST method handlers 93 // add REST method handlers
94 AddRestStreamHandler("GET", "/regions/", GetHandler); 94 AddRestStreamHandler("GET", "/regions/", GetHandler);
95 AddRestStreamHandler("POST", "/regions/", PostHandler);
95 } 96 }
96 catch (Exception e) 97 catch (Exception e)
97 { 98 {