aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Servers
diff options
context:
space:
mode:
authorMelanie Thielker2009-05-09 00:39:01 +0000
committerMelanie Thielker2009-05-09 00:39:01 +0000
commita582d1b1a201224df97d1e4030ae7d471aa7f120 (patch)
treed5ac7f936ac3841fe37b6b48524ea43910e35e83 /OpenSim/Servers
parent* Fix windows build. Thanks RemedyTomm for the patch (diff)
downloadopensim-SC_OLD-a582d1b1a201224df97d1e4030ae7d471aa7f120.zip
opensim-SC_OLD-a582d1b1a201224df97d1e4030ae7d471aa7f120.tar.gz
opensim-SC_OLD-a582d1b1a201224df97d1e4030ae7d471aa7f120.tar.bz2
opensim-SC_OLD-a582d1b1a201224df97d1e4030ae7d471aa7f120.tar.xz
Add the /data and /metadata retrieval modes to the new asset server.
Not functional yet.
Diffstat (limited to '')
-rw-r--r--OpenSim/Servers/Asset/AssetServerGetHandler.cs96
-rw-r--r--OpenSim/Servers/Base/ServerUtils.cs75
2 files changed, 115 insertions, 56 deletions
diff --git a/OpenSim/Servers/Asset/AssetServerGetHandler.cs b/OpenSim/Servers/Asset/AssetServerGetHandler.cs
index 6c4d9b3..80226d4 100644
--- a/OpenSim/Servers/Asset/AssetServerGetHandler.cs
+++ b/OpenSim/Servers/Asset/AssetServerGetHandler.cs
@@ -33,6 +33,7 @@ using System.Text;
33using System.Text.RegularExpressions; 33using System.Text.RegularExpressions;
34using System.Xml; 34using System.Xml;
35using System.Xml.Serialization; 35using System.Xml.Serialization;
36using OpenSim.Servers.Base;
36using OpenSim.Services.Interfaces; 37using OpenSim.Services.Interfaces;
37using OpenSim.Services.AssetService; 38using OpenSim.Services.AssetService;
38using OpenSim.Framework; 39using OpenSim.Framework;
@@ -60,77 +61,60 @@ namespace OpenSim.Servers.AssetServer
60 if (p.Length == 0) 61 if (p.Length == 0)
61 return result; 62 return result;
62 63
63 AssetBase asset = m_AssetService.Get(p[0]); 64 if (p.Length > 1 && p[1] == "data")
65 {
66 result = m_AssetService.GetData(p[0]);
67 if (result == null)
68 result = new byte[0];
64 69
65 if (asset != null) 70 httpResponse.StatusCode = (int)HttpStatusCode.OK;
71 httpResponse.ContentType = "application/octet-stream";
72 }
73 else if(p.Length > 1 && p[1] == "metadata")
66 { 74 {
67 if (p.Length > 1 && p[1] == "data") 75 AssetMetadata metadata = m_AssetService.GetMetadata(p[0]);
76
77 if (metadata != null)
68 { 78 {
79 XmlSerializer xs =
80 new XmlSerializer(typeof(AssetMetadata));
81 result = SerializeResult(xs, metadata);
82
69 httpResponse.StatusCode = (int)HttpStatusCode.OK; 83 httpResponse.StatusCode = (int)HttpStatusCode.OK;
70 httpResponse.ContentType = 84 httpResponse.ContentType =
71 SLAssetTypeToContentType(asset.Type); 85 ServerUtils.SLAssetTypeToContentType(metadata.Type);
72
73 result = asset.Data;
74 } 86 }
75 else 87 }
88 else
89 {
90 AssetBase asset = m_AssetService.Get(p[0]);
91
92 if (asset != null)
76 { 93 {
77 XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); 94 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
78 MemoryStream ms = new MemoryStream(); 95 result = SerializeResult(xs, asset);
79 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
80 xw.Formatting = Formatting.Indented;
81 xs.Serialize(xw, asset);
82 xw.Flush();
83 96
84 ms.Seek(0, SeekOrigin.Begin); 97 httpResponse.StatusCode = (int)HttpStatusCode.OK;
85 result = ms.GetBuffer(); 98 httpResponse.ContentType =
86 99 ServerUtils.SLAssetTypeToContentType(asset.Type);
87 Array.Resize<byte>(ref result, (int)ms.Length);
88 } 100 }
89 } 101 }
90 return result; 102 return result;
91 } 103 }
92 104
93 private string SLAssetTypeToContentType(int assetType) 105 private byte[] SerializeResult(XmlSerializer xs, object data)
94 { 106 {
95 switch (assetType) 107 MemoryStream ms = new MemoryStream();
96 { 108 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
97 case 0: 109 xw.Formatting = Formatting.Indented;
98 return "image/jp2"; 110 xs.Serialize(xw, data);
99 case 1: 111 xw.Flush();
100 return "application/ogg"; 112
101 case 2: 113 ms.Seek(0, SeekOrigin.Begin);
102 return "application/x-metaverse-callingcard"; 114 byte[] ret = ms.GetBuffer();
103 case 3: 115 Array.Resize<byte>(ref ret, (int)ms.Length);
104 return "application/x-metaverse-landmark"; 116
105 case 5: 117 return ret;
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 } 118 }
135 } 119 }
136} 120}
diff --git a/OpenSim/Servers/Base/ServerUtils.cs b/OpenSim/Servers/Base/ServerUtils.cs
new file mode 100644
index 0000000..b648e45
--- /dev/null
+++ b/OpenSim/Servers/Base/ServerUtils.cs
@@ -0,0 +1,75 @@
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
28namespace OpenSim.Servers.AssetServer
29{
30 public static class ServerUtils
31 {
32 public static string SLAssetTypeToContentType(int assetType)
33 {
34 switch (assetType)
35 {
36 case 0:
37 return "image/jp2";
38 case 1:
39 return "application/ogg";
40 case 2:
41 return "application/x-metaverse-callingcard";
42 case 3:
43 return "application/x-metaverse-landmark";
44 case 5:
45 return "application/x-metaverse-clothing";
46 case 6:
47 return "application/x-metaverse-primitive";
48 case 7:
49 return "application/x-metaverse-notecard";
50 case 8:
51 return "application/x-metaverse-folder";
52 case 10:
53 return "application/x-metaverse-lsl";
54 case 11:
55 return "application/x-metaverse-lso";
56 case 12:
57 return "image/tga";
58 case 13:
59 return "application/x-metaverse-bodypart";
60 case 17:
61 return "audio/x-wav";
62 case 19:
63 return "image/jpeg";
64 case 20:
65 return "application/x-metaverse-animation";
66 case 21:
67 return "application/x-metaverse-gesture";
68 case 22:
69 return "application/x-metaverse-simstate";
70 default:
71 return "application/octet-stream";
72 }
73 }
74 }
75}