28 using System.Collections.Generic;
30 using System.Reflection;
37 using OpenSim.Framework;
38 using OpenSim.Framework.ServiceAuth;
39 using OpenSim.Services.Connectors;
40 using OpenSim.Services.Interfaces;
41 using OpenSim.Server.Base;
43 namespace OpenSim.Services.Connectors
47 private static readonly ILog m_log =
49 MethodBase.GetCurrentMethod().DeclaringType);
51 private string m_ServerURI = String.Empty;
52 private ExpiringCache<string, List<EstateSettings>> m_EstateCache =
new ExpiringCache<string, List<EstateSettings>>();
53 private const int EXPIRATION = 5 * 60;
62 IConfig gridConfig = source.Configs[
"EstateService"];
63 if (gridConfig == null)
65 m_log.Error(
"[ESTATE CONNECTOR]: EstateService missing from OpenSim.ini");
66 throw new Exception(
"Estate connector init error");
69 string serviceURI = gridConfig.GetString(
"EstateServerURI",
72 if (serviceURI == String.Empty)
74 m_log.Error(
"[ESTATE CONNECTOR]: No Server URI named in section EstateService");
75 throw new Exception(
"Estate connector init error");
77 m_ServerURI = serviceURI;
79 base.Initialise(source,
"EstateService");
82 #region IEstateDataService
86 string reply = string.Empty;
87 string uri = m_ServerURI +
"/estates";
89 reply = MakeRequest(
"GET", uri,
string.Empty);
90 if (String.IsNullOrEmpty(reply))
91 return new List<EstateSettings>();
93 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
95 List<EstateSettings> estates =
new List<EstateSettings>();
96 if (replyData != null && replyData.Count > 0)
98 m_log.DebugFormat(
"[ESTATE CONNECTOR]: LoadEstateSettingsAll returned {0} elements", replyData.Count);
99 Dictionary<string, object>.ValueCollection estateData = replyData.Values;
100 foreach (
object r
in estateData)
102 if (r is Dictionary<string, object>)
108 m_EstateCache.AddOrUpdate(
"estates", estates, EXPIRATION);
111 m_log.DebugFormat(
"[ESTATE CONNECTOR]: LoadEstateSettingsAll from {0} received null or zero response", uri);
119 List<int> eids =
new List<int>();
121 List<EstateSettings> estates = null;
122 if (!m_EstateCache.TryGetValue(
"estates", out estates))
123 LoadEstateSettingsAll();
134 List<EstateSettings> estates = null;
135 if (!m_EstateCache.TryGetValue(
"estates", out estates))
136 LoadEstateSettingsAll();
138 List<int> eids =
new List<int>();
149 List<EstateSettings> estates = null;
150 if (!m_EstateCache.TryGetValue(
"estates", out estates))
151 LoadEstateSettingsAll();
153 List<int> eids =
new List<int>();
163 string reply = string.Empty;
165 string uri = m_ServerURI +
"/estates/regions/?eid=" + estateID.ToString();
167 reply = MakeRequest(
"GET", uri,
string.Empty);
168 if (String.IsNullOrEmpty(reply))
169 return new List<UUID>();
171 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
173 List<UUID> regions =
new List<UUID>();
174 if (replyData != null && replyData.Count > 0)
176 m_log.DebugFormat(
"[ESTATE CONNECTOR]: GetRegions for estate {0} returned {1} elements", estateID, replyData.Count);
177 Dictionary<string, object>.ValueCollection data = replyData.Values;
178 foreach (
object r
in data)
180 UUID uuid = UUID.Zero;
181 if (UUID.TryParse(r.ToString(), out uuid))
186 m_log.DebugFormat(
"[ESTATE CONNECTOR]: GetRegions from {0} received null or zero response", uri);
193 string reply = string.Empty;
195 string uri = m_ServerURI + string.Format(
"/estates/estate/?region={0}&create={1}", regionID, create);
197 reply = MakeRequest(
"GET", uri,
string.Empty);
198 if (String.IsNullOrEmpty(reply))
201 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
203 if (replyData != null && replyData.Count > 0)
205 m_log.DebugFormat(
"[ESTATE CONNECTOR]: LoadEstateSettings({0}) returned {1} elements", regionID, replyData.Count);
210 m_log.DebugFormat(
"[ESTATE CONNECTOR]: LoadEstateSettings(regionID) from {0} received null or zero response", uri);
217 string reply = string.Empty;
219 string uri = m_ServerURI + string.Format(
"/estates/estate/?eid={0}", estateID);
221 reply = MakeRequest(
"GET", uri,
string.Empty);
222 if (String.IsNullOrEmpty(reply))
225 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
227 if (replyData != null && replyData.Count > 0)
229 m_log.DebugFormat(
"[ESTATE CONNECTOR]: LoadEstateSettings({0}) returned {1} elements", estateID, replyData.Count);
234 m_log.DebugFormat(
"[ESTATE CONNECTOR]: LoadEstateSettings(estateID) from {0} received null or zero response", uri);
252 string uri = m_ServerURI + (
"/estates/estate");
254 Dictionary<string, object> formdata = es.ToMap();
255 formdata[
"OP"] =
"STORE";
257 PostRequest(uri, formdata);
263 string uri = m_ServerURI + String.Format(
"/estates/estate/?eid={0}®ion={1}", estateID, regionID);
265 Dictionary<string, object> formdata =
new Dictionary<string, object>();
266 formdata[
"OP"] =
"LINK";
267 return PostRequest(uri, formdata);
270 private bool PostRequest(
string uri, Dictionary<string, object> sendData)
272 string reqString = ServerUtils.BuildQueryString(sendData);
274 string reply = MakeRequest(
"POST", uri, reqString);
275 if (String.IsNullOrEmpty(reply))
278 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
281 if (replyData != null && replyData.Count > 0)
283 if (replyData.ContainsKey(
"Result"))
285 if (Boolean.TryParse(replyData[
"Result"].ToString(), out result))
286 m_log.DebugFormat(
"[ESTATE CONNECTOR]: PostRequest {0} returned {1}", uri, result);
290 m_log.DebugFormat(
"[ESTATE CONNECTOR]: PostRequest {0} received null or zero response", uri);
306 private string MakeRequest(
string verb,
string uri,
string formdata)
308 string reply = string.Empty;
311 reply = SynchronousRestFormsRequester.MakeRequest(verb, uri, formdata, m_Auth);
313 catch (WebException e)
315 using (HttpWebResponse hwr = (HttpWebResponse)e.Response)
319 if (hwr.StatusCode == HttpStatusCode.NotFound)
320 m_log.Error(string.Format(
"[ESTATE CONNECTOR]: Resource {0} not found ", uri));
321 if (hwr.StatusCode == HttpStatusCode.Unauthorized)
322 m_log.Error(string.Format(
"[ESTATE CONNECTOR]: Web request {0} requires authentication ", uri));
325 m_log.Error(string.Format(
326 "[ESTATE CONNECTOR]: WebException for {0} {1} {2} ",
327 verb, uri, formdata, e));
332 m_log.DebugFormat(
"[ESTATE CONNECTOR]: Exception when contacting estate server at {0}: {1}", uri, e.Message);
List< UUID > GetRegions(int estateID)
Get the UUIDs of all the regions in an estate.
EstateSettings CreateNewEstate()
Forbidden operation
void StoreEstateSettings(EstateSettings es)
Store estate settings.
bool DeleteEstate(int estateID)
Forbidden operation
List< int > GetEstates(string search)
Get estate IDs.
List< int > GetEstatesAll()
Get the IDs of all estates.
EstateDataRemoteConnector(IConfigSource source)
List< int > GetEstatesByOwner(UUID ownerID)
Get the IDs of all estates owned by the given user.
EstateSettings LoadEstateSettings(UUID regionID, bool create)
Load estate settings for a region.
EstateSettings LoadEstateSettings(int estateID)
Load estate settings for an estate ID.
List< EstateSettings > LoadEstateSettingsAll()
Load/Get all estate settings.
virtual void Initialise(IConfigSource source)
bool LinkRegion(UUID regionID, int estateID)
Link a region to an estate.