Merge pull request #2543 from ermshiperete/Xamarin-31021
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Channels / ChannelServices.cs
index 124d01a44294f656c7278191d65f4bf86d5acec5..d15ea7d943fbbd99a5054ef4c9bc62edd1b9d23c 100644 (file)
@@ -32,6 +32,7 @@
 //
 
 using System.Collections;
+using System.Collections.Generic;
 using System.Reflection;
 using System.Runtime.Remoting;
 using System.Runtime.Remoting.Channels;
@@ -70,6 +71,7 @@ namespace System.Runtime.Remoting
 
 namespace System.Runtime.Remoting.Channels
 {
+       [System.Runtime.InteropServices.ComVisible (true)]
        public sealed class ChannelServices
        {
                private static ArrayList registeredChannels = new ArrayList ();
@@ -132,7 +134,15 @@ namespace System.Runtime.Remoting.Channels
                        }
                        else {
                                foreach (object data in channelDataArray) {
-                                       IMessageSink sink = sender.CreateMessageSink (url, data, out objectUri);
+                                       IMessageSink sink;
+
+                                       if (data is IChannelDataStore) {
+                                               // Don't provide the url in this case, since some channels won't
+                                               // check the channelData parameter if the url is not null.
+                                               sink = sender.CreateMessageSink (null, data, out objectUri);
+                                       } else {
+                                               sink = sender.CreateMessageSink (url, data, out objectUri);
+                                       }
                                        if (sink != null) return sink;          
                                }
                        }
@@ -144,12 +154,15 @@ namespace System.Runtime.Remoting.Channels
                        get {
                                lock (registeredChannels.SyncRoot)
                                {
-                                       IChannel[] channels = new IChannel[registeredChannels.Count];
-       
-                                       for (int i = 0; i < registeredChannels.Count; i++)
-                                               channels[i] = (IChannel) registeredChannels[i];
-       
-                                       return channels;
+                                       var list = new List<IChannel> ();
+                                       
+                                       for (int i = 0; i < registeredChannels.Count; i++) {
+                                               IChannel ch = (IChannel) registeredChannels[i];
+                                               if (ch is CrossAppDomainChannel) continue;
+                                               list.Add (ch);
+                                       }
+
+                                       return list.ToArray ();
                                }
                        }
                }
@@ -201,7 +214,7 @@ namespace System.Runtime.Remoting.Channels
                                
                        ClientIdentity ident = (ClientIdentity) RemotingServices.GetRealProxy (obj).ObjectIdentity;
                        IMessageSink sink = ident.ChannelSink;
-                       ArrayList dics = new ArrayList ();
+                       var dics = new List<IDictionary> ();
                        
                        while (sink != null && !(sink is IClientChannelSink))
                                sink = sink.NextSink;
@@ -216,7 +229,7 @@ namespace System.Runtime.Remoting.Channels
                                csink = csink.NextChannelSink;
                        }
 
-                       IDictionary[] adics = (IDictionary[]) dics.ToArray (typeof(IDictionary[]));
+                       IDictionary[] adics = dics.ToArray ();
                        return new AggregateDictionary (adics);
                }
 
@@ -225,7 +238,7 @@ namespace System.Runtime.Remoting.Channels
                        string uri = RemotingServices.GetObjectUri (obj);
                        if (uri == null) return new string [0];
 
-                       ArrayList list = new ArrayList ();
+                       var list = new List<string> ();
 
                        lock (registeredChannels.SyncRoot)
                        {
@@ -239,11 +252,27 @@ namespace System.Runtime.Remoting.Channels
                                }
                        }
                        
-                       return  (string[]) list.ToArray (typeof(string));
+                       return list.ToArray ();
                }
 
+               [Obsolete ("Use RegisterChannel(IChannel,Boolean)")]
                public static void RegisterChannel (IChannel chnl)
                {
+                       RegisterChannel (chnl, false);
+               }
+
+               public static void RegisterChannel (IChannel chnl, bool ensureSecurity)
+               {
+                       if (chnl == null)
+                               throw new ArgumentNullException ("chnl");
+
+                       if (ensureSecurity) {
+                               ISecurableChannel securable = chnl as ISecurableChannel;
+                               if (securable == null)
+                                       throw new RemotingException (String.Format ("Channel {0} is not securable while ensureSecurity is specified as true", chnl.ChannelName));
+                               securable.IsSecured = true;
+                       }
+                       
                        // Put the channel in the correct place according to its priority.
                        // Since there are not many channels, a linear search is ok.
 
@@ -263,9 +292,10 @@ namespace System.Runtime.Remoting.Channels
                                
                                if (pos != -1) registeredChannels.Insert (pos, chnl);
                                else registeredChannels.Add (chnl);
-                               
+
                                IChannelReceiver receiver = chnl as IChannelReceiver;
-                               if (receiver != null) receiver.StartListening (null);
+                               if (receiver != null && oldStartModeTypes.Contains (chnl.GetType().ToString ()))
+                                       receiver.StartListening (null);
                        }
                }
 
@@ -373,10 +403,8 @@ namespace System.Runtime.Remoting.Channels
                                return null;
                        }
                        
-#if NET_1_1
                        if (RemotingConfiguration.CustomErrorsEnabled (IsLocalCall (msg)))
                                replySink = new ExceptionFilterSink (msg, replySink);
-#endif
                        
                        return _crossContextSink.AsyncProcessMessage (msg, replySink);          
                }
@@ -395,7 +423,6 @@ namespace System.Runtime.Remoting.Channels
 
                internal static IMessage CheckReturnMessage (IMessage callMsg, IMessage retMsg)
                {
-#if NET_1_1
                        IMethodReturnMessage ret = retMsg as IMethodReturnMessage;
                        if (ret != null && ret.Exception != null)
                        {
@@ -405,7 +432,6 @@ namespace System.Runtime.Remoting.Channels
                                        retMsg = new MethodResponse (ex, (IMethodCallMessage)callMsg);
                                }
                        }
-#endif
                        return retMsg;
                }
                
@@ -446,7 +472,7 @@ namespace System.Runtime.Remoting.Channels
 
                internal static object [] GetCurrentChannelInfo ()
                {
-                       ArrayList list = new ArrayList ();
+                       var list = new List<object> ();
                        
                        lock (registeredChannels.SyncRoot)
                        {
@@ -461,8 +487,14 @@ namespace System.Runtime.Remoting.Channels
                                }
                        }
                        
-                       return  list.ToArray ();
+                       return list.ToArray ();
                }
+
+               // Back compatibility fix. StartListener will be called for the types listed here               
+               static IList oldStartModeTypes = new string[] {
+                       "Novell.Zenworks.Zmd.Public.UnixServerChannel",
+                       "Novell.Zenworks.Zmd.Public.UnixChannel"
+               };
        }
        
        internal class ExceptionFilterSink: IMessageSink