diff options
Diffstat (limited to 'OpenSim/Server')
-rw-r--r-- | OpenSim/Server/Base/HttpServerBase.cs | 2 | ||||
-rw-r--r-- | OpenSim/Server/Base/Properties/AssemblyInfo.cs | 33 | ||||
-rw-r--r-- | OpenSim/Server/Base/ServicesServerBase.cs | 175 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 20 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs | 47 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | 15 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs | 110 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Properties/AssemblyInfo.cs | 33 | ||||
-rw-r--r-- | OpenSim/Server/Properties/AssemblyInfo.cs | 33 |
9 files changed, 296 insertions, 172 deletions
diff --git a/OpenSim/Server/Base/HttpServerBase.cs b/OpenSim/Server/Base/HttpServerBase.cs index 29b1c00..954783c 100644 --- a/OpenSim/Server/Base/HttpServerBase.cs +++ b/OpenSim/Server/Base/HttpServerBase.cs | |||
@@ -52,7 +52,7 @@ namespace OpenSim.Server.Base | |||
52 | 52 | ||
53 | protected override void ReadConfig() | 53 | protected override void ReadConfig() |
54 | { | 54 | { |
55 | IConfig networkConfig = m_Config.Configs["Network"]; | 55 | IConfig networkConfig = Config.Configs["Network"]; |
56 | 56 | ||
57 | if (networkConfig == null) | 57 | if (networkConfig == null) |
58 | { | 58 | { |
diff --git a/OpenSim/Server/Base/Properties/AssemblyInfo.cs b/OpenSim/Server/Base/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4bbe358 --- /dev/null +++ b/OpenSim/Server/Base/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Server.Base")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("OpenSimulator developers")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("8fbd5035-0dbc-4b9a-ad1a-a7567f254ea9")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.7.5.*")] | ||
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index 2f12288..ecd69b0 100644 --- a/OpenSim/Server/Base/ServicesServerBase.cs +++ b/OpenSim/Server/Base/ServicesServerBase.cs | |||
@@ -34,6 +34,7 @@ using System.Text; | |||
34 | using System.Xml; | 34 | using System.Xml; |
35 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Framework.Console; | 36 | using OpenSim.Framework.Console; |
37 | using OpenSim.Framework.Servers; | ||
37 | using log4net; | 38 | using log4net; |
38 | using log4net.Config; | 39 | using log4net.Config; |
39 | using log4net.Appender; | 40 | using log4net.Appender; |
@@ -43,7 +44,7 @@ using Nini.Config; | |||
43 | 44 | ||
44 | namespace OpenSim.Server.Base | 45 | namespace OpenSim.Server.Base |
45 | { | 46 | { |
46 | public class ServicesServerBase | 47 | public class ServicesServerBase : ServerBase |
47 | { | 48 | { |
48 | // Logger | 49 | // Logger |
49 | // | 50 | // |
@@ -55,15 +56,6 @@ namespace OpenSim.Server.Base | |||
55 | // | 56 | // |
56 | protected string[] m_Arguments; | 57 | protected string[] m_Arguments; |
57 | 58 | ||
58 | // Configuration | ||
59 | // | ||
60 | protected IConfigSource m_Config = null; | ||
61 | |||
62 | public IConfigSource Config | ||
63 | { | ||
64 | get { return m_Config; } | ||
65 | } | ||
66 | |||
67 | public string ConfigDirectory | 59 | public string ConfigDirectory |
68 | { | 60 | { |
69 | get; | 61 | get; |
@@ -74,21 +66,10 @@ namespace OpenSim.Server.Base | |||
74 | // | 66 | // |
75 | private bool m_Running = true; | 67 | private bool m_Running = true; |
76 | 68 | ||
77 | // PID file | ||
78 | // | ||
79 | private string m_pidFile = String.Empty; | ||
80 | |||
81 | /// <summary> | ||
82 | /// Time at which this server was started | ||
83 | /// </summary> | ||
84 | protected DateTime m_startuptime; | ||
85 | |||
86 | // Handle all the automagical stuff | 69 | // Handle all the automagical stuff |
87 | // | 70 | // |
88 | public ServicesServerBase(string prompt, string[] args) | 71 | public ServicesServerBase(string prompt, string[] args) : base() |
89 | { | 72 | { |
90 | m_startuptime = DateTime.Now; | ||
91 | |||
92 | // Save raw arguments | 73 | // Save raw arguments |
93 | // | 74 | // |
94 | m_Arguments = args; | 75 | m_Arguments = args; |
@@ -134,11 +115,11 @@ namespace OpenSim.Server.Base | |||
134 | configUri.Scheme == Uri.UriSchemeHttp) | 115 | configUri.Scheme == Uri.UriSchemeHttp) |
135 | { | 116 | { |
136 | XmlReader r = XmlReader.Create(iniFile); | 117 | XmlReader r = XmlReader.Create(iniFile); |
137 | m_Config = new XmlConfigSource(r); | 118 | Config = new XmlConfigSource(r); |
138 | } | 119 | } |
139 | else | 120 | else |
140 | { | 121 | { |
141 | m_Config = new IniConfigSource(iniFile); | 122 | Config = new IniConfigSource(iniFile); |
142 | } | 123 | } |
143 | } | 124 | } |
144 | catch (Exception e) | 125 | catch (Exception e) |
@@ -150,13 +131,13 @@ namespace OpenSim.Server.Base | |||
150 | // Merge the configuration from the command line into the | 131 | // Merge the configuration from the command line into the |
151 | // loaded file | 132 | // loaded file |
152 | // | 133 | // |
153 | m_Config.Merge(argvConfig); | 134 | Config.Merge(argvConfig); |
154 | 135 | ||
155 | // Refresh the startupConfig post merge | 136 | // Refresh the startupConfig post merge |
156 | // | 137 | // |
157 | if (m_Config.Configs["Startup"] != null) | 138 | if (Config.Configs["Startup"] != null) |
158 | { | 139 | { |
159 | startupConfig = m_Config.Configs["Startup"]; | 140 | startupConfig = Config.Configs["Startup"]; |
160 | } | 141 | } |
161 | 142 | ||
162 | ConfigDirectory = startupConfig.GetString("ConfigDirectory", "."); | 143 | ConfigDirectory = startupConfig.GetString("ConfigDirectory", "."); |
@@ -188,6 +169,8 @@ namespace OpenSim.Server.Base | |||
188 | MainConsole.Instance = new LocalConsole(prompt); | 169 | MainConsole.Instance = new LocalConsole(prompt); |
189 | } | 170 | } |
190 | 171 | ||
172 | m_console = MainConsole.Instance; | ||
173 | |||
191 | // Configure the appenders for log4net | 174 | // Configure the appenders for log4net |
192 | // | 175 | // |
193 | OpenSimAppender consoleAppender = null; | 176 | OpenSimAppender consoleAppender = null; |
@@ -203,54 +186,15 @@ namespace OpenSim.Server.Base | |||
203 | XmlConfigurator.Configure(); | 186 | XmlConfigurator.Configure(); |
204 | } | 187 | } |
205 | 188 | ||
206 | ILoggerRepository repository = LogManager.GetRepository(); | 189 | RegisterCommonAppenders(startupConfig); |
207 | IAppender[] appenders = repository.GetAppenders(); | ||
208 | |||
209 | foreach (IAppender appender in appenders) | ||
210 | { | ||
211 | if (appender.Name == "Console") | ||
212 | { | ||
213 | consoleAppender = (OpenSimAppender)appender; | ||
214 | } | ||
215 | if (appender.Name == "LogFileAppender") | ||
216 | { | ||
217 | fileAppender = (FileAppender)appender; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | if (consoleAppender == null) | ||
222 | { | ||
223 | System.Console.WriteLine("No console appender found. Server can't start"); | ||
224 | Thread.CurrentThread.Abort(); | ||
225 | } | ||
226 | else | ||
227 | { | ||
228 | consoleAppender.Console = (ConsoleBase)MainConsole.Instance; | ||
229 | |||
230 | if (null == consoleAppender.Threshold) | ||
231 | consoleAppender.Threshold = Level.All; | ||
232 | } | ||
233 | |||
234 | // Set log file | ||
235 | // | ||
236 | if (fileAppender != null) | ||
237 | { | ||
238 | if (startupConfig != null) | ||
239 | { | ||
240 | string cfgFileName = startupConfig.GetString("logfile", null); | ||
241 | if (cfgFileName != null) | ||
242 | { | ||
243 | fileAppender.File = cfgFileName; | ||
244 | fileAppender.ActivateOptions(); | ||
245 | } | ||
246 | } | ||
247 | } | ||
248 | 190 | ||
249 | if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) | 191 | if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) |
250 | { | 192 | { |
251 | CreatePIDFile(startupConfig.GetString("PIDFile")); | 193 | CreatePIDFile(startupConfig.GetString("PIDFile")); |
252 | } | 194 | } |
253 | 195 | ||
196 | RegisterCommonCommands(); | ||
197 | |||
254 | // Register the quit command | 198 | // Register the quit command |
255 | // | 199 | // |
256 | MainConsole.Instance.Commands.AddCommand("General", false, "quit", | 200 | MainConsole.Instance.Commands.AddCommand("General", false, "quit", |
@@ -260,16 +204,6 @@ namespace OpenSim.Server.Base | |||
260 | MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", | 204 | MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", |
261 | "shutdown", | 205 | "shutdown", |
262 | "Quit the application", HandleQuit); | 206 | "Quit the application", HandleQuit); |
263 | |||
264 | // Register a command to read other commands from a file | ||
265 | MainConsole.Instance.Commands.AddCommand("General", false, "command-script", | ||
266 | "command-script <script>", | ||
267 | "Run a command script from file", HandleScript); | ||
268 | |||
269 | MainConsole.Instance.Commands.AddCommand("General", false, "show uptime", | ||
270 | "show uptime", | ||
271 | "Show server uptime", HandleShow); | ||
272 | |||
273 | 207 | ||
274 | // Allow derived classes to perform initialization that | 208 | // Allow derived classes to perform initialization that |
275 | // needs to be done after the console has opened | 209 | // needs to be done after the console has opened |
@@ -296,8 +230,8 @@ namespace OpenSim.Server.Base | |||
296 | } | 230 | } |
297 | } | 231 | } |
298 | 232 | ||
299 | if (m_pidFile != String.Empty) | 233 | RemovePIDFile(); |
300 | File.Delete(m_pidFile); | 234 | |
301 | return 0; | 235 | return 0; |
302 | } | 236 | } |
303 | 237 | ||
@@ -305,43 +239,9 @@ namespace OpenSim.Server.Base | |||
305 | { | 239 | { |
306 | m_Running = false; | 240 | m_Running = false; |
307 | m_log.Info("[CONSOLE] Quitting"); | 241 | m_log.Info("[CONSOLE] Quitting"); |
308 | } | ||
309 | 242 | ||
310 | protected virtual void HandleScript(string module, string[] parms) | ||
311 | { | ||
312 | if (parms.Length != 2) | ||
313 | { | ||
314 | return; | ||
315 | } | ||
316 | RunCommandScript(parms[1]); | ||
317 | } | 243 | } |
318 | 244 | ||
319 | /// <summary> | ||
320 | /// Run an optional startup list of commands | ||
321 | /// </summary> | ||
322 | /// <param name="fileName"></param> | ||
323 | private void RunCommandScript(string fileName) | ||
324 | { | ||
325 | if (File.Exists(fileName)) | ||
326 | { | ||
327 | m_log.Info("[COMMANDFILE]: Running " + fileName); | ||
328 | |||
329 | using (StreamReader readFile = File.OpenText(fileName)) | ||
330 | { | ||
331 | string currentCommand; | ||
332 | while ((currentCommand = readFile.ReadLine()) != null) | ||
333 | { | ||
334 | if (currentCommand != String.Empty) | ||
335 | { | ||
336 | m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'"); | ||
337 | MainConsole.Instance.RunCommand(currentCommand); | ||
338 | } | ||
339 | } | ||
340 | } | ||
341 | } | ||
342 | } | ||
343 | |||
344 | |||
345 | protected virtual void ReadConfig() | 245 | protected virtual void ReadConfig() |
346 | { | 246 | { |
347 | } | 247 | } |
@@ -349,50 +249,5 @@ namespace OpenSim.Server.Base | |||
349 | protected virtual void Initialise() | 249 | protected virtual void Initialise() |
350 | { | 250 | { |
351 | } | 251 | } |
352 | |||
353 | protected void CreatePIDFile(string path) | ||
354 | { | ||
355 | try | ||
356 | { | ||
357 | string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); | ||
358 | FileStream fs = File.Create(path); | ||
359 | Byte[] buf = Encoding.ASCII.GetBytes(pidstring); | ||
360 | fs.Write(buf, 0, buf.Length); | ||
361 | fs.Close(); | ||
362 | m_pidFile = path; | ||
363 | } | ||
364 | catch (Exception) | ||
365 | { | ||
366 | } | ||
367 | } | ||
368 | |||
369 | public virtual void HandleShow(string module, string[] cmd) | ||
370 | { | ||
371 | List<string> args = new List<string>(cmd); | ||
372 | |||
373 | args.RemoveAt(0); | ||
374 | |||
375 | string[] showParams = args.ToArray(); | ||
376 | |||
377 | switch (showParams[0]) | ||
378 | { | ||
379 | case "uptime": | ||
380 | MainConsole.Instance.Output(GetUptimeReport()); | ||
381 | break; | ||
382 | } | ||
383 | } | ||
384 | |||
385 | /// <summary> | ||
386 | /// Return a report about the uptime of this server | ||
387 | /// </summary> | ||
388 | /// <returns></returns> | ||
389 | protected string GetUptimeReport() | ||
390 | { | ||
391 | StringBuilder sb = new StringBuilder(String.Format("Time now is {0}\n", DateTime.Now)); | ||
392 | sb.Append(String.Format("Server has been running since {0}, {1}\n", m_startuptime.DayOfWeek, m_startuptime)); | ||
393 | sb.Append(String.Format("That is an elapsed time of {0}\n", DateTime.Now - m_startuptime)); | ||
394 | |||
395 | return sb.ToString(); | ||
396 | } | ||
397 | } | 252 | } |
398 | } | 253 | } |
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 46b0c67..ff45d94 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | |||
@@ -67,10 +67,25 @@ namespace OpenSim.Server.Handlers.Asset | |||
67 | throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); | 67 | throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); |
68 | 68 | ||
69 | bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); | 69 | bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); |
70 | bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false); | ||
71 | |||
72 | AllowedRemoteDeleteTypes allowedRemoteDeleteTypes; | ||
73 | |||
74 | if (!allowDelete) | ||
75 | { | ||
76 | allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.None; | ||
77 | } | ||
78 | else | ||
79 | { | ||
80 | if (allowDeleteAllTypes) | ||
81 | allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.All; | ||
82 | else | ||
83 | allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.MapTile; | ||
84 | } | ||
70 | 85 | ||
71 | server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); | 86 | server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); |
72 | server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); | 87 | server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); |
73 | server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete)); | 88 | server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes)); |
74 | 89 | ||
75 | MainConsole.Instance.Commands.AddCommand("Assets", false, | 90 | MainConsole.Instance.Commands.AddCommand("Assets", false, |
76 | "show asset", | 91 | "show asset", |
@@ -141,6 +156,9 @@ namespace OpenSim.Server.Handlers.Asset | |||
141 | } | 156 | } |
142 | 157 | ||
143 | string fileName = rawAssetId; | 158 | string fileName = rawAssetId; |
159 | |||
160 | if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, fileName)) | ||
161 | return; | ||
144 | 162 | ||
145 | using (FileStream fs = new FileStream(fileName, FileMode.CreateNew)) | 163 | using (FileStream fs = new FileStream(fileName, FileMode.CreateNew)) |
146 | { | 164 | { |
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index 0cfe5b1..986394b 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs | |||
@@ -42,18 +42,32 @@ using OpenSim.Framework.Servers.HttpServer; | |||
42 | 42 | ||
43 | namespace OpenSim.Server.Handlers.Asset | 43 | namespace OpenSim.Server.Handlers.Asset |
44 | { | 44 | { |
45 | /// <summary> | ||
46 | /// Remote deletes allowed. | ||
47 | /// </summary> | ||
48 | public enum AllowedRemoteDeleteTypes | ||
49 | { | ||
50 | None, | ||
51 | MapTile, | ||
52 | All | ||
53 | } | ||
54 | |||
45 | public class AssetServerDeleteHandler : BaseStreamHandler | 55 | public class AssetServerDeleteHandler : BaseStreamHandler |
46 | { | 56 | { |
47 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 57 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | 58 | ||
49 | private IAssetService m_AssetService; | 59 | private IAssetService m_AssetService; |
50 | protected bool m_allowDelete; | ||
51 | 60 | ||
52 | public AssetServerDeleteHandler(IAssetService service, bool allowDelete) : | 61 | /// <summary> |
62 | /// Asset types that can be deleted remotely. | ||
63 | /// </summary> | ||
64 | private AllowedRemoteDeleteTypes m_allowedTypes; | ||
65 | |||
66 | public AssetServerDeleteHandler(IAssetService service, AllowedRemoteDeleteTypes allowedTypes) : | ||
53 | base("DELETE", "/assets") | 67 | base("DELETE", "/assets") |
54 | { | 68 | { |
55 | m_AssetService = service; | 69 | m_AssetService = service; |
56 | m_allowDelete = allowDelete; | 70 | m_allowedTypes = allowedTypes; |
57 | } | 71 | } |
58 | 72 | ||
59 | public override byte[] Handle(string path, Stream request, | 73 | public override byte[] Handle(string path, Stream request, |
@@ -63,13 +77,32 @@ namespace OpenSim.Server.Handlers.Asset | |||
63 | 77 | ||
64 | string[] p = SplitParams(path); | 78 | string[] p = SplitParams(path); |
65 | 79 | ||
66 | if (p.Length > 0 && m_allowDelete) | 80 | if (p.Length > 0) |
67 | { | 81 | { |
68 | result = m_AssetService.Delete(p[0]); | 82 | if (m_allowedTypes != AllowedRemoteDeleteTypes.None) |
83 | { | ||
84 | string assetID = p[0]; | ||
85 | |||
86 | AssetBase asset = m_AssetService.Get(assetID); | ||
87 | if (asset != null) | ||
88 | { | ||
89 | if (m_allowedTypes == AllowedRemoteDeleteTypes.All | ||
90 | || (int)(asset.Flags & AssetFlags.Maptile) != 0) | ||
91 | { | ||
92 | result = m_AssetService.Delete(assetID); | ||
93 | } | ||
94 | else | ||
95 | { | ||
96 | m_log.DebugFormat( | ||
97 | "[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but type is {1} and allowed remote delete types are {2}", | ||
98 | assetID, (AssetFlags)asset.Flags, m_allowedTypes); | ||
99 | } | ||
100 | } | ||
101 | } | ||
69 | } | 102 | } |
70 | 103 | ||
71 | XmlSerializer xs = new XmlSerializer(typeof(bool)); | 104 | XmlSerializer xs = new XmlSerializer(typeof(bool)); |
72 | return ServerUtils.SerializeResult(xs, result); | 105 | return ServerUtils.SerializeResult(xs, result); |
73 | } | 106 | } |
74 | } | 107 | } |
75 | } | 108 | } \ No newline at end of file |
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs index 87b3d2d..a006fa8 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | |||
@@ -57,14 +57,23 @@ namespace OpenSim.Server.Handlers.Asset | |||
57 | public override byte[] Handle(string path, Stream request, | 57 | public override byte[] Handle(string path, Stream request, |
58 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 58 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
59 | { | 59 | { |
60 | AssetBase asset; | ||
60 | XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); | 61 | XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); |
61 | AssetBase asset = (AssetBase) xs.Deserialize(request); | 62 | |
63 | try | ||
64 | { | ||
65 | asset = (AssetBase)xs.Deserialize(request); | ||
66 | } | ||
67 | catch (XmlException) | ||
68 | { | ||
69 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
70 | return null; | ||
71 | } | ||
62 | 72 | ||
63 | string[] p = SplitParams(path); | 73 | string[] p = SplitParams(path); |
64 | if (p.Length > 1) | 74 | if (p.Length > 1) |
65 | { | 75 | { |
66 | bool result = | 76 | bool result = m_AssetService.UpdateContent(p[1], asset.Data); |
67 | m_AssetService.UpdateContent(p[1], asset.Data); | ||
68 | 77 | ||
69 | xs = new XmlSerializer(typeof(bool)); | 78 | xs = new XmlSerializer(typeof(bool)); |
70 | return ServerUtils.SerializeResult(xs, result); | 79 | return ServerUtils.SerializeResult(xs, result); |
diff --git a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs new file mode 100644 index 0000000..427fa16 --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs | |||
@@ -0,0 +1,110 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Net; | ||
31 | using System.Text; | ||
32 | using System.Xml; | ||
33 | using System.Xml.Serialization; | ||
34 | using Nini.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Server.Handlers.Asset; | ||
39 | using OpenSim.Services.AssetService; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Tests.Common; | ||
42 | using OpenSim.Tests.Common.Mock; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers.Asset.Test | ||
45 | { | ||
46 | [TestFixture] | ||
47 | public class AssetServerPostHandlerTests : OpenSimTestCase | ||
48 | { | ||
49 | [Test] | ||
50 | public void TestGoodAssetStoreRequest() | ||
51 | { | ||
52 | TestHelpers.InMethod(); | ||
53 | |||
54 | UUID assetId = TestHelpers.ParseTail(0x1); | ||
55 | |||
56 | IConfigSource config = new IniConfigSource(); | ||
57 | config.AddConfig("AssetService"); | ||
58 | config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
59 | |||
60 | AssetService assetService = new AssetService(config); | ||
61 | |||
62 | AssetServerPostHandler asph = new AssetServerPostHandler(assetService); | ||
63 | |||
64 | AssetBase asset = AssetHelpers.CreateNotecardAsset(assetId, "Hello World"); | ||
65 | |||
66 | MemoryStream buffer = new MemoryStream(); | ||
67 | |||
68 | XmlWriterSettings settings = new XmlWriterSettings(); | ||
69 | settings.Encoding = Encoding.UTF8; | ||
70 | |||
71 | using (XmlWriter writer = XmlWriter.Create(buffer, settings)) | ||
72 | { | ||
73 | XmlSerializer serializer = new XmlSerializer(typeof(AssetBase)); | ||
74 | serializer.Serialize(writer, asset); | ||
75 | writer.Flush(); | ||
76 | } | ||
77 | |||
78 | buffer.Position = 0; | ||
79 | asph.Handle(null, buffer, null, null); | ||
80 | |||
81 | AssetBase retrievedAsset = assetService.Get(assetId.ToString()); | ||
82 | |||
83 | Assert.That(retrievedAsset, Is.Not.Null); | ||
84 | } | ||
85 | |||
86 | [Test] | ||
87 | public void TestBadXmlAssetStoreRequest() | ||
88 | { | ||
89 | TestHelpers.InMethod(); | ||
90 | |||
91 | IConfigSource config = new IniConfigSource(); | ||
92 | config.AddConfig("AssetService"); | ||
93 | config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
94 | |||
95 | AssetService assetService = new AssetService(config); | ||
96 | |||
97 | AssetServerPostHandler asph = new AssetServerPostHandler(assetService); | ||
98 | |||
99 | MemoryStream buffer = new MemoryStream(); | ||
100 | byte[] badData = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f }; | ||
101 | buffer.Write(badData, 0, badData.Length); | ||
102 | buffer.Position = 0; | ||
103 | |||
104 | TestOSHttpResponse response = new TestOSHttpResponse(); | ||
105 | asph.Handle(null, buffer, null, response); | ||
106 | |||
107 | Assert.That(response.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest)); | ||
108 | } | ||
109 | } | ||
110 | } \ No newline at end of file | ||
diff --git a/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs b/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..53e9737 --- /dev/null +++ b/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Server.Handlers")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("OpenSimulator developers")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("6319afca-d740-4468-a95d-d7f87a081cb3")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.7.5.*")] | ||
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||
diff --git a/OpenSim/Server/Properties/AssemblyInfo.cs b/OpenSim/Server/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ebc10fb --- /dev/null +++ b/OpenSim/Server/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("Robust")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("OpenSimulator developers")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("d347c5cb-baf8-4566-a221-35d948e1776f")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.7.5.*")] | ||
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||