1
1
/*
2
- * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016
2
+ * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
3
3
* Jonathan Schleifer <[email protected] >
4
4
* Copyright (c) 2011, Florian Zeitz <[email protected] >
5
5
* Copyright (c) 2011, Jos Kuijpers <[email protected] >
@@ -96,40 +96,29 @@ - (void)SSL_startTLSWithExpectedHost: (OFString *)host
96
96
- (void )SSL_super_close ;
97
97
@end
98
98
99
- @interface SSLSocket_ConnectContext : OFObject
99
+ @interface SSLSocket_ConnectContext : OFObject <OFTLSSocketDelegate>
100
100
{
101
101
OFString *_host;
102
102
uint16_t _port;
103
- id _target;
104
- SEL _selector;
105
- id _context;
103
+ id <OFTLSSocketDelegate> _delegate;
106
104
}
107
105
108
106
- (instancetype )initWithHost : (OFString *)host
109
107
port : (uint16_t )port
110
- target : (id )target
111
- selector : (SEL )selector
112
- context : (id )context ;
113
- - (void )socketDidConnect : (SSLSocket *)sock
114
- context : (id )context
115
- exception : (id )exception ;
108
+ delegate : (id <OFTLSSocketDelegate>)delegate ;
116
109
@end
117
110
118
111
@implementation SSLSocket_ConnectContext
119
112
- (instancetype )initWithHost : (OFString *)host
120
113
port : (uint16_t )port
121
- target : (id )target
122
- selector : (SEL )selector
123
- context : (id )context
114
+ delegate : (id <OFTLSSocketDelegate>)delegate
124
115
{
125
116
self = [super init ];
126
117
127
118
@try {
128
119
_host = [host copy ];
129
120
_port = port;
130
- _target = [target retain ];
131
- _selector = selector;
132
- _context = [context retain ];
121
+ _delegate = [delegate retain ];
133
122
} @catch (id e) {
134
123
[self release ];
135
124
@throw e;
@@ -140,37 +129,46 @@ - (instancetype)initWithHost: (OFString *)host
140
129
141
130
- (void )dealloc
142
131
{
143
- [_host release ];
144
- [_target release ];
145
- [_context release ];
132
+ [_delegate release ];
146
133
147
134
[super dealloc ];
148
135
}
149
136
150
- - (void )socketDidConnect : (SSLSocket * )sock
151
- context : (id ) context
152
- exception : (id ) exception
137
+ - (void )socket : (OF_KINDOF(OFTCPSocket *) )sock
138
+ didConnectToHost : (OFString *) host
139
+ port : (uint16_t ) port
153
140
{
154
- void (*func)(id , SEL , OFTCPSocket *, id , id ) =
155
- (void (*)(id , SEL , OFTCPSocket *, id , id ))
156
- [_target methodForSelector: _selector];
157
-
158
- if (exception == nil ) {
159
- @try {
160
- [sock SSL_startTLSWithExpectedHost: _host
161
- port: _port];
162
- } @catch (id e) {
163
- func (_target, _selector, sock, _context, e);
164
- return ;
165
- }
141
+ @try {
142
+ [sock SSL_startTLSWithExpectedHost: _host
143
+ port: _port];
144
+ } @catch (id e) {
145
+ [_delegate socket: sock
146
+ didFailToConnectWithException: e
147
+ host: host
148
+ port: port];
149
+ return ;
166
150
}
167
151
168
- func (_target, _selector, sock, _context, exception);
152
+ [_delegate socket: sock
153
+ didConnectToHost: host
154
+ port: port];
155
+ }
156
+
157
+ - (void )socket : (OF_KINDOF(OFTCPSocket *))sock
158
+ didFailToConnectWithException : (id )exception
159
+ host : (OFString *)host
160
+ port : (uint16_t )port
161
+ {
162
+ return [_delegate socket: sock
163
+ didFailToConnectWithException: exception
164
+ host: host
165
+ port: port];
169
166
}
170
167
@end
171
168
172
169
@implementation SSLSocket
173
- @synthesize delegate = _delegate, certificateFile = _certificateFile;
170
+ @dynamic delegate;
171
+ @synthesize certificateFile = _certificateFile;
174
172
@synthesize privateKeyFile = _privateKeyFile;
175
173
@synthesize privateKeyPassphrase = _privateKeyPassphrase;
176
174
@synthesize certificateVerificationEnabled = _certificateVerificationEnabled;
@@ -359,26 +357,17 @@ - (void)startTLSWithExpectedHost: (OFString *)host
359
357
- (void )asyncConnectToHost : (OFString *)host
360
358
port : (uint16_t )port
361
359
runLoopMode : (of_run_loop_mode_t )runLoopMode
362
- target : (id )target
363
- selector : (SEL )selector
364
- context : (id )userContext
365
360
{
366
361
void *pool = objc_autoreleasePoolPush ();
367
362
SSLSocket_ConnectContext *context;
368
363
369
364
context = [[[SSLSocket_ConnectContext alloc ]
370
365
initWithHost: host
371
366
port: port
372
- target: target
373
- selector: selector
374
- context: userContext] autorelease ];
367
+ delegate: _delegate] autorelease ];
375
368
[super asyncConnectToHost: host
376
369
port: port
377
- runLoopMode: runLoopMode
378
- target: context
379
- selector: @selector (socketDidConnect:context:
380
- exception: )
381
- context: nil ];
370
+ runLoopMode: runLoopMode];
382
371
383
372
objc_autoreleasePoolPop (pool);
384
373
}
0 commit comments