Skip to content

Commit

Permalink
SOCKS proxy support in AsyncSocket
Browse files Browse the repository at this point in the history
  • Loading branch information
psychs committed Nov 3, 2009
1 parent 18e3f74 commit 1987147
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
4 changes: 4 additions & 0 deletions LimeChat.xcodeproj/project.pbxproj
Expand Up @@ -73,6 +73,7 @@
787817C80D860ED30049CF95 /* unicodeutil.rb in Resources */ = {isa = PBXBuildFile; fileRef = 787817C70D860ED30049CF95 /* unicodeutil.rb */; };
787898250CF38C510045585B /* filelogger.rb in Resources */ = {isa = PBXBuildFile; fileRef = 787898240CF38C510045585B /* filelogger.rb */; };
787A36A20C6A392600DDB70D /* fieldeditortextview.rb in Resources */ = {isa = PBXBuildFile; fileRef = 787A36A10C6A392600DDB70D /* fieldeditortextview.rb */; };
78835406109FEA7F00CD2FFF /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78835405109FEA7F00CD2FFF /* SystemConfiguration.framework */; };
7884E54E0CDA91F500AF3678 /* SACrashReporter in Resources */ = {isa = PBXBuildFile; fileRef = 7884E5450CDA91F500AF3678 /* SACrashReporter */; };
7889CAB90D646E2C003D808E /* WelcomeDialog.nib in Resources */ = {isa = PBXBuildFile; fileRef = 7889CAB70D646E2C003D808E /* WelcomeDialog.nib */; };
7889CABF0D647494003D808E /* welcomedialog.rb in Resources */ = {isa = PBXBuildFile; fileRef = 7889CABE0D647494003D808E /* welcomedialog.rb */; };
Expand Down Expand Up @@ -228,6 +229,7 @@
787898240CF38C510045585B /* filelogger.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = filelogger.rb; sourceTree = "<group>"; };
787A36A10C6A392600DDB70D /* fieldeditortextview.rb */ = {isa = PBXFileReference; fileEncoding = 0; lastKnownFileType = text.script.ruby; path = fieldeditortextview.rb; sourceTree = "<group>"; };
787FD46C0BFE960100F2F22D /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = "<absolute>"; };
78835405109FEA7F00CD2FFF /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = /System/Library/Frameworks/SystemConfiguration.framework; sourceTree = "<absolute>"; };
7884E5450CDA91F500AF3678 /* SACrashReporter */ = {isa = PBXFileReference; lastKnownFileType = folder; name = SACrashReporter; path = vendor/SACrashReporter; sourceTree = "<group>"; };
7889CAB80D646E2C003D808E /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/WelcomeDialog.nib; sourceTree = "<group>"; };
7889CABE0D647494003D808E /* welcomedialog.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = welcomedialog.rb; sourceTree = "<group>"; };
Expand Down Expand Up @@ -281,6 +283,7 @@
78E5723D0C1C30BA00BDF7EC /* CoreServices.framework in Frameworks */,
789AF78A10859FEE006848B3 /* RubyCocoa.framework in Frameworks */,
78FA9F651085AA1400001F13 /* Sparkle.framework in Frameworks */,
78835406109FEA7F00CD2FFF /* SystemConfiguration.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -357,6 +360,7 @@
787FD46C0BFE960100F2F22D /* Carbon.framework */,
780253C20C09525900C170D4 /* CoreServices.framework */,
788D56F00BB6872B00DDBF69 /* WebKit.framework */,
78835405109FEA7F00CD2FFF /* SystemConfiguration.framework */,
789AF78910859FEE006848B3 /* RubyCocoa.framework */,
78FA9F641085AA1400001F13 /* Sparkle.framework */,
);
Expand Down
4 changes: 4 additions & 0 deletions objc/AsyncSocket.h
Expand Up @@ -133,6 +133,10 @@ typedef enum AsyncSocketError AsyncSocketError;
/* SSL support */
- (void) useSSL;

/* Proxy support */
- (void) useSystemSocksProxy;
- (void) useSocksProxyVersion:(int)version host:(NSString*)host port:(int)port user:(NSString*)user password:(NSString*)password;

/* The following methods won't block. To not time out, use a negative time interval. If they time out, "onSocket:disconnectWithError:" is called. The tag is for your convenience. You can use it as an array index, step number, state id, pointer, etc., just like the socket's user data. */

/* This will read a certain number of bytes, and call the delegate method when those bytes have been read. If there is an error, partially read data is lost. If the length is 0, this method does nothing and the delegate is not called. */
Expand Down
50 changes: 40 additions & 10 deletions objc/AsyncSocket.m
Expand Up @@ -13,6 +13,7 @@
#import <netinet/in.h>
#import <arpa/inet.h>
#import <netdb.h>
#import <SystemConfiguration/SystemConfiguration.h>

#pragma mark Declarations

Expand Down Expand Up @@ -1569,16 +1570,45 @@ static void MyCFWriteStreamCallback (CFWriteStreamRef stream, CFStreamEventType

- (void)useSSL
{
NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:
(NSString *)kCFStreamSocketSecurityLevelNegotiatedSSL, kCFStreamSSLLevel,
kCFBooleanTrue, kCFStreamSSLAllowsAnyRoot,
kCFBooleanFalse, kCFStreamSSLValidatesCertificateChain,
kCFNull, kCFStreamSSLPeerName,
kCFBooleanFalse, kCFStreamSSLIsServer,
nil];

CFReadStreamSetProperty(theReadStream, kCFStreamPropertySSLSettings, settings);
CFWriteStreamSetProperty(theWriteStream, kCFStreamPropertySSLSettings, settings);
NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:
(NSString*)kCFStreamSocketSecurityLevelNegotiatedSSL, kCFStreamSSLLevel,
kCFBooleanTrue, kCFStreamSSLAllowsAnyRoot,
kCFBooleanFalse, kCFStreamSSLValidatesCertificateChain,
kCFNull, kCFStreamSSLPeerName,
kCFBooleanFalse, kCFStreamSSLIsServer,
nil];

CFReadStreamSetProperty(theReadStream, kCFStreamPropertySSLSettings, settings);
CFWriteStreamSetProperty(theWriteStream, kCFStreamPropertySSLSettings, settings);
}

- (void)useSystemSocksProxy
{
CFDictionaryRef settings = SCDynamicStoreCopyProxies(NULL);
CFReadStreamSetProperty(theReadStream, kCFStreamPropertySOCKSProxy, settings);
CFWriteStreamSetProperty(theWriteStream, kCFStreamPropertySOCKSProxy, settings);
CFRelease(settings);
}

- (void)useSocksProxyVersion:(int)version host:(NSString*)host port:(int)port user:(NSString*)user password:(NSString*)password
{
NSMutableDictionary* settings = [NSMutableDictionary dictionary];

if (version == 4) {
[settings setObject:(NSString*)kCFStreamSocketSOCKSVersion4 forKey:(NSString*)kCFStreamPropertySOCKSVersion];
}
else {
[settings setObject:(NSString*)kCFStreamSocketSOCKSVersion5 forKey:(NSString*)kCFStreamPropertySOCKSVersion];
}

[settings setObject:host forKey:(NSString*)kCFStreamPropertySOCKSProxyHost];
[settings setObject:[NSNumber numberWithInt:port] forKey:(NSString*)kCFStreamPropertySOCKSProxyPort];

if ([user length]) [settings setObject:user forKey:(NSString*)kCFStreamPropertySOCKSUser];
if ([password length]) [settings setObject:password forKey:(NSString*)kCFStreamPropertySOCKSPassword];

CFReadStreamSetProperty(theReadStream, kCFStreamPropertySOCKSProxy, settings);
CFWriteStreamSetProperty(theWriteStream, kCFStreamPropertySOCKSProxy, settings);
}

+ (NSString*)posixErrorStringFromErrno:(int)code
Expand Down

0 comments on commit 1987147

Please sign in to comment.