diff options
author | Melanie Thielker | 2009-05-04 20:15:39 +0000 |
---|---|---|
committer | Melanie Thielker | 2009-05-04 20:15:39 +0000 |
commit | acfb5051cd328ab21aba5bfc2878ce84d496a7f1 (patch) | |
tree | e828f8688de36d91c1917a02b651939580168125 /OpenSim/Framework/Servers/GetAssetStreamHandler.cs | |
parent | * Resolve http://opensimulator.org/mantis/view.php?id=3573 (diff) | |
download | opensim-SC_OLD-acfb5051cd328ab21aba5bfc2878ce84d496a7f1.zip opensim-SC_OLD-acfb5051cd328ab21aba5bfc2878ce84d496a7f1.tar.gz opensim-SC_OLD-acfb5051cd328ab21aba5bfc2878ce84d496a7f1.tar.bz2 opensim-SC_OLD-acfb5051cd328ab21aba5bfc2878ce84d496a7f1.tar.xz |
Intermediate commit. WILL NOT COMPILE!
Diffstat (limited to 'OpenSim/Framework/Servers/GetAssetStreamHandler.cs')
-rw-r--r-- | OpenSim/Framework/Servers/GetAssetStreamHandler.cs | 216 |
1 files changed, 0 insertions, 216 deletions
diff --git a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs deleted file mode 100644 index 628ee4e..0000000 --- a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs +++ /dev/null | |||
@@ -1,216 +0,0 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Text.RegularExpressions; | ||
33 | using System.Xml; | ||
34 | using System.Xml.Serialization; | ||
35 | using log4net; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Data; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Servers; | ||
40 | using OpenSim.Framework.Statistics; | ||
41 | using System.Net; | ||
42 | |||
43 | namespace OpenSim.Framework.Servers | ||
44 | { | ||
45 | public class GetAssetStreamHandler : BaseStreamHandler | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | // private OpenAsset_Main m_assetManager; | ||
50 | private IAssetDataPlugin m_assetProvider; | ||
51 | |||
52 | /// <summary> | ||
53 | /// Constructor. | ||
54 | /// </summary> | ||
55 | /// <param name="assetManager"></param> | ||
56 | /// <param name="assetProvider"></param> | ||
57 | public GetAssetStreamHandler(IAssetDataPlugin assetProvider) | ||
58 | : base("GET", "/assets") | ||
59 | { | ||
60 | m_log.Info("[REST]: In Get Request"); | ||
61 | // m_assetManager = assetManager; | ||
62 | m_assetProvider = assetProvider; | ||
63 | } | ||
64 | |||
65 | public override byte[] Handle(string path, Stream request, | ||
66 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
67 | { | ||
68 | string param = GetParam(path); | ||
69 | byte[] result = new byte[] { }; | ||
70 | |||
71 | string[] p = param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries); | ||
72 | |||
73 | if (p.Length > 0) | ||
74 | { | ||
75 | UUID assetID = UUID.Zero; | ||
76 | |||
77 | if (!UUID.TryParse(p[0], out assetID)) | ||
78 | { | ||
79 | m_log.InfoFormat( | ||
80 | "[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]); | ||
81 | return result; | ||
82 | } | ||
83 | |||
84 | if (StatsManager.AssetStats != null) | ||
85 | StatsManager.AssetStats.AddRequest(); | ||
86 | |||
87 | AssetBase asset = m_assetProvider.FetchAsset(assetID); | ||
88 | if (asset != null) | ||
89 | { | ||
90 | // if (asset.ContainsReferences) | ||
91 | // { | ||
92 | // asset.Data = ProcessOutgoingAssetData(asset.Data); | ||
93 | // } | ||
94 | if (p.Length > 1 && p[1] == "data") | ||
95 | { | ||
96 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
97 | httpResponse.ContentType = SLAssetTypeToContentType(asset.Type); | ||
98 | result = asset.Data; | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); | ||
103 | MemoryStream ms = new MemoryStream(); | ||
104 | XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8); | ||
105 | xw.Formatting = Formatting.Indented; | ||
106 | xs.Serialize(xw, asset); | ||
107 | xw.Flush(); | ||
108 | |||
109 | ms.Seek(0, SeekOrigin.Begin); | ||
110 | //StreamReader sr = new StreamReader(ms); | ||
111 | |||
112 | result = ms.GetBuffer(); | ||
113 | |||
114 | Array.Resize<byte>(ref result, (int)ms.Length); | ||
115 | } | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | if (StatsManager.AssetStats != null) | ||
120 | StatsManager.AssetStats.AddNotFoundRequest(); | ||
121 | |||
122 | m_log.InfoFormat("[REST]: GET:/asset failed to find {0}", assetID); | ||
123 | } | ||
124 | } | ||
125 | |||
126 | return result; | ||
127 | } | ||
128 | |||
129 | // private byte[] ProcessOutgoingAssetData(byte[] assetData) | ||
130 | // { | ||
131 | // string data = Encoding.ASCII.GetString(assetData); | ||
132 | |||
133 | // data = ProcessAssetDataString(data); | ||
134 | |||
135 | // return Encoding.ASCII.GetBytes(data); | ||
136 | // } | ||
137 | |||
138 | public string ProcessAssetDataString(string data) | ||
139 | { | ||
140 | Regex regex = new Regex("(creator_id|owner_id)\\s+(\\S+)"); | ||
141 | |||
142 | // IUserService userService = null; | ||
143 | |||
144 | data = regex.Replace(data, delegate(Match m) | ||
145 | { | ||
146 | string result = String.Empty; | ||
147 | |||
148 | // string key = m.Groups[1].Captures[0].Value; | ||
149 | // | ||
150 | // string value = m.Groups[2].Captures[0].Value; | ||
151 | // | ||
152 | // Guid userUri; | ||
153 | // | ||
154 | // switch (key) | ||
155 | // { | ||
156 | // case "creator_id": | ||
157 | // userUri = new Guid(value); | ||
158 | // // result = "creator_url " + userService(userService, userUri); | ||
159 | // break; | ||
160 | // | ||
161 | // case "owner_id": | ||
162 | // userUri = new Guid(value); | ||
163 | // // result = "owner_url " + ResolveUserUri(userService, userUri); | ||
164 | // break; | ||
165 | // } | ||
166 | |||
167 | return result; | ||
168 | }); | ||
169 | |||
170 | return data; | ||
171 | } | ||
172 | |||
173 | private string SLAssetTypeToContentType(int assetType) | ||
174 | { | ||
175 | switch (assetType) | ||
176 | { | ||
177 | case 0: | ||
178 | return "image/jp2"; | ||
179 | case 1: | ||
180 | return "application/ogg"; | ||
181 | case 2: | ||
182 | return "application/x-metaverse-callingcard"; | ||
183 | case 3: | ||
184 | return "application/x-metaverse-landmark"; | ||
185 | case 5: | ||
186 | return "application/x-metaverse-clothing"; | ||
187 | case 6: | ||
188 | return "application/x-metaverse-primitive"; | ||
189 | case 7: | ||
190 | return "application/x-metaverse-notecard"; | ||
191 | case 8: | ||
192 | return "application/x-metaverse-folder"; | ||
193 | case 10: | ||
194 | return "application/x-metaverse-lsl"; | ||
195 | case 11: | ||
196 | return "application/x-metaverse-lso"; | ||
197 | case 12: | ||
198 | return "image/tga"; | ||
199 | case 13: | ||
200 | return "application/x-metaverse-bodypart"; | ||
201 | case 17: | ||
202 | return "audio/x-wav"; | ||
203 | case 19: | ||
204 | return "image/jpeg"; | ||
205 | case 20: | ||
206 | return "application/x-metaverse-animation"; | ||
207 | case 21: | ||
208 | return "application/x-metaverse-gesture"; | ||
209 | case 22: | ||
210 | return "application/x-metaverse-simstate"; | ||
211 | default: | ||
212 | return "application/octet-stream"; | ||
213 | } | ||
214 | } | ||
215 | } | ||
216 | } | ||