28 using System.Collections.Generic;
30 using System.Reflection;
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;
44 namespace OpenSim.Server.Handlers
48 private string m_ConfigName =
"EstateService";
51 base(config, server, configName)
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));
57 string service = serverConfig.GetString(
"LocalServiceModule",
60 if (service == String.Empty)
61 throw new Exception(
"No LocalServiceModule in config file");
63 Object[] args =
new Object[] { config };
66 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ;
89 base(
"GET",
"/estates", auth)
91 m_EstateService = service;
97 Dictionary<string, object> data = null;
99 string[] p = SplitParams(path);
105 data = GetEstates(httpRequest, httpResponse);
108 string resource = p[0];
112 if (
"estate".Equals(resource))
113 data = GetEstate(httpRequest, httpResponse);
115 else if (
"regions".Equals(resource))
116 data = GetRegions(httpRequest, httpResponse);
120 data =
new Dictionary<string, object>();
122 string xmlString = ServerUtils.BuildXmlResponse(data);
123 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
133 Dictionary<string, object> data = null;
134 string name = (string)httpRequest.
Query[
"name"];
135 string owner = (
string)httpRequest.Query[
"owner"];
137 if (!
string.IsNullOrEmpty(name) || !string.IsNullOrEmpty(owner))
139 List<int> estateIDs = null;
140 if (!
string.IsNullOrEmpty(name))
142 estateIDs = m_EstateService.GetEstates(name);
144 else if (!
string.IsNullOrEmpty(owner))
146 UUID ownerID = UUID.Zero;
147 if (UUID.TryParse(owner, out ownerID))
148 estateIDs = m_EstateService.GetEstatesByOwner(ownerID);
151 if (estateIDs == null || (estateIDs != null && estateIDs.Count == 0))
152 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
155 httpResponse.
StatusCode = (
int)HttpStatusCode.OK;
156 httpResponse.ContentType =
"text/xml";
157 data =
new Dictionary<string, object>();
159 foreach (
int id in estateIDs)
160 data[
"estate" + i++] = id;
165 List<EstateSettings> estates = m_EstateService.LoadEstateSettingsAll();
166 if (estates == null || estates.Count == 0)
168 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
172 httpResponse.StatusCode = (int)HttpStatusCode.OK;
174 data =
new Dictionary<string, object>();
177 data[
"estate" + i++] = es.ToMap();
189 Dictionary<string, object> data = null;
190 string region = (string)httpRequest.
Query[
"region"];
191 string eid = (
string)httpRequest.Query[
"eid"];
195 if (!
string.IsNullOrEmpty(region))
197 UUID regionID = UUID.Zero;
198 if (
UUID.TryParse(region, out regionID))
200 string create = (string)httpRequest.
Query[
"create"];
201 bool createYN =
false;
202 Boolean.TryParse(create, out createYN);
203 estate = m_EstateService.LoadEstateSettings(regionID, createYN);
206 else if (!
string.IsNullOrEmpty(eid))
209 if (Int32.TryParse(eid, out
id))
210 estate = m_EstateService.LoadEstateSettings(
id);
215 httpResponse.StatusCode = (int)HttpStatusCode.OK;
217 data = estate.
ToMap();
220 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
228 Dictionary<string, object> data = null;
229 string eid = (string)httpRequest.
Query[
"eid"];
231 httpResponse.
StatusCode = (
int)HttpStatusCode.NotFound;
232 if (!
string.IsNullOrEmpty(eid))
235 if (Int32.TryParse(eid, out
id))
237 List<UUID> regions = m_EstateService.GetRegions(id);
238 if (regions != null && regions.Count > 0)
240 data =
new Dictionary<string, object>();
242 foreach (UUID uuid
in regions)
243 data[
"region" + i++] = uuid.ToString();
244 httpResponse.StatusCode = (int)HttpStatusCode.OK;
256 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
265 base(
"POST",
"/estates", auth)
267 m_EstateService = service;
273 Dictionary<string, object> data = null;
275 string[] p = SplitParams(path);
279 string resource = p[0];
283 if (
"estate".Equals(resource))
285 StreamReader sr =
new StreamReader(request);
286 string body = sr.ReadToEnd();
290 Dictionary<string, object> requestData = ServerUtils.ParseQueryString(body);
292 data = UpdateEstate(requestData, httpRequest, httpResponse);
297 data =
new Dictionary<string, object>();
299 string xmlString = ServerUtils.BuildXmlResponse(data);
300 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
304 private Dictionary<string, object> UpdateEstate(Dictionary<string, object> requestData,
IOSHttpRequest httpRequest,
IOSHttpResponse httpResponse)
308 Dictionary<string, object> result =
new Dictionary<string, object>();
309 string eid = (string)httpRequest.
Query[
"eid"];
310 string region = (
string)httpRequest.Query[
"region"];
312 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
314 if (
string.IsNullOrEmpty(eid) && string.IsNullOrEmpty(region) &&
315 requestData.ContainsKey(
"OP") && requestData[
"OP"] != null &&
"STORE".Equals(requestData[
"OP"]))
319 m_EstateService.StoreEstateSettings(es);
321 httpResponse.StatusCode = (int)HttpStatusCode.OK;
322 result[
"Result"] =
true;
324 else if (!
string.IsNullOrEmpty(region) && !string.IsNullOrEmpty(eid) &&
325 requestData.ContainsKey(
"OP") && requestData[
"OP"] != null &&
"LINK".Equals(requestData[
"OP"]))
328 UUID regionID = UUID.Zero;
329 if (UUID.TryParse(region, out regionID) && Int32.TryParse(eid, out id))
331 m_log.DebugFormat(
"[EstateServerPostHandler]: Link region {0} to estate {1}", regionID, id);
332 httpResponse.StatusCode = (int)HttpStatusCode.OK;
333 result[
"Result"] = m_EstateService.LinkRegion(regionID,
id);
337 m_log.WarnFormat(
"[EstateServerPostHandler]: something wrong with POST request {0}", httpRequest.RawUrl);
override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
Dictionary< string, object > ToMap()
string ContentType
Content type property.
EstateDataRobustConnector(IConfigSource config, IHttpServer server, string configName)
EstateServerPostHandler(IEstateDataService service, IServiceAuth auth)
int StatusCode
HTTP status code.
Base streamed request handler.
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs.
EstateServerGetHandler(IEstateDataService service, IServiceAuth auth)
override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)