Merge branch 'master' into connector_plugin

Conflicts:
	OpenSim/Server/Base/ServicesServerBase.cs
This commit is contained in:
BlueWall
2012-11-25 17:03:14 -05:00
453 changed files with 13672 additions and 8935 deletions

View File

@@ -52,7 +52,7 @@ namespace OpenSim.Server.Base
protected override void ReadConfig()
{
IConfig networkConfig = m_Config.Configs["Network"];
IConfig networkConfig = Config.Configs["Network"];
if (networkConfig == null)
{

View File

@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OpenSim.Server.Base")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("http://opensimulator.org")]
[assembly: AssemblyProduct("OpenSim")]
[assembly: AssemblyCopyright("OpenSimulator developers")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8fbd5035-0dbc-4b9a-ad1a-a7567f254ea9")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.7.5.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -34,6 +34,7 @@ using System.Text;
using System.Xml;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Framework.Servers;
using log4net;
using log4net.Config;
using log4net.Appender;
@@ -43,7 +44,7 @@ using Nini.Config;
namespace OpenSim.Server.Base
{
public class ServicesServerBase
public class ServicesServerBase : ServerBase
{
// Logger
//
@@ -55,15 +56,6 @@ namespace OpenSim.Server.Base
//
protected string[] m_Arguments;
// Configuration
//
protected IConfigSource m_Config = null;
public IConfigSource Config
{
get { return m_Config; }
}
public string ConfigDirectory
{
get;
@@ -74,21 +66,10 @@ namespace OpenSim.Server.Base
//
private bool m_Running = true;
// PID file
//
private string m_pidFile = String.Empty;
/// <summary>
/// Time at which this server was started
/// </summary>
protected DateTime m_startuptime;
// Handle all the automagical stuff
//
public ServicesServerBase(string prompt, string[] args)
public ServicesServerBase(string prompt, string[] args) : base()
{
m_startuptime = DateTime.Now;
// Save raw arguments
//
m_Arguments = args;
@@ -134,11 +115,11 @@ namespace OpenSim.Server.Base
configUri.Scheme == Uri.UriSchemeHttp)
{
XmlReader r = XmlReader.Create(iniFile);
m_Config = new XmlConfigSource(r);
Config = new XmlConfigSource(r);
}
else
{
m_Config = new IniConfigSource(iniFile);
Config = new IniConfigSource(iniFile);
}
}
catch (Exception e)
@@ -150,13 +131,13 @@ namespace OpenSim.Server.Base
// Merge the configuration from the command line into the
// loaded file
//
m_Config.Merge(argvConfig);
Config.Merge(argvConfig);
// Refresh the startupConfig post merge
//
if (m_Config.Configs["Startup"] != null)
if (Config.Configs["Startup"] != null)
{
startupConfig = m_Config.Configs["Startup"];
startupConfig = Config.Configs["Startup"];
}
ConfigDirectory = startupConfig.GetString("ConfigDirectory", ".");
@@ -188,6 +169,8 @@ namespace OpenSim.Server.Base
MainConsole.Instance = new LocalConsole(prompt);
}
m_console = MainConsole.Instance;
// Configure the appenders for log4net
//
OpenSimAppender consoleAppender = null;
@@ -203,54 +186,15 @@ namespace OpenSim.Server.Base
XmlConfigurator.Configure();
}
ILoggerRepository repository = LogManager.GetRepository();
IAppender[] appenders = repository.GetAppenders();
foreach (IAppender appender in appenders)
{
if (appender.Name == "Console")
{
consoleAppender = (OpenSimAppender)appender;
}
if (appender.Name == "LogFileAppender")
{
fileAppender = (FileAppender)appender;
}
}
if (consoleAppender == null)
{
System.Console.WriteLine("No console appender found. Server can't start");
Thread.CurrentThread.Abort();
}
else
{
consoleAppender.Console = (ConsoleBase)MainConsole.Instance;
if (null == consoleAppender.Threshold)
consoleAppender.Threshold = Level.All;
}
// Set log file
//
if (fileAppender != null)
{
if (startupConfig != null)
{
string cfgFileName = startupConfig.GetString("logfile", null);
if (cfgFileName != null)
{
fileAppender.File = cfgFileName;
fileAppender.ActivateOptions();
}
}
}
RegisterCommonAppenders(startupConfig);
if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty)
{
CreatePIDFile(startupConfig.GetString("PIDFile"));
}
RegisterCommonCommands();
// Register the quit command
//
MainConsole.Instance.Commands.AddCommand("General", false, "quit",
@@ -260,16 +204,6 @@ namespace OpenSim.Server.Base
MainConsole.Instance.Commands.AddCommand("General", false, "shutdown",
"shutdown",
"Quit the application", HandleQuit);
// Register a command to read other commands from a file
MainConsole.Instance.Commands.AddCommand("General", false, "command-script",
"command-script <script>",
"Run a command script from file", HandleScript);
MainConsole.Instance.Commands.AddCommand("General", false, "show uptime",
"show uptime",
"Show server uptime", HandleShow);
// Allow derived classes to perform initialization that
// needs to be done after the console has opened
@@ -296,8 +230,8 @@ namespace OpenSim.Server.Base
}
}
if (m_pidFile != String.Empty)
File.Delete(m_pidFile);
RemovePIDFile();
return 0;
}
@@ -305,43 +239,9 @@ namespace OpenSim.Server.Base
{
m_Running = false;
m_log.Info("[CONSOLE] Quitting");
}
protected virtual void HandleScript(string module, string[] parms)
{
if (parms.Length != 2)
{
return;
}
RunCommandScript(parms[1]);
}
/// <summary>
/// Run an optional startup list of commands
/// </summary>
/// <param name="fileName"></param>
private void RunCommandScript(string fileName)
{
if (File.Exists(fileName))
{
m_log.Info("[COMMANDFILE]: Running " + fileName);
using (StreamReader readFile = File.OpenText(fileName))
{
string currentCommand;
while ((currentCommand = readFile.ReadLine()) != null)
{
if (currentCommand != String.Empty)
{
m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
MainConsole.Instance.RunCommand(currentCommand);
}
}
}
}
}
protected virtual void ReadConfig()
{
}
@@ -349,50 +249,5 @@ namespace OpenSim.Server.Base
protected virtual void Initialise()
{
}
protected void CreatePIDFile(string path)
{
try
{
string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
FileStream fs = File.Create(path);
Byte[] buf = Encoding.ASCII.GetBytes(pidstring);
fs.Write(buf, 0, buf.Length);
fs.Close();
m_pidFile = path;
}
catch (Exception)
{
}
}
public virtual void HandleShow(string module, string[] cmd)
{
List<string> args = new List<string>(cmd);
args.RemoveAt(0);
string[] showParams = args.ToArray();
switch (showParams[0])
{
case "uptime":
MainConsole.Instance.Output(GetUptimeReport());
break;
}
}
/// <summary>
/// Return a report about the uptime of this server
/// </summary>
/// <returns></returns>
protected string GetUptimeReport()
{
StringBuilder sb = new StringBuilder(String.Format("Time now is {0}\n", DateTime.Now));
sb.Append(String.Format("Server has been running since {0}, {1}\n", m_startuptime.DayOfWeek, m_startuptime));
sb.Append(String.Format("That is an elapsed time of {0}\n", DateTime.Now - m_startuptime));
return sb.ToString();
}
}
}

View File

@@ -67,10 +67,25 @@ namespace OpenSim.Server.Handlers.Asset
throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName));
bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false);
bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false);
AllowedRemoteDeleteTypes allowedRemoteDeleteTypes;
if (!allowDelete)
{
allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.None;
}
else
{
if (allowDeleteAllTypes)
allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.All;
else
allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.MapTile;
}
server.AddStreamHandler(new AssetServerGetHandler(m_AssetService));
server.AddStreamHandler(new AssetServerPostHandler(m_AssetService));
server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete));
server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes));
MainConsole.Instance.Commands.AddCommand("Assets", false,
"show asset",
@@ -141,6 +156,9 @@ namespace OpenSim.Server.Handlers.Asset
}
string fileName = rawAssetId;
if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, fileName))
return;
using (FileStream fs = new FileStream(fileName, FileMode.CreateNew))
{

View File

@@ -42,18 +42,32 @@ using OpenSim.Framework.Servers.HttpServer;
namespace OpenSim.Server.Handlers.Asset
{
/// <summary>
/// Remote deletes allowed.
/// </summary>
public enum AllowedRemoteDeleteTypes
{
None,
MapTile,
All
}
public class AssetServerDeleteHandler : BaseStreamHandler
{
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IAssetService m_AssetService;
protected bool m_allowDelete;
public AssetServerDeleteHandler(IAssetService service, bool allowDelete) :
/// <summary>
/// Asset types that can be deleted remotely.
/// </summary>
private AllowedRemoteDeleteTypes m_allowedTypes;
public AssetServerDeleteHandler(IAssetService service, AllowedRemoteDeleteTypes allowedTypes) :
base("DELETE", "/assets")
{
m_AssetService = service;
m_allowDelete = allowDelete;
m_allowedTypes = allowedTypes;
}
public override byte[] Handle(string path, Stream request,
@@ -63,13 +77,32 @@ namespace OpenSim.Server.Handlers.Asset
string[] p = SplitParams(path);
if (p.Length > 0 && m_allowDelete)
if (p.Length > 0)
{
result = m_AssetService.Delete(p[0]);
if (m_allowedTypes != AllowedRemoteDeleteTypes.None)
{
string assetID = p[0];
AssetBase asset = m_AssetService.Get(assetID);
if (asset != null)
{
if (m_allowedTypes == AllowedRemoteDeleteTypes.All
|| (int)(asset.Flags & AssetFlags.Maptile) != 0)
{
result = m_AssetService.Delete(assetID);
}
else
{
m_log.DebugFormat(
"[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but type is {1} and allowed remote delete types are {2}",
assetID, (AssetFlags)asset.Flags, m_allowedTypes);
}
}
}
}
XmlSerializer xs = new XmlSerializer(typeof(bool));
return ServerUtils.SerializeResult(xs, result);
}
}
}
}

View File

@@ -57,14 +57,23 @@ namespace OpenSim.Server.Handlers.Asset
public override byte[] Handle(string path, Stream request,
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
AssetBase asset;
XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
AssetBase asset = (AssetBase) xs.Deserialize(request);
try
{
asset = (AssetBase)xs.Deserialize(request);
}
catch (XmlException)
{
httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
return null;
}
string[] p = SplitParams(path);
if (p.Length > 1)
{
bool result =
m_AssetService.UpdateContent(p[1], asset.Data);
bool result = m_AssetService.UpdateContent(p[1], asset.Data);
xs = new XmlSerializer(typeof(bool));
return ServerUtils.SerializeResult(xs, result);

View File

@@ -0,0 +1,110 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using Nini.Config;
using NUnit.Framework;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Server.Handlers.Asset;
using OpenSim.Services.AssetService;
using OpenSim.Services.Interfaces;
using OpenSim.Tests.Common;
using OpenSim.Tests.Common.Mock;
namespace OpenSim.Server.Handlers.Asset.Test
{
[TestFixture]
public class AssetServerPostHandlerTests : OpenSimTestCase
{
[Test]
public void TestGoodAssetStoreRequest()
{
TestHelpers.InMethod();
UUID assetId = TestHelpers.ParseTail(0x1);
IConfigSource config = new IniConfigSource();
config.AddConfig("AssetService");
config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
AssetService assetService = new AssetService(config);
AssetServerPostHandler asph = new AssetServerPostHandler(assetService);
AssetBase asset = AssetHelpers.CreateNotecardAsset(assetId, "Hello World");
MemoryStream buffer = new MemoryStream();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
using (XmlWriter writer = XmlWriter.Create(buffer, settings))
{
XmlSerializer serializer = new XmlSerializer(typeof(AssetBase));
serializer.Serialize(writer, asset);
writer.Flush();
}
buffer.Position = 0;
asph.Handle(null, buffer, null, null);
AssetBase retrievedAsset = assetService.Get(assetId.ToString());
Assert.That(retrievedAsset, Is.Not.Null);
}
[Test]
public void TestBadXmlAssetStoreRequest()
{
TestHelpers.InMethod();
IConfigSource config = new IniConfigSource();
config.AddConfig("AssetService");
config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
AssetService assetService = new AssetService(config);
AssetServerPostHandler asph = new AssetServerPostHandler(assetService);
MemoryStream buffer = new MemoryStream();
byte[] badData = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f };
buffer.Write(badData, 0, badData.Length);
buffer.Position = 0;
TestOSHttpResponse response = new TestOSHttpResponse();
asph.Handle(null, buffer, null, response);
Assert.That(response.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest));
}
}
}

View File

@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OpenSim.Server.Handlers")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("http://opensimulator.org")]
[assembly: AssemblyProduct("OpenSim")]
[assembly: AssemblyCopyright("OpenSimulator developers")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6319afca-d740-4468-a95d-d7f87a081cb3")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.7.5.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Robust")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("http://opensimulator.org")]
[assembly: AssemblyProduct("OpenSim")]
[assembly: AssemblyCopyright("OpenSimulator developers")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d347c5cb-baf8-4566-a221-35d948e1776f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.7.5.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]