aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs
diff options
context:
space:
mode:
authorJeff Ames2009-05-11 15:14:15 +0000
committerJeff Ames2009-05-11 15:14:15 +0000
commit516440367680ce43417442bbf9570eaadd503235 (patch)
tree30f84174c08638681d4926a0e7773e572ec645f2 /OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs
parentadding code to check for old-style responses ("True") (diff)
downloadopensim-SC-516440367680ce43417442bbf9570eaadd503235.zip
opensim-SC-516440367680ce43417442bbf9570eaadd503235.tar.gz
opensim-SC-516440367680ce43417442bbf9570eaadd503235.tar.bz2
opensim-SC-516440367680ce43417442bbf9570eaadd503235.tar.xz
Update svn properties.
Diffstat (limited to 'OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs')
-rw-r--r--OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs392
1 files changed, 196 insertions, 196 deletions
diff --git a/OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs b/OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs
index 6e03ea8..fc4eed7 100644
--- a/OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs
+++ b/OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs
@@ -1,196 +1,196 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the 12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Net; 31using System.Net;
32using System.Reflection; 32using System.Reflection;
33using System.Text; 33using System.Text;
34using System.Text.RegularExpressions; 34using System.Text.RegularExpressions;
35using System.Xml; 35using System.Xml;
36using System.Xml.Serialization; 36using System.Xml.Serialization;
37using log4net; 37using log4net;
38using OpenMetaverse; 38using OpenMetaverse;
39using OpenSim.Framework.Servers.HttpServer; 39using OpenSim.Framework.Servers.HttpServer;
40using OpenSim.Framework.Statistics; 40using OpenSim.Framework.Statistics;
41 41
42namespace OpenSim.Framework.Servers 42namespace OpenSim.Framework.Servers
43{ 43{
44 public abstract class BaseGetAssetStreamHandler : BaseStreamHandler 44 public abstract class BaseGetAssetStreamHandler : BaseStreamHandler
45 { 45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 47
48 protected BaseGetAssetStreamHandler(string httpMethod, string path) : base(httpMethod, path) 48 protected BaseGetAssetStreamHandler(string httpMethod, string path) : base(httpMethod, path)
49 { 49 {
50 } 50 }
51 51
52 protected abstract AssetBase GetAsset(UUID assetID); 52 protected abstract AssetBase GetAsset(UUID assetID);
53 53
54 public override byte[] Handle(string path, Stream request, 54 public override byte[] Handle(string path, Stream request,
55 OSHttpRequest httpRequest, OSHttpResponse httpResponse) 55 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
56 { 56 {
57 byte[] result = new byte[] { }; 57 byte[] result = new byte[] { };
58 58
59 string[] p = SplitParams(path); 59 string[] p = SplitParams(path);
60 60
61 if (p.Length > 0) 61 if (p.Length > 0)
62 { 62 {
63 UUID assetID = UUID.Zero; 63 UUID assetID = UUID.Zero;
64 64
65 if (!UUID.TryParse(p[0], out assetID)) 65 if (!UUID.TryParse(p[0], out assetID))
66 { 66 {
67 m_log.InfoFormat( 67 m_log.InfoFormat(
68 "[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]); 68 "[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]);
69 return result; 69 return result;
70 } 70 }
71 71
72 if (StatsManager.AssetStats != null) 72 if (StatsManager.AssetStats != null)
73 StatsManager.AssetStats.AddRequest(); 73 StatsManager.AssetStats.AddRequest();
74 74
75 AssetBase asset = GetAsset(assetID); 75 AssetBase asset = GetAsset(assetID);
76 76
77 if (asset != null) 77 if (asset != null)
78 { 78 {
79// if (asset.ContainsReferences) 79// if (asset.ContainsReferences)
80// { 80// {
81// asset.Data = ProcessOutgoingAssetData(asset.Data); 81// asset.Data = ProcessOutgoingAssetData(asset.Data);
82// } 82// }
83 if (p.Length > 1 && p[1] == "data") 83 if (p.Length > 1 && p[1] == "data")
84 { 84 {
85 httpResponse.StatusCode = (int)HttpStatusCode.OK; 85 httpResponse.StatusCode = (int)HttpStatusCode.OK;
86 httpResponse.ContentType = SLAssetTypeToContentType(asset.Type); 86 httpResponse.ContentType = SLAssetTypeToContentType(asset.Type);
87 result = asset.Data; 87 result = asset.Data;
88 } 88 }
89 else 89 else
90 { 90 {
91 XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); 91 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
92 MemoryStream ms = new MemoryStream(); 92 MemoryStream ms = new MemoryStream();
93 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8); 93 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
94 xw.Formatting = Formatting.Indented; 94 xw.Formatting = Formatting.Indented;
95 xs.Serialize(xw, asset); 95 xs.Serialize(xw, asset);
96 xw.Flush(); 96 xw.Flush();
97 97
98 ms.Seek(0, SeekOrigin.Begin); 98 ms.Seek(0, SeekOrigin.Begin);
99 //StreamReader sr = new StreamReader(ms); 99 //StreamReader sr = new StreamReader(ms);
100 100
101 result = ms.GetBuffer(); 101 result = ms.GetBuffer();
102 102
103 Array.Resize<byte>(ref result, (int)ms.Length); 103 Array.Resize<byte>(ref result, (int)ms.Length);
104 } 104 }
105 } 105 }
106 else 106 else
107 { 107 {
108 if (StatsManager.AssetStats != null) 108 if (StatsManager.AssetStats != null)
109 StatsManager.AssetStats.AddNotFoundRequest(); 109 StatsManager.AssetStats.AddNotFoundRequest();
110 110
111 m_log.InfoFormat("[REST]: GET:/asset failed to find {0}", assetID); 111 m_log.InfoFormat("[REST]: GET:/asset failed to find {0}", assetID);
112 } 112 }
113 } 113 }
114 114
115 return result; 115 return result;
116 } 116 }
117 117
118 public string ProcessAssetDataString(string data) 118 public string ProcessAssetDataString(string data)
119 { 119 {
120 Regex regex = new Regex("(creator_id|owner_id)\\s+(\\S+)"); 120 Regex regex = new Regex("(creator_id|owner_id)\\s+(\\S+)");
121 121
122 // IUserService userService = null; 122 // IUserService userService = null;
123 123
124 data = regex.Replace(data, delegate(Match m) 124 data = regex.Replace(data, delegate(Match m)
125 { 125 {
126 string result = String.Empty; 126 string result = String.Empty;
127 127
128// string key = m.Groups[1].Captures[0].Value; 128// string key = m.Groups[1].Captures[0].Value;
129// 129//
130// string value = m.Groups[2].Captures[0].Value; 130// string value = m.Groups[2].Captures[0].Value;
131// 131//
132// Guid userUri; 132// Guid userUri;
133// 133//
134// switch (key) 134// switch (key)
135// { 135// {
136// case "creator_id": 136// case "creator_id":
137// userUri = new Guid(value); 137// userUri = new Guid(value);
138// // result = "creator_url " + userService(userService, userUri); 138// // result = "creator_url " + userService(userService, userUri);
139// break; 139// break;
140// 140//
141// case "owner_id": 141// case "owner_id":
142// userUri = new Guid(value); 142// userUri = new Guid(value);
143// // result = "owner_url " + ResolveUserUri(userService, userUri); 143// // result = "owner_url " + ResolveUserUri(userService, userUri);
144// break; 144// break;
145// } 145// }
146 146
147 return result; 147 return result;
148 }); 148 });
149 149
150 return data; 150 return data;
151 } 151 }
152 152
153 private string SLAssetTypeToContentType(int assetType) 153 private string SLAssetTypeToContentType(int assetType)
154 { 154 {
155 switch (assetType) 155 switch (assetType)
156 { 156 {
157 case 0: 157 case 0:
158 return "image/jp2"; 158 return "image/jp2";
159 case 1: 159 case 1:
160 return "application/ogg"; 160 return "application/ogg";
161 case 2: 161 case 2:
162 return "application/x-metaverse-callingcard"; 162 return "application/x-metaverse-callingcard";
163 case 3: 163 case 3:
164 return "application/x-metaverse-landmark"; 164 return "application/x-metaverse-landmark";
165 case 5: 165 case 5:
166 return "application/x-metaverse-clothing"; 166 return "application/x-metaverse-clothing";
167 case 6: 167 case 6:
168 return "application/x-metaverse-primitive"; 168 return "application/x-metaverse-primitive";
169 case 7: 169 case 7:
170 return "application/x-metaverse-notecard"; 170 return "application/x-metaverse-notecard";
171 case 8: 171 case 8:
172 return "application/x-metaverse-folder"; 172 return "application/x-metaverse-folder";
173 case 10: 173 case 10:
174 return "application/x-metaverse-lsl"; 174 return "application/x-metaverse-lsl";
175 case 11: 175 case 11:
176 return "application/x-metaverse-lso"; 176 return "application/x-metaverse-lso";
177 case 12: 177 case 12:
178 return "image/tga"; 178 return "image/tga";
179 case 13: 179 case 13:
180 return "application/x-metaverse-bodypart"; 180 return "application/x-metaverse-bodypart";
181 case 17: 181 case 17:
182 return "audio/x-wav"; 182 return "audio/x-wav";
183 case 19: 183 case 19:
184 return "image/jpeg"; 184 return "image/jpeg";
185 case 20: 185 case 20:
186 return "application/x-metaverse-animation"; 186 return "application/x-metaverse-animation";
187 case 21: 187 case 21:
188 return "application/x-metaverse-gesture"; 188 return "application/x-metaverse-gesture";
189 case 22: 189 case 22:
190 return "application/x-metaverse-simstate"; 190 return "application/x-metaverse-simstate";
191 default: 191 default:
192 return "application/octet-stream"; 192 return "application/octet-stream";
193 } 193 }
194 } 194 }
195 } 195 }
196} 196}