diff options
author | Diva Canto | 2012-11-27 14:43:01 -0800 |
---|---|---|
committer | Diva Canto | 2012-11-27 14:43:01 -0800 |
commit | a82f699f4348ea1ab139ab338973c9cee04df712 (patch) | |
tree | d1bf4948670e1d207fe4f6c60f6b7771e1625839 /OpenSim/Server | |
parent | Prevent the core Groups module from being enabled when its name doesn't match... (diff) | |
parent | BulletSim: reorganize linear movement routine into separate subroutines enabl... (diff) | |
download | opensim-SC_OLD-a82f699f4348ea1ab139ab338973c9cee04df712.zip opensim-SC_OLD-a82f699f4348ea1ab139ab338973c9cee04df712.tar.gz opensim-SC_OLD-a82f699f4348ea1ab139ab338973c9cee04df712.tar.bz2 opensim-SC_OLD-a82f699f4348ea1ab139ab338973c9cee04df712.tar.xz |
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Server')
-rw-r--r-- | OpenSim/Server/Base/HttpServerBase.cs | 2 | ||||
-rw-r--r-- | OpenSim/Server/Base/ServicesServerBase.cs | 177 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | 15 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs | 110 |
4 files changed, 139 insertions, 165 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/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index 0cff6ed..5b23149 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,34 +56,14 @@ 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 | // Run flag | 59 | // Run flag |
68 | // | 60 | // |
69 | private bool m_Running = true; | 61 | private bool m_Running = true; |
70 | 62 | ||
71 | // PID file | ||
72 | // | ||
73 | private string m_pidFile = String.Empty; | ||
74 | |||
75 | /// <summary> | ||
76 | /// Time at which this server was started | ||
77 | /// </summary> | ||
78 | protected DateTime m_startuptime; | ||
79 | |||
80 | // Handle all the automagical stuff | 63 | // Handle all the automagical stuff |
81 | // | 64 | // |
82 | public ServicesServerBase(string prompt, string[] args) | 65 | public ServicesServerBase(string prompt, string[] args) : base() |
83 | { | 66 | { |
84 | m_startuptime = DateTime.Now; | ||
85 | |||
86 | // Save raw arguments | 67 | // Save raw arguments |
87 | // | 68 | // |
88 | m_Arguments = args; | 69 | m_Arguments = args; |
@@ -128,11 +109,11 @@ namespace OpenSim.Server.Base | |||
128 | configUri.Scheme == Uri.UriSchemeHttp) | 109 | configUri.Scheme == Uri.UriSchemeHttp) |
129 | { | 110 | { |
130 | XmlReader r = XmlReader.Create(iniFile); | 111 | XmlReader r = XmlReader.Create(iniFile); |
131 | m_Config = new XmlConfigSource(r); | 112 | Config = new XmlConfigSource(r); |
132 | } | 113 | } |
133 | else | 114 | else |
134 | { | 115 | { |
135 | m_Config = new IniConfigSource(iniFile); | 116 | Config = new IniConfigSource(iniFile); |
136 | } | 117 | } |
137 | } | 118 | } |
138 | catch (Exception e) | 119 | catch (Exception e) |
@@ -144,13 +125,13 @@ namespace OpenSim.Server.Base | |||
144 | // Merge the configuration from the command line into the | 125 | // Merge the configuration from the command line into the |
145 | // loaded file | 126 | // loaded file |
146 | // | 127 | // |
147 | m_Config.Merge(argvConfig); | 128 | Config.Merge(argvConfig); |
148 | 129 | ||
149 | // Refresh the startupConfig post merge | 130 | // Refresh the startupConfig post merge |
150 | // | 131 | // |
151 | if (m_Config.Configs["Startup"] != null) | 132 | if (Config.Configs["Startup"] != null) |
152 | { | 133 | { |
153 | startupConfig = m_Config.Configs["Startup"]; | 134 | startupConfig = Config.Configs["Startup"]; |
154 | } | 135 | } |
155 | 136 | ||
156 | prompt = startupConfig.GetString("Prompt", prompt); | 137 | prompt = startupConfig.GetString("Prompt", prompt); |
@@ -180,6 +161,8 @@ namespace OpenSim.Server.Base | |||
180 | MainConsole.Instance = new LocalConsole(prompt); | 161 | MainConsole.Instance = new LocalConsole(prompt); |
181 | } | 162 | } |
182 | 163 | ||
164 | m_console = MainConsole.Instance; | ||
165 | |||
183 | // Configure the appenders for log4net | 166 | // Configure the appenders for log4net |
184 | // | 167 | // |
185 | OpenSimAppender consoleAppender = null; | 168 | OpenSimAppender consoleAppender = null; |
@@ -195,54 +178,15 @@ namespace OpenSim.Server.Base | |||
195 | XmlConfigurator.Configure(); | 178 | XmlConfigurator.Configure(); |
196 | } | 179 | } |
197 | 180 | ||
198 | ILoggerRepository repository = LogManager.GetRepository(); | 181 | RegisterCommonAppenders(startupConfig); |
199 | IAppender[] appenders = repository.GetAppenders(); | ||
200 | |||
201 | foreach (IAppender appender in appenders) | ||
202 | { | ||
203 | if (appender.Name == "Console") | ||
204 | { | ||
205 | consoleAppender = (OpenSimAppender)appender; | ||
206 | } | ||
207 | if (appender.Name == "LogFileAppender") | ||
208 | { | ||
209 | fileAppender = (FileAppender)appender; | ||
210 | } | ||
211 | } | ||
212 | |||
213 | if (consoleAppender == null) | ||
214 | { | ||
215 | System.Console.WriteLine("No console appender found. Server can't start"); | ||
216 | Thread.CurrentThread.Abort(); | ||
217 | } | ||
218 | else | ||
219 | { | ||
220 | consoleAppender.Console = (ConsoleBase)MainConsole.Instance; | ||
221 | |||
222 | if (null == consoleAppender.Threshold) | ||
223 | consoleAppender.Threshold = Level.All; | ||
224 | } | ||
225 | |||
226 | // Set log file | ||
227 | // | ||
228 | if (fileAppender != null) | ||
229 | { | ||
230 | if (startupConfig != null) | ||
231 | { | ||
232 | string cfgFileName = startupConfig.GetString("logfile", null); | ||
233 | if (cfgFileName != null) | ||
234 | { | ||
235 | fileAppender.File = cfgFileName; | ||
236 | fileAppender.ActivateOptions(); | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | 182 | ||
241 | if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) | 183 | if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) |
242 | { | 184 | { |
243 | CreatePIDFile(startupConfig.GetString("PIDFile")); | 185 | CreatePIDFile(startupConfig.GetString("PIDFile")); |
244 | } | 186 | } |
245 | 187 | ||
188 | RegisterCommonCommands(); | ||
189 | |||
246 | // Register the quit command | 190 | // Register the quit command |
247 | // | 191 | // |
248 | MainConsole.Instance.Commands.AddCommand("General", false, "quit", | 192 | MainConsole.Instance.Commands.AddCommand("General", false, "quit", |
@@ -252,16 +196,6 @@ namespace OpenSim.Server.Base | |||
252 | MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", | 196 | MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", |
253 | "shutdown", | 197 | "shutdown", |
254 | "Quit the application", HandleQuit); | 198 | "Quit the application", HandleQuit); |
255 | |||
256 | // Register a command to read other commands from a file | ||
257 | MainConsole.Instance.Commands.AddCommand("General", false, "command-script", | ||
258 | "command-script <script>", | ||
259 | "Run a command script from file", HandleScript); | ||
260 | |||
261 | MainConsole.Instance.Commands.AddCommand("General", false, "show uptime", | ||
262 | "show uptime", | ||
263 | "Show server uptime", HandleShow); | ||
264 | |||
265 | 199 | ||
266 | // Allow derived classes to perform initialization that | 200 | // Allow derived classes to perform initialization that |
267 | // needs to be done after the console has opened | 201 | // needs to be done after the console has opened |
@@ -288,8 +222,8 @@ namespace OpenSim.Server.Base | |||
288 | } | 222 | } |
289 | } | 223 | } |
290 | 224 | ||
291 | if (m_pidFile != String.Empty) | 225 | RemovePIDFile(); |
292 | File.Delete(m_pidFile); | 226 | |
293 | return 0; | 227 | return 0; |
294 | } | 228 | } |
295 | 229 | ||
@@ -297,43 +231,9 @@ namespace OpenSim.Server.Base | |||
297 | { | 231 | { |
298 | m_Running = false; | 232 | m_Running = false; |
299 | m_log.Info("[CONSOLE] Quitting"); | 233 | m_log.Info("[CONSOLE] Quitting"); |
300 | } | ||
301 | 234 | ||
302 | protected virtual void HandleScript(string module, string[] parms) | ||
303 | { | ||
304 | if (parms.Length != 2) | ||
305 | { | ||
306 | return; | ||
307 | } | ||
308 | RunCommandScript(parms[1]); | ||
309 | } | 235 | } |
310 | 236 | ||
311 | /// <summary> | ||
312 | /// Run an optional startup list of commands | ||
313 | /// </summary> | ||
314 | /// <param name="fileName"></param> | ||
315 | private void RunCommandScript(string fileName) | ||
316 | { | ||
317 | if (File.Exists(fileName)) | ||
318 | { | ||
319 | m_log.Info("[COMMANDFILE]: Running " + fileName); | ||
320 | |||
321 | using (StreamReader readFile = File.OpenText(fileName)) | ||
322 | { | ||
323 | string currentCommand; | ||
324 | while ((currentCommand = readFile.ReadLine()) != null) | ||
325 | { | ||
326 | if (currentCommand != String.Empty) | ||
327 | { | ||
328 | m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'"); | ||
329 | MainConsole.Instance.RunCommand(currentCommand); | ||
330 | } | ||
331 | } | ||
332 | } | ||
333 | } | ||
334 | } | ||
335 | |||
336 | |||
337 | protected virtual void ReadConfig() | 237 | protected virtual void ReadConfig() |
338 | { | 238 | { |
339 | } | 239 | } |
@@ -341,50 +241,5 @@ namespace OpenSim.Server.Base | |||
341 | protected virtual void Initialise() | 241 | protected virtual void Initialise() |
342 | { | 242 | { |
343 | } | 243 | } |
344 | |||
345 | protected void CreatePIDFile(string path) | ||
346 | { | ||
347 | try | ||
348 | { | ||
349 | string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); | ||
350 | FileStream fs = File.Create(path); | ||
351 | Byte[] buf = Encoding.ASCII.GetBytes(pidstring); | ||
352 | fs.Write(buf, 0, buf.Length); | ||
353 | fs.Close(); | ||
354 | m_pidFile = path; | ||
355 | } | ||
356 | catch (Exception) | ||
357 | { | ||
358 | } | ||
359 | } | ||
360 | |||
361 | public virtual void HandleShow(string module, string[] cmd) | ||
362 | { | ||
363 | List<string> args = new List<string>(cmd); | ||
364 | |||
365 | args.RemoveAt(0); | ||
366 | |||
367 | string[] showParams = args.ToArray(); | ||
368 | |||
369 | switch (showParams[0]) | ||
370 | { | ||
371 | case "uptime": | ||
372 | MainConsole.Instance.Output(GetUptimeReport()); | ||
373 | break; | ||
374 | } | ||
375 | } | ||
376 | |||
377 | /// <summary> | ||
378 | /// Return a report about the uptime of this server | ||
379 | /// </summary> | ||
380 | /// <returns></returns> | ||
381 | protected string GetUptimeReport() | ||
382 | { | ||
383 | StringBuilder sb = new StringBuilder(String.Format("Time now is {0}\n", DateTime.Now)); | ||
384 | sb.Append(String.Format("Server has been running since {0}, {1}\n", m_startuptime.DayOfWeek, m_startuptime)); | ||
385 | sb.Append(String.Format("That is an elapsed time of {0}\n", DateTime.Now - m_startuptime)); | ||
386 | |||
387 | return sb.ToString(); | ||
388 | } | ||
389 | } | 244 | } |
390 | } | 245 | } \ 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 | ||