Adjust to ObjFW changes

This commit is contained in:
Jonathan Schleifer 2018-12-08 18:28:13 +01:00
parent a1f8adaa57
commit bdfa70b3e5
No known key found for this signature in database
GPG key ID: D83A76BFE376345E
2 changed files with 61 additions and 58 deletions

View file

@ -33,7 +33,6 @@ OF_ASSUME_NONNULL_BEGIN
@interface SSLSocket: OFTCPSocket <OFTLSSocket> @interface SSLSocket: OFTCPSocket <OFTLSSocket>
{ {
SSL *_SSL; SSL *_SSL;
id <OFTLSSocketDelegate> _delegate;
OFString *_certificateFile, *_privateKeyFile; OFString *_certificateFile, *_privateKeyFile;
const char *_privateKeyPassphrase; const char *_privateKeyPassphrase;
bool _certificateVerificationEnabled; bool _certificateVerificationEnabled;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
* Jonathan Schleifer <js@heap.zone> * Jonathan Schleifer <js@heap.zone>
* Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de> * Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
* Copyright (c) 2011, Jos Kuijpers <jos@kuijpersvof.nl> * Copyright (c) 2011, Jos Kuijpers <jos@kuijpersvof.nl>
@ -96,40 +96,35 @@ locking_callback(int mode, int n, const char *file, int line)
- (void)SSL_super_close; - (void)SSL_super_close;
@end @end
@interface SSLSocket_ConnectContext: OFObject @interface SSLSocket_ConnectDelegate: OFObject <OFTLSSocketDelegate>
{ {
SSLSocket *_socket;
OFString *_host; OFString *_host;
uint16_t _port; uint16_t _port;
id _target; id <OFTLSSocketDelegate> _delegate;
SEL _selector;
id _context;
} }
- (instancetype)initWithHost: (OFString *)host - (instancetype)initWithSocket: (SSLSocket *)sock
host: (OFString *)host
port: (uint16_t)port port: (uint16_t)port
target: (id)target delegate: (id <OFTLSSocketDelegate>)delegate;
selector: (SEL)selector
context: (id)context;
- (void)socketDidConnect: (SSLSocket *)sock
context: (id)context
exception: (id)exception;
@end @end
@implementation SSLSocket_ConnectContext @implementation SSLSocket_ConnectDelegate
- (instancetype)initWithHost: (OFString *)host - (instancetype)initWithSocket: (SSLSocket *)sock
host: (OFString *)host
port: (uint16_t)port port: (uint16_t)port
target: (id)target delegate: (id <OFTLSSocketDelegate>)delegate
selector: (SEL)selector
context: (id)context
{ {
self = [super init]; self = [super init];
@try { @try {
_socket = [sock retain];
_host = [host copy]; _host = [host copy];
_port = port; _port = port;
_target = [target retain]; _delegate = [delegate retain];
_selector = selector;
_context = [context retain]; [_socket setDelegate: self];
} @catch (id e) { } @catch (id e) {
[self release]; [self release];
@throw e; @throw e;
@ -140,37 +135,54 @@ locking_callback(int mode, int n, const char *file, int line)
- (void)dealloc - (void)dealloc
{ {
[_host release]; if ([_socket delegate] == self)
[_target release]; [_socket setDelegate: _delegate];
[_context release];
[_socket release];
[_delegate release];
[super dealloc]; [super dealloc];
} }
- (void)socketDidConnect: (SSLSocket *)sock - (void)socket: (OF_KINDOF(OFTCPSocket *))sock
context: (id)context didConnectToHost: (OFString *)host
exception: (id)exception port: (uint16_t)port
{ {
void (*func)(id, SEL, OFTCPSocket *, id, id) =
(void (*)(id, SEL, OFTCPSocket *, id, id))
[_target methodForSelector: _selector];
if (exception == nil) {
@try { @try {
[sock SSL_startTLSWithExpectedHost: _host [sock SSL_startTLSWithExpectedHost: _host
port: _port]; port: _port];
} @catch (id e) { } @catch (id e) {
func(_target, _selector, sock, _context, e); [_socket setDelegate: _delegate];
[_delegate socket: sock
didFailToConnectWithException: e
host: host
port: port];
return; return;
} }
}
func(_target, _selector, sock, _context, exception); [_socket setDelegate: _delegate];
[_delegate socket: sock
didConnectToHost: host
port: port];
}
- (void)socket: (OF_KINDOF(OFTCPSocket *))sock
didFailToConnectWithException: (id)exception
host: (OFString *)host
port: (uint16_t)port
{
[_socket setDelegate: _delegate];
return [_delegate socket: sock
didFailToConnectWithException: exception
host: host
port: port];
} }
@end @end
@implementation SSLSocket @implementation SSLSocket
@synthesize delegate = _delegate, certificateFile = _certificateFile; @dynamic delegate;
@synthesize certificateFile = _certificateFile;
@synthesize privateKeyFile = _privateKeyFile; @synthesize privateKeyFile = _privateKeyFile;
@synthesize privateKeyPassphrase = _privateKeyPassphrase; @synthesize privateKeyPassphrase = _privateKeyPassphrase;
@synthesize certificateVerificationEnabled = _certificateVerificationEnabled; @synthesize certificateVerificationEnabled = _certificateVerificationEnabled;
@ -359,26 +371,18 @@ locking_callback(int mode, int n, const char *file, int line)
- (void)asyncConnectToHost: (OFString *)host - (void)asyncConnectToHost: (OFString *)host
port: (uint16_t)port port: (uint16_t)port
runLoopMode: (of_run_loop_mode_t)runLoopMode runLoopMode: (of_run_loop_mode_t)runLoopMode
target: (id)target
selector: (SEL)selector
context: (id)userContext
{ {
void *pool = objc_autoreleasePoolPush(); void *pool = objc_autoreleasePoolPush();
SSLSocket_ConnectContext *context; SSLSocket_ConnectDelegate *connectDelegate;
context = [[[SSLSocket_ConnectContext alloc] connectDelegate = [[[SSLSocket_ConnectDelegate alloc]
initWithHost: host initWithSocket: self
host: host
port: port port: port
target: target delegate: _delegate] autorelease];
selector: selector
context: userContext] autorelease];
[super asyncConnectToHost: host [super asyncConnectToHost: host
port: port port: port
runLoopMode: runLoopMode runLoopMode: runLoopMode];
target: context
selector: @selector(socketDidConnect:context:
exception:)
context: nil];
objc_autoreleasePoolPop(pool); objc_autoreleasePoolPop(pool);
} }