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

Commit

Permalink
fix #78, customized http header for tcp supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Cenmrev committed May 5, 2018
1 parent 61853c6 commit 8d62d28
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 67 deletions.
21 changes: 20 additions & 1 deletion V2RayX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
buildPhases = (
9504C0741C662C3000352520 /* Sources */,
9504C0751C662C3000352520 /* Frameworks */,
9DB94D77209D273A0001E9DD /* Run Script */,
953B60541DB3E31D00D40654 /* Run Script */,
9504C0761C662C3000352520 /* Resources */,
);
Expand Down Expand Up @@ -376,7 +377,7 @@
9504C0701C662C3000352520 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Project V2Ray";
TargetAttributes = {
9504C0771C662C3000352520 = {
Expand Down Expand Up @@ -449,6 +450,20 @@
shellPath = /bin/sh;
shellScript = "\"$SRCROOT\"/V2RayX/dlcore.sh";
};
9DB94D77209D273A0001E9DD /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Run Script";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "buildNumber=$(/usr/libexec/PlistBuddy -c \"Print CFBundleVersion\" \"$INFOPLIST_FILE\")\nbuildNumber=$(($buildNumber + 1))\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $buildNumber\" \"$INFOPLIST_FILE\"";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down Expand Up @@ -526,12 +541,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -577,12 +594,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
4 changes: 3 additions & 1 deletion V2RayX/ConfigWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
@property (weak) IBOutlet NSPopUpButton *kcpCongestionButton;
@property (weak) IBOutlet NSPopUpButton *kcpHeaderTypeButton;
//tcp fields
@property (weak) IBOutlet NSPopUpButton *tcpHeaderTypeButton;
@property (weak) IBOutlet NSButton *tcpHeaderCusButton;
@property (unsafe_unretained) IBOutlet NSTextView *tcpHdField;

//ws fields
@property (weak) IBOutlet NSButton *wsCrButton;
@property (weak) IBOutlet NSTextField *wsPathField;
Expand Down
67 changes: 43 additions & 24 deletions V2RayX/ConfigWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ - (IBAction)showTransportSettings:(id)sender {
}
}
//tcp
[_tcpHeaderTypeButton selectItemAtIndex:[transportSettings[@"tcpSettings"][@"header"][@"type"] isEqualToString:@"http"] ? 1 : 0];
[_tcpHeaderCusButton setState:[transportSettings[@"tcpSettings"][@"header"][@"type"] isEqualToString:@"http"] ? 1 : 0];
if ([_tcpHeaderCusButton state]) {
[_tcpHdField setString:
[[NSString alloc]initWithData:[NSJSONSerialization dataWithJSONObject:transportSettings[@"tcpSettings"][@"header"] options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding]];
}
//websocket
[_wsCrButton setState:[transportSettings[@"wsSettings"][@"connectionReuse"] boolValue]];
NSString *savedWsPath = transportSettings[@"wsSettings"][@"path"];
Expand Down Expand Up @@ -208,7 +212,7 @@ - (IBAction)tReset:(id)sender {
[_kcpCongestionButton selectItemAtIndex:0];
[_kcpHeaderTypeButton selectItemAtIndex:0];
//tcp fields
[_tcpHeaderTypeButton selectItemAtIndex:0];
[_tcpHeaderCusButton setState:0];
//ws fields
[_wsCrButton setState:1];
[_wsPathField setStringValue:@""];
Expand All @@ -225,6 +229,23 @@ - (IBAction)tCancel:(id)sender {
[[self window] endSheet:_transportWindow];
}
- (IBAction)tOK:(id)sender {
//check tcp header
NSString* tcpHttpHeaderString = @"{\"type\": \"none\"}";
if ([self->_tcpHeaderCusButton state]) {
tcpHttpHeaderString = [self->_tcpHdField string];
}
NSError* httpHeaderParseError;
NSDictionary* tcpHttpHeader = [NSJSONSerialization JSONObjectWithData:[tcpHttpHeaderString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&httpHeaderParseError];
NSLog(@"%@", tcpHttpHeader);
if (httpHeaderParseError) {
NSAlert* parseAlert = [[NSAlert alloc] init];
[parseAlert setMessageText:@"Error in parsing customized http header!"];
[parseAlert beginSheetModalForWindow:_transportWindow completionHandler:^(NSModalResponse returnCode) {
return;
}];
return;
}

NSAlert* settingAlert = [[NSAlert alloc] init];
[settingAlert setMessageText:@"Make sure you have read the help before clicking OK!"];
[settingAlert addButtonWithTitle:@"Yes, save!"];
Expand All @@ -239,45 +260,43 @@ - (IBAction)tOK:(id)sender {
[settingAlert beginSheetModalForWindow:_transportWindow completionHandler:^(NSModalResponse returnCode) {
if (returnCode == NSAlertFirstButtonReturn) {
//save settings

NSDictionary *streamSettings =
@{@"kcpSettings":
@{@"mtu":[NSNumber numberWithInteger:[_kcpMtuField integerValue]],
@"tti":[NSNumber numberWithInteger:[_kcpTtiField integerValue]],
@"uplinkCapacity":[NSNumber numberWithInteger:[_kcpUcField integerValue]],
@"downlinkCapacity":[NSNumber numberWithInteger:[_kcpDcField integerValue]],
@"readBufferSize":[NSNumber numberWithInteger:[_kcpRbField integerValue]],
@"writeBufferSize":[NSNumber numberWithInteger:[_kcpWbField integerValue]],
@"congestion":[NSNumber numberWithBool:[_kcpCongestionButton indexOfSelectedItem] != 0],
@"header":@{@"type":[[_kcpHeaderTypeButton selectedItem] title]}
},
@"tcpSettings":
@{
@"header":@{@"type":[[_tcpHeaderTypeButton selectedItem] title]}
@{@"mtu":[NSNumber numberWithInteger:[self->_kcpMtuField integerValue]],
@"tti":[NSNumber numberWithInteger:[self->_kcpTtiField integerValue]],
@"uplinkCapacity":[NSNumber numberWithInteger:[self->_kcpUcField integerValue]],
@"downlinkCapacity":[NSNumber numberWithInteger:[self->_kcpDcField integerValue]],
@"readBufferSize":[NSNumber numberWithInteger:[self->_kcpRbField integerValue]],
@"writeBufferSize":[NSNumber numberWithInteger:[self->_kcpWbField integerValue]],
@"congestion":[NSNumber numberWithBool:[self->_kcpCongestionButton indexOfSelectedItem] != 0],
@"header":@{@"type":[[self->_kcpHeaderTypeButton selectedItem] title]}
},
@"tcpSettings":@{@"header": tcpHttpHeader},
@"wsSettings": @{
@"connectionReuse": [NSNumber numberWithBool:[_wsCrButton state]==1],
@"path": nilCoalescing([_wsPathField stringValue], @"")
@"connectionReuse": [NSNumber numberWithBool:[self->_wsCrButton state]==1],
@"path": nilCoalescing([self->_wsPathField stringValue], @"")
},
@"security": [_tlsUseButton state] ? @"tls" : @"none",
@"security": [self->_tlsUseButton state] ? @"tls" : @"none",
@"tlsSettings": @{
@"serverName": nilCoalescing([_tlsSnField stringValue], @""),
@"allowInsecure": [NSNumber numberWithBool:[_tlsAiButton state]==1],
@"serverName": nilCoalescing([self->_tlsSnField stringValue], @""),
@"allowInsecure": [NSNumber numberWithBool:[self->_tlsAiButton state]==1],
},
@"httpSettings": @{
@"host": httpHosts,
@"path": nilCoalescing([_httpPathField stringValue], @"")
@"path": nilCoalescing([self->_httpPathField stringValue], @"")
}
};
NSDictionary* muxSettings = @{
@"enabled":[NSNumber numberWithBool:[_muxEnableButton state]==1],
@"concurrency":[NSNumber numberWithInteger:[_muxConcurrencyField integerValue]]
@"enabled":[NSNumber numberWithBool:[self->_muxEnableButton state]==1],
@"concurrency":[NSNumber numberWithInteger:[self->_muxConcurrencyField integerValue]]
};
NSDictionary* proxySettings = @{@"address": nilCoalescing([_proxyAddressField stringValue], @""), @"port": @([_proxyPortField integerValue])};
NSDictionary* proxySettings = @{@"address": nilCoalescing([self->_proxyAddressField stringValue], @""), @"port": @([self->_proxyPortField integerValue])};
self.selectedProfile.muxSettings = muxSettings;
self.selectedProfile.streamSettings = streamSettings;
self.selectedProfile.proxySettings = proxySettings;
//close sheet
[[self window] endSheet:_transportWindow];
[[self window] endSheet:self->_transportWindow];
}
}];
}
Expand Down

0 comments on commit 8d62d28

Please sign in to comment.