︙ | | | ︙ | |
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#import "OFUDPSocket.h"
#import "OFUDPSocket+Private.h"
#import "OFDNSQueryFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#ifndef SOCK_DNS
# define SOCK_DNS 0
#endif
|
|
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#import "OFUDPSocket.h"
#import "OFUDPSocket+Private.h"
#import "OFDNSQueryFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerResponseException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#ifndef SOCK_DNS
# define SOCK_DNS 0
#endif
|
︙ | | | ︙ | |
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
|
componentLength = buffer[(*i)++];
if (componentLength & 0xC0) {
size_t j;
OFString *suffix;
if (pointerLevel == 0)
@throw [OFInvalidServerReplyException
exception];
if (*i >= length)
@throw [OFTruncatedDataException exception];
j = ((componentLength & 0x3F) << 8) | buffer[(*i)++];
if (j == *i - 2)
/* Pointing to itself?! */
@throw [OFInvalidServerReplyException
exception];
suffix = parseName(buffer, length, &j,
pointerLevel - 1);
if (components.count == 0)
return suffix;
|
|
|
|
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
|
componentLength = buffer[(*i)++];
if (componentLength & 0xC0) {
size_t j;
OFString *suffix;
if (pointerLevel == 0)
@throw [OFInvalidServerResponseException
exception];
if (*i >= length)
@throw [OFTruncatedDataException exception];
j = ((componentLength & 0x3F) << 8) | buffer[(*i)++];
if (j == *i - 2)
/* Pointing to itself?! */
@throw [OFInvalidServerResponseException
exception];
suffix = parseName(buffer, length, &j,
pointerLevel - 1);
if (components.count == 0)
return suffix;
|
︙ | | | ︙ | |
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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
234
235
236
237
238
239
|
OFDNSRecordType recordType, uint32_t TTL, const unsigned char *buffer,
size_t length, size_t i, uint16_t dataLength)
{
if (recordType == OFDNSRecordTypeA && DNSClass == OFDNSClassIN) {
OFSocketAddress address;
if (dataLength != 4)
@throw [OFInvalidServerReplyException exception];
memset(&address, 0, sizeof(address));
address.family = OFSocketAddressFamilyIPv4;
address.length = sizeof(address.sockaddr.in);
address.sockaddr.in.sin_family = AF_INET;
memcpy(&address.sockaddr.in.sin_addr.s_addr, buffer + i, 4);
return [[[OFADNSResourceRecord alloc]
initWithName: name
address: &address
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeNS) {
size_t j = i;
OFString *authoritativeHost = parseName(buffer, length, &j,
maxAllowedPointers);
if (j != i + dataLength)
@throw [OFInvalidServerReplyException exception];
return [[[OFNSDNSResourceRecord alloc]
initWithName: name
DNSClass: DNSClass
authoritativeHost: authoritativeHost
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeCNAME) {
size_t j = i;
OFString *alias = parseName(buffer, length, &j,
maxAllowedPointers);
if (j != i + dataLength)
@throw [OFInvalidServerReplyException exception];
return [[[OFCNAMEDNSResourceRecord alloc]
initWithName: name
DNSClass: DNSClass
alias: alias
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeSOA) {
size_t j = i;
OFString *primaryNameServer = parseName(buffer, length, &j,
maxAllowedPointers);
OFString *responsiblePerson;
uint32_t serialNumber, refreshInterval, retryInterval;
uint32_t expirationInterval, minTTL;
if (j > i + dataLength)
@throw [OFInvalidServerReplyException exception];
responsiblePerson = parseName(buffer, length, &j,
maxAllowedPointers);
if (dataLength - (j - i) != 20)
@throw [OFInvalidServerReplyException exception];
serialNumber = (buffer[j] << 24) | (buffer[j + 1] << 16) |
(buffer[j + 2] << 8) | buffer[j + 3];
refreshInterval = (buffer[j + 4] << 24) |
(buffer[j + 5] << 16) | (buffer[j + 6] << 8) |
buffer[j + 7];
retryInterval = (buffer[j + 8] << 24) | (buffer[j + 9] << 16) |
|
|
|
|
|
|
|
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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
234
235
236
237
238
239
|
OFDNSRecordType recordType, uint32_t TTL, const unsigned char *buffer,
size_t length, size_t i, uint16_t dataLength)
{
if (recordType == OFDNSRecordTypeA && DNSClass == OFDNSClassIN) {
OFSocketAddress address;
if (dataLength != 4)
@throw [OFInvalidServerResponseException exception];
memset(&address, 0, sizeof(address));
address.family = OFSocketAddressFamilyIPv4;
address.length = sizeof(address.sockaddr.in);
address.sockaddr.in.sin_family = AF_INET;
memcpy(&address.sockaddr.in.sin_addr.s_addr, buffer + i, 4);
return [[[OFADNSResourceRecord alloc]
initWithName: name
address: &address
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeNS) {
size_t j = i;
OFString *authoritativeHost = parseName(buffer, length, &j,
maxAllowedPointers);
if (j != i + dataLength)
@throw [OFInvalidServerResponseException exception];
return [[[OFNSDNSResourceRecord alloc]
initWithName: name
DNSClass: DNSClass
authoritativeHost: authoritativeHost
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeCNAME) {
size_t j = i;
OFString *alias = parseName(buffer, length, &j,
maxAllowedPointers);
if (j != i + dataLength)
@throw [OFInvalidServerResponseException exception];
return [[[OFCNAMEDNSResourceRecord alloc]
initWithName: name
DNSClass: DNSClass
alias: alias
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeSOA) {
size_t j = i;
OFString *primaryNameServer = parseName(buffer, length, &j,
maxAllowedPointers);
OFString *responsiblePerson;
uint32_t serialNumber, refreshInterval, retryInterval;
uint32_t expirationInterval, minTTL;
if (j > i + dataLength)
@throw [OFInvalidServerResponseException exception];
responsiblePerson = parseName(buffer, length, &j,
maxAllowedPointers);
if (dataLength - (j - i) != 20)
@throw [OFInvalidServerResponseException exception];
serialNumber = (buffer[j] << 24) | (buffer[j + 1] << 16) |
(buffer[j + 2] << 8) | buffer[j + 3];
refreshInterval = (buffer[j + 4] << 24) |
(buffer[j + 5] << 16) | (buffer[j + 6] << 8) |
buffer[j + 7];
retryInterval = (buffer[j + 8] << 24) | (buffer[j + 9] << 16) |
|
︙ | | | ︙ | |
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
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
|
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypePTR) {
size_t j = i;
OFString *domainName = parseName(buffer, length, &j,
maxAllowedPointers);
if (j != i + dataLength)
@throw [OFInvalidServerReplyException exception];
return [[[OFPTRDNSResourceRecord alloc]
initWithName: name
DNSClass: DNSClass
domainName: domainName
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeHINFO) {
size_t j = i;
OFString *CPU = parseString(buffer, length, &j);
OFString *OS;
if (j > i + dataLength)
@throw [OFInvalidServerReplyException exception];
OS = parseString(buffer, length, &j);
if (j != i + dataLength)
@throw [OFInvalidServerReplyException exception];
return [[[OFHINFODNSResourceRecord alloc]
initWithName: name
DNSClass: DNSClass
CPU: CPU
OS: OS
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeMX) {
uint16_t preference;
size_t j;
OFString *mailExchange;
if (dataLength < 2)
@throw [OFInvalidServerReplyException exception];
preference = (buffer[i] << 8) | buffer[i + 1];
j = i + 2;
mailExchange = parseName(buffer, length, &j,
maxAllowedPointers);
if (j != i + dataLength)
@throw [OFInvalidServerReplyException exception];
return [[[OFMXDNSResourceRecord alloc]
initWithName: name
DNSClass: DNSClass
preference: preference
mailExchange: mailExchange
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeTXT) {
OFMutableArray *textStrings = [OFMutableArray array];
while (dataLength > 0) {
uint_fast8_t stringLength = buffer[i++];
dataLength--;
if (stringLength > dataLength)
@throw [OFInvalidServerReplyException
exception];
[textStrings addObject:
[OFData dataWithItems: buffer + i
count: stringLength]];
i += stringLength;
|
|
|
|
|
|
|
|
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
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
|
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypePTR) {
size_t j = i;
OFString *domainName = parseName(buffer, length, &j,
maxAllowedPointers);
if (j != i + dataLength)
@throw [OFInvalidServerResponseException exception];
return [[[OFPTRDNSResourceRecord alloc]
initWithName: name
DNSClass: DNSClass
domainName: domainName
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeHINFO) {
size_t j = i;
OFString *CPU = parseString(buffer, length, &j);
OFString *OS;
if (j > i + dataLength)
@throw [OFInvalidServerResponseException exception];
OS = parseString(buffer, length, &j);
if (j != i + dataLength)
@throw [OFInvalidServerResponseException exception];
return [[[OFHINFODNSResourceRecord alloc]
initWithName: name
DNSClass: DNSClass
CPU: CPU
OS: OS
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeMX) {
uint16_t preference;
size_t j;
OFString *mailExchange;
if (dataLength < 2)
@throw [OFInvalidServerResponseException exception];
preference = (buffer[i] << 8) | buffer[i + 1];
j = i + 2;
mailExchange = parseName(buffer, length, &j,
maxAllowedPointers);
if (j != i + dataLength)
@throw [OFInvalidServerResponseException exception];
return [[[OFMXDNSResourceRecord alloc]
initWithName: name
DNSClass: DNSClass
preference: preference
mailExchange: mailExchange
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeTXT) {
OFMutableArray *textStrings = [OFMutableArray array];
while (dataLength > 0) {
uint_fast8_t stringLength = buffer[i++];
dataLength--;
if (stringLength > dataLength)
@throw [OFInvalidServerResponseException
exception];
[textStrings addObject:
[OFData dataWithItems: buffer + i
count: stringLength]];
i += stringLength;
|
︙ | | | ︙ | |
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
} else if (recordType == OFDNSRecordTypeRP) {
size_t j = i;
OFString *mailbox = parseName(buffer, length, &j,
maxAllowedPointers);
OFString *TXTDomainName;
if (j > i + dataLength)
@throw [OFInvalidServerReplyException exception];
TXTDomainName = parseName(buffer, length, &j,
maxAllowedPointers);
if (j != i + dataLength)
@throw [OFInvalidServerReplyException exception];
return [[[OFRPDNSResourceRecord alloc]
initWithName: name
DNSClass: DNSClass
mailbox: mailbox
TXTDomainName: TXTDomainName
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeAAAA &&
DNSClass == OFDNSClassIN) {
OFSocketAddress address;
if (dataLength != 16)
@throw [OFInvalidServerReplyException exception];
memset(&address, 0, sizeof(address));
address.family = OFSocketAddressFamilyIPv6;
address.length = sizeof(address.sockaddr.in6);
#ifdef AF_INET6
address.sockaddr.in6.sin6_family = AF_INET6;
|
|
|
|
|
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
} else if (recordType == OFDNSRecordTypeRP) {
size_t j = i;
OFString *mailbox = parseName(buffer, length, &j,
maxAllowedPointers);
OFString *TXTDomainName;
if (j > i + dataLength)
@throw [OFInvalidServerResponseException exception];
TXTDomainName = parseName(buffer, length, &j,
maxAllowedPointers);
if (j != i + dataLength)
@throw [OFInvalidServerResponseException exception];
return [[[OFRPDNSResourceRecord alloc]
initWithName: name
DNSClass: DNSClass
mailbox: mailbox
TXTDomainName: TXTDomainName
TTL: TTL] autorelease];
} else if (recordType == OFDNSRecordTypeAAAA &&
DNSClass == OFDNSClassIN) {
OFSocketAddress address;
if (dataLength != 16)
@throw [OFInvalidServerResponseException exception];
memset(&address, 0, sizeof(address));
address.family = OFSocketAddressFamilyIPv6;
address.length = sizeof(address.sockaddr.in6);
#ifdef AF_INET6
address.sockaddr.in6.sin6_family = AF_INET6;
|
︙ | | | ︙ | |
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
} else if (recordType == OFDNSRecordTypeSRV &&
DNSClass == OFDNSClassIN) {
uint16_t priority, weight, port;
size_t j;
OFString *target;
if (dataLength < 6)
@throw [OFInvalidServerReplyException exception];
priority = (buffer[i] << 8) | buffer[i + 1];
weight = (buffer[i + 2] << 8) | buffer[i + 3];
port = (buffer[i + 4] << 8) | buffer[i + 5];
j = i + 6;
target = parseName(buffer, length, &j, maxAllowedPointers);
if (j != i + dataLength)
@throw [OFInvalidServerReplyException exception];
return [[[OFSRVDNSResourceRecord alloc]
initWithName: name
priority: priority
weight: weight
target: target
port: port
|
|
|
|
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
} else if (recordType == OFDNSRecordTypeSRV &&
DNSClass == OFDNSClassIN) {
uint16_t priority, weight, port;
size_t j;
OFString *target;
if (dataLength < 6)
@throw [OFInvalidServerResponseException exception];
priority = (buffer[i] << 8) | buffer[i + 1];
weight = (buffer[i + 2] << 8) | buffer[i + 3];
port = (buffer[i + 4] << 8) | buffer[i + 5];
j = i + 6;
target = parseName(buffer, length, &j, maxAllowedPointers);
if (j != i + dataLength)
@throw [OFInvalidServerResponseException exception];
return [[[OFSRVDNSResourceRecord alloc]
initWithName: name
priority: priority
weight: weight
target: target
port: port
|
︙ | | | ︙ | |
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
|
context->_queryData.count < 12)
@throw [OFInvalidArgumentException exception];
queryDataBuffer = context->_queryData.items;
/* QR */
if ((buffer[2] & 0x80) == 0)
@throw [OFInvalidServerReplyException exception];
/* Opcode */
if ((buffer[2] & 0x78) != (queryDataBuffer[2] & 0x78))
@throw [OFInvalidServerReplyException exception];
/* TC */
if (buffer[2] & 0x02) {
OFRunLoopMode runLoopMode;
if (context->_settings->_usesTCP)
@throw [OFTruncatedDataException exception];
|
|
|
|
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
|
context->_queryData.count < 12)
@throw [OFInvalidArgumentException exception];
queryDataBuffer = context->_queryData.items;
/* QR */
if ((buffer[2] & 0x80) == 0)
@throw [OFInvalidServerResponseException exception];
/* Opcode */
if ((buffer[2] & 0x78) != (queryDataBuffer[2] & 0x78))
@throw [OFInvalidServerResponseException exception];
/* TC */
if (buffer[2] & 0x02) {
OFRunLoopMode runLoopMode;
if (context->_settings->_usesTCP)
@throw [OFTruncatedDataException exception];
|
︙ | | | ︙ | |
︙ | | | ︙ | |
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#import "OFURL.h"
#import "OFAlreadyConnectedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"
#import "OFUnsupportedVersionException.h"
|
|
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#import "OFURL.h"
#import "OFAlreadyConnectedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerResponseException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"
#import "OFUnsupportedVersionException.h"
|
︙ | | | ︙ | |
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
|
if (line == nil) {
[self closeAndReconnect];
return false;
}
if (![line hasPrefix: @"HTTP/"] || line.length < 9 ||
[line characterAtIndex: 8] != ' ')
@throw [OFInvalidServerReplyException exception];
_version = [[line substringWithRange: OFMakeRange(5, 3)] copy];
if (![_version isEqual: @"1.0"] && ![_version isEqual: @"1.1"])
@throw [OFUnsupportedVersionException
exceptionWithVersion: _version];
status = [line substringWithRange: OFMakeRange(9, 3)].longLongValue;
if (status < 0 || status > 599)
@throw [OFInvalidServerReplyException exception];
_status = (short)status;
return true;
}
- (bool)handleServerHeader: (OFString *)line stream: (OFStream *)stream
{
OFString *key, *value, *old;
const char *lineC, *tmp;
char *keyC;
if (line == nil)
@throw [OFInvalidServerReplyException exception];
if (line.length == 0) {
[_serverHeaders makeImmutable];
if ([_client->_delegate respondsToSelector: @selector(client:
didReceiveHeaders:statusCode:request:)])
[_client->_delegate client: _client
|
|
|
|
|
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
|
if (line == nil) {
[self closeAndReconnect];
return false;
}
if (![line hasPrefix: @"HTTP/"] || line.length < 9 ||
[line characterAtIndex: 8] != ' ')
@throw [OFInvalidServerResponseException exception];
_version = [[line substringWithRange: OFMakeRange(5, 3)] copy];
if (![_version isEqual: @"1.0"] && ![_version isEqual: @"1.1"])
@throw [OFUnsupportedVersionException
exceptionWithVersion: _version];
status = [line substringWithRange: OFMakeRange(9, 3)].longLongValue;
if (status < 0 || status > 599)
@throw [OFInvalidServerResponseException exception];
_status = (short)status;
return true;
}
- (bool)handleServerHeader: (OFString *)line stream: (OFStream *)stream
{
OFString *key, *value, *old;
const char *lineC, *tmp;
char *keyC;
if (line == nil)
@throw [OFInvalidServerResponseException exception];
if (line.length == 0) {
[_serverHeaders makeImmutable];
if ([_client->_delegate respondsToSelector: @selector(client:
didReceiveHeaders:statusCode:request:)])
[_client->_delegate client: _client
|
︙ | | | ︙ | |
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
return false;
}
lineC = line.UTF8String;
if ((tmp = strchr(lineC, ':')) == NULL)
@throw [OFInvalidServerReplyException exception];
keyC = OFAllocMemory(tmp - lineC + 1, 1);
memcpy(keyC, lineC, tmp - lineC);
keyC[tmp - lineC] = '\0';
normalizeKey(keyC);
@try {
|
|
|
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
return false;
}
lineC = line.UTF8String;
if ((tmp = strchr(lineC, ':')) == NULL)
@throw [OFInvalidServerResponseException exception];
keyC = OFAllocMemory(tmp - lineC + 1, 1);
memcpy(keyC, lineC, tmp - lineC);
keyC[tmp - lineC] = '\0';
normalizeKey(keyC);
@try {
|
︙ | | | ︙ | |
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
|
exception: (id)exception
{
bool ret;
if (exception != nil) {
if ([exception isKindOfClass:
[OFInvalidEncodingException class]])
exception = [OFInvalidServerReplyException exception];
[self raiseException: exception];
return false;
}
@try {
if (_firstLine) {
|
|
>
|
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
|
exception: (id)exception
{
bool ret;
if (exception != nil) {
if ([exception isKindOfClass:
[OFInvalidEncodingException class]])
exception =
[OFInvalidServerResponseException exception];
[self raiseException: exception];
return false;
}
@try {
if (_firstLine) {
|
︙ | | | ︙ | |
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
|
_chunked = [[headers objectForKey: @"Transfer-Encoding"]
isEqual: @"chunked"];
contentLength = [headers objectForKey: @"Content-Length"];
if (contentLength != nil) {
if (_chunked || contentLength.length == 0)
@throw [OFInvalidServerReplyException exception];
_hasContentLength = true;
@try {
unsigned long long toRead =
contentLength.unsignedLongLongValue;
if (toRead > LLONG_MAX)
@throw [OFOutOfRangeException exception];
_toRead = (long long)toRead;
} @catch (OFInvalidFormatException *e) {
@throw [OFInvalidServerReplyException exception];
}
}
}
- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length
{
if (_stream == nil)
|
|
|
|
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
|
_chunked = [[headers objectForKey: @"Transfer-Encoding"]
isEqual: @"chunked"];
contentLength = [headers objectForKey: @"Content-Length"];
if (contentLength != nil) {
if (_chunked || contentLength.length == 0)
@throw [OFInvalidServerResponseException exception];
_hasContentLength = true;
@try {
unsigned long long toRead =
contentLength.unsignedLongLongValue;
if (toRead > LLONG_MAX)
@throw [OFOutOfRangeException exception];
_toRead = (long long)toRead;
} @catch (OFInvalidFormatException *e) {
@throw [OFInvalidServerResponseException exception];
}
}
}
- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length
{
if (_stream == nil)
|
︙ | | | ︙ | |
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
|
if (_toRead == -2) {
char tmp[2];
switch ([_stream readIntoBuffer: tmp length: 2]) {
case 2:
_toRead++;
if (tmp[1] != '\n')
@throw [OFInvalidServerReplyException
exception];
case 1:
_toRead++;
if (tmp[0] != '\r')
@throw [OFInvalidServerReplyException
exception];
}
if (_setAtEndOfStream && _toRead == 0)
_atEndOfStream = true;
return 0;
} else if (_toRead == -1) {
char tmp;
if ([_stream readIntoBuffer: &tmp length: 1] == 1) {
_toRead++;
if (tmp != '\n')
@throw [OFInvalidServerReplyException
exception];
}
if (_setAtEndOfStream && _toRead == 0)
_atEndOfStream = true;
return 0;
|
|
|
|
|
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
|
if (_toRead == -2) {
char tmp[2];
switch ([_stream readIntoBuffer: tmp length: 2]) {
case 2:
_toRead++;
if (tmp[1] != '\n')
@throw [OFInvalidServerResponseException
exception];
case 1:
_toRead++;
if (tmp[0] != '\r')
@throw [OFInvalidServerResponseException
exception];
}
if (_setAtEndOfStream && _toRead == 0)
_atEndOfStream = true;
return 0;
} else if (_toRead == -1) {
char tmp;
if ([_stream readIntoBuffer: &tmp length: 1] == 1) {
_toRead++;
if (tmp != '\n')
@throw [OFInvalidServerResponseException
exception];
}
if (_setAtEndOfStream && _toRead == 0)
_atEndOfStream = true;
return 0;
|
︙ | | | ︙ | |
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
|
void *pool = objc_autoreleasePoolPush();
OFString *line;
size_t pos;
@try {
line = [_stream tryReadLine];
} @catch (OFInvalidEncodingException *e) {
@throw [OFInvalidServerReplyException exception];
}
if (line == nil)
return 0;
pos = [line rangeOfString: @";"].location;
if (pos != OFNotFound)
line = [line substringToIndex: pos];
if (line.length < 1) {
/*
* We have read the empty string because the stream is
* at end of stream.
*/
if (_stream.atEndOfStream && pos == OFNotFound)
@throw [OFTruncatedDataException exception];
else
@throw [OFInvalidServerReplyException
exception];
}
@try {
unsigned long long toRead =
[line unsignedLongLongValueWithBase: 16];
if (toRead > LLONG_MAX)
@throw [OFOutOfRangeException exception];
_toRead = (long long)toRead;
} @catch (OFInvalidFormatException *e) {
@throw [OFInvalidServerReplyException exception];
}
if (_toRead == 0) {
_setAtEndOfStream = true;
_toRead = -2;
}
|
|
|
|
|
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
|
void *pool = objc_autoreleasePoolPush();
OFString *line;
size_t pos;
@try {
line = [_stream tryReadLine];
} @catch (OFInvalidEncodingException *e) {
@throw [OFInvalidServerResponseException exception];
}
if (line == nil)
return 0;
pos = [line rangeOfString: @";"].location;
if (pos != OFNotFound)
line = [line substringToIndex: pos];
if (line.length < 1) {
/*
* We have read the empty string because the stream is
* at end of stream.
*/
if (_stream.atEndOfStream && pos == OFNotFound)
@throw [OFTruncatedDataException exception];
else
@throw [OFInvalidServerResponseException
exception];
}
@try {
unsigned long long toRead =
[line unsignedLongLongValueWithBase: 16];
if (toRead > LLONG_MAX)
@throw [OFOutOfRangeException exception];
_toRead = (long long)toRead;
} @catch (OFInvalidFormatException *e) {
@throw [OFInvalidServerResponseException exception];
}
if (_toRead == 0) {
_setAtEndOfStream = true;
_toRead = -2;
}
|
︙ | | | ︙ | |
︙ | | | ︙ | |
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# import "ObjFWTLS.h"
#endif
#import "OFConnectionFailedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFResolveHostFailedException.h"
#import "OFRetrieveItemAttributesFailedException.h"
#import "OFUnsupportedProtocolException.h"
#import "OFWriteFailedException.h"
|
|
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# import "ObjFWTLS.h"
#endif
#import "OFConnectionFailedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerResponseException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFResolveHostFailedException.h"
#import "OFRetrieveItemAttributesFailedException.h"
#import "OFUnsupportedProtocolException.h"
#import "OFWriteFailedException.h"
|
︙ | | | ︙ | |
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
|
OF_LOCALIZED(@"download_failed_connection_failed",
@"%[prog]: Failed to download <%[url]>!\n"
@" Connection failed: %[exception]",
@"prog", [OFApplication programName],
@"url", request.URL.string,
@"exception", exception)];
} else if ([exception isKindOfClass:
[OFInvalidServerReplyException class]]) {
if (!_quiet)
[OFStdOut writeString: @"\n"];
[OFStdErr writeLine: OF_LOCALIZED(
@"download_failed_invalid_server_reply",
@"%[prog]: Failed to download <%[url]>!\n"
@" Invalid server reply!",
@"prog", [OFApplication programName],
@"url", request.URL.string)];
} else if ([exception isKindOfClass:
[OFUnsupportedProtocolException class]]) {
if (!_quiet)
[OFStdOut writeString: @"\n"];
|
|
|
|
|
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
|
OF_LOCALIZED(@"download_failed_connection_failed",
@"%[prog]: Failed to download <%[url]>!\n"
@" Connection failed: %[exception]",
@"prog", [OFApplication programName],
@"url", request.URL.string,
@"exception", exception)];
} else if ([exception isKindOfClass:
[OFInvalidServerResponseException class]]) {
if (!_quiet)
[OFStdOut writeString: @"\n"];
[OFStdErr writeLine: OF_LOCALIZED(
@"download_failed_invalid_server_response",
@"%[prog]: Failed to download <%[url]>!\n"
@" Invalid server response!",
@"prog", [OFApplication programName],
@"url", request.URL.string)];
} else if ([exception isKindOfClass:
[OFUnsupportedProtocolException class]]) {
if (!_quiet)
[OFStdOut writeString: @"\n"];
|
︙ | | | ︙ | |