aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs
diff options
context:
space:
mode:
authorDr Scofield2008-08-20 10:11:11 +0000
committerDr Scofield2008-08-20 10:11:11 +0000
commit5e83a758157520d48b15c725f5be2b196d2414e3 (patch)
tree42ab07bde2a984d06632abd30e6ad59877021f3f /OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs
parentAdding unit test for issue 2006, though it's commented out as those compiler (diff)
downloadopensim-SC-5e83a758157520d48b15c725f5be2b196d2414e3.zip
opensim-SC-5e83a758157520d48b15c725f5be2b196d2414e3.tar.gz
opensim-SC-5e83a758157520d48b15c725f5be2b196d2414e3.tar.bz2
opensim-SC-5e83a758157520d48b15c725f5be2b196d2414e3.tar.xz
From: Alan Webb <alan_webb@us.ibm.com>
cleanups of the REST inventory code.
Diffstat (limited to 'OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs')
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs59
1 files changed, 34 insertions, 25 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs
index 85748fa..a40d197 100644
--- a/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs
+++ b/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs
@@ -23,6 +23,7 @@
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 28
28using libsecondlife; 29using libsecondlife;
@@ -39,8 +40,10 @@ using OpenSim.Framework.Communications.Cache;
39 40
40namespace OpenSim.ApplicationPlugins.Rest.Inventory 41namespace OpenSim.ApplicationPlugins.Rest.Inventory
41{ 42{
43
42 public class RestAssetServices : IRest 44 public class RestAssetServices : IRest
43 { 45 {
46
44 private bool enabled = false; 47 private bool enabled = false;
45 private string qPrefix = "assets"; 48 private string qPrefix = "assets";
46 49
@@ -49,6 +52,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
49 52
50 public RestAssetServices() 53 public RestAssetServices()
51 { 54 {
55
52 Rest.Log.InfoFormat("{0} Asset services initializing", MsgId); 56 Rest.Log.InfoFormat("{0} Asset services initializing", MsgId);
53 Rest.Log.InfoFormat("{0} Using REST Implementation Version {1}", MsgId, Rest.Version); 57 Rest.Log.InfoFormat("{0} Using REST Implementation Version {1}", MsgId, Rest.Version);
54 58
@@ -69,6 +73,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
69 enabled = true; 73 enabled = true;
70 74
71 Rest.Log.InfoFormat("{0} Asset services initialization complete", MsgId); 75 Rest.Log.InfoFormat("{0} Asset services initialization complete", MsgId);
76
72 } 77 }
73 78
74 // Post-construction, pre-enabled initialization opportunity 79 // Post-construction, pre-enabled initialization opportunity
@@ -79,7 +84,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
79 } 84 }
80 85
81 // Called by the plug-in to halt REST processing. Local processing is 86 // Called by the plug-in to halt REST processing. Local processing is
82 // disabled, and control blocks until all current processing has 87 // disabled, and control blocks until all current processing has
83 // completed. No new processing will be started 88 // completed. No new processing will be started
84 89
85 public void Close() 90 public void Close()
@@ -106,14 +111,14 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
106 111
107 private void DoAsset(RequestData rparm) 112 private void DoAsset(RequestData rparm)
108 { 113 {
109 if (!enabled) 114
110 return; 115 if (!enabled) return;
111 116
112 AssetRequestData rdata = (AssetRequestData) rparm; 117 AssetRequestData rdata = (AssetRequestData) rparm;
113 118
114 Rest.Log.DebugFormat("{0} REST Asset handler ENTRY", MsgId); 119 Rest.Log.DebugFormat("{0} REST Asset handler ENTRY", MsgId);
115 120
116 // Now that we know this is a serious attempt to 121 // Now that we know this is a serious attempt to
117 // access inventory data, we should find out who 122 // access inventory data, we should find out who
118 // is asking, and make sure they are authorized 123 // is asking, and make sure they are authorized
119 // to do so. We need to validate the caller's 124 // to do so. We need to validate the caller's
@@ -124,14 +129,14 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
124 // With the present HTTP server we can't use the 129 // With the present HTTP server we can't use the
125 // builtin authentication mechanisms because they 130 // builtin authentication mechanisms because they
126 // would be enforced for all in-bound requests. 131 // would be enforced for all in-bound requests.
127 // Instead we look at the headers ourselves and 132 // Instead we look at the headers ourselves and
128 // handle authentication directly. 133 // handle authentication directly.
129 134
130 try 135 try
131 { 136 {
132 if (!rdata.IsAuthenticated) 137 if (!rdata.IsAuthenticated)
133 { 138 {
134 rdata.Fail(Rest.HttpStatusCodeNotAuthorized, Rest.HttpStatusDescNotAuthorized); 139 rdata.Fail(Rest.HttpStatusCodeNotAuthorized, String.Format("user \"{0}\" could not be authenticated"));
135 } 140 }
136 } 141 }
137 catch (RestException e) 142 catch (RestException e)
@@ -139,13 +144,13 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
139 if (e.statusCode == Rest.HttpStatusCodeNotAuthorized) 144 if (e.statusCode == Rest.HttpStatusCodeNotAuthorized)
140 { 145 {
141 Rest.Log.WarnFormat("{0} User not authenticated", MsgId); 146 Rest.Log.WarnFormat("{0} User not authenticated", MsgId);
142 Rest.Log.DebugFormat("{0} Authorization header: {1}", MsgId, 147 Rest.Log.DebugFormat("{0} Authorization header: {1}", MsgId,
143 rdata.request.Headers.Get("Authorization")); 148 rdata.request.Headers.Get("Authorization"));
144 } 149 }
145 else 150 else
146 { 151 {
147 Rest.Log.ErrorFormat("{0} User authentication failed", MsgId); 152 Rest.Log.ErrorFormat("{0} User authentication failed", MsgId);
148 Rest.Log.DebugFormat("{0} Authorization header: {1}", MsgId, 153 Rest.Log.DebugFormat("{0} Authorization header: {1}", MsgId,
149 rdata.request.Headers.Get("Authorization")); 154 rdata.request.Headers.Get("Authorization"));
150 } 155 }
151 throw (e); 156 throw (e);
@@ -155,7 +160,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
155 // the parameters we need, fail the request. Parameters do NOT include 160 // the parameters we need, fail the request. Parameters do NOT include
156 // any supplied query values. 161 // any supplied query values.
157 162
158 if (rdata.parameters.Length > 0) 163 if (rdata.Parameters.Length > 0)
159 { 164 {
160 switch (rdata.method) 165 switch (rdata.method)
161 { 166 {
@@ -168,26 +173,27 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
168 case "post" : 173 case "post" :
169 case "delete" : 174 case "delete" :
170 default : 175 default :
171 Rest.Log.WarnFormat("{0} Asset: Method not supported: {1}", 176 Rest.Log.WarnFormat("{0} Asset: Method not supported: {1}",
172 MsgId, rdata.method); 177 MsgId, rdata.method);
173 rdata.Fail(Rest.HttpStatusCodeBadRequest, 178 rdata.Fail(Rest.HttpStatusCodeBadRequest,String.Format("method <{0}> not supported", rdata.method));
174 Rest.HttpStatusDescBadRequest);
175 break; 179 break;
176 } 180 }
177 } 181 }
178 else 182 else
179 { 183 {
180 Rest.Log.WarnFormat("{0} Asset: No agent information provided", MsgId); 184 Rest.Log.WarnFormat("{0} Asset: No agent information provided", MsgId);
181 rdata.Fail(Rest.HttpStatusCodeBadRequest, Rest.HttpStatusDescBadRequest); 185 rdata.Fail(Rest.HttpStatusCodeBadRequest, "no agent information provided");
182 } 186 }
183 187
184 Rest.Log.DebugFormat("{0} REST Asset handler EXIT", MsgId); 188 Rest.Log.DebugFormat("{0} REST Asset handler EXIT", MsgId);
189
185 } 190 }
186 191
187 #endregion Interface 192 #endregion Interface
188 193
189 private void DoGet(AssetRequestData rdata) 194 private void DoGet(AssetRequestData rdata)
190 { 195 {
196
191 bool istexture = false; 197 bool istexture = false;
192 198
193 Rest.Log.DebugFormat("{0} REST Asset handler, Method = <{1}> ENTRY", MsgId, rdata.method); 199 Rest.Log.DebugFormat("{0} REST Asset handler, Method = <{1}> ENTRY", MsgId, rdata.method);
@@ -195,14 +201,16 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
195 // The only parameter we accept is an LLUUID for 201 // The only parameter we accept is an LLUUID for
196 // the asset 202 // the asset
197 203
198 if (rdata.parameters.Length == 1) 204 if (rdata.Parameters.Length == 1)
199 { 205 {
200 LLUUID uuid = new LLUUID(rdata.parameters[0]); 206
207 LLUUID uuid = new LLUUID(rdata.Parameters[0]);
201 AssetBase asset = Rest.AssetServices.GetAsset(uuid, istexture); 208 AssetBase asset = Rest.AssetServices.GetAsset(uuid, istexture);
202 209
203 if (asset != null) 210 if (asset != null)
204 { 211 {
205 Rest.Log.DebugFormat("{0} Asset located <{1}>", MsgId, rdata.parameters[0]); 212
213 Rest.Log.DebugFormat("{0} Asset located <{1}>", MsgId, rdata.Parameters[0]);
206 214
207 rdata.initXmlWriter(); 215 rdata.initXmlWriter();
208 216
@@ -218,17 +226,18 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
218 rdata.writer.WriteBase64(asset.Data,0,asset.Data.Length); 226 rdata.writer.WriteBase64(asset.Data,0,asset.Data.Length);
219 227
220 rdata.writer.WriteFullEndElement(); 228 rdata.writer.WriteFullEndElement();
229
221 } 230 }
222 else 231 else
223 { 232 {
224 Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, rdata.path); 233 Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, rdata.path);
225 rdata.Fail(Rest.HttpStatusCodeNotFound, 234 rdata.Fail(Rest.HttpStatusCodeNotFound, "invalid parameters");
226 Rest.HttpStatusDescNotFound);
227 } 235 }
228 } 236 }
229 237
230 rdata.Complete(); 238 rdata.Complete();
231 rdata.Respond("Asset " + rdata.method + ": Normal completion"); 239 rdata.Respond("Asset " + rdata.method + ": Normal completion");
240
232 } 241 }
233 242
234 private void DoPut(AssetRequestData rdata) 243 private void DoPut(AssetRequestData rdata)
@@ -238,7 +247,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
238 // The only parameter we accept is an LLUUID for 247 // The only parameter we accept is an LLUUID for
239 // the asset 248 // the asset
240 249
241 if (rdata.parameters.Length == 1) 250 if (rdata.Parameters.Length == 1)
242 { 251 {
243 rdata.initXmlReader(); 252 rdata.initXmlReader();
244 XmlReader xml = rdata.reader; 253 XmlReader xml = rdata.reader;
@@ -246,12 +255,11 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
246 if (!xml.ReadToFollowing("Asset")) 255 if (!xml.ReadToFollowing("Asset"))
247 { 256 {
248 Rest.Log.DebugFormat("{0} Invalid request data: <{1}>", MsgId, rdata.path); 257 Rest.Log.DebugFormat("{0} Invalid request data: <{1}>", MsgId, rdata.path);
249 rdata.Fail(Rest.HttpStatusCodeBadRequest, 258 rdata.Fail(Rest.HttpStatusCodeBadRequest,"invalid request data");
250 Rest.HttpStatusDescBadRequest);
251 } 259 }
252 260
253 AssetBase asset = new AssetBase(); 261 AssetBase asset = new AssetBase();
254 asset.ID = rdata.parameters[0]; 262 asset.ID = rdata.Parameters[0];
255 asset.Name = xml.GetAttribute("name"); 263 asset.Name = xml.GetAttribute("name");
256 asset.Description = xml.GetAttribute("desc"); 264 asset.Description = xml.GetAttribute("desc");
257 asset.Type = SByte.Parse(xml.GetAttribute("type")); 265 asset.Type = SByte.Parse(xml.GetAttribute("type"));
@@ -264,12 +272,12 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
264 else 272 else
265 { 273 {
266 Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, rdata.path); 274 Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, rdata.path);
267 rdata.Fail(Rest.HttpStatusCodeNotFound, 275 rdata.Fail(Rest.HttpStatusCodeNotFound, "invalid parameters");
268 Rest.HttpStatusDescNotFound);
269 } 276 }
270 277
271 rdata.Complete(); 278 rdata.Complete();
272 rdata.Respond("Asset " + rdata.method + ": Normal completion"); 279 rdata.Respond("Asset " + rdata.method + ": Normal completion");
280
273 } 281 }
274 282
275 internal class AssetRequestData : RequestData 283 internal class AssetRequestData : RequestData
@@ -279,5 +287,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
279 { 287 {
280 } 288 }
281 } 289 }
290
282 } 291 }
283} 292}