From ab83f45ac2d2a9ba60c3d0927ae1a45d431fc5e3 Mon Sep 17 00:00:00 2001 From: yangziy Date: Thu, 27 Sep 2018 18:49:53 +0800 Subject: [PATCH] Now ServerProfile class depends on Validator class (in Utils.swift). --- ShadowsocksX-NG/ServerProfile.swift | 37 +---------------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/ShadowsocksX-NG/ServerProfile.swift b/ShadowsocksX-NG/ServerProfile.swift index b66da167e..6fd7b1f27 100644 --- a/ShadowsocksX-NG/ServerProfile.swift +++ b/ShadowsocksX-NG/ServerProfile.swift @@ -196,42 +196,7 @@ class ServerProfile: NSObject, NSCopying { } func isValid() -> Bool { - func validateIpAddress(_ ipToValidate: String) -> Bool { - - var sin = sockaddr_in() - var sin6 = sockaddr_in6() - - if ipToValidate.withCString({ cstring in inet_pton(AF_INET6, cstring, &sin6.sin6_addr) }) == 1 { - // IPv6 peer. - return true - } - else if ipToValidate.withCString({ cstring in inet_pton(AF_INET, cstring, &sin.sin_addr) }) == 1 { - // IPv4 peer. - return true - } - - return false; - } - - func validateDomainName(_ value: String) -> Bool { - let validHostnameRegex = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$" - - if (value.range(of: validHostnameRegex, options: .regularExpression) != nil) { - return true - } else { - return false - } - } - - if !(validateIpAddress(serverHost) || validateDomainName(serverHost)){ - return false - } - - if password.isEmpty { - return false - } - - return true + return Validator.serverHost(serverHost) && Validator.password(password) } private func makeLegacyURL() -> URL? {