ObjFW  Check-in [4d335e89d6]

Overview
Comment:OFDNSResolver: Look at static hosts to get address
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4d335e89d6ee8359be2eef25e36872723e3d1528fcd989e1073d44c7c63934ad
User & Date: js on 2018-10-07 02:39:39
Other Links: manifest | tags
Context
2018-10-07
21:06
OFTCPSocket: Use OF_KINDOF for block types check-in: 53172692a6 user: js tags: trunk
02:39
OFDNSResolver: Look at static hosts to get address check-in: 4d335e89d6 user: js tags: trunk
02:06
Remove resolver.m check-in: 6e9ee122eb user: js tags: trunk
Changes

Modified src/OFDNSResolver.m from [f094c42133] to [5597695463].

2072
2073
2074
2075
2076
2077
2078

2079
2080
2081
2082
2083
2084
2085
2086
2087


2088
2089
2090

2091


2092
2093
2094
2095




2096



2097
2098




















































2099
2100
2101

2102


2103
2104
2105
2106
2107
2108
2109
			     addressFamily: (of_socket_address_family_t)
						addressFamily
			       runLoopMode: (of_run_loop_mode_t)runLoopMode
				    target: (id)target
				  selector: (SEL)selector
				   context: (id)userContext
{

	void *pool = objc_autoreleasePoolPush();
	OFDNSResolver_AsyncResolveSocketAddressesContext *context;

	@try {
		of_socket_address_t address =
		    of_socket_address_parse_ip(host, 0);
		OFData *addresses;
		void (*method)(id, SEL, OFDNSResolver *, OFString *, OFData *,
		    id, id);



		if (addressFamily != OF_SOCKET_ADDRESS_FAMILY_ANY &&
		    address.family != addressFamily)

			@throw [OFInvalidArgumentException exception];



		addresses = [OFData dataWithItems: &address
				    itemSize: sizeof(address)
				       count: 1];








		method = (void (*)(id, SEL, OFDNSResolver *, OFString *,
		    OFData *, id, id))[target methodForSelector: selector];




















































		method(target, selector, self, host, addresses, userContext,
		    nil);
	} @catch (OFInvalidFormatException *e) {

	}



	context = [[[OFDNSResolver_AsyncResolveSocketAddressesContext alloc]
	    initWithHost: host
		  target: target
		selector: selector
		 context: userContext] autorelease];








>
|





<

|
>
>


|
>
|
>
>




>
>
>
>
|
>
>
>
|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


<
>

>
>







2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085

2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164

2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
			     addressFamily: (of_socket_address_family_t)
						addressFamily
			       runLoopMode: (of_run_loop_mode_t)runLoopMode
				    target: (id)target
				  selector: (SEL)selector
				   context: (id)userContext
{
	OFArray OF_GENERIC(OFString *) *aliases;
	void *pool;
	OFDNSResolver_AsyncResolveSocketAddressesContext *context;

	@try {
		of_socket_address_t address =
		    of_socket_address_parse_ip(host, 0);

		void (*method)(id, SEL, OFDNSResolver *, OFString *, OFData *,
		    id, id) = (void (*)(id, SEL, OFDNSResolver *, OFString *,
		    OFData *, id, id))[target methodForSelector: selector];
		OFData *addresses;

		if (addressFamily != OF_SOCKET_ADDRESS_FAMILY_ANY &&
		    address.family != addressFamily) {
			method(target, selector, self, host, nil, userContext,
			    [OFInvalidArgumentException exception]);
			return;
		}

		addresses = [OFData dataWithItems: &address
				    itemSize: sizeof(address)
				       count: 1];
		method(target, selector, self, host, addresses, userContext,
		    nil);
		return;
	} @catch (OFInvalidFormatException *e) {
	}

	if ((aliases = [_staticHosts objectForKey: host]) != nil) {
		void (*method)(id, SEL, OFDNSResolver *, OFString *, OFData *,
		    id, id) = (void (*)(id, SEL, OFDNSResolver *, OFString *,
		    OFData *, id, id))[target methodForSelector: selector];
		OFMutableData *addresses = [OFMutableData
		    dataWithItemSize: sizeof(of_socket_address_t)];

		for (OFString *alias in aliases) {
			of_socket_address_t address;

			@try {
				address = of_socket_address_parse_ip(alias, 0);
			} @catch (OFInvalidFormatException *e) {
				continue;
			}

			if (addressFamily != OF_SOCKET_ADDRESS_FAMILY_ANY &&
			    address.family != addressFamily)
				continue;

			[addresses addItem: &address];
		}

		[addresses makeImmutable];

		if ([addresses count] == 0) {
			OFResolveHostFailedException *exception;
			of_dns_resource_record_type_t type;

			switch (addressFamily) {
			case OF_SOCKET_ADDRESS_FAMILY_ANY:
				type = OF_DNS_RESOURCE_RECORD_TYPE_ALL;
				break;
			case OF_SOCKET_ADDRESS_FAMILY_IPV4:
				type = OF_DNS_RESOURCE_RECORD_TYPE_A;
				break;
			case OF_SOCKET_ADDRESS_FAMILY_IPV6:
				type = OF_DNS_RESOURCE_RECORD_TYPE_AAAA;
				break;
			default:
				method(target, selector, self, host, nil,
				    userContext,
				    [OFInvalidArgumentException exception]);
				return;
			}

			exception = [OFResolveHostFailedException
			    exceptionWithHost: host
				  recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
				   recordType: type
					error: OF_DNS_RESOLVER_ERROR_NO_RESULT];
			method(target, selector, self, host, nil, userContext,
			    exception);
			return;
		}

		method(target, selector, self, host, addresses, userContext,
		    nil);

		return;
	}

	pool = objc_autoreleasePoolPush();

	context = [[[OFDNSResolver_AsyncResolveSocketAddressesContext alloc]
	    initWithHost: host
		  target: target
		selector: selector
		 context: userContext] autorelease];