From d7ec68669151b75cba1a5a213c653b4d365cf962 Mon Sep 17 00:00:00 2001
From: Dr Scofield
Date: Thu, 29 May 2008 15:46:54 +0000
Subject: this is a snapshot of the OSHttpServer work-in-progress. it's an
initial skeleton, far from complete, just want to check in early and often.
---
OpenSim/Framework/Servers/OSHttpRequest.cs | 14 +++
OpenSim/Framework/Servers/OSHttpRequestPump.cs | 58 ++++++++++++
OpenSim/Framework/Servers/OSHttpServer.cs | 119 +++++++++++++++++++++++++
3 files changed, 191 insertions(+)
create mode 100644 OpenSim/Framework/Servers/OSHttpRequestPump.cs
create mode 100644 OpenSim/Framework/Servers/OSHttpServer.cs
(limited to 'OpenSim')
diff --git a/OpenSim/Framework/Servers/OSHttpRequest.cs b/OpenSim/Framework/Servers/OSHttpRequest.cs
index a290e0e..dac2347 100644
--- a/OpenSim/Framework/Servers/OSHttpRequest.cs
+++ b/OpenSim/Framework/Servers/OSHttpRequest.cs
@@ -44,7 +44,9 @@ namespace OpenSim.Framework.Servers
private string _httpMethod;
private Stream _inputStream;
private bool _isSecureConnection;
+ private bool _isAuthenticated;
private bool _keepAlive;
+ private bool _hasbody;
private string _rawUrl;
private Uri _url;
private NameValueCollection _queryString;
@@ -95,6 +97,16 @@ namespace OpenSim.Framework.Servers
get { return _isSecureConnection; }
}
+ public bool IsAuthenticated
+ {
+ get { return _isAuthenticated; }
+ }
+
+ public bool HasEntityBody
+ {
+ get { return _hasbody; }
+ }
+
public bool KeepAlive
{
get { return _keepAlive; }
@@ -133,8 +145,10 @@ namespace OpenSim.Framework.Servers
_cookies = req.Cookies;
_headers = req.Headers;
_httpMethod = req.HttpMethod;
+ _hasbody = req.HasEntityBody;
_inputStream = req.InputStream;
_isSecureConnection = req.IsSecureConnection;
+ _isAuthenticated = req.IsAuthenticated;
_keepAlive = req.KeepAlive;
_rawUrl = req.RawUrl;
_url = req.Url;
diff --git a/OpenSim/Framework/Servers/OSHttpRequestPump.cs b/OpenSim/Framework/Servers/OSHttpRequestPump.cs
new file mode 100644
index 0000000..78348bb
--- /dev/null
+++ b/OpenSim/Framework/Servers/OSHttpRequestPump.cs
@@ -0,0 +1,58 @@
+/*
+ * 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 OpenSim 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 HttpServer;
+
+namespace OpenSim.Framework.Servers
+{
+ ///
+ /// OSHttpServer provides an HTTP server bound to a specific
+ /// port. When instantiated with just address and port it uses
+ /// normal HTTP, when instantiated with address, port, and X509
+ /// certificate, it uses HTTPS.
+ ///
+ public class OSHttpRequestPump
+ {
+ protected OSHttpServer _httpServer;
+
+ public OSHttpRequestPump()
+ {
+ }
+
+ public static OSHttpRequestPump[] Pumps(OSHttpServer server, int poolSize)
+ {
+ OSHttpRequestPump[] pumps = new OSHttpRequestPump[poolSize];
+ for(int i = 0; i < pumps.Length; i++)
+ {
+ pumps[i]._httpServer = server;
+ }
+
+ return pumps;
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenSim/Framework/Servers/OSHttpServer.cs b/OpenSim/Framework/Servers/OSHttpServer.cs
new file mode 100644
index 0000000..e6caac3
--- /dev/null
+++ b/OpenSim/Framework/Servers/OSHttpServer.cs
@@ -0,0 +1,119 @@
+/*
+ * 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 OpenSim 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.Net;
+using System.Net.Sockets;
+using System.Reflection;
+using System.Threading;
+using System.Security.Cryptography.X509Certificates;
+using log4net;
+using HttpServer;
+
+using HttpListener = HttpServer.HttpListener;
+
+namespace OpenSim.Framework.Servers
+{
+ ///
+ /// OSHttpServer provides an HTTP server bound to a specific
+ /// port. When instantiated with just address and port it uses
+ /// normal HTTP, when instantiated with address, port, and X509
+ /// certificate, it uses HTTPS.
+ ///
+ public class OSHttpServer
+ {
+ private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
+ // underlying HttpServer.HttpListener
+ protected HttpListener _listener;
+ protected Thread _engine;
+
+ // OSHttpRequestPumps "pumping" incoming OSHttpRequests
+ // upwards
+ protected OSHttpRequestPump[] _pumps;
+
+ // thread identifier
+ protected string _engineId;
+ public string EngineID
+ {
+ get { return _engineId; }
+ }
+
+ ///
+ /// True if this is an HTTPS connection; false otherwise.
+ ///
+ protected bool _isSecure;
+ public bool IsSecure
+ {
+ get { return _isSecure; }
+ }
+
+ ///
+ /// Instantiate an HTTP server.
+ ///
+ public OSHttpServer(IPAddress address, int port, int poolSize)
+ {
+ _engineId = String.Format("OSHttpServer [HTTP:{0}/ps:{1}]", port, poolSize);
+ _isSecure = false;
+
+ _pumps = OSHttpRequestPump.Pumps(this, poolSize);
+ }
+
+ ///
+ /// Instantiate an HTTPS server.
+ ///
+ public OSHttpServer(IPAddress address, int port, X509Certificate certificate, int poolSize) :
+ this(address, port, poolSize)
+ {
+ _engineId = String.Format("OSHttpServer [HTTPS:{0}/ps:{1}]", port, poolSize);
+ _isSecure = true;
+ }
+
+ ///
+ /// Start the HTTP server engine.
+ ///
+ public void Start()
+ {
+ _engine = new Thread(new ThreadStart(Engine));
+ _engine.Name = _engineId;
+ _engine.IsBackground = true;
+ _engine.Start();
+ ThreadTracker.Add(_engine);
+ }
+
+ ///
+ ///
+ private void Engine()
+ {
+ while (true)
+ {
+ // do stuff
+ }
+ }
+
+ }
+}
--
cgit v1.1