aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Servers/Asset/AssetServerGetHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Servers/Asset/AssetServerGetHandler.cs136
1 files changed, 136 insertions, 0 deletions
diff --git a/OpenSim/Servers/Asset/AssetServerGetHandler.cs b/OpenSim/Servers/Asset/AssetServerGetHandler.cs
new file mode 100644
index 0000000..6c4d9b3
--- /dev/null
+++ b/OpenSim/Servers/Asset/AssetServerGetHandler.cs
@@ -0,0 +1,136 @@
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 OpenSim 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
28using Nini.Config;
29using System;
30using System.IO;
31using System.Net;
32using System.Text;
33using System.Text.RegularExpressions;
34using System.Xml;
35using System.Xml.Serialization;
36using OpenSim.Services.Interfaces;
37using OpenSim.Services.AssetService;
38using OpenSim.Framework;
39using OpenSim.Framework.Servers.HttpServer;
40
41namespace OpenSim.Servers.AssetServer
42{
43 public class AssetServerGetHandler : BaseStreamHandler
44 {
45 private IAssetService m_AssetService;
46
47 public AssetServerGetHandler(IAssetService service) :
48 base("GET", "/assets")
49 {
50 m_AssetService = service;
51 }
52
53 public override byte[] Handle(string path, Stream request,
54 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
55 {
56 byte[] result = new byte[0];
57
58 string[] p = SplitParams(path);
59
60 if (p.Length == 0)
61 return result;
62
63 AssetBase asset = m_AssetService.Get(p[0]);
64
65 if (asset != null)
66 {
67 if (p.Length > 1 && p[1] == "data")
68 {
69 httpResponse.StatusCode = (int)HttpStatusCode.OK;
70 httpResponse.ContentType =
71 SLAssetTypeToContentType(asset.Type);
72
73 result = asset.Data;
74 }
75 else
76 {
77 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
78 MemoryStream ms = new MemoryStream();
79 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
80 xw.Formatting = Formatting.Indented;
81 xs.Serialize(xw, asset);
82 xw.Flush();
83
84 ms.Seek(0, SeekOrigin.Begin);
85 result = ms.GetBuffer();
86
87 Array.Resize<byte>(ref result, (int)ms.Length);
88 }
89 }
90 return result;
91 }
92
93 private string SLAssetTypeToContentType(int assetType)
94 {
95 switch (assetType)
96 {
97 case 0:
98 return "image/jp2";
99 case 1:
100 return "application/ogg";
101 case 2:
102 return "application/x-metaverse-callingcard";
103 case 3:
104 return "application/x-metaverse-landmark";
105 case 5:
106 return "application/x-metaverse-clothing";
107 case 6:
108 return "application/x-metaverse-primitive";
109 case 7:
110 return "application/x-metaverse-notecard";
111 case 8:
112 return "application/x-metaverse-folder";
113 case 10:
114 return "application/x-metaverse-lsl";
115 case 11:
116 return "application/x-metaverse-lso";
117 case 12:
118 return "image/tga";
119 case 13:
120 return "application/x-metaverse-bodypart";
121 case 17:
122 return "audio/x-wav";
123 case 19:
124 return "image/jpeg";
125 case 20:
126 return "application/x-metaverse-animation";
127 case 21:
128 return "application/x-metaverse-gesture";
129 case 22:
130 return "application/x-metaverse-simstate";
131 default:
132 return "application/octet-stream";
133 }
134 }
135 }
136}