aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/BakedTextures
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakes.cs148
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs71
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs69
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs76
4 files changed, 364 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakes.cs b/OpenSim/Server/Handlers/BakedTextures/XBakes.cs
new file mode 100644
index 0000000..4e55433
--- /dev/null
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakes.cs
@@ -0,0 +1,148 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Diagnostics;
30using System.Collections.Generic;
31using System.IO;
32using System.Text;
33using System.Threading;
34using System.Reflection;
35using OpenSim.Framework;
36using OpenSim.Framework.Console;
37using OpenSim.Server.Base;
38using OpenSim.Services.Base;
39using OpenSim.Services.Interfaces;
40using Nini.Config;
41using log4net;
42using OpenMetaverse;
43
44namespace OpenSim.Server.Handlers.BakedTextures
45{
46 public class XBakes : ServiceBase, IBakedTextureService
47 {
48 private static readonly ILog m_log =
49 LogManager.GetLogger(
50 MethodBase.GetCurrentMethod().DeclaringType);
51
52 protected string m_FSBase;
53
54 private System.Text.UTF8Encoding utf8encoding =
55 new System.Text.UTF8Encoding();
56
57 public XBakes(IConfigSource config) : base(config)
58 {
59 MainConsole.Instance.Commands.AddCommand("fs", false,
60 "delete bakes", "delete bakes <ID>",
61 "Delete agent's baked textures from server",
62 HandleDeleteBakes);
63
64 IConfig assetConfig = config.Configs["BakedTextureService"];
65 if (assetConfig == null)
66 {
67 throw new Exception("No BakedTextureService configuration");
68 }
69
70 m_FSBase = assetConfig.GetString("BaseDirectory", String.Empty);
71 if (m_FSBase == String.Empty)
72 {
73 m_log.ErrorFormat("[BAKES]: BaseDirectory not specified");
74 throw new Exception("Configuration error");
75 }
76
77 m_log.Info("[BAKES]: XBakes service enabled");
78 }
79
80 public string Get(string id)
81 {
82 string file = HashToFile(id);
83 string diskFile = Path.Combine(m_FSBase, file);
84
85 if (File.Exists(diskFile))
86 {
87 try
88 {
89 byte[] content = File.ReadAllBytes(diskFile);
90
91 return utf8encoding.GetString(content);
92 }
93 catch
94 {
95 }
96 }
97 return String.Empty;
98 }
99
100 public void Store(string id, string sdata)
101 {
102 string file = HashToFile(id);
103 string diskFile = Path.Combine(m_FSBase, file);
104
105 Directory.CreateDirectory(Path.GetDirectoryName(diskFile));
106
107 File.Delete(diskFile);
108
109 byte[] data = utf8encoding.GetBytes(sdata);
110
111 using (FileStream fs = File.Create(diskFile))
112 fs.Write(data, 0, data.Length);
113 }
114
115 private void HandleDeleteBakes(string module, string[] args)
116 {
117 if (args.Length < 3)
118 {
119 MainConsole.Instance.Output("Syntax: delete bakes <ID>");
120 return;
121 }
122
123 string file = HashToFile(args[2]);
124 string diskFile = Path.Combine(m_FSBase, file);
125
126 if (File.Exists(diskFile))
127 {
128 File.Delete(diskFile);
129 MainConsole.Instance.Output("Bakes deleted");
130 return;
131 }
132 MainConsole.Instance.Output("Bakes not found");
133 }
134
135 public string HashToPath(string hash)
136 {
137 return Path.Combine(hash.Substring(0, 2),
138 Path.Combine(hash.Substring(2, 2),
139 Path.Combine(hash.Substring(4, 2),
140 hash.Substring(6, 4))));
141 }
142
143 public string HashToFile(string hash)
144 {
145 return Path.Combine(HashToPath(hash), hash);
146 }
147 }
148}
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs
new file mode 100644
index 0000000..3c61673
--- /dev/null
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs
@@ -0,0 +1,71 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using Nini.Config;
29using log4net;
30using System;
31using System.IO;
32using System.Reflection;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces;
40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
42using OpenSim.Framework.Servers.HttpServer;
43
44namespace OpenSim.Server.Handlers.BakedTextures
45{
46 public class BakesServerGetHandler : BaseStreamHandler
47 {
48// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49
50 private IBakedTextureService m_BakesService;
51 private System.Text.UTF8Encoding utf8 =
52 new System.Text.UTF8Encoding();
53
54 public BakesServerGetHandler(IBakedTextureService service, IServiceAuth auth) :
55 base("GET", "/bakes", auth)
56 {
57 m_BakesService = service;
58 }
59
60 protected override byte[] ProcessRequest(
61 string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
62 {
63 string[] p = SplitParams(path);
64
65 if (p.Length == 0)
66 return new byte[0];
67
68 return utf8.GetBytes(m_BakesService.Get(p[0]));
69 }
70 }
71}
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs
new file mode 100644
index 0000000..4c12967
--- /dev/null
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs
@@ -0,0 +1,69 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.ServiceAuth;
33using OpenSim.Framework.Servers.HttpServer;
34using OpenSim.Server.Handlers.Base;
35
36namespace OpenSim.Server.Handlers.BakedTextures
37{
38 public class XBakesConnector : ServiceConnector
39 {
40 private IBakedTextureService m_BakesService;
41 private string m_ConfigName = "BakedTextureService";
42
43 public XBakesConnector(IConfigSource config, IHttpServer server, string configName) :
44 base(config, server, configName)
45 {
46 if (configName != String.Empty)
47 m_ConfigName = configName;
48
49 IConfig serverConfig = config.Configs[m_ConfigName];
50 if (serverConfig == null)
51 throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName));
52
53 string assetService = serverConfig.GetString("LocalServiceModule",
54 String.Empty);
55
56 if (assetService == String.Empty)
57 throw new Exception("No BakedTextureService in config file");
58
59 Object[] args = new Object[] { config };
60 m_BakesService =
61 ServerUtils.LoadPlugin<IBakedTextureService>(assetService, args);
62
63 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
64
65 server.AddStreamHandler(new BakesServerGetHandler(m_BakesService, auth));
66 server.AddStreamHandler(new BakesServerPostHandler(m_BakesService, auth));
67 }
68 }
69}
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs
new file mode 100644
index 0000000..e38543b
--- /dev/null
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs
@@ -0,0 +1,76 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces;
40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
42using OpenSim.Framework.Servers.HttpServer;
43
44namespace OpenSim.Server.Handlers.BakedTextures
45{
46 public class BakesServerPostHandler : BaseStreamHandler
47 {
48// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49
50 private IBakedTextureService m_BakesService;
51
52 public BakesServerPostHandler(IBakedTextureService service, IServiceAuth auth) :
53 base("POST", "/bakes", auth)
54 {
55 m_BakesService = service;
56 }
57
58 protected override byte[] ProcessRequest(
59 string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
60 {
61 string[] p = SplitParams(path);
62
63 if (p.Length == 0)
64 {
65 return new byte[0];
66 }
67
68 StreamReader sr = new StreamReader(request);
69
70 m_BakesService.Store(p[0], sr.ReadToEnd());
71 sr.Close();
72
73 return new byte[0];
74 }
75 }
76} \ No newline at end of file