aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/UserAccounts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs (renamed from OpenSim/Services/UserService/UserService.cs)53
-rw-r--r--OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs257
2 files changed, 276 insertions, 34 deletions
diff --git a/OpenSim/Services/UserService/UserService.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs
index e8b9fc3..f17a8de 100644
--- a/OpenSim/Services/UserService/UserService.cs
+++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs
@@ -26,51 +26,36 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Reflection;
30using Nini.Config; 29using Nini.Config;
31using OpenSim.Data; 30using OpenSim.Server.Base;
32using OpenSim.Services.Interfaces; 31using OpenSim.Services.Interfaces;
33using System.Collections.Generic; 32using OpenSim.Framework.Servers.HttpServer;
34using OpenMetaverse; 33using OpenSim.Server.Handlers.Base;
35 34
36namespace OpenSim.Services.UserAccountService 35namespace OpenSim.Server.Handlers.UserAccounts
37{ 36{
38 public class UserAccountService : UserAccountServiceBase, IUserAccountService 37 public class UserAccountServiceConnector : ServiceConnector
39 { 38 {
40 public UserAccountService(IConfigSource config) : base(config) 39 private IUserAccountService m_UserAccountService;
41 { 40 private string m_ConfigName = "UserAccountService";
42 }
43 41
44 public UserAccount GetUserAccount(UUID scopeID, string firstName, 42 public UserAccountServiceConnector(IConfigSource config, IHttpServer server, string configName) :
45 string lastName) 43 base(config, server, configName)
46 { 44 {
47 return null; 45 IConfig serverConfig = config.Configs[m_ConfigName];
48 } 46 if (serverConfig == null)
47 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
49 48
50 public UserAccount GetUserAccount(UUID scopeID, UUID userID) 49 string service = serverConfig.GetString("LocalServiceModule",
51 { 50 String.Empty);
52 return null;
53 }
54 51
55 public bool SetHomePosition(UserAccount data, UUID regionID, UUID regionSecret) 52 if (service == String.Empty)
56 { 53 throw new Exception("No LocalServiceModule in config file");
57 return false;
58 }
59 54
60 public bool SetUserAccount(UserAccount data, UUID principalID, string token) 55 Object[] args = new Object[] { config };
61 { 56 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(service, args);
62 return false;
63 }
64
65 public bool CreateUserAccount(UserAccount data, UUID principalID, string token)
66 {
67 return false;
68 }
69 57
70 public List<UserAccount> GetUserAccount(UUID scopeID, 58 server.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService));
71 string query)
72 {
73 return null;
74 } 59 }
75 } 60 }
76} 61}
diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs
new file mode 100644
index 0000000..544ffea
--- /dev/null
+++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs
@@ -0,0 +1,257 @@
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.Servers.HttpServer;
43using OpenMetaverse;
44
45namespace OpenSim.Server.Handlers.UserAccounts
46{
47 public class UserAccountServerPostHandler : BaseStreamHandler
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IUserAccountService m_UserAccountService;
52
53 public UserAccountServerPostHandler(IUserAccountService service) :
54 base("POST", "/accounts")
55 {
56 m_UserAccountService = service;
57 }
58
59 public override byte[] Handle(string path, Stream requestData,
60 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
61 {
62 StreamReader sr = new StreamReader(requestData);
63 string body = sr.ReadToEnd();
64 sr.Close();
65 body = body.Trim();
66
67 // We need to check the authorization header
68 //httpRequest.Headers["authorization"] ...
69
70 //m_log.DebugFormat("[XXX]: query String: {0}", body);
71
72 try
73 {
74 Dictionary<string, object> request =
75 ServerUtils.ParseQueryString(body);
76
77 if (!request.ContainsKey("METHOD"))
78 return FailureResult();
79
80 string method = request["METHOD"].ToString();
81
82 switch (method)
83 {
84 case "getaccount":
85 return GetAccount(request);
86 case "getaccounts":
87 return GetAccounts(request);
88 case "setaccount":
89 return StoreAccount(request);
90 }
91 m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method);
92 }
93 catch (Exception e)
94 {
95 m_log.Debug("[PRESENCE HANDLER]: Exception {0}" + e);
96 }
97
98 return FailureResult();
99
100 }
101
102 byte[] GetAccount(Dictionary<string, object> request)
103 {
104 UserAccount account = null;
105 UUID scopeID = UUID.Zero;
106 Dictionary<string, object> result = new Dictionary<string, object>();
107
108 if (!request.ContainsKey("ScopeID"))
109 {
110 result["result"] = "null";
111 return ResultToBytes(result);
112 }
113
114 if (!UUID.TryParse(request["ScopeID"].ToString(), out scopeID))
115 {
116 result["result"] = "null";
117 return ResultToBytes(result);
118 }
119
120 if (request.ContainsKey("UserID") && request["UserID"] != null)
121 {
122 UUID userID;
123 if (UUID.TryParse(request["UserID"].ToString(), out userID))
124 account = m_UserAccountService.GetUserAccount(scopeID, userID);
125 }
126
127 else if (request.ContainsKey("Email") && request["Email"] != null)
128 account = m_UserAccountService.GetUserAccount(scopeID, request["Email"].ToString());
129
130 else if (request.ContainsKey("FirstName") && request.ContainsKey("LastName") &&
131 request["FirstName"] != null && request["LastName"] != null)
132 account = m_UserAccountService.GetUserAccount(scopeID, request["FirstName"].ToString(), request["LastName"].ToString());
133
134 if (account == null)
135 result["result"] = "null";
136 else
137 result["result"] = account.ToKeyValuePairs();
138
139 return ResultToBytes(result);
140 }
141
142 byte[] GetAccounts(Dictionary<string, object> request)
143 {
144 if (!request.ContainsKey("ScopeID") || !request.ContainsKey("query"))
145 return FailureResult();
146
147 UUID scopeID = UUID.Zero;
148 if (!UUID.TryParse(request["ScopeID"].ToString(), out scopeID))
149 return FailureResult();
150
151 string query = request["query"].ToString();
152
153 List<UserAccount> accounts = m_UserAccountService.GetUserAccounts(scopeID, query);
154
155 Dictionary<string, object> result = new Dictionary<string, object>();
156 if ((accounts == null) || ((accounts != null) && (accounts.Count == 0)))
157 result["result"] = "null";
158 else
159 {
160 int i = 0;
161 foreach (UserAccount acc in accounts)
162 {
163 Dictionary<string, object> rinfoDict = acc.ToKeyValuePairs();
164 result["account" + i] = rinfoDict;
165 i++;
166 }
167 }
168
169 string xmlString = ServerUtils.BuildXmlResponse(result);
170 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
171 UTF8Encoding encoding = new UTF8Encoding();
172 return encoding.GetBytes(xmlString);
173 }
174
175 byte[] StoreAccount(Dictionary<string, object> request)
176 {
177 if (!request.ContainsKey("account"))
178 return FailureResult();
179 if (request["account"] == null)
180 return FailureResult();
181 if (!(request["account"] is Dictionary<string, object>))
182 return FailureResult();
183
184 UserAccount account = new UserAccount((Dictionary<string, object>)request["account"]);
185
186 if (m_UserAccountService.StoreUserAccount(account))
187 return SuccessResult();
188
189 return FailureResult();
190 }
191
192 private byte[] SuccessResult()
193 {
194 XmlDocument doc = new XmlDocument();
195
196 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
197 "", "");
198
199 doc.AppendChild(xmlnode);
200
201 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
202 "");
203
204 doc.AppendChild(rootElement);
205
206 XmlElement result = doc.CreateElement("", "result", "");
207 result.AppendChild(doc.CreateTextNode("Success"));
208
209 rootElement.AppendChild(result);
210
211 return DocToBytes(doc);
212 }
213
214 private byte[] FailureResult()
215 {
216 XmlDocument doc = new XmlDocument();
217
218 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
219 "", "");
220
221 doc.AppendChild(xmlnode);
222
223 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
224 "");
225
226 doc.AppendChild(rootElement);
227
228 XmlElement result = doc.CreateElement("", "result", "");
229 result.AppendChild(doc.CreateTextNode("Failure"));
230
231 rootElement.AppendChild(result);
232
233 return DocToBytes(doc);
234 }
235
236 private byte[] DocToBytes(XmlDocument doc)
237 {
238 MemoryStream ms = new MemoryStream();
239 XmlTextWriter xw = new XmlTextWriter(ms, null);
240 xw.Formatting = Formatting.Indented;
241 doc.WriteTo(xw);
242 xw.Flush();
243
244 return ms.ToArray();
245 }
246
247 private byte[] ResultToBytes(Dictionary<string, object> result)
248 {
249 string xmlString = ServerUtils.BuildXmlResponse(result);
250 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
251 UTF8Encoding encoding = new UTF8Encoding();
252 return encoding.GetBytes(xmlString);
253 }
254
255
256 }
257}