Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 0908916

Browse files
committed
ssd:// support continued
1 parent ed617f9 commit 0908916

File tree

5 files changed

+59
-33
lines changed

5 files changed

+59
-33
lines changed

V2RayX/AppDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ - (IBAction)updateSubscriptions:(id)sender {
566566
_subsOutbounds = [[NSMutableArray alloc] init];
567567
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
568568
for (NSString* link in self.subscriptions) {
569-
NSDictionary* r = [ConfigImporter importFromSubscriptionOfV2RayN:link];
569+
NSDictionary* r = [ConfigImporter importFromHTTPSubscription:link];
570570
if (r) {
571571
for (ServerProfile* p in r[@"vmess"]) {
572572
[self.subsOutbounds addObject:[p outboundProfile]];

V2RayX/ConfigImporter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
1414
+ (NSMutableDictionary*)ssOutboundFromSSLink:(NSString*)link;
1515
+ (NSMutableDictionary*)ssOutboundFromSSConfig:(NSDictionary*)jsonObject;
1616
+ (ServerProfile*)importFromVmessOfV2RayN:(NSString*)vmessStr;
17-
+ (NSMutableDictionary*)importFromSubscriptionOfV2RayN:(NSString*)httpLink;
17+
+ (NSMutableDictionary*)importFromHTTPSubscription:(NSString*)httpLink;
1818
+ (NSMutableDictionary*)importFromStandardConfigFiles:(NSArray*)files;
1919
+ (NSMutableDictionary*)validateRuleSet:(NSMutableDictionary*)set;
2020
+ (NSMutableDictionary* _Nonnull)importFromSubscriptionOfSSD: (NSString* _Nonnull)ssdLink;

V2RayX/ConfigImporter.m

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,62 @@
99

1010
@implementation ConfigImporter
1111

12-
+ (NSString*)decodeBase64String:(NSString*)encoded {
12+
+ (NSString* _Nonnull)decodeBase64String:(NSString*)encoded {
13+
if (!encoded || ![encoded isKindOfClass:[NSString class]] || encoded.length == 0) {
14+
return @"";
15+
}
1316
NSMutableString* fixed = [encoded mutableCopy];
1417
NSInteger numAdd = encoded.length % 4;
1518
for (int i = 0; i < numAdd; i += 1) {
1619
[fixed appendString:@"="];
1720
}
18-
NSData* decodedData = [[NSData alloc] initWithBase64EncodedString:fixed options:NSDataBase64DecodingIgnoreUnknownCharacters];
19-
return [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
21+
@try {
22+
NSData* decodedData = [[NSData alloc] initWithBase64EncodedString:fixed options:NSDataBase64DecodingIgnoreUnknownCharacters];
23+
NSString* decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
24+
assert(decodedString != nil);
25+
return decodedString;
26+
} @catch (NSException *exception) {
27+
return @"";
28+
}
2029
}
2130

2231
+ (NSDictionary*)parseLegacySSLink:(NSString*)link {
2332
//http://shadowsocks.org/en/config/quick-guide.html
2433
@try {
2534
NSString* encoded = [[link stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] substringFromIndex:5];
26-
NSString* encodedRemoveTag = [encoded componentsSeparatedByString:@"#"][0];
35+
NSArray* hashTagSeperatedParts = [encoded componentsSeparatedByString:@"#"];
36+
NSString* encodedRemoveTag = hashTagSeperatedParts[0];
2737
NSData* decodedData = [[NSData alloc] initWithBase64EncodedString:encodedRemoveTag options:0];
2838
NSString* decoded = [[NSString alloc] initWithData: decodedData
2939
encoding:NSUTF8StringEncoding];
3040

3141
NSArray* parts = [decoded componentsSeparatedByString:@"@"];
32-
NSArray* server_port = [parts[1] componentsSeparatedByString:@":"];
33-
NSMutableArray* method_password = [[parts[0] componentsSeparatedByString:@":"] mutableCopy];
34-
NSString* method = method_password[0];
35-
[method_password removeObjectAtIndex:0];
36-
return @{
37-
@"server":server_port[0],
38-
@"server_port":server_port[1],
39-
@"password": [method_password componentsJoinedByString:@":"],
40-
@"method":method};
42+
NSArray* addressAndPort = [parts[1] componentsSeparatedByString:@":"];
43+
NSMutableArray* methodAndPassword = [[parts[0] componentsSeparatedByString:@":"] mutableCopy];
44+
NSString* method = methodAndPassword[0];
45+
[methodAndPassword removeObjectAtIndex:0];
46+
47+
NSNumberFormatter* f = [[NSNumberFormatter alloc] init];
48+
f.numberStyle = NSNumberFormatterDecimalStyle;
49+
NSNumber *port = [f numberFromString:addressAndPort[1]];
50+
51+
if (hashTagSeperatedParts.count == 1) {
52+
return @{
53+
@"server":addressAndPort[0],
54+
@"server_port":port,
55+
@"password": [methodAndPassword componentsJoinedByString:@":"],
56+
@"method":method};
57+
} else {
58+
return @{
59+
@"server":addressAndPort[0],
60+
@"server_port":port,
61+
@"password": [methodAndPassword componentsJoinedByString:@":"],
62+
@"method":method,
63+
@"tag":hashTagSeperatedParts[1]
64+
};
65+
}
4166
} @catch (NSException *exception) {
4267
return nil;
43-
} @finally {
44-
;
4568
}
4669
}
4770

@@ -70,7 +93,6 @@ + (NSDictionary*)parseStandardSSLink:(NSString*)link {
7093
if (!port) {
7194
return nil;
7295
}
73-
7496
return @{
7597
@"server":hostInfo[0],
7698
@"server_port":port,
@@ -80,12 +102,10 @@ + (NSDictionary*)parseStandardSSLink:(NSString*)link {
80102
};
81103
} @catch (NSException *exception) {
82104
return nil;
83-
} @finally {
84-
;
85105
}
86106
}
87107

88-
+ (NSMutableDictionary*)ssOutboundFromSSLink:(NSString*)link {
108+
+ (NSMutableDictionary* )ssOutboundFromSSLink:(NSString*)link {
89109
NSDictionary* parsed = [ConfigImporter parseStandardSSLink:link];
90110
if (parsed) {
91111
return [ConfigImporter ssOutboundFromSSConfig:parsed];
@@ -257,7 +277,7 @@ + (NSMutableDictionary*)importFromStandardConfigFiles:(NSArray*)files {
257277
return result;
258278
}
259279

260-
+ (NSMutableDictionary*)importFromSubscriptionOfV2RayN: (NSString*)httpLink {
280+
+ (NSMutableDictionary*)importFromHTTPSubscription: (NSString*)httpLink {
261281
// https://blog.csdn.net/yi_zz32/article/details/48769487
262282
NSMutableDictionary* result = [@{@"vmess": @[], @"other": @[]} mutableDeepCopy];
263283
if (![@"http" isEqualToString:[httpLink substringToIndex:4]]) {
@@ -286,6 +306,8 @@ + (NSMutableDictionary*)importFromSubscriptionOfV2RayN: (NSString*)httpLink {
286306
[result[@"other"] addObject:outbound];
287307
continue;
288308
}
309+
NSMutableDictionary* ssdResults = [ConfigImporter importFromSubscriptionOfSSD:linkStr];
310+
[result[@"other"] addObjectsFromArray:ssdResults[@"other"]];
289311
}
290312
}
291313
return result;

V2RayX/ConfigWindowController.m

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,23 +336,27 @@ - (void)presentImportResultOfVmessCount:(NSInteger)vmessCount otherCount:(NSInte
336336
}
337337

338338
- (IBAction)importFromMiscLinks:(id)sender {
339-
[self askInputWithPrompt:@"V2RayX will try importing vmess:// and http(s):// links from v2rayN ." handler:^(NSString *inputStr) {
339+
[self askInputWithPrompt:@"V2RayX will try importing ssd://, vmess:// and http(s):// links from v2rayN and SSD." handler:^(NSString *inputStr) {
340340
if ([inputStr length] != 0) {
341-
ServerProfile* p = [ConfigImporter importFromVmessOfV2RayN:inputStr];
342341
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
342+
ServerProfile* p = [ConfigImporter importFromVmessOfV2RayN:inputStr];
343343
NSInteger vmessCount = 0;
344344
NSInteger otherCount = 0;
345345
if (p) {
346346
[self.profiles addObject:p];
347347
vmessCount = 1;
348-
} else {
349-
NSMutableDictionary* p2 = [ConfigImporter importFromSubscriptionOfV2RayN:inputStr];
350-
if (p2) {
351-
[self.profiles addObjectsFromArray:p2[@"vmess"]];
352-
[self.outbounds addObjectsFromArray:p2[@"other"]];
353-
vmessCount = [p2[@"vmess"] count];
354-
otherCount = [p2[@"other"] count];
355-
}
348+
}
349+
NSDictionary* ssdResult = [ConfigImporter importFromSubscriptionOfSSD:inputStr];
350+
for (NSDictionary* d in ssdResult[@"other"]) {
351+
[self.outbounds addObject:[d mutableDeepCopy]];
352+
otherCount += 1;
353+
}
354+
NSMutableDictionary* p2 = [ConfigImporter importFromHTTPSubscription:inputStr];
355+
if (p2) {
356+
[self.profiles addObjectsFromArray:p2[@"vmess"]];
357+
[self.outbounds addObjectsFromArray:p2[@"other"]];
358+
vmessCount += [p2[@"vmess"] count];
359+
otherCount += [p2[@"other"] count];
356360
}
357361
[self presentImportResultOfVmessCount:vmessCount otherCount:otherCount ruleSetCount:0];
358362
});

V2RayX/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
24-
<string>1142</string>
24+
<string>1235</string>
2525
<key>LSMinimumSystemVersion</key>
2626
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
2727
<key>LSUIElement</key>

0 commit comments

Comments
 (0)