Merge branch 'master' into careminster

Conflicts:
	bin/HttpServer_OpenSim.dll
avinationmerge
Melanie 2013-02-07 20:51:51 +00:00
commit 45f5a6a6db
12 changed files with 5877 additions and 4542 deletions

View File

@ -54,6 +54,16 @@ namespace OpenSim.Framework.Servers.HttpServer
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private HttpServerLogWriter httpserverlog = new HttpServerLogWriter(); private HttpServerLogWriter httpserverlog = new HttpServerLogWriter();
/// <summary>
/// This is a pending websocket request before it got an sucessful upgrade response.
/// The consumer must call handler.HandshakeAndUpgrade() to signal to the handler to
/// start the connection and optionally provide an origin authentication method.
/// </summary>
/// <param name="servicepath"></param>
/// <param name="handler"></param>
public delegate void WebSocketRequestDelegate(string servicepath, WebSocketHttpServerHandler handler);
/// <summary> /// <summary>
/// Gets or sets the debug level. /// Gets or sets the debug level.
/// </summary> /// </summary>
@ -87,6 +97,9 @@ namespace OpenSim.Framework.Servers.HttpServer
protected Dictionary<string, PollServiceEventArgs> m_pollHandlers = protected Dictionary<string, PollServiceEventArgs> m_pollHandlers =
new Dictionary<string, PollServiceEventArgs>(); new Dictionary<string, PollServiceEventArgs>();
protected Dictionary<string, WebSocketRequestDelegate> m_WebSocketHandlers =
new Dictionary<string, WebSocketRequestDelegate>();
protected uint m_port; protected uint m_port;
protected uint m_sslport; protected uint m_sslport;
protected bool m_ssl; protected bool m_ssl;
@ -170,6 +183,22 @@ namespace OpenSim.Framework.Servers.HttpServer
} }
} }
public void AddWebSocketHandler(string servicepath, WebSocketRequestDelegate handler)
{
lock (m_WebSocketHandlers)
{
if (!m_WebSocketHandlers.ContainsKey(servicepath))
m_WebSocketHandlers.Add(servicepath, handler);
}
}
public void RemoveWebSocketHandler(string servicepath)
{
lock (m_WebSocketHandlers)
if (m_WebSocketHandlers.ContainsKey(servicepath))
m_WebSocketHandlers.Remove(servicepath);
}
public List<string> GetStreamHandlerKeys() public List<string> GetStreamHandlerKeys()
{ {
lock (m_streamHandlers) lock (m_streamHandlers)
@ -410,9 +439,24 @@ namespace OpenSim.Framework.Servers.HttpServer
public void OnHandleRequestIOThread(IHttpClientContext context, IHttpRequest request) public void OnHandleRequestIOThread(IHttpClientContext context, IHttpRequest request)
{ {
OSHttpRequest req = new OSHttpRequest(context, request); OSHttpRequest req = new OSHttpRequest(context, request);
WebSocketRequestDelegate dWebSocketRequestDelegate = null;
lock (m_WebSocketHandlers)
{
if (m_WebSocketHandlers.ContainsKey(req.RawUrl))
dWebSocketRequestDelegate = m_WebSocketHandlers[req.RawUrl];
}
if (dWebSocketRequestDelegate != null)
{
dWebSocketRequestDelegate(req.Url.AbsolutePath, new WebSocketHttpServerHandler(req, context, 8192));
return;
}
OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context);
HandleRequest(req, resp); HandleRequest(req, resp);
// !!!HACK ALERT!!! // !!!HACK ALERT!!!
// There seems to be a bug in the underlying http code that makes subsequent requests // There seems to be a bug in the underlying http code that makes subsequent requests
@ -501,7 +545,7 @@ namespace OpenSim.Framework.Servers.HttpServer
LogIncomingToStreamHandler(request, requestHandler); LogIncomingToStreamHandler(request, requestHandler);
response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type. response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type.
if (requestHandler is IStreamedRequestHandler) if (requestHandler is IStreamedRequestHandler)
{ {
IStreamedRequestHandler streamedRequestHandler = requestHandler as IStreamedRequestHandler; IStreamedRequestHandler streamedRequestHandler = requestHandler as IStreamedRequestHandler;

View File

@ -98,7 +98,17 @@ namespace OpenSim.Framework.Servers.HttpServer
bool AddXmlRPCHandler(string method, XmlRpcMethod handler, bool keepAlive); bool AddXmlRPCHandler(string method, XmlRpcMethod handler, bool keepAlive);
bool AddJsonRPCHandler(string method, JsonRPCMethod handler); bool AddJsonRPCHandler(string method, JsonRPCMethod handler);
/// <summary>
/// Websocket HTTP server handlers.
/// </summary>
/// <param name="servicepath"></param>
/// <param name="handler"></param>
void AddWebSocketHandler(string servicepath, BaseHttpServer.WebSocketRequestDelegate handler);
void RemoveWebSocketHandler(string servicepath);
/// <summary> /// <summary>
/// Gets the XML RPC handler for given method name /// Gets the XML RPC handler for given method name
/// </summary> /// </summary>

File diff suppressed because it is too large Load Diff

View File

@ -70,6 +70,11 @@ namespace OpenSim.Framework.Servers.Tests
public void Close() { } public void Close() { }
public bool EndWhenDone { get { return false;} set { return;}} public bool EndWhenDone { get { return false;} set { return;}}
public HTTPNetworkContext GiveMeTheNetworkStreamIKnowWhatImDoing()
{
return new HTTPNetworkContext();
}
public event EventHandler<DisconnectedEventArgs> Disconnected = delegate { }; public event EventHandler<DisconnectedEventArgs> Disconnected = delegate { };
/// <summary> /// <summary>
/// A request have been received in the context. /// A request have been received in the context.

View File

@ -0,0 +1,174 @@
/*
* 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.Collections.Generic;
using System.Reflection;
using OpenSim.Framework.Servers;
using Mono.Addins;
using log4net;
using Nini.Config;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Framework.Servers.HttpServer;
namespace OpenSim.Region.OptionalModules.WebSocketEchoModule
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "WebSocketEchoModule")]
public class WebSocketEchoModule : ISharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private bool enabled;
public string Name { get { return "WebSocketEchoModule"; } }
public Type ReplaceableInterface { get { return null; } }
private HashSet<WebSocketHttpServerHandler> _activeHandlers = new HashSet<WebSocketHttpServerHandler>();
public void Initialise(IConfigSource pConfig)
{
enabled =(pConfig.Configs["WebSocketEcho"] != null);
if (enabled)
m_log.DebugFormat("[WebSocketEchoModule]: INITIALIZED MODULE");
}
/// <summary>
/// This method sets up the callback to WebSocketHandlerCallback below when a HTTPRequest comes in for /echo
/// </summary>
public void PostInitialise()
{
if (enabled)
MainServer.Instance.AddWebSocketHandler("/echo", WebSocketHandlerCallback);
}
// This gets called by BaseHttpServer and gives us an opportunity to set things on the WebSocket handler before we turn it on
public void WebSocketHandlerCallback(string path, WebSocketHttpServerHandler handler)
{
SubscribeToEvents(handler);
handler.SetChunksize(8192);
handler.NoDelay_TCP_Nagle = true;
handler.HandshakeAndUpgrade();
}
//These are our normal events
public void SubscribeToEvents(WebSocketHttpServerHandler handler)
{
handler.OnClose += HandlerOnOnClose;
handler.OnText += HandlerOnOnText;
handler.OnUpgradeCompleted += HandlerOnOnUpgradeCompleted;
handler.OnData += HandlerOnOnData;
handler.OnPong += HandlerOnOnPong;
}
public void UnSubscribeToEvents(WebSocketHttpServerHandler handler)
{
handler.OnClose -= HandlerOnOnClose;
handler.OnText -= HandlerOnOnText;
handler.OnUpgradeCompleted -= HandlerOnOnUpgradeCompleted;
handler.OnData -= HandlerOnOnData;
handler.OnPong -= HandlerOnOnPong;
}
private void HandlerOnOnPong(object sender, PongEventArgs pongdata)
{
m_log.Info("[WebSocketEchoModule]: Got a pong.. ping time: " + pongdata.PingResponseMS);
}
private void HandlerOnOnData(object sender, WebsocketDataEventArgs data)
{
WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;
obj.SendData(data.Data);
m_log.Info("[WebSocketEchoModule]: We received a bunch of ugly non-printable bytes");
obj.SendPingCheck();
}
private void HandlerOnOnUpgradeCompleted(object sender, UpgradeCompletedEventArgs completeddata)
{
WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;
_activeHandlers.Add(obj);
}
private void HandlerOnOnText(object sender, WebsocketTextEventArgs text)
{
WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;
obj.SendMessage(text.Data);
m_log.Info("[WebSocketEchoModule]: We received this: " + text.Data);
}
// Remove the references to our handler
private void HandlerOnOnClose(object sender, CloseEventArgs closedata)
{
WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;
UnSubscribeToEvents(obj);
lock (_activeHandlers)
_activeHandlers.Remove(obj);
obj.Dispose();
}
// Shutting down.. so shut down all sockets.
// Note.. this should be done outside of an ienumerable if you're also hook to the close event.
public void Close()
{
if (!enabled)
return;
// We convert this to a for loop so we're not in in an IEnumerable when the close
//call triggers an event which then removes item from _activeHandlers that we're enumerating
WebSocketHttpServerHandler[] items = new WebSocketHttpServerHandler[_activeHandlers.Count];
_activeHandlers.CopyTo(items);
for (int i = 0; i < items.Length; i++)
{
items[i].Close(string.Empty);
items[i].Dispose();
}
_activeHandlers.Clear();
MainServer.Instance.RemoveWebSocketHandler("/echo");
}
public void AddRegion(Scene scene)
{
m_log.DebugFormat("[WebSocketEchoModule]: REGION {0} ADDED", scene.RegionInfo.RegionName);
}
public void RemoveRegion(Scene scene)
{
m_log.DebugFormat("[WebSocketEchoModule]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
}
public void RegionLoaded(Scene scene)
{
m_log.DebugFormat("[WebSocketEchoModule]: REGION {0} LOADED", scene.RegionInfo.RegionName);
}
}
}

View File

@ -146,7 +146,7 @@ namespace OpenSim.Region.OptionalModules.PhysicsParameters
{ {
foreach (PhysParameterEntry ppe in physScene.GetParameterList()) foreach (PhysParameterEntry ppe in physScene.GetParameterList())
{ {
float val = 0.0f; string val = string.Empty;
if (physScene.GetPhysicsParameter(ppe.name, out val)) if (physScene.GetPhysicsParameter(ppe.name, out val))
{ {
WriteOut(" {0}/{1} = {2}", scene.RegionInfo.RegionName, ppe.name, val); WriteOut(" {0}/{1} = {2}", scene.RegionInfo.RegionName, ppe.name, val);
@ -159,7 +159,7 @@ namespace OpenSim.Region.OptionalModules.PhysicsParameters
} }
else else
{ {
float val = 0.0f; string val = string.Empty;
if (physScene.GetPhysicsParameter(parm, out val)) if (physScene.GetPhysicsParameter(parm, out val))
{ {
WriteOut(" {0}/{1} = {2}", scene.RegionInfo.RegionName, parm, val); WriteOut(" {0}/{1} = {2}", scene.RegionInfo.RegionName, parm, val);
@ -185,21 +185,12 @@ namespace OpenSim.Region.OptionalModules.PhysicsParameters
return; return;
} }
string parm = "xxx"; string parm = "xxx";
float val = 0f; string valparm = String.Empty;
uint localID = (uint)PhysParameterEntry.APPLY_TO_NONE; // set default value uint localID = (uint)PhysParameterEntry.APPLY_TO_NONE; // set default value
try try
{ {
parm = cmdparms[2]; parm = cmdparms[2];
string valparm = cmdparms[3].ToLower(); valparm = cmdparms[3].ToLower();
if (valparm == "true")
val = PhysParameterEntry.NUMERIC_TRUE;
else
{
if (valparm == "false")
val = PhysParameterEntry.NUMERIC_FALSE;
else
val = float.Parse(valparm, Culture.NumberFormatInfo);
}
if (cmdparms.Length > 4) if (cmdparms.Length > 4)
{ {
if (cmdparms[4].ToLower() == "all") if (cmdparms[4].ToLower() == "all")
@ -224,7 +215,7 @@ namespace OpenSim.Region.OptionalModules.PhysicsParameters
IPhysicsParameters physScene = scene.PhysicsScene as IPhysicsParameters; IPhysicsParameters physScene = scene.PhysicsScene as IPhysicsParameters;
if (physScene != null) if (physScene != null)
{ {
if (!physScene.SetPhysicsParameter(parm, val, localID)) if (!physScene.SetPhysicsParameter(parm, valparm, localID))
{ {
WriteError("Failed set of parameter '{0}' for region '{1}'", parm, scene.RegionInfo.RegionName); WriteError("Failed set of parameter '{0}' for region '{1}'", parm, scene.RegionInfo.RegionName);
} }

View File

@ -641,24 +641,6 @@ public static class BSParam
return (b == ConfigurationParameters.numericTrue ? true : false); return (b == ConfigurationParameters.numericTrue ? true : false);
} }
private static void ResetBroadphasePoolTainted(BSScene pPhysScene, float v)
{
BSScene physScene = pPhysScene;
physScene.TaintedObject("BSParam.ResetBroadphasePoolTainted", delegate()
{
physScene.PE.ResetBroadphasePool(physScene.World);
});
}
private static void ResetConstraintSolverTainted(BSScene pPhysScene, float v)
{
BSScene physScene = pPhysScene;
physScene.TaintedObject("BSParam.ResetConstraintSolver", delegate()
{
physScene.PE.ResetConstraintSolver(physScene.World);
});
}
// Search through the parameter definitions and return the matching // Search through the parameter definitions and return the matching
// ParameterDefn structure. // ParameterDefn structure.
// Case does not matter as names are compared after converting to lower case. // Case does not matter as names are compared after converting to lower case.
@ -722,6 +704,22 @@ public static class BSParam
} }
} }
private static void ResetBroadphasePoolTainted(BSScene pPhysScene, float v)
{
BSScene physScene = pPhysScene;
physScene.TaintedObject("BSParam.ResetBroadphasePoolTainted", delegate()
{
physScene.PE.ResetBroadphasePool(physScene.World);
});
}
private static void ResetConstraintSolverTainted(BSScene pPhysScene, float v)
{
BSScene physScene = pPhysScene;
physScene.TaintedObject("BSParam.ResetConstraintSolver", delegate()
{
physScene.PE.ResetConstraintSolver(physScene.World);
});
}
} }
} }

View File

@ -876,14 +876,39 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// will use the next time since it's pinned and shared memory. // will use the next time since it's pinned and shared memory.
// Some of the values require calling into the physics engine to get the new // Some of the values require calling into the physics engine to get the new
// value activated ('terrainFriction' for instance). // value activated ('terrainFriction' for instance).
public bool SetPhysicsParameter(string parm, float val, uint localID) public bool SetPhysicsParameter(string parm, string val, uint localID)
{ {
bool ret = false; bool ret = false;
float valf = 0f;
if (val.ToLower() == "true")
{
valf = PhysParameterEntry.NUMERIC_TRUE;
}
else
{
if (val.ToLower() == "false")
{
valf = PhysParameterEntry.NUMERIC_FALSE;
}
else
{
try
{
valf = float.Parse(val);
}
catch
{
valf = 0f;
}
}
}
BSParam.ParameterDefn theParam; BSParam.ParameterDefn theParam;
if (BSParam.TryGetParameter(parm, out theParam)) if (BSParam.TryGetParameter(parm, out theParam))
{ {
// Set the value in the C# code // Set the value in the C# code
theParam.setter(this, parm, localID, val); theParam.setter(this, parm, localID, valf);
// Optionally set the parameter in the unmanaged code // Optionally set the parameter in the unmanaged code
if (theParam.onObject != null) if (theParam.onObject != null)
@ -898,16 +923,16 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
case PhysParameterEntry.APPLY_TO_NONE: case PhysParameterEntry.APPLY_TO_NONE:
// This will cause a call into the physical world if some operation is specified (SetOnObject). // This will cause a call into the physical world if some operation is specified (SetOnObject).
objectIDs.Add(TERRAIN_ID); objectIDs.Add(TERRAIN_ID);
TaintedUpdateParameter(parm, objectIDs, val); TaintedUpdateParameter(parm, objectIDs, valf);
break; break;
case PhysParameterEntry.APPLY_TO_ALL: case PhysParameterEntry.APPLY_TO_ALL:
lock (PhysObjects) objectIDs = new List<uint>(PhysObjects.Keys); lock (PhysObjects) objectIDs = new List<uint>(PhysObjects.Keys);
TaintedUpdateParameter(parm, objectIDs, val); TaintedUpdateParameter(parm, objectIDs, valf);
break; break;
default: default:
// setting only one localID // setting only one localID
objectIDs.Add(localID); objectIDs.Add(localID);
TaintedUpdateParameter(parm, objectIDs, val); TaintedUpdateParameter(parm, objectIDs, valf);
break; break;
} }
} }
@ -942,14 +967,14 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// Get parameter. // Get parameter.
// Return 'false' if not able to get the parameter. // Return 'false' if not able to get the parameter.
public bool GetPhysicsParameter(string parm, out float value) public bool GetPhysicsParameter(string parm, out string value)
{ {
float val = 0f; string val = String.Empty;
bool ret = false; bool ret = false;
BSParam.ParameterDefn theParam; BSParam.ParameterDefn theParam;
if (BSParam.TryGetParameter(parm, out theParam)) if (BSParam.TryGetParameter(parm, out theParam))
{ {
val = theParam.getter(this); val = theParam.getter(this).ToString();
ret = true; ret = true;
} }
value = val; value = val;

View File

@ -60,14 +60,14 @@ namespace OpenSim.Region.Physics.Manager
// Set parameter on a specific or all instances. // Set parameter on a specific or all instances.
// Return 'false' if not able to set the parameter. // Return 'false' if not able to set the parameter.
bool SetPhysicsParameter(string parm, float value, uint localID); bool SetPhysicsParameter(string parm, string value, uint localID);
// Get parameter. // Get parameter.
// Return 'false' if not able to get the parameter. // Return 'false' if not able to get the parameter.
bool GetPhysicsParameter(string parm, out float value); bool GetPhysicsParameter(string parm, out string value);
// Get parameter from a particular object // Get parameter from a particular object
// TODO: // TODO:
// bool GetPhysicsParameter(string parm, out float value, uint localID); // bool GetPhysicsParameter(string parm, out string value, uint localID);
} }
} }

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1587,6 +1587,8 @@
</Files> </Files>
</Project> </Project>
<Project frameworkVersion="v3_5" name="OpenSim.Region.ClientStack.LindenCaps" path="OpenSim/Region/ClientStack/Linden/Caps" type="Library"> <Project frameworkVersion="v3_5" name="OpenSim.Region.ClientStack.LindenCaps" path="OpenSim/Region/ClientStack/Linden/Caps" type="Library">
<Configuration name="Debug"> <Configuration name="Debug">
<Options> <Options>
@ -1631,6 +1633,7 @@
</Files> </Files>
</Project> </Project>
<Project frameworkVersion="v3_5" name="OpenSim.Region.CoreModules" path="OpenSim/Region/CoreModules" type="Library"> <Project frameworkVersion="v3_5" name="OpenSim.Region.CoreModules" path="OpenSim/Region/CoreModules" type="Library">
<Configuration name="Debug"> <Configuration name="Debug">
<Options> <Options>