aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs')
-rw-r--r--OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs206
1 files changed, 206 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs
new file mode 100644
index 0000000..713b755
--- /dev/null
+++ b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs
@@ -0,0 +1,206 @@
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
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using System.Collections.Generic;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Framework;
42using OpenSim.Framework.ServiceAuth;
43using OpenSim.Framework.Servers.HttpServer;
44using OpenMetaverse;
45
46namespace OpenSim.Server.Handlers.AgentPreferences
47{
48 public class AgentPreferencesServerPostHandler : BaseStreamHandler
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private IAgentPreferencesService m_AgentPreferencesService;
53
54 public AgentPreferencesServerPostHandler(IAgentPreferencesService service, IServiceAuth auth) :
55 base("POST", "/agentprefs", auth)
56 {
57 m_AgentPreferencesService = service;
58 }
59
60 protected override byte[] ProcessRequest(string path, Stream requestData,
61 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
62 {
63 StreamReader sr = new StreamReader(requestData);
64 string body = sr.ReadToEnd();
65 sr.Close();
66 body = body.Trim();
67
68 //m_log.DebugFormat("[XXX]: query String: {0}", body);
69
70 try
71 {
72 Dictionary<string, object> request =
73 ServerUtils.ParseQueryString(body);
74
75 if (!request.ContainsKey("METHOD"))
76 return FailureResult();
77
78 string method = request["METHOD"].ToString();
79
80 switch (method)
81 {
82 case "getagentprefs":
83 return GetAgentPrefs(request);
84 case "setagentprefs":
85 return SetAgentPrefs(request);
86 case "getagentlang":
87 return GetAgentLang(request);
88 }
89 m_log.DebugFormat("[AGENT PREFERENCES HANDLER]: unknown method request: {0}", method);
90 }
91 catch (Exception e)
92 {
93 m_log.DebugFormat("[AGENT PREFERENCES HANDLER]: Exception {0}", e);
94 }
95
96 return FailureResult();
97 }
98
99 byte[] GetAgentPrefs(Dictionary<string, object> request)
100 {
101 if (!request.ContainsKey("UserID"))
102 return FailureResult();
103
104 UUID userID;
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();
110
111 string xmlString = ServerUtils.BuildXmlResponse(result);
112
113 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
114 }
115
116 byte[] SetAgentPrefs(Dictionary<string, object> request)
117 {
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"))
121 {
122 return FailureResult();
123 }
124
125 UUID userID;
126 if (!UUID.TryParse(request["PrincipalID"].ToString(), out userID))
127 return FailureResult();
128
129 AgentPrefs data = new AgentPrefs(userID);
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());
137
138 return m_AgentPreferencesService.StoreAgentPreferences(data) ? SuccessResult() : FailureResult();
139 }
140
141 byte[] GetAgentLang(Dictionary<string, object> request)
142 {
143 if (!request.ContainsKey("UserID"))
144 return FailureResult();
145 UUID userID;
146 if (!UUID.TryParse(request["UserID"].ToString(), out userID))
147 return FailureResult();
148
149 string lang = "en-us";
150 AgentPrefs prefs = m_AgentPreferencesService.GetAgentPreferences(userID);
151 if (prefs != null)
152 {
153 if (prefs.LanguageIsPublic)
154 lang = prefs.Language;
155 }
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);
160 }
161
162 private byte[] SuccessResult()
163 {
164 XmlDocument doc = new XmlDocument();
165
166 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
167 "", "");
168
169 doc.AppendChild(xmlnode);
170
171 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
172 "");
173
174 doc.AppendChild(rootElement);
175
176 XmlElement result = doc.CreateElement("", "result", "");
177 result.AppendChild(doc.CreateTextNode("Success"));
178
179 rootElement.AppendChild(result);
180
181 return Util.DocToBytes(doc);
182 }
183
184 private byte[] FailureResult()
185 {
186 XmlDocument doc = new XmlDocument();
187
188 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
189 "", "");
190
191 doc.AppendChild(xmlnode);
192
193 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
194 "");
195
196 doc.AppendChild(rootElement);
197
198 XmlElement result = doc.CreateElement("", "result", "");
199 result.AppendChild(doc.CreateTextNode("Failure"));
200
201 rootElement.AppendChild(result);
202
203 return Util.DocToBytes(doc);
204 }
205 }
206}