Skip to content

Commit ab83f45

Browse files
committed
Now ServerProfile class depends on Validator class (in Utils.swift).
1 parent c15d81f commit ab83f45

File tree

1 file changed

+1
-36
lines changed

1 file changed

+1
-36
lines changed

ShadowsocksX-NG/ServerProfile.swift

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -196,42 +196,7 @@ class ServerProfile: NSObject, NSCopying {
196196
}
197197

198198
func isValid() -> Bool {
199-
func validateIpAddress(_ ipToValidate: String) -> Bool {
200-
201-
var sin = sockaddr_in()
202-
var sin6 = sockaddr_in6()
203-
204-
if ipToValidate.withCString({ cstring in inet_pton(AF_INET6, cstring, &sin6.sin6_addr) }) == 1 {
205-
// IPv6 peer.
206-
return true
207-
}
208-
else if ipToValidate.withCString({ cstring in inet_pton(AF_INET, cstring, &sin.sin_addr) }) == 1 {
209-
// IPv4 peer.
210-
return true
211-
}
212-
213-
return false;
214-
}
215-
216-
func validateDomainName(_ value: String) -> Bool {
217-
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])$"
218-
219-
if (value.range(of: validHostnameRegex, options: .regularExpression) != nil) {
220-
return true
221-
} else {
222-
return false
223-
}
224-
}
225-
226-
if !(validateIpAddress(serverHost) || validateDomainName(serverHost)){
227-
return false
228-
}
229-
230-
if password.isEmpty {
231-
return false
232-
}
233-
234-
return true
199+
return Validator.serverHost(serverHost) && Validator.password(password)
235200
}
236201

237202
private func makeLegacyURL() -> URL? {

0 commit comments

Comments
 (0)