|
@@ -26,6 +26,9 @@
|
|
|
*/
|
|
|
|
|
|
using System;
|
|
|
+using System.IO;
|
|
|
+using System.Text;
|
|
|
+using System.Net;
|
|
|
using Nini.Config;
|
|
|
using OpenSim.Server.Base;
|
|
|
using OpenSim.Services.Interfaces;
|
|
@@ -37,33 +40,91 @@ namespace OpenSim.Server.Handlers.BakedTextures
|
|
|
{
|
|
|
public class XBakesConnector : ServiceConnector
|
|
|
{
|
|
|
- private IBakedTextureService m_BakesService;
|
|
|
private string m_ConfigName = "BakedTextureService";
|
|
|
|
|
|
public XBakesConnector(IConfigSource config, IHttpServer server, string configName) :
|
|
|
base(config, server, configName)
|
|
|
{
|
|
|
- if (configName != String.Empty)
|
|
|
+ if (configName != string.Empty)
|
|
|
m_ConfigName = configName;
|
|
|
|
|
|
IConfig serverConfig = config.Configs[m_ConfigName];
|
|
|
if (serverConfig == null)
|
|
|
throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName));
|
|
|
|
|
|
- string assetService = serverConfig.GetString("LocalServiceModule",
|
|
|
- String.Empty);
|
|
|
+ string bakesServiceName = serverConfig.GetString("LocalServiceModule", string.Empty);
|
|
|
|
|
|
- if (assetService == String.Empty)
|
|
|
+ if (string.IsNullOrWhiteSpace(bakesServiceName))
|
|
|
throw new Exception("No BakedTextureService in config file");
|
|
|
|
|
|
- Object[] args = new Object[] { config };
|
|
|
- m_BakesService =
|
|
|
- ServerUtils.LoadPlugin<IBakedTextureService>(assetService, args);
|
|
|
+ object[] args = new object[] { config };
|
|
|
+ IBakedTextureService bakesService = ServerUtils.LoadPlugin<IBakedTextureService>(bakesServiceName, args);
|
|
|
|
|
|
IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
|
|
|
|
|
|
- server.AddStreamHandler(new BakesServerGetHandler(m_BakesService, auth));
|
|
|
- server.AddStreamHandler(new BakesServerPostHandler(m_BakesService, auth));
|
|
|
+ server.AddSimpleStreamHandler(new BakesServerHandler(bakesService, auth), true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class BakesServerHandler : SimpleStreamHandler
|
|
|
+ {
|
|
|
+ private IBakedTextureService m_BakesService;
|
|
|
+
|
|
|
+ public BakesServerHandler(IBakedTextureService service, IServiceAuth auth) :
|
|
|
+ base("/bakes", auth)
|
|
|
+ {
|
|
|
+ m_BakesService = service;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void ProcessRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
|
|
+ {
|
|
|
+ if(m_BakesService == null)
|
|
|
+ {
|
|
|
+ httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ switch (httpRequest.HttpMethod)
|
|
|
+ {
|
|
|
+ case "GET":
|
|
|
+ doGet(httpRequest, httpResponse);
|
|
|
+ break;
|
|
|
+ case "POST":
|
|
|
+ doPost(httpRequest, httpResponse);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ httpResponse.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ httpResponse.StatusCode = (int)HttpStatusCode.OK;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doGet(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
|
|
+ {
|
|
|
+ string[] p = SplitParams(httpRequest.UriPath);
|
|
|
+ httpRequest.InputStream.Dispose();
|
|
|
+
|
|
|
+ if (p.Length == 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ httpResponse.RawBuffer = m_BakesService.Get(p[0]);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doPost(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
|
|
+ {
|
|
|
+ string[] p = SplitParams(httpRequest.UriPath);
|
|
|
+
|
|
|
+ if (p.Length == 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ using (StreamReader sr = new StreamReader(httpRequest.InputStream))
|
|
|
+ m_BakesService.Store(p[0], sr.ReadToEnd());
|
|
|
+ httpRequest.InputStream.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ public string[] SplitParams(string path)
|
|
|
+ {
|
|
|
+ string param = GetParam(path);
|
|
|
+ return param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
}
|
|
|
}
|
|
|
}
|