aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Asset
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/Asset')
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetServerConnector.cs127
1 files changed, 126 insertions, 1 deletions
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
index df571fa..9960228 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
@@ -26,7 +26,11 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.IO;
29using Nini.Config; 30using Nini.Config;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Framework.Console;
30using OpenSim.Server.Base; 34using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces; 35using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer; 36using OpenSim.Framework.Servers.HttpServer;
@@ -67,6 +71,127 @@ namespace OpenSim.Server.Handlers.Asset
67 server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); 71 server.AddStreamHandler(new AssetServerGetHandler(m_AssetService));
68 server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); 72 server.AddStreamHandler(new AssetServerPostHandler(m_AssetService));
69 server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete)); 73 server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete));
74
75 MainConsole.Instance.Commands.AddCommand("kfs", false,
76 "show digest",
77 "show digest <ID>",
78 "Show asset digest",
79 HandleShowDigest);
80
81 MainConsole.Instance.Commands.AddCommand("kfs", false,
82 "delete asset",
83 "delete asset <ID>",
84 "Delete asset from database",
85 HandleDeleteAsset);
86
87 MainConsole.Instance.Commands.AddCommand("kfs", false,
88 "dump asset",
89 "dump asset <ID>",
90 "Dump asset to a file",
91 "The filename is the same as the ID given.",
92 HandleDumpAsset);
93 }
94
95 void HandleDeleteAsset(string module, string[] args)
96 {
97 if (args.Length < 3)
98 {
99 MainConsole.Instance.Output("Syntax: delete asset <ID>");
100 return;
101 }
102
103 AssetBase asset = m_AssetService.Get(args[2]);
104
105 if (asset == null || asset.Data.Length == 0)
106 {
107 MainConsole.Instance.Output("Asset not found");
108 return;
109 }
110
111 m_AssetService.Delete(args[2]);
112
113 //MainConsole.Instance.Output("Asset deleted");
114 // TODO: Implement this
115
116 MainConsole.Instance.Output("Asset deletion not supported by database");
117 }
118
119 void HandleDumpAsset(string module, string[] args)
120 {
121 if (args.Length < 3)
122 {
123 MainConsole.Instance.Output("Usage is dump asset <ID>");
124 return;
125 }
126
127 UUID assetId;
128 string rawAssetId = args[2];
129
130 if (!UUID.TryParse(rawAssetId, out assetId))
131 {
132 MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid ID format", rawAssetId);
133 return;
134 }
135
136 AssetBase asset = m_AssetService.Get(assetId.ToString());
137 if (asset == null)
138 {
139 MainConsole.Instance.OutputFormat("ERROR: No asset found with ID {0}", assetId);
140 return;
141 }
142
143 string fileName = rawAssetId;
144
145 using (FileStream fs = new FileStream(fileName, FileMode.CreateNew))
146 {
147 using (BinaryWriter bw = new BinaryWriter(fs))
148 {
149 bw.Write(asset.Data);
150 }
151 }
152
153 MainConsole.Instance.OutputFormat("Asset dumped to file {0}", fileName);
154 }
155
156 void HandleShowDigest(string module, string[] args)
157 {
158 if (args.Length < 3)
159 {
160 MainConsole.Instance.Output("Syntax: show digest <ID>");
161 return;
162 }
163
164 AssetBase asset = m_AssetService.Get(args[2]);
165
166 if (asset == null || asset.Data.Length == 0)
167 {
168 MainConsole.Instance.Output("Asset not found");
169 return;
170 }
171
172 int i;
173
174 MainConsole.Instance.OutputFormat("Name: {0}", asset.Name);
175 MainConsole.Instance.OutputFormat("Description: {0}", asset.Description);
176 MainConsole.Instance.OutputFormat("Type: {0} (type number = {1})", (AssetType)asset.Type, asset.Type);
177 MainConsole.Instance.OutputFormat("Content-type: {0}", asset.Metadata.ContentType);
178 MainConsole.Instance.OutputFormat("Flags: {0}", asset.Metadata.Flags);
179
180 for (i = 0 ; i < 5 ; i++)
181 {
182 int off = i * 16;
183 if (asset.Data.Length <= off)
184 break;
185 int len = 16;
186 if (asset.Data.Length < off + len)
187 len = asset.Data.Length - off;
188
189 byte[] line = new byte[len];
190 Array.Copy(asset.Data, off, line, 0, len);
191
192 string text = BitConverter.ToString(line);
193 MainConsole.Instance.Output(String.Format("{0:x4}: {1}", off, text));
194 }
70 } 195 }
71 } 196 }
72} 197} \ No newline at end of file