diff options
author | Mike Mazur | 2009-02-16 02:27:17 +0000 |
---|---|---|
committer | Mike Mazur | 2009-02-16 02:27:17 +0000 |
commit | 07b8d51da8186e537da35c1d56d176b4843d8eaa (patch) | |
tree | 9ae3581af0ca34a4210b77ca304d9ba75440fb51 /OpenSim | |
parent | Update to new generic DataPluginFactory calls. (diff) | |
download | opensim-SC-07b8d51da8186e537da35c1d56d176b4843d8eaa.zip opensim-SC-07b8d51da8186e537da35c1d56d176b4843d8eaa.tar.gz opensim-SC-07b8d51da8186e537da35c1d56d176b4843d8eaa.tar.bz2 opensim-SC-07b8d51da8186e537da35c1d56d176b4843d8eaa.tar.xz |
AssetInventoryServer now compiles while using the standard OpenSim
console and HttpServer. It doesn't work though.
Diffstat (limited to '')
7 files changed, 796 insertions, 564 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs index 19f2081..bd05d59 100644 --- a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs +++ b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs | |||
@@ -36,17 +36,19 @@ using System.Security.Cryptography.X509Certificates; | |||
36 | using System.ServiceProcess; | 36 | using System.ServiceProcess; |
37 | using ExtensionLoader; | 37 | using ExtensionLoader; |
38 | using ExtensionLoader.Config; | 38 | using ExtensionLoader.Config; |
39 | using HttpServer; | 39 | //using HttpServer; |
40 | using log4net; | 40 | using log4net; |
41 | using OpenSim.Framework; | 41 | using OpenSim.Framework; |
42 | using OpenSim.Framework.Servers; | ||
43 | using OpenSim.Framework.Console; | ||
42 | 44 | ||
43 | namespace OpenSim.Grid.AssetInventoryServer | 45 | namespace OpenSim.Grid.AssetInventoryServer |
44 | { | 46 | { |
45 | public class AssetInventoryServer : ServiceBase | 47 | public class AssetInventoryServer : BaseOpenSimServer//ServiceBase |
46 | { | 48 | { |
47 | public const string CONFIG_FILE = "AssetInventoryServer.ini"; | 49 | public const string CONFIG_FILE = "AssetInventoryServer.ini"; |
48 | 50 | ||
49 | public WebServer HttpServer; | 51 | //public WebServer HttpServer; |
50 | public IniConfigSource ConfigFile; | 52 | public IniConfigSource ConfigFile; |
51 | 53 | ||
52 | public IAssetStorageProvider StorageProvider; | 54 | public IAssetStorageProvider StorageProvider; |
@@ -60,7 +62,9 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
60 | 62 | ||
61 | public AssetInventoryServer() | 63 | public AssetInventoryServer() |
62 | { | 64 | { |
63 | this.ServiceName = "OpenSimAssetInventoryServer"; | 65 | m_console = new ConsoleBase("Asset"); |
66 | MainConsole.Instance = m_console; | ||
67 | //this.ServiceName = "OpenSimAssetInventoryServer"; | ||
64 | } | 68 | } |
65 | 69 | ||
66 | public bool Start() | 70 | public bool Start() |
@@ -123,7 +127,7 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
123 | catch (Exception ex) | 127 | catch (Exception ex) |
124 | { | 128 | { |
125 | Logger.Log.Error("Initializing the HTTP server failed, shutting down: " + ex.Message); | 129 | Logger.Log.Error("Initializing the HTTP server failed, shutting down: " + ex.Message); |
126 | Stop(); | 130 | Shutdown(); |
127 | return false; | 131 | return false; |
128 | } | 132 | } |
129 | 133 | ||
@@ -138,7 +142,17 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
138 | return true; | 142 | return true; |
139 | } | 143 | } |
140 | 144 | ||
141 | public void Shutdown() | 145 | public void Work() |
146 | { | ||
147 | m_console.Notice("Enter help for a list of commands"); | ||
148 | |||
149 | while (true) | ||
150 | { | ||
151 | m_console.Prompt(); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | public override void ShutdownSpecific() | ||
142 | { | 156 | { |
143 | foreach (IAssetInventoryServerPlugin plugin in frontends) | 157 | foreach (IAssetInventoryServerPlugin plugin in frontends) |
144 | { | 158 | { |
@@ -162,26 +176,27 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
162 | 176 | ||
163 | void InitHttpServer(int port, X509Certificate serverCert) | 177 | void InitHttpServer(int port, X509Certificate serverCert) |
164 | { | 178 | { |
165 | if (serverCert != null) | 179 | //if (serverCert != null) |
166 | HttpServer = new WebServer(IPAddress.Any, port, serverCert, null, false); | 180 | // HttpServer = new WebServer(IPAddress.Any, port, serverCert, null, false); |
167 | else | 181 | //else |
168 | HttpServer = new WebServer(IPAddress.Any, port); | 182 | // HttpServer = new WebServer(IPAddress.Any, port); |
169 | 183 | ||
170 | HttpServer.LogWriter = new log4netLogWriter(Logger.Log); | 184 | //HttpServer.LogWriter = new log4netLogWriter(Logger.Log); |
171 | 185 | ||
172 | HttpServer.Set404Handler( | 186 | //HttpServer.Set404Handler( |
173 | delegate(IHttpClientContext client, IHttpRequest request, IHttpResponse response) | 187 | // delegate(IHttpClientContext client, IHttpRequest request, IHttpResponse response) |
174 | { | 188 | // { |
175 | Logger.Log.Warn("Requested page was not found: " + request.Uri.PathAndQuery); | 189 | // Logger.Log.Warn("Requested page was not found: " + request.Uri.PathAndQuery); |
176 | 190 | ||
177 | string notFoundString = "<html><head><title>Page Not Found</title></head><body>The requested page or method was not found</body></html>"; | 191 | // string notFoundString = "<html><head><title>Page Not Found</title></head><body>The requested page or method was not found</body></html>"; |
178 | byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundString); | 192 | // byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundString); |
179 | response.Body.Write(buffer, 0, buffer.Length); | 193 | // response.Body.Write(buffer, 0, buffer.Length); |
180 | response.Status = HttpStatusCode.NotFound; | 194 | // response.Status = HttpStatusCode.NotFound; |
181 | return true; | 195 | // return true; |
182 | } | 196 | // } |
183 | ); | 197 | //); |
184 | 198 | ||
199 | m_httpServer = new BaseHttpServer(8003); | ||
185 | HttpServer.Start(); | 200 | HttpServer.Start(); |
186 | 201 | ||
187 | Logger.Log.Info("Asset server is listening on port " + port); | 202 | Logger.Log.Info("Asset server is listening on port " + port); |
@@ -189,14 +204,14 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
189 | 204 | ||
190 | #region ServiceBase Overrides | 205 | #region ServiceBase Overrides |
191 | 206 | ||
192 | protected override void OnStart(string[] args) | 207 | //protected override void OnStart(string[] args) |
193 | { | 208 | //{ |
194 | Start(); | 209 | // Start(); |
195 | } | 210 | //} |
196 | protected override void OnStop() | 211 | //protected override void OnStop() |
197 | { | 212 | //{ |
198 | Shutdown(); | 213 | // Shutdown(); |
199 | } | 214 | //} |
200 | 215 | ||
201 | #endregion | 216 | #endregion |
202 | 217 | ||
@@ -231,36 +246,36 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
231 | } | 246 | } |
232 | } | 247 | } |
233 | 248 | ||
234 | public class log4netLogWriter : ILogWriter | 249 | //public class log4netLogWriter : ILogWriter |
235 | { | 250 | //{ |
236 | ILog Log; | 251 | // ILog Log; |
237 | 252 | ||
238 | public log4netLogWriter(ILog log) | 253 | // public log4netLogWriter(ILog log) |
239 | { | 254 | // { |
240 | Log = log; | 255 | // Log = log; |
241 | } | 256 | // } |
242 | 257 | ||
243 | public void Write(object source, LogPrio prio, string message) | 258 | // public void Write(object source, LogPrio prio, string message) |
244 | { | 259 | // { |
245 | switch (prio) | 260 | // switch (prio) |
246 | { | 261 | // { |
247 | case LogPrio.Trace: | 262 | // case LogPrio.Trace: |
248 | case LogPrio.Debug: | 263 | // case LogPrio.Debug: |
249 | Log.DebugFormat("{0}: {1}", source, message); | 264 | // Log.DebugFormat("{0}: {1}", source, message); |
250 | break; | 265 | // break; |
251 | case LogPrio.Info: | 266 | // case LogPrio.Info: |
252 | Log.InfoFormat("{0}: {1}", source, message); | 267 | // Log.InfoFormat("{0}: {1}", source, message); |
253 | break; | 268 | // break; |
254 | case LogPrio.Warning: | 269 | // case LogPrio.Warning: |
255 | Log.WarnFormat("{0}: {1}", source, message); | 270 | // Log.WarnFormat("{0}: {1}", source, message); |
256 | break; | 271 | // break; |
257 | case LogPrio.Error: | 272 | // case LogPrio.Error: |
258 | Log.ErrorFormat("{0}: {1}", source, message); | 273 | // Log.ErrorFormat("{0}: {1}", source, message); |
259 | break; | 274 | // break; |
260 | case LogPrio.Fatal: | 275 | // case LogPrio.Fatal: |
261 | Log.FatalFormat("{0}: {1}", source, message); | 276 | // Log.FatalFormat("{0}: {1}", source, message); |
262 | break; | 277 | // break; |
263 | } | 278 | // } |
264 | } | 279 | // } |
265 | } | 280 | //} |
266 | } | 281 | } |
diff --git a/OpenSim/Grid/AssetInventoryServer/Main.cs b/OpenSim/Grid/AssetInventoryServer/Main.cs index 894a32a..2f01281 100644 --- a/OpenSim/Grid/AssetInventoryServer/Main.cs +++ b/OpenSim/Grid/AssetInventoryServer/Main.cs | |||
@@ -50,8 +50,9 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
50 | Environment.Exit(0); | 50 | Environment.Exit(0); |
51 | }; | 51 | }; |
52 | 52 | ||
53 | while (true) | 53 | server.Work(); |
54 | Console.ReadLine(); | 54 | //while (true) |
55 | // Console.ReadLine(); | ||
55 | } | 56 | } |
56 | #else | 57 | #else |
57 | ServiceBase[] servicesToRun = new ServiceBase[] { new AssetInventoryServer() }; | 58 | ServiceBase[] servicesToRun = new ServiceBase[] { new AssetInventoryServer() }; |
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 | ||
30 | using System; | 30 | using System; |
31 | using System.IO; | ||
31 | using System.Collections.Generic; | 32 | using System.Collections.Generic; |
32 | using System.Collections.Specialized; | 33 | using System.Collections.Specialized; |
33 | using System.Net; | 34 | using System.Net; |
34 | using System.Text; | 35 | using System.Text; |
35 | using System.Web; | 36 | using System.Web; |
36 | using OpenMetaverse; | 37 | using OpenMetaverse; |
37 | using HttpServer; | ||
38 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
39 | using OpenSim.Framework.Servers; | ||
39 | 40 | ||
40 | namespace OpenSim.Grid.AssetInventoryServer.Plugins | 41 | namespace 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}\">< Previous Page</a> | ", request.Uri.AbsolutePath, page - 1); | ||
115 | html.AppendFormat("<a href=\"{0}?page={1}\">Next Page ></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> </td><td> </td><td>{0}</td><td>{1}</td><td> </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}\">< Previous Page</a> | ", httpRequest.RawUrl, page - 1); | ||
149 | html.AppendFormat("<a href=\"{0}?page={1}\">Next Page ></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> </td><td> </td><td>{0}</td><td>{1}</td><td> </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; | |||
37 | using OpenMetaverse; | 37 | using OpenMetaverse; |
38 | using HttpServer; | 38 | using HttpServer; |
39 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
40 | using OpenSim.Framework.Servers; | ||
40 | 41 | ||
41 | namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | 42 | namespace 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 | ||
30 | using System; | 30 | using System; |
31 | using System.IO; | ||
31 | using System.Collections.Generic; | 32 | using System.Collections.Generic; |
32 | using System.Net; | 33 | using System.Net; |
33 | using System.Xml; | 34 | using System.Xml; |
@@ -35,12 +36,13 @@ using OpenMetaverse; | |||
35 | using OpenMetaverse.StructuredData; | 36 | using OpenMetaverse.StructuredData; |
36 | using HttpServer; | 37 | using HttpServer; |
37 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
39 | using OpenSim.Framework.Servers; | ||
38 | 40 | ||
39 | namespace OpenSim.Grid.AssetInventoryServer.Plugins | 41 | namespace 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 | } |
diff --git a/OpenSim/Grid/AssetInventoryServer/Utils.cs b/OpenSim/Grid/AssetInventoryServer/Utils.cs index e1b62a4..52e2370 100644 --- a/OpenSim/Grid/AssetInventoryServer/Utils.cs +++ b/OpenSim/Grid/AssetInventoryServer/Utils.cs | |||
@@ -36,12 +36,13 @@ using System.Xml.Serialization; | |||
36 | using OpenMetaverse; | 36 | using OpenMetaverse; |
37 | using OpenMetaverse.StructuredData; | 37 | using OpenMetaverse.StructuredData; |
38 | using HttpServer; | 38 | using HttpServer; |
39 | using OpenSim.Framework.Servers; | ||
39 | 40 | ||
40 | namespace OpenSim.Grid.AssetInventoryServer | 41 | namespace OpenSim.Grid.AssetInventoryServer |
41 | { | 42 | { |
42 | public static class Utils | 43 | public static class Utils |
43 | { | 44 | { |
44 | public static UUID GetAuthToken(IHttpRequest request) | 45 | public static UUID GetAuthToken(OSHttpRequest request) |
45 | { | 46 | { |
46 | UUID authToken = UUID.Zero; | 47 | UUID authToken = UUID.Zero; |
47 | 48 | ||
@@ -55,13 +56,13 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
55 | UUID.TryParse(authHeaderParts[1], out authToken); | 56 | UUID.TryParse(authHeaderParts[1], out authToken); |
56 | } | 57 | } |
57 | 58 | ||
58 | if (authToken == UUID.Zero && request.Cookies != null) | 59 | //if (authToken == UUID.Zero && request.Cookies != null) |
59 | { | 60 | //{ |
60 | // Check for an authToken cookie to make logins browser-compatible | 61 | // // Check for an authToken cookie to make logins browser-compatible |
61 | RequestCookie authCookie = request.Cookies["authToken"]; | 62 | // RequestCookie authCookie = request.Cookies["authToken"]; |
62 | if (authCookie != null) | 63 | // if (authCookie != null) |
63 | UUID.TryParse(authCookie.Value, out authToken); | 64 | // UUID.TryParse(authCookie.Value, out authToken); |
64 | } | 65 | //} |
65 | 66 | ||
66 | return authToken; | 67 | return authToken; |
67 | } | 68 | } |