aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMelanie Thielker2009-05-08 18:45:52 +0000
committerMelanie Thielker2009-05-08 18:45:52 +0000
commita1631c496ef7965a8f0b388b39ae521cfb02b11a (patch)
tree903926f79d6df67b23b533ac3d5db5e77461f5b5
parentfix up the comments a little (diff)
downloadopensim-SC-a1631c496ef7965a8f0b388b39ae521cfb02b11a.zip
opensim-SC-a1631c496ef7965a8f0b388b39ae521cfb02b11a.tar.gz
opensim-SC-a1631c496ef7965a8f0b388b39ae521cfb02b11a.tar.bz2
opensim-SC-a1631c496ef7965a8f0b388b39ae521cfb02b11a.tar.xz
The new asset server now actually serves existing assets
-rw-r--r--OpenSim/Servers/Asset/AssetServerConnector.cs2
-rw-r--r--OpenSim/Servers/Asset/AssetServerGetHandler.cs136
-rw-r--r--OpenSim/Services/AssetService/AssetService.cs8
-rw-r--r--prebuild.xml1
4 files changed, 146 insertions, 1 deletions
diff --git a/OpenSim/Servers/Asset/AssetServerConnector.cs b/OpenSim/Servers/Asset/AssetServerConnector.cs
index fb84211..c9d2300 100644
--- a/OpenSim/Servers/Asset/AssetServerConnector.cs
+++ b/OpenSim/Servers/Asset/AssetServerConnector.cs
@@ -39,6 +39,8 @@ namespace OpenSim.Servers.AssetServer
39 public AssetServiceConnector(IConfigSource config, IHttpServer server) 39 public AssetServiceConnector(IConfigSource config, IHttpServer server)
40 { 40 {
41 m_AssetService = new AssetService(config); 41 m_AssetService = new AssetService(config);
42
43 server.AddStreamHandler(new AssetServerGetHandler(m_AssetService));
42 } 44 }
43 } 45 }
44} 46}
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}
diff --git a/OpenSim/Services/AssetService/AssetService.cs b/OpenSim/Services/AssetService/AssetService.cs
index 233fa62..d6e5141 100644
--- a/OpenSim/Services/AssetService/AssetService.cs
+++ b/OpenSim/Services/AssetService/AssetService.cs
@@ -32,6 +32,7 @@ using log4net;
32using OpenSim.Framework; 32using OpenSim.Framework;
33using OpenSim.Data; 33using OpenSim.Data;
34using OpenSim.Services.Interfaces; 34using OpenSim.Services.Interfaces;
35using OpenMetaverse;
35 36
36namespace OpenSim.Services.AssetService 37namespace OpenSim.Services.AssetService
37{ 38{
@@ -63,7 +64,12 @@ namespace OpenSim.Services.AssetService
63 64
64 public AssetBase Get(string id) 65 public AssetBase Get(string id)
65 { 66 {
66 return null; 67 UUID assetID;
68
69 if (!UUID.TryParse(id, out assetID))
70 return null;
71
72 return m_Database.FetchAsset(assetID);
67 } 73 }
68 74
69 public AssetMetadata GetMetadata(string id) 75 public AssetMetadata GetMetadata(string id)
diff --git a/prebuild.xml b/prebuild.xml
index 66a255c..7c94ef2 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -1395,6 +1395,7 @@
1395 1395
1396 <ReferencePath>../../../bin/</ReferencePath> 1396 <ReferencePath>../../../bin/</ReferencePath>
1397 <Reference name="System"/> 1397 <Reference name="System"/>
1398 <Reference name="System.Xml"/>
1398 <Reference name="OpenMetaverseTypes.dll"/> 1399 <Reference name="OpenMetaverseTypes.dll"/>
1399 <Reference name="OpenMetaverse.dll"/> 1400 <Reference name="OpenMetaverse.dll"/>
1400 <Reference name="OpenSim.Framework"/> 1401 <Reference name="OpenSim.Framework"/>