Encode kcptun infomations to ss url.

This commit is contained in:
Charlie Qiu
2017-01-12 11:35:05 +08:00
parent f7cca35948
commit 5c1db71ab7
2 changed files with 66 additions and 0 deletions

View File

@ -71,4 +71,54 @@ class KcptunProfile: NSObject {
]
return conf
}
func urlQueryItems() -> [URLQueryItem] {
return [
URLQueryItem(name: "mode", value: mode),
URLQueryItem(name: "key", value: key),
URLQueryItem(name: "crypt", value: crypt),
URLQueryItem(name: "datashard", value: "\(datashard)"),
URLQueryItem(name: "parityshard", value: "\(parityshard)"),
URLQueryItem(name: "nocomp", value: nocomp.description),
]
}
func loadUrlQueryItems(items: [URLQueryItem]) {
for item in items {
switch item.name {
case "mode":
if let v = item.value {
mode = v
}
case "key":
if let v = item.value {
key = v
}
case "crypt":
if let v = item.value {
crypt = v
}
case "datashard":
if let v = item.value {
if let vv = uint(v) {
datashard = vv
}
}
case "parityshard":
if let v = item.value {
if let vv = uint(v) {
parityshard = vv
}
}
case "nocomp":
if let v = item.value {
if let vv = Bool(v) {
nocomp = vv
}
}
default:
continue
}
}
}
}

View File

@ -81,6 +81,16 @@ class ServerProfile: NSObject, NSCopying {
.filter({ $0.name == "OTA" }).first?.value {
ota = NSString(string: otaStr).boolValue
}
if let enabledKcptunStr = parsedUrl.queryItems?
.filter({ $0.name == "Kcptun" }).first?.value {
enabledKcptun = NSString(string: enabledKcptunStr).boolValue
}
if enabledKcptun {
if let items = parsedUrl.queryItems {
self.kcptunProfile.loadUrlQueryItems(items: items)
}
}
}
public func copy(with zone: NSZone? = nil) -> Any {
@ -219,6 +229,12 @@ class ServerProfile: NSObject, NSCopying {
url.queryItems = [URLQueryItem(name: "Remark", value: remark),
URLQueryItem(name: "OTA", value: ota.description)]
if enabledKcptun {
url.queryItems?.append(contentsOf: [
URLQueryItem(name: "Kcptun", value: enabledKcptun.description),
])
url.queryItems?.append(contentsOf: kcptunProfile.urlQueryItems())
}
let parts = url.string?.replacingOccurrences(
of: "//", with: "",