ObjFW  Check-in [a3b3333128]

Overview
Comment:Make it possible to set a default SOCKS5 proxy for all OFTCPSockets.

For example, this is useful if you want to use
+[OFString stringWithContentsOfURL:] with a proxy or if you just want
to use anything that uses an OFTCPSocket with a proxy (even 3rd party
libraries).

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a3b3333128a717d5472a1636f4cef12b789b7d6b4956247666616a2052c1d8ad
User & Date: js on 2011-12-08 02:25:45
Other Links: manifest | tags
Context
2011-12-08
02:45
Stop Xcode 4.2 from trying to "upgrade" the project. check-in: 7e335ca1a8 user: js tags: trunk
02:25
Make it possible to set a default SOCKS5 proxy for all OFTCPSockets. check-in: a3b3333128 user: js tags: trunk
2011-12-06
02:02
Remove useless invocation of +[OFObject inheritMethodsFromClass:]. check-in: 4f62045a3a user: js tags: trunk
Changes

Modified src/OFTCPSocket.h from [02231d7620] to [fa3ba9a6c5].

45
46
47
48
49
50
51




























52
53
54
55
56
57
58

#ifdef OF_HAVE_PROPERTIES
@property (assign, readonly, getter=isListening) BOOL listening;
@property (copy) OFString *SOCKS5Host;
@property (assign) uint16_t SOCKS5Port;
#endif





























/**
 * \brief Sets the host to use as a SOCKS5 proxy.
 *
 * \param host The host to use as a SOCKS5 proxy
 */
- (void)setSOCKS5Host: (OFString*)host;








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







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

#ifdef OF_HAVE_PROPERTIES
@property (assign, readonly, getter=isListening) BOOL listening;
@property (copy) OFString *SOCKS5Host;
@property (assign) uint16_t SOCKS5Port;
#endif

/**
 * \brief Sets the global SOCKS5 proxy host to use when creating a new socket
 *
 * \param host The host to use as a SOCKS5 proxy when creating a new socket
 */
+ (void)setSOCKS5Host: (OFString*)host;

/**
 * \brief Returns the host to use as a SOCKS5 proxy when creating a new socket
 *
 * \return The host to use as a SOCKS5 proxy when creating a new socket
 */
+ (OFString*)SOCKS5Host;

/**
 * \brief Sets the global SOCKS5 proxy port to use when creating a new socket
 *
 * \param port The port to use as a SOCKS5 proxy when creating a new socket
 */
+ (void)setSOCKS5Port: (uint16_t)port;

/**
 * \brief Returns the port to use as a SOCKS5 proxy when creating a new socket
 *
 * \return The port to use as a SOCKS5 proxy when creating a new socket
 */
+ (uint16_t)SOCKS5Port;

/**
 * \brief Sets the host to use as a SOCKS5 proxy.
 *
 * \param host The host to use as a SOCKS5 proxy
 */
- (void)setSOCKS5Host: (OFString*)host;

Modified src/OFTCPSocket.m from [367a20fe47] to [59c9f9facb].

66
67
68
69
70
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

/* References for static linking */
void _references_to_categories_of_OFTCPSocket(void)
{
	_OFTCPSocket_SOCKS5_reference = 1;
}




@implementation OFTCPSocket
#if defined(OF_THREADS) && !defined(HAVE_THREADSAFE_GETADDRINFO)
+ (void)initialize
{
	if (self == [OFTCPSocket class])
		mutex = [[OFMutex alloc] init];
}
#endif























- init
{
	self = [super init];


	sock = INVALID_SOCKET;
	sockAddr = NULL;

	SOCKS5Port = 1080;





	return self;
}








- (void)setSOCKS5Host: (OFString*)host
{
	OF_SETTER(SOCKS5Host, host, YES, YES)
}

- (OFString*)SOCKS5Host







>
>
>








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





>
|
|
>
|
>
>
>
>



>
>
>
>
>
>
>







66
67
68
69
70
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

/* References for static linking */
void _references_to_categories_of_OFTCPSocket(void)
{
	_OFTCPSocket_SOCKS5_reference = 1;
}

static OFString *defaultSOCKS5Host = nil;
static uint16_t defaultSOCKS5Port = 1080;

@implementation OFTCPSocket
#if defined(OF_THREADS) && !defined(HAVE_THREADSAFE_GETADDRINFO)
+ (void)initialize
{
	if (self == [OFTCPSocket class])
		mutex = [[OFMutex alloc] init];
}
#endif

+ (void)setSOCKS5Host: (OFString*)host
{
	id old = defaultSOCKS5Host;
	defaultSOCKS5Host = [host copy];
	[old release];
}

+ (OFString*)SOCKS5Host
{
	return [[defaultSOCKS5Host copy] autorelease];
}

+ (void)setSOCKS5Port: (uint16_t)port
{
	defaultSOCKS5Port = port;
}

+ (uint16_t)SOCKS5Port
{
	return defaultSOCKS5Port;
}

- init
{
	self = [super init];

	@try {
		sock = INVALID_SOCKET;
		sockAddr = NULL;
		SOCKS5Host = [defaultSOCKS5Host copy];
		SOCKS5Port = defaultSOCKS5Port;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[SOCKS5Host release];

	[super dealloc];
}

- (void)setSOCKS5Host: (OFString*)host
{
	OF_SETTER(SOCKS5Host, host, YES, YES)
}

- (OFString*)SOCKS5Host