diff options
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs')
-rw-r--r-- | OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs | 137 |
1 files changed, 87 insertions, 50 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 | ||
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 | } |