aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/BakedTextures
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakes.cs150
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs70
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs66
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs78
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..d1b2e12
--- /dev/null
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakes.cs
@@ -0,0 +1,150 @@
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 FileStream fs = File.Create(diskFile);
111
112 fs.Write(data, 0, data.Length);
113
114 fs.Close();
115 }
116
117 private void HandleDeleteBakes(string module, string[] args)
118 {
119 if (args.Length < 3)
120 {
121 MainConsole.Instance.Output("Syntax: delete bakes <ID>");
122 return;
123 }
124
125 string file = HashToFile(args[2]);
126 string diskFile = Path.Combine(m_FSBase, file);
127
128 if (File.Exists(diskFile))
129 {
130 File.Delete(diskFile);
131 MainConsole.Instance.Output("Bakes deleted");
132 return;
133 }
134 MainConsole.Instance.Output("Bakes not found");
135 }
136
137 public string HashToPath(string hash)
138 {
139 return Path.Combine(hash.Substring(0, 2),
140 Path.Combine(hash.Substring(2, 2),
141 Path.Combine(hash.Substring(4, 2),
142 hash.Substring(6, 4))));
143 }
144
145 public string HashToFile(string hash)
146 {
147 return Path.Combine(HashToPath(hash), hash);
148 }
149 }
150}
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs
new file mode 100644
index 0000000..fb4b794
--- /dev/null
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs
@@ -0,0 +1,70 @@
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.Servers.HttpServer;
42
43namespace OpenSim.Server.Handlers.BakedTextures
44{
45 public class BakesServerGetHandler : BaseStreamHandler
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private IBakedTextureService m_BakesService;
50 private System.Text.UTF8Encoding utf8 =
51 new System.Text.UTF8Encoding();
52
53 public BakesServerGetHandler(IBakedTextureService service) :
54 base("GET", "/bakes")
55 {
56 m_BakesService = service;
57 }
58
59 public override byte[] Handle(string path, Stream request,
60 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
61 {
62 string[] p = SplitParams(path);
63
64 if (p.Length == 0)
65 return new byte[0];
66
67 return utf8.GetBytes(m_BakesService.Get(p[0]));
68 }
69 }
70}
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs
new file mode 100644
index 0000000..7bf7641
--- /dev/null
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs
@@ -0,0 +1,66 @@
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.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base;
34
35namespace OpenSim.Server.Handlers.BakedTextures
36{
37 public class XBakesConnector : ServiceConnector
38 {
39 private IBakedTextureService m_BakesService;
40 private string m_ConfigName = "BakedTextureService";
41
42 public XBakesConnector(IConfigSource config, IHttpServer server, string configName) :
43 base(config, server, configName)
44 {
45 if (configName != String.Empty)
46 m_ConfigName = configName;
47
48 IConfig serverConfig = config.Configs[m_ConfigName];
49 if (serverConfig == null)
50 throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName));
51
52 string assetService = serverConfig.GetString("LocalServiceModule",
53 String.Empty);
54
55 if (assetService == String.Empty)
56 throw new Exception("No BakedTextureService in config file");
57
58 Object[] args = new Object[] { config };
59 m_BakesService =
60 ServerUtils.LoadPlugin<IBakedTextureService>(assetService, args);
61
62 server.AddStreamHandler(new BakesServerGetHandler(m_BakesService));
63 server.AddStreamHandler(new BakesServerPostHandler(m_BakesService));
64 }
65 }
66}
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs
new file mode 100644
index 0000000..69adb7f
--- /dev/null
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs
@@ -0,0 +1,78 @@
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.Servers.HttpServer;
42
43namespace OpenSim.Server.Handlers.BakedTextures
44{
45 public class BakesServerPostHandler : BaseStreamHandler
46 {
47 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private IBakedTextureService m_BakesService;
50
51 private System.Text.UTF8Encoding utf8 =
52 new System.Text.UTF8Encoding();
53
54 public BakesServerPostHandler(IBakedTextureService service) :
55 base("POST", "/bakes")
56 {
57 m_BakesService = service;
58 }
59
60 public override byte[] Handle(string path, Stream request,
61 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
62 {
63 string[] p = SplitParams(path);
64
65 if (p.Length == 0)
66 {
67 return new byte[0];
68 }
69
70 StreamReader sr = new StreamReader(request);
71
72 m_BakesService.Store(p[0], sr.ReadToEnd());
73 sr.Close();
74
75 return new byte[0];
76 }
77 }
78}