aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-05-28 17:49:34 +0000
committerJustin Clarke Casey2008-05-28 17:49:34 +0000
commitfb91a1aa49c098d03989a931280eaf668dceef18 (patch)
tree15dc2b18eaa7fac353d07eda7a6bf21fce1cfd64 /OpenSim/Region/Environment/Modules
parentspring cleaning, remove a bit of db4o grid server (diff)
downloadopensim-SC-fb91a1aa49c098d03989a931280eaf668dceef18.zip
opensim-SC-fb91a1aa49c098d03989a931280eaf668dceef18.tar.gz
opensim-SC-fb91a1aa49c098d03989a931280eaf668dceef18.tar.bz2
opensim-SC-fb91a1aa49c098d03989a931280eaf668dceef18.tar.xz
* Put in stubs for "load-oar" command, including ultra-primitive temporary tar loading code
* Currently as a test, this will successfully load only the first file of an opensim archive and do absolutely nothing with it
Diffstat (limited to 'OpenSim/Region/Environment/Modules')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs66
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequest.cs (renamed from OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs)10
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs6
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs108
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveWriter.cs (renamed from OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs)3
5 files changed, 182 insertions, 11 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs
new file mode 100644
index 0000000..0a3c4c5
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.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 OpenSim 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 OpenSim.Region.Environment.Scenes;
29using System.Reflection;
30using log4net;
31
32namespace OpenSim.Region.Environment.Modules.World.Archiver
33{
34 /// <summary>
35 /// Handles an individual archive read request
36 /// </summary>
37 public class ArchiveReadRequest
38 {
39 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
40
41 private Scene m_scene;
42 private string m_loadPath;
43
44 public ArchiveReadRequest(Scene scene, string loadPath)
45 {
46 m_scene = scene;
47 m_loadPath = loadPath;
48
49 DearchiveRegion();
50 }
51
52 protected void DearchiveRegion()
53 {
54 TarArchiveReader archive = new TarArchiveReader(m_loadPath);
55
56 // Just test for now by reading first file
57 string filePath = "ERROR";
58
59 byte[] data = archive.Read(out filePath);
60
61 m_log.DebugFormat("Successfully read {0} ({1} bytes) from archive {2}", filePath, data.Length, m_loadPath);
62
63 archive.Close();
64 }
65 }
66}
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequest.cs
index 364b31f..b952200 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequest.cs
@@ -44,9 +44,9 @@ namespace OpenSim.Region.Environment
44 public delegate void AssetsRequestCallback(IDictionary<LLUUID, AssetBase> assets); 44 public delegate void AssetsRequestCallback(IDictionary<LLUUID, AssetBase> assets);
45 45
46 /// <summary> 46 /// <summary>
47 /// Handles an individual archive request 47 /// Handles an individual archive write request
48 /// </summary> 48 /// </summary>
49 public class ArchiveRequest 49 public class ArchiveWriteRequest
50 { 50 {
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 52
@@ -55,7 +55,7 @@ namespace OpenSim.Region.Environment
55 55
56 private string m_serializedEntities; 56 private string m_serializedEntities;
57 57
58 public ArchiveRequest(Scene scene, string savePath) 58 public ArchiveWriteRequest(Scene scene, string savePath)
59 { 59 {
60 m_scene = scene; 60 m_scene = scene;
61 m_savePath = savePath; 61 m_savePath = savePath;
@@ -65,8 +65,6 @@ namespace OpenSim.Region.Environment
65 65
66 protected void ArchiveRegion() 66 protected void ArchiveRegion()
67 { 67 {
68 m_log.Warn("[ARCHIVER]: Archive region not yet implemented");
69
70 Dictionary<LLUUID, int> textureUuids = new Dictionary<LLUUID, int>(); 68 Dictionary<LLUUID, int> textureUuids = new Dictionary<LLUUID, int>();
71 69
72 List<EntityBase> entities = m_scene.GetEntities(); 70 List<EntityBase> entities = m_scene.GetEntities();
@@ -103,7 +101,7 @@ namespace OpenSim.Region.Environment
103 101
104 // XXX: Shouldn't hijack the asset async callback thread like this - this is only temporary 102 // XXX: Shouldn't hijack the asset async callback thread like this - this is only temporary
105 103
106 TarArchive archive = new TarArchive(); 104 TarArchiveWriter archive = new TarArchiveWriter();
107 105
108 archive.AddFile("prims.xml", m_serializedEntities); 106 archive.AddFile("prims.xml", m_serializedEntities);
109 107
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs
index cff9235..0e3123e 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs
@@ -72,12 +72,12 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
72 72
73 public void ArchiveRegion(string savePath) 73 public void ArchiveRegion(string savePath)
74 { 74 {
75 new ArchiveRequest(m_scene, savePath); 75 new ArchiveWriteRequest(m_scene, savePath);
76 } 76 }
77 77
78 public void DearchiveRegion(string loadPath) 78 public void DearchiveRegion(string loadPath)
79 { 79 {
80 m_log.Warn("[ARCHIVER]: Dearchive region not yet implemented"); 80 new ArchiveReadRequest(m_scene, loadPath);
81 } 81 }
82 } 82 }
83} \ No newline at end of file 83}
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs
new file mode 100644
index 0000000..e785c6c
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs
@@ -0,0 +1,108 @@
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 OpenSim 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.IO;
30//using System.Reflection;
31//using log4net;
32
33namespace OpenSim.Region.Environment.Modules.World.Archiver
34{
35 /// <summary>
36 /// Temporary code to do the bare minimum required to read a tar archive for our purposes
37 /// </summary>
38 public class TarArchiveReader
39 {
40// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
41
42 protected static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding();
43
44 /// <summary>
45 /// Binary reader for the underlying stream
46 /// </summary>
47 protected BinaryReader m_br;
48
49 public TarArchiveReader(string archivePath)
50 {
51 m_br = new BinaryReader(new FileStream(archivePath, FileMode.Open));
52 }
53
54 public byte[] Read(out string filePath)
55 {
56 TarHeader header = ReadHeader();
57 filePath = header.FilePath;
58 return m_br.ReadBytes(header.FileSize);
59 }
60
61 /// <summary>
62 /// Read the next 512 byte chunk of data as a tar header.
63 /// </summary>
64 /// <returns>A tar header struct</returns>
65 protected TarHeader ReadHeader()
66 {
67 TarHeader tarHeader = new TarHeader();
68
69 byte[] header = m_br.ReadBytes(512);
70
71 tarHeader.FilePath = m_asciiEncoding.GetString(header, 0, 100);
72 tarHeader.FileSize = ConvertOctalBytesToDecimal(header, 124, 11);
73
74 return tarHeader;
75 }
76
77 public void Close()
78 {
79 m_br.Close();
80 }
81
82 /// <summary>
83 /// Convert octal bytes to a decimal representation
84 /// </summary>
85 /// <param name="bytes"></param>
86 /// <returns></returns>
87 public static int ConvertOctalBytesToDecimal(byte[] bytes, int startIndex, int count)
88 {
89 string oString = m_asciiEncoding.GetString(bytes, startIndex, count);
90
91 int d = 0;
92
93 foreach (char c in oString)
94 {
95 d <<= 3;
96 d |= c - '0';
97 }
98
99 return d;
100 }
101 }
102
103 public struct TarHeader
104 {
105 public string FilePath;
106 public int FileSize;
107 }
108}
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveWriter.cs
index c7492fe..e951755 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveWriter.cs
@@ -25,7 +25,6 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28
29using System; 28using System;
30using System.Collections.Generic; 29using System.Collections.Generic;
31using System.IO; 30using System.IO;
@@ -38,7 +37,7 @@ namespace OpenSim.Region.Environment
38 /// <summary> 37 /// <summary>
39 /// Temporary code to produce a tar archive in tar v7 format 38 /// Temporary code to produce a tar archive in tar v7 format
40 /// </summary> 39 /// </summary>
41 public class TarArchive 40 public class TarArchiveWriter
42 { 41 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 43