aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/AssetInventoryServer/Plugins
diff options
context:
space:
mode:
authorMike Mazur2009-02-16 02:27:17 +0000
committerMike Mazur2009-02-16 02:27:17 +0000
commit07b8d51da8186e537da35c1d56d176b4843d8eaa (patch)
tree9ae3581af0ca34a4210b77ca304d9ba75440fb51 /OpenSim/Grid/AssetInventoryServer/Plugins
parentUpdate to new generic DataPluginFactory calls. (diff)
downloadopensim-SC_OLD-07b8d51da8186e537da35c1d56d176b4843d8eaa.zip
opensim-SC_OLD-07b8d51da8186e537da35c1d56d176b4843d8eaa.tar.gz
opensim-SC_OLD-07b8d51da8186e537da35c1d56d176b4843d8eaa.tar.bz2
opensim-SC_OLD-07b8d51da8186e537da35c1d56d176b4843d8eaa.tar.xz
AssetInventoryServer now compiles while using the standard OpenSim
console and HttpServer. It doesn't work though.
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer/Plugins')
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs137
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs211
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs514
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs329
4 files changed, 703 insertions, 488 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs
index f445b97..bb38d5d 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs
@@ -28,20 +28,21 @@
28 */ 28 */
29 29
30using System; 30using System;
31using System.IO;
31using System.Collections.Generic; 32using System.Collections.Generic;
32using System.Collections.Specialized; 33using System.Collections.Specialized;
33using System.Net; 34using System.Net;
34using System.Text; 35using System.Text;
35using System.Web; 36using System.Web;
36using OpenMetaverse; 37using OpenMetaverse;
37using HttpServer;
38using OpenSim.Framework; 38using OpenSim.Framework;
39using OpenSim.Framework.Servers;
39 40
40namespace OpenSim.Grid.AssetInventoryServer.Plugins 41namespace OpenSim.Grid.AssetInventoryServer.Plugins
41{ 42{
42 public class BrowseFrontendPlugin : IAssetInventoryServerPlugin 43 public class BrowseFrontendPlugin : IAssetInventoryServerPlugin
43 { 44 {
44 AssetInventoryServer server; 45 AssetInventoryServer m_server;
45 46
46 public BrowseFrontendPlugin() 47 public BrowseFrontendPlugin()
47 { 48 {
@@ -51,10 +52,11 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
51 52
52 public void Initialise(AssetInventoryServer server) 53 public void Initialise(AssetInventoryServer server)
53 { 54 {
54 this.server = server; 55 m_server = server;
55 56
56 // Request for / or /?... 57 // Request for / or /?...
57 server.HttpServer.AddHandler("get", null, @"(^/$)|(^/\?.*)", BrowseRequestHandler); 58 //server.HttpServer.AddHandler("get", null, @"(^/$)|(^/\?.*)", BrowseRequestHandler);
59 m_server.HttpServer.AddStreamHandler(new BrowseRequestHandler(server));
58 60
59 Logger.Log.Info("[ASSET] Browser Frontend loaded."); 61 Logger.Log.Info("[ASSET] Browser Frontend loaded.");
60 } 62 }
@@ -85,67 +87,102 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
85 87
86 #endregion IPlugin implementation 88 #endregion IPlugin implementation
87 89
88 bool BrowseRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 90 public class BrowseRequestHandler : IStreamedRequestHandler
89 { 91 {
90 const int ASSETS_PER_PAGE = 25; 92 AssetInventoryServer m_server;
91 const string HEADER = "<html><head><title>Asset Server</title></head><body>"; 93 string m_contentType;
92 const string TABLE_HEADER = 94 string m_httpMethod;
93 "<table><tr><th>Name</th><th>Description</th><th>Type</th><th>ID</th><th>Temporary</th><th>SHA-1</th></tr>"; 95 string m_path;
94 const string TABLE_FOOTER = "</table>";
95 const string FOOTER = "</body></html>";
96 96
97 UUID authToken = Utils.GetAuthToken(request); 97 public BrowseRequestHandler(AssetInventoryServer server)
98 {
99 m_server = server;
100 m_contentType = null;
101 m_httpMethod = "GET";
102 m_path = @"(^/$)|(^/\?.*)";
103 }
98 104
99 StringBuilder html = new StringBuilder(); 105 #region IStreamedRequestHandler implementation
100 int start = 0; 106
101 uint page = 0; 107 public string ContentType
108 {
109 get { return m_contentType; }
110 }
111
112 public string HttpMethod
113 {
114 get { return m_httpMethod; }
115 }
102 116
103 if (!String.IsNullOrEmpty(request.Uri.Query)) 117 public string Path
104 { 118 {
105 NameValueCollection query = HttpUtility.ParseQueryString(request.Uri.Query); 119 get { return m_path; }
106 if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page))
107 start = (int)page * ASSETS_PER_PAGE;
108 } 120 }
109 121
110 html.AppendLine(HEADER); 122 public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
123 {
124 const int ASSETS_PER_PAGE = 25;
125 const string HEADER = "<html><head><title>Asset Server</title></head><body>";
126 const string TABLE_HEADER =
127 "<table><tr><th>Name</th><th>Description</th><th>Type</th><th>ID</th><th>Temporary</th><th>SHA-1</th></tr>";
128 const string TABLE_FOOTER = "</table>";
129 const string FOOTER = "</body></html>";
111 130
112 html.AppendLine("<p>"); 131 UUID authToken = Utils.GetAuthToken(httpRequest);
113 if (page > 0)
114 html.AppendFormat("<a href=\"{0}?page={1}\">&lt; Previous Page</a> | ", request.Uri.AbsolutePath, page - 1);
115 html.AppendFormat("<a href=\"{0}?page={1}\">Next Page &gt;</a>", request.Uri.AbsolutePath, page + 1);
116 html.AppendLine("</p>");
117 132
118 html.AppendLine(TABLE_HEADER); 133 StringBuilder html = new StringBuilder();
134 int start = 0;
135 uint page = 0;
119 136
120 server.StorageProvider.ForEach( 137 if (!String.IsNullOrEmpty(httpRequest.Url.Query))
121 delegate(Metadata data)
122 { 138 {
123 if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID)) 139 NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query);
124 { 140 if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page))
125 html.AppendLine(String.Format( 141 start = (int)page * ASSETS_PER_PAGE;
126 "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>", 142 }
127 data.Name, data.Description, data.ContentType, data.ID, data.Temporary,
128 BitConverter.ToString(data.SHA1).Replace("-", String.Empty)));
129 }
130 else
131 {
132 html.AppendLine(String.Format(
133 "<tr><td>[Protected Asset]</td><td>&nbsp;</td><td>&nbsp;</td><td>{0}</td><td>{1}</td><td>&nbsp;</td></tr>",
134 data.ID, data.Temporary));
135 }
136 }, start, ASSETS_PER_PAGE
137 );
138 143
139 html.AppendLine(TABLE_FOOTER); 144 html.AppendLine(HEADER);
140 145
141 html.AppendLine(FOOTER); 146 html.AppendLine("<p>");
147 if (page > 0)
148 html.AppendFormat("<a href=\"{0}?page={1}\">&lt; Previous Page</a> | ", httpRequest.RawUrl, page - 1);
149 html.AppendFormat("<a href=\"{0}?page={1}\">Next Page &gt;</a>", httpRequest.RawUrl, page + 1);
150 html.AppendLine("</p>");
142 151
143 byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString()); 152 html.AppendLine(TABLE_HEADER);
153
154 m_server.StorageProvider.ForEach(
155 delegate(Metadata data)
156 {
157 if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID))
158 {
159 html.AppendLine(String.Format(
160 "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>",
161 data.Name, data.Description, data.ContentType, data.ID, data.Temporary,
162 BitConverter.ToString(data.SHA1).Replace("-", String.Empty)));
163 }
164 else
165 {
166 html.AppendLine(String.Format(
167 "<tr><td>[Protected Asset]</td><td>&nbsp;</td><td>&nbsp;</td><td>{0}</td><td>{1}</td><td>&nbsp;</td></tr>",
168 data.ID, data.Temporary));
169 }
170 }, start, ASSETS_PER_PAGE
171 );
172
173 html.AppendLine(TABLE_FOOTER);
174
175 html.AppendLine(FOOTER);
176
177 byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString());
178
179 httpResponse.StatusCode = (int) HttpStatusCode.OK;
180 httpResponse.Body.Write(responseData, 0, responseData.Length);
181 httpResponse.Body.Flush();
182 return responseData;
183 }
144 184
145 response.Status = HttpStatusCode.OK; 185 #endregion IStreamedRequestHandler implementation
146 response.Body.Write(responseData, 0, responseData.Length);
147 response.Body.Flush();
148 return true;
149 } 186 }
150 } 187 }
151} 188}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
index f831e24..3431ff3 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
@@ -37,6 +37,7 @@ using System.Xml.Serialization;
37using OpenMetaverse; 37using OpenMetaverse;
38using HttpServer; 38using HttpServer;
39using OpenSim.Framework; 39using OpenSim.Framework;
40using OpenSim.Framework.Servers;
40 41
41namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim 42namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
42{ 43{
@@ -55,10 +56,10 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
55 this.server = server; 56 this.server = server;
56 57
57 // Asset request 58 // Asset request
58 server.HttpServer.AddHandler("get", null, @"^/assets/", AssetRequestHandler); 59 server.HttpServer.AddStreamHandler(new AssetRequestHandler(server));
59 60
60 // Asset creation 61 // Asset creation
61 server.HttpServer.AddHandler("post", null, @"^/assets/", AssetPostHandler); 62 server.HttpServer.AddStreamHandler(new AssetPostHandler(server));
62 63
63 Logger.Log.Info("[ASSET] OpenSim Asset Frontend loaded."); 64 Logger.Log.Info("[ASSET] OpenSim Asset Frontend loaded.");
64 } 65 }
@@ -89,100 +90,172 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
89 90
90 #endregion IPlugin implementation 91 #endregion IPlugin implementation
91 92
92 bool AssetRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 93 public class AssetRequestHandler : IStreamedRequestHandler
93 { 94 {
94 UUID assetID; 95 AssetInventoryServer m_server;
95 // Split the URL up to get the asset ID out 96 string m_contentType;
96 string[] rawUrl = request.Uri.PathAndQuery.Split('/'); 97 string m_httpMethod;
98 string m_path;
97 99
98 if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID)) 100 public AssetRequestHandler(AssetInventoryServer server)
99 { 101 {
100 Metadata metadata; 102 m_server = server;
101 byte[] assetData; 103 m_contentType = null;
102 BackendResponse dataResponse; 104 m_httpMethod = "GET";
105 m_path = @"^/assets/";
106 }
107
108 #region IStreamedRequestHandler implementation
109
110 public string ContentType
111 {
112 get { return m_contentType; }
113 }
114
115 public string HttpMethod
116 {
117 get { return m_httpMethod; }
118 }
119
120 public string Path
121 {
122 get { return m_path; }
123 }
124
125 public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
126 {
127 byte[] buffer = null;
128 UUID assetID;
129 // Split the URL up to get the asset ID out
130 string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
103 131
104 if ((dataResponse = server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success) 132 if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID))
105 { 133 {
106 AssetBase asset = new AssetBase(); 134 Metadata metadata;
107 asset.Data = assetData; 135 byte[] assetData;
108 asset.Metadata.FullID = metadata.ID; 136 BackendResponse dataResponse;
109 asset.Metadata.Name = metadata.Name; 137
110 asset.Metadata.Description = metadata.Description; 138 if ((dataResponse = m_server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
111 asset.Metadata.CreationDate = metadata.CreationDate; 139 {
112 asset.Metadata.Type = (sbyte) Utils.ContentTypeToSLAssetType(metadata.ContentType); 140 AssetBase asset = new AssetBase();
113 asset.Metadata.Local = false; 141 asset.Data = assetData;
114 asset.Metadata.Temporary = metadata.Temporary; 142 asset.Metadata.FullID = metadata.ID;
115 143 asset.Metadata.Name = metadata.Name;
116 XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); 144 asset.Metadata.Description = metadata.Description;
117 MemoryStream ms = new MemoryStream(); 145 asset.Metadata.CreationDate = metadata.CreationDate;
118 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8); 146 asset.Metadata.Type = (sbyte) Utils.ContentTypeToSLAssetType(metadata.ContentType);
119 xs.Serialize(xw, asset); 147 asset.Metadata.Local = false;
120 xw.Flush(); 148 asset.Metadata.Temporary = metadata.Temporary;
121 149
122 ms.Seek(0, SeekOrigin.Begin); 150 XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
123 byte[] buffer = ms.GetBuffer(); 151 MemoryStream ms = new MemoryStream();
124 152 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
125 response.Status = HttpStatusCode.OK; 153 xs.Serialize(xw, asset);
126 response.ContentType = "application/xml"; 154 xw.Flush();
127 response.ContentLength = ms.Length; 155
128 response.Body.Write(buffer, 0, (int) ms.Length); 156 ms.Seek(0, SeekOrigin.Begin);
129 response.Body.Flush(); 157 buffer = ms.GetBuffer();
158
159 httpResponse.StatusCode = (int) HttpStatusCode.OK;
160 httpResponse.ContentType = "application/xml";
161 httpResponse.ContentLength = ms.Length;
162 httpResponse.Body.Write(buffer, 0, (int) ms.Length);
163 httpResponse.Body.Flush();
164 }
165 else
166 {
167 Logger.Log.WarnFormat("Failed to fetch asset data or metadata for {0}: {1}", assetID, dataResponse);
168 httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
169 }
130 } 170 }
131 else 171 else
132 { 172 {
133 Logger.Log.WarnFormat("Failed to fetch asset data or metadata for {0}: {1}", assetID, dataResponse); 173 Logger.Log.Warn("Unrecognized OpenSim asset request: " + httpRequest.Url.PathAndQuery);
134 response.Status = HttpStatusCode.NotFound;
135 } 174 }
136 } 175
137 else 176 return buffer;
138 {
139 Logger.Log.Warn("Unrecognized OpenSim asset request: " + request.Uri.PathAndQuery);
140 } 177 }
141 178
142 return true; 179 #endregion IStreamedRequestHandler implementation
143 } 180 }
144 181
145 bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 182 public class AssetPostHandler : IStreamedRequestHandler
146 { 183 {
147 Metadata metadata = new Metadata(); 184 AssetInventoryServer m_server;
185 string m_contentType;
186 string m_httpMethod;
187 string m_path;
188
189 public AssetPostHandler(AssetInventoryServer server)
190 {
191 m_server = server;
192 m_contentType = null;
193 m_httpMethod = "POST";
194 m_path = @"^/assets/";
195 }
196
197 #region IStreamedRequestHandler implementation
148 198
149 try 199 public string ContentType
150 { 200 {
151 AssetBase asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(request.Body); 201 get { return m_contentType; }
202 }
152 203
153 if (asset.Data != null && asset.Data.Length > 0) 204 public string HttpMethod
205 {
206 get { return m_httpMethod; }
207 }
208
209 public string Path
210 {
211 get { return m_path; }
212 }
213
214 public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
215 //bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
216 {
217 Metadata metadata = new Metadata();
218
219 try
154 { 220 {
155 metadata.ID = asset.Metadata.FullID; 221 AssetBase asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(httpRequest.InputStream);
156 metadata.ContentType = Utils.SLAssetTypeToContentType((int) asset.Metadata.Type); 222
157 metadata.Name = asset.Metadata.Name; 223 if (asset.Data != null && asset.Data.Length > 0)
158 metadata.Description = asset.Metadata.Description; 224 {
159 metadata.Temporary = asset.Metadata.Temporary; 225 metadata.ID = asset.Metadata.FullID;
226 metadata.ContentType = Utils.SLAssetTypeToContentType((int) asset.Metadata.Type);
227 metadata.Name = asset.Metadata.Name;
228 metadata.Description = asset.Metadata.Description;
229 metadata.Temporary = asset.Metadata.Temporary;
160 230
161 metadata.SHA1 = OpenMetaverse.Utils.SHA1(asset.Data); 231 metadata.SHA1 = OpenMetaverse.Utils.SHA1(asset.Data);
162 metadata.CreationDate = DateTime.Now; 232 metadata.CreationDate = DateTime.Now;
163 233
164 BackendResponse storageResponse = server.StorageProvider.TryCreateAsset(metadata, asset.Data); 234 BackendResponse storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, asset.Data);
165 235
166 if (storageResponse == BackendResponse.Success) 236 if (storageResponse == BackendResponse.Success)
167 response.Status = HttpStatusCode.Created; 237 httpResponse.StatusCode = (int) HttpStatusCode.Created;
168 else if (storageResponse == BackendResponse.NotFound) 238 else if (storageResponse == BackendResponse.NotFound)
169 response.Status = HttpStatusCode.NotFound; 239 httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
240 else
241 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
242 }
170 else 243 else
171 response.Status = HttpStatusCode.InternalServerError; 244 {
245 Logger.Log.Warn("AssetPostHandler called with no asset data");
246 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
247 }
172 } 248 }
173 else 249 catch (Exception ex)
174 { 250 {
175 Logger.Log.Warn("AssetPostHandler called with no asset data"); 251 Logger.Log.Warn("Failed to parse POST data (expecting AssetBase): " + ex.Message);
176 response.Status = HttpStatusCode.BadRequest; 252 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
177 } 253 }
178 } 254
179 catch (Exception ex) 255 return null;
180 {
181 Logger.Log.Warn("Failed to parse POST data (expecting AssetBase): " + ex.Message);
182 response.Status = HttpStatusCode.BadRequest;
183 } 256 }
184 257
185 return true; 258 #endregion IStreamedRequestHandler implementation
186 } 259 }
187 } 260 }
188} 261}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs
index 0f3867a..ac67159 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs
@@ -56,16 +56,16 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
56 { 56 {
57 this.server = server; 57 this.server = server;
58 58
59 server.HttpServer.AddHandler("post", null, @"^/GetInventory/", GetInventoryHandler); 59 //server.HttpServer.AddHandler("post", null, @"^/GetInventory/", GetInventoryHandler);
60 server.HttpServer.AddHandler("post", null, @"^/CreateInventory/", CreateInventoryHandler); 60 //server.HttpServer.AddHandler("post", null, @"^/CreateInventory/", CreateInventoryHandler);
61 server.HttpServer.AddHandler("post", null, @"^/NewFolder/", NewFolderHandler); 61 //server.HttpServer.AddHandler("post", null, @"^/NewFolder/", NewFolderHandler);
62 server.HttpServer.AddHandler("post", null, @"^/UpdateFolder/", UpdateFolderHandler); 62 //server.HttpServer.AddHandler("post", null, @"^/UpdateFolder/", UpdateFolderHandler);
63 server.HttpServer.AddHandler("post", null, @"^/MoveFolder/", MoveFolderHandler); 63 //server.HttpServer.AddHandler("post", null, @"^/MoveFolder/", MoveFolderHandler);
64 server.HttpServer.AddHandler("post", null, @"^/PurgeFolder/", PurgeFolderHandler); 64 //server.HttpServer.AddHandler("post", null, @"^/PurgeFolder/", PurgeFolderHandler);
65 server.HttpServer.AddHandler("post", null, @"^/NewItem/", NewItemHandler); 65 //server.HttpServer.AddHandler("post", null, @"^/NewItem/", NewItemHandler);
66 server.HttpServer.AddHandler("post", null, @"^/DeleteItem/", DeleteItemHandler); 66 //server.HttpServer.AddHandler("post", null, @"^/DeleteItem/", DeleteItemHandler);
67 server.HttpServer.AddHandler("post", null, @"^/RootFolders/", RootFoldersHandler); 67 //server.HttpServer.AddHandler("post", null, @"^/RootFolders/", RootFoldersHandler);
68 server.HttpServer.AddHandler("post", null, @"^/ActiveGestures/", ActiveGesturesHandler); 68 //server.HttpServer.AddHandler("post", null, @"^/ActiveGestures/", ActiveGesturesHandler);
69 69
70 Logger.Log.Info("[INVENTORY] OpenSim Inventory Frontend loaded."); 70 Logger.Log.Info("[INVENTORY] OpenSim Inventory Frontend loaded.");
71 } 71 }
@@ -96,253 +96,253 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
96 96
97 #endregion IPlugin implementation 97 #endregion IPlugin implementation
98 98
99 bool GetInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 99 //bool GetInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
100 { 100 //{
101 UUID sessionID, agentID; 101 // UUID sessionID, agentID;
102 UUID ownerID = DeserializeUUID(request.Body, out agentID, out sessionID); 102 // UUID ownerID = DeserializeUUID(request.Body, out agentID, out sessionID);
103 103
104 if (ownerID != UUID.Zero) 104 // if (ownerID != UUID.Zero)
105 { 105 // {
106 Logger.Log.Warn("GetInventory is not scalable on some inventory backends, avoid calling it wherever possible"); 106 // Logger.Log.Warn("GetInventory is not scalable on some inventory backends, avoid calling it wherever possible");
107 107
108 Uri owner = Utils.GetOpenSimUri(ownerID); 108 // Uri owner = Utils.GetOpenSimUri(ownerID);
109 InventoryCollection inventory; 109 // InventoryCollection inventory;
110 BackendResponse storageResponse = server.InventoryProvider.TryFetchInventory(owner, out inventory); 110 // BackendResponse storageResponse = server.InventoryProvider.TryFetchInventory(owner, out inventory);
111 111
112 if (storageResponse == BackendResponse.Success) 112 // if (storageResponse == BackendResponse.Success)
113 { 113 // {
114 collectionSerializer.Serialize(response.Body, inventory); 114 // collectionSerializer.Serialize(response.Body, inventory);
115 response.Body.Flush(); 115 // response.Body.Flush();
116 } 116 // }
117 else if (storageResponse == BackendResponse.NotFound) 117 // else if (storageResponse == BackendResponse.NotFound)
118 { 118 // {
119 // Return an empty inventory set to mimic OpenSim.Grid.InventoryServer.exe 119 // // Return an empty inventory set to mimic OpenSim.Grid.InventoryServer.exe
120 inventory = new InventoryCollection(); 120 // inventory = new InventoryCollection();
121 inventory.UserID = ownerID; 121 // inventory.UserID = ownerID;
122 inventory.Folders = new Dictionary<UUID, InventoryFolder>(); 122 // inventory.Folders = new Dictionary<UUID, InventoryFolder>();
123 inventory.Items = new Dictionary<UUID, InventoryItem>(); 123 // inventory.Items = new Dictionary<UUID, InventoryItem>();
124 collectionSerializer.Serialize(response.Body, inventory); 124 // collectionSerializer.Serialize(response.Body, inventory);
125 response.Body.Flush(); 125 // response.Body.Flush();
126 } 126 // }
127 else 127 // else
128 { 128 // {
129 response.Status = HttpStatusCode.InternalServerError; 129 // response.Status = HttpStatusCode.InternalServerError;
130 } 130 // }
131 } 131 // }
132 else 132 // else
133 { 133 // {
134 response.Status = HttpStatusCode.BadRequest; 134 // response.Status = HttpStatusCode.BadRequest;
135 } 135 // }
136 136
137 return true; 137 // return true;
138 } 138 //}
139 139
140 bool CreateInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 140 //bool CreateInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
141 { 141 //{
142 UUID ownerID = DeserializeUUID(request.Body); 142 // UUID ownerID = DeserializeUUID(request.Body);
143 143
144 if (ownerID != UUID.Zero) 144 // if (ownerID != UUID.Zero)
145 { 145 // {
146 Uri owner = Utils.GetOpenSimUri(ownerID); 146 // Uri owner = Utils.GetOpenSimUri(ownerID);
147 Logger.Log.DebugFormat("Created URI {0} for inventory creation", owner); 147 // Logger.Log.DebugFormat("Created URI {0} for inventory creation", owner);
148 148
149 InventoryFolder rootFolder = new InventoryFolder("My Inventory", ownerID, UUID.Zero, (short)AssetType.Folder); 149 // InventoryFolder rootFolder = new InventoryFolder("My Inventory", ownerID, UUID.Zero, (short)AssetType.Folder);
150 BackendResponse storageResponse = server.InventoryProvider.TryCreateInventory(owner, rootFolder); 150 // BackendResponse storageResponse = server.InventoryProvider.TryCreateInventory(owner, rootFolder);
151 if (storageResponse == BackendResponse.Success) 151 // if (storageResponse == BackendResponse.Success)
152 { 152 // {
153 CreateFolder("Animations", ownerID, rootFolder.ID, AssetType.Animation); 153 // CreateFolder("Animations", ownerID, rootFolder.ID, AssetType.Animation);
154 CreateFolder("Body Parts", ownerID, rootFolder.ID, AssetType.Bodypart); 154 // CreateFolder("Body Parts", ownerID, rootFolder.ID, AssetType.Bodypart);
155 CreateFolder("Calling Cards", ownerID, rootFolder.ID, AssetType.CallingCard); 155 // CreateFolder("Calling Cards", ownerID, rootFolder.ID, AssetType.CallingCard);
156 CreateFolder("Clothing", ownerID, rootFolder.ID, AssetType.Clothing); 156 // CreateFolder("Clothing", ownerID, rootFolder.ID, AssetType.Clothing);
157 CreateFolder("Gestures", ownerID, rootFolder.ID, AssetType.Gesture); 157 // CreateFolder("Gestures", ownerID, rootFolder.ID, AssetType.Gesture);
158 CreateFolder("Landmarks", ownerID, rootFolder.ID, AssetType.Landmark); 158 // CreateFolder("Landmarks", ownerID, rootFolder.ID, AssetType.Landmark);
159 CreateFolder("Lost and Found", ownerID, rootFolder.ID, AssetType.LostAndFoundFolder); 159 // CreateFolder("Lost and Found", ownerID, rootFolder.ID, AssetType.LostAndFoundFolder);
160 CreateFolder("Notecards", ownerID, rootFolder.ID, AssetType.Notecard); 160 // CreateFolder("Notecards", ownerID, rootFolder.ID, AssetType.Notecard);
161 CreateFolder("Objects", ownerID, rootFolder.ID, AssetType.Object); 161 // CreateFolder("Objects", ownerID, rootFolder.ID, AssetType.Object);
162 CreateFolder("Photo Album", ownerID, rootFolder.ID, AssetType.SnapshotFolder); 162 // CreateFolder("Photo Album", ownerID, rootFolder.ID, AssetType.SnapshotFolder);
163 CreateFolder("Scripts", ownerID, rootFolder.ID, AssetType.LSLText); 163 // CreateFolder("Scripts", ownerID, rootFolder.ID, AssetType.LSLText);
164 CreateFolder("Sounds", ownerID, rootFolder.ID, AssetType.Sound); 164 // CreateFolder("Sounds", ownerID, rootFolder.ID, AssetType.Sound);
165 CreateFolder("Textures", ownerID, rootFolder.ID, AssetType.Texture); 165 // CreateFolder("Textures", ownerID, rootFolder.ID, AssetType.Texture);
166 CreateFolder("Trash", ownerID, rootFolder.ID, AssetType.TrashFolder); 166 // CreateFolder("Trash", ownerID, rootFolder.ID, AssetType.TrashFolder);
167 167
168 SerializeBool(response.Body, true); 168 // SerializeBool(response.Body, true);
169 return true; 169 // return true;
170 } 170 // }
171 } 171 // }
172 172
173 SerializeBool(response.Body, false); 173 // SerializeBool(response.Body, false);
174 return true; 174 // return true;
175 } 175 //}
176 176
177 bool NewFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 177 //bool NewFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
178 { 178 //{
179 UUID agentID, sessionID; 179 // UUID agentID, sessionID;
180 InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID); 180 // InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID);
181 181
182 if (folder != null) 182 // if (folder != null)
183 { 183 // {
184 Uri owner = Utils.GetOpenSimUri(folder.Owner); 184 // Uri owner = Utils.GetOpenSimUri(folder.Owner);
185 185
186 // Some calls that are moving or updating a folder instead of creating a new one 186 // // Some calls that are moving or updating a folder instead of creating a new one
187 // will pass in an InventoryFolder without the name set. If this is the case we 187 // // will pass in an InventoryFolder without the name set. If this is the case we
188 // need to look up the name first 188 // // need to look up the name first
189 if (String.IsNullOrEmpty(folder.Name)) 189 // if (String.IsNullOrEmpty(folder.Name))
190 { 190 // {
191 InventoryFolder oldFolder; 191 // InventoryFolder oldFolder;
192 if (server.InventoryProvider.TryFetchFolder(owner, folder.ID, out oldFolder) == BackendResponse.Success) 192 // if (server.InventoryProvider.TryFetchFolder(owner, folder.ID, out oldFolder) == BackendResponse.Success)
193 folder.Name = oldFolder.Name; 193 // folder.Name = oldFolder.Name;
194 } 194 // }
195 195
196 BackendResponse storageResponse = server.InventoryProvider.TryCreateFolder(owner, folder); 196 // BackendResponse storageResponse = server.InventoryProvider.TryCreateFolder(owner, folder);
197 197
198 if (storageResponse == BackendResponse.Success) 198 // if (storageResponse == BackendResponse.Success)
199 { 199 // {
200 SerializeBool(response.Body, true); 200 // SerializeBool(response.Body, true);
201 return true; 201 // return true;
202 } 202 // }
203 } 203 // }
204 204
205 SerializeBool(response.Body, false); 205 // SerializeBool(response.Body, false);
206 return true; 206 // return true;
207 } 207 //}
208 208
209 bool UpdateFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 209 //bool UpdateFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
210 { 210 //{
211 return NewFolderHandler(client, request, response); 211 // return NewFolderHandler(client, request, response);
212 } 212 //}
213 213
214 bool MoveFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 214 //bool MoveFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
215 { 215 //{
216 return NewFolderHandler(client, request, response); 216 // return NewFolderHandler(client, request, response);
217 } 217 //}
218 218
219 bool PurgeFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 219 //bool PurgeFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
220 { 220 //{
221 UUID agentID, sessionID; 221 // UUID agentID, sessionID;
222 InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID); 222 // InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID);
223 223
224 if (folder != null) 224 // if (folder != null)
225 { 225 // {
226 Uri owner = Utils.GetOpenSimUri(folder.Owner); 226 // Uri owner = Utils.GetOpenSimUri(folder.Owner);
227 BackendResponse storageResponse = server.InventoryProvider.TryPurgeFolder(owner, folder.ID); 227 // BackendResponse storageResponse = server.InventoryProvider.TryPurgeFolder(owner, folder.ID);
228 228
229 if (storageResponse == BackendResponse.Success) 229 // if (storageResponse == BackendResponse.Success)
230 { 230 // {
231 SerializeBool(response.Body, true); 231 // SerializeBool(response.Body, true);
232 return true; 232 // return true;
233 } 233 // }
234 } 234 // }
235 235
236 SerializeBool(response.Body, false); 236 // SerializeBool(response.Body, false);
237 return true; 237 // return true;
238 } 238 //}
239 239
240 bool NewItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 240 //bool NewItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
241 { 241 //{
242 UUID agentID, sessionID; 242 // UUID agentID, sessionID;
243 InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID); 243 // InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID);
244 244
245 if (item != null) 245 // if (item != null)
246 { 246 // {
247 Uri owner = Utils.GetOpenSimUri(agentID); 247 // Uri owner = Utils.GetOpenSimUri(agentID);
248 BackendResponse storageResponse = server.InventoryProvider.TryCreateItem(owner, item); 248 // BackendResponse storageResponse = server.InventoryProvider.TryCreateItem(owner, item);
249 249
250 if (storageResponse == BackendResponse.Success) 250 // if (storageResponse == BackendResponse.Success)
251 { 251 // {
252 SerializeBool(response.Body, true); 252 // SerializeBool(response.Body, true);
253 return true; 253 // return true;
254 } 254 // }
255 } 255 // }
256 256
257 SerializeBool(response.Body, false); 257 // SerializeBool(response.Body, false);
258 return true; 258 // return true;
259 } 259 //}
260 260
261 bool DeleteItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 261 //bool DeleteItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
262 { 262 //{
263 UUID agentID, sessionID; 263 // UUID agentID, sessionID;
264 InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID); 264 // InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID);
265 265
266 if (item != null) 266 // if (item != null)
267 { 267 // {
268 Uri owner = Utils.GetOpenSimUri(item.Owner); 268 // Uri owner = Utils.GetOpenSimUri(item.Owner);
269 BackendResponse storageResponse = server.InventoryProvider.TryDeleteItem(owner, item.ID); 269 // BackendResponse storageResponse = server.InventoryProvider.TryDeleteItem(owner, item.ID);
270 270
271 if (storageResponse == BackendResponse.Success) 271 // if (storageResponse == BackendResponse.Success)
272 { 272 // {
273 SerializeBool(response.Body, true); 273 // SerializeBool(response.Body, true);
274 return true; 274 // return true;
275 } 275 // }
276 } 276 // }
277 277
278 SerializeBool(response.Body, false); 278 // SerializeBool(response.Body, false);
279 return true; 279 // return true;
280 } 280 //}
281 281
282 bool RootFoldersHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 282 //bool RootFoldersHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
283 { 283 //{
284 UUID ownerID = DeserializeUUID(request.Body); 284 // UUID ownerID = DeserializeUUID(request.Body);
285 285
286 if (ownerID != UUID.Zero) 286 // if (ownerID != UUID.Zero)
287 { 287 // {
288 Uri owner = Utils.GetOpenSimUri(ownerID); 288 // Uri owner = Utils.GetOpenSimUri(ownerID);
289 List<InventoryFolder> skeleton; 289 // List<InventoryFolder> skeleton;
290 BackendResponse storageResponse = server.InventoryProvider.TryFetchFolderList(owner, out skeleton); 290 // BackendResponse storageResponse = server.InventoryProvider.TryFetchFolderList(owner, out skeleton);
291 291
292 if (storageResponse == BackendResponse.Success) 292 // if (storageResponse == BackendResponse.Success)
293 { 293 // {
294 SerializeFolderList(response.Body, skeleton); 294 // SerializeFolderList(response.Body, skeleton);
295 } 295 // }
296 else if (storageResponse == BackendResponse.NotFound) 296 // else if (storageResponse == BackendResponse.NotFound)
297 { 297 // {
298 // Return an empty set of inventory so the requester knows that 298 // // Return an empty set of inventory so the requester knows that
299 // an inventory needs to be created for this agent 299 // // an inventory needs to be created for this agent
300 SerializeFolderList(response.Body, new List<InventoryFolder>(0)); 300 // SerializeFolderList(response.Body, new List<InventoryFolder>(0));
301 } 301 // }
302 else 302 // else
303 { 303 // {
304 response.Status = HttpStatusCode.InternalServerError; 304 // response.Status = HttpStatusCode.InternalServerError;
305 } 305 // }
306 } 306 // }
307 else 307 // else
308 { 308 // {
309 response.Status = HttpStatusCode.BadRequest; 309 // response.Status = HttpStatusCode.BadRequest;
310 } 310 // }
311 311
312 return true; 312 // return true;
313 } 313 //}
314 314
315 bool ActiveGesturesHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 315 //bool ActiveGesturesHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
316 { 316 //{
317 UUID ownerID = DeserializeUUID(request.Body); 317 // UUID ownerID = DeserializeUUID(request.Body);
318 318
319 if (ownerID != UUID.Zero) 319 // if (ownerID != UUID.Zero)
320 { 320 // {
321 Uri owner = Utils.GetOpenSimUri(ownerID); 321 // Uri owner = Utils.GetOpenSimUri(ownerID);
322 List<InventoryItem> gestures; 322 // List<InventoryItem> gestures;
323 BackendResponse storageResponse = server.InventoryProvider.TryFetchActiveGestures(owner, out gestures); 323 // BackendResponse storageResponse = server.InventoryProvider.TryFetchActiveGestures(owner, out gestures);
324 324
325 if (storageResponse == BackendResponse.Success) 325 // if (storageResponse == BackendResponse.Success)
326 { 326 // {
327 SerializeItemList(response.Body, gestures); 327 // SerializeItemList(response.Body, gestures);
328 } 328 // }
329 else if (storageResponse == BackendResponse.NotFound) 329 // else if (storageResponse == BackendResponse.NotFound)
330 { 330 // {
331 // Return an empty set of gestures to match OpenSim.Grid.InventoryServer.exe behavior 331 // // Return an empty set of gestures to match OpenSim.Grid.InventoryServer.exe behavior
332 SerializeItemList(response.Body, new List<InventoryItem>(0)); 332 // SerializeItemList(response.Body, new List<InventoryItem>(0));
333 } 333 // }
334 else 334 // else
335 { 335 // {
336 response.Status = HttpStatusCode.InternalServerError; 336 // response.Status = HttpStatusCode.InternalServerError;
337 } 337 // }
338 } 338 // }
339 else 339 // else
340 { 340 // {
341 response.Status = HttpStatusCode.BadRequest; 341 // response.Status = HttpStatusCode.BadRequest;
342 } 342 // }
343 343
344 return true; 344 // return true;
345 } 345 //}
346 346
347 BackendResponse CreateFolder(string name, UUID ownerID, UUID parentID, AssetType assetType) 347 BackendResponse CreateFolder(string name, UUID ownerID, UUID parentID, AssetType assetType)
348 { 348 {
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
index fddc385..d1ea201 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
@@ -28,6 +28,7 @@
28 */ 28 */
29 29
30using System; 30using System;
31using System.IO;
31using System.Collections.Generic; 32using System.Collections.Generic;
32using System.Net; 33using System.Net;
33using System.Xml; 34using System.Xml;
@@ -35,12 +36,13 @@ using OpenMetaverse;
35using OpenMetaverse.StructuredData; 36using OpenMetaverse.StructuredData;
36using HttpServer; 37using HttpServer;
37using OpenSim.Framework; 38using OpenSim.Framework;
39using OpenSim.Framework.Servers;
38 40
39namespace OpenSim.Grid.AssetInventoryServer.Plugins 41namespace OpenSim.Grid.AssetInventoryServer.Plugins
40{ 42{
41 public class ReferenceFrontendPlugin : IAssetInventoryServerPlugin 43 public class ReferenceFrontendPlugin : IAssetInventoryServerPlugin
42 { 44 {
43 AssetInventoryServer server; 45 AssetInventoryServer m_server;
44 46
45 public ReferenceFrontendPlugin() 47 public ReferenceFrontendPlugin()
46 { 48 {
@@ -50,18 +52,16 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
50 52
51 public void Initialise(AssetInventoryServer server) 53 public void Initialise(AssetInventoryServer server)
52 { 54 {
53 this.server = server; 55 m_server = server;
54 56
55 // Asset metadata request 57 // Asset metadata request
56 server.HttpServer.AddHandler("get", null, @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/metadata", 58 m_server.HttpServer.AddStreamHandler(new MetadataRequestHandler(server));
57 MetadataRequestHandler);
58 59
59 // Asset data request 60 // Asset data request
60 server.HttpServer.AddHandler("get", null, @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/data", 61 m_server.HttpServer.AddStreamHandler(new DataRequestHandler(server));
61 DataRequestHandler);
62 62
63 // Asset creation 63 // Asset creation
64 server.HttpServer.AddHandler("post", null, "^/createasset", CreateRequestHandler); 64 m_server.HttpServer.AddStreamHandler(new CreateRequestHandler(server));
65 65
66 Logger.Log.Info("[ASSET] Reference Frontend loaded."); 66 Logger.Log.Info("[ASSET] Reference Frontend loaded.");
67 } 67 }
@@ -92,174 +92,279 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
92 92
93 #endregion IPlugin implementation 93 #endregion IPlugin implementation
94 94
95 bool MetadataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 95 public class MetadataRequestHandler : IStreamedRequestHandler
96 { 96 {
97 UUID assetID; 97 AssetInventoryServer m_server;
98 // Split the URL up into an AssetID and a method 98 string m_contentType;
99 string[] rawUrl = request.Uri.PathAndQuery.Split('/'); 99 string m_httpMethod;
100 string m_path;
100 101
101 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID)) 102 public MetadataRequestHandler(AssetInventoryServer server)
102 { 103 {
103 UUID authToken = Utils.GetAuthToken(request); 104 m_server = server;
105 m_contentType = null;
106 m_httpMethod = "GET";
107 m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/metadata";
108 }
109
110 #region IStreamedRequestHandler implementation
111
112 public string ContentType
113 {
114 get { return m_contentType; }
115 }
116
117 public string HttpMethod
118 {
119 get { return m_httpMethod; }
120 }
121
122 public string Path
123 {
124 get { return m_path; }
125 }
104 126
105 if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID)) 127 public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
128 {
129 byte[] serializedData = null;
130 UUID assetID;
131 // Split the URL up into an AssetID and a method
132 string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
133
134 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
106 { 135 {
107 Metadata metadata; 136 UUID authToken = Utils.GetAuthToken(httpRequest);
108 BackendResponse storageResponse = server.StorageProvider.TryFetchMetadata(assetID, out metadata);
109 137
110 if (storageResponse == BackendResponse.Success) 138 if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
111 { 139 {
112 // If the asset data location wasn't specified in the metadata, specify it 140 Metadata metadata;
113 // manually here by pointing back to this asset server 141 BackendResponse storageResponse = m_server.StorageProvider.TryFetchMetadata(assetID, out metadata);
114 if (!metadata.Methods.ContainsKey("data"))
115 {
116 metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data",
117 request.Uri.Scheme, request.Uri.Authority, assetID));
118 }
119 142
120 byte[] serializedData = metadata.SerializeToBytes(); 143 if (storageResponse == BackendResponse.Success)
144 {
145 // If the asset data location wasn't specified in the metadata, specify it
146 // manually here by pointing back to this asset server
147 if (!metadata.Methods.ContainsKey("data"))
148 {
149 metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data",
150 httpRequest.Url.Scheme, httpRequest.Url.Authority, assetID));
151 }
121 152
122 response.Status = HttpStatusCode.OK; 153 serializedData = metadata.SerializeToBytes();
123 response.ContentType = "application/json";
124 response.ContentLength = serializedData.Length;
125 response.Body.Write(serializedData, 0, serializedData.Length);
126 154
127 } 155 httpResponse.StatusCode = (int) HttpStatusCode.OK;
128 else if (storageResponse == BackendResponse.NotFound) 156 httpResponse.ContentType = "application/json";
129 { 157 httpResponse.ContentLength = serializedData.Length;
130 Logger.Log.Warn("Could not find metadata for asset " + assetID.ToString()); 158 httpResponse.Body.Write(serializedData, 0, serializedData.Length);
131 response.Status = HttpStatusCode.NotFound; 159 }
160 else if (storageResponse == BackendResponse.NotFound)
161 {
162 Logger.Log.Warn("Could not find metadata for asset " + assetID.ToString());
163 httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
164 }
165 else
166 {
167 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
168 }
132 } 169 }
133 else 170 else
134 { 171 {
135 response.Status = HttpStatusCode.InternalServerError; 172 httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
136 } 173 }
137 } 174
138 else 175 return serializedData;
139 {
140 response.Status = HttpStatusCode.Forbidden;
141 } 176 }
142 177
143 return true; 178 httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
179 return serializedData;
144 } 180 }
145 181
146 response.Status = HttpStatusCode.NotFound; 182 #endregion IStreamedRequestHandler implementation
147 return true;
148 } 183 }
149 184
150 bool DataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 185 public class DataRequestHandler : IStreamedRequestHandler
151 { 186 {
152 UUID assetID; 187 AssetInventoryServer m_server;
153 // Split the URL up into an AssetID and a method 188 string m_contentType;
154 string[] rawUrl = request.Uri.PathAndQuery.Split('/'); 189 string m_httpMethod;
190 string m_path;
191
192 public DataRequestHandler(AssetInventoryServer server)
193 {
194 m_server = server;
195 m_contentType = null;
196 m_httpMethod = "GET";
197 m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/data";
198 }
199
200 #region IStreamedRequestHandler implementation
201
202 public string ContentType
203 {
204 get { return m_contentType; }
205 }
155 206
156 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID)) 207 public string HttpMethod
157 { 208 {
158 UUID authToken = Utils.GetAuthToken(request); 209 get { return m_httpMethod; }
210 }
211
212 public string Path
213 {
214 get { return m_path; }
215 }
159 216
160 if (server.AuthorizationProvider.IsDataAuthorized(authToken, assetID)) 217 public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
218 {
219 byte[] assetData = null;
220 UUID assetID;
221 // Split the URL up into an AssetID and a method
222 string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
223
224 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
161 { 225 {
162 byte[] assetData; 226 UUID authToken = Utils.GetAuthToken(httpRequest);
163 BackendResponse storageResponse = server.StorageProvider.TryFetchData(assetID, out assetData);
164 227
165 if (storageResponse == BackendResponse.Success) 228 if (m_server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
166 { 229 {
167 response.Status = HttpStatusCode.OK; 230 BackendResponse storageResponse = m_server.StorageProvider.TryFetchData(assetID, out assetData);
168 response.Status = HttpStatusCode.OK; 231
169 response.ContentType = "application/octet-stream"; 232 if (storageResponse == BackendResponse.Success)
170 response.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString()); 233 {
171 response.ContentLength = assetData.Length; 234 httpResponse.StatusCode = (int) HttpStatusCode.OK;
172 response.Body.Write(assetData, 0, assetData.Length); 235 httpResponse.ContentType = "application/octet-stream";
173 } 236 httpResponse.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString());
174 else if (storageResponse == BackendResponse.NotFound) 237 httpResponse.ContentLength = assetData.Length;
175 { 238 httpResponse.Body.Write(assetData, 0, assetData.Length);
176 response.Status = HttpStatusCode.NotFound; 239 }
240 else if (storageResponse == BackendResponse.NotFound)
241 {
242 httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
243 }
244 else
245 {
246 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
247 }
177 } 248 }
178 else 249 else
179 { 250 {
180 response.Status = HttpStatusCode.InternalServerError; 251 httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
181 } 252 }
182 } 253
183 else 254 return assetData;
184 {
185 response.Status = HttpStatusCode.Forbidden;
186 } 255 }
187 256
188 return true; 257 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
258 return assetData;
189 } 259 }
190 260
191 response.Status = HttpStatusCode.BadRequest; 261 #endregion IStreamedRequestHandler implementation
192 return true;
193 } 262 }
194 263
195 bool CreateRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 264 public class CreateRequestHandler : IStreamedRequestHandler
196 { 265 {
197 UUID authToken = Utils.GetAuthToken(request); 266 AssetInventoryServer m_server;
267 string m_contentType;
268 string m_httpMethod;
269 string m_path;
198 270
199 if (server.AuthorizationProvider.IsCreateAuthorized(authToken)) 271 public CreateRequestHandler(AssetInventoryServer server)
200 { 272 {
201 try 273 m_server = server;
202 { 274 m_contentType = null;
203 OSD osdata = OSDParser.DeserializeJson(request.Body); 275 m_httpMethod = "POST";
276 m_path = "^/createasset";
277 }
204 278
205 if (osdata.Type == OSDType.Map) 279 #region IStreamedRequestHandler implementation
206 { 280
207 OSDMap map = (OSDMap)osdata; 281 public string ContentType
208 Metadata metadata = new Metadata(); 282 {
209 metadata.Deserialize(map); 283 get { return m_contentType; }
284 }
285
286 public string HttpMethod
287 {
288 get { return m_httpMethod; }
289 }
290
291 public string Path
292 {
293 get { return m_path; }
294 }
295
296 public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
297 {
298 byte[] responseData = null;
299 UUID authToken = Utils.GetAuthToken(httpRequest);
210 300
211 byte[] assetData = map["data"].AsBinary(); 301 if (m_server.AuthorizationProvider.IsCreateAuthorized(authToken))
302 {
303 try
304 {
305 OSD osdata = OSDParser.DeserializeJson(httpRequest.InputStream);
212 306
213 if (assetData != null && assetData.Length > 0) 307 if (osdata.Type == OSDType.Map)
214 { 308 {
215 BackendResponse storageResponse; 309 OSDMap map = (OSDMap)osdata;
310 Metadata metadata = new Metadata();
311 metadata.Deserialize(map);
216 312
217 if (metadata.ID != UUID.Zero) 313 byte[] assetData = map["data"].AsBinary();
218 storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData);
219 else
220 storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
221 314
222 if (storageResponse == BackendResponse.Success) 315 if (assetData != null && assetData.Length > 0)
223 {
224 response.Status = HttpStatusCode.Created;
225 OSDMap responseMap = new OSDMap(1);
226 responseMap["id"] = OSD.FromUUID(metadata.ID);
227 LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap);
228 byte[] responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
229 response.Body.Write(responseData, 0, responseData.Length);
230 response.Body.Flush();
231 }
232 else if (storageResponse == BackendResponse.NotFound)
233 { 316 {
234 response.Status = HttpStatusCode.NotFound; 317 BackendResponse storageResponse;
318
319 if (metadata.ID != UUID.Zero)
320 storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData);
321 else
322 storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
323
324 if (storageResponse == BackendResponse.Success)
325 {
326 httpResponse.StatusCode = (int) HttpStatusCode.Created;
327 OSDMap responseMap = new OSDMap(1);
328 responseMap["id"] = OSD.FromUUID(metadata.ID);
329 LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap);
330 responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
331 httpResponse.Body.Write(responseData, 0, responseData.Length);
332 httpResponse.Body.Flush();
333 }
334 else if (storageResponse == BackendResponse.NotFound)
335 {
336 httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
337 }
338 else
339 {
340 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
341 }
235 } 342 }
236 else 343 else
237 { 344 {
238 response.Status = HttpStatusCode.InternalServerError; 345 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
239 } 346 }
240 } 347 }
241 else 348 else
242 { 349 {
243 response.Status = HttpStatusCode.BadRequest; 350 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
244 } 351 }
245 } 352 }
246 else 353 catch (Exception ex)
247 { 354 {
248 response.Status = HttpStatusCode.BadRequest; 355 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
356 httpResponse.StatusDescription = ex.Message;
249 } 357 }
250 } 358 }
251 catch (Exception ex) 359 else
252 { 360 {
253 response.Status = HttpStatusCode.InternalServerError; 361 httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
254 response.Reason = ex.Message;
255 } 362 }
256 } 363
257 else 364 return responseData;
258 {
259 response.Status = HttpStatusCode.Forbidden;
260 } 365 }
261 366
262 return true; 367 #endregion IStreamedRequestHandler implementation
263 } 368 }
264 } 369 }
265} 370}