aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/UserAccountService
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/UserAccountService')
-rw-r--r--OpenSim/Services/UserAccountService/UserAccountService.cs184
-rw-r--r--OpenSim/Services/UserAccountService/UserAccountServiceBase.cs73
2 files changed, 257 insertions, 0 deletions
diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs
new file mode 100644
index 0000000..c14651d
--- /dev/null
+++ b/OpenSim/Services/UserAccountService/UserAccountService.cs
@@ -0,0 +1,184 @@
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 System;
29using System.Reflection;
30using Nini.Config;
31using OpenSim.Data;
32using OpenSim.Services.Interfaces;
33using System.Collections.Generic;
34using OpenMetaverse;
35
36namespace OpenSim.Services.UserAccountService
37{
38 public class UserAccountService : UserAccountServiceBase, IUserAccountService
39 {
40 public UserAccountService(IConfigSource config) : base(config)
41 {
42 }
43
44 public UserAccount GetUserAccount(UUID scopeID, string firstName,
45 string lastName)
46 {
47 UserAccountData[] d;
48
49 if (scopeID != UUID.Zero)
50 {
51 d = m_Database.Get(
52 new string[] {"ScopeID", "FirstName", "LastName"},
53 new string[] {scopeID.ToString(), firstName, lastName});
54 }
55 else
56 {
57 d = m_Database.Get(
58 new string[] {"FirstName", "LastName"},
59 new string[] {firstName, lastName});
60 }
61
62 if (d.Length < 1)
63 return null;
64
65 return MakeUserAccount(d[0]);
66 }
67
68 private UserAccount MakeUserAccount(UserAccountData d)
69 {
70 UserAccount u = new UserAccount();
71 u.FirstName = d.FirstName;
72 u.LastName = d.LastName;
73 u.PrincipalID = d.PrincipalID;
74 u.ScopeID = d.ScopeID;
75 u.Email = d.Data["Email"].ToString();
76 u.Created = Convert.ToInt32(d.Data["Created"].ToString());
77
78 string[] URLs = d.Data["ServiceURLs"].ToString().Split(new char[] {' '});
79 u.ServiceURLs = new Dictionary<string, object>();
80
81 foreach(string url in URLs)
82 {
83 string[] parts = url.Split(new char[] {'='});
84
85 if (parts.Length != 2)
86 continue;
87
88 string name = System.Web.HttpUtility.UrlDecode(parts[0]);
89 string val = System.Web.HttpUtility.UrlDecode(parts[1]);
90
91 u.ServiceURLs[name] = val;
92 }
93
94 return u;
95 }
96
97 public UserAccount GetUserAccount(UUID scopeID, string email)
98 {
99 UserAccountData[] d;
100
101 if (scopeID != UUID.Zero)
102 {
103 d = m_Database.Get(
104 new string[] {"ScopeID", "Email"},
105 new string[] {scopeID.ToString(), email});
106 }
107 else
108 {
109 d = m_Database.Get(
110 new string[] {"Email"},
111 new string[] {email});
112 }
113
114 if (d.Length < 1)
115 return null;
116
117 return MakeUserAccount(d[0]);
118 }
119
120 public UserAccount GetUserAccount(UUID scopeID, UUID principalID)
121 {
122 UserAccountData[] d;
123
124 if (scopeID != UUID.Zero)
125 {
126 d = m_Database.Get(
127 new string[] {"ScopeID", "PrincipalID"},
128 new string[] {scopeID.ToString(), principalID.ToString()});
129 }
130 else
131 {
132 d = m_Database.Get(
133 new string[] {"PrincipalID"},
134 new string[] {principalID.ToString()});
135 }
136
137 if (d.Length < 1)
138 return null;
139
140 return MakeUserAccount(d[0]);
141 }
142
143 public bool StoreUserAccount(UserAccount data)
144 {
145 UserAccountData d = new UserAccountData();
146
147 d.FirstName = data.FirstName;
148 d.LastName = data.LastName;
149 d.PrincipalID = data.PrincipalID;
150 d.ScopeID = data.ScopeID;
151 d.Data = new Dictionary<string,string>();
152 d.Data["Email"] = data.Email;
153 d.Data["Created"] = data.Created.ToString();
154
155 List<string> parts = new List<string>();
156
157 foreach (KeyValuePair<string,object> kvp in data.ServiceURLs)
158 {
159 string key = System.Web.HttpUtility.UrlEncode(kvp.Key);
160 string val = System.Web.HttpUtility.UrlEncode(kvp.Value.ToString());
161 parts.Add(key + "=" + val);
162 }
163
164 d.Data["ServiceURLs"] = string.Join(" ", parts.ToArray());
165
166 return m_Database.Store(d);
167 }
168
169 public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
170 {
171 UserAccountData[] d = m_Database.GetUsers(scopeID, query);
172
173 if (d == null)
174 return new List<UserAccount>();
175
176 List<UserAccount> ret = new List<UserAccount>();
177
178 foreach (UserAccountData data in d)
179 ret.Add(MakeUserAccount(data));
180
181 return ret;
182 }
183 }
184}
diff --git a/OpenSim/Services/UserAccountService/UserAccountServiceBase.cs b/OpenSim/Services/UserAccountService/UserAccountServiceBase.cs
new file mode 100644
index 0000000..70ed594
--- /dev/null
+++ b/OpenSim/Services/UserAccountService/UserAccountServiceBase.cs
@@ -0,0 +1,73 @@
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 System;
29using System.Reflection;
30using Nini.Config;
31using OpenSim.Data;
32using OpenSim.Services.Interfaces;
33using OpenSim.Services.Base;
34
35namespace OpenSim.Services.UserAccountService
36{
37 public class UserAccountServiceBase: ServiceBase
38 {
39 protected IUserAccountData m_Database = null;
40
41 public UserAccountServiceBase(IConfigSource config) : base(config)
42 {
43 string dllName = String.Empty;
44 string connString = String.Empty;
45 string realm = "useraccounts";
46
47 IConfig dbConfig = config.Configs["DatabaseService"];
48 if (dbConfig != null)
49 {
50 dllName = dbConfig.GetString("StorageProvider", String.Empty);
51 connString = dbConfig.GetString("ConnectionString", String.Empty);
52 }
53
54 IConfig userConfig = config.Configs["UserAccountService"];
55 if (userConfig == null)
56 throw new Exception("No UserAccountService configuration");
57
58 dllName = userConfig.GetString("StorageProvider", dllName);
59
60 if (dllName == String.Empty)
61 throw new Exception("No StorageProvider configured");
62
63 connString = userConfig.GetString("ConnectionString", connString);
64
65 realm = userConfig.GetString("Realm", realm);
66
67 m_Database = LoadPlugin<IUserAccountData>(dllName, new Object[] {connString, realm});
68
69 if (m_Database == null)
70 throw new Exception("Could not find a storage interface in the given module");
71 }
72 }
73}