Merge pull request #297 from ermshiperete/4959
[mono.git] / mcs / class / corlib / System.Runtime.Remoting / RemotingConfiguration.cs
index 7d861b0401257d9d5d2bb0cddeca6bea387ff84c..46e71422e04baf501f3327fe6cfa3d393355a068 100644 (file)
@@ -31,6 +31,7 @@
 //
 
 using System;
+using System.Globalization;
 using System.IO;
 using System.Reflection;
 using System.Collections;
@@ -41,19 +42,14 @@ using Mono.Xml;
 
 namespace System.Runtime.Remoting
 {      
-       public class RemotingConfiguration
+       [System.Runtime.InteropServices.ComVisible (true)]
+       public static class RemotingConfiguration
        {
-               //
-               // Private constructor: nobody instantiates this.
-               //
-               private RemotingConfiguration ()
-               {
-               }
                
                static string applicationID = null;
                static string applicationName = null;
-               static string configFile = "";
-               static SmallXmlParser parser = null; 
+//             static string configFile = "";
+//             static SmallXmlParser parser = null; 
                static string processGuid = null;
                static bool defaultConfigRead = false;
                static bool defaultDelayedConfigRead = false;
@@ -73,27 +69,25 @@ namespace System.Runtime.Remoting
                public static string ApplicationId 
                {
                        get 
-                       { 
-                               applicationID = AppDomain.CurrentDomain.SetupInformation.ApplicationName; 
+                       {
+                               applicationID = ApplicationName; 
                                return applicationID;
                        }
                }
                
                public static string ApplicationName 
                {
-                       get { 
-                               try {
-                                       applicationName = AppDomain.CurrentDomain.SetupInformation.ApplicationName; 
-                               }
-                               catch (Exception e) {
-                                       throw e;
-                               }
-                               // We return null if the application name has not been set.
-                               return null;
-                       }
+                       get { return applicationName; }
                        set { applicationName = value; }
                }
-               
+
+               [MonoTODO]
+               public static CustomErrorsModes CustomErrorsMode
+               {
+                       get { throw new NotImplementedException (); }
+                       set { throw new NotImplementedException (); }
+               }
+
                public static string ProcessId 
                {
                        get {
@@ -107,21 +101,26 @@ namespace System.Runtime.Remoting
 
                // public methods
                
-               public static void Configure (string filename) 
+               [MonoTODO ("ensureSecurity support has not been implemented")]
+               public static void Configure (string filename, bool ensureSecurity) 
                {
-                       lock (channelTemplates)
-                       {
-                               if (!defaultConfigRead)
-                               {
+                       lock (channelTemplates) {
+                               if (!defaultConfigRead) {
                                        ReadConfigFile (Environment.GetMachineConfigPath ());
                                        defaultConfigRead = true;
                                }
-                               
+
                                if (filename != null)
                                        ReadConfigFile (filename);
                        }
                }
 
+               [Obsolete ("Use Configure(String,Boolean)")]
+               public static void Configure (string filename) 
+               {
+                       Configure (filename, false);
+               }
+
                private static void ReadConfigFile (string filename)
                {
                        try
@@ -134,7 +133,7 @@ namespace System.Runtime.Remoting
                        }
                        catch (Exception ex)
                        {
-                               throw new RemotingException ("Configuration file '" + filename + "' could not be loaded: " + ex.Message);
+                               throw new RemotingException ("Configuration file '" + filename + "' could not be loaded: " + ex.Message, ex);
                        }
                }
                
@@ -193,19 +192,19 @@ namespace System.Runtime.Remoting
                        }
                }
 
-               public static bool IsActivationAllowed (Type serverType) 
+               public static bool IsActivationAllowed (Type svrType) 
                {
                        lock (channelTemplates)
                        {
-                               return activatedServiceEntries.ContainsKey (serverType);
+                               return activatedServiceEntries.ContainsKey (svrType);
                        }
                }
 
-               public static ActivatedClientTypeEntry IsRemotelyActivatedClientType (Type serviceType) 
+               public static ActivatedClientTypeEntry IsRemotelyActivatedClientType (Type svrType) 
                {
                        lock (channelTemplates)
                        {
-                               return activatedClientEntries [serviceType] as ActivatedClientTypeEntry;
+                               return activatedClientEntries [svrType] as ActivatedClientTypeEntry;
                        }
                }
 
@@ -214,11 +213,11 @@ namespace System.Runtime.Remoting
                        return IsRemotelyActivatedClientType (Assembly.Load(assemblyName).GetType (typeName));
                }
 
-               public static WellKnownClientTypeEntry IsWellKnownClientType (Type serviceType) 
+               public static WellKnownClientTypeEntry IsWellKnownClientType (Type svrType) 
                {
                        lock (channelTemplates)
                        {
-                               return wellKnownClientEntries [serviceType] as WellKnownClientTypeEntry;
+                               return wellKnownClientEntries [svrType] as WellKnownClientTypeEntry;
                        }
                }
 
@@ -280,9 +279,9 @@ namespace System.Runtime.Remoting
                        }
                }
 
-               public static void RegisterWellKnownServiceType (Type type, string objectUrl, WellKnownObjectMode mode) 
+               public static void RegisterWellKnownServiceType (Type type, string objectUri, WellKnownObjectMode mode) 
                {
-                       RegisterWellKnownServiceType (new WellKnownServiceTypeEntry (type, objectUrl, mode));
+                       RegisterWellKnownServiceType (new WellKnownServiceTypeEntry (type, objectUri, mode));
                }
 
                public static void RegisterWellKnownServiceType (WellKnownServiceTypeEntry entry) 
@@ -376,10 +375,16 @@ namespace System.Runtime.Remoting
 
                internal static void SetCustomErrorsMode (string mode)
                {
-                       if (mode != "on" && mode != "off" && mode != "remoteOnly")
+                       if (mode == null)
+                               throw new RemotingException ("mode attribute is required");
+
+                       // the mode is case insensitive
+                       string m = mode.ToLower ();
+
+                       if (m != "on" && m != "off" && m != "remoteonly")
                                throw new RemotingException ("Invalid custom error mode: " + mode);
                                
-                       _errorMode = mode;
+                       _errorMode = m;
                }
        }
 
@@ -416,10 +421,11 @@ namespace System.Runtime.Remoting
                
                bool CheckPath (string path)
                {
-                       if (path.StartsWith ("/"))
+                       CompareInfo ci = CultureInfo.InvariantCulture.CompareInfo;
+                       if (ci.IsPrefix (path, "/", CompareOptions.Ordinal))
                                return path == currentXmlPath;
                        else
-                               return currentXmlPath.EndsWith (path);
+                               return ci.IsSuffix (currentXmlPath, path, CompareOptions.Ordinal);
                }
                
                public void OnStartParsing (SmallXmlParser parser) {}
@@ -439,7 +445,7 @@ namespace System.Runtime.Remoting
                        }
                        catch (Exception ex)
                        {
-                               throw new RemotingException ("Error in element " + name + ": " + ex.Message);
+                               throw new RemotingException ("Error in element " + name + ": " + ex.Message, ex);
                        }
                }
                
@@ -581,8 +587,8 @@ namespace System.Runtime.Remoting
                        if (currentProviderData != null)
                        {
                                currentProviderData.Pop ();
-                               if (currentProviderData.Count > 0) return;
-                               currentProviderData = null;
+                               if (currentProviderData.Count == 0) 
+                                       currentProviderData = null;
                        }
                        
                        currentXmlPath = currentXmlPath.Substring (0, currentXmlPath.Length - name.Length - 1);