aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/AssetServer/RestService.cs
diff options
context:
space:
mode:
authorTleiades Hax2007-10-26 11:46:27 +0000
committerTleiades Hax2007-10-26 11:46:27 +0000
commit5e7dba726896fcb84882b53952651742926e6efb (patch)
treea396337e721912fd954e8a66e26d16c375d7bab4 /OpenSim/Grid/AssetServer/RestService.cs
parentadd my set-eol-style script. Can be run on Linux (diff)
downloadopensim-SC-5e7dba726896fcb84882b53952651742926e6efb.zip
opensim-SC-5e7dba726896fcb84882b53952651742926e6efb.tar.gz
opensim-SC-5e7dba726896fcb84882b53952651742926e6efb.tar.bz2
opensim-SC-5e7dba726896fcb84882b53952651742926e6efb.tar.xz
Very early first implementation of grid based assets.
Run this on a major grid, and weep
Diffstat (limited to 'OpenSim/Grid/AssetServer/RestService.cs')
-rw-r--r--OpenSim/Grid/AssetServer/RestService.cs109
1 files changed, 109 insertions, 0 deletions
diff --git a/OpenSim/Grid/AssetServer/RestService.cs b/OpenSim/Grid/AssetServer/RestService.cs
new file mode 100644
index 0000000..88a1668
--- /dev/null
+++ b/OpenSim/Grid/AssetServer/RestService.cs
@@ -0,0 +1,109 @@
1using System;
2using System.IO;
3using System.Xml;
4using System.Xml.Serialization;
5using System.Text;
6
7using libsecondlife;
8using OpenSim.Framework.Types;
9using OpenSim.Framework.Servers;
10using OpenSim.Framework.Interfaces;
11using OpenSim.Framework.Console;
12
13namespace OpenSim.Grid.AssetServer
14{
15 public class GetAssetStreamHandler : BaseStreamHandler
16 {
17 OpenAsset_Main m_assetManager;
18 IAssetProvider m_assetProvider;
19
20 override public byte[] Handle(string path, Stream request)
21 {
22 string param = GetParam(path);
23 byte[] result = new byte[] { };
24 try {
25
26 string[] p = param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries);
27
28 if (p.Length > 0)
29 {
30 LLUUID assetID;
31 bool isTexture = false;
32 LLUUID.TryParse(p[0], out assetID);
33 if (p.Length > 1)
34 {
35 if (string.Compare(p[1], "texture", true) == 0)
36 isTexture = true;
37 }
38
39
40 AssetBase asset = m_assetProvider.FetchAsset(assetID);
41 if (asset != null)
42 {
43 MainLog.Instance.Debug("REST", "GET:/asset found {0}, {1}", assetID, asset.Name);
44
45 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
46 MemoryStream ms = new MemoryStream();
47 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
48 xw.Formatting = Formatting.Indented;
49 xs.Serialize(xw, asset);
50 xw.Flush();
51
52 ms.Seek(0, SeekOrigin.Begin);
53 StreamReader sr = new StreamReader(ms);
54
55 result = ms.GetBuffer();
56 Array.Resize<byte>(ref result, (int)ms.Length);
57 }
58 else
59 {
60 MainLog.Instance.Verbose("REST", "GET:/asset failed to find {0}", assetID);
61 }
62 }
63 }
64 catch (Exception e)
65 {
66 MainLog.Instance.Error(e.ToString());
67 }
68 return result;
69 }
70
71 public GetAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider)
72 : base("GET", "/assets" )
73 {
74 m_assetManager = assetManager;
75 m_assetProvider = assetProvider;
76 }
77 }
78
79 public class PostAssetStreamHandler : BaseStreamHandler
80 {
81 OpenAsset_Main m_assetManager;
82 IAssetProvider m_assetProvider;
83
84 override public byte[] Handle(string path, Stream request)
85 {
86 string param = GetParam(path);
87
88 LLUUID assetId;
89 if(param.Length > 0)
90 LLUUID.TryParse(param, out assetId);
91 byte[] txBuffer = new byte[4096];
92
93 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
94 AssetBase asset = (AssetBase)xs.Deserialize(request);
95
96 MainLog.Instance.Verbose("REST", "StoreAndCommitAsset {0}", asset.FullID);
97 m_assetProvider.CreateAsset(asset);
98
99 return new byte[] { };
100 }
101
102 public PostAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider)
103 : base("POST", "/assets")
104 {
105 m_assetManager = assetManager;
106 m_assetProvider = assetProvider;
107 }
108 }
109}