Modified src/OFDNSResolver.m
from [dbbe2fd8c5]
to [5d30f91158].
︙ | | |
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
|
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
|
-
+
-
+
|
if (_IPv6Socket == nil) {
of_socket_address_t address =
of_socket_address_parse_ip(@"::", 0);
_IPv6Socket = [[OFUDPSocket alloc] init];
[_IPv6Socket of_bindToAddress: &address
extraType: SOCK_DNS];
_IPv6Socket.blocking = false;
_IPv6Socket.canBlock = false;
_IPv6Socket.delegate = self;
}
sock = _IPv6Socket;
break;
#endif
case OF_SOCKET_ADDRESS_FAMILY_IPV4:
if (_IPv4Socket == nil) {
of_socket_address_t address =
of_socket_address_parse_ip(@"0.0.0.0", 0);
_IPv4Socket = [[OFUDPSocket alloc] init];
[_IPv4Socket of_bindToAddress: &address
extraType: SOCK_DNS];
_IPv4Socket.blocking = false;
_IPv4Socket.canBlock = false;
_IPv4Socket.delegate = self;
}
sock = _IPv4Socket;
break;
default:
@throw [OFInvalidArgumentException exception];
|
︙ | | |
Modified src/OFDatagramSocket.h
from [c9598f3c24]
to [cb9e65f15c].
︙ | | |
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
* than one thread at the same time is not thread-safe, even if copy
* was called to create one "instance" for every thread!
*/
@interface OFDatagramSocket: OFObject <OFCopying, OFReadyForReadingObserving,
OFReadyForWritingObserving>
{
of_socket_t _socket;
bool _blocking;
bool _canBlock;
#ifdef OF_WII
bool _broadcastAllowed;
bool _canSendToBroadcastAddresses;
#endif
id <OFDatagramSocketDelegate> _Nullable _delegate;
OF_RESERVE_IVARS(4)
}
/*!
* @brief Whether the socket is in blocking mode.
* @brief Whether the socket can block.
*
* By default, a socket is in blocking mode.
* By default, a socket can block.
*/
@property (nonatomic, getter=isBlocking) bool blocking;
@property (nonatomic) bool canBlock;
/*!
* @brief Whether the socket is allowed to send to broadcast addresses.
* @brief Whether the socket can send to broadcast addresses.
*/
@property (nonatomic, getter=isBroadcastAllowed) bool broadcastAllowed;
@property (nonatomic) bool canSendToBroadcastAddresses;
/*!
* @brief The delegate for asynchronous operations on the socket.
*
* @note The delegate is retained for as long as asynchronous operations are
* still ongoing.
*/
|
︙ | | |
Modified src/OFDatagramSocket.m
from [08aed9e1e3]
to [4cd95b929d].
︙ | | |
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
-
+
|
@try {
if (self.class == [OFDatagramSocket class]) {
[self doesNotRecognizeSelector: _cmd];
abort();
}
_socket = INVALID_SOCKET;
_blocking = true;
_canBlock = true;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
|
︙ | | |
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
}
- (id)copy
{
return [self retain];
}
- (bool)isBlocking
- (bool)canBlock
{
return _blocking;
return _canBlock;
}
- (void)setBlocking: (bool)enable
- (void)setCanBlock: (bool)canBlock
{
#if defined(HAVE_FCNTL)
int flags = fcntl(_socket, F_GETFL, 0);
if (flags == -1)
@throw [OFSetOptionFailedException exceptionWithObject: self
errNo: errno];
if (enable)
if (canBlock)
flags &= ~O_NONBLOCK;
else
flags |= O_NONBLOCK;
if (fcntl(_socket, F_SETFL, flags) == -1)
@throw [OFSetOptionFailedException exceptionWithObject: self
errNo: errno];
_blocking = enable;
_canBlock = canBlock;
#elif defined(OF_WINDOWS)
u_long v = enable;
u_long v = canBlock;
if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
_blocking = enable;
_canBlock = canBlock;
#else
OF_UNRECOGNIZED_SELECTOR
#endif
}
- (void)setBroadcastAllowed: (bool)allowed
- (void)setCanSendToBroadcastAddresses: (bool)canSendToBroadcastAddresses
{
int v = allowed;
int v = canSendToBroadcastAddresses;
if (setsockopt(_socket, SOL_SOCKET, SO_BROADCAST,
(char *)&v, (socklen_t)sizeof(v)) != 0)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
#ifdef OF_WII
_broadcastAllowed = allowed;
_canSendToBroadcastAddresses = allowed;
#endif
}
- (bool)isBroadcastAllowed
- (bool)canSendToBroadcastAddresses
{
#ifndef OF_WII
int v;
socklen_t len = sizeof(v);
if (getsockopt(_socket, SOL_SOCKET, SO_BROADCAST,
(char *)&v, &len) != 0 || len != sizeof(v))
@throw [OFGetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
return v;
#else
return _broadcastAllowed;
return _canSendToBroadcastAddresses;
#endif
}
- (size_t)receiveIntoBuffer: (void *)buffer
length: (size_t)length
sender: (of_socket_address_t *)sender
{
|
︙ | | |
Modified src/OFHTTPClient.h
from [1c7acee4b8]
to [a28aee5e52].
︙ | | |
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
-
+
-
+
-
+
|
OF_SUBCLASSING_RESTRICTED
@interface OFHTTPClient: OFObject
{
#ifdef OF_HTTPCLIENT_M
@public
#endif
OFObject <OFHTTPClientDelegate> *_Nullable _delegate;
bool _insecureRedirectsAllowed, _inProgress;
bool _allowsInsecureRedirects, _inProgress;
OFTCPSocket *_Nullable _socket;
OFURL *_Nullable _lastURL;
bool _lastWasHEAD;
OFHTTPResponse *_Nullable _lastResponse;
}
/*!
* @brief The delegate of the HTTP request.
*/
@property OF_NULLABLE_PROPERTY (assign, nonatomic)
OFObject <OFHTTPClientDelegate> *delegate;
/*!
* @brief Whether redirects from HTTPS to HTTP will be allowed.
* @brief Whether the HTTP client allows redirects from HTTPS to HTTP.
*/
@property (nonatomic) bool insecureRedirectsAllowed;
@property (nonatomic) bool allowsInsecureRedirects;
/*!
* @brief Creates a new OFHTTPClient.
*
* @return A new, autoreleased OFHTTPClient
*/
+ (instancetype)client;
|
︙ | | |
Modified src/OFHTTPClient.m
from [8b55b3abfe]
to [7d20d55912].
︙ | | |
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
-
+
|
if ([newURLScheme caseInsensitiveCompare: @"http"] !=
OF_ORDERED_SAME &&
[newURLScheme caseInsensitiveCompare: @"https"] !=
OF_ORDERED_SAME)
follow = false;
if (!_client->_insecureRedirectsAllowed &&
if (!_client->_allowsInsecureRedirects &&
[URL.scheme caseInsensitiveCompare: @"https"] ==
OF_ORDERED_SAME &&
[newURLScheme caseInsensitiveCompare: @"http"] ==
OF_ORDERED_SAME)
follow = false;
if (follow && [_client->_delegate respondsToSelector: @selector(
|
︙ | | |
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
|
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
|
-
+
|
else
return defaultShouldFollow(request.method, statusCode);
}
@end
@implementation OFHTTPClient
@synthesize delegate = _delegate;
@synthesize insecureRedirectsAllowed = _insecureRedirectsAllowed;
@synthesize allowsInsecureRedirects = _allowsInsecureRedirects;
+ (instancetype)client
{
return [[[self alloc] init] autorelease];
}
- (void)dealloc
|
︙ | | |
Modified src/OFIPSocketAsyncConnector.m
from [bca137df6a]
to [6a448fb9d2].
︙ | | |
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
-
+
|
[super dealloc];
}
- (void)didConnect
{
if (_exception == nil)
[_socket setBlocking: true];
[_socket setCanBlock: true];
#ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
if ([_socket isKindOfClass: [OFTCPSocket class]])
((of_tcp_socket_async_connect_block_t)_block)(
_exception);
# ifdef OF_HAVE_SCTP
|
︙ | | |
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
-
+
-
+
|
* Additionally, on Wii, there is no getsockopt(), so it would not be
* possible to get the error (or success) after connecting anyway.
*
* So for now, connecting is blocking on Wii and 3DS.
*
* FIXME: Use a different thread as a work around.
*/
[_socket setBlocking: true];
[_socket setCanBlock: true];
#else
[_socket setBlocking: false];
[_socket setCanBlock: false];
#endif
if (![_socket of_connectSocketToAddress: &address
errNo: &errNo]) {
#if !defined(OF_NINTENDO_3DS) && !defined(OF_WII)
if (errNo == EINPROGRESS) {
[OFRunLoop of_addAsyncConnectForSocket: _socket
|
︙ | | |
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
-
+
|
return;
#if !defined(OF_NINTENDO_3DS) && !defined(OF_WII)
}
#endif
}
#if defined(OF_NINTENDO_3DS) || defined(OF_WII)
[_socket setBlocking: false];
[_socket setCanBlock: false];
#endif
[self didConnect];
}
- (void)resolver: (OFDNSResolver *)resolver
didResolveHost: (OFString *)host
|
︙ | | |
Modified src/OFIPXSocket.m
from [f311d46952]
to [06e0564b9c].
︙ | | |
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
-
+
|
SOCK_DGRAM | SOCK_CLOEXEC, protocol)) == INVALID_SOCKET)
@throw [OFBindFailedException
exceptionWithPort: port
packetType: packetType
socket: self
errNo: of_socket_errno()];
_blocking = true;
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) {
|
︙ | | |
Modified src/OFSCTPSocket.h
from [1a4def476d]
to [946c9ca590].
︙ | | |
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
+
-
+
-
+
|
*/
@interface OFSCTPSocket: OFSequencedPacketSocket
{
OF_RESERVE_IVARS(4)
}
/*!
* @brief Whether sending packets can be delayed. Setting this to NO sets
* @brief Whether SCTP_NODELAY is enabled for the connection
* SCTP_NODELAY on the socket.
*/
@property (nonatomic, getter=isNoDelayEnabled) bool noDelayEnabled;
@property (nonatomic) bool canDelaySendingPackets;
/*!
* @brief The delegate for asynchronous operations on the socket.
*
* @note The delegate is retained for as long as asynchronous operations are
* still ongoing.
*/
|
︙ | | |
Modified src/OFSCTPSocket.m
from [e60922f38a]
to [f509519c08].
︙ | | |
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
-
+
|
SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_SCTP)) == INVALID_SOCKET)
@throw [OFBindFailedException
exceptionWithHost: host
port: port
socket: self
errNo: of_socket_errno()];
_blocking = true;
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR,
|
︙ | | |
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
-
+
-
+
-
+
-
+
|
@throw [OFBindFailedException exceptionWithHost: host
port: port
socket: self
errNo: EAFNOSUPPORT];
}
}
- (void)setNoDelayEnabled: (bool)enabled
- (void)setCanDelaySendingPackets: (bool)canDelaySendingPackets
{
int v = enabled;
int v = !canDelaySendingPackets;
if (setsockopt(_socket, IPPROTO_SCTP, SCTP_NODELAY,
(char *)&v, (socklen_t)sizeof(v)) != 0)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
}
- (bool)isNoDelayEnabled
- (bool)canDelaySendingPackets
{
int v;
socklen_t len = sizeof(v);
if (getsockopt(_socket, IPPROTO_SCTP, SCTP_NODELAY,
(char *)&v, &len) != 0 || len != sizeof(v))
@throw [OFGetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
return v;
return !v;
}
@end
|
Modified src/OFSPXSocket.m
from [d20cbb636c]
to [9940cead8b].
︙ | | |
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
-
+
|
if (![_socket of_createSocketForAddress: &address
errNo: &errNo]) {
exception = [self of_connectionFailedExceptionForErrNo: errNo];
goto inform_delegate;
}
_socket.blocking = false;
_socket.canBlock = false;
if (![_socket of_connectSocketToAddress: &address
errNo: &errNo]) {
if (errNo == EINPROGRESS) {
[OFRunLoop of_addAsyncConnectForSocket: _socket
mode: runLoopMode
delegate: self];
|
︙ | | |
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
-
+
|
- (void)of_socketDidConnect: (id)sock
exception: (id)exception
{
id <OFSPXSocketDelegate> delegate = ((OFSPXSocket *)sock).delegate;
if (exception == nil)
((OFSPXSocket *)sock).blocking = true;
((OFSPXSocket *)sock).canBlock = true;
#ifdef OF_HAVE_BLOCKS
if (_block != NULL)
_block(exception);
else {
#endif
if ([delegate respondsToSelector:
|
︙ | | |
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
-
+
|
SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == INVALID_SOCKET)
@throw [OFBindFailedException
exceptionWithPort: port
packetType: SPX_PACKET_TYPE
socket: self
errNo: of_socket_errno()];
_blocking = true;
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) {
|
︙ | | |
Modified src/OFSPXStreamSocket.m
from [65dc3f6ee6]
to [cb1a9316c7].
︙ | | |
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
-
+
|
if (![_socket of_createSocketForAddress: &address
errNo: &errNo]) {
exception = [self of_connectionFailedExceptionForErrNo: errNo];
goto inform_delegate;
}
_socket.blocking = false;
_socket.canBlock = false;
if (![_socket of_connectSocketToAddress: &address
errNo: &errNo]) {
if (errNo == EINPROGRESS) {
[OFRunLoop of_addAsyncConnectForSocket: _socket
mode: runLoopMode
delegate: self];
|
︙ | | |
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
-
+
|
- (void)of_socketDidConnect: (id)sock
exception: (id)exception
{
id <OFSPXStreamSocketDelegate> delegate =
((OFSPXStreamSocket *)sock).delegate;
if (exception == nil)
((OFSPXStreamSocket *)sock).blocking = true;
((OFSPXStreamSocket *)sock).canBlock = true;
#ifdef OF_HAVE_BLOCKS
if (_block != NULL)
_block(exception);
else {
#endif
if ([delegate respondsToSelector:
|
︙ | | |
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
-
+
|
SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == INVALID_SOCKET)
@throw [OFBindFailedException
exceptionWithPort: port
packetType: SPX_PACKET_TYPE
socket: self
errNo: of_socket_errno()];
_blocking = true;
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) {
|
︙ | | |
Modified src/OFSequencedPacketSocket.h
from [5d1d2d056e]
to [92ebbc1deb].
︙ | | |
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
-
+
-
+
-
+
-
+
|
* than one thread at the same time is not thread-safe, even if copy
* was called to create one "instance" for every thread!
*/
@interface OFSequencedPacketSocket: OFObject <OFCopying,
OFReadyForReadingObserving, OFReadyForWritingObserving>
{
of_socket_t _socket;
bool _blocking, _listening;
bool _canBlock, _listening;
of_socket_address_t _remoteAddress;
id _Nullable _delegate;
OF_RESERVE_IVARS(4)
}
/*!
* @brief Whether the socket is in blocking mode.
* @brief Whether the socket can block.
*
* By default, a socket is in blocking mode.
* By default, a socket can block.
*/
@property (nonatomic, getter=isBlocking) bool blocking;
@property (nonatomic) bool canBlock;
/*!
* @brief Whether the socket is a listening socket.
*/
@property (readonly, nonatomic, getter=isListening) bool listening;
/*!
|
︙ | | |
Modified src/OFSequencedPacketSocket.m
from [02e9d8a16c]
to [395d4dcdd4].
︙ | | |
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
-
+
|
@try {
if (self.class == [OFSequencedPacketSocket class]) {
[self doesNotRecognizeSelector: _cmd];
abort();
}
_socket = INVALID_SOCKET;
_blocking = true;
_canBlock = true;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
|
︙ | | |
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
#endif
- (id)copy
{
return [self retain];
}
- (bool)isBlocking
- (bool)canBlock
{
return _blocking;
return _canBlock;
}
- (void)setBlocking: (bool)enable
- (void)setCanBlock: (bool)canBlock
{
#if defined(HAVE_FCNTL)
int flags = fcntl(_socket, F_GETFL, 0);
if (flags == -1)
@throw [OFSetOptionFailedException exceptionWithObject: self
errNo: errno];
if (enable)
if (canBlock)
flags &= ~O_NONBLOCK;
else
flags |= O_NONBLOCK;
if (fcntl(_socket, F_SETFL, flags) == -1)
@throw [OFSetOptionFailedException exceptionWithObject: self
errNo: errno];
_blocking = enable;
_canBlock = canBlock;
#elif defined(OF_WINDOWS)
u_long v = enable;
u_long v = canBlock;
if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
_blocking = enable;
_canBlock = canBlock;
#else
OF_UNRECOGNIZED_SELECTOR
#endif
}
- (size_t)receiveIntoBuffer: (void *)buffer
length: (size_t)length
|
︙ | | |
Modified src/OFStream.h
from [849d120fde]
to [cac7e1c78f].
︙ | | |
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
-
+
-
+
-
+
-
+
-
+
-
+
|
* the methods that do the actual work. OFStream uses those for all other
* methods and does all the caching and other stuff for you. If you
* override these methods without the `lowlevel` prefix, you *will* break
* caching and get broken results!
*/
@interface OFStream: OFObject <OFCopying>
{
bool _blocking;
bool _canBlock;
id _Nullable _delegate;
#ifndef OF_SEEKABLE_STREAM_M
@private
#endif
char *_Nullable _readBuffer, *_Nullable _readBufferMemory;
char *_Nullable _writeBuffer;
size_t _readBufferLength, _writeBufferLength;
bool _writeBuffered, _waitingForDelimiter;
bool _buffersWrites, _waitingForDelimiter;
OF_RESERVE_IVARS(4)
}
/*!
* @brief Whether the end of the stream has been reached.
*/
@property (readonly, nonatomic, getter=isAtEndOfStream) bool atEndOfStream;
/*!
* @brief Whether writes are buffered.
*/
@property (nonatomic, nonatomic, getter=isWriteBuffered) bool writeBuffered;
@property (nonatomic, nonatomic) bool buffersWrites;
/*!
* @brief Whether data is present in the internal read buffer.
*/
@property (readonly, nonatomic) bool hasDataInReadBuffer;
/*!
* @brief Whether the stream is in blocking mode.
* @brief Whether the stream can block.
*
* By default, a stream is in blocking mode.
* By default, a stream can block.
* On Win32, setting this currently only works for sockets!
*/
@property (nonatomic, getter=isBlocking) bool blocking;
@property (nonatomic) bool canBlock;
/*!
* @brief The delegate for asynchronous operations on the stream.
*
* @note The delegate is retained for as long as asynchronous operations are
* still ongoing.
*/
|
︙ | | |
Modified src/OFStream.m
from [c63329fd4a]
to [dd10e2b21b].
︙ | | |
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
+
-
+
|
#import "OFWriteFailedException.h"
#import "of_asprintf.h"
#define MIN_READ_SIZE 512
@implementation OFStream
@synthesize buffersWrites = _buffersWrites;
@synthesize of_waitingForDelimiter = _waitingForDelimiter, delegate = _delegate;
#if defined(SIGPIPE) && defined(SIG_IGN)
+ (void)initialize
{
if (self == [OFStream class])
signal(SIGPIPE, SIG_IGN);
}
#endif
- (instancetype)init
{
self = [super init];
@try {
if (self.class == [OFStream class]) {
[self doesNotRecognizeSelector: _cmd];
abort();
}
_blocking = true;
_canBlock = true;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
|
︙ | | |
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
|
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
|
-
-
-
-
-
-
-
-
-
-
-
+
-
+
|
- (OFString *)tryReadTillDelimiter: (OFString *)delimiter
{
return [self tryReadTillDelimiter: delimiter
encoding: OF_STRING_ENCODING_UTF_8];
}
- (bool)isWriteBuffered
{
return _writeBuffered;
}
- (void)setWriteBuffered: (bool)enable
{
_writeBuffered = enable;
}
- (void)flushWriteBuffer
{
if (_writeBuffer == NULL)
return;
[self lowlevelWriteBuffer: _writeBuffer
length: _writeBufferLength];
[self freeMemory: _writeBuffer];
_writeBuffer = NULL;
_writeBufferLength = 0;
}
- (size_t)writeBuffer: (const void *)buffer
length: (size_t)length
{
if (!_writeBuffered) {
if (!_buffersWrites) {
size_t bytesWritten = [self lowlevelWriteBuffer: buffer
length: length];
if (_blocking && bytesWritten < length)
if (_canBlock && bytesWritten < length)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
bytesWritten: bytesWritten
errNo: 0];
return bytesWritten;
|
︙ | | |
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
|
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
|
-
+
-
+
-
+
-
+
|
}
- (bool)hasDataInReadBuffer
{
return (_readBufferLength > 0);
}
- (bool)isBlocking
- (bool)canBlock
{
return _blocking;
return _canBlock;
}
- (void)setBlocking: (bool)enable
- (void)setCanBlock: (bool)canBlock
{
#if defined(HAVE_FCNTL) && !defined(OF_AMIGAOS)
bool readImplemented = false, writeImplemented = false;
@try {
int readFlags;
readFlags = fcntl(((id <OFReadyForReadingObserving>)self)
.fileDescriptorForReading, F_GETFL, 0);
readImplemented = true;
if (readFlags == -1)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: errno];
if (enable)
if (canBlock)
readFlags &= ~O_NONBLOCK;
else
readFlags |= O_NONBLOCK;
if (fcntl(((id <OFReadyForReadingObserving>)self)
.fileDescriptorForReading, F_SETFL, readFlags) == -1)
@throw [OFSetOptionFailedException
|
︙ | | |
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
|
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
|
-
+
-
+
|
writeImplemented = true;
if (writeFlags == -1)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: errno];
if (enable)
if (canBlock)
writeFlags &= ~O_NONBLOCK;
else
writeFlags |= O_NONBLOCK;
if (fcntl(((id <OFReadyForWritingObserving>)self)
.fileDescriptorForWriting, F_SETFL, writeFlags) == -1)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: errno];
} @catch (OFNotImplementedException *e) {
}
if (!readImplemented && !writeImplemented)
@throw [OFNotImplementedException exceptionWithSelector: _cmd
object: self];
_blocking = enable;
_canBlock = canBlock;
#else
OF_UNRECOGNIZED_SELECTOR
#endif
}
- (int)fileDescriptorForReading
{
|
︙ | | |
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
|
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
|
-
+
|
[self freeMemory: _readBufferMemory];
_readBuffer = _readBufferMemory = NULL;
_readBufferLength = 0;
[self freeMemory: _writeBuffer];
_writeBuffer = NULL;
_writeBufferLength = 0;
_writeBuffered = false;
_buffersWrites = false;
_waitingForDelimiter = false;
}
@end
|
Modified src/OFStreamSocket.m
from [1b3aa72b95]
to [2df2daa037].
︙ | | |
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
-
+
-
+
-
+
-
+
|
errNo: of_socket_errno()];
#endif
return (size_t)bytesWritten;
}
#if defined(OF_WINDOWS) || defined(OF_AMIGAOS)
- (void)setBlocking: (bool)enable
- (void)setCanBlock: (bool)canBlock
{
# ifdef OF_WINDOWS
u_long v = enable;
u_long v = canBlock;
# else
char v = enable;
char v = canBlock;
# endif
if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
_blocking = enable;
_canBlock = canBlock;
}
#endif
- (int)fileDescriptorForReading
{
#ifndef OF_WINDOWS
return _socket;
|
︙ | | |
Modified src/OFTCPSocket.h
from [8293d08642]
to [cedf99692f].
︙ | | |
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
-
+
-
+
-
+
+
-
+
|
#ifdef OF_HAVE_CLASS_PROPERTIES
@property (class, nullable, copy, nonatomic) OFString *SOCKS5Host;
@property (class, nonatomic) uint16_t SOCKS5Port;
#endif
#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
/*!
* @brief Whether keep alives are enabled for the connection.
* @brief Whether the socket sends keep alives for the connection.
*
* @warning This is not available on the Wii or Nintendo 3DS!
*/
@property (nonatomic, getter=isKeepAliveEnabled) bool keepAliveEnabled;
@property (nonatomic) bool sendsKeepAlives;
#endif
#ifndef OF_WII
/*!
* @brief Whether TCP_NODELAY is enabled for the connection
* @brief Whether sending segments can be delayed. Setting this to NO sets
* TCP_NODELAY on the socket.
*
* @warning This is not available on the Wii!
*/
@property (nonatomic, getter=isNoDelayEnabled) bool noDelayEnabled;
@property (nonatomic) bool canDelaySendingSegments;
#endif
/*!
* @brief The host to use as a SOCKS5 proxy.
*/
@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *SOCKS5Host;
|
︙ | | |
Modified src/OFTCPSocket.m
from [243bdb7d8b]
to [dc32b6d4c9].
︙ | | |
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
-
+
|
SOCK_STREAM | SOCK_CLOEXEC, 0)) == INVALID_SOCKET)
@throw [OFBindFailedException
exceptionWithHost: host
port: port
socket: self
errNo: of_socket_errno()];
_blocking = true;
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR,
|
︙ | | |
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
port: port
socket: self
errNo: EADDRNOTAVAIL];
#endif
}
#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
- (void)setKeepAliveEnabled: (bool)enabled
- (void)setSendsKeepAlives: (bool)sendsKeepAlives
{
int v = enabled;
int v = sendsKeepAlives;
if (setsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE,
(char *)&v, (socklen_t)sizeof(v)) != 0)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
}
- (bool)isKeepAliveEnabled
- (bool)sendsKeepAlives
{
int v;
socklen_t len = sizeof(v);
if (getsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE,
(char *)&v, &len) != 0 || len != sizeof(v))
@throw [OFGetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
return v;
}
#endif
#ifndef OF_WII
- (void)setNoDelayEnabled: (bool)enabled
- (void)setCanDelaySendingSegments: (bool)canDelaySendingSegments
{
int v = enabled;
int v = !canDelaySendingSegments;
if (setsockopt(_socket, IPPROTO_TCP, TCP_NODELAY,
(char *)&v, (socklen_t)sizeof(v)) != 0)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
}
- (bool)isNoDelayEnabled
- (bool)canDelaySendingSegments
{
int v;
socklen_t len = sizeof(v);
if (getsockopt(_socket, IPPROTO_TCP, TCP_NODELAY,
(char *)&v, &len) != 0 || len != sizeof(v))
@throw [OFGetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
return v;
return !v;
}
#endif
- (void)close
{
#ifdef OF_WII
_port = 0;
#endif
[super close];
}
@end
|
Modified src/OFTCPSocketSOCKS5Connector.m
from [de0e24bef7]
to [a4bbcb1257].
︙ | | |
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
-
-
-
|
[_request release];
[super dealloc];
}
- (void)didConnect
{
if (_exception == nil)
_socket.blocking = true;
_socket.delegate = _delegate;
#ifdef OF_HAVE_BLOCKS
if (_block != NULL)
_block(_exception);
else {
#endif
|
︙ | | |
Modified src/OFTLSSocket.h
from [c867497861]
to [ba822d3148].
︙ | | |
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
-
+
-
+
-
|
* @warning You have to ensure that this is in secure memory protected from
* swapping! This is also the reason why this is not an OFString.
*/
@property OF_NULLABLE_PROPERTY (assign, nonatomic)
const char *privateKeyPassphrase;
/*!
* @brief Whether certificate verification is enabled.
* @brief Whether certificates are verified.
*
* The default is enabled.
*/
@property (nonatomic, getter=isCertificateVerificationEnabled)
@property (nonatomic) bool verifiesCertificates;
bool certificateVerificationEnabled;
/*!
* @brief Initializes the TLS socket with the specified TCP socket as its
* underlying socket.
*
* @param socket The TCP socket to use as underlying socket
*/
|
︙ | | |
Modified src/OFTarArchive.m
from [9fc8cae7a2]
to [74012ab28d].
︙ | | |
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
|
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
|
-
+
-
+
-
+
|
if (_toWrite > 0)
@throw [OFTruncatedDataException exception];
remainder = 512 - _entry.size % 512;
if (remainder != 512) {
bool wasWriteBuffered = _stream.writeBuffered;
bool didBufferWrites = _stream.buffersWrites;
[_stream setWriteBuffered: true];
_stream.buffersWrites = true;
while (remainder--)
[_stream writeInt8: 0];
[_stream flushWriteBuffer];
_stream.writeBuffered = wasWriteBuffered;
_stream.buffersWrites = didBufferWrites;
}
[_stream release];
_stream = nil;
[super close];
}
@end
|
Modified src/OFUDPSocket.m
from [2b709ddc80]
to [851b1788ef].
︙ | | |
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
-
+
|
@throw [OFBindFailedException
exceptionWithHost: host
port: port
socket: self
errNo: of_socket_errno()];
}
_blocking = true;
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
/* {} needed to avoid warning with Clang 10 if next #if is false. */
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) {
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
}
#endif
|
︙ | | |
Modified utils/ofhttp/OFHTTP.m
from [37d96aee35]
to [da5c2f66e5].
︙ | | |
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
|
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
|
-
+
-
-
+
+
|
@"%[prog]: Cannot use -o / --output when more than one URL "
@"has been specified!",
@"prog", [OFApplication programName])];
[OFApplication terminateWithStatus: 1];
}
if (_insecure)
_HTTPClient.insecureRedirectsAllowed = true;
_HTTPClient.allowsInsecureRedirects = true;
[self performSelector: @selector(downloadNextURL)
afterDelay: 0];
}
- (void)client: (OFHTTPClient *)client
didCreateSocket: (OFTCPSocket *)sock
request: (OFHTTPRequest *)request
{
if (_insecure && [sock respondsToSelector:
@selector(setCertificateVerificationEnabled:)])
((id <OFTLSSocket>)sock).certificateVerificationEnabled = false;
@selector(setVerifiesCertificates:)])
((id <OFTLSSocket>)sock).verifiesCertificates = false;
}
- (void)client: (OFHTTPClient *)client
wantsRequestBody: (OFStream *)body
request: (OFHTTPRequest *)request
{
/* TODO: Do asynchronously and print status */
|
︙ | | |