aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/AssetService/HGAssetService.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/Connectors/Asset/HGAssetServiceConnector.cs (renamed from OpenSim/Services/AssetService/HGAssetService.cs)357
1 files changed, 178 insertions, 179 deletions
diff --git a/OpenSim/Services/AssetService/HGAssetService.cs b/OpenSim/Services/Connectors/Asset/HGAssetServiceConnector.cs
index b3e3f17..31e0aa9 100644
--- a/OpenSim/Services/AssetService/HGAssetService.cs
+++ b/OpenSim/Services/Connectors/Asset/HGAssetServiceConnector.cs
@@ -1,179 +1,178 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the 12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using log4net; 28using log4net;
29using Nini.Config; 29using Nini.Config;
30using System; 30using System;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Reflection; 32using System.Reflection;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Services.Interfaces; 34using OpenSim.Services.Interfaces;
35using OpenSim.Services.Connectors; 35
36 36namespace OpenSim.Services.Connectors
37namespace OpenSim.Services.AssetService 37{
38{ 38 public class HGAssetServiceConnector : IAssetService
39 public class HGAssetService : IAssetService 39 {
40 { 40 private static readonly ILog m_log =
41 private static readonly ILog m_log = 41 LogManager.GetLogger(
42 LogManager.GetLogger( 42 MethodBase.GetCurrentMethod().DeclaringType);
43 MethodBase.GetCurrentMethod().DeclaringType); 43
44 44 private Dictionary<string, AssetServicesConnector> m_connectors = new Dictionary<string, AssetServicesConnector>();
45 private Dictionary<string, AssetServicesConnector> m_connectors = new Dictionary<string, AssetServicesConnector>(); 45
46 46 public HGAssetServiceConnector(IConfigSource source)
47 public HGAssetService(IConfigSource source) 47 {
48 { 48 IConfig moduleConfig = source.Configs["Modules"];
49 IConfig moduleConfig = source.Configs["Modules"]; 49 if (moduleConfig != null)
50 if (moduleConfig != null) 50 {
51 { 51 // string name = moduleConfig.GetString("AssetServices", "");
52 // string name = moduleConfig.GetString("AssetServices", ""); 52
53 53 IConfig assetConfig = source.Configs["AssetService"];
54 IConfig assetConfig = source.Configs["AssetService"]; 54 if (assetConfig == null)
55 if (assetConfig == null) 55 {
56 { 56 m_log.Error("[HG ASSET SERVICE]: AssetService missing from OpenSim.ini");
57 m_log.Error("[HG ASSET SERVICE]: AssetService missing from OpanSim.ini"); 57 return;
58 return; 58 }
59 } 59
60 60 m_log.Info("[HG ASSET SERVICE]: HG asset service enabled");
61 m_log.Info("[HG ASSET SERVICE]: HG asset service enabled"); 61 }
62 } 62 }
63 } 63
64 64 private bool StringToUrlAndAssetID(string id, out string url, out string assetID)
65 private bool StringToUrlAndAssetID(string id, out string url, out string assetID) 65 {
66 { 66 url = String.Empty;
67 url = String.Empty; 67 assetID = String.Empty;
68 assetID = String.Empty; 68
69 69 Uri assetUri;
70 Uri assetUri; 70
71 71 if (Uri.TryCreate(id, UriKind.Absolute, out assetUri) &&
72 if (Uri.TryCreate(id, UriKind.Absolute, out assetUri) && 72 assetUri.Scheme == Uri.UriSchemeHttp)
73 assetUri.Scheme == Uri.UriSchemeHttp) 73 {
74 { 74 url = "http://" + assetUri.Authority;
75 url = "http://" + assetUri.Authority; 75 assetID = assetUri.LocalPath.Trim(new char[] {'/'});
76 assetID = assetUri.LocalPath.Trim(new char[] {'/'}); 76 return true;
77 return true; 77 }
78 } 78
79 79 return false;
80 return false; 80 }
81 } 81
82 82 private IAssetService GetConnector(string url)
83 private IAssetService GetConnector(string url) 83 {
84 { 84 AssetServicesConnector connector = null;
85 AssetServicesConnector connector = null; 85 lock (m_connectors)
86 lock (m_connectors) 86 {
87 { 87 if (m_connectors.ContainsKey(url))
88 if (m_connectors.ContainsKey(url)) 88 {
89 { 89 connector = m_connectors[url];
90 connector = m_connectors[url]; 90 }
91 } 91 else
92 else 92 {
93 { 93 // We're instantiating this class explicitly, but this won't
94 // We're instantiating this class explicitly, but this won't 94 // work in general, because the remote grid may be running
95 // work in general, because the remote grid may be running 95 // an asset server that has a different protocol.
96 // an asset server that has a different protocol. 96 // Eventually we will want a piece of protocol asking
97 // Eventually we will want a piece of protocol asking 97 // the remote server about its kind. Definitely cool thing to do!
98 // the remote server about its kind. Definitely cool thing to do! 98 connector = new AssetServicesConnector(url);
99 connector = new AssetServicesConnector(url); 99 m_connectors.Add(url, connector);
100 m_connectors.Add(url, connector); 100 }
101 } 101 }
102 } 102 return connector;
103 return connector; 103 }
104 } 104
105 105 public AssetBase Get(string id)
106 public AssetBase Get(string id) 106 {
107 { 107 string url = string.Empty;
108 string url = string.Empty; 108 string assetID = string.Empty;
109 string assetID = string.Empty; 109
110 110 if (StringToUrlAndAssetID(id, out url, out assetID))
111 if (StringToUrlAndAssetID(id, out url, out assetID)) 111 {
112 { 112 IAssetService connector = GetConnector(url);
113 IAssetService connector = GetConnector(url); 113 return connector.Get(assetID);
114 return connector.Get(assetID); 114 }
115 } 115
116 116 return null;
117 return null; 117 }
118 } 118
119 119 public AssetMetadata GetMetadata(string id)
120 public AssetMetadata GetMetadata(string id) 120 {
121 { 121 string url = string.Empty;
122 string url = string.Empty; 122 string assetID = string.Empty;
123 string assetID = string.Empty; 123
124 124 if (StringToUrlAndAssetID(id, out url, out assetID))
125 if (StringToUrlAndAssetID(id, out url, out assetID)) 125 {
126 { 126 IAssetService connector = GetConnector(url);
127 IAssetService connector = GetConnector(url); 127 return connector.GetMetadata(assetID);
128 return connector.GetMetadata(assetID); 128 }
129 } 129
130 130 return null;
131 return null; 131 }
132 } 132
133 133 public byte[] GetData(string id)
134 public byte[] GetData(string id) 134 {
135 { 135 return null;
136 return null; 136 }
137 } 137
138 138 public bool Get(string id, Object sender, AssetRetrieved handler)
139 public bool Get(string id, Object sender, AssetRetrieved handler) 139 {
140 { 140 string url = string.Empty;
141 string url = string.Empty; 141 string assetID = string.Empty;
142 string assetID = string.Empty; 142
143 143 if (StringToUrlAndAssetID(id, out url, out assetID))
144 if (StringToUrlAndAssetID(id, out url, out assetID)) 144 {
145 { 145 IAssetService connector = GetConnector(url);
146 IAssetService connector = GetConnector(url); 146 return connector.Get(assetID, sender, handler);
147 return connector.Get(assetID, sender, handler); 147 }
148 } 148
149 149 return false;
150 return false; 150 }
151 } 151
152 152 public string Store(AssetBase asset)
153 public string Store(AssetBase asset) 153 {
154 { 154 string url = string.Empty;
155 string url = string.Empty; 155 string assetID = string.Empty;
156 string assetID = string.Empty; 156
157 157 if (StringToUrlAndAssetID(asset.ID, out url, out assetID))
158 if (StringToUrlAndAssetID(asset.ID, out url, out assetID)) 158 {
159 { 159 IAssetService connector = GetConnector(url);
160 IAssetService connector = GetConnector(url); 160 // Restore the assetID to a simple UUID
161 // Restore the assetID to a simple UUID 161 asset.ID = assetID;
162 asset.ID = assetID; 162 return connector.Store(asset);
163 return connector.Store(asset); 163 }
164 } 164
165 165 return String.Empty;
166 return String.Empty; 166 }
167 } 167
168 168 public bool UpdateContent(string id, byte[] data)
169 public bool UpdateContent(string id, byte[] data) 169 {
170 { 170 return false;
171 return false; 171 }
172 } 172
173 173 public bool Delete(string id)
174 public bool Delete(string id) 174 {
175 { 175 return false;
176 return false; 176 }
177 } 177 }
178 } 178}
179}