ObjFW  Diff

Differences From Artifact [de3749afa6]:

To Artifact [aa220e27b3]:


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50







-








+







#import "resolver.h"
#import "macros.h"

#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
# include "threading.h"
#endif

#import "OFAddressTranslationFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
# import "OFLockFailedException.h"
# import "OFUnlockFailedException.h"
#endif
#import "OFResolveHostFailedException.h"

#import "socket_helpers.h"

#if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
static of_mutex_t mutex;

OF_CONSTRUCTOR()
71
72
73
74
75
76
77
78
79
80
81
82



83


84

85
86
87
88
89
90
91
92
93





94
95
96
97
98
99
100
71
72
73
74
75
76
77





78
79
80
81
82
83

84
85
86
87
88
89
90
91


92
93
94
95
96
97
98
99
100
101
102
103







-
-
-
-
-
+
+
+

+
+
-
+







-
-
+
+
+
+
+








# if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
	if (!of_mutex_lock(&mutex))
		@throw [OFLockFailedException exception];

	@try {
# endif
		int error;

		if ((error = getaddrinfo([host UTF8String], portCString, &hints,
		    &res0)) != 0)
			@throw [OFAddressTranslationFailedException
		if (getaddrinfo([host UTF8String], portCString, &hints,
		    &res0) != 0)
			@throw [OFResolveHostFailedException
			    exceptionWithHost: host
				  recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
				   recordType: 0
					error: error];
					error: OF_DNS_RESOLVER_ERROR_UNKNOWN];

		count = 0;
		for (res = res0; res != NULL; res = res->ai_next)
			count++;

		if (count == 0) {
			freeaddrinfo(res0);
			@throw [OFAddressTranslationFailedException
			    exceptionWithHost: host];
			@throw [OFResolveHostFailedException
			    exceptionWithHost: host
				  recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
				   recordType: 0
					error: OF_DNS_RESOLVER_ERROR_NO_RESULT];
		}

		if ((ret = calloc(count + 1, sizeof(*ret))) == NULL) {
			freeaddrinfo(res0);
			@throw [OFOutOfMemoryException
			    exceptionWithRequestedSize: (count + 1) *
							sizeof(*ret)];
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
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







-
+

+
+
-
+






-
-
+
+
+
+
+







			ret[1] = NULL;

			return ret;
		}

		if ((he = gethostbyname((const void *)[host UTF8String])) ==
		    NULL || he->h_addrtype != AF_INET)
			@throw [OFAddressTranslationFailedException
			@throw [OFResolveHostFailedException
			    exceptionWithHost: host
				  recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
				   recordType: 0
					error: h_errno];
					error: OF_DNS_RESOLVER_ERROR_UNKNOWN];

		count = 0;
		for (ip = (char **)he->h_addr_list; *ip != NULL; ip++)
			count++;

		if (count == 0)
			@throw [OFAddressTranslationFailedException
			    exceptionWithHost: host];
			@throw [OFResolveHostFailedException
			    exceptionWithHost: host
				  recordClass: OF_DNS_RESOURCE_RECORD_CLASS_IN
				   recordType: 0
					error: OF_DNS_RESOLVER_ERROR_NO_RESULT];

		if ((ret = calloc(count + 1, sizeof(*ret))) == NULL)
			@throw [OFOutOfMemoryException
			    exceptionWithRequestedSize: (count + 1) *
							sizeof(*ret)];

		if ((results = malloc(count * sizeof(*results))) == NULL) {