2008-11-03 Gonzalo Paniagua Javier <gonzalo@novell.com>
[mono.git] / mcs / class / System / System.Net / HttpListener.cs
index d8e97f1167a3ccfaeebbe7820bf9e1b196c95508..6c13adb646073f90d3cdcbb0d91e1fbaab3e08cb 100644 (file)
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-#if NET_2_0
-using System.Collections.Generic;
+
+#if NET_2_0 && SECURITY_DEP
+
+using System.Collections;
 using System.Threading;
 //TODO: logging
 namespace System.Net {
@@ -40,16 +42,16 @@ namespace System.Net {
                bool listening;
                bool disposed;
 
-               Dictionary<HttpListenerContext,HttpListenerContext> registry;
-               List<HttpListenerContext> ctx_queue;
-               List<ListenerAsyncResult> wait_queue;
+               Hashtable registry;   // Dictionary<HttpListenerContext,HttpListenerContext> 
+               ArrayList ctx_queue;  // List<HttpListenerContext> ctx_queue;
+               ArrayList wait_queue; // List<ListenerAsyncResult> wait_queue;
 
                public HttpListener ()
                {
                        prefixes = new HttpListenerPrefixCollection (this);
-                       registry = new Dictionary<HttpListenerContext,HttpListenerContext> ();
-                       ctx_queue = new List<HttpListenerContext> ();
-                       wait_queue = new List<ListenerAsyncResult> ();
+                       registry = new Hashtable ();
+                       ctx_queue = new ArrayList ();
+                       wait_queue = new ArrayList ();
                        auth_schemes = AuthenticationSchemes.Anonymous;
                }
 
@@ -118,7 +120,6 @@ namespace System.Net {
                                return;
 
                        if (!listening) {
-                               disposed = true;
                                return;
                        }
 
@@ -136,6 +137,7 @@ namespace System.Net {
                        }
 
                        Close (false);
+                       disposed = true;
                }
 
                void Close (bool force)
@@ -143,7 +145,6 @@ namespace System.Net {
                        CheckDisposed ();
                        EndPointManager.RemoveListener (this);
                        Cleanup (force);
-                       disposed = true;
                }
 
                void Cleanup (bool close_existing)
@@ -215,7 +216,11 @@ namespace System.Net {
                                        wait_queue.RemoveAt (idx);
                        }
 
-                       return ares.GetContext (); // This will throw on error.
+                       HttpListenerContext context = ares.GetContext ();
+                       if (auth_schemes != AuthenticationSchemes.Anonymous) {
+                               context.ParseAuthentication ();
+                       }
+                       return context; // This will throw on error.
                }
 
                public HttpListenerContext GetContext ()
@@ -250,8 +255,8 @@ namespace System.Net {
                        if (disposed)
                                return;
 
-                       disposed = true;
                        Close (true); //TODO: Should we force here or not?
+                       disposed = true;
                }
 
                internal void CheckDisposed ()
@@ -266,7 +271,7 @@ namespace System.Net {
                        if (ctx_queue.Count == 0)
                                return null;
 
-                       HttpListenerContext context = ctx_queue [0];
+                       HttpListenerContext context = (HttpListenerContext) ctx_queue [0];
                        ctx_queue.RemoveAt (0);
                        return context;
                }
@@ -281,7 +286,7 @@ namespace System.Net {
                                if (wait_queue.Count == 0) {
                                        ctx_queue.Add (context);
                                } else {
-                                       ListenerAsyncResult ares = wait_queue [0];
+                                       ListenerAsyncResult ares = (ListenerAsyncResult) wait_queue [0];
                                        wait_queue.RemoveAt (0);
                                        ares.Complete (context);
                                }