clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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  
28 using log4net;
29 using System;
30 using System.Collections.Generic;
31 using System.IO;
32 using System.Reflection;
33 using Nini.Config;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Communications;
36 using OpenSim.Framework.ServiceAuth;
37 using OpenSim.Server.Base;
38 using OpenSim.Services.Interfaces;
39 using OpenMetaverse;
40  
41 namespace OpenSim.Services.Connectors
42 {
43 public class UserAccountServicesConnector : BaseServiceConnector, IUserAccountService
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(
47 MethodBase.GetCurrentMethod().DeclaringType);
48  
49 private string m_ServerURI = String.Empty;
50  
51 public UserAccountServicesConnector()
52 {
53 }
54  
55 public UserAccountServicesConnector(string serverURI)
56 {
57 m_ServerURI = serverURI.TrimEnd('/');
58 }
59  
60 public UserAccountServicesConnector(IConfigSource source)
61 {
62 Initialise(source);
63 }
64  
65 public virtual void Initialise(IConfigSource source)
66 {
67 IConfig assetConfig = source.Configs["UserAccountService"];
68 if (assetConfig == null)
69 {
70 m_log.Error("[ACCOUNT CONNECTOR]: UserAccountService missing from OpenSim.ini");
71 throw new Exception("User account connector init error");
72 }
73  
74 string serviceURI = assetConfig.GetString("UserAccountServerURI",
75 String.Empty);
76  
77 if (serviceURI == String.Empty)
78 {
79 m_log.Error("[ACCOUNT CONNECTOR]: No Server URI named in section UserAccountService");
80 throw new Exception("User account connector init error");
81 }
82 m_ServerURI = serviceURI;
83  
84 base.Initialise(source, "UserAccountService");
85 }
86  
87 public virtual UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
88 {
89 Dictionary<string, object> sendData = new Dictionary<string, object>();
90 //sendData["SCOPEID"] = scopeID.ToString();
91 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
92 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
93 sendData["METHOD"] = "getaccount";
94  
95 sendData["ScopeID"] = scopeID;
96 sendData["FirstName"] = firstName.ToString();
97 sendData["LastName"] = lastName.ToString();
98  
99 return SendAndGetReply(sendData);
100 }
101  
102 public virtual UserAccount GetUserAccount(UUID scopeID, string email)
103 {
104 Dictionary<string, object> sendData = new Dictionary<string, object>();
105 //sendData["SCOPEID"] = scopeID.ToString();
106 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
107 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
108 sendData["METHOD"] = "getaccount";
109  
110 sendData["ScopeID"] = scopeID;
111 sendData["Email"] = email;
112  
113 return SendAndGetReply(sendData);
114 }
115  
116 public virtual UserAccount GetUserAccount(UUID scopeID, UUID userID)
117 {
118 //m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUserAccount {0}", userID);
119 Dictionary<string, object> sendData = new Dictionary<string, object>();
120 //sendData["SCOPEID"] = scopeID.ToString();
121 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
122 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
123 sendData["METHOD"] = "getaccount";
124  
125 sendData["ScopeID"] = scopeID;
126 sendData["UserID"] = userID.ToString();
127  
128 return SendAndGetReply(sendData);
129 }
130  
131 public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
132 {
133 Dictionary<string, object> sendData = new Dictionary<string, object>();
134 //sendData["SCOPEID"] = scopeID.ToString();
135 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
136 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
137 sendData["METHOD"] = "getaccounts";
138  
139 sendData["ScopeID"] = scopeID.ToString();
140 sendData["query"] = query;
141  
142 string reply = string.Empty;
143 string reqString = ServerUtils.BuildQueryString(sendData);
144 string uri = m_ServerURI + "/accounts";
145 // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString);
146 try
147 {
148 reply = SynchronousRestFormsRequester.MakeRequest("POST",
149 uri,
150 reqString,
151 m_Auth);
152 if (reply == null || (reply != null && reply == string.Empty))
153 {
154 m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received null or empty reply");
155 return null;
156 }
157 }
158 catch (Exception e)
159 {
160 m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message);
161 }
162  
163 List<UserAccount> accounts = new List<UserAccount>();
164  
165 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
166  
167 if (replyData != null)
168 {
169 if (replyData.ContainsKey("result") && replyData["result"].ToString() == "null")
170 {
171 return accounts;
172 }
173  
174 Dictionary<string, object>.ValueCollection accountList = replyData.Values;
175 //m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count);
176 foreach (object acc in accountList)
177 {
178 if (acc is Dictionary<string, object>)
179 {
180 UserAccount pinfo = new UserAccount((Dictionary<string, object>)acc);
181 accounts.Add(pinfo);
182 }
183 else
184 m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received invalid response type {0}",
185 acc.GetType());
186 }
187 }
188 else
189 m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUserAccounts received null response");
190  
191 return accounts;
192 }
193  
194 public void InvalidateCache(UUID userID)
195 {
196 }
197  
198 public virtual bool StoreUserAccount(UserAccount data)
199 {
200 Dictionary<string, object> sendData = new Dictionary<string, object>();
201 //sendData["SCOPEID"] = scopeID.ToString();
202 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
203 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
204 sendData["METHOD"] = "setaccount";
205  
206 Dictionary<string, object> structData = data.ToKeyValuePairs();
207  
208 foreach (KeyValuePair<string, object> kvp in structData)
209 {
210 if (kvp.Value == null)
211 {
212 m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Null value for {0}", kvp.Key);
213 continue;
214 }
215 sendData[kvp.Key] = kvp.Value.ToString();
216 }
217  
218 return SendAndGetBoolReply(sendData);
219 }
220  
221 private UserAccount SendAndGetReply(Dictionary<string, object> sendData)
222 {
223 string reply = string.Empty;
224 string reqString = ServerUtils.BuildQueryString(sendData);
225 string uri = m_ServerURI + "/accounts";
226 // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString);
227 try
228 {
229 reply = SynchronousRestFormsRequester.MakeRequest("POST",
230 uri,
231 reqString,
232 m_Auth);
233 if (reply == null || (reply != null && reply == string.Empty))
234 {
235 m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccount received null or empty reply");
236 return null;
237 }
238 }
239 catch (Exception e)
240 {
241 m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message);
242 }
243  
244 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
245 UserAccount account = null;
246  
247 if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null))
248 {
249 if (replyData["result"] is Dictionary<string, object>)
250 {
251 account = new UserAccount((Dictionary<string, object>)replyData["result"]);
252 }
253 }
254  
255 return account;
256  
257 }
258  
259 private bool SendAndGetBoolReply(Dictionary<string, object> sendData)
260 {
261 string reqString = ServerUtils.BuildQueryString(sendData);
262 string uri = m_ServerURI + "/accounts";
263 // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString);
264 try
265 {
266 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
267 uri,
268 reqString,
269 m_Auth);
270 if (reply != string.Empty)
271 {
272 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
273  
274 if (replyData.ContainsKey("result"))
275 {
276 if (replyData["result"].ToString().ToLower() == "success")
277 return true;
278 else
279 return false;
280 }
281 else
282 m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount reply data does not contain result field");
283  
284 }
285 else
286 m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount received empty reply");
287 }
288 catch (Exception e)
289 {
290 m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message);
291 }
292  
293 return false;
294 }
295  
296 }
297 }