Merge pull request #4781 from kumpera/unaligned-cleanup-1
[mono.git] / mcs / class / System / System.Net / ListenerPrefix.cs
index d4a55e033ef6568dddb67b0f82a4154f0b1ac757..f7cb7b381458a7b3b8d621f76111e478cddc7cad 100644 (file)
@@ -27,8 +27,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if SECURITY_DEP
-
 namespace System.Net {
        sealed class ListenerPrefix
        {
@@ -86,91 +84,77 @@ namespace System.Net {
                        return original.GetHashCode ();
                }
 
-        void Parse(string uri)
-        {
-            ushort default_port = 80;
-            if (uri.StartsWith("https://"))
-            {
-                default_port = 443;
-                secure = true;
-            }
-
-            int length = uri.Length;
-            int start_host = uri.IndexOf(':') + 3;
-            if (start_host >= length)
-                throw new ArgumentException("No host specified.");
-
-            int startPort = uri.IndexOf(':', start_host, length - start_host);
-            if (uri[start_host] == '[')
-            {
-                startPort = uri.IndexOf("]:") + 1;
-            }
-            if (start_host == startPort)
-                throw new ArgumentException("No host specified.");
-
-            int root = uri.IndexOf('/', start_host, length - start_host);
-            if (root == -1)
-                throw new ArgumentException("No path specified.");
-
-            if (startPort > 0)
-            {
-                host = uri.Substring(start_host, startPort - start_host).Trim('[', ']');
-                port = UInt16.Parse(uri.Substring(startPort + 1, root - startPort - 1));
-            }
-            else
-            {
-                host = uri.Substring(start_host, root - start_host).Trim('[', ']');
-                port = default_port;
-            }
-            path = uri.Substring(root);
-
-            if (path.Length != 1)
-                path = path.Substring(0, path.Length - 1);
-        }
-
-        public static void CheckUri(string uri)
-        {
-            if (uri == null)
-                throw new ArgumentNullException("uriPrefix");
-
-            if (!uri.StartsWith("http://") && !uri.StartsWith("https://"))
-                throw new ArgumentException("Only 'http' and 'https' schemes are supported.");
-
-            int length = uri.Length;
-            int start_host = uri.IndexOf(':') + 3;
-            if (start_host >= length)
-                throw new ArgumentException("No host specified.");
-
-
-            int startPort = uri.IndexOf(':', start_host, length - start_host);
-            if (uri[start_host] == '[')
-            {
-                startPort = uri.IndexOf("]:") + 1;
-            }
-            if (start_host == startPort)
-                throw new ArgumentException("No host specified.");
-            int root = uri.IndexOf('/', start_host, length - start_host);
-            if (root == -1)
-                throw new ArgumentException("No path specified.");
-
-            if (startPort > 0)
-            {
-                try
-                {
-                    int p = Int32.Parse(uri.Substring(startPort + 1, root - startPort - 1));
-                    if (p <= 0 || p >= 65536)
-                        throw new Exception();
-                }
-                catch
-                {
-                    throw new ArgumentException("Invalid port.");
-                }
-            }
-
-            if (uri[uri.Length - 1] != '/')
-                throw new ArgumentException("The prefix must end with '/'");
-        }
-    }
-}
-#endif
+               void Parse (string uri)
+               {
+                       ushort default_port = 80;
+                       if (uri.StartsWith ("https://")) {
+                               default_port = 443;
+                               secure = true;
+                       }
+
+                       int length = uri.Length;
+                       int start_host = uri.IndexOf (':') + 3;
+                       if (start_host >= length)
+                               throw new ArgumentException ("No host specified.");
+
+                       int startPort = uri.IndexOf (':', start_host, length - start_host);
+                       if (uri [start_host] == '[') {
+                               startPort = uri.IndexOf ("]:") + 1;
+                       }
+                       if (start_host == startPort)
+                               throw new ArgumentException ("No host specified.");
+
+                       int root = uri.IndexOf ('/', start_host, length - start_host);
+                       if (root == -1)
+                               throw new ArgumentException ("No path specified.");
+
+                       if (startPort > 0) {
+                               host = uri.Substring (start_host, startPort - start_host).Trim ('[', ']');
+                               port = UInt16.Parse (uri.Substring (startPort + 1, root - startPort - 1));
+                       } else {
+                               host = uri.Substring (start_host, root - start_host).Trim ('[', ']');
+                               port = default_port;
+                       }
+                       path = uri.Substring (root);
+
+                       if (path.Length != 1)
+                               path = path.Substring (0, path.Length - 1);
+               }
 
+               public static void CheckUri (string uri)
+               {
+                       if (uri == null)
+                               throw new ArgumentNullException ("uriPrefix");
+
+                       if (!uri.StartsWith ("http://") && !uri.StartsWith ("https://"))
+                               throw new ArgumentException ("Only 'http' and 'https' schemes are supported.");
+
+                       int length = uri.Length;
+                       int start_host = uri.IndexOf (':') + 3;
+                       if (start_host >= length)
+                               throw new ArgumentException ("No host specified.");
+
+                       int startPort = uri.IndexOf (':', start_host, length - start_host);
+                       if (uri [start_host] == '[')
+                               startPort = uri.IndexOf ("]:") + 1;
+                       if (start_host == startPort)
+                               throw new ArgumentException ("No host specified.");
+                       int root = uri.IndexOf ('/', start_host, length - start_host);
+                       if (root == -1)
+                               throw new ArgumentException ("No path specified.");
+
+                       if (startPort > 0) {
+                               try {
+                                       int p = Int32.Parse (uri.Substring (startPort + 1, root - startPort - 1));
+                                       if (p <= 0 || p >= 65536)
+                                               throw new Exception ();
+                               } catch {
+                                       throw new ArgumentException ("Invalid port.");
+                               }
+                       }
+
+                       if (uri [uri.Length - 1] != '/')
+                               throw new ArgumentException ("The prefix must end with '/'");
+               }
+       }
+}