aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/AgentPreferences
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs206
-rw-r--r--OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs (renamed from OpenSim/ApplicationPlugins/Rest/Inventory/IRestHandler.cs)47
2 files changed, 232 insertions, 21 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}
diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/IRestHandler.cs b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs
index a88fe88..a581ea2 100644
--- a/OpenSim/ApplicationPlugins/Rest/Inventory/IRestHandler.cs
+++ b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs
@@ -25,35 +25,40 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28
29using System;
30using Nini.Config;
31using OpenSim.Server.Base;
32using OpenSim.Services.Interfaces;
33using OpenSim.Framework.ServiceAuth;
28using OpenSim.Framework.Servers.HttpServer; 34using OpenSim.Framework.Servers.HttpServer;
35using OpenSim.Server.Handlers.Base;
29 36
30namespace OpenSim.ApplicationPlugins.Rest.Inventory 37namespace OpenSim.Server.Handlers.AgentPreferences
31{ 38{
39 public class AgentPreferencesServiceConnector : ServiceConnector
40 {
41 private IAgentPreferencesService m_AgentPreferencesService;
42 private string m_ConfigName = "AgentPreferencesService";
32 43
33 /// <remarks> 44 public AgentPreferencesServiceConnector(IConfigSource config, IHttpServer server, string configName) :
34 /// The handler delegates are not noteworthy. The allocator allows 45 base(config, server, configName)
35 /// a given handler to optionally subclass the base RequestData 46 {
36 /// structure to carry any locally required per-request state 47 IConfig serverConfig = config.Configs[m_ConfigName];
37 /// needed. 48 if (serverConfig == null)
38 /// </remarks> 49 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
39 50
40 public delegate void RestMethodHandler(RequestData rdata); 51 string service = serverConfig.GetString("LocalServiceModule", String.Empty);
41 public delegate RequestData RestMethodAllocator(OSHttpRequest request, OSHttpResponse response, string path);
42 52
43 /// <summary> 53 if (String.IsNullOrWhiteSpace(service))
44 /// This interface exports the generic plugin-handling services 54 throw new Exception("No LocalServiceModule in config file");
45 /// available to each loaded REST services module (IRest implementation)
46 /// </summary>
47 55
48 internal interface IRestHandler 56 Object[] args = new Object[] { config };
49 { 57 m_AgentPreferencesService = ServerUtils.LoadPlugin<IAgentPreferencesService>(service, args);
50 58
51 string MsgId { get; } 59 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ;
52 string RequestId { get; }
53
54 void AddPathHandler(RestMethodHandler mh, string path, RestMethodAllocator ma);
55 void AddStreamHandler(string httpMethod, string path, RestMethod method);
56 60
61 server.AddStreamHandler(new AgentPreferencesServerPostHandler(m_AgentPreferencesService, auth));
62 }
57 } 63 }
58
59} 64}