aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs317
1 files changed, 317 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs
new file mode 100644
index 0000000..6e1d657
--- /dev/null
+++ b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs
@@ -0,0 +1,317 @@
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.Console;
36using OpenSim.Framework.Communications;
37using OpenSim.Framework.Servers.HttpServer;
38using OpenSim.Services.Interfaces;
39using OpenSim.Server.Base;
40using OpenMetaverse;
41
42namespace OpenSim.Services.Connectors
43{
44 public class XInventoryServicesConnector : IInventoryService
45 {
46 private static readonly ILog m_log =
47 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
49
50 private string m_ServerURI = String.Empty;
51
52 public XInventoryServicesConnector()
53 {
54 }
55
56 public XInventoryServicesConnector(string serverURI)
57 {
58 m_ServerURI = serverURI.TrimEnd('/');
59 }
60
61 public XInventoryServicesConnector(IConfigSource source)
62 {
63 Initialise(source);
64 }
65
66 public virtual void Initialise(IConfigSource source)
67 {
68 IConfig assetConfig = source.Configs["InventoryService"];
69 if (assetConfig == null)
70 {
71 m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpanSim.ini");
72 throw new Exception("Inventory connector init error");
73 }
74
75 string serviceURI = assetConfig.GetString("InventoryServerURI",
76 String.Empty);
77
78 if (serviceURI == String.Empty)
79 {
80 m_log.Error("[INVENTORY CONNECTOR]: No Server URI named in section InventoryService");
81 throw new Exception("Inventory connector init error");
82 }
83 m_ServerURI = serviceURI;
84 }
85
86 public bool CreateUserInventory(UUID principalID)
87 {
88 Dictionary<string,object> ret = MakeRequest("CREATEUSERINVENTORY",
89 new Dictionary<string,object> {
90 { "PRINCIPAL", principalID.ToString() }
91 });
92
93 if (ret == null)
94 return false;
95
96 return bool.Parse(ret["RESULT"].ToString());
97 }
98
99 public List<InventoryFolderBase> GetInventorySkeleton(UUID userId)
100 {
101 return null;
102 }
103
104 public InventoryFolderBase GetRootFolder(UUID principalID)
105 {
106 return null;
107 }
108
109 public InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
110 {
111 return null;
112 }
113
114 public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
115 {
116 return null;
117 }
118
119 public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
120 {
121 return null;
122 }
123
124 public bool AddFolder(InventoryFolderBase folder)
125 {
126 Dictionary<string,object> ret = MakeRequest("ADDFOLDER",
127 new Dictionary<string,object> {
128 { "ParentID", folder.ParentID.ToString() },
129 { "Type", folder.Type.ToString() },
130 { "Version", folder.Version.ToString() },
131 { "Name", folder.Name.ToString() },
132 { "Owner", folder.Owner.ToString() },
133 { "ID", folder.ID.ToString() }
134 });
135
136 if (ret == null)
137 return false;
138
139 return bool.Parse(ret["RESULT"].ToString());
140 }
141
142 public bool UpdateFolder(InventoryFolderBase folder)
143 {
144 Dictionary<string,object> ret = MakeRequest("UPDATEFOLDER",
145 new Dictionary<string,object> {
146 { "ParentID", folder.ParentID.ToString() },
147 { "Type", folder.Type.ToString() },
148 { "Version", folder.Version.ToString() },
149 { "Name", folder.Name.ToString() },
150 { "Owner", folder.Owner.ToString() },
151 { "ID", folder.ID.ToString() }
152 });
153
154 if (ret == null)
155 return false;
156
157 return bool.Parse(ret["RESULT"].ToString());
158 }
159
160 public bool MoveFolder(InventoryFolderBase folder)
161 {
162 Dictionary<string,object> ret = MakeRequest("MOVEFOLDER",
163 new Dictionary<string,object> {
164 { "ParentID", folder.ParentID.ToString() },
165 { "ID", folder.ID.ToString() }
166 });
167
168 if (ret == null)
169 return false;
170
171 return bool.Parse(ret["RESULT"].ToString());
172 }
173
174 public bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
175 {
176 List<string> slist = new List<string>();
177
178 foreach (UUID f in folderIDs)
179 slist.Add(f.ToString());
180
181 Dictionary<string,object> ret = MakeRequest("DELETEFOLDERS",
182 new Dictionary<string,object> {
183 { "PRINCIPAL", principalID.ToString() },
184 { "FOLDERS", slist }
185 });
186
187 if (ret == null)
188 return false;
189
190 return bool.Parse(ret["RESULT"].ToString());
191 }
192
193 public bool PurgeFolder(InventoryFolderBase folder)
194 {
195 Dictionary<string,object> ret = MakeRequest("PURGEFOLDER",
196 new Dictionary<string,object> {
197 { "ID", folder.ID.ToString() }
198 });
199
200 if (ret == null)
201 return false;
202
203 return bool.Parse(ret["RESULT"].ToString());
204 }
205
206 public bool AddItem(InventoryItemBase item)
207 {
208 Dictionary<string,object> ret = MakeRequest("CREATEUSERINVENTORY",
209 new Dictionary<string,object> {
210 });
211
212 if (ret == null)
213 return false;
214
215 return bool.Parse(ret["RESULT"].ToString());
216 }
217
218 public bool UpdateItem(InventoryItemBase item)
219 {
220 Dictionary<string,object> ret = MakeRequest("CREATEUSERINVENTORY",
221 new Dictionary<string,object> {
222 });
223
224 if (ret == null)
225 return false;
226
227 return bool.Parse(ret["RESULT"].ToString());
228 }
229
230 public bool MoveItems(UUID ownerID, List<InventoryItemBase> items)
231 {
232 return false;
233 }
234
235 public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
236 {
237 List<string> slist = new List<string>();
238
239 foreach (UUID f in itemIDs)
240 slist.Add(f.ToString());
241
242 Dictionary<string,object> ret = MakeRequest("DELETEITEMS",
243 new Dictionary<string,object> {
244 { "PRINCIPAL", principalID.ToString() },
245 { "ITEMS", slist }
246 });
247
248 if (ret == null)
249 return false;
250
251 return bool.Parse(ret["RESULT"].ToString());
252 }
253
254 public InventoryItemBase GetItem(InventoryItemBase item)
255 {
256 return null;
257 }
258
259 public InventoryFolderBase GetFolder(InventoryFolderBase folder)
260 {
261 return null;
262 }
263
264 public List<InventoryItemBase> GetActiveGestures(UUID userId)
265 {
266 return null;
267 }
268
269 public int GetAssetPermissions(UUID principalID, UUID assetID)
270 {
271 Dictionary<string,object> ret = MakeRequest("GETASSETPERMISSIONS",
272 new Dictionary<string,object> {
273 { "PRINCIPAL", principalID.ToString() },
274 { "ASSET", assetID.ToString() }
275 });
276
277 if (ret == null)
278 return false;
279
280 return int.Parse(ret["RESULT"].ToString());
281 }
282
283
284 // These are either obsolete or unused
285 //
286 public InventoryCollection GetUserInventory(UUID principalID)
287 {
288 return null;
289 }
290
291 public void GetUserInventory(UUID principalID, InventoryReceiptCallback callback)
292 {
293 }
294
295 public bool HasInventoryForUser(UUID principalID)
296 {
297 return false;
298 }
299
300 // Helpers
301 //
302 private Dictionary<string,object> MakeRequest(string method,
303 Dictionary<string,object> sendData)
304 {
305 sendData["METHOD"] = method;
306
307 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
308 m_ServerURI + "/xinventory",
309 ServerUtils.BuildQueryString(sendData));
310
311 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
312 reply);
313
314 return replyData;
315 }
316 }
317}