aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-05-09 23:25:01 +0100
committerJustin Clark-Casey (justincc)2012-05-09 23:25:01 +0100
commitd8a78374aa11c5460d6e58a6f4110fca61dfded4 (patch)
tree4214094c092eeff11f2dcd60f71cfc294ab887be /OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs
parentImprove logging on the prim inventory script asset request path for future use. (diff)
downloadopensim-SC_OLD-d8a78374aa11c5460d6e58a6f4110fca61dfded4.zip
opensim-SC_OLD-d8a78374aa11c5460d6e58a6f4110fca61dfded4.tar.gz
opensim-SC_OLD-d8a78374aa11c5460d6e58a6f4110fca61dfded4.tar.bz2
opensim-SC_OLD-d8a78374aa11c5460d6e58a6f4110fca61dfded4.tar.xz
Where necessary, rename OpenSim/Services/Connectors/*.cs files to reflect the actual class names.
This is usually because the file name was singular (*Service*) but the class name was plural (*Services*). This is to make configuration easier rather than having to look in the c# code itself to find the slightly different name of the connector. This does not affect existing configuration since the files are being renamed rather than the classes.
Diffstat (limited to 'OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs287
1 files changed, 287 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs b/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs
new file mode 100644
index 0000000..6d5ce28
--- /dev/null
+++ b/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs
@@ -0,0 +1,287 @@
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 log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Server.Base;
37using OpenSim.Services.Interfaces;
38using OpenMetaverse;
39
40namespace OpenSim.Services.Connectors
41{
42 public class UserAccountServicesConnector : IUserAccountService
43 {
44 private static readonly ILog m_log =
45 LogManager.GetLogger(
46 MethodBase.GetCurrentMethod().DeclaringType);
47
48 private string m_ServerURI = String.Empty;
49
50 public UserAccountServicesConnector()
51 {
52 }
53
54 public UserAccountServicesConnector(string serverURI)
55 {
56 m_ServerURI = serverURI.TrimEnd('/');
57 }
58
59 public UserAccountServicesConnector(IConfigSource source)
60 {
61 Initialise(source);
62 }
63
64 public virtual void Initialise(IConfigSource source)
65 {
66 IConfig assetConfig = source.Configs["UserAccountService"];
67 if (assetConfig == null)
68 {
69 m_log.Error("[ACCOUNT CONNECTOR]: UserAccountService missing from OpenSim.ini");
70 throw new Exception("User account connector init error");
71 }
72
73 string serviceURI = assetConfig.GetString("UserAccountServerURI",
74 String.Empty);
75
76 if (serviceURI == String.Empty)
77 {
78 m_log.Error("[ACCOUNT CONNECTOR]: No Server URI named in section UserAccountService");
79 throw new Exception("User account connector init error");
80 }
81 m_ServerURI = serviceURI;
82 }
83
84 public virtual UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
85 {
86 Dictionary<string, object> sendData = new Dictionary<string, object>();
87 //sendData["SCOPEID"] = scopeID.ToString();
88 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
89 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
90 sendData["METHOD"] = "getaccount";
91
92 sendData["ScopeID"] = scopeID;
93 sendData["FirstName"] = firstName.ToString();
94 sendData["LastName"] = lastName.ToString();
95
96 return SendAndGetReply(sendData);
97 }
98
99 public virtual UserAccount GetUserAccount(UUID scopeID, string email)
100 {
101 Dictionary<string, object> sendData = new Dictionary<string, object>();
102 //sendData["SCOPEID"] = scopeID.ToString();
103 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
104 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
105 sendData["METHOD"] = "getaccount";
106
107 sendData["ScopeID"] = scopeID;
108 sendData["Email"] = email;
109
110 return SendAndGetReply(sendData);
111 }
112
113 public virtual UserAccount GetUserAccount(UUID scopeID, UUID userID)
114 {
115 //m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUserAccount {0}", userID);
116 Dictionary<string, object> sendData = new Dictionary<string, object>();
117 //sendData["SCOPEID"] = scopeID.ToString();
118 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
119 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
120 sendData["METHOD"] = "getaccount";
121
122 sendData["ScopeID"] = scopeID;
123 sendData["UserID"] = userID.ToString();
124
125 return SendAndGetReply(sendData);
126 }
127
128 public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
129 {
130 Dictionary<string, object> sendData = new Dictionary<string, object>();
131 //sendData["SCOPEID"] = scopeID.ToString();
132 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
133 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
134 sendData["METHOD"] = "getaccounts";
135
136 sendData["ScopeID"] = scopeID.ToString();
137 sendData["query"] = query;
138
139 string reply = string.Empty;
140 string reqString = ServerUtils.BuildQueryString(sendData);
141 string uri = m_ServerURI + "/accounts";
142 // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString);
143 try
144 {
145 reply = SynchronousRestFormsRequester.MakeRequest("POST",
146 uri,
147 reqString);
148 if (reply == null || (reply != null && reply == string.Empty))
149 {
150 m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received null or empty reply");
151 return null;
152 }
153 }
154 catch (Exception e)
155 {
156 m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message);
157 }
158
159 List<UserAccount> accounts = new List<UserAccount>();
160
161 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
162
163 if (replyData != null)
164 {
165 if (replyData.ContainsKey("result") && replyData.ContainsKey("result").ToString() == "null")
166 {
167 return accounts;
168 }
169
170 Dictionary<string, object>.ValueCollection accountList = replyData.Values;
171 //m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count);
172 foreach (object acc in accountList)
173 {
174 if (acc is Dictionary<string, object>)
175 {
176 UserAccount pinfo = new UserAccount((Dictionary<string, object>)acc);
177 accounts.Add(pinfo);
178 }
179 else
180 m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received invalid response type {0}",
181 acc.GetType());
182 }
183 }
184 else
185 m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUserAccounts received null response");
186
187 return accounts;
188 }
189
190 public virtual bool StoreUserAccount(UserAccount data)
191 {
192 Dictionary<string, object> sendData = new Dictionary<string, object>();
193 //sendData["SCOPEID"] = scopeID.ToString();
194 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
195 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
196 sendData["METHOD"] = "setaccount";
197
198 Dictionary<string, object> structData = data.ToKeyValuePairs();
199
200 foreach (KeyValuePair<string, object> kvp in structData)
201 {
202 if (kvp.Value == null)
203 {
204 m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Null value for {0}", kvp.Key);
205 continue;
206 }
207 sendData[kvp.Key] = kvp.Value.ToString();
208 }
209
210 return SendAndGetBoolReply(sendData);
211 }
212
213 private UserAccount SendAndGetReply(Dictionary<string, object> sendData)
214 {
215 string reply = string.Empty;
216 string reqString = ServerUtils.BuildQueryString(sendData);
217 string uri = m_ServerURI + "/accounts";
218 // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString);
219 try
220 {
221 reply = SynchronousRestFormsRequester.MakeRequest("POST",
222 uri,
223 reqString);
224 if (reply == null || (reply != null && reply == string.Empty))
225 {
226 m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccount received null or empty reply");
227 return null;
228 }
229 }
230 catch (Exception e)
231 {
232 m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message);
233 }
234
235 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
236 UserAccount account = null;
237
238 if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null))
239 {
240 if (replyData["result"] is Dictionary<string, object>)
241 {
242 account = new UserAccount((Dictionary<string, object>)replyData["result"]);
243 }
244 }
245
246 return account;
247
248 }
249
250 private bool SendAndGetBoolReply(Dictionary<string, object> sendData)
251 {
252 string reqString = ServerUtils.BuildQueryString(sendData);
253 string uri = m_ServerURI + "/accounts";
254 // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString);
255 try
256 {
257 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
258 uri,
259 reqString);
260 if (reply != string.Empty)
261 {
262 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
263
264 if (replyData.ContainsKey("result"))
265 {
266 if (replyData["result"].ToString().ToLower() == "success")
267 return true;
268 else
269 return false;
270 }
271 else
272 m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount reply data does not contain result field");
273
274 }
275 else
276 m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount received empty reply");
277 }
278 catch (Exception e)
279 {
280 m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message);
281 }
282
283 return false;
284 }
285
286 }
287}