Skip to content

Commit

Permalink
Now ServerProfile class depends on Validator class (in Utils.swift).
Browse files Browse the repository at this point in the history
  • Loading branch information
yangziy committed Sep 27, 2018
1 parent c15d81f commit ab83f45
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions ShadowsocksX-NG/ServerProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down

0 comments on commit ab83f45

Please sign in to comment.