ObjXMPP  Check-in [206960e7ca]

Overview
Comment:Separate server (where to connect to) and domain (what that server hosts)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 206960e7cafbcc99855aa589bc31eb335f41385d0d2a8177c017f2443bf095c3
User & Date: florob@babelmonkeys.de on 2011-05-27 00:17:47
Other Links: manifest | tags
Context
2011-05-27
14:52
Don't throw an exception if SRV records don't exist check-in: 20cf4eff73 user: florob@babelmonkeys.de tags: trunk
00:17
Separate server (where to connect to) and domain (what that server hosts) check-in: 206960e7ca user: florob@babelmonkeys.de tags: trunk
2011-05-26
20:42
Check for res_ndestroy. check-in: 3b589295f9 user: js tags: trunk
Changes

Modified src/XMPPConnection.h from [6a0f28070a] to [413ddf29d0].

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
#ifdef OF_HAVE_OPTONAL_PROTOCOLS
    <OFXMLParserDelegate, OFXMLElementBuilderDelegate>
#endif
{
	OFTCPSocket *sock;
	OFXMLParser *parser, *oldParser;
	OFXMLElementBuilder *elementBuilder, *oldElementBuilder;
	OFString *username, *password, *server, *resource;
	XMPPJID *JID;
	uint16_t port;
	id <XMPPConnectionDelegate, OFObject> delegate;
	XMPPAuthenticator *authModule;
	BOOL needsSession;
	unsigned int lastID;
	OFString *bindID, *sessionID;
	XMPPRoster *roster;
}

#ifdef OF_HAVE_PROPERTIES
@property (copy) OFString *username, *password, *server, *resource;
@property (copy, readonly) XMPPJID *JID;
@property (assign) uint16_t port;
@property (retain) id <XMPPConnectionDelegate> delegate;
@property (readonly, retain) XMPPRoster *roster;
@property (readonly, retain, getter=socket) OFTCPSocket *sock;
#endif








|











|







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
#ifdef OF_HAVE_OPTONAL_PROTOCOLS
    <OFXMLParserDelegate, OFXMLElementBuilderDelegate>
#endif
{
	OFTCPSocket *sock;
	OFXMLParser *parser, *oldParser;
	OFXMLElementBuilder *elementBuilder, *oldElementBuilder;
	OFString *username, *password, *server, *domain, *resource;
	XMPPJID *JID;
	uint16_t port;
	id <XMPPConnectionDelegate, OFObject> delegate;
	XMPPAuthenticator *authModule;
	BOOL needsSession;
	unsigned int lastID;
	OFString *bindID, *sessionID;
	XMPPRoster *roster;
}

#ifdef OF_HAVE_PROPERTIES
@property (copy) OFString *username, *password, *server, *domain, *resource;
@property (copy, readonly) XMPPJID *JID;
@property (assign) uint16_t port;
@property (retain) id <XMPPConnectionDelegate> delegate;
@property (readonly, retain) XMPPRoster *roster;
@property (readonly, retain, getter=socket) OFTCPSocket *sock;
#endif

135
136
137
138
139
140
141


142
143
144
145
146
147
148

- (void)setUsername: (OFString*)username;
- (OFString*)username;
- (void)setPassword: (OFString*)password;
- (OFString*)password;
- (void)setServer: (OFString*)server;
- (OFString*)server;


- (void)setResource: (OFString*)resource;
- (OFString*)resource;
- (XMPPJID*)JID;
- (void)setPort: (uint16_t)port;
- (uint16_t)port;
- (void)setDelegate: (id <XMPPConnectionDelegate>)delegate;
- (id <XMPPConnectionDelegate>)delegate;







>
>







135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

- (void)setUsername: (OFString*)username;
- (OFString*)username;
- (void)setPassword: (OFString*)password;
- (OFString*)password;
- (void)setServer: (OFString*)server;
- (OFString*)server;
- (void)setDomain: (OFString*)domain;
- (OFString*)domain;
- (void)setResource: (OFString*)resource;
- (OFString*)resource;
- (XMPPJID*)JID;
- (void)setPort: (uint16_t)port;
- (uint16_t)port;
- (void)setDelegate: (id <XMPPConnectionDelegate>)delegate;
- (id <XMPPConnectionDelegate>)delegate;

Modified src/XMPPConnection.m from [a911724822] to [7679e224b3].

73
74
75
76
77
78
79

80
81
82
83
84
85
86
{
	[sock release];
	[parser release];
	[elementBuilder release];
	[username release];
	[password release];
	[server release];

	[resource release];
	[JID release];
	[delegate release];
	[authModule release];
	[bindID release];
	[sessionID release];
	[roster release];







>







73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{
	[sock release];
	[parser release];
	[elementBuilder release];
	[username release];
	[password release];
	[server release];
	[domain release];
	[resource release];
	[JID release];
	[delegate release];
	[authModule release];
	[bindID release];
	[sessionID release];
	[roster release];
166
167
168
169
170
171
172



























173
174
175
176
177
178
179
	[old release];
}

- (OFString*)server
{
	return [[server copy] autorelease];
}




























- (void)setPassword: (OFString*)password_
{
	OFString *old = password;
	char *pass;
	Stringprep_rc rc;








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







167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
	[old release];
}

- (OFString*)server
{
	return [[server copy] autorelease];
}

- (void)setDomain: (OFString*)domain_
{
	OFString *old = domain;
	char *srv;
	Stringprep_rc rc;

	if ((rc = stringprep_profile([domain_ cString], &srv,
	    "Nameprep", 0)) != STRINGPREP_OK)
		@throw [XMPPStringPrepFailedException newWithClass: isa
							connection: self
							   profile: @"Nameprep"
							    string: domain_];

	@try {
		domain = [[OFString alloc] initWithCString: srv];
	} @finally {
		free(srv);
	}

	[old release];
}

- (OFString*)domain
{
	return [[domain copy] autorelease];
}

- (void)setPassword: (OFString*)password_
{
	OFString *old = password;
	char *pass;
	Stringprep_rc rc;

197
198
199
200
201
202
203

204
205



206











207












208
209
210
211
212
213

214
215
216
217
218


219

220
221
222

223
224
225
226
227
228
229
{
	return [[password copy] autorelease];
}

- (void)connect
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	XMPPSRVLookup *SRVLookup = [XMPPSRVLookup lookupWithDomain: server];
	OFEnumerator *enumerator = [SRVLookup objectEnumerator];



	XMPPSRVEntry *candidate;
























	while ((candidate = [enumerator nextObject]) != nil) {
		@try {
			[sock connectToHost: [candidate target]
				     onPort: [candidate port]];
			break;
		} @catch (OFAddressTranslationFailedException *e) {

			[e release];
		} @catch (OFConnectionFailedException *e) {
			[e release];
		}
	}




	if (!candidate)
		[sock connectToHost: server
			     onPort: port];


	[self XMPP_startStream];

	[pool release];
}

- (void)handleConnection







>
|
|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
>
|
|
|
|
|
>
>
|
>
|
|
|
>







225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
{
	return [[password copy] autorelease];
}

- (void)connect
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	XMPPSRVEntry *candidate = nil;
	XMPPSRVLookup *SRVLookup;
	OFEnumerator *enumerator;
	OFString *domainToASCII;
	char *cDomainToASCII;
	Idna_rc rc;

	if (server)
		[sock connectToHost: server
			     onPort: port];
	else {
		if ((rc = idna_to_ascii_8z([domain cString], &cDomainToASCII,
		    IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS)
			@throw [XMPPIDNATranslationFailedException
				newWithClass: isa
				  connection: self
				   operation: @"ToASCII"
				      string: domain];

		@try {
			domainToASCII = [OFString
			    stringWithCString: cDomainToASCII];
		} @finally {
			free(cDomainToASCII);
		}

		@try {
			SRVLookup = [XMPPSRVLookup
			    lookupWithDomain: domainToASCII];
			enumerator = [SRVLookup objectEnumerator];

			while ((candidate = [enumerator nextObject]) != nil) {
				@try {
					[sock connectToHost: [candidate target]
						     onPort: [candidate port]];
					break;
				} @catch (OFAddressTranslationFailedException
				    *e) {
					[e release];
				} @catch (OFConnectionFailedException *e) {
					[e release];
				}
			}
		} @catch (OFAddressTranslationFailedException *e) {
			[e release];
		}

		if (!candidate)
			[sock connectToHost: domainToASCII
				     onPort: port];
	}

	[self XMPP_startStream];

	[pool release];
}

- (void)handleConnection
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
		of_log(@"Did not get expected stream start!");
		assert(0);
	}

	enumerator = [attributes objectEnumerator];
	while ((attribute = [enumerator nextObject]) != nil) {
		if ([[attribute name] isEqual: @"from"] &&
		    ![[attribute stringValue] isEqual: server]) {
			of_log(@"Got invalid from in stream start!");
			assert(0);
		}
	}

	[parser setDelegate: elementBuilder];
}







|







350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
		of_log(@"Did not get expected stream start!");
		assert(0);
	}

	enumerator = [attributes objectEnumerator];
	while ((attribute = [enumerator nextObject]) != nil) {
		if ([[attribute name] isEqual: @"from"] &&
		    ![[attribute stringValue] isEqual: domain]) {
			of_log(@"Got invalid from in stream start!");
			assert(0);
		}
	}

	[parser setDelegate: elementBuilder];
}
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379

	roster = [[XMPPRoster alloc] initWithConnection: self];

	[sock writeFormat: @"<?xml version='1.0'?>\n"
			   @"<stream:stream to='%@' "
			   @"xmlns='" XMPP_NS_CLIENT @"' "
			   @"xmlns:stream='" XMPP_NS_STREAM @"' "
			   @"version='1.0'>", server];
}

- (void)XMPP_handleStanza: (OFXMLElement*)element
{
	if ([[element name] isEqual: @"iq"]) {
		[self XMPP_handleIQ: [XMPPIQ stanzaWithElement: element]];
		return;







|







425
426
427
428
429
430
431
432
433
434
435
436
437
438
439

	roster = [[XMPPRoster alloc] initWithConnection: self];

	[sock writeFormat: @"<?xml version='1.0'?>\n"
			   @"<stream:stream to='%@' "
			   @"xmlns='" XMPP_NS_CLIENT @"' "
			   @"xmlns:stream='" XMPP_NS_STREAM @"' "
			   @"version='1.0'>", domain];
}

- (void)XMPP_handleStanza: (OFXMLElement*)element
{
	if ([[element name] isEqual: @"iq"]) {
		[self XMPP_handleIQ: [XMPPIQ stanzaWithElement: element]];
		return;

Modified tests/test.m from [4642dd9fd4] to [5b97008ac4].

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
	[conn setDelegate: self];

	if ([arguments count] != 3) {
		of_log(@"Invalid count of command line arguments!");
		[OFApplication terminateWithStatus: 1];
	}

	[conn setServer: [arguments objectAtIndex: 0]];
	[conn setUsername: [arguments objectAtIndex: 1]];
	[conn setPassword: [arguments objectAtIndex: 2]];
	[conn setResource: @"ObjXMPP"];

	@try {
		[conn connect];
		[conn handleConnection];







|







93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
	[conn setDelegate: self];

	if ([arguments count] != 3) {
		of_log(@"Invalid count of command line arguments!");
		[OFApplication terminateWithStatus: 1];
	}

	[conn setDomain: [arguments objectAtIndex: 0]];
	[conn setUsername: [arguments objectAtIndex: 1]];
	[conn setPassword: [arguments objectAtIndex: 2]];
	[conn setResource: @"ObjXMPP"];

	@try {
		[conn connect];
		[conn handleConnection];