diff options
author | Mike Mazur | 2009-02-16 02:25:44 +0000 |
---|---|---|
committer | Mike Mazur | 2009-02-16 02:25:44 +0000 |
commit | 16fa7f516a484e9f21fac34262214b3d9d761823 (patch) | |
tree | 925c10831c04d053b707857ffa785482316d4dcb /OpenSim/Grid/AssetInventoryServer/Extensions/OpenSimMySQLInventory.cs | |
parent | Added OpenSim asset frontend plugin. (diff) | |
download | opensim-SC_OLD-16fa7f516a484e9f21fac34262214b3d9d761823.zip opensim-SC_OLD-16fa7f516a484e9f21fac34262214b3d9d761823.tar.gz opensim-SC_OLD-16fa7f516a484e9f21fac34262214b3d9d761823.tar.bz2 opensim-SC_OLD-16fa7f516a484e9f21fac34262214b3d9d761823.tar.xz |
Converted to Linux newlines.
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer/Extensions/OpenSimMySQLInventory.cs')
-rw-r--r-- | OpenSim/Grid/AssetInventoryServer/Extensions/OpenSimMySQLInventory.cs | 1608 |
1 files changed, 804 insertions, 804 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Extensions/OpenSimMySQLInventory.cs b/OpenSim/Grid/AssetInventoryServer/Extensions/OpenSimMySQLInventory.cs index 7d6c0c2..07bf92f 100644 --- a/OpenSim/Grid/AssetInventoryServer/Extensions/OpenSimMySQLInventory.cs +++ b/OpenSim/Grid/AssetInventoryServer/Extensions/OpenSimMySQLInventory.cs | |||
@@ -1,804 +1,804 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2008 Intel Corporation | 2 | * Copyright (c) 2008 Intel Corporation |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * Redistribution and use in source and binary forms, with or without | 4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions | 5 | * modification, are permitted provided that the following conditions |
6 | * are met: | 6 | * are met: |
7 | * | 7 | * |
8 | * -- Redistributions of source code must retain the above copyright | 8 | * -- Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. | 9 | * notice, this list of conditions and the following disclaimer. |
10 | * -- Redistributions in binary form must reproduce the above copyright | 10 | * -- Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 12 | * documentation and/or other materials provided with the distribution. |
13 | * -- Neither the name of the Intel Corporation nor the names of its | 13 | * -- Neither the name of the Intel Corporation nor the names of its |
14 | * contributors may be used to endorse or promote products derived from | 14 | * contributors may be used to endorse or promote products derived from |
15 | * this software without specific prior written permission. | 15 | * this software without specific prior written permission. |
16 | * | 16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
20 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS | 20 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS |
21 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 21 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | using System; | 30 | using System; |
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Net; | 32 | using System.Net; |
33 | using System.Data; | 33 | using System.Data; |
34 | using MySql.Data.MySqlClient; | 34 | using MySql.Data.MySqlClient; |
35 | using ExtensionLoader; | 35 | using ExtensionLoader; |
36 | using ExtensionLoader.Config; | 36 | using ExtensionLoader.Config; |
37 | using OpenMetaverse; | 37 | using OpenMetaverse; |
38 | using OpenMetaverse.StructuredData; | 38 | using OpenMetaverse.StructuredData; |
39 | 39 | ||
40 | namespace OpenSim.Grid.AssetInventoryServer.Extensions | 40 | namespace OpenSim.Grid.AssetInventoryServer.Extensions |
41 | { | 41 | { |
42 | public class OpenSimMySQLInventory : IExtension<AssetInventoryServer>, IInventoryProvider | 42 | public class OpenSimMySQLInventory : IExtension<AssetInventoryServer>, IInventoryProvider |
43 | { | 43 | { |
44 | const string EXTENSION_NAME = "OpenSimMySQLInventory"; // Used in metrics reporting | 44 | const string EXTENSION_NAME = "OpenSimMySQLInventory"; // Used in metrics reporting |
45 | 45 | ||
46 | AssetInventoryServer server; | 46 | AssetInventoryServer server; |
47 | 47 | ||
48 | public OpenSimMySQLInventory() | 48 | public OpenSimMySQLInventory() |
49 | { | 49 | { |
50 | } | 50 | } |
51 | 51 | ||
52 | #region Required Interfaces | 52 | #region Required Interfaces |
53 | 53 | ||
54 | public void Start(AssetInventoryServer server) | 54 | public void Start(AssetInventoryServer server) |
55 | { | 55 | { |
56 | this.server = server; | 56 | this.server = server; |
57 | 57 | ||
58 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 58 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
59 | { | 59 | { |
60 | try | 60 | try |
61 | { | 61 | { |
62 | dbConnection.Open(); | 62 | dbConnection.Open(); |
63 | Logger.Log.Info("Connected to MySQL inventory backend: " + dbConnection.ServerVersion); | 63 | Logger.Log.Info("Connected to MySQL inventory backend: " + dbConnection.ServerVersion); |
64 | } | 64 | } |
65 | catch (MySqlException ex) | 65 | catch (MySqlException ex) |
66 | { | 66 | { |
67 | Logger.Log.Error("Connection to MySQL inventory backend failed: " + ex.Message); | 67 | Logger.Log.Error("Connection to MySQL inventory backend failed: " + ex.Message); |
68 | } | 68 | } |
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | public void Stop() | 72 | public void Stop() |
73 | { | 73 | { |
74 | } | 74 | } |
75 | 75 | ||
76 | public BackendResponse TryFetchItem(Uri owner, UUID itemID, out InventoryItem item) | 76 | public BackendResponse TryFetchItem(Uri owner, UUID itemID, out InventoryItem item) |
77 | { | 77 | { |
78 | item = null; | 78 | item = null; |
79 | BackendResponse ret; | 79 | BackendResponse ret; |
80 | 80 | ||
81 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 81 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
82 | { | 82 | { |
83 | IDataReader reader; | 83 | IDataReader reader; |
84 | 84 | ||
85 | try | 85 | try |
86 | { | 86 | { |
87 | dbConnection.Open(); | 87 | dbConnection.Open(); |
88 | 88 | ||
89 | IDbCommand command = dbConnection.CreateCommand(); | 89 | IDbCommand command = dbConnection.CreateCommand(); |
90 | command.CommandText = String.Format("SELECT assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," + | 90 | command.CommandText = String.Format("SELECT assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," + |
91 | "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + | 91 | "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + |
92 | "creationDate,groupID,groupOwned,flags,avatarID,parentFolderID,inventoryGroupPermissions FROM inventoryitems WHERE inventoryID='{0}'", | 92 | "creationDate,groupID,groupOwned,flags,avatarID,parentFolderID,inventoryGroupPermissions FROM inventoryitems WHERE inventoryID='{0}'", |
93 | itemID.ToString()); | 93 | itemID.ToString()); |
94 | reader = command.ExecuteReader(); | 94 | reader = command.ExecuteReader(); |
95 | 95 | ||
96 | if (reader.Read()) | 96 | if (reader.Read()) |
97 | { | 97 | { |
98 | item = new InventoryItem(); | 98 | item = new InventoryItem(); |
99 | item.ID = itemID; | 99 | item.ID = itemID; |
100 | item.AssetID = UUID.Parse(reader.GetString(0)); | 100 | item.AssetID = UUID.Parse(reader.GetString(0)); |
101 | item.AssetType = reader.GetInt32(1); | 101 | item.AssetType = reader.GetInt32(1); |
102 | item.Name = reader.GetString(2); | 102 | item.Name = reader.GetString(2); |
103 | item.Description = reader.GetString(3); | 103 | item.Description = reader.GetString(3); |
104 | item.NextPermissions = (uint)reader.GetInt32(4); | 104 | item.NextPermissions = (uint)reader.GetInt32(4); |
105 | item.CurrentPermissions = (uint)reader.GetInt32(5); | 105 | item.CurrentPermissions = (uint)reader.GetInt32(5); |
106 | item.InvType = reader.GetInt32(6); | 106 | item.InvType = reader.GetInt32(6); |
107 | item.Creator = UUID.Parse(reader.GetString(7)); | 107 | item.Creator = UUID.Parse(reader.GetString(7)); |
108 | item.BasePermissions = (uint)reader.GetInt32(8); | 108 | item.BasePermissions = (uint)reader.GetInt32(8); |
109 | item.EveryOnePermissions = (uint)reader.GetInt32(9); | 109 | item.EveryOnePermissions = (uint)reader.GetInt32(9); |
110 | item.SalePrice = reader.GetInt32(10); | 110 | item.SalePrice = reader.GetInt32(10); |
111 | item.SaleType = reader.GetByte(11); | 111 | item.SaleType = reader.GetByte(11); |
112 | item.CreationDate = reader.GetInt32(12); | 112 | item.CreationDate = reader.GetInt32(12); |
113 | item.GroupID = UUID.Parse(reader.GetString(13)); | 113 | item.GroupID = UUID.Parse(reader.GetString(13)); |
114 | item.GroupOwned = reader.GetBoolean(14); | 114 | item.GroupOwned = reader.GetBoolean(14); |
115 | item.Flags = (uint)reader.GetInt32(15); | 115 | item.Flags = (uint)reader.GetInt32(15); |
116 | item.Owner = UUID.Parse(reader.GetString(16)); | 116 | item.Owner = UUID.Parse(reader.GetString(16)); |
117 | item.Folder = UUID.Parse(reader.GetString(17)); | 117 | item.Folder = UUID.Parse(reader.GetString(17)); |
118 | item.GroupPermissions = (uint)reader.GetInt32(18); | 118 | item.GroupPermissions = (uint)reader.GetInt32(18); |
119 | 119 | ||
120 | ret = BackendResponse.Success; | 120 | ret = BackendResponse.Success; |
121 | } | 121 | } |
122 | else | 122 | else |
123 | { | 123 | { |
124 | ret = BackendResponse.NotFound; | 124 | ret = BackendResponse.NotFound; |
125 | } | 125 | } |
126 | } | 126 | } |
127 | catch (MySqlException ex) | 127 | catch (MySqlException ex) |
128 | { | 128 | { |
129 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); | 129 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
130 | ret = BackendResponse.Failure; | 130 | ret = BackendResponse.Failure; |
131 | } | 131 | } |
132 | } | 132 | } |
133 | 133 | ||
134 | server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); | 134 | server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); |
135 | return ret; | 135 | return ret; |
136 | } | 136 | } |
137 | 137 | ||
138 | public BackendResponse TryFetchFolder(Uri owner, UUID folderID, out InventoryFolder folder) | 138 | public BackendResponse TryFetchFolder(Uri owner, UUID folderID, out InventoryFolder folder) |
139 | { | 139 | { |
140 | folder = null; | 140 | folder = null; |
141 | BackendResponse ret; | 141 | BackendResponse ret; |
142 | 142 | ||
143 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 143 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
144 | { | 144 | { |
145 | IDataReader reader; | 145 | IDataReader reader; |
146 | 146 | ||
147 | try | 147 | try |
148 | { | 148 | { |
149 | dbConnection.Open(); | 149 | dbConnection.Open(); |
150 | 150 | ||
151 | IDbCommand command = dbConnection.CreateCommand(); | 151 | IDbCommand command = dbConnection.CreateCommand(); |
152 | command.CommandText = String.Format("SELECT folderName,type,version,agentID,parentFolderID FROM inventoryfolders WHERE folderID='{0}'", | 152 | command.CommandText = String.Format("SELECT folderName,type,version,agentID,parentFolderID FROM inventoryfolders WHERE folderID='{0}'", |
153 | folderID.ToString()); | 153 | folderID.ToString()); |
154 | reader = command.ExecuteReader(); | 154 | reader = command.ExecuteReader(); |
155 | 155 | ||
156 | if (reader.Read()) | 156 | if (reader.Read()) |
157 | { | 157 | { |
158 | folder = new InventoryFolder(); | 158 | folder = new InventoryFolder(); |
159 | folder.Children = null; // This call only returns data for the folder itself, no children data | 159 | folder.Children = null; // This call only returns data for the folder itself, no children data |
160 | folder.ID = folderID; | 160 | folder.ID = folderID; |
161 | folder.Name = reader.GetString(0); | 161 | folder.Name = reader.GetString(0); |
162 | folder.Type = reader.GetInt16(1); | 162 | folder.Type = reader.GetInt16(1); |
163 | folder.Version = (ushort)reader.GetInt16(2); | 163 | folder.Version = (ushort)reader.GetInt16(2); |
164 | folder.Owner = UUID.Parse(reader.GetString(3)); | 164 | folder.Owner = UUID.Parse(reader.GetString(3)); |
165 | folder.ParentID = UUID.Parse(reader.GetString(4)); | 165 | folder.ParentID = UUID.Parse(reader.GetString(4)); |
166 | 166 | ||
167 | ret = BackendResponse.Success; | 167 | ret = BackendResponse.Success; |
168 | } | 168 | } |
169 | else | 169 | else |
170 | { | 170 | { |
171 | ret = BackendResponse.NotFound; | 171 | ret = BackendResponse.NotFound; |
172 | } | 172 | } |
173 | } | 173 | } |
174 | catch (MySqlException ex) | 174 | catch (MySqlException ex) |
175 | { | 175 | { |
176 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); | 176 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
177 | ret = BackendResponse.Failure; | 177 | ret = BackendResponse.Failure; |
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now); | 181 | server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now); |
182 | return ret; | 182 | return ret; |
183 | } | 183 | } |
184 | 184 | ||
185 | public BackendResponse TryFetchFolderContents(Uri owner, UUID folderID, out InventoryCollection contents) | 185 | public BackendResponse TryFetchFolderContents(Uri owner, UUID folderID, out InventoryCollection contents) |
186 | { | 186 | { |
187 | contents = null; | 187 | contents = null; |
188 | BackendResponse ret; | 188 | BackendResponse ret; |
189 | 189 | ||
190 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 190 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
191 | { | 191 | { |
192 | IDataReader reader; | 192 | IDataReader reader; |
193 | 193 | ||
194 | try | 194 | try |
195 | { | 195 | { |
196 | dbConnection.Open(); | 196 | dbConnection.Open(); |
197 | 197 | ||
198 | contents = new InventoryCollection(); | 198 | contents = new InventoryCollection(); |
199 | 199 | ||
200 | #region Folder retrieval | 200 | #region Folder retrieval |
201 | 201 | ||
202 | IDbCommand command = dbConnection.CreateCommand(); | 202 | IDbCommand command = dbConnection.CreateCommand(); |
203 | command.CommandText = String.Format("SELECT folderName,type,version,agentID,folderID FROM inventoryfolders WHERE parentFolderID='{0}'", | 203 | command.CommandText = String.Format("SELECT folderName,type,version,agentID,folderID FROM inventoryfolders WHERE parentFolderID='{0}'", |
204 | folderID.ToString()); | 204 | folderID.ToString()); |
205 | reader = command.ExecuteReader(); | 205 | reader = command.ExecuteReader(); |
206 | 206 | ||
207 | contents.Folders = new Dictionary<UUID, InventoryFolder>(); | 207 | contents.Folders = new Dictionary<UUID, InventoryFolder>(); |
208 | 208 | ||
209 | while (reader.Read()) | 209 | while (reader.Read()) |
210 | { | 210 | { |
211 | InventoryFolder folder = new InventoryFolder(); | 211 | InventoryFolder folder = new InventoryFolder(); |
212 | folder.ParentID = folderID; | 212 | folder.ParentID = folderID; |
213 | folder.Children = null; // This call doesn't do recursion | 213 | folder.Children = null; // This call doesn't do recursion |
214 | folder.Name = reader.GetString(0); | 214 | folder.Name = reader.GetString(0); |
215 | folder.Type = reader.GetInt16(1); | 215 | folder.Type = reader.GetInt16(1); |
216 | folder.Version = (ushort)reader.GetInt16(2); | 216 | folder.Version = (ushort)reader.GetInt16(2); |
217 | folder.Owner = UUID.Parse(reader.GetString(3)); | 217 | folder.Owner = UUID.Parse(reader.GetString(3)); |
218 | folder.ID = UUID.Parse(reader.GetString(4)); | 218 | folder.ID = UUID.Parse(reader.GetString(4)); |
219 | 219 | ||
220 | contents.Folders.Add(folder.ID, folder); | 220 | contents.Folders.Add(folder.ID, folder); |
221 | contents.UserID = folder.Owner; | 221 | contents.UserID = folder.Owner; |
222 | } | 222 | } |
223 | 223 | ||
224 | reader.Close(); | 224 | reader.Close(); |
225 | 225 | ||
226 | #endregion Folder retrieval | 226 | #endregion Folder retrieval |
227 | 227 | ||
228 | #region Item retrieval | 228 | #region Item retrieval |
229 | 229 | ||
230 | command = dbConnection.CreateCommand(); | 230 | command = dbConnection.CreateCommand(); |
231 | command.CommandText = String.Format("SELECT assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," + | 231 | command.CommandText = String.Format("SELECT assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," + |
232 | "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + | 232 | "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + |
233 | "creationDate,groupID,groupOwned,flags,avatarID,inventoryID,inventoryGroupPermissions FROM inventoryitems WHERE parentFolderID='{0}'", | 233 | "creationDate,groupID,groupOwned,flags,avatarID,inventoryID,inventoryGroupPermissions FROM inventoryitems WHERE parentFolderID='{0}'", |
234 | folderID.ToString()); | 234 | folderID.ToString()); |
235 | reader = command.ExecuteReader(); | 235 | reader = command.ExecuteReader(); |
236 | 236 | ||
237 | contents.Items = new Dictionary<UUID, InventoryItem>(); | 237 | contents.Items = new Dictionary<UUID, InventoryItem>(); |
238 | 238 | ||
239 | while (reader.Read()) | 239 | while (reader.Read()) |
240 | { | 240 | { |
241 | InventoryItem item = new InventoryItem(); | 241 | InventoryItem item = new InventoryItem(); |
242 | item.Folder = folderID; | 242 | item.Folder = folderID; |
243 | item.AssetID = UUID.Parse(reader.GetString(0)); | 243 | item.AssetID = UUID.Parse(reader.GetString(0)); |
244 | item.AssetType = reader.GetInt32(1); | 244 | item.AssetType = reader.GetInt32(1); |
245 | item.Name = reader.GetString(2); | 245 | item.Name = reader.GetString(2); |
246 | item.Description = reader.GetString(3); | 246 | item.Description = reader.GetString(3); |
247 | item.NextPermissions = (uint)reader.GetInt32(4); | 247 | item.NextPermissions = (uint)reader.GetInt32(4); |
248 | item.CurrentPermissions = (uint)reader.GetInt32(5); | 248 | item.CurrentPermissions = (uint)reader.GetInt32(5); |
249 | item.InvType = reader.GetInt32(6); | 249 | item.InvType = reader.GetInt32(6); |
250 | item.Creator = UUID.Parse(reader.GetString(7)); | 250 | item.Creator = UUID.Parse(reader.GetString(7)); |
251 | item.BasePermissions = (uint)reader.GetInt32(8); | 251 | item.BasePermissions = (uint)reader.GetInt32(8); |
252 | item.EveryOnePermissions = (uint)reader.GetInt32(9); | 252 | item.EveryOnePermissions = (uint)reader.GetInt32(9); |
253 | item.SalePrice = reader.GetInt32(10); | 253 | item.SalePrice = reader.GetInt32(10); |
254 | item.SaleType = reader.GetByte(11); | 254 | item.SaleType = reader.GetByte(11); |
255 | item.CreationDate = reader.GetInt32(12); | 255 | item.CreationDate = reader.GetInt32(12); |
256 | item.GroupID = UUID.Parse(reader.GetString(13)); | 256 | item.GroupID = UUID.Parse(reader.GetString(13)); |
257 | item.GroupOwned = reader.GetBoolean(14); | 257 | item.GroupOwned = reader.GetBoolean(14); |
258 | item.Flags = (uint)reader.GetInt32(15); | 258 | item.Flags = (uint)reader.GetInt32(15); |
259 | item.Owner = UUID.Parse(reader.GetString(16)); | 259 | item.Owner = UUID.Parse(reader.GetString(16)); |
260 | item.ID = UUID.Parse(reader.GetString(17)); | 260 | item.ID = UUID.Parse(reader.GetString(17)); |
261 | item.GroupPermissions = (uint)reader.GetInt32(18); | 261 | item.GroupPermissions = (uint)reader.GetInt32(18); |
262 | 262 | ||
263 | contents.Items.Add(item.ID, item); | 263 | contents.Items.Add(item.ID, item); |
264 | contents.UserID = item.Owner; | 264 | contents.UserID = item.Owner; |
265 | } | 265 | } |
266 | 266 | ||
267 | #endregion Item retrieval | 267 | #endregion Item retrieval |
268 | 268 | ||
269 | ret = BackendResponse.Success; | 269 | ret = BackendResponse.Success; |
270 | } | 270 | } |
271 | catch (MySqlException ex) | 271 | catch (MySqlException ex) |
272 | { | 272 | { |
273 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); | 273 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
274 | ret = BackendResponse.Failure; | 274 | ret = BackendResponse.Failure; |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | server.MetricsProvider.LogInventoryFetchFolderContents(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); | 278 | server.MetricsProvider.LogInventoryFetchFolderContents(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); |
279 | return ret; | 279 | return ret; |
280 | } | 280 | } |
281 | 281 | ||
282 | public BackendResponse TryFetchFolderList(Uri owner, out List<InventoryFolder> folders) | 282 | public BackendResponse TryFetchFolderList(Uri owner, out List<InventoryFolder> folders) |
283 | { | 283 | { |
284 | folders = null; | 284 | folders = null; |
285 | BackendResponse ret; | 285 | BackendResponse ret; |
286 | UUID ownerID; | 286 | UUID ownerID; |
287 | 287 | ||
288 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) | 288 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) |
289 | { | 289 | { |
290 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 290 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
291 | { | 291 | { |
292 | IDataReader reader; | 292 | IDataReader reader; |
293 | 293 | ||
294 | try | 294 | try |
295 | { | 295 | { |
296 | dbConnection.Open(); | 296 | dbConnection.Open(); |
297 | folders = new List<InventoryFolder>(); | 297 | folders = new List<InventoryFolder>(); |
298 | 298 | ||
299 | IDbCommand command = dbConnection.CreateCommand(); | 299 | IDbCommand command = dbConnection.CreateCommand(); |
300 | command.CommandText = String.Format("SELECT folderName,type,version,folderID,parentFolderID FROM inventoryfolders WHERE agentID='{0}'", | 300 | command.CommandText = String.Format("SELECT folderName,type,version,folderID,parentFolderID FROM inventoryfolders WHERE agentID='{0}'", |
301 | ownerID.ToString()); | 301 | ownerID.ToString()); |
302 | reader = command.ExecuteReader(); | 302 | reader = command.ExecuteReader(); |
303 | 303 | ||
304 | while (reader.Read()) | 304 | while (reader.Read()) |
305 | { | 305 | { |
306 | InventoryFolder folder = new InventoryFolder(); | 306 | InventoryFolder folder = new InventoryFolder(); |
307 | folder.Owner = ownerID; | 307 | folder.Owner = ownerID; |
308 | folder.Children = null; // This call does not create a folder hierarchy | 308 | folder.Children = null; // This call does not create a folder hierarchy |
309 | folder.Name = reader.GetString(0); | 309 | folder.Name = reader.GetString(0); |
310 | folder.Type = reader.GetInt16(1); | 310 | folder.Type = reader.GetInt16(1); |
311 | folder.Version = (ushort)reader.GetInt16(2); | 311 | folder.Version = (ushort)reader.GetInt16(2); |
312 | folder.ID = UUID.Parse(reader.GetString(3)); | 312 | folder.ID = UUID.Parse(reader.GetString(3)); |
313 | folder.ParentID = UUID.Parse(reader.GetString(4)); | 313 | folder.ParentID = UUID.Parse(reader.GetString(4)); |
314 | 314 | ||
315 | folders.Add(folder); | 315 | folders.Add(folder); |
316 | } | 316 | } |
317 | 317 | ||
318 | ret = BackendResponse.Success; | 318 | ret = BackendResponse.Success; |
319 | } | 319 | } |
320 | catch (MySqlException ex) | 320 | catch (MySqlException ex) |
321 | { | 321 | { |
322 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); | 322 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
323 | ret = BackendResponse.Failure; | 323 | ret = BackendResponse.Failure; |
324 | } | 324 | } |
325 | } | 325 | } |
326 | } | 326 | } |
327 | else | 327 | else |
328 | { | 328 | { |
329 | ret = BackendResponse.NotFound; | 329 | ret = BackendResponse.NotFound; |
330 | } | 330 | } |
331 | 331 | ||
332 | server.MetricsProvider.LogInventoryFetchFolderList(EXTENSION_NAME, ret, owner, DateTime.Now); | 332 | server.MetricsProvider.LogInventoryFetchFolderList(EXTENSION_NAME, ret, owner, DateTime.Now); |
333 | return ret; | 333 | return ret; |
334 | } | 334 | } |
335 | 335 | ||
336 | public BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory) | 336 | public BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory) |
337 | { | 337 | { |
338 | inventory = null; | 338 | inventory = null; |
339 | BackendResponse ret; | 339 | BackendResponse ret; |
340 | List<InventoryFolder> folders; | 340 | List<InventoryFolder> folders; |
341 | UUID ownerID; | 341 | UUID ownerID; |
342 | 342 | ||
343 | ret = TryFetchFolderList(owner, out folders); | 343 | ret = TryFetchFolderList(owner, out folders); |
344 | 344 | ||
345 | if (ret == BackendResponse.Success) | 345 | if (ret == BackendResponse.Success) |
346 | { | 346 | { |
347 | // Add the retrieved folders to the inventory collection | 347 | // Add the retrieved folders to the inventory collection |
348 | inventory = new InventoryCollection(); | 348 | inventory = new InventoryCollection(); |
349 | inventory.Folders = new Dictionary<UUID, InventoryFolder>(folders.Count); | 349 | inventory.Folders = new Dictionary<UUID, InventoryFolder>(folders.Count); |
350 | foreach (InventoryFolder folder in folders) | 350 | foreach (InventoryFolder folder in folders) |
351 | inventory.Folders[folder.ID] = folder; | 351 | inventory.Folders[folder.ID] = folder; |
352 | 352 | ||
353 | // Fetch inventory items | 353 | // Fetch inventory items |
354 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) | 354 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) |
355 | { | 355 | { |
356 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 356 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
357 | { | 357 | { |
358 | IDataReader reader; | 358 | IDataReader reader; |
359 | 359 | ||
360 | try | 360 | try |
361 | { | 361 | { |
362 | dbConnection.Open(); | 362 | dbConnection.Open(); |
363 | 363 | ||
364 | IDbCommand command = dbConnection.CreateCommand(); | 364 | IDbCommand command = dbConnection.CreateCommand(); |
365 | command.CommandText = String.Format("SELECT assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," + | 365 | command.CommandText = String.Format("SELECT assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," + |
366 | "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + | 366 | "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + |
367 | "creationDate,groupID,groupOwned,flags,inventoryID,parentFolderID,inventoryGroupPermissions FROM inventoryitems WHERE " + | 367 | "creationDate,groupID,groupOwned,flags,inventoryID,parentFolderID,inventoryGroupPermissions FROM inventoryitems WHERE " + |
368 | "avatarID='{0}'", ownerID.ToString()); | 368 | "avatarID='{0}'", ownerID.ToString()); |
369 | reader = command.ExecuteReader(); | 369 | reader = command.ExecuteReader(); |
370 | 370 | ||
371 | inventory.UserID = ownerID; | 371 | inventory.UserID = ownerID; |
372 | inventory.Items = new Dictionary<UUID, InventoryItem>(); | 372 | inventory.Items = new Dictionary<UUID, InventoryItem>(); |
373 | 373 | ||
374 | while (reader.Read()) | 374 | while (reader.Read()) |
375 | { | 375 | { |
376 | InventoryItem item = new InventoryItem(); | 376 | InventoryItem item = new InventoryItem(); |
377 | item.Owner = ownerID; | 377 | item.Owner = ownerID; |
378 | item.AssetID = UUID.Parse(reader.GetString(0)); | 378 | item.AssetID = UUID.Parse(reader.GetString(0)); |
379 | item.AssetType = reader.GetInt32(1); | 379 | item.AssetType = reader.GetInt32(1); |
380 | item.Name = reader.GetString(2); | 380 | item.Name = reader.GetString(2); |
381 | item.Description = reader.GetString(3); | 381 | item.Description = reader.GetString(3); |
382 | item.NextPermissions = (uint)reader.GetInt32(4); | 382 | item.NextPermissions = (uint)reader.GetInt32(4); |
383 | item.CurrentPermissions = (uint)reader.GetInt32(5); | 383 | item.CurrentPermissions = (uint)reader.GetInt32(5); |
384 | item.InvType = reader.GetInt32(6); | 384 | item.InvType = reader.GetInt32(6); |
385 | item.Creator = UUID.Parse(reader.GetString(7)); | 385 | item.Creator = UUID.Parse(reader.GetString(7)); |
386 | item.BasePermissions = (uint)reader.GetInt32(8); | 386 | item.BasePermissions = (uint)reader.GetInt32(8); |
387 | item.EveryOnePermissions = (uint)reader.GetInt32(9); | 387 | item.EveryOnePermissions = (uint)reader.GetInt32(9); |
388 | item.SalePrice = reader.GetInt32(10); | 388 | item.SalePrice = reader.GetInt32(10); |
389 | item.SaleType = reader.GetByte(11); | 389 | item.SaleType = reader.GetByte(11); |
390 | item.CreationDate = reader.GetInt32(12); | 390 | item.CreationDate = reader.GetInt32(12); |
391 | item.GroupID = UUID.Parse(reader.GetString(13)); | 391 | item.GroupID = UUID.Parse(reader.GetString(13)); |
392 | item.GroupOwned = reader.GetBoolean(14); | 392 | item.GroupOwned = reader.GetBoolean(14); |
393 | item.Flags = (uint)reader.GetInt32(15); | 393 | item.Flags = (uint)reader.GetInt32(15); |
394 | item.ID = UUID.Parse(reader.GetString(16)); | 394 | item.ID = UUID.Parse(reader.GetString(16)); |
395 | item.Folder = UUID.Parse(reader.GetString(17)); | 395 | item.Folder = UUID.Parse(reader.GetString(17)); |
396 | item.GroupPermissions = (uint)reader.GetInt32(18); | 396 | item.GroupPermissions = (uint)reader.GetInt32(18); |
397 | 397 | ||
398 | inventory.Items.Add(item.ID, item); | 398 | inventory.Items.Add(item.ID, item); |
399 | } | 399 | } |
400 | 400 | ||
401 | ret = BackendResponse.Success; | 401 | ret = BackendResponse.Success; |
402 | } | 402 | } |
403 | catch (MySqlException ex) | 403 | catch (MySqlException ex) |
404 | { | 404 | { |
405 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); | 405 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
406 | ret = BackendResponse.Failure; | 406 | ret = BackendResponse.Failure; |
407 | } | 407 | } |
408 | } | 408 | } |
409 | } | 409 | } |
410 | else | 410 | else |
411 | { | 411 | { |
412 | ret = BackendResponse.NotFound; | 412 | ret = BackendResponse.NotFound; |
413 | } | 413 | } |
414 | } | 414 | } |
415 | 415 | ||
416 | server.MetricsProvider.LogInventoryFetchInventory(EXTENSION_NAME, ret, owner, DateTime.Now); | 416 | server.MetricsProvider.LogInventoryFetchInventory(EXTENSION_NAME, ret, owner, DateTime.Now); |
417 | return ret; | 417 | return ret; |
418 | } | 418 | } |
419 | 419 | ||
420 | public BackendResponse TryFetchActiveGestures(Uri owner, out List<InventoryItem> gestures) | 420 | public BackendResponse TryFetchActiveGestures(Uri owner, out List<InventoryItem> gestures) |
421 | { | 421 | { |
422 | gestures = null; | 422 | gestures = null; |
423 | BackendResponse ret; | 423 | BackendResponse ret; |
424 | UUID ownerID; | 424 | UUID ownerID; |
425 | 425 | ||
426 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) | 426 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) |
427 | { | 427 | { |
428 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 428 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
429 | { | 429 | { |
430 | IDataReader reader; | 430 | IDataReader reader; |
431 | 431 | ||
432 | try | 432 | try |
433 | { | 433 | { |
434 | dbConnection.Open(); | 434 | dbConnection.Open(); |
435 | 435 | ||
436 | MySqlCommand command = new MySqlCommand("SELECT assetID,inventoryName,inventoryDescription,inventoryNextPermissions," + | 436 | MySqlCommand command = new MySqlCommand("SELECT assetID,inventoryName,inventoryDescription,inventoryNextPermissions," + |
437 | "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + | 437 | "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + |
438 | "creationDate,groupID,groupOwned,inventoryID,parentFolderID,inventoryGroupPermissions FROM inventoryitems WHERE " + | 438 | "creationDate,groupID,groupOwned,inventoryID,parentFolderID,inventoryGroupPermissions FROM inventoryitems WHERE " + |
439 | "avatarId=?uuid AND assetType=?type AND flags=1", dbConnection); | 439 | "avatarId=?uuid AND assetType=?type AND flags=1", dbConnection); |
440 | command.Parameters.AddWithValue("?uuid", ownerID.ToString()); | 440 | command.Parameters.AddWithValue("?uuid", ownerID.ToString()); |
441 | command.Parameters.AddWithValue("?type", (int)AssetType.Gesture); | 441 | command.Parameters.AddWithValue("?type", (int)AssetType.Gesture); |
442 | reader = command.ExecuteReader(); | 442 | reader = command.ExecuteReader(); |
443 | 443 | ||
444 | while (reader.Read()) | 444 | while (reader.Read()) |
445 | { | 445 | { |
446 | InventoryItem item = new InventoryItem(); | 446 | InventoryItem item = new InventoryItem(); |
447 | item.Owner = ownerID; | 447 | item.Owner = ownerID; |
448 | item.AssetType = (int)AssetType.Gesture; | 448 | item.AssetType = (int)AssetType.Gesture; |
449 | item.Flags = (uint)1; | 449 | item.Flags = (uint)1; |
450 | item.AssetID = UUID.Parse(reader.GetString(0)); | 450 | item.AssetID = UUID.Parse(reader.GetString(0)); |
451 | item.Name = reader.GetString(1); | 451 | item.Name = reader.GetString(1); |
452 | item.Description = reader.GetString(2); | 452 | item.Description = reader.GetString(2); |
453 | item.NextPermissions = (uint)reader.GetInt32(3); | 453 | item.NextPermissions = (uint)reader.GetInt32(3); |
454 | item.CurrentPermissions = (uint)reader.GetInt32(4); | 454 | item.CurrentPermissions = (uint)reader.GetInt32(4); |
455 | item.InvType = reader.GetInt32(5); | 455 | item.InvType = reader.GetInt32(5); |
456 | item.Creator = UUID.Parse(reader.GetString(6)); | 456 | item.Creator = UUID.Parse(reader.GetString(6)); |
457 | item.BasePermissions = (uint)reader.GetInt32(7); | 457 | item.BasePermissions = (uint)reader.GetInt32(7); |
458 | item.EveryOnePermissions = (uint)reader.GetInt32(8); | 458 | item.EveryOnePermissions = (uint)reader.GetInt32(8); |
459 | item.SalePrice = reader.GetInt32(9); | 459 | item.SalePrice = reader.GetInt32(9); |
460 | item.SaleType = reader.GetByte(10); | 460 | item.SaleType = reader.GetByte(10); |
461 | item.CreationDate = reader.GetInt32(11); | 461 | item.CreationDate = reader.GetInt32(11); |
462 | item.GroupID = UUID.Parse(reader.GetString(12)); | 462 | item.GroupID = UUID.Parse(reader.GetString(12)); |
463 | item.GroupOwned = reader.GetBoolean(13); | 463 | item.GroupOwned = reader.GetBoolean(13); |
464 | item.ID = UUID.Parse(reader.GetString(14)); | 464 | item.ID = UUID.Parse(reader.GetString(14)); |
465 | item.Folder = UUID.Parse(reader.GetString(15)); | 465 | item.Folder = UUID.Parse(reader.GetString(15)); |
466 | item.GroupPermissions = (uint)reader.GetInt32(16); | 466 | item.GroupPermissions = (uint)reader.GetInt32(16); |
467 | 467 | ||
468 | gestures.Add(item); | 468 | gestures.Add(item); |
469 | } | 469 | } |
470 | 470 | ||
471 | ret = BackendResponse.Success; | 471 | ret = BackendResponse.Success; |
472 | } | 472 | } |
473 | catch (MySqlException ex) | 473 | catch (MySqlException ex) |
474 | { | 474 | { |
475 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); | 475 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
476 | ret = BackendResponse.Failure; | 476 | ret = BackendResponse.Failure; |
477 | } | 477 | } |
478 | } | 478 | } |
479 | } | 479 | } |
480 | else | 480 | else |
481 | { | 481 | { |
482 | ret = BackendResponse.NotFound; | 482 | ret = BackendResponse.NotFound; |
483 | } | 483 | } |
484 | 484 | ||
485 | server.MetricsProvider.LogInventoryFetchActiveGestures(EXTENSION_NAME, ret, owner, DateTime.Now); | 485 | server.MetricsProvider.LogInventoryFetchActiveGestures(EXTENSION_NAME, ret, owner, DateTime.Now); |
486 | return ret; | 486 | return ret; |
487 | } | 487 | } |
488 | 488 | ||
489 | public BackendResponse TryCreateItem(Uri owner, InventoryItem item) | 489 | public BackendResponse TryCreateItem(Uri owner, InventoryItem item) |
490 | { | 490 | { |
491 | BackendResponse ret; | 491 | BackendResponse ret; |
492 | 492 | ||
493 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 493 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
494 | { | 494 | { |
495 | try | 495 | try |
496 | { | 496 | { |
497 | dbConnection.Open(); | 497 | dbConnection.Open(); |
498 | 498 | ||
499 | MySqlCommand command = new MySqlCommand( | 499 | MySqlCommand command = new MySqlCommand( |
500 | "REPLACE INTO inventoryitems (assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," + | 500 | "REPLACE INTO inventoryitems (assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," + |
501 | "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + | 501 | "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + |
502 | "creationDate,groupID,groupOwned,flags,inventoryID,avatarID,parentFolderID,inventoryGroupPermissions) VALUES " + | 502 | "creationDate,groupID,groupOwned,flags,inventoryID,avatarID,parentFolderID,inventoryGroupPermissions) VALUES " + |
503 | 503 | ||
504 | "(?assetID,?assetType,?inventoryName,?inventoryDescription,?inventoryNextPermissions,?inventoryCurrentPermissions,?invType," + | 504 | "(?assetID,?assetType,?inventoryName,?inventoryDescription,?inventoryNextPermissions,?inventoryCurrentPermissions,?invType," + |
505 | "?creatorID,?inventoryBasePermissions,?inventoryEveryOnePermissions,?salePrice,?saleType,?creationDate,?groupID,?groupOwned," + | 505 | "?creatorID,?inventoryBasePermissions,?inventoryEveryOnePermissions,?salePrice,?saleType,?creationDate,?groupID,?groupOwned," + |
506 | "?flags,?inventoryID,?avatarID,?parentFolderID,?inventoryGroupPermissions)", dbConnection); | 506 | "?flags,?inventoryID,?avatarID,?parentFolderID,?inventoryGroupPermissions)", dbConnection); |
507 | 507 | ||
508 | command.Parameters.AddWithValue("?assetID", item.AssetID.ToString()); | 508 | command.Parameters.AddWithValue("?assetID", item.AssetID.ToString()); |
509 | command.Parameters.AddWithValue("?assetType", item.AssetType); | 509 | command.Parameters.AddWithValue("?assetType", item.AssetType); |
510 | command.Parameters.AddWithValue("?inventoryName", item.Name); | 510 | command.Parameters.AddWithValue("?inventoryName", item.Name); |
511 | command.Parameters.AddWithValue("?inventoryDescription", item.Description); | 511 | command.Parameters.AddWithValue("?inventoryDescription", item.Description); |
512 | command.Parameters.AddWithValue("?inventoryNextPermissions", item.NextPermissions); | 512 | command.Parameters.AddWithValue("?inventoryNextPermissions", item.NextPermissions); |
513 | command.Parameters.AddWithValue("?inventoryCurrentPermissions", item.CurrentPermissions); | 513 | command.Parameters.AddWithValue("?inventoryCurrentPermissions", item.CurrentPermissions); |
514 | command.Parameters.AddWithValue("?invType", item.InvType); | 514 | command.Parameters.AddWithValue("?invType", item.InvType); |
515 | command.Parameters.AddWithValue("?creatorID", item.Creator.ToString()); | 515 | command.Parameters.AddWithValue("?creatorID", item.Creator.ToString()); |
516 | command.Parameters.AddWithValue("?inventoryBasePermissions", item.BasePermissions); | 516 | command.Parameters.AddWithValue("?inventoryBasePermissions", item.BasePermissions); |
517 | command.Parameters.AddWithValue("?inventoryEveryOnePermissions", item.EveryOnePermissions); | 517 | command.Parameters.AddWithValue("?inventoryEveryOnePermissions", item.EveryOnePermissions); |
518 | command.Parameters.AddWithValue("?salePrice", item.SalePrice); | 518 | command.Parameters.AddWithValue("?salePrice", item.SalePrice); |
519 | command.Parameters.AddWithValue("?saleType", item.SaleType); | 519 | command.Parameters.AddWithValue("?saleType", item.SaleType); |
520 | command.Parameters.AddWithValue("?creationDate", item.CreationDate); | 520 | command.Parameters.AddWithValue("?creationDate", item.CreationDate); |
521 | command.Parameters.AddWithValue("?groupID", item.GroupID.ToString()); | 521 | command.Parameters.AddWithValue("?groupID", item.GroupID.ToString()); |
522 | command.Parameters.AddWithValue("?groupOwned", item.GroupOwned); | 522 | command.Parameters.AddWithValue("?groupOwned", item.GroupOwned); |
523 | command.Parameters.AddWithValue("?flags", item.Flags); | 523 | command.Parameters.AddWithValue("?flags", item.Flags); |
524 | command.Parameters.AddWithValue("?inventoryID", item.ID); | 524 | command.Parameters.AddWithValue("?inventoryID", item.ID); |
525 | command.Parameters.AddWithValue("?avatarID", item.Owner); | 525 | command.Parameters.AddWithValue("?avatarID", item.Owner); |
526 | command.Parameters.AddWithValue("?parentFolderID", item.Folder); | 526 | command.Parameters.AddWithValue("?parentFolderID", item.Folder); |
527 | command.Parameters.AddWithValue("?inventoryGroupPermissions", item.GroupPermissions); | 527 | command.Parameters.AddWithValue("?inventoryGroupPermissions", item.GroupPermissions); |
528 | 528 | ||
529 | int rowsAffected = command.ExecuteNonQuery(); | 529 | int rowsAffected = command.ExecuteNonQuery(); |
530 | if (rowsAffected == 1) | 530 | if (rowsAffected == 1) |
531 | { | 531 | { |
532 | ret = BackendResponse.Success; | 532 | ret = BackendResponse.Success; |
533 | } | 533 | } |
534 | else if (rowsAffected == 2) | 534 | else if (rowsAffected == 2) |
535 | { | 535 | { |
536 | Logger.Log.Info("Replaced inventory item " + item.ID.ToString()); | 536 | Logger.Log.Info("Replaced inventory item " + item.ID.ToString()); |
537 | ret = BackendResponse.Success; | 537 | ret = BackendResponse.Success; |
538 | } | 538 | } |
539 | else | 539 | else |
540 | { | 540 | { |
541 | Logger.Log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); | 541 | Logger.Log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); |
542 | ret = BackendResponse.Failure; | 542 | ret = BackendResponse.Failure; |
543 | } | 543 | } |
544 | } | 544 | } |
545 | catch (MySqlException ex) | 545 | catch (MySqlException ex) |
546 | { | 546 | { |
547 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); | 547 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
548 | ret = BackendResponse.Failure; | 548 | ret = BackendResponse.Failure; |
549 | } | 549 | } |
550 | } | 550 | } |
551 | 551 | ||
552 | server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, false, DateTime.Now); | 552 | server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, false, DateTime.Now); |
553 | return ret; | 553 | return ret; |
554 | } | 554 | } |
555 | 555 | ||
556 | public BackendResponse TryCreateFolder(Uri owner, InventoryFolder folder) | 556 | public BackendResponse TryCreateFolder(Uri owner, InventoryFolder folder) |
557 | { | 557 | { |
558 | BackendResponse ret; | 558 | BackendResponse ret; |
559 | 559 | ||
560 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 560 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
561 | { | 561 | { |
562 | try | 562 | try |
563 | { | 563 | { |
564 | dbConnection.Open(); | 564 | dbConnection.Open(); |
565 | 565 | ||
566 | MySqlCommand command = new MySqlCommand( | 566 | MySqlCommand command = new MySqlCommand( |
567 | "REPLACE INTO inventoryfolders (folderName,type,version,folderID,agentID,parentFolderID) VALUES " + | 567 | "REPLACE INTO inventoryfolders (folderName,type,version,folderID,agentID,parentFolderID) VALUES " + |
568 | "(?folderName,?type,?version,?folderID,?agentID,?parentFolderID)", dbConnection); | 568 | "(?folderName,?type,?version,?folderID,?agentID,?parentFolderID)", dbConnection); |
569 | 569 | ||
570 | command.Parameters.AddWithValue("?folderName", folder.Name); | 570 | command.Parameters.AddWithValue("?folderName", folder.Name); |
571 | command.Parameters.AddWithValue("?type", folder.Type); | 571 | command.Parameters.AddWithValue("?type", folder.Type); |
572 | command.Parameters.AddWithValue("?version", folder.Version); | 572 | command.Parameters.AddWithValue("?version", folder.Version); |
573 | command.Parameters.AddWithValue("?folderID", folder.ID); | 573 | command.Parameters.AddWithValue("?folderID", folder.ID); |
574 | command.Parameters.AddWithValue("?agentID", folder.Owner); | 574 | command.Parameters.AddWithValue("?agentID", folder.Owner); |
575 | command.Parameters.AddWithValue("?parentFolderID", folder.ParentID); | 575 | command.Parameters.AddWithValue("?parentFolderID", folder.ParentID); |
576 | 576 | ||
577 | int rowsAffected = command.ExecuteNonQuery(); | 577 | int rowsAffected = command.ExecuteNonQuery(); |
578 | if (rowsAffected == 1) | 578 | if (rowsAffected == 1) |
579 | { | 579 | { |
580 | ret = BackendResponse.Success; | 580 | ret = BackendResponse.Success; |
581 | } | 581 | } |
582 | else if (rowsAffected == 2) | 582 | else if (rowsAffected == 2) |
583 | { | 583 | { |
584 | Logger.Log.Info("Replaced inventory folder " + folder.ID.ToString()); | 584 | Logger.Log.Info("Replaced inventory folder " + folder.ID.ToString()); |
585 | ret = BackendResponse.Success; | 585 | ret = BackendResponse.Success; |
586 | } | 586 | } |
587 | else | 587 | else |
588 | { | 588 | { |
589 | Logger.Log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); | 589 | Logger.Log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); |
590 | ret = BackendResponse.Failure; | 590 | ret = BackendResponse.Failure; |
591 | } | 591 | } |
592 | } | 592 | } |
593 | catch (MySqlException ex) | 593 | catch (MySqlException ex) |
594 | { | 594 | { |
595 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); | 595 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
596 | ret = BackendResponse.Failure; | 596 | ret = BackendResponse.Failure; |
597 | } | 597 | } |
598 | } | 598 | } |
599 | 599 | ||
600 | server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, true, DateTime.Now); | 600 | server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, true, DateTime.Now); |
601 | return ret; | 601 | return ret; |
602 | } | 602 | } |
603 | 603 | ||
604 | public BackendResponse TryCreateInventory(Uri owner, InventoryFolder rootFolder) | 604 | public BackendResponse TryCreateInventory(Uri owner, InventoryFolder rootFolder) |
605 | { | 605 | { |
606 | return TryCreateFolder(owner, rootFolder); | 606 | return TryCreateFolder(owner, rootFolder); |
607 | } | 607 | } |
608 | 608 | ||
609 | public BackendResponse TryDeleteItem(Uri owner, UUID itemID) | 609 | public BackendResponse TryDeleteItem(Uri owner, UUID itemID) |
610 | { | 610 | { |
611 | BackendResponse ret; | 611 | BackendResponse ret; |
612 | UUID ownerID; | 612 | UUID ownerID; |
613 | 613 | ||
614 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) | 614 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) |
615 | { | 615 | { |
616 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 616 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
617 | { | 617 | { |
618 | try | 618 | try |
619 | { | 619 | { |
620 | dbConnection.Open(); | 620 | dbConnection.Open(); |
621 | 621 | ||
622 | MySqlCommand command = new MySqlCommand( | 622 | MySqlCommand command = new MySqlCommand( |
623 | "DELETE FROM inventoryitems WHERE inventoryID=?inventoryID AND avatarID=?avatarID", dbConnection); | 623 | "DELETE FROM inventoryitems WHERE inventoryID=?inventoryID AND avatarID=?avatarID", dbConnection); |
624 | 624 | ||
625 | command.Parameters.AddWithValue("?inventoryID", itemID.ToString()); | 625 | command.Parameters.AddWithValue("?inventoryID", itemID.ToString()); |
626 | command.Parameters.AddWithValue("?avatarID", ownerID.ToString()); | 626 | command.Parameters.AddWithValue("?avatarID", ownerID.ToString()); |
627 | 627 | ||
628 | int rowsAffected = command.ExecuteNonQuery(); | 628 | int rowsAffected = command.ExecuteNonQuery(); |
629 | if (rowsAffected == 1) | 629 | if (rowsAffected == 1) |
630 | { | 630 | { |
631 | ret = BackendResponse.Success; | 631 | ret = BackendResponse.Success; |
632 | } | 632 | } |
633 | else | 633 | else |
634 | { | 634 | { |
635 | Logger.Log.ErrorFormat("MySQL DELETE query affected {0} rows", rowsAffected); | 635 | Logger.Log.ErrorFormat("MySQL DELETE query affected {0} rows", rowsAffected); |
636 | ret = BackendResponse.NotFound; | 636 | ret = BackendResponse.NotFound; |
637 | } | 637 | } |
638 | } | 638 | } |
639 | catch (MySqlException ex) | 639 | catch (MySqlException ex) |
640 | { | 640 | { |
641 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); | 641 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
642 | ret = BackendResponse.Failure; | 642 | ret = BackendResponse.Failure; |
643 | } | 643 | } |
644 | } | 644 | } |
645 | } | 645 | } |
646 | else | 646 | else |
647 | { | 647 | { |
648 | ret = BackendResponse.NotFound; | 648 | ret = BackendResponse.NotFound; |
649 | } | 649 | } |
650 | 650 | ||
651 | server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); | 651 | server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); |
652 | return ret; | 652 | return ret; |
653 | } | 653 | } |
654 | 654 | ||
655 | public BackendResponse TryDeleteFolder(Uri owner, UUID folderID) | 655 | public BackendResponse TryDeleteFolder(Uri owner, UUID folderID) |
656 | { | 656 | { |
657 | BackendResponse ret; | 657 | BackendResponse ret; |
658 | UUID ownerID; | 658 | UUID ownerID; |
659 | 659 | ||
660 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) | 660 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) |
661 | { | 661 | { |
662 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 662 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
663 | { | 663 | { |
664 | try | 664 | try |
665 | { | 665 | { |
666 | dbConnection.Open(); | 666 | dbConnection.Open(); |
667 | 667 | ||
668 | MySqlCommand command = new MySqlCommand( | 668 | MySqlCommand command = new MySqlCommand( |
669 | "DELETE FROM inventoryfolders WHERE folderID=?folderID AND agentID=?agentID", dbConnection); | 669 | "DELETE FROM inventoryfolders WHERE folderID=?folderID AND agentID=?agentID", dbConnection); |
670 | 670 | ||
671 | command.Parameters.AddWithValue("?folderID", folderID.ToString()); | 671 | command.Parameters.AddWithValue("?folderID", folderID.ToString()); |
672 | command.Parameters.AddWithValue("?agentID", ownerID.ToString()); | 672 | command.Parameters.AddWithValue("?agentID", ownerID.ToString()); |
673 | 673 | ||
674 | int rowsAffected = command.ExecuteNonQuery(); | 674 | int rowsAffected = command.ExecuteNonQuery(); |
675 | if (rowsAffected == 1) | 675 | if (rowsAffected == 1) |
676 | { | 676 | { |
677 | ret = BackendResponse.Success; | 677 | ret = BackendResponse.Success; |
678 | } | 678 | } |
679 | else | 679 | else |
680 | { | 680 | { |
681 | Logger.Log.ErrorFormat("MySQL DELETE query affected {0} rows", rowsAffected); | 681 | Logger.Log.ErrorFormat("MySQL DELETE query affected {0} rows", rowsAffected); |
682 | ret = BackendResponse.NotFound; | 682 | ret = BackendResponse.NotFound; |
683 | } | 683 | } |
684 | } | 684 | } |
685 | catch (MySqlException ex) | 685 | catch (MySqlException ex) |
686 | { | 686 | { |
687 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); | 687 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
688 | ret = BackendResponse.Failure; | 688 | ret = BackendResponse.Failure; |
689 | } | 689 | } |
690 | } | 690 | } |
691 | } | 691 | } |
692 | else | 692 | else |
693 | { | 693 | { |
694 | ret = BackendResponse.NotFound; | 694 | ret = BackendResponse.NotFound; |
695 | } | 695 | } |
696 | 696 | ||
697 | server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now); | 697 | server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now); |
698 | return ret; | 698 | return ret; |
699 | } | 699 | } |
700 | 700 | ||
701 | public BackendResponse TryPurgeFolder(Uri owner, UUID folderID) | 701 | public BackendResponse TryPurgeFolder(Uri owner, UUID folderID) |
702 | { | 702 | { |
703 | BackendResponse ret; | 703 | BackendResponse ret; |
704 | UUID ownerID; | 704 | UUID ownerID; |
705 | 705 | ||
706 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) | 706 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) |
707 | { | 707 | { |
708 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 708 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
709 | { | 709 | { |
710 | try | 710 | try |
711 | { | 711 | { |
712 | dbConnection.Open(); | 712 | dbConnection.Open(); |
713 | 713 | ||
714 | #region Delete items | 714 | #region Delete items |
715 | 715 | ||
716 | MySqlCommand command = new MySqlCommand( | 716 | MySqlCommand command = new MySqlCommand( |
717 | "DELETE FROM inventoryitems WHERE parentFolderID=?parentFolderID AND avatarID=?avatarID", dbConnection); | 717 | "DELETE FROM inventoryitems WHERE parentFolderID=?parentFolderID AND avatarID=?avatarID", dbConnection); |
718 | 718 | ||
719 | command.Parameters.AddWithValue("?parentFolderID", folderID.ToString()); | 719 | command.Parameters.AddWithValue("?parentFolderID", folderID.ToString()); |
720 | command.Parameters.AddWithValue("?avatarID", ownerID.ToString()); | 720 | command.Parameters.AddWithValue("?avatarID", ownerID.ToString()); |
721 | 721 | ||
722 | int rowsAffected = command.ExecuteNonQuery(); | 722 | int rowsAffected = command.ExecuteNonQuery(); |
723 | 723 | ||
724 | #endregion Delete items | 724 | #endregion Delete items |
725 | 725 | ||
726 | #region Delete folders | 726 | #region Delete folders |
727 | 727 | ||
728 | command = new MySqlCommand( | 728 | command = new MySqlCommand( |
729 | "DELETE FROM inventoryfolders WHERE parentFolderID=?parentFolderID AND agentID=?agentID", dbConnection); | 729 | "DELETE FROM inventoryfolders WHERE parentFolderID=?parentFolderID AND agentID=?agentID", dbConnection); |
730 | 730 | ||
731 | command.Parameters.AddWithValue("?parentFolderID", folderID.ToString()); | 731 | command.Parameters.AddWithValue("?parentFolderID", folderID.ToString()); |
732 | command.Parameters.AddWithValue("?agentID", ownerID.ToString()); | 732 | command.Parameters.AddWithValue("?agentID", ownerID.ToString()); |
733 | 733 | ||
734 | rowsAffected += command.ExecuteNonQuery(); | 734 | rowsAffected += command.ExecuteNonQuery(); |
735 | 735 | ||
736 | #endregion Delete folders | 736 | #endregion Delete folders |
737 | 737 | ||
738 | Logger.Log.DebugFormat("Deleted {0} inventory objects from MySQL in a folder purge", rowsAffected); | 738 | Logger.Log.DebugFormat("Deleted {0} inventory objects from MySQL in a folder purge", rowsAffected); |
739 | 739 | ||
740 | ret = BackendResponse.Success; | 740 | ret = BackendResponse.Success; |
741 | } | 741 | } |
742 | catch (MySqlException ex) | 742 | catch (MySqlException ex) |
743 | { | 743 | { |
744 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); | 744 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
745 | ret = BackendResponse.Failure; | 745 | ret = BackendResponse.Failure; |
746 | } | 746 | } |
747 | } | 747 | } |
748 | } | 748 | } |
749 | else | 749 | else |
750 | { | 750 | { |
751 | ret = BackendResponse.NotFound; | 751 | ret = BackendResponse.NotFound; |
752 | } | 752 | } |
753 | 753 | ||
754 | server.MetricsProvider.LogInventoryPurgeFolder(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); | 754 | server.MetricsProvider.LogInventoryPurgeFolder(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); |
755 | return ret; | 755 | return ret; |
756 | } | 756 | } |
757 | 757 | ||
758 | public int ForEach(Action<Metadata> action, int start, int count) | 758 | public int ForEach(Action<Metadata> action, int start, int count) |
759 | { | 759 | { |
760 | int rowCount = 0; | 760 | int rowCount = 0; |
761 | 761 | ||
762 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) | 762 | using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
763 | { | 763 | { |
764 | MySqlDataReader reader; | 764 | MySqlDataReader reader; |
765 | 765 | ||
766 | try | 766 | try |
767 | { | 767 | { |
768 | dbConnection.Open(); | 768 | dbConnection.Open(); |
769 | 769 | ||
770 | MySqlCommand command = dbConnection.CreateCommand(); | 770 | MySqlCommand command = dbConnection.CreateCommand(); |
771 | command.CommandText = String.Format("SELECT name,description,assetType,temporary,data,id FROM assets LIMIT {0}, {1}", | 771 | command.CommandText = String.Format("SELECT name,description,assetType,temporary,data,id FROM assets LIMIT {0}, {1}", |
772 | start, count); | 772 | start, count); |
773 | reader = command.ExecuteReader(); | 773 | reader = command.ExecuteReader(); |
774 | } | 774 | } |
775 | catch (MySqlException ex) | 775 | catch (MySqlException ex) |
776 | { | 776 | { |
777 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); | 777 | Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
778 | return 0; | 778 | return 0; |
779 | } | 779 | } |
780 | 780 | ||
781 | while (reader.Read()) | 781 | while (reader.Read()) |
782 | { | 782 | { |
783 | Metadata metadata = new Metadata(); | 783 | Metadata metadata = new Metadata(); |
784 | metadata.CreationDate = OpenMetaverse.Utils.Epoch; | 784 | metadata.CreationDate = OpenMetaverse.Utils.Epoch; |
785 | metadata.Description = reader.GetString(1); | 785 | metadata.Description = reader.GetString(1); |
786 | metadata.ID = UUID.Parse(reader.GetString(5)); | 786 | metadata.ID = UUID.Parse(reader.GetString(5)); |
787 | metadata.Name = reader.GetString(0); | 787 | metadata.Name = reader.GetString(0); |
788 | metadata.SHA1 = OpenMetaverse.Utils.SHA1((byte[])reader.GetValue(4)); | 788 | metadata.SHA1 = OpenMetaverse.Utils.SHA1((byte[])reader.GetValue(4)); |
789 | metadata.Temporary = reader.GetBoolean(3); | 789 | metadata.Temporary = reader.GetBoolean(3); |
790 | metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); | 790 | metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); |
791 | 791 | ||
792 | action(metadata); | 792 | action(metadata); |
793 | ++rowCount; | 793 | ++rowCount; |
794 | } | 794 | } |
795 | 795 | ||
796 | reader.Close(); | 796 | reader.Close(); |
797 | } | 797 | } |
798 | 798 | ||
799 | return rowCount; | 799 | return rowCount; |
800 | } | 800 | } |
801 | 801 | ||
802 | #endregion Required Interfaces | 802 | #endregion Required Interfaces |
803 | } | 803 | } |
804 | } | 804 | } |