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