Differences From Artifact [8914dd7f51]:
- File
src/OFDNSResolver.m
— part of check-in
[8555d64ee6]
at
2018-09-10 20:44:40
on branch trunk
— OFDNSResolver: Method to resolve host to addresses
This provides more convenience when the goal is to connect a socket and
provides functionality similar to getaddrinfo().No support for resolving CNAMEs yet - this will be the next step. (user: js, size: 48894) [annotate] [blame] [check-ins using]
To Artifact [721e3310ec]:
- File src/OFDNSResolver.m — part of check-in [7ba597c52d] at 2018-09-15 13:45:03 on branch trunk — OFDNSResolver: Group records by domain name (user: js, size: 49332) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
170 171 172 173 174 175 176 | - (instancetype)initWithHost: (OFString *)host target: (id)target selector: (SEL)selector context: (id)context; - (void)resolver: (OFDNSResolver *)resolver didResolveDomainName: (OFString *)domainName | | | | | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | - (instancetype)initWithHost: (OFString *)host target: (id)target selector: (SEL)selector context: (id)context; - (void)resolver: (OFDNSResolver *)resolver didResolveDomainName: (OFString *)domainName answerRecords: (OFDictionary *)answerRecords authorityRecords: (OFDictionary *)authorityRecords additionalRecords: (OFDictionary *)additionalRecords context: (id)context exception: (id)exception; @end @interface OFDNSResolver () - (void)of_setDefaults; - (void)of_obtainSystemConfig; |
︙ | ︙ | |||
583 584 585 586 587 588 589 | return [[[OFDNSResourceRecord alloc] initWithName: name recordClass: recordClass recordType: recordType TTL: TTL] autorelease]; } | | > > | | 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | return [[[OFDNSResourceRecord alloc] initWithName: name recordClass: recordClass recordType: recordType TTL: TTL] autorelease]; } static OFDictionary * parseSection(const unsigned char *buffer, size_t length, size_t *i, uint_fast16_t count) { OFMutableDictionary *ret = [OFMutableDictionary dictionary]; OFEnumerator OF_GENERIC(OFMutableArray *) *objectEnumerator; OFMutableArray *array; for (uint_fast16_t j = 0; j < count; j++) { OFString *name = parseName(buffer, length, i, MAX_ALLOWED_POINTERS); of_dns_resource_record_class_t recordClass; of_dns_resource_record_type_t recordType; uint32_t TTL; |
︙ | ︙ | |||
616 617 618 619 620 621 622 | if (*i + dataLength > length) @throw [OFTruncatedDataException exception]; record = parseResourceRecord(name, recordClass, recordType, TTL, buffer, length, *i, dataLength); *i += dataLength; | > > > > > > > > | > > > > | > | | | | | | 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | if (*i + dataLength > length) @throw [OFTruncatedDataException exception]; record = parseResourceRecord(name, recordClass, recordType, TTL, buffer, length, *i, dataLength); *i += dataLength; array = [ret objectForKey: name]; if (array == nil) { array = [OFMutableArray array]; [ret setObject: array forKey: name]; } [array addObject: record]; } objectEnumerator = [ret objectEnumerator]; while ((array = [objectEnumerator nextObject]) != nil) [array makeImmutable]; [ret makeImmutable]; return ret; } static void callback(id target, SEL selector, OFDNSResolver *resolver, OFString *domainName, OFDictionary *answerRecords, OFDictionary *authorityRecords, OFDictionary *additionalRecords, id context, id exception) { void (*method)(id, SEL, OFDNSResolver *, OFString *, OFDictionary *, OFDictionary *, OFDictionary *, id, id) = (void (*)(id, SEL, OFDNSResolver *, OFString *, OFDictionary *, OFDictionary *, OFDictionary *, id, id))[target methodForSelector: selector]; method(target, selector, resolver, domainName, answerRecords, authorityRecords, additionalRecords, context, exception); } @implementation OFDNSResolverSettings - (instancetype)initWithNameServers: (OFArray *)nameServers |
︙ | ︙ | |||
812 813 814 815 816 817 818 | [_records release]; [super dealloc]; } - (void)resolver: (OFDNSResolver *)resolver didResolveDomainName: (OFString *)domainName | | | | | | < < | 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 | [_records release]; [super dealloc]; } - (void)resolver: (OFDNSResolver *)resolver didResolveDomainName: (OFString *)domainName answerRecords: (OFDictionary *)answerRecords authorityRecords: (OFDictionary *)authorityRecords additionalRecords: (OFDictionary *)additionalRecords context: (id)context exception: (id)exception { /* * TODO: Error handling could be improved. Ignore error if there are * responses, otherwise propagate error. */ of_socket_address_family_t addressFamily = [context intValue]; _expectedResponses--; if (exception == nil) { for (OFDNSResourceRecord *record in [answerRecords objectForKey: domainName]) { if ([record recordClass] != OF_DNS_RESOURCE_RECORD_CLASS_IN) continue; switch ([record recordType]) { case OF_DNS_RESOURCE_RECORD_TYPE_A: if (addressFamily == |
︙ | ︙ | |||
1609 1610 1611 1612 1613 1614 1615 | - (bool)of_socket: (OFUDPSocket *)sock didReceiveIntoBuffer: (unsigned char *)buffer length: (size_t)length sender: (of_socket_address_t)sender context: (id)context exception: (id)exception { | | | | 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 | - (bool)of_socket: (OFUDPSocket *)sock didReceiveIntoBuffer: (unsigned char *)buffer length: (size_t)length sender: (of_socket_address_t)sender context: (id)context exception: (id)exception { OFDictionary *answerRecords = nil, *authorityRecords = nil; OFDictionary *additionalRecords = nil; OFNumber *ID; OFDNSResolverQuery *query; if (exception != nil) { if ([exception respondsToSelector: @selector(errNo)]) return ([exception errNo] == EINTR); |
︙ | ︙ |