31 using System.Reflection;
35 using System.Text.RegularExpressions;
37 using System.Xml.Serialization;
38 using System.Collections.Generic;
39 using OpenSim.Server.Base;
40 using OpenSim.Services.Interfaces;
41 using OpenSim.Framework;
42 using OpenSim.Framework.ServiceAuth;
43 using OpenSim.Framework.Servers.HttpServer;
46 namespace OpenSim.Server.Handlers.AgentPreferences
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55 base(
"POST",
"/agentprefs", auth)
57 m_AgentPreferencesService = service;
63 StreamReader sr =
new StreamReader(requestData);
64 string body = sr.ReadToEnd();
72 Dictionary<string, object> request =
73 ServerUtils.ParseQueryString(body);
75 if (!request.ContainsKey(
"METHOD"))
76 return FailureResult();
78 string method = request[
"METHOD"].ToString();
83 return GetAgentPrefs(request);
85 return SetAgentPrefs(request);
87 return GetAgentLang(request);
89 m_log.DebugFormat(
"[AGENT PREFERENCES HANDLER]: unknown method request: {0}", method);
93 m_log.DebugFormat(
"[AGENT PREFERENCES HANDLER]: Exception {0}", e);
96 return FailureResult();
99 byte[] GetAgentPrefs(Dictionary<string, object> request)
101 if (!request.ContainsKey(
"UserID"))
102 return FailureResult();
105 if (!UUID.TryParse(request[
"UserID"].ToString(), out userID))
106 return FailureResult();
107 AgentPrefs prefs = m_AgentPreferencesService.GetAgentPreferences(userID);
108 Dictionary<string, object> result =
new Dictionary<string, object>();
109 result = prefs.ToKeyValuePairs();
111 string xmlString = ServerUtils.BuildXmlResponse(result);
113 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
116 byte[] SetAgentPrefs(Dictionary<string, object> request)
118 if (!request.ContainsKey(
"PrincipalID") || !request.ContainsKey(
"AccessPrefs") || !request.ContainsKey(
"HoverHeight")
119 || !request.ContainsKey(
"Language") || !request.ContainsKey(
"LanguageIsPublic") || !request.ContainsKey(
"PermEveryone")
120 || !request.ContainsKey(
"PermGroup") || !request.ContainsKey(
"PermNextOwner"))
122 return FailureResult();
126 if (!UUID.TryParse(request[
"PrincipalID"].ToString(), out userID))
127 return FailureResult();
130 data.AccessPrefs = request[
"AccessPrefs"].ToString();
131 data.HoverHeight = double.Parse(request[
"HoverHeight"].ToString());
132 data.Language = request[
"Language"].ToString();
133 data.LanguageIsPublic = bool.Parse(request[
"LanguageIsPublic"].ToString());
134 data.PermEveryone = int.Parse(request[
"PermEveryone"].ToString());
135 data.PermGroup = int.Parse(request[
"PermGroup"].ToString());
136 data.PermNextOwner = int.Parse(request[
"PermNextOwner"].ToString());
138 return m_AgentPreferencesService.StoreAgentPreferences(data) ? SuccessResult() : FailureResult();
141 byte[] GetAgentLang(Dictionary<string, object> request)
143 if (!request.ContainsKey(
"UserID"))
144 return FailureResult();
146 if (!UUID.TryParse(request[
"UserID"].ToString(), out userID))
147 return FailureResult();
149 string lang =
"en-us";
150 AgentPrefs prefs = m_AgentPreferencesService.GetAgentPreferences(userID);
154 lang = prefs.Language;
156 Dictionary<string, object> result =
new Dictionary<string, object>();
157 result[
"Language"] = lang;
158 string xmlString = ServerUtils.BuildXmlResponse(result);
159 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
162 private byte[] SuccessResult()
164 XmlDocument doc =
new XmlDocument();
166 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
169 doc.AppendChild(xmlnode);
171 XmlElement rootElement = doc.CreateElement(
"",
"ServerResponse",
174 doc.AppendChild(rootElement);
176 XmlElement result = doc.CreateElement(
"",
"result",
"");
177 result.AppendChild(doc.CreateTextNode(
"Success"));
179 rootElement.AppendChild(result);
181 return Util.DocToBytes(doc);
184 private byte[] FailureResult()
186 XmlDocument doc =
new XmlDocument();
188 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
191 doc.AppendChild(xmlnode);
193 XmlElement rootElement = doc.CreateElement(
"",
"ServerResponse",
196 doc.AppendChild(rootElement);
198 XmlElement result = doc.CreateElement(
"",
"result",
"");
199 result.AppendChild(doc.CreateTextNode(
"Failure"));
201 rootElement.AppendChild(result);
203 return Util.DocToBytes(doc);
override byte[] ProcessRequest(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
Base streamed request handler.
Interactive OpenSim region server
AgentPreferencesServerPostHandler(IAgentPreferencesService service, IServiceAuth auth)