WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 508ba69

Browse files
committed
fix routing parse
1 parent 910ed07 commit 508ba69

File tree

7 files changed

+100
-137
lines changed

7 files changed

+100
-137
lines changed

V2rayU.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
6D6DF06E32A1DC263EDF1A8E /* PacUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D6DF62A40417837EA751D88 /* PacUtils.swift */; };
4040
6D6DF2CF13D9FD3C7C6492A4 /* QrcodeWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D6DF12EA09D2D80788666D0 /* QrcodeWindow.swift */; };
4141
6D6DF6F065067CD879201FF9 /* Scanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D6DF87840CDA04AF0E9D36E /* Scanner.swift */; };
42+
6D6DF7C2F627A8BABECA4C32 /* tmp1.json in Resources */ = {isa = PBXBuildFile; fileRef = 6D6DFCE2F5044A1164CB14E3 /* tmp1.json */; };
43+
6D6DF872C0DECC082122D783 /* tmp.json in Resources */ = {isa = PBXBuildFile; fileRef = 6D6DF8E42F7E29CCBEFF5468 /* tmp.json */; };
4244
6D6DF8BFC33F97E9AFCA5A4B /* V2rayConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D6DFD9F5991B38B128888D6 /* V2rayConfig.swift */; };
4345
6D6DFB41BC9692C90A47F31B /* UserRulesWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D6DF587B6AF8CEE029E48BC /* UserRulesWindow.swift */; };
4446
6D6DFD4A3A226788760150F8 /* UserRulesWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6D6DF010124783F31646A895 /* UserRulesWindow.xib */; };
@@ -148,6 +150,8 @@
148150
6D6DF62A40417837EA751D88 /* PacUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PacUtils.swift; sourceTree = "<group>"; };
149151
6D6DF69C7CA7EBEFFE8E22D1 /* abp.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = abp.js; sourceTree = "<group>"; };
150152
6D6DF87840CDA04AF0E9D36E /* Scanner.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Scanner.swift; sourceTree = "<group>"; };
153+
6D6DF8E42F7E29CCBEFF5468 /* tmp.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = tmp.json; sourceTree = "<group>"; };
154+
6D6DFCE2F5044A1164CB14E3 /* tmp1.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = tmp1.json; sourceTree = "<group>"; };
151155
6D6DFD9F5991B38B128888D6 /* V2rayConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = V2rayConfig.swift; sourceTree = "<group>"; };
152156
6D6DFFB0110E2442FC8337A5 /* format.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = format.js; sourceTree = "<group>"; };
153157
8E15DFCD449143CCC309A1A0 /* Pods-V2rayU.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-V2rayU.debug.xcconfig"; path = "Pods/Target Support Files/Pods-V2rayU/Pods-V2rayU.debug.xcconfig"; sourceTree = "<group>"; };
@@ -242,6 +246,8 @@
242246
664EB372216C9A5E00B6AE0D /* Products */,
243247
A10EFB32D901F1862C489D12 /* Pods */,
244248
956412AC8DEB3D3D182A5D49 /* Frameworks */,
249+
6D6DF8E42F7E29CCBEFF5468 /* tmp.json */,
250+
6D6DFCE2F5044A1164CB14E3 /* tmp1.json */,
245251
);
246252
sourceTree = "<group>";
247253
};
@@ -486,6 +492,8 @@
486492
664EB377216C9A5F00B6AE0D /* Assets.xcassets in Resources */,
487493
66FEAD53217EE14C009DECF9 /* ConfigWindow.xib in Resources */,
488494
6D6DFD4A3A226788760150F8 /* UserRulesWindow.xib in Resources */,
495+
6D6DF872C0DECC082122D783 /* tmp.json in Resources */,
496+
6D6DF7C2F627A8BABECA4C32 /* tmp1.json in Resources */,
489497
);
490498
runOnlyForDeploymentPostprocessing = 0;
491499
};

V2rayU.xcodeproj/xcshareddata/xcschemes/V2rayUCmd.xcscheme

Lines changed: 0 additions & 125 deletions
This file was deleted.

V2rayU.xcodeproj/xcuserdata/yanue.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
<key>orderHint</key>
1515
<integer>0</integer>
1616
</dict>
17-
<key>V2rayUCmd.xcscheme_^#shared#^_</key>
18-
<dict>
19-
<key>orderHint</key>
20-
<integer>2</integer>
21-
</dict>
2217
<key>V2rayUHelper.xcscheme</key>
2318
<dict>
2419
<key>orderHint</key>
@@ -32,12 +27,12 @@
3227
<key>V2rayULauncher.xcscheme_^#shared#^_</key>
3328
<dict>
3429
<key>orderHint</key>
35-
<integer>13</integer>
30+
<integer>12</integer>
3631
</dict>
3732
<key>V2rayUTests.test.xcscheme</key>
3833
<dict>
3934
<key>orderHint</key>
40-
<integer>3</integer>
35+
<integer>2</integer>
4136
</dict>
4237
<key>V2rayUTests.testDecodeUrl.xcscheme</key>
4338
<dict>
@@ -82,6 +77,11 @@
8277
<key>orderHint</key>
8378
<integer>20</integer>
8479
</dict>
80+
<key>V2rayUTests.testV2ray.xcscheme</key>
81+
<dict>
82+
<key>orderHint</key>
83+
<integer>3</integer>
84+
</dict>
8585
</dict>
8686
<key>SuppressBuildableAutocreation</key>
8787
<dict>

V2rayU/ConfigWindow.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class ConfigWindowController: NSWindowController, NSWindowDelegate, NSTabViewDel
112112
// add default
113113
V2rayServer.add(remark: "default", json: "", isValid: false)
114114
}
115+
116+
self.configText.isAutomaticQuoteSubstitutionEnabled = false
115117
}
116118

117119
override func windowDidLoad() {

V2rayU/v2ray/V2rayConfig.swift

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ let jsSourceFormatConfig =
2121
if (!deStr) {
2222
return "error: cannot decode uri"
2323
}
24-
24+
2525
try {
2626
var obj = JSON.parse(deStr);
2727
if (!obj) {
2828
return "error: cannot parse json"
2929
}
30-
30+
3131
var v2rayConfig = {};
3232
// ordered keys
3333
v2rayConfig["log"] = obj.log;
@@ -85,6 +85,7 @@ class V2rayConfig: NSObject {
8585
var streamWs = WsSettings()
8686
var streamH2 = HttpSettings()
8787
var streamQuic = QuicSettings()
88+
var routing = V2rayRouting()
8889

8990
// tls
9091
var streamTlsSecurity = "none"
@@ -601,12 +602,85 @@ class V2rayConfig: NSObject {
601602
// ------------ parse outbound end -------------------------------------------
602603

603604
if json["routing"].dictionaryValue.count > 0 {
604-
// return "missing routing"
605+
v2ray.routing = self.parseRouting(jsonParams: json["routing"]);
605606
}
606607

607608
v2ray.transport = self.parseTransport(steamJson: json["transport"])
608609
}
609610

611+
func parseRouting(jsonParams: JSON) -> (V2rayRouting) {
612+
var routing = V2rayRouting()
613+
routing.settings.rules = []
614+
615+
if jsonParams["strategy"].stringValue.count > 0 {
616+
routing.strategy = jsonParams["strategy"].stringValue;
617+
}
618+
619+
if jsonParams["settings"].exists() {
620+
621+
if (V2rayRoutingSetting.domainStrategy(rawValue: jsonParams["settings"]["domainStrategy"].stringValue) != nil) {
622+
routing.settings.domainStrategy = V2rayRoutingSetting.domainStrategy(rawValue: jsonParams["settings"]["domainStrategy"].stringValue)!
623+
}
624+
625+
if jsonParams["settings"]["rules"].arrayValue.count > 0 {
626+
for subJson in jsonParams["settings"]["rules"].arrayValue {
627+
var rule = V2rayRoutingSettingRule()
628+
// reset
629+
rule.type = nil;
630+
rule.outboundTag = nil;
631+
rule.domain = nil;
632+
rule.ip = nil;
633+
634+
if (subJson["type"].stringValue.count > 0) {
635+
rule.type = subJson["type"].stringValue
636+
}
637+
if (subJson["outboundTag"].stringValue.count > 0) {
638+
rule.outboundTag = subJson["outboundTag"].stringValue
639+
}
640+
if (subJson["domain"].arrayValue.count > 0) {
641+
rule.domain = subJson["domain"].arrayValue.map {
642+
$0.stringValue
643+
}
644+
}
645+
if (subJson["ip"].arrayValue.count > 0) {
646+
rule.ip = subJson["ip"].arrayValue.map {
647+
$0.stringValue
648+
}
649+
}
650+
if (subJson["port"].stringValue.count > 0) {
651+
rule.port = subJson["port"].stringValue
652+
}
653+
if (subJson["network"].stringValue.count > 0) {
654+
rule.network = subJson["network"].stringValue
655+
}
656+
if (subJson["source"].arrayValue.count > 0) {
657+
rule.source = subJson["source"].arrayValue.map {
658+
$0.stringValue
659+
}
660+
}
661+
if (subJson["user"].arrayValue.count > 0) {
662+
rule.user = subJson["user"].arrayValue.map {
663+
$0.stringValue
664+
}
665+
}
666+
if (subJson["inboundTag"].arrayValue.count > 0) {
667+
rule.inboundTag = subJson["inboundTag"].arrayValue.map {
668+
$0.stringValue
669+
}
670+
}
671+
if (subJson["protocol"].arrayValue.count > 0) {
672+
rule.`protocol` = subJson["protocol"].arrayValue.map {
673+
$0.stringValue
674+
}
675+
}
676+
routing.settings.rules.append(rule)
677+
}
678+
}
679+
}
680+
681+
return routing
682+
}
683+
610684
// parse inbound from json
611685
func parseInbound(jsonParams: JSON) -> (V2rayInbound) {
612686
var v2rayInbound = V2rayInbound()

V2rayU/v2ray/v2rayInbound.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ extension V2rayInbound {
7575
try container.encode(port, forKey: .port)
7676
try container.encode(listen, forKey: .listen)
7777
try container.encode(`protocol`, forKey: .`protocol`)
78-
try container.encode(tag, forKey: .tag)
78+
79+
// ignore nil
80+
if tag != nil {
81+
try container.encode(tag, forKey: .tag)
82+
}
7983

8084
// ignore nil
8185
if streamSettings != nil {
@@ -134,7 +138,7 @@ struct V2rayInboundHttp: Codable {
134138
var timeout: Int = 360
135139
var allowTransparent: Bool?
136140
var userLevel: Int?
137-
var accounts:[V2rayInboundHttpAccount]?
141+
var accounts: [V2rayInboundHttpAccount]?
138142
}
139143

140144
struct V2rayInboundHttpAccount: Codable {

screenshot/1.png

-10.5 KB
Loading

0 commit comments

Comments
 (0)