// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if SECURITY_DEP
-
namespace System.Net {
sealed class ListenerPrefix
{
if (start_host >= length)
throw new ArgumentException ("No host specified.");
- int colon = uri.IndexOf (':', start_host, length - start_host);
- int root;
- if (colon > 0) {
- host = uri.Substring (start_host, colon - start_host);
- root = uri.IndexOf ('/', colon, length - colon);
- port = (ushort) Int32.Parse (uri.Substring (colon + 1, root - colon - 1));
- path = uri.Substring (root);
+ 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 {
- root = uri.IndexOf ('/', start_host, length - start_host);
- host = uri.Substring (start_host, root - start_host);
+ host = uri.Substring (start_host, root - start_host).Trim ('[', ']');
port = default_port;
- path = uri.Substring (root);
}
+ path = uri.Substring (root);
+
if (path.Length != 1)
path = path.Substring (0, path.Length - 1);
}
if (uri == null)
throw new ArgumentNullException ("uriPrefix");
- if(!uri.StartsWith ("http://") && !uri.StartsWith ("https://"))
+ if (!uri.StartsWith ("http://") && !uri.StartsWith ("https://"))
throw new ArgumentException ("Only 'http' and 'https' schemes are supported.");
int length = uri.Length;
if (start_host >= length)
throw new ArgumentException ("No host specified.");
- int colon = uri.IndexOf (':', start_host, length - start_host);
- if (start_host == colon)
+ 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.");
- int root;
- if (colon > 0) {
- root = uri.IndexOf ('/', colon, length - colon);
- if (root == -1)
- throw new ArgumentException ("No path specified.");
-
+ if (startPort > 0) {
try {
- int p = Int32.Parse (uri.Substring (colon + 1, root - colon - 1));
+ 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.");
}
- } else {
- root = uri.IndexOf ('/', start_host, length - start_host);
- if (root == -1)
- throw new ArgumentException ("No path specified.");
}
if (uri [uri.Length - 1] != '/')
}
}
}
-#endif
-