diff options
author | Diva Canto | 2015-01-06 21:24:44 -0800 |
---|---|---|
committer | Diva Canto | 2015-01-06 21:24:44 -0800 |
commit | 8e562f04d1576bd51138ac656f796ba18965fdcf (patch) | |
tree | c06dce809cb04c971ac545e9793d885ea555e611 /OpenSim/Server/Handlers/Estate | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC-8e562f04d1576bd51138ac656f796ba18965fdcf.zip opensim-SC-8e562f04d1576bd51138ac656f796ba18965fdcf.tar.gz opensim-SC-8e562f04d1576bd51138ac656f796ba18965fdcf.tar.bz2 opensim-SC-8e562f04d1576bd51138ac656f796ba18965fdcf.tar.xz |
Donation of robust network connectors for estate service, as promised. This allows to have one central database for estates without having to open the MySql port. This is off by default, so not to disturb everyone's existing installations. To use it, see GridCommon.ini.example [EstateDataStore] section and Robust*.ini.example's new additions.
Note that I also made things consistent by removing both the EstateDataService and the SimulationService into their own dlls, just like all other services. They really didn't belong in Services.Connectors, since everything in that component is about network connectors to robust backends. We may have too many dlls, and at some point it might not be a bad idea to merge all services into one single dll, since they all have more or less the same dependencies.
Diffstat (limited to 'OpenSim/Server/Handlers/Estate')
-rw-r--r-- | OpenSim/Server/Handlers/Estate/EstateDataRobustConnector.cs | 345 |
1 files changed, 345 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Estate/EstateDataRobustConnector.cs b/OpenSim/Server/Handlers/Estate/EstateDataRobustConnector.cs new file mode 100644 index 0000000..4fe74f9 --- /dev/null +++ b/OpenSim/Server/Handlers/Estate/EstateDataRobustConnector.cs | |||
@@ -0,0 +1,345 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Net; | ||
32 | |||
33 | using Nini.Config; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | |||
37 | using OpenSim.Server.Base; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.ServiceAuth; | ||
41 | using OpenSim.Framework.Servers.HttpServer; | ||
42 | using OpenSim.Server.Handlers.Base; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers | ||
45 | { | ||
46 | public class EstateDataRobustConnector : ServiceConnector | ||
47 | { | ||
48 | private string m_ConfigName = "EstateService"; | ||
49 | |||
50 | public EstateDataRobustConnector(IConfigSource config, IHttpServer server, string configName) : | ||
51 | base(config, server, configName) | ||
52 | { | ||
53 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
54 | if (serverConfig == null) | ||
55 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); | ||
56 | |||
57 | string service = serverConfig.GetString("LocalServiceModule", | ||
58 | String.Empty); | ||
59 | |||
60 | if (service == String.Empty) | ||
61 | throw new Exception("No LocalServiceModule in config file"); | ||
62 | |||
63 | Object[] args = new Object[] { config }; | ||
64 | IEstateDataService e_service = ServerUtils.LoadPlugin<IEstateDataService>(service, args); | ||
65 | |||
66 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ; | ||
67 | |||
68 | server.AddStreamHandler(new EstateServerGetHandler(e_service, auth)); | ||
69 | server.AddStreamHandler(new EstateServerPostHandler(e_service, auth)); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | |||
74 | public class EstateServerGetHandler : BaseStreamHandler | ||
75 | { | ||
76 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
77 | |||
78 | IEstateDataService m_EstateService; | ||
79 | |||
80 | // Possibilities | ||
81 | // /estates/estate/?region=uuid&create=[t|f] | ||
82 | // /estates/estate/?eid=int | ||
83 | // /estates/?name=string | ||
84 | // /estates/?owner=uuid | ||
85 | // /estates/ (all) | ||
86 | // /estates/regions/?eid=int | ||
87 | |||
88 | public EstateServerGetHandler(IEstateDataService service, IServiceAuth auth) : | ||
89 | base("GET", "/estates", auth) | ||
90 | { | ||
91 | m_EstateService = service; | ||
92 | } | ||
93 | |||
94 | protected override byte[] ProcessRequest(string path, Stream request, | ||
95 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
96 | { | ||
97 | byte[] result = new byte[0]; | ||
98 | Dictionary<string, object> data = null; | ||
99 | |||
100 | string[] p = SplitParams(path); | ||
101 | |||
102 | // /estates/ (all) | ||
103 | // /estates/?name=string | ||
104 | // /estates/?owner=uuid | ||
105 | if (p.Length == 0) | ||
106 | data = GetEstates(httpRequest, httpResponse); | ||
107 | else | ||
108 | { | ||
109 | string resource = p[0]; | ||
110 | |||
111 | // /estates/estate/?region=uuid&create=[t|f] | ||
112 | // /estates/estate/?eid=int | ||
113 | if ("estate".Equals(resource)) | ||
114 | data = GetEstate(httpRequest, httpResponse); | ||
115 | // /estates/regions/?eid=int | ||
116 | else if ("regions".Equals(resource)) | ||
117 | data = GetRegions(httpRequest, httpResponse); | ||
118 | } | ||
119 | |||
120 | if (data == null) | ||
121 | data = new Dictionary<string, object>(); | ||
122 | |||
123 | string xmlString = ServerUtils.BuildXmlResponse(data); | ||
124 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
125 | |||
126 | } | ||
127 | |||
128 | private Dictionary<string, object> GetEstates(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
129 | { | ||
130 | // /estates/ (all) | ||
131 | // /estates/?name=string | ||
132 | // /estates/?owner=uuid | ||
133 | |||
134 | Dictionary<string, object> data = null; | ||
135 | string name = (string)httpRequest.Query["name"]; | ||
136 | string owner = (string)httpRequest.Query["owner"]; | ||
137 | |||
138 | if (!string.IsNullOrEmpty(name) || !string.IsNullOrEmpty(owner)) | ||
139 | { | ||
140 | List<int> estateIDs = null; | ||
141 | if (!string.IsNullOrEmpty(name)) | ||
142 | { | ||
143 | estateIDs = m_EstateService.GetEstates(name); | ||
144 | } | ||
145 | else if (!string.IsNullOrEmpty(owner)) | ||
146 | { | ||
147 | UUID ownerID = UUID.Zero; | ||
148 | if (UUID.TryParse(owner, out ownerID)) | ||
149 | estateIDs = m_EstateService.GetEstatesByOwner(ownerID); | ||
150 | } | ||
151 | |||
152 | if (estateIDs == null || (estateIDs != null && estateIDs.Count == 0)) | ||
153 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
154 | else | ||
155 | { | ||
156 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
157 | httpResponse.ContentType = "text/xml"; | ||
158 | data = new Dictionary<string, object>(); | ||
159 | int i = 0; | ||
160 | foreach (int id in estateIDs) | ||
161 | data["estate" + i++] = id; | ||
162 | } | ||
163 | } | ||
164 | else | ||
165 | { | ||
166 | List<EstateSettings> estates = m_EstateService.LoadEstateSettingsAll(); | ||
167 | if (estates == null || estates.Count == 0) | ||
168 | { | ||
169 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
170 | } | ||
171 | else | ||
172 | { | ||
173 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
174 | httpResponse.ContentType = "text/xml"; | ||
175 | data = new Dictionary<string, object>(); | ||
176 | int i = 0; | ||
177 | foreach (EstateSettings es in estates) | ||
178 | data["estate" + i++] = es.ToMap(); | ||
179 | |||
180 | } | ||
181 | } | ||
182 | |||
183 | return data; | ||
184 | } | ||
185 | |||
186 | private Dictionary<string, object> GetEstate(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
187 | { | ||
188 | // /estates/estate/?region=uuid&create=[t|f] | ||
189 | // /estates/estate/?eid=int | ||
190 | Dictionary<string, object> data = null; | ||
191 | string region = (string)httpRequest.Query["region"]; | ||
192 | string eid = (string)httpRequest.Query["eid"]; | ||
193 | |||
194 | EstateSettings estate = null; | ||
195 | |||
196 | if (!string.IsNullOrEmpty(region)) | ||
197 | { | ||
198 | UUID regionID = UUID.Zero; | ||
199 | if (UUID.TryParse(region, out regionID)) | ||
200 | { | ||
201 | string create = (string)httpRequest.Query["create"]; | ||
202 | bool createYN = false; | ||
203 | Boolean.TryParse(create, out createYN); | ||
204 | estate = m_EstateService.LoadEstateSettings(regionID, createYN); | ||
205 | } | ||
206 | } | ||
207 | else if (!string.IsNullOrEmpty(eid)) | ||
208 | { | ||
209 | int id = 0; | ||
210 | if (Int32.TryParse(eid, out id)) | ||
211 | estate = m_EstateService.LoadEstateSettings(id); | ||
212 | } | ||
213 | |||
214 | if (estate != null) | ||
215 | { | ||
216 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
217 | httpResponse.ContentType = "text/xml"; | ||
218 | data = estate.ToMap(); | ||
219 | } | ||
220 | else | ||
221 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
222 | |||
223 | return data; | ||
224 | } | ||
225 | |||
226 | private Dictionary<string, object> GetRegions(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
227 | { | ||
228 | // /estates/regions/?eid=int | ||
229 | Dictionary<string, object> data = null; | ||
230 | string eid = (string)httpRequest.Query["eid"]; | ||
231 | |||
232 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
233 | if (!string.IsNullOrEmpty(eid)) | ||
234 | { | ||
235 | int id = 0; | ||
236 | if (Int32.TryParse(eid, out id)) | ||
237 | { | ||
238 | List<UUID> regions = m_EstateService.GetRegions(id); | ||
239 | if (regions != null && regions.Count > 0) | ||
240 | { | ||
241 | data = new Dictionary<string, object>(); | ||
242 | int i = 0; | ||
243 | foreach (UUID uuid in regions) | ||
244 | data["region" + i++] = uuid.ToString(); | ||
245 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
246 | httpResponse.ContentType = "text/xml"; | ||
247 | } | ||
248 | } | ||
249 | } | ||
250 | |||
251 | return data; | ||
252 | } | ||
253 | } | ||
254 | |||
255 | public class EstateServerPostHandler : BaseStreamHandler | ||
256 | { | ||
257 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
258 | |||
259 | IEstateDataService m_EstateService; | ||
260 | |||
261 | // Possibilities | ||
262 | // /estates/estate/ (post an estate) | ||
263 | // /estates/estate/?eid=int®ion=uuid (link a region to an estate) | ||
264 | |||
265 | public EstateServerPostHandler(IEstateDataService service, IServiceAuth auth) : | ||
266 | base("POST", "/estates", auth) | ||
267 | { | ||
268 | m_EstateService = service; | ||
269 | } | ||
270 | |||
271 | protected override byte[] ProcessRequest(string path, Stream request, | ||
272 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
273 | { | ||
274 | byte[] result = new byte[0]; | ||
275 | Dictionary<string, object> data = null; | ||
276 | |||
277 | string[] p = SplitParams(path); | ||
278 | |||
279 | if (p.Length > 0) | ||
280 | { | ||
281 | string resource = p[0]; | ||
282 | |||
283 | // /estates/estate/ | ||
284 | // /estates/estate/?eid=int®ion=uuid | ||
285 | if ("estate".Equals(resource)) | ||
286 | { | ||
287 | StreamReader sr = new StreamReader(request); | ||
288 | string body = sr.ReadToEnd(); | ||
289 | sr.Close(); | ||
290 | body = body.Trim(); | ||
291 | |||
292 | Dictionary<string, object> requestData = ServerUtils.ParseQueryString(body); | ||
293 | |||
294 | data = UpdateEstate(requestData, httpRequest, httpResponse); | ||
295 | } | ||
296 | } | ||
297 | |||
298 | if (data == null) | ||
299 | data = new Dictionary<string, object>(); | ||
300 | |||
301 | string xmlString = ServerUtils.BuildXmlResponse(data); | ||
302 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
303 | |||
304 | } | ||
305 | |||
306 | private Dictionary<string, object> UpdateEstate(Dictionary<string, object> requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
307 | { | ||
308 | // /estates/estate/ | ||
309 | // /estates/estate/?eid=int®ion=uuid | ||
310 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
311 | string eid = (string)httpRequest.Query["eid"]; | ||
312 | string region = (string)httpRequest.Query["region"]; | ||
313 | |||
314 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
315 | |||
316 | if (string.IsNullOrEmpty(eid) && string.IsNullOrEmpty(region) && | ||
317 | requestData.ContainsKey("OP") && requestData["OP"] != null && "STORE".Equals(requestData["OP"])) | ||
318 | { | ||
319 | // /estates/estate/ | ||
320 | EstateSettings es = new EstateSettings(requestData); | ||
321 | m_EstateService.StoreEstateSettings(es); | ||
322 | //m_log.DebugFormat("[EstateServerPostHandler]: Store estate {0}", es.ToString()); | ||
323 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
324 | result["Result"] = true; | ||
325 | } | ||
326 | else if (!string.IsNullOrEmpty(region) && !string.IsNullOrEmpty(eid) && | ||
327 | requestData.ContainsKey("OP") && requestData["OP"] != null && "LINK".Equals(requestData["OP"])) | ||
328 | { | ||
329 | int id = 0; | ||
330 | UUID regionID = UUID.Zero; | ||
331 | if (UUID.TryParse(region, out regionID) && Int32.TryParse(eid, out id)) | ||
332 | { | ||
333 | m_log.DebugFormat("[EstateServerPostHandler]: Link region {0} to estate {1}", regionID, id); | ||
334 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
335 | result["Result"] = m_EstateService.LinkRegion(regionID, id); | ||
336 | } | ||
337 | } | ||
338 | else | ||
339 | m_log.WarnFormat("[EstateServerPostHandler]: something wrong with POST request {0}", httpRequest.RawUrl); | ||
340 | |||
341 | return result; | ||
342 | } | ||
343 | |||
344 | } | ||
345 | } | ||