aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDr Scofield2008-09-23 15:07:20 +0000
committerDr Scofield2008-09-23 15:07:20 +0000
commit29950ba419018f3cc4c2cf3db7f42db9f5653992 (patch)
treee60132104e1747b62f1508495ceb3e1ad7402add
parentReorder projects in prebuild.xml to enable dependecies from DNE to Shared (diff)
downloadopensim-SC_OLD-29950ba419018f3cc4c2cf3db7f42db9f5653992.zip
opensim-SC_OLD-29950ba419018f3cc4c2cf3db7f42db9f5653992.tar.gz
opensim-SC_OLD-29950ba419018f3cc4c2cf3db7f42db9f5653992.tar.bz2
opensim-SC_OLD-29950ba419018f3cc4c2cf3db7f42db9f5653992.tar.xz
this add POST support for asset services (howto forthcoming) and fixes
a couple of minor bugs.
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs118
1 files changed, 109 insertions, 9 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs
index 7a6d4af..dcd209f 100644
--- a/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs
+++ b/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs
@@ -170,6 +170,8 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
170 DoPut(rdata); 170 DoPut(rdata);
171 break; 171 break;
172 case "post" : 172 case "post" :
173 DoPost(rdata);
174 break;
173 case "delete" : 175 case "delete" :
174 default : 176 default :
175 Rest.Log.WarnFormat("{0} Asset: Method not supported: {1}", 177 Rest.Log.WarnFormat("{0} Asset: Method not supported: {1}",
@@ -238,6 +240,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
238 } 240 }
239 241
240 /// <summary> 242 /// <summary>
243 /// UPDATE existing item, if it exists. URI identifies the item in question.
241 /// The only parameter we recognize is a UUID. The enclosed asset data (base-64 encoded) 244 /// The only parameter we recognize is a UUID. The enclosed asset data (base-64 encoded)
242 /// is decoded and stored in the database, identified by the supplied UUID. 245 /// is decoded and stored in the database, identified by the supplied UUID.
243 /// </summary> 246 /// </summary>
@@ -245,10 +248,14 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
245 private void DoPut(AssetRequestData rdata) 248 private void DoPut(AssetRequestData rdata)
246 { 249 {
247 250
251 bool modified = false;
252 bool created = false;
253
248 Rest.Log.DebugFormat("{0} REST Asset handler, Method = <{1}> ENTRY", MsgId, rdata.method); 254 Rest.Log.DebugFormat("{0} REST Asset handler, Method = <{1}> ENTRY", MsgId, rdata.method);
249 255
250 if (rdata.Parameters.Length == 1) 256 if (rdata.Parameters.Length == 1)
251 { 257 {
258
252 rdata.initXmlReader(); 259 rdata.initXmlReader();
253 XmlReader xml = rdata.reader; 260 XmlReader xml = rdata.reader;
254 261
@@ -258,16 +265,29 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
258 rdata.Fail(Rest.HttpStatusCodeBadRequest,"invalid request data"); 265 rdata.Fail(Rest.HttpStatusCodeBadRequest,"invalid request data");
259 } 266 }
260 267
261 AssetBase asset = new AssetBase(); 268 UUID uuid = new UUID(rdata.Parameters[0]);
262 asset.ID = rdata.Parameters[0]; 269 AssetBase asset = Rest.AssetServices.GetAsset(uuid, false);
263 asset.Name = xml.GetAttribute("name"); 270
271 modified = (asset != null);
272 created = !modified;
273
274 asset = new AssetBase();
275 asset.FullID = uuid;
276 asset.Name = xml.GetAttribute("name");
264 asset.Description = xml.GetAttribute("desc"); 277 asset.Description = xml.GetAttribute("desc");
265 asset.Type = SByte.Parse(xml.GetAttribute("type")); 278 asset.Type = SByte.Parse(xml.GetAttribute("type"));
266 asset.Local = Int32.Parse(xml.GetAttribute("local")) != 0; 279 asset.Local = Int32.Parse(xml.GetAttribute("local")) != 0;
267 asset.Temporary = Int32.Parse(xml.GetAttribute("temporary")) != 0; 280 asset.Temporary = Int32.Parse(xml.GetAttribute("temporary")) != 0;
268 asset.Data = Convert.FromBase64String(xml.ReadElementContentAsString("Asset", "")); 281 asset.Data = Convert.FromBase64String(xml.ReadElementContentAsString("Asset", ""));
282
283 if (asset.ID != rdata.Parameters[0])
284 {
285 Rest.Log.WarnFormat("{0} URI and payload disagree on UUID U:{1} vs P:{2}",
286 MsgId, rdata.Parameters[0], asset.ID);
287 }
269 288
270 Rest.AssetServices.AddAsset(asset); 289 Rest.AssetServices.AddAsset(asset);
290
271 } 291 }
272 else 292 else
273 { 293 {
@@ -275,8 +295,88 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
275 rdata.Fail(Rest.HttpStatusCodeNotFound, "invalid parameters"); 295 rdata.Fail(Rest.HttpStatusCodeNotFound, "invalid parameters");
276 } 296 }
277 297
278 rdata.Complete(); 298 if (created)
279 rdata.Respond(String.Format("Asset <{0}>: Normal completion", rdata.method)); 299 {
300 rdata.Complete(Rest.HttpStatusCodeCreated);
301 }
302 else
303 {
304 if (modified)
305 {
306 rdata.Complete(Rest.HttpStatusCodeOK);
307 }
308 else
309 {
310 rdata.Complete(Rest.HttpStatusCodeNoContent);
311 }
312 }
313
314 rdata.Respond(String.Format("Asset {0} : Normal completion", rdata.method));
315
316 }
317
318 /// <summary>
319 /// CREATE new item, replace if it exists. URI identifies the context for the item in question.
320 /// No parameters are required for POST, just thepayload.
321 /// </summary>
322
323 private void DoPost(AssetRequestData rdata)
324 {
325
326 bool modified = false;
327 bool created = false;
328
329 Rest.Log.DebugFormat("{0} REST Asset handler, Method = <{1}> ENTRY", MsgId, rdata.method);
330
331 if (rdata.Parameters.Length != 0)
332 {
333 Rest.Log.WarnFormat("{0} Parameters ignored <{1}>", MsgId, rdata.path);
334 Rest.Log.InfoFormat("{0} POST of an asset has no parameters", MsgId, rdata.path);
335 }
336
337 rdata.initXmlReader();
338 XmlReader xml = rdata.reader;
339
340 if (!xml.ReadToFollowing("Asset"))
341 {
342 Rest.Log.DebugFormat("{0} Invalid request data: <{1}>", MsgId, rdata.path);
343 rdata.Fail(Rest.HttpStatusCodeBadRequest,"invalid request data");
344 }
345
346 UUID uuid = new UUID(xml.GetAttribute("id"));
347 AssetBase asset = Rest.AssetServices.GetAsset(uuid, false);
348
349 modified = (asset != null);
350 created = !modified;
351
352 asset = new AssetBase();
353 asset.FullID = uuid;
354 asset.Name = xml.GetAttribute("name");
355 asset.Description = xml.GetAttribute("desc");
356 asset.Type = SByte.Parse(xml.GetAttribute("type"));
357 asset.Local = Int32.Parse(xml.GetAttribute("local")) != 0;
358 asset.Temporary = Int32.Parse(xml.GetAttribute("temporary")) != 0;
359 asset.Data = Convert.FromBase64String(xml.ReadElementContentAsString("Asset", ""));
360
361 Rest.AssetServices.AddAsset(asset);
362
363 if (created)
364 {
365 rdata.Complete(Rest.HttpStatusCodeCreated);
366 }
367 else
368 {
369 if (modified)
370 {
371 rdata.Complete(Rest.HttpStatusCodeOK);
372 }
373 else
374 {
375 rdata.Complete(Rest.HttpStatusCodeNoContent);
376 }
377 }
378
379 rdata.Respond(String.Format("Asset {0} : Normal completion", rdata.method));
280 380
281 } 381 }
282 382