ObjFW  Check-in [3f74e4c5df]

Overview
Comment:Improve OFAddressTranslationFailedException.

This adds +[exceptionWithHost:]. This is useful when a hostname is
resolved without a socket.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3f74e4c5df7eab532624006d553be92432017b11959cb400a4f7e5315554dcdb
User & Date: js on 2013-06-23 14:15:57
Other Links: manifest | tags
Context
2013-06-23
21:52
Add a few casts to make GCC happy. check-in: 6192726d32 user: js tags: trunk
14:15
Improve OFAddressTranslationFailedException. check-in: 3f74e4c5df user: js tags: trunk
11:28
OFAlreadyConnectedException: Make socket optional. check-in: 71f54d7bb6 user: js tags: trunk
Changes

Modified src/exceptions/OFAddressTranslationFailedException.h from [59a41d896a] to [8d15134d03].

45
46
47
48
49
50
51








52
53
54
55
56
57
58
59
60
61
62
63
64
65
66








67
68
69
70
71
72
73
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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







+
+
+
+
+
+
+
+















+
+
+
+
+
+
+
+







 * @return A new, autoreleased address translation failed exception
 */
+ (instancetype)exceptionWithSocket: (OFTCPSocket*)socket;

/*!
 * @brief Creates a new, autoreleased address translation failed exception.
 *
 * @param host The host for which translation was requested
 * @return A new, autoreleased address translation failed exception
 */
+ (instancetype)exceptionWithHost: (OFString*)host;

/*!
 * @brief Creates a new, autoreleased address translation failed exception.
 *
 * @param host The host for which translation was requested
 * @param socket The socket which could not translate the address
 * @return A new, autoreleased address translation failed exception
 */
+ (instancetype)exceptionWithHost: (OFString*)host
			   socket: (OFTCPSocket*)socket;

/*!
 * @brief Initializes an already allocated address translation failed exception.
 *
 * @param socket The socket which could not translate the address
 * @return An initialized address translation failed exception
 */
- initWithSocket: (OFTCPSocket*)socket;

/*!
 * @brief Initializes an already allocated address translation failed exception.
 *
 * @param host The host for which translation was requested
 * @return An initialized address translation failed exception
 */
- initWithHost: (OFString*)host;

/*!
 * @brief Initializes an already allocated address translation failed exception.
 *
 * @param host The host for which translation was requested
 * @param socket The socket which could not translate the address
 * @return An initialized address translation failed exception
 */

Modified src/exceptions/OFAddressTranslationFailedException.m from [d737be39ca] to [075dc3d4fd].

23
24
25
26
27
28
29





30
31
32
33
34
35
36
37
38

39
40
41
42
43

44
45
46

47
48
49
50

51
52
53

54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44




45



46

47
48

49
50


51








52

53
54
55
56
57
58
59







+
+
+
+
+








-
+

-
-
-
-
+
-
-
-
+
-


-
+

-
-
+
-
-
-
-
-
-
-
-
+
-







#import "common.h"

@implementation OFAddressTranslationFailedException
+ (instancetype)exceptionWithSocket: (OFTCPSocket*)socket
{
	return [[[self alloc] initWithSocket: socket] autorelease];
}

+ (instancetype)exceptionWithHost: (OFString*)host
{
	return [[[self alloc] initWithHost: host] autorelease];
}

+ (instancetype)exceptionWithHost: (OFString*)host
			   socket: (OFTCPSocket*)socket
{
	return [[[self alloc] initWithHost: host
				    socket: socket] autorelease];
}

- init
- initWithSocket: (OFTCPSocket*)socket
{
	@try {
		[self doesNotRecognizeSelector: _cmd];
	} @catch (id e) {
		[self release];
	return [self initWithHost: nil
		@throw e;
	}

			   socket: socket];
	abort();
}

- initWithSocket: (OFTCPSocket*)socket
- initWithHost: (OFString*)host
{
	self = [super init];

	return [self initWithHost: host
	@try {
		_socket = [socket retain];
		_errNo  = GET_AT_ERRNO;
	} @catch (id e) {
		[self release];
		@throw e;
	}

			   socket: nil];
	return self;
}

- initWithHost: (OFString*)host
	socket: (OFTCPSocket*)socket
{
	self = [super init];

85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100

101
102
103













104
105
106
107
108
109
110
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
104
105
106
107
108
109
110
111







-
+







-
+

-
-
+
+
+
+
+
+
+
+
+
+
+
+
+







	[_socket release];

	[super dealloc];
}

- (OFString*)description
{
	if (_host != nil)
	if (_host != nil && _socket != nil)
		return [OFString stringWithFormat:
		    @"The host %@ could not be translated to an address for a "
		    @"socket of type %@. This means that either the host was "
		    @"not found, there was a problem with the name server, "
		    @"there was a problem with your network connection or you "
		    @"specified an invalid host. " ERRFMT, _host,
		    [_socket class], AT_ERRPARAM];
	else
	else if (_socket != nil)
		return [OFString stringWithFormat:
		    @"An address could not be translated translation for a "
		    @"socket of type %@! " ERRFMT, [_socket class],
		    @"An address could not be translated for a socket of type "
		    @"%@! " ERRFMT, [_socket class],
		    AT_ERRPARAM];
	else if (_host != nil)
		return [OFString stringWithFormat:
		    @"The host %@ could not be translated to an address. This "
		    @"means that either the host was not found, there was a "
		    @"problem with the name server, there was a problem with "
		    @"your network connection or you specified an invalid "
		    @"host. " ERRFMT, _host, AT_ERRPARAM];
	else
		return [OFString stringWithFormat:
		    @"An address could not be translated! " ERRFMT,
		    AT_ERRPARAM];
}

- (OFString*)host
{
	OF_GETTER(_host, false)
}