mirror of
https://github.com/opensim/opensim.git
synced 2026-08-07 01:35:46 +08:00
Massive tab and trailing space cleanup
This commit is contained in:
@@ -58,7 +58,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
/// <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
|
||||
/// 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>
|
||||
@@ -104,7 +104,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
new Dictionary<string, PollServiceEventArgs>();
|
||||
|
||||
protected Dictionary<string, WebSocketRequestDelegate> m_WebSocketHandlers =
|
||||
new Dictionary<string, WebSocketRequestDelegate>();
|
||||
new Dictionary<string, WebSocketRequestDelegate>();
|
||||
|
||||
protected uint m_port;
|
||||
protected uint m_sslport;
|
||||
@@ -253,7 +253,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
return new List<string>(m_rpcHandlers.Keys);
|
||||
}
|
||||
|
||||
// JsonRPC
|
||||
// JsonRPC
|
||||
public bool AddJsonRPCHandler(string method, JsonRPCMethod handler)
|
||||
{
|
||||
lock(jsonRpcHandlers)
|
||||
@@ -459,11 +459,11 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
dWebSocketRequestDelegate(req.Url.AbsolutePath, new WebSocketHttpServerHandler(req, context, 8192));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context);
|
||||
resp.ReuseContext = true;
|
||||
// resp.ReuseContext = false;
|
||||
HandleRequest(req, resp);
|
||||
HandleRequest(req, resp);
|
||||
|
||||
// !!!HACK ALERT!!!
|
||||
// There seems to be a bug in the underlying http code that makes subsequent requests
|
||||
@@ -554,7 +554,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
LogIncomingToStreamHandler(request, requestHandler);
|
||||
|
||||
response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type.
|
||||
|
||||
|
||||
if (requestHandler is IStreamedRequestHandler)
|
||||
{
|
||||
IStreamedRequestHandler streamedRequestHandler = requestHandler as IStreamedRequestHandler;
|
||||
@@ -630,16 +630,16 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
case "text/html":
|
||||
if (DebugLevel >= 3)
|
||||
LogIncomingToContentTypeHandler(request);
|
||||
|
||||
|
||||
buffer = HandleHTTPRequest(request, response);
|
||||
break;
|
||||
|
||||
|
||||
case "application/llsd+xml":
|
||||
case "application/xml+llsd":
|
||||
case "application/llsd+json":
|
||||
if (DebugLevel >= 3)
|
||||
LogIncomingToContentTypeHandler(request);
|
||||
|
||||
|
||||
buffer = HandleLLSDRequests(request, response);
|
||||
break;
|
||||
|
||||
@@ -649,7 +649,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
buffer = HandleJsonRpcRequests(request, response);
|
||||
break;
|
||||
|
||||
|
||||
case "text/xml":
|
||||
case "application/xml":
|
||||
case "application/json":
|
||||
@@ -666,7 +666,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
if (DebugLevel >= 3)
|
||||
LogIncomingToContentTypeHandler(request);
|
||||
|
||||
|
||||
buffer = HandleLLSDRequests(request, response);
|
||||
}
|
||||
// m_log.DebugFormat("[BASE HTTP SERVER]: Checking for HTTP Handler for request {0}", request.RawUrl);
|
||||
@@ -674,18 +674,18 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
if (DebugLevel >= 3)
|
||||
LogIncomingToContentTypeHandler(request);
|
||||
|
||||
|
||||
buffer = HandleHTTPRequest(request, response);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DebugLevel >= 3)
|
||||
LogIncomingToXmlRpcHandler(request);
|
||||
|
||||
|
||||
// generic login request.
|
||||
buffer = HandleXmlRpcRequests(request, response);
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -972,7 +972,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
// private bool TryGetAgentHandler(OSHttpRequest request, OSHttpResponse response, out IHttpAgentHandler agentHandler)
|
||||
// {
|
||||
// agentHandler = null;
|
||||
//
|
||||
//
|
||||
// lock (m_agentHandlers)
|
||||
// {
|
||||
// foreach (IHttpAgentHandler handler in m_agentHandlers.Values)
|
||||
@@ -1171,7 +1171,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// JsonRpc (v2.0 only)
|
||||
// JsonRpc (v2.0 only)
|
||||
// Batch requests not yet supported
|
||||
private byte[] HandleJsonRpcRequests(OSHttpRequest request, OSHttpResponse response)
|
||||
{
|
||||
@@ -1188,7 +1188,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
jsonRpcResponse.Error.Code = ErrorCode.InternalError;
|
||||
jsonRpcResponse.Error.Message = e.Message;
|
||||
}
|
||||
|
||||
|
||||
requestStream.Close();
|
||||
|
||||
if (jsonRpcRequest != null)
|
||||
@@ -1253,7 +1253,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
string responseData = string.Empty;
|
||||
|
||||
responseData = jsonRpcResponse.Serialize();
|
||||
|
||||
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(responseData);
|
||||
return buffer;
|
||||
}
|
||||
@@ -1533,7 +1533,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (String.IsNullOrEmpty(bestMatch))
|
||||
{
|
||||
llsdHandler = null;
|
||||
@@ -1899,8 +1899,8 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
response.SendChunked = false;
|
||||
response.ContentLength64 = buffer.Length;
|
||||
response.ContentEncoding = Encoding.UTF8;
|
||||
|
||||
|
||||
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@@ -1977,7 +1977,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
throw e;
|
||||
}
|
||||
|
||||
m_requestsProcessedStat
|
||||
m_requestsProcessedStat
|
||||
= new Stat(
|
||||
"HTTPRequestsServed",
|
||||
"Number of inbound HTTP requests processed",
|
||||
@@ -1989,7 +1989,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
MeasuresOfInterest.AverageChangeOverTime,
|
||||
stat => stat.Value = RequestNumber,
|
||||
StatVerbosity.Debug);
|
||||
|
||||
|
||||
StatsManager.RegisterStat(m_requestsProcessedStat);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,13 +69,13 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
StatsManager.RegisterStat(
|
||||
new Stat(
|
||||
"requests",
|
||||
"requests",
|
||||
"Number of requests received by this service endpoint",
|
||||
"requests",
|
||||
"service",
|
||||
string.Format("{0}:{1}", httpMethod, path),
|
||||
StatType.Pull,
|
||||
"requests",
|
||||
"requests",
|
||||
"Number of requests received by this service endpoint",
|
||||
"requests",
|
||||
"service",
|
||||
string.Format("{0}:{1}", httpMethod, path),
|
||||
StatType.Pull,
|
||||
MeasuresOfInterest.AverageChangeOverTime,
|
||||
s => s.Value = RequestsReceived,
|
||||
StatVerbosity.Debug));
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
: base(httpMethod, path, name, description) {}
|
||||
|
||||
protected BaseStreamHandler(string httpMethod, string path, IServiceAuth auth)
|
||||
: base(httpMethod, path, null, null)
|
||||
: base(httpMethod, path, null, null)
|
||||
{
|
||||
m_Auth = auth;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
HttpStatusCode statusCode;
|
||||
|
||||
if (!m_Auth.Authenticate(httpRequest.Headers, httpResponse.AddHeader, out statusCode))
|
||||
{
|
||||
{
|
||||
httpResponse.StatusCode = (int)statusCode;
|
||||
httpResponse.ContentType = "text/plain";
|
||||
return new byte[0];
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
/// </remarks>
|
||||
public abstract class BaseStreamHandlerBasicDOSProtector : BaseRequestHandler, IStreamedRequestHandler
|
||||
{
|
||||
|
||||
|
||||
private readonly BasicDosProtectorOptions _options;
|
||||
private readonly BasicDOSProtector _dosProtector;
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
result = ThrottledRequest(path, request, httpRequest, httpResponse);
|
||||
if (_options.MaxConcurrentSessions > 0)
|
||||
_dosProtector.ProcessEnd(clientstring, endpoint);
|
||||
|
||||
|
||||
RequestsHandled++;
|
||||
|
||||
return result;
|
||||
@@ -81,7 +81,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
private string GetRemoteAddr(IOSHttpRequest httpRequest)
|
||||
{
|
||||
string remoteaddr = string.Empty;
|
||||
@@ -101,7 +101,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
clientstring = GetRemoteAddr(httpRequest);
|
||||
|
||||
return clientstring;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
private readonly GenericHTTPMethod _normalMethod;
|
||||
private readonly GenericHTTPMethod _throttledMethod;
|
||||
|
||||
|
||||
private readonly BasicDosProtectorOptions _options;
|
||||
private readonly BasicDOSProtector _dosProtector;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
_normalMethod = normalMethod;
|
||||
_throttledMethod = throttledMethod;
|
||||
|
||||
|
||||
_options = options;
|
||||
_dosProtector = new BasicDOSProtector(_options);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
return process;
|
||||
}
|
||||
|
||||
|
||||
private string GetRemoteAddr(Hashtable request)
|
||||
{
|
||||
string remoteaddr = "";
|
||||
|
||||
@@ -45,26 +45,26 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
// // the handlers - it is NOT required to be an actual agent header
|
||||
// // value.
|
||||
// bool AddAgentHandler(string agent, IHttpAgentHandler handler);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Add a handler for an HTTP request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This handler can actually be invoked either as
|
||||
///
|
||||
/// http://<hostname>:<port>/?method=<methodName>
|
||||
///
|
||||
/// This handler can actually be invoked either as
|
||||
///
|
||||
/// http://<hostname>:<port>/?method=<methodName>
|
||||
///
|
||||
/// or
|
||||
///
|
||||
///
|
||||
/// http://<hostname>:<port><method>
|
||||
///
|
||||
///
|
||||
/// if the method name starts with a slash. For example, AddHTTPHandler("/object/", ...) on a standalone region
|
||||
/// server will register a handler that can be invoked with either
|
||||
///
|
||||
///
|
||||
/// http://localhost:9000/?method=/object/
|
||||
///
|
||||
///
|
||||
/// or
|
||||
///
|
||||
///
|
||||
/// http://localhost:9000/object/
|
||||
///
|
||||
/// In addition, the handler invoked by the HTTP server for any request is the one when best matches the request
|
||||
@@ -87,7 +87,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
/// <param name="handler">handle the LLSD response</param>
|
||||
/// <returns></returns>
|
||||
bool AddLLSDHandler(string path, LLSDMethod handler);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Add a stream handler to the http server. If the handler already exists, then nothing happens.
|
||||
/// </summary>
|
||||
@@ -98,7 +98,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
bool AddXmlRPCHandler(string method, XmlRpcMethod handler, bool keepAlive);
|
||||
|
||||
bool AddJsonRPCHandler(string method, JsonRPCMethod handler);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Websocket HTTP server handlers.
|
||||
/// </summary>
|
||||
@@ -108,7 +108,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
|
||||
void RemoveWebSocketHandler(string servicepath);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the XML RPC handler for given method name
|
||||
/// </summary>
|
||||
@@ -125,7 +125,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
// /// <param name="handler"></param>
|
||||
// /// <returns></returns>
|
||||
// bool RemoveAgentHandler(string agent, IHttpAgentHandler handler);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Remove an HTTP handler
|
||||
/// </summary>
|
||||
@@ -134,15 +134,15 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
void RemoveHTTPHandler(string httpMethod, string path);
|
||||
|
||||
void RemovePollServiceHTTPHandler(string httpMethod, string path);
|
||||
|
||||
|
||||
bool RemoveLLSDHandler(string path, LLSDMethod handler);
|
||||
|
||||
|
||||
void RemoveStreamHandler(string httpMethod, string path);
|
||||
|
||||
void RemoveXmlRPCHandler(string method);
|
||||
|
||||
void RemoveJsonRPCHandler(string method);
|
||||
|
||||
|
||||
string GetHTTP404(string host);
|
||||
|
||||
string GetHTTP500();
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
void Handle(string path, Stream request, Stream response, IOSHttpRequest httpReqbuest, IOSHttpResponse httpResponse);
|
||||
}
|
||||
|
||||
|
||||
public interface IGenericHTTPHandler : IRequestHandler
|
||||
{
|
||||
Hashtable Handle(string path, Hashtable request);
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
public class JsonRpcRequestManager
|
||||
{
|
||||
static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
|
||||
public JsonRpcRequestManager()
|
||||
{
|
||||
}
|
||||
@@ -188,6 +188,6 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,11 +155,11 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
private string _userAgent;
|
||||
|
||||
internal IHttpRequest IHttpRequest
|
||||
{
|
||||
{
|
||||
get { return _request; }
|
||||
}
|
||||
|
||||
internal IHttpClientContext IHttpClientContext
|
||||
internal IHttpClientContext IHttpClientContext
|
||||
{
|
||||
get { return _context; }
|
||||
}
|
||||
@@ -192,19 +192,19 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (null != req.Headers["content-type"])
|
||||
_contentType = _request.Headers["content-type"];
|
||||
if (null != req.Headers["user-agent"])
|
||||
_userAgent = req.Headers["user-agent"];
|
||||
|
||||
|
||||
if (null != req.Headers["remote_addr"])
|
||||
{
|
||||
try
|
||||
{
|
||||
IPAddress addr = IPAddress.Parse(req.Headers["remote_addr"]);
|
||||
// sometimes req.Headers["remote_port"] returns a comma separated list, so use
|
||||
// the first one in the list and log it
|
||||
// the first one in the list and log it
|
||||
string[] strPorts = req.Headers["remote_port"].Split(new char[] { ',' });
|
||||
if (strPorts.Length > 1)
|
||||
{
|
||||
@@ -216,7 +216,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
_log.ErrorFormat("[OSHttpRequest]: format exception on addr/port {0}:{1}, ignoring",
|
||||
_log.ErrorFormat("[OSHttpRequest]: format exception on addr/port {0}:{1}, ignoring",
|
||||
req.Headers["remote_addr"], req.Headers["remote_port"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
public bool KeepAlive
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
return _httpResponse.Connection == ConnectionType.KeepAlive;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
/// 300 Redirect: different presentation forms available, take a pick
|
||||
/// </summary>
|
||||
RedirectMultipleChoices = 300,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 301 Redirect: requested resource has moved and now lives somewhere else
|
||||
/// </summary>
|
||||
|
||||
@@ -46,14 +46,14 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
public RequestMethod Request;
|
||||
public UUID Id;
|
||||
public int TimeOutms;
|
||||
public EventType Type;
|
||||
public EventType Type;
|
||||
|
||||
public enum EventType : int
|
||||
{
|
||||
LongPoll = 0,
|
||||
LslHttp = 1,
|
||||
Inventory = 2,
|
||||
Texture = 3,
|
||||
Texture = 3,
|
||||
Mesh = 4
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
startInfo.ThreadPoolName = "PoolService";
|
||||
|
||||
m_threadPool = new SmartThreadPool(startInfo);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Start()
|
||||
@@ -109,7 +109,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
true,
|
||||
null,
|
||||
1000 * 60 * 10);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// 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.Framework.Servers.HttpServer")]
|
||||
@@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
|
||||
[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
|
||||
// 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)]
|
||||
|
||||
@@ -25,7 +25,7 @@ using System.Runtime.InteropServices;
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
|
||||
@@ -291,5 +291,5 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
serializer.Serialize(xmlWriter, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
public event PongDelegate OnPong;
|
||||
|
||||
/// <summary>
|
||||
/// This is a regular HTTP Request... This may be removed in the future.
|
||||
/// This is a regular HTTP Request... This may be removed in the future.
|
||||
/// </summary>
|
||||
// public event RegularHttpRequestDelegate OnRegularHttpRequest;
|
||||
|
||||
@@ -93,9 +93,9 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
/// When the websocket is closed, this will be fired.
|
||||
/// </summary>
|
||||
public event CloseDelegate OnClose;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Set this delegate to allow your module to validate the origin of the
|
||||
/// Set this delegate to allow your module to validate the origin of the
|
||||
/// Websocket request. Primary line of defense against cross site scripting
|
||||
/// </summary>
|
||||
public ValidateHandshake HandshakeValidateMethodOverride = null;
|
||||
@@ -181,7 +181,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
throw new InvalidOperationException("The socket has been shutdown");
|
||||
}
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_networkContext != null && _networkContext.Socket != null)
|
||||
@@ -194,8 +194,8 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This triggers the websocket to start the upgrade process...
|
||||
/// This is a Generalized Networking 'common sense' helper method. Some people expect to call Start() instead
|
||||
/// This triggers the websocket to start the upgrade process...
|
||||
/// This is a Generalized Networking 'common sense' helper method. Some people expect to call Start() instead
|
||||
/// of the more context appropriate HandshakeAndUpgrade()
|
||||
/// </summary>
|
||||
public void Start()
|
||||
@@ -261,7 +261,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
acceptKey = GenerateAcceptKey(websocketKey);
|
||||
string rawaccept = string.Format(HandshakeAcceptText, acceptKey);
|
||||
SendUpgradeSuccess(rawaccept);
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
@@ -282,7 +282,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a handshake response key string based on the client's
|
||||
/// Generates a handshake response key string based on the client's
|
||||
/// provided key to prove to the client that we're allowing the Websocket
|
||||
/// upgrade of our own free will and we were not coerced into doing it.
|
||||
/// </summary>
|
||||
@@ -298,7 +298,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
SHA1 hashobj = SHA1.Create();
|
||||
string ret = Convert.ToBase64String(hashobj.ComputeHash(Encoding.UTF8.GetBytes(acceptkey)));
|
||||
hashobj.Clear();
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -310,11 +310,11 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
// Create a new websocket state so we can keep track of data in between network reads.
|
||||
WebSocketState socketState = new WebSocketState() { ReceivedBytes = new List<byte>(), Header = WebsocketFrameHeader.HeaderDefault(), FrameComplete = true};
|
||||
|
||||
|
||||
byte[] bhandshakeResponse = Encoding.UTF8.GetBytes(pHandshakeResponse);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
@@ -324,7 +324,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
}
|
||||
// Begin reading the TCP stream before writing the Upgrade success message to the other side of the stream.
|
||||
_networkContext.Stream.BeginRead(_buffer, 0, _bufferLength, OnReceive, socketState);
|
||||
|
||||
|
||||
// Write the upgrade handshake success message
|
||||
_networkContext.Stream.Write(bhandshakeResponse, 0, bhandshakeResponse.Length);
|
||||
_networkContext.Stream.Flush();
|
||||
@@ -345,7 +345,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
Close(string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -369,7 +369,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
/// <summary>
|
||||
/// This is our ugly Async OnReceive event handler.
|
||||
/// This chunks the input stream based on the length of the provided buffer and processes out
|
||||
/// This chunks the input stream based on the length of the provided buffer and processes out
|
||||
/// as many frames as it can. It then moves the unprocessed data to the beginning of the buffer.
|
||||
/// </summary>
|
||||
/// <param name="ar">Our Async State from beginread</param>
|
||||
@@ -390,7 +390,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
if (_bufferPosition > _bufferLength)
|
||||
{
|
||||
// Message too big for chunksize.. not sure how this happened...
|
||||
// Message too big for chunksize.. not sure how this happened...
|
||||
//Close(string.Empty);
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
if (pheader.PayloadLen > (ulong) _maxPayloadBytes)
|
||||
{
|
||||
Close("Invalid Payload size");
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
if (pheader.PayloadLen > 0)
|
||||
@@ -487,7 +487,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
_socketState.ReceivedBytes.Clear();
|
||||
_socketState.ExpectedBytes = 0;
|
||||
// do some processing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (offset > 0)
|
||||
@@ -504,7 +504,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
}
|
||||
else
|
||||
{
|
||||
// We can't read the stream anymore...
|
||||
// We can't read the stream anymore...
|
||||
}
|
||||
}
|
||||
catch (IOException)
|
||||
@@ -533,7 +533,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
textMessageFrame.Header.Opcode = WebSocketReader.OpCode.Text;
|
||||
textMessageFrame.Header.IsEnd = true;
|
||||
SendSocket(textMessageFrame.ToBytes());
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void SendData(byte[] data)
|
||||
@@ -657,7 +657,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
SendSocket(pongFrame.ToBytes());
|
||||
break;
|
||||
case WebSocketReader.OpCode.Pong:
|
||||
|
||||
|
||||
PongDelegate pongD = OnPong;
|
||||
if (pongD != null)
|
||||
{
|
||||
@@ -701,7 +701,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
textD(this, new WebsocketTextEventArgs() { Data = Encoding.UTF8.GetString(psocketState.ReceivedBytes.ToArray()) });
|
||||
}
|
||||
|
||||
|
||||
// Send Done Event!
|
||||
}
|
||||
break;
|
||||
@@ -719,7 +719,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
if (psocketState.ContinuationFrame.Header.Opcode == WebSocketReader.OpCode.Text)
|
||||
{
|
||||
// Send Done event
|
||||
// Send Done event
|
||||
TextDelegate textD = OnText;
|
||||
if (textD != null)
|
||||
{
|
||||
@@ -744,9 +744,9 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
break;
|
||||
case WebSocketReader.OpCode.Close:
|
||||
Close(string.Empty);
|
||||
|
||||
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
psocketState.Header.SetDefault();
|
||||
psocketState.ReceivedBytes.Clear();
|
||||
@@ -837,12 +837,12 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to read a header off the provided buffer. Returns true, exports a WebSocketFrameheader,
|
||||
/// Attempts to read a header off the provided buffer. Returns true, exports a WebSocketFrameheader,
|
||||
/// and an int to move the buffer forward when it reads a header. False when it can't read a header
|
||||
/// </summary>
|
||||
/// <param name="pBuffer">Bytes read from the stream</param>
|
||||
/// <param name="pOffset">Starting place in the stream to begin trying to read from</param>
|
||||
/// <param name="length">Lenth in the stream to try and read from. Provided for cases where the
|
||||
/// <param name="length">Lenth in the stream to try and read from. Provided for cases where the
|
||||
/// buffer's length is larger then the data in it</param>
|
||||
/// <param name="oHeader">Outputs the read WebSocket frame header</param>
|
||||
/// <param name="moveBuffer">Informs the calling stream to move the buffer forward</param>
|
||||
@@ -897,7 +897,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
oHeader.PayloadLen = BitConverter.ToUInt16(pBuffer, pOffset + index);
|
||||
index += 2;
|
||||
break;
|
||||
case 127: // we got more this is a bigger frame
|
||||
case 127: // we got more this is a bigger frame
|
||||
// 8 bytes - uint64 - most significant bit 0 network byte order
|
||||
minumheadersize += 8;
|
||||
if (length < minumheadersize)
|
||||
@@ -909,7 +909,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
oHeader.PayloadLen = BitConverter.ToUInt64(pBuffer, pOffset + index);
|
||||
index += 8;
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
//oHeader.PayloadLeft = oHeader.PayloadLen; // Start the count in case it's chunked over the network. This is different then frame fragmentation
|
||||
if (oHeader.IsMasked)
|
||||
@@ -937,9 +937,9 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
/*
|
||||
* RFC6455
|
||||
nib 0 1 2 3 4 5 6 7
|
||||
byt 0 1 2 3
|
||||
dec 0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
byt 0 1 2 3
|
||||
dec 0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-------+-+-------------+-------------------------------+
|
||||
|F|R|R|R| opcode|M| Payload len | Extended payload length |
|
||||
|I|S|S|S| (4) |A| (7) | (16/64) +
|
||||
@@ -963,7 +963,7 @@ dec 0 1 2 3
|
||||
public static readonly WebSocketFrame DefaultFrame = new WebSocketFrame(){Header = new WebsocketFrameHeader(),WebSocketPayload = new byte[0]};
|
||||
public WebsocketFrameHeader Header;
|
||||
public byte[] WebSocketPayload;
|
||||
|
||||
|
||||
public byte[] ToBytes()
|
||||
{
|
||||
Header.PayloadLen = (ulong)WebSocketPayload.Length;
|
||||
@@ -991,7 +991,7 @@ dec 0 1 2 3
|
||||
public int Mask;
|
||||
/*
|
||||
byt 0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+---------------+---------------+---------------+---------------+
|
||||
| Octal 1 | Octal 2 | Octal 3 | Octal 4 |
|
||||
+---------------+---------------+---------------+---------------+
|
||||
@@ -1002,11 +1002,11 @@ byt 0 1 2 3
|
||||
|
||||
public UInt64 PayloadLen;
|
||||
//public UInt64 PayloadLeft;
|
||||
// Payload is X + Y
|
||||
// Payload is X + Y
|
||||
//public UInt64 ExtensionDataLength;
|
||||
//public UInt64 ApplicationDataLength;
|
||||
public static readonly WebsocketFrameHeader ZeroHeader = WebsocketFrameHeader.HeaderDefault();
|
||||
|
||||
|
||||
public void SetDefault()
|
||||
{
|
||||
|
||||
@@ -1025,16 +1025,16 @@ byt 0 1 2 3
|
||||
/// <summary>
|
||||
/// Returns a byte array representing the Frame header
|
||||
/// </summary>
|
||||
/// <param name="payload">This is the frame data payload. The header describes the size of the payload.
|
||||
/// <param name="payload">This is the frame data payload. The header describes the size of the payload.
|
||||
/// If payload is null, a Zero sized payload is assumed</param>
|
||||
/// <returns>Returns a byte array representing the frame header</returns>
|
||||
public byte[] ToBytes(byte[] payload)
|
||||
{
|
||||
List<byte> result = new List<byte>();
|
||||
|
||||
|
||||
// Squeeze in our opcode and our ending bit.
|
||||
result.Add((byte)((byte)Opcode | (IsEnd?0x80:0x00) ));
|
||||
|
||||
|
||||
// Again with the three different byte interpretations of size..
|
||||
|
||||
//bytesize
|
||||
@@ -1056,7 +1056,7 @@ byt 0 1 2 3
|
||||
Array.Reverse(payloadLengthByte);
|
||||
result.AddRange(payloadLengthByte);
|
||||
}
|
||||
|
||||
|
||||
// Only add a payload if it's not null
|
||||
if (payload != null)
|
||||
{
|
||||
@@ -1155,5 +1155,5 @@ byt 0 1 2 3
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
private readonly XmlRpcMethod _normalMethod;
|
||||
private readonly XmlRpcMethod _throttledMethod;
|
||||
|
||||
|
||||
private readonly BasicDosProtectorOptions _options;
|
||||
private readonly BasicDOSProtector _dosProtector;
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
_normalMethod = normalMethod;
|
||||
_throttledMethod = throttledMethod;
|
||||
|
||||
|
||||
_options = options;
|
||||
_dosProtector = new BasicDOSProtector(_options);
|
||||
|
||||
@@ -87,5 +87,5 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user