Encode kcptun infomations to ss url.
This commit is contained in:
@ -71,4 +71,54 @@ class KcptunProfile: NSObject {
|
|||||||
]
|
]
|
||||||
return conf
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,16 @@ class ServerProfile: NSObject, NSCopying {
|
|||||||
.filter({ $0.name == "OTA" }).first?.value {
|
.filter({ $0.name == "OTA" }).first?.value {
|
||||||
ota = NSString(string: otaStr).boolValue
|
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 {
|
public func copy(with zone: NSZone? = nil) -> Any {
|
||||||
@ -219,6 +229,12 @@ class ServerProfile: NSObject, NSCopying {
|
|||||||
|
|
||||||
url.queryItems = [URLQueryItem(name: "Remark", value: remark),
|
url.queryItems = [URLQueryItem(name: "Remark", value: remark),
|
||||||
URLQueryItem(name: "OTA", value: ota.description)]
|
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(
|
let parts = url.string?.replacingOccurrences(
|
||||||
of: "//", with: "",
|
of: "//", with: "",
|
||||||
|
Reference in New Issue
Block a user