HGInventoryServiceConnector.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. using log4net;
  28. using Nini.Config;
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Reflection;
  32. using OpenSim.Framework;
  33. using OpenSim.Services.Interfaces;
  34. using OpenMetaverse;
  35. namespace OpenSim.Services.Connectors.Inventory
  36. {
  37. public class HGInventoryServiceConnector : ISessionAuthInventoryService
  38. {
  39. private static readonly ILog m_log =
  40. LogManager.GetLogger(
  41. MethodBase.GetCurrentMethod().DeclaringType);
  42. private Dictionary<string, InventoryServicesConnector> m_connectors = new Dictionary<string, InventoryServicesConnector>();
  43. public HGInventoryServiceConnector(IConfigSource source)
  44. {
  45. IConfig moduleConfig = source.Configs["Modules"];
  46. if (moduleConfig != null)
  47. {
  48. IConfig inventoryConfig = source.Configs["InventoryService"];
  49. if (inventoryConfig == null)
  50. {
  51. m_log.Error("[HG INVENTORY SERVICE]: InventoryService missing from OpenSim.ini");
  52. return;
  53. }
  54. m_log.Info("[HG INVENTORY SERVICE]: HG inventory service enabled");
  55. }
  56. }
  57. private bool StringToUrlAndUserID(string id, out string url, out string userID)
  58. {
  59. url = String.Empty;
  60. userID = String.Empty;
  61. Uri assetUri;
  62. if (Uri.TryCreate(id, UriKind.Absolute, out assetUri) &&
  63. assetUri.Scheme == Uri.UriSchemeHttp)
  64. {
  65. url = "http://" + assetUri.Authority;
  66. userID = assetUri.LocalPath.Trim(new char[] { '/' });
  67. return true;
  68. }
  69. return false;
  70. }
  71. private ISessionAuthInventoryService GetConnector(string url)
  72. {
  73. InventoryServicesConnector connector = null;
  74. lock (m_connectors)
  75. {
  76. if (m_connectors.ContainsKey(url))
  77. {
  78. connector = m_connectors[url];
  79. }
  80. else
  81. {
  82. // We're instantiating this class explicitly, but this won't
  83. // work in general, because the remote grid may be running
  84. // an inventory server that has a different protocol.
  85. // Eventually we will want a piece of protocol asking
  86. // the remote server about its kind. Definitely cool thing to do!
  87. connector = new InventoryServicesConnector(url);
  88. m_connectors.Add(url, connector);
  89. }
  90. }
  91. return connector;
  92. }
  93. public string Host
  94. {
  95. get { return string.Empty; }
  96. }
  97. public void GetUserInventory(string id, UUID sessionID, InventoryReceiptCallback callback)
  98. {
  99. m_log.Debug("[HGInventory]: GetUserInventory " + id);
  100. string url = string.Empty;
  101. string userID = string.Empty;
  102. if (StringToUrlAndUserID(id, out url, out userID))
  103. {
  104. ISessionAuthInventoryService connector = GetConnector(url);
  105. connector.GetUserInventory(userID, sessionID, callback);
  106. }
  107. }
  108. public bool AddFolder(string id, InventoryFolderBase folder, UUID sessionID)
  109. {
  110. string url = string.Empty;
  111. string userID = string.Empty;
  112. if (StringToUrlAndUserID(id, out url, out userID))
  113. {
  114. ISessionAuthInventoryService connector = GetConnector(url);
  115. return connector.AddFolder(userID, folder, sessionID);
  116. }
  117. return false;
  118. }
  119. public bool UpdateFolder(string id, InventoryFolderBase folder, UUID sessionID)
  120. {
  121. string url = string.Empty;
  122. string userID = string.Empty;
  123. if (StringToUrlAndUserID(id, out url, out userID))
  124. {
  125. ISessionAuthInventoryService connector = GetConnector(url);
  126. return connector.UpdateFolder(userID, folder, sessionID);
  127. }
  128. return false;
  129. }
  130. public bool MoveFolder(string id, InventoryFolderBase folder, UUID sessionID)
  131. {
  132. string url = string.Empty;
  133. string userID = string.Empty;
  134. if (StringToUrlAndUserID(id, out url, out userID))
  135. {
  136. ISessionAuthInventoryService connector = GetConnector(url);
  137. return connector.MoveFolder(userID, folder, sessionID);
  138. }
  139. return false;
  140. }
  141. public bool PurgeFolder(string id, InventoryFolderBase folder, UUID sessionID)
  142. {
  143. string url = string.Empty;
  144. string userID = string.Empty;
  145. if (StringToUrlAndUserID(id, out url, out userID))
  146. {
  147. ISessionAuthInventoryService connector = GetConnector(url);
  148. return connector.PurgeFolder(userID, folder, sessionID);
  149. }
  150. return false;
  151. }
  152. public bool AddItem(string id, InventoryItemBase item, UUID sessionID)
  153. {
  154. string url = string.Empty;
  155. string userID = string.Empty;
  156. if (StringToUrlAndUserID(id, out url, out userID))
  157. {
  158. ISessionAuthInventoryService connector = GetConnector(url);
  159. return connector.AddItem(userID, item, sessionID);
  160. }
  161. return false;
  162. }
  163. public bool UpdateItem(string id, InventoryItemBase item, UUID sessionID)
  164. {
  165. string url = string.Empty;
  166. string userID = string.Empty;
  167. if (StringToUrlAndUserID(id, out url, out userID))
  168. {
  169. ISessionAuthInventoryService connector = GetConnector(url);
  170. return connector.UpdateItem(userID, item, sessionID);
  171. }
  172. return false;
  173. }
  174. public bool DeleteItem(string id, InventoryItemBase item, UUID sessionID)
  175. {
  176. string url = string.Empty;
  177. string userID = string.Empty;
  178. if (StringToUrlAndUserID(id, out url, out userID))
  179. {
  180. ISessionAuthInventoryService connector = GetConnector(url);
  181. return connector.UpdateItem(userID, item, sessionID);
  182. }
  183. return false;
  184. }
  185. public InventoryItemBase QueryItem(string id, InventoryItemBase item, UUID sessionID)
  186. {
  187. string url = string.Empty;
  188. string userID = string.Empty;
  189. if (StringToUrlAndUserID(id, out url, out userID))
  190. {
  191. ISessionAuthInventoryService connector = GetConnector(url);
  192. return connector.QueryItem(userID, item, sessionID);
  193. }
  194. return null;
  195. }
  196. public InventoryFolderBase QueryFolder(string id, InventoryFolderBase folder, UUID sessionID)
  197. {
  198. string url = string.Empty;
  199. string userID = string.Empty;
  200. if (StringToUrlAndUserID(id, out url, out userID))
  201. {
  202. ISessionAuthInventoryService connector = GetConnector(url);
  203. return connector.QueryFolder(userID, folder, sessionID);
  204. }
  205. return null;
  206. }
  207. }
  208. }