ObjXMPP  Check-in [180bf3d08b]

Overview
Comment:Modernize coding style
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 180bf3d08b20f3a2ef07fe1368d9c29b3a9763b2a347713035962673e6e1011f
User & Date: js on 2018-11-05 21:22:12
Other Links: manifest | tags
Context
2018-11-05
22:02
Fix compilation with GCC check-in: 4e3a1310e6 user: js tags: trunk
21:22
Modernize coding style check-in: 180bf3d08b user: js tags: trunk
00:14
Remove dependency on libresolv check-in: d6978b56f0 user: js tags: trunk
Changes

Modified src/XMPPAuthenticator.h from [b6faf55748] to [607adf2236].

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
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







-
-
+
+










-
-
-
+
+
+
+







 * @brief Initializes an already allocated XMPPAuthenticator with an authcid
 *	  and password.
 *
 * @param authcid The authcid to authenticate with
 * @param password The password to authenticate with
 * @return A initialized XMPPAuthenticator
 */
- initWithAuthcid: (nullable OFString *)authcid
	 password: (nullable OFString *)password;
- (instancetype)initWithAuthcid: (nullable OFString *)authcid
		       password: (nullable OFString *)password;

/*!
 * @brief Initializes an already allocated XMPPSCRAMAuthenticator with an
 *	  authzid, authcid and password.
 *
 * @param authzid The authzid to get authorization for
 * @param authcid The authcid to authenticate with
 * @param password The password to authenticate with
 * @return A initialized XMPPAuthenticator
 */
- initWithAuthzid: (nullable OFString *)authzid
	  authcid: (nullable OFString *)authcid
	 password: (nullable OFString *)password OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithAuthzid: (nullable OFString *)authzid
			authcid: (nullable OFString *)authcid
		       password: (nullable OFString *)password
    OF_DESIGNATED_INITIALIZER;

/*!
 * @brief Returns OFData containing the initial authentication message.
 *
 * @return An OFDataAray containing the initial authentication message
 */
- (nullable OFData *)initialMessage;

Modified src/XMPPAuthenticator.m from [545c182be0] to [b80241dab2].

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
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







-
-
+
+






-
-
-
+
+
+







#endif

#import "XMPPAuthenticator.h"

@implementation XMPPAuthenticator
@synthesize authzid = _authzid, authcid = _authcid, password = _password;

- initWithAuthcid: (OFString *)authcid
	 password: (OFString *)password
- (instancetype)initWithAuthcid: (OFString *)authcid
		       password: (OFString *)password
{
	return [self initWithAuthzid: nil
			     authcid: authcid
			    password: password];
}

- initWithAuthzid: (OFString *)authzid
	  authcid: (OFString *)authcid
	 password: (OFString *)password
- (instancetype)initWithAuthzid: (OFString *)authzid
			authcid: (OFString *)authcid
		       password: (OFString *)password
{
	self = [super init];

	@try {
		_authzid = [authzid copy];
		_authcid = [authcid copy];
		_password = [password copy];

Modified src/XMPPCallback.h from [ee73746306] to [3047c2358f].

39
40
41
42
43
44
45
46

47
48
49
50
51
52


53
54
55
56
57
58
39
40
41
42
43
44
45

46
47
48
49
50


51
52
53
54
55
56
57
58







-
+




-
-
+
+






#ifdef OF_HAVE_BLOCKS
	xmpp_callback_block_t _block;
#endif
}

#ifdef OF_HAVE_BLOCKS
+ (instancetype)callbackWithBlock: (xmpp_callback_block_t)callback;
- initWithBlock: (xmpp_callback_block_t)callback;
- (instancetype)initWithBlock: (xmpp_callback_block_t)callback;
#endif

+ (instancetype)callbackWithTarget: (id)target
			  selector: (SEL)selector;
- initWithTarget: (id)target
	selector: (SEL)selector;
- (instancetype)initWithTarget: (id)target
		      selector: (SEL)selector;

- (void)runWithIQ: (XMPPIQ *)iq
       connection: (XMPPConnection *)connection;
@end

OF_ASSUME_NONNULL_END

Modified src/XMPPCallback.m from [7b928d9476] to [199809011f].

30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44







-
+







#ifdef OF_HAVE_BLOCKS
+ (instancetype)callbackWithBlock: (xmpp_callback_block_t)block
{
	return [[(XMPPCallback *)[self alloc]
	    initWithBlock: block] autorelease];
}

- initWithBlock: (xmpp_callback_block_t)block
- (instancetype)initWithBlock: (xmpp_callback_block_t)block
{
	self = [super init];

	@try {
		_block = [block copy];
	} @catch (id e) {
		[self release];
52
53
54
55
56
57
58
59
60


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


59
60
61
62
63
64
65
66
67







-
-
+
+







+ (instancetype)callbackWithTarget: (id)target
			  selector: (SEL)selector
{
	return [[[self alloc] initWithTarget: target
				    selector: selector] autorelease];
}

- initWithTarget: (id)target
	selector: (SEL)selector
- (instancetype)initWithTarget: (id)target
		      selector: (SEL)selector
{
	self = [super init];

	_target = [target retain];
	_selector = selector;

	return self;

Modified src/XMPPConnection.m from [9754b2ecb4] to [b5eb472034].

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
90
91
92
93
94
95
96
97
98
99
100
101
102

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







-
-

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

-
-
+
+

-
-
+
+

-
-















-
+







#import "XMPPXMLElementBuilder.h"
#import "namespaces.h"

#import <ObjFW/macros.h>

#define BUFFER_LENGTH 512

OF_ASSUME_NONNULL_BEGIN

@interface XMPPConnection ()
- (void)xmpp_socketDidConnect: (OFTCPSocket *)socket
		      context: (OFArray *)nextSRVRecords
		    exception: (id)exception;
- (void)xmpp_tryNextSRVRecord: (OFArray *)SRVRecords;
-  (void)xmpp_resolver: (OFDNSResolver *)resolver
  didResolveDomainName: (OFString *)domainName
	 answerRecords: (OFDictionary *)answerRecords
      authorityRecords: (OFDictionary *)authorityRecords
     additionalRecords: (OFDictionary *)additionalRecords
	       context: (OFString *)domainToASCII
	     exception: (id)exception;
-  (bool)xmpp_parseBuffer: (const void *)buffer
		   length: (size_t)length;
- (bool)xmpp_stream: (OFStream *)stream
  didReadIntoBuffer: (char *)buffer
	     length: (size_t)length
	  exception: (OFException *)exception;
- (void)XMPP_startStream;
- (void)XMPP_handleStream: (OFXMLElement *)element;
- (void)XMPP_handleTLS: (OFXMLElement *)element;
- (void)XMPP_handleSASL: (OFXMLElement *)element;
- (void)XMPP_handleStanza: (OFXMLElement *)element;
- (void)XMPP_sendAuth: (OFString *)authName;
- (void)XMPP_sendResourceBind;
- (void)XMPP_sendStreamError: (OFString *)condition
			text: (nullable OFString *)text;
- (void)xmpp_startStream;
- (void)xmpp_handleStanza: (OFXMLElement *)element;
- (void)xmpp_handleStream: (OFXMLElement *)element;
- (void)xmpp_handleTLS: (OFXMLElement *)element;
- (void)xmpp_handleSASL: (OFXMLElement *)element;
- (void)xmpp_handleIQ: (XMPPIQ *)IQ;
- (void)xmpp_handleMessage: (XMPPMessage *)message;
- (void)xmpp_handlePresence: (XMPPPresence *)presence;
- (void)xmpp_handleFeatures: (OFXMLElement *)element;
- (void)xmpp_sendAuth: (OFString *)authName;
- (void)xmpp_sendResourceBind;
- (void)xmpp_sendStreamError: (OFString *)condition
			text: (OFString *)text;
- (void)XMPP_handleIQ: (XMPPIQ *)IQ;
- (void)XMPP_handleMessage: (XMPPMessage *)message;
- (void)XMPP_handlePresence: (XMPPPresence *)presence;
- (void)XMPP_handleFeatures: (OFXMLElement *)element;
- (void)XMPP_handleResourceBindForConnection: (XMPPConnection *)connection
- (void)xmpp_handleResourceBindForConnection: (XMPPConnection *)connection
					  IQ: (XMPPIQ *)IQ;
- (void)XMPP_sendSession;
- (void)XMPP_handleSessionForConnection: (XMPPConnection *)connection
- (void)xmpp_sendSession;
- (void)xmpp_handleSessionForConnection: (XMPPConnection *)connection
				     IQ: (XMPPIQ *)IQ;
- (OFString *)XMPP_IDNAToASCII: (OFString *)domain;
- (XMPPMulticastDelegate *)XMPP_delegates;
- (OFString *)xmpp_IDNAToASCII: (OFString *)domain;
- (XMPPMulticastDelegate *)xmpp_delegates;
@end

OF_ASSUME_NONNULL_END

@implementation XMPPConnection
@synthesize username = _username, resource = _resource, server = _server;
@synthesize domain = _domain, password = _password, language = _language;
@synthesize privateKeyFile = _privateKeyFile;
@synthesize certificateFile = _certificateFile, socket = _socket;
@synthesize encryptionRequired = _encryptionRequired, encrypted = _encrypted;
@synthesize supportsRosterVersioning = _supportsRosterVersioning;
@synthesize supportsStreamManagement = _supportsStreamManagement;

+ (instancetype)connection
{
	return [[[self alloc] init] autorelease];
}

- init
- (instancetype)init
{
	self = [super init];

	@try {
		_port = 5222;
		_delegates = [[XMPPMulticastDelegate alloc] init];
		_callbacks = [[OFMutableDictionary alloc] init];
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215







-
+







}

- (void)setServer: (OFString *)server
{
	OFString *old = _server;

	if (server != nil)
		_server = [self XMPP_IDNAToASCII: server];
		_server = [self xmpp_IDNAToASCII: server];
	else
		_server = nil;

	[old release];
}

- (void)setDomain: (OFString *)domain
217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
230
231
232
233
234
235
236

237
238
239
240
241
242
243
244







-
+








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

		_domainToASCII = [self XMPP_IDNAToASCII: _domain];
		_domainToASCII = [self xmpp_IDNAToASCII: _domain];
	} else {
		_domain = nil;
		_domainToASCII = nil;
	}

	[oldDomain release];
	[oldDomainToASCII release];
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
290

291
292
293
294
295
296
297
298
299
300
301
302

303
304
305
306
307

308
309
310
311
312
313
314
266
267
268
269
270
271
272

273
274
275
276
277
278
279
280

281
282
283
284
285
286
287
288
289
290
291

292
293
294
295
296
297

298
299
300
301
302

303
304
305
306
307
308
309
310
311
312
313
314

315
316
317
318
319

320
321
322
323
324
325
326
327







-
+







-
+










-
+





-
+




-
+











-
+




-
+







		}
	} else
		_password = nil;

	[old release];
}

- (void)XMPP_socketDidConnect: (OFTCPSocket *)socket
- (void)xmpp_socketDidConnect: (OFTCPSocket *)socket
		      context: (OFArray *)nextSRVRecords
		    exception: (id)exception
{
	char *buffer;

	if (exception != nil) {
		if (nextSRVRecords != nil) {
			[self XMPP_tryNextSRVRecord: nextSRVRecords];
			[self xmpp_tryNextSRVRecord: nextSRVRecords];
			return;
		}

		[_delegates
		    broadcastSelector: @selector(connection:didThrowException:)
			   withObject: self
			   withObject: exception];
		return;
	}

	[self XMPP_startStream];
	[self xmpp_startStream];

	buffer = [self allocMemoryWithSize: BUFFER_LENGTH];
	[_socket asyncReadIntoBuffer: buffer
			      length: BUFFER_LENGTH
			      target: self
			    selector: @selector(XMPP_stream:didReadIntoBuffer:
			    selector: @selector(xmpp_stream:didReadIntoBuffer:
					  length:exception:)
			     context: nil];
}

- (void)XMPP_tryNextSRVRecord: (OFArray *)SRVRecords
- (void)xmpp_tryNextSRVRecord: (OFArray *)SRVRecords
{
	OFSRVDNSResourceRecord *record = [SRVRecords objectAtIndex: 0];

	SRVRecords = [SRVRecords objectsInRange:
	    of_range(1, [SRVRecords count] - 1)];
	if ([SRVRecords count] == 0)
		SRVRecords = nil;

	[_socket asyncConnectToHost: [record target]
			       port: [record port]
			     target: self
			   selector: @selector(XMPP_socketDidConnect:
			   selector: @selector(xmpp_socketDidConnect:
					 context:exception:)
			    context: SRVRecords];
}

-  (void)XMPP_resolver: (OFDNSResolver *)resolver
-  (void)xmpp_resolver: (OFDNSResolver *)resolver
  didResolveDomainName: (OFString *)domainName
	 answerRecords: (OFDictionary *)answerRecords
      authorityRecords: (OFDictionary *)authorityRecords
     additionalRecords: (OFDictionary *)additionalRecords
	       context: (OFString *)domainToASCII
	     exception: (id)exception
{
331
332
333
334
335
336
337
338

339
340
341
342
343
344

345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367

368
369
370
371
372
373
374
375
376

377
378
379
380
381
382
383
384
385
386
387
388
389

390
391
392
393
394
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418
419
420
421
422
423
424
425
426

427
428
429
430
431
432
433
344
345
346
347
348
349
350

351
352
353
354
355
356

357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372

373
374
375
376
377
378
379

380
381
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409
410
411
412
413

414
415
416
417
418
419
420
421
422
423

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

439
440
441
442
443
444
445
446







-
+





-
+















-
+






-
+








-
+












-
+











-
+









-
+














-
+







	[records makeImmutable];

	if ([records count] == 0) {
		/* Fall back to A / AAA record. */
		[_socket asyncConnectToHost: domainToASCII
				       port: _port
				     target: self
				   selector: @selector(XMPP_socketDidConnect:
				   selector: @selector(xmpp_socketDidConnect:
						 context:exception:)
				    context: nil];
		return;
	}

	[self XMPP_tryNextSRVRecord: records];
	[self xmpp_tryNextSRVRecord: records];
}

- (void)asyncConnect
{
	void *pool = objc_autoreleasePoolPush();

	if (_socket != nil)
		@throw [OFAlreadyConnectedException exception];

	_socket = [[OFTCPSocket alloc] init];

	if (_server != nil)
		[_socket asyncConnectToHost: _server
				       port: _port
				     target: self
				   selector: @selector(XMPP_socketDidConnect:
				   selector: @selector(xmpp_socketDidConnect:
						 context:exception:)
				    context: nil];
	else
		[[OFThread DNSResolver]
		    asyncResolveHost: _domainToASCII
			      target: self
			    selector: @selector(XMPP_resolver:
			    selector: @selector(xmpp_resolver:
					  didResolveDomainName:answerRecords:
					  authorityRecords:additionalRecords:
					  context:exception:)
			     context: _domainToASCII];

	objc_autoreleasePoolPop(pool);
}

-  (bool)XMPP_parseBuffer: (const void *)buffer
-  (bool)xmpp_parseBuffer: (const void *)buffer
		   length: (size_t)length
{
	if ([_socket isAtEndOfStream]) {
		[_delegates broadcastSelector: @selector(connectionWasClosed:)
				   withObject: self];
		return false;
	}

	@try {
		[_parser parseBuffer: buffer
			     length: length];
	} @catch (OFMalformedXMLException *e) {
		[self XMPP_sendStreamError: @"bad-format"
		[self xmpp_sendStreamError: @"bad-format"
				      text: nil];
		[self close];
		return false;
	}

	return true;
}

- (void)parseBuffer: (const void *)buffer
	     length: (size_t)length
{
	[self XMPP_parseBuffer: buffer
	[self xmpp_parseBuffer: buffer
			length: length];

	[_oldParser release];
	[_oldElementBuilder release];

	_oldParser = nil;
	_oldElementBuilder = nil;
}

- (bool)XMPP_stream: (OFStream *)stream
- (bool)xmpp_stream: (OFStream *)stream
  didReadIntoBuffer: (char *)buffer
	     length: (size_t)length
	  exception: (OFException *)exception
{
	if (exception != nil) {
		[_delegates broadcastSelector: @selector(connection:
						   didThrowException:)
				   withObject: self
				   withObject: exception];
		[self close];
		return false;
	}

	@try {
		if (![self XMPP_parseBuffer: buffer
		if (![self xmpp_parseBuffer: buffer
				     length: length])
			return false;
	} @catch (id e) {
		[_delegates broadcastSelector: @selector(connection:
						   didThrowException:)
				   withObject: self
				   withObject: e];
441
442
443
444
445
446
447
448

449
450
451
452
453
454
455
454
455
456
457
458
459
460

461
462
463
464
465
466
467
468







-
+








		_oldParser = nil;
		_oldElementBuilder = nil;

		[_socket asyncReadIntoBuffer: buffer
				      length: BUFFER_LENGTH
				      target: self
				    selector: @selector(XMPP_stream:
				    selector: @selector(xmpp_stream:
						  didReadIntoBuffer:length:
						  exception:)
				     context: nil];

		return false;
	}

579
580
581
582
583
584
585
586

587
588
589
590
591
592

593
594
595
596
597
598
599
600

601
602
603
604
605
606

607
608
609
610
611
612
613
592
593
594
595
596
597
598

599
600
601
602
603
604

605
606
607
608
609
610
611
612

613
614
615
616
617
618

619
620
621
622
623
624
625
626







-
+





-
+







-
+





-
+







		// No dedicated stream error for this, may not even be XMPP
		[self close];
		[_socket close];
		return;
	}

	if (![prefix isEqual: @"stream"]) {
		[self XMPP_sendStreamError: @"bad-namespace-prefix"
		[self xmpp_sendStreamError: @"bad-namespace-prefix"
				      text: nil];
		return;
	}

	if (![NS isEqual: XMPP_NS_STREAM]) {
		[self XMPP_sendStreamError: @"invalid-namespace"
		[self xmpp_sendStreamError: @"invalid-namespace"
				      text: nil];
		return;
	}

	for (OFXMLAttribute *attribute in attributes) {
		if ([[attribute name] isEqual: @"from"] &&
		    ![[attribute stringValue] isEqual: _domain]) {
			[self XMPP_sendStreamError: @"invalid-from"
			[self xmpp_sendStreamError: @"invalid-from"
					      text: nil];
			return;
		}
		if ([[attribute name] isEqual: @"version"] &&
		    ![[attribute stringValue] isEqual: @"1.0"]) {
			[self XMPP_sendStreamError: @"unsupported-version"
			[self xmpp_sendStreamError: @"unsupported-version"
					      text: nil];
			return;
		}
	}

	[parser setDelegate: _elementBuilder];
}
624
625
626
627
628
629
630
631

632
633
634

635
636
637

638
639
640

641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656

657
658
659
660
661
662
663
637
638
639
640
641
642
643

644
645
646

647
648
649

650
651
652

653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668

669
670
671
672
673
674
675
676







-
+


-
+


-
+


-
+















-
+







	      forNamespace: XMPP_NS_STREAM];

	[_delegates broadcastSelector: @selector(connection:didReceiveElement:)
			   withObject: self
			   withObject: element];

	if ([[element namespace] isEqual: XMPP_NS_CLIENT])
		[self XMPP_handleStanza: element];
		[self xmpp_handleStanza: element];

	if ([[element namespace] isEqual: XMPP_NS_STREAM])
		[self XMPP_handleStream: element];
		[self xmpp_handleStream: element];

	if ([[element namespace] isEqual: XMPP_NS_STARTTLS])
		[self XMPP_handleTLS: element];
		[self xmpp_handleTLS: element];

	if ([[element namespace] isEqual: XMPP_NS_SASL])
		[self XMPP_handleSASL: element];
		[self xmpp_handleSASL: element];
}

- (void)elementBuilder: (OFXMLElementBuilder *)builder
  didNotExpectCloseTag: (OFString *)name
		prefix: (OFString *)prefix
	     namespace: (OFString *)ns
{
	if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] ||
	    ![ns isEqual: XMPP_NS_STREAM])
		@throw [OFMalformedXMLException exception];
	else {
		[self close];
	}
}

- (void)XMPP_startStream
- (void)xmpp_startStream
{
	OFString *langString = @"";

	/* Make sure we don't get any old events */
	[_parser setDelegate: nil];
	[_elementBuilder setDelegate: nil];

704
705
706
707
708
709
710
711

712
713
714

715
716
717
718
719

720
721
722
723
724
725

726
727
728
729
730

731
732
733
734
735

736
737
738

739
740
741
742
743
744
745
717
718
719
720
721
722
723

724
725
726

727
728
729
730
731

732
733
734
735
736
737

738
739
740
741
742

743
744
745
746
747

748
749
750

751
752
753
754
755
756
757
758







-
+


-
+




-
+





-
+




-
+




-
+


-
+







	[_JID release];
	_JID = nil;
	_streamOpen = _needsSession = _encrypted = false;
	_supportsRosterVersioning = _supportsStreamManagement = false;
	_lastID = 0;
}

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

	if ([[element name] isEqual: @"message"]) {
		[self XMPP_handleMessage:
		[self xmpp_handleMessage:
		    [XMPPMessage stanzaWithElement: element]];
		return;
	}

	if ([[element name] isEqual: @"presence"]) {
		[self XMPP_handlePresence:
		[self xmpp_handlePresence:
		    [XMPPPresence stanzaWithElement: element]];
		return;
	}

	[self XMPP_sendStreamError: @"unsupported-stanza-type"
	[self xmpp_sendStreamError: @"unsupported-stanza-type"
			      text: nil];
}


- (void)XMPP_handleStream: (OFXMLElement *)element
- (void)xmpp_handleStream: (OFXMLElement *)element
{
	if ([[element name] isEqual: @"features"]) {
		[self XMPP_handleFeatures: element];
		[self xmpp_handleFeatures: element];
		return;
	}

	if ([[element name] isEqual: @"error"]) {
		OFString *condition, *reason;
		[self close];
		[_socket close]; // Remote has already closed his stream
832
833
834
835
836
837
838
839

840
841
842
843
844
845
846
845
846
847
848
849
850
851

852
853
854
855
856
857
858
859







-
+







				     reason: reason];
		return;
	}

	assert(0);
}

- (void)XMPP_handleTLS: (OFXMLElement *)element
- (void)xmpp_handleTLS: (OFXMLElement *)element
{
	if ([[element name] isEqual: @"proceed"]) {
		/* FIXME: Catch errors here */
		SSLSocket *newSock;

		[_delegates broadcastSelector: @selector(
						   connectionWillUpgradeToTLS:)
861
862
863
864
865
866
867
868

869
870
871
872
873
874
875
876
877
878
879
880

881
882
883
884
885
886
887
874
875
876
877
878
879
880

881
882
883
884
885
886
887
888
889
890
891
892

893
894
895
896
897
898
899
900







-
+











-
+







		_encrypted = true;

		[_delegates broadcastSelector: @selector(
						   connectionDidUpgradeToTLS:)
				   withObject: self];

		/* Stream restart */
		[self XMPP_startStream];
		[self xmpp_startStream];

		return;
	}

	if ([[element name] isEqual: @"failure"])
		/* TODO: Find/create an exception to throw here */
		@throw [OFException exception];

	assert(0);
}

- (void)XMPP_handleSASL: (OFXMLElement *)element
- (void)xmpp_handleSASL: (OFXMLElement *)element
{
	if ([[element name] isEqual: @"challenge"]) {
		OFXMLElement *responseTag;
		OFData *challenge =
		    [OFData dataWithBase64EncodedString: [element stringValue]];
		OFData *response = [_authModule continueWithData: challenge];

904
905
906
907
908
909
910
911

912
913
914
915
916
917
918
919
920
921
922
923
924
925
926

927
928
929
930
931
932
933
917
918
919
920
921
922
923

924
925
926
927
928
929
930
931
932
933
934
935
936
937
938

939
940
941
942
943
944
945
946







-
+














-
+







		    dataWithBase64EncodedString: [element stringValue]]];

		[_delegates broadcastSelector: @selector(
						   connectionWasAuthenticated:)
				   withObject: self];

		/* Stream restart */
		[self XMPP_startStream];
		[self xmpp_startStream];

		return;
	}

	if ([[element name] isEqual: @"failure"]) {
		/* FIXME: Do more parsing/handling */
		@throw [XMPPAuthFailedException
		    exceptionWithConnection: self
				     reason: [element XMLString]];
	}

	assert(0);
}

- (void)XMPP_handleIQ: (XMPPIQ *)IQ
- (void)xmpp_handleIQ: (XMPPIQ *)IQ
{
	bool handled = false;
	XMPPCallback *callback;
	OFString *key;

	if ((key = [[IQ from] fullJID]) == nil)
		key = [_JID bareJID];
950
951
952
953
954
955
956
957

958
959
960
961
962
963
964

965
966
967
968
969
970
971

972
973
974
975
976
977
978
963
964
965
966
967
968
969

970
971
972
973
974
975
976

977
978
979
980
981
982
983

984
985
986
987
988
989
990
991







-
+






-
+






-
+







	if (!handled && ![[IQ type] isEqual: @"error"] &&
	    ![[IQ type] isEqual: @"result"]) {
		[self sendStanza: [IQ errorIQWithType: @"cancel"
					    condition: @"service-unavailable"]];
	}
}

- (void)XMPP_handleMessage: (XMPPMessage *)message
- (void)xmpp_handleMessage: (XMPPMessage *)message
{
	[_delegates broadcastSelector: @selector(connection:didReceiveMessage:)
			   withObject: self
			   withObject: message];
}

- (void)XMPP_handlePresence: (XMPPPresence *)presence
- (void)xmpp_handlePresence: (XMPPPresence *)presence
{
	[_delegates broadcastSelector: @selector(connection:didReceivePresence:)
			   withObject: self
			   withObject: presence];
}

- (void)XMPP_handleFeatures: (OFXMLElement *)element
- (void)xmpp_handleFeatures: (OFXMLElement *)element
{
	OFXMLElement *startTLS = [element elementForName: @"starttls"
					       namespace: XMPP_NS_STARTTLS];
	OFXMLElement *bind = [element elementForName: @"bind"
					   namespace: XMPP_NS_BIND];
	OFXMLElement *session = [element elementForName: @"session"
					      namespace: XMPP_NS_SESSION];
996
997
998
999
1000
1001
1002
1003
1004

1005
1006
1007
1008
1009
1010
1011
1012
1013

1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024

1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035

1036
1037
1038
1039
1040
1041
1042
1043

1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055

1056
1057
1058
1059
1060
1061
1062

1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082

1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102

1103
1104
1105
1106

1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126

1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143

1144
1145
1146
1147
1148
1149
1150
1151
1152

1153
1154
1155
1156
1157
1158
1159
1160
1161
1162

1163
1164
1165

1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176

1177
1178
1179
1180
1181
1182
1183
1009
1010
1011
1012
1013
1014
1015


1016



1017
1018
1019
1020
1021

1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032

1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043

1044
1045
1046
1047
1048
1049
1050
1051

1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063

1064
1065
1066
1067
1068
1069
1070

1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090

1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110

1111
1112
1113
1114

1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134

1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151

1152
1153
1154
1155
1156
1157
1158
1159
1160

1161
1162
1163
1164
1165
1166
1167
1168
1169
1170

1171
1172
1173

1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184

1185
1186
1187
1188
1189
1190
1191
1192







-
-
+
-
-
-





-
+










-
+










-
+







-
+











-
+






-
+



















-
+



















-
+



-
+



















-
+
















-
+








-
+









-
+


-
+










-
+







		_supportsRosterVersioning = true;

	if ([element elementForName: @"sm"
			  namespace: XMPP_NS_SM] != nil)
		_supportsStreamManagement = true;

	if (mechs != nil) {
		OFEnumerator *enumerator;
		OFXMLElement *mech;
		for (OFXMLElement *mech in [mechs children])

		enumerator = [[mechs children] objectEnumerator];
		while ((mech = [enumerator nextObject]) != nil)
			[mechanisms addObject: [mech stringValue]];

		if (_privateKeyFile != nil && _certificateFile != nil &&
		    [mechanisms containsObject: @"EXTERNAL"]) {
			_authModule = [[XMPPEXTERNALAuth alloc] init];
			[self XMPP_sendAuth: @"EXTERNAL"];
			[self xmpp_sendAuth: @"EXTERNAL"];
			return;
		}

		if ([mechanisms containsObject: @"SCRAM-SHA-1-PLUS"]) {
			_authModule = [[XMPPSCRAMAuth alloc]
			    initWithAuthcid: _username
				   password: _password
				 connection: self
				       hash: [OFSHA1Hash class]
			      plusAvailable: true];
			[self XMPP_sendAuth: @"SCRAM-SHA-1-PLUS"];
			[self xmpp_sendAuth: @"SCRAM-SHA-1-PLUS"];
			return;
		}

		if ([mechanisms containsObject: @"SCRAM-SHA-1"]) {
			_authModule = [[XMPPSCRAMAuth alloc]
			    initWithAuthcid: _username
				   password: _password
				 connection: self
				       hash: [OFSHA1Hash class]
			      plusAvailable: false];
			[self XMPP_sendAuth: @"SCRAM-SHA-1"];
			[self xmpp_sendAuth: @"SCRAM-SHA-1"];
			return;
		}

		if ([mechanisms containsObject: @"PLAIN"] && _encrypted) {
			_authModule = [[XMPPPLAINAuth alloc]
			    initWithAuthcid: _username
				   password: _password];
			[self XMPP_sendAuth: @"PLAIN"];
			[self xmpp_sendAuth: @"PLAIN"];
			return;
		}

		assert(0);
	}

	if (session != nil && [session elementForName: @"optional"
					    namespace: XMPP_NS_SESSION] == nil)
		_needsSession = true;

	if (bind != nil) {
		[self XMPP_sendResourceBind];
		[self xmpp_sendResourceBind];
		return;
	}

	assert(0);
}

- (void)XMPP_sendAuth: (OFString *)authName
- (void)xmpp_sendAuth: (OFString *)authName
{
	OFXMLElement *authTag;
	OFData *initialMessage = [_authModule initialMessage];

	authTag = [OFXMLElement elementWithName: @"auth"
				      namespace: XMPP_NS_SASL];
	[authTag addAttributeWithName: @"mechanism"
			  stringValue: authName];
	if (initialMessage) {
		if ([initialMessage count] == 0)
			[authTag setStringValue: @"="];
		else
			[authTag setStringValue:
			    [initialMessage stringByBase64Encoding]];
	}

	[self sendStanza: authTag];
}

- (void)XMPP_sendResourceBind
- (void)xmpp_sendResourceBind
{
	XMPPIQ *IQ;
	OFXMLElement *bind;

	IQ = [XMPPIQ IQWithType: @"set"
			     ID: [self generateStanzaID]];

	bind = [OFXMLElement elementWithName: @"bind"
				   namespace: XMPP_NS_BIND];

	if (_resource != nil)
		[bind addChild: [OFXMLElement elementWithName: @"resource"
						    namespace: XMPP_NS_BIND
						  stringValue: _resource]];

	[IQ addChild: bind];

	[self	    sendIQ: IQ
	    callbackTarget: self
		  selector: @selector(XMPP_handleResourceBindForConnection:
		  selector: @selector(xmpp_handleResourceBindForConnection:
				IQ:)];
}

- (void)XMPP_sendStreamError: (OFString *)condition
- (void)xmpp_sendStreamError: (OFString *)condition
			text: (OFString *)text
{
	OFXMLElement *error = [OFXMLElement
	    elementWithName: @"error"
		  namespace: XMPP_NS_STREAM];
	[error setPrefix: @"stream"
	    forNamespace: XMPP_NS_STREAM];
	[error addChild: [OFXMLElement elementWithName: condition
					     namespace: XMPP_NS_XMPP_STREAM]];
	if (text)
		[error addChild: [OFXMLElement
		    elementWithName: @"text"
			  namespace: XMPP_NS_XMPP_STREAM
			stringValue: text]];
	[_parser setDelegate: nil];
	[self sendStanza: error];
	[self close];
}

- (void)XMPP_handleResourceBindForConnection: (XMPPConnection *)connection
- (void)xmpp_handleResourceBindForConnection: (XMPPConnection *)connection
					  IQ: (XMPPIQ *)IQ
{
	OFXMLElement *bindElement, *JIDElement;

	assert([[IQ type] isEqual: @"result"]);

	bindElement = [IQ elementForName: @"bind"
			       namespace: XMPP_NS_BIND];

	assert(bindElement != nil);

	JIDElement = [bindElement elementForName: @"jid"
				       namespace: XMPP_NS_BIND];
	_JID = [[XMPPJID alloc] initWithString: [JIDElement stringValue]];

	if (_needsSession) {
		[self XMPP_sendSession];
		[self xmpp_sendSession];
		return;
	}

	[_delegates broadcastSelector: @selector(connection:wasBoundToJID:)
			   withObject: self
			   withObject: _JID];
}

- (void)XMPP_sendSession
- (void)xmpp_sendSession
{
	XMPPIQ *IQ = [XMPPIQ IQWithType: @"set"
				     ID: [self generateStanzaID]];

	[IQ addChild: [OFXMLElement elementWithName: @"session"
					  namespace: XMPP_NS_SESSION]];

	[self	    sendIQ: IQ
	    callbackTarget: self
		  selector: @selector(XMPP_handleSessionForConnection:IQ:)];
		  selector: @selector(xmpp_handleSessionForConnection:IQ:)];
}

- (void)XMPP_handleSessionForConnection: (XMPPConnection *)connection
- (void)xmpp_handleSessionForConnection: (XMPPConnection *)connection
				     IQ: (XMPPIQ *)IQ
{
	if (![[IQ type] isEqual: @"result"])
		OF_ENSURE(0);

	[_delegates broadcastSelector: @selector(connection:wasBoundToJID:)
			   withObject: self
			   withObject: _JID];
}

- (OFString *)XMPP_IDNAToASCII: (OFString *)domain
- (OFString *)xmpp_IDNAToASCII: (OFString *)domain
{
	OFString *ret;
	char *cDomain;
	Idna_rc rc;

	if ((rc = idna_to_ascii_8z([domain UTF8String],
	    &cDomain, IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS)
1215
1216
1217
1218
1219
1220
1221
1222

1223
1224
1225
1226
1224
1225
1226
1227
1228
1229
1230

1231
1232
1233
1234
1235







-
+




}

- (void)removeDelegate: (id <XMPPConnectionDelegate>)delegate
{
	[_delegates removeDelegate: delegate];
}

- (XMPPMulticastDelegate *)XMPP_delegates
- (XMPPMulticastDelegate *)xmpp_delegates
{
	return _delegates;
}
@end

Modified src/XMPPContact+Private.h from [19b0cc5ea8] to [bbdffdaaee].

1
2
3
4
5
6
7


8
9
10


11
12
13
1
2
3
4
5


6
7
8


9
10
11
12
13





-
-
+
+

-
-
+
+



#import "XMPPContact.h"

OF_ASSUME_NONNULL_BEGIN

@interface XMPPContact ()
- (void)XMPP_setRosterItem: (XMPPRosterItem *)rosterItem;
- (void)XMPP_setPresence: (XMPPPresence *)presence
- (void)xmpp_setRosterItem: (XMPPRosterItem *)rosterItem;
- (void)xmpp_setPresence: (XMPPPresence *)presence
		resource: (OFString *)resource;
- (void)XMPP_removePresenceForResource: (OFString *)resource;
- (void)XMPP_setLockedOnJID: (nullable XMPPJID *)JID;
- (void)xmpp_removePresenceForResource: (OFString *)resource;
- (void)xmpp_setLockedOnJID: (nullable XMPPJID *)JID;
@end

OF_ASSUME_NONNULL_END

Modified src/XMPPContact.m from [f961d31c3a] to [fbc7c24c31].

26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40







-
+







#import "XMPPMessage.h"
#import "XMPPConnection.h"

@implementation XMPPContact
@synthesize rosterItem = _rosterItem;
@synthesize presences = _presences;

- init
- (instancetype)init
{
	self = [super init];

	@try {
		_presences = [[OFMutableDictionary alloc] init];
	} @catch (id e) {
		[self release];
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
90
91
92
93
94

95
96
97

98
99
100
101
102
103
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
90
91
92
93

94
95
96

97
98
99
100
101
102
103







-
+






-
+









-
+


-
+








-
+


-
+






		[message setTo: [_rosterItem JID]];
	else
		[message setTo: _lockedOnJID];

	[connection sendStanza: message];
}

- (void)XMPP_setRosterItem: (XMPPRosterItem *)rosterItem
- (void)xmpp_setRosterItem: (XMPPRosterItem *)rosterItem
{
	XMPPRosterItem *old = _rosterItem;
	_rosterItem = [rosterItem retain];
	[old release];
}

- (void)XMPP_setPresence: (XMPPPresence *)presence
- (void)xmpp_setPresence: (XMPPPresence *)presence
		resource: (OFString *)resource
{
	if (resource != nil)
		[_presences setObject: presence
			       forKey: resource];
	else
		[_presences setObject: presence
			       forKey: @""];

	[self XMPP_setLockedOnJID: nil];
	[self xmpp_setLockedOnJID: nil];
}

- (void)XMPP_removePresenceForResource: (OFString *)resource
- (void)xmpp_removePresenceForResource: (OFString *)resource
{
	if (resource != nil) {
		[_presences removeObjectForKey: resource];
	} else {
		[_presences release];
		_presences = [[OFMutableDictionary alloc] init];
	}

	[self XMPP_setLockedOnJID: nil];
	[self xmpp_setLockedOnJID: nil];
}

- (void)XMPP_setLockedOnJID: (XMPPJID *)JID;
- (void)xmpp_setLockedOnJID: (XMPPJID *)JID;
{
	XMPPJID *old = _lockedOnJID;
	_lockedOnJID = [JID retain];
	[old release];
}
@end

Modified src/XMPPContactManager.h from [7f67dd17c8] to [274d8d6d35].

120
121
122
123
124
125
126
127
128



129
130
131
132
133
134
135
120
121
122
123
124
125
126


127
128
129
130
131
132
133
134
135
136







-
-
+
+
+







/*!
 * @brief Initializes an already allocated XMPPContactManager.
 *
 * @param connection The connection to be used to track contacts
 * @param roster The roster used by the contact manager
 * @return An initialized XMPPContactManager
 */
- initWithConnection: (XMPPConnection *)connection
	      roster: (XMPPRoster *)roster OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithConnection: (XMPPConnection *)connection
			    roster: (XMPPRoster *)roster
    OF_DESIGNATED_INITIALIZER;

- (void)sendSubscribedToJID: (XMPPJID *)subscriber;
- (void)sendUnsubscribedToJID: (XMPPJID *)subscriber;

/*!
 * @brief Adds the specified delegate.
 *

Modified src/XMPPContactManager.m from [e40b256e89] to [5c8553fb32].

28
29
30
31
32
33
34
35
36


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


35
36
37
38
39
40
41
42
43







-
-
+
+







#import "XMPPMulticastDelegate.h"
#import "XMPPPresence.h"
#import "XMPPRosterItem.h"

@implementation XMPPContactManager
@synthesize contacts = _contacts;

- initWithConnection: (XMPPConnection *)connection
	      roster: (XMPPRoster *)roster
- (instancetype)initWithConnection: (XMPPConnection *)connection
			    roster: (XMPPRoster *)roster
{
	self = [super init];

	@try {
		_connection = connection;
		[_connection addDelegate: self];
		_roster = roster;
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
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







-
-

-
-

-
+
-




-

+


+

-
+
-
-
-
+
+







- (void)removeDelegate: (id <XMPPContactManagerDelegate>)delegate
{
	[_delegates removeDelegate: delegate];
}

- (void)rosterWasReceived: (XMPPRoster *)roster
{
	OFEnumerator *contactEnumerator;
	XMPPContact *contact;
	OFDictionary *rosterItems;
	OFEnumerator *rosterItemEnumerator;
	OFString *bareJID;

	contactEnumerator = [_contacts objectEnumerator];
	for (XMPPContact *contact in _contacts)
	while ((contact = [contactEnumerator nextObject]) != nil) {
		[_delegates broadcastSelector: @selector(contactManager:
						   didRemoveContact:)
				   withObject: self
				   withObject: contact];
	}
	[_contacts release];
	_contacts = nil;

	_contacts = [[OFMutableDictionary alloc] init];

	rosterItems = [roster rosterItems];
	rosterItemEnumerator = [rosterItems keyEnumerator];
	for (OFString *bareJID in rosterItems) {
	while ((bareJID = [rosterItemEnumerator nextObject]) != nil) {
		contact = [[[XMPPContact alloc] init] autorelease];
		[contact XMPP_setRosterItem:
		XMPPContact *contact = [[[XMPPContact alloc] init] autorelease];
		[contact xmpp_setRosterItem:
		    [rosterItems objectForKey: bareJID]];
		[_contacts setObject: contact
			      forKey: bareJID];
		[_delegates broadcastSelector: @selector(contactManager:
						   didAddContact:)
				   withObject: self
				   withObject: contact];
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
147
148
149
150

151
152
153
154
155
156
157
158







-
+











-
+







					   withObject: contact];
		[_contacts removeObjectForKey: bareJID];
		return;
	}

	if (contact == nil) {
		contact = [[[XMPPContact alloc] init] autorelease];
		[contact XMPP_setRosterItem: rosterItem];
		[contact xmpp_setRosterItem: rosterItem];
		[_contacts setObject: contact
			     forKey: bareJID];
		[_delegates broadcastSelector: @selector(contactManager:
						   didAddContact:)
				   withObject: self
				   withObject: contact];
	} else {
		[_delegates broadcastSelector: @selector(contact:
						   willUpdateWithRosterItem:)
				   withObject: contact
				   withObject: rosterItem];
		[contact XMPP_setRosterItem: rosterItem];
		[contact xmpp_setRosterItem: rosterItem];
	}
}

-   (void)connection: (XMPPConnection *)connection
  didReceivePresence: (XMPPPresence *)presence
{
	XMPPContact *contact;
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
208
209
210
211
212

213
214
215
216
217
218
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
208
209
210
211
212
213







-
+










-
+

















-
+







	contact = [_contacts objectForKey: [JID bareJID]];
	if (contact == nil)
		return;

	/* Available presence */
	if ([type isEqual: @"available"]) {
		[contact XMPP_setPresence: presence
		[contact xmpp_setPresence: presence
				 resource: [JID resource]];
		[_delegates broadcastSelector: @selector(contact:
						   didSendPresence:)
				   withObject: contact
				   withObject: presence];
		return;
	}

	/* Unavailable presence */
	if ([type isEqual: @"unavailable"]) {
		[contact XMPP_removePresenceForResource: [JID resource]];
		[contact xmpp_removePresenceForResource: [JID resource]];
		[_delegates broadcastSelector: @selector(contact:
						   didSendPresence:)
				   withObject: contact
				   withObject: presence];
		return;
	}
}

-  (void)connection: (XMPPConnection *)connection
  didReceiveMessage: (XMPPMessage *)message
{
	XMPPJID *JID = [message from];
	XMPPContact *contact = [_contacts objectForKey: [JID bareJID]];

	if (contact == nil)
		return;

	[contact XMPP_setLockedOnJID: JID];
	[contact xmpp_setLockedOnJID: JID];

	[_delegates broadcastSelector: @selector(contact:didSendMessage:)
			   withObject: contact
			   withObject: message];
}
@end

Modified src/XMPPDiscoEntity.h from [2ffff60b5d] to [e249639d50].

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
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







-
-
-
-
-
+
+
+
+
+









-
+










-
-
+
+
+







 * @param connection The XMPPConnection to serve responses on.
 * @param capsNode The node advertised for the entity's capabilites
 * @return A new autoreleased XMPPDiscoEntity
 */
+ (instancetype)discoEntityWithConnection: (XMPPConnection *)connection
				 capsNode: (OFString *)capsNode;

- initWithJID: (XMPPJID *)JID
	 node: (nullable OFString *)node OF_UNAVAILABLE;
- initWithJID: (XMPPJID *)JID
	 node: (nullable OFString *)node
	 name: (nullable OFString *)name OF_UNAVAILABLE;
- (instancetype)initWithJID: (XMPPJID *)JID
		       node: (nullable OFString *)node OF_UNAVAILABLE;
- (instancetype)initWithJID: (XMPPJID *)JID
		       node: (nullable OFString *)node
		       name: (nullable OFString *)name OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated XMPPDiscoEntity with the specified
 *	  connection.
 *
 * @param connection The XMPPConnection to serve responses on.
 *	  This must already be bound to a resource)
 * @return An initialized XMPPDiscoEntity
 */
- initWithConnection: (XMPPConnection *)connection;
- (instancetype)initWithConnection: (XMPPConnection *)connection;

/*!
 * @brief Initializes an already allocated XMPPDiscoEntity with the specified
 *	  connection.
 *
 * @param connection The XMPPConnection to serve responses on.
 *	  This must already be bound to a resource)
 * @param capsNode The node advertised for the entity's capabilites
 * @return An initialized XMPPDiscoEntity
 */
- initWithConnection: (XMPPConnection *)connection
	    capsNode: (nullable OFString *)capsNode OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithConnection: (XMPPConnection *)connection
			  capsNode: (nullable OFString *)capsNode
    OF_DESIGNATED_INITIALIZER;

/*!
 * @brief Adds a XMPPDiscoNode to provide responses for.
 *
 * @param node The XMPPDiscoNode to provide responses for
 */
- (void)addDiscoNode: (XMPPDiscoNode *)node;

Modified src/XMPPDiscoEntity.m from [40cdae8631] to [90e2de8bd2].

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
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







-
+





-
-
-
+
+
+




-
-
+
+







+ (instancetype)discoEntityWithConnection: (XMPPConnection *)connection
				 capsNode: (OFString *)capsNode
{
	return [[[self alloc] initWithConnection: connection
					capsNode: capsNode] autorelease];
}

- initWithConnection: (XMPPConnection *)connection
- (instancetype)initWithConnection: (XMPPConnection *)connection
{
	return [self initWithConnection: connection
			       capsNode: nil];
}

- initWithJID: (XMPPJID *)JID
	 node: (nullable OFString *)node
	 name: (nullable OFString *)name
- (instancetype)initWithJID: (XMPPJID *)JID
		       node: (nullable OFString *)node
		       name: (nullable OFString *)name
{
	OF_INVALID_INIT_METHOD
}

- initWithConnection: (XMPPConnection *)connection
	    capsNode: (OFString *)capsNode
- (instancetype)initWithConnection: (XMPPConnection *)connection
			  capsNode: (OFString *)capsNode
{
	self = [super initWithJID: [connection JID]
			     node: nil
			     name: nil];

	@try {
		_discoNodes = [[OFMutableDictionary alloc] init];
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
89
90
91
92
93
94
95



96
97
98
99

100

101
102
103

104

105
106
107
108
109
110
111







-
-
-




-
+
-



-
+
-







{
	[_discoNodes setObject: node
			forKey: [node node]];
}

- (OFString *)capsHash
{
	OFEnumerator *enumerator;
	XMPPDiscoIdentity *identity;
	OFString *feature;
	OFMutableString *caps = [OFMutableString string];
	OFSHA1Hash *hash = [OFSHA1Hash cryptoHash];
	OFData *digest;

	enumerator = [_identities objectEnumerator];
	for (XMPPDiscoIdentity *identity in _identities)
	while ((identity = [enumerator nextObject]) != nil)
		[caps appendFormat: @"%@/%@//%@<", [identity category],
		    [identity type], [identity name]];

	enumerator = [_features objectEnumerator];
	for (OFString *feature in _features)
	while ((feature = [enumerator nextObject]) != nil)
		[caps appendFormat: @"%@<", feature];

	[hash updateWithBuffer: [caps UTF8String]
			length: [caps UTF8StringLength]];

	digest = [OFData dataWithItems: [hash digest]
				 count: [[hash class] digestSize]];
133
134
135
136
137
138
139
140

141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159

160
161
162
163
164
165

166
167
168
169
170

171
172
173
174
175
176
177
178
128
129
130
131
132
133
134

135
136
137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153

154
155
156
157
158
159

160
161
162
163
164

165
166
167
168
169
170
171
172
173







-
+




-
+













-
+





-
+




-
+








	OFXMLElement *query = [IQ elementForName: @"query"
				       namespace: XMPP_NS_DISCO_ITEMS];

	if (query != nil) {
		OFString *node =
		    [[query attributeForName: @"node"] stringValue];
		if (node == nil)
			return [self XMPP_handleItemsIQ: IQ
			return [self xmpp_handleItemsIQ: IQ
					     connection: connection];

		XMPPDiscoNode *responder = [_discoNodes objectForKey: node];
		if (responder != nil)
			return [responder XMPP_handleItemsIQ: IQ
			return [responder xmpp_handleItemsIQ: IQ
						  connection: connection];

		return false;
	}

	query = [IQ elementForName: @"query"
			 namespace: XMPP_NS_DISCO_INFO];

	if (query != nil) {
		OFString *node =
		    [[query attributeForName: @"node"] stringValue];

		if (node == nil)
			return [self XMPP_handleInfoIQ: IQ
			return [self xmpp_handleInfoIQ: IQ
					    connection: connection];

		OFString *capsNode = [_capsNode stringByAppendingFormat: @"#%@",
					 [self capsHash]];
		if ([capsNode isEqual: node])
			return [self XMPP_handleInfoIQ: IQ
			return [self xmpp_handleInfoIQ: IQ
					    connection: connection];

		XMPPDiscoNode *responder = [_discoNodes objectForKey: node];
		if (responder != nil)
			return [responder XMPP_handleInfoIQ: IQ
			return [responder xmpp_handleInfoIQ: IQ
						 connection: connection];

		return false;
	}

	return false;
}
@end

Modified src/XMPPDiscoIdentity.h from [810c5e6737] to [201199f107].

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
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







-
+










-
-
-
+
+
+
+









-
-
+
+



 * @param category The category of the identity
 * @param type The type of the identity
 * @return A new autoreleased XMPPDiscoIdentity
 */
+ (instancetype)identityWithCategory: (OFString *)category
				type: (OFString *)type;

- init OF_UNAVAILABLE;
- (instancetype)init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated XMPPDiscoIdentity with the specified
 *	  category, type and name.
 *
 * @param category The category of the identity
 * @param type The type of the identity
 * @param name The name of the identity
 * @return An initialized XMPPDiscoIdentity
 */
- initWithCategory: (OFString *)category
	      type: (OFString *)type
	      name: (nullable OFString *)name OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithCategory: (OFString *)category
			    type: (OFString *)type
			    name: (nullable OFString *)name
    OF_DESIGNATED_INITIALIZER;

/*!
 * @brief Initializes an already allocated XMPPDiscoIdentity with the specified
 *	  category and type.
 *
 * @param category The category of the identity
 * @param type The type of the identity
 * @return An initialized XMPPDiscoIdentity
 */
- initWithCategory: (OFString *)category
	      type: (OFString *)type;
- (instancetype)initWithCategory: (OFString *)category
			    type: (OFString *)type;
@end

OF_ASSUME_NONNULL_END

Modified src/XMPPDiscoIdentity.m from [7825267e7d] to [e06950dbbc].

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
70
71
72
73
74

75
76
77
78
79
80
81
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
70
71
72
73

74
75
76
77
78
79
80
81







-
-
-
+
+
+


















-
-
+
+






-
+







+ (instancetype)identityWithCategory: (OFString *)category
				type: (OFString *)type
{
	return [[[self alloc] initWithCategory: category
					  type: type] autorelease];
}

- initWithCategory: (OFString *)category
	      type: (OFString *)type
	      name: (OFString *)name
- (instancetype)initWithCategory: (OFString *)category
			    type: (OFString *)type
			    name: (OFString *)name
{
	self = [super init];

	@try {
		if (category == nil || type == nil)
			@throw [OFInvalidArgumentException exception];

		_category = [category copy];
		_name = [name copy];
		_type = [type copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithCategory: (OFString *)category
	      type: (OFString *)type
- (instancetype)initWithCategory: (OFString *)category
			    type: (OFString *)type
{
	return [self initWithCategory: category
				 type: type
				 name: nil];
}

- init
- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_category release];

Modified src/XMPPDiscoNode+Private.h from [e20421d02a] to [21faea9249].

1
2
3
4
5
6
7
8
9

10
11

12
13
14
15
1
2
3
4
5
6
7
8

9
10

11
12
13
14
15








-
+

-
+




#import "XMPPDiscoNode.h"

OF_ASSUME_NONNULL_BEGIN

@class XMPPConnection;
@class XMPPIQ;

@interface XMPPDiscoNode ()
- (bool)XMPP_handleItemsIQ: (XMPPIQ *)IQ
- (bool)xmpp_handleItemsIQ: (XMPPIQ *)IQ
		connection: (XMPPConnection *)connection;
- (bool)XMPP_handleInfoIQ: (XMPPIQ *)IQ
- (bool)xmpp_handleInfoIQ: (XMPPIQ *)IQ
	       connection: (XMPPConnection *)connection;
@end

OF_ASSUME_NONNULL_END

Modified src/XMPPDiscoNode.h from [252498f722] to [2f2951260b].

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
137
138
139
140





141
142
143
144
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





137
138
139
140
141
142
143
144
145







-
-
+
+










-
-
-
+
+
+
+

-
-
-
-
-
+
+
+
+
+


-
-
-
-
-
+
+
+
+
+


-
-
-
-
-
+
+
+
+
+




 * @brief Initializes an already allocated XMPPDiscoNode with the specified
 *	  JID and node
 *
 * @param JID The JID this node lives on
 * @param node The node's opaque name
 * @return An initialized XMPPDiscoNode
 */
- initWithJID: (XMPPJID *)JID
	 node: (nullable OFString *)node;
- (instancetype)initWithJID: (XMPPJID *)JID
		       node: (nullable OFString *)node;

/*!
 * @brief Initializes an already allocated XMPPDiscoNode with the specified
 *	  JID, node and name
 *
 * @param JID The JID this node lives on
 * @param node The node's opaque name
 * @param name The node's human friendly name
 * @return An initialized XMPPDiscoNode
 */
- initWithJID: (XMPPJID *)JID
	 node: (nullable OFString *)node
	 name: (nullable OFString *)name OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithJID: (XMPPJID *)JID
		       node: (nullable OFString *)node
		       name: (nullable OFString *)name
    OF_DESIGNATED_INITIALIZER;

 /*!
  * @brief Adds an XMPPDiscoIdentity to the node
  *
  * @param identity The XMPPDiscoIdentity to add
  */
/*!
 * @brief Adds an XMPPDiscoIdentity to the node
 *
 * @param identity The XMPPDiscoIdentity to add
 */
- (void)addIdentity: (XMPPDiscoIdentity *)identity;

 /*!
  * @brief Adds a feature to the node
  *
  * @param feature The feature to add
  */
/*!
 * @brief Adds a feature to the node
 *
 * @param feature The feature to add
 */
- (void)addFeature: (OFString *)feature;

 /*!
  * @brief Adds a XMPPDiscoNode as child of the node
  *
  * @param node The XMPPDiscoNode to add as child
  */
/*!
 * @brief Adds a XMPPDiscoNode as child of the node
 *
 * @param node The XMPPDiscoNode to add as child
 */
- (void)addChildNode: (XMPPDiscoNode *)node;
@end

OF_ASSUME_NONNULL_END

Modified src/XMPPDiscoNode.m from [07959d2558] to [fb7f062274].

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
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







-
-
+
+






-
-
-
+
+
+







			    name: (OFString *)name
{
	return [[[self alloc] initWithJID: JID
				     node: node
				     name: name] autorelease];
}

- initWithJID: (XMPPJID *)JID
	 node: (OFString *)node
- (instancetype)initWithJID: (XMPPJID *)JID
		       node: (OFString *)node
{
	return [self initWithJID: JID
			    node: node
			    name: nil];
}

- initWithJID: (XMPPJID *)JID
	 node: (OFString *)node
	 name: (OFString *)name
- (instancetype)initWithJID: (XMPPJID *)JID
		       node: (OFString *)node
		       name: (OFString *)name
{
	self = [super init];

	@try {
		if (JID == nil &&
		    ![self isKindOfClass: [XMPPDiscoEntity class]])
			@throw [OFInvalidArgumentException exception];
116
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150
116
117
118
119
120
121
122

123
124
125
126
127


128
129
130
131
132
133
134
135
136
137
138
139

140

141
142
143
144
145
146
147







-
+




-
-












-
+
-








- (void)addChildNode: (XMPPDiscoNode *)node
{
	[_childNodes setObject: node
			forKey: [node node]];
}

- (bool)XMPP_handleItemsIQ: (XMPPIQ *)IQ
- (bool)xmpp_handleItemsIQ: (XMPPIQ *)IQ
		connection: (XMPPConnection *)connection
{
	XMPPIQ *resultIQ;
	OFXMLElement *response;
	XMPPDiscoNode *child;
	OFEnumerator *enumerator;
	OFXMLElement *query = [IQ elementForName: @"query"
				       namespace: XMPP_NS_DISCO_ITEMS];
	OFString *node = [[query attributeForName: @"node"] stringValue];

	if (!(node == _node) && ![node isEqual: _node])
		return false;

	resultIQ = [IQ resultIQ];
	response = [OFXMLElement elementWithName: @"query"
				       namespace: XMPP_NS_DISCO_ITEMS];
	[resultIQ addChild: response];

	enumerator = [_childNodes objectEnumerator];
	for (XMPPDiscoNode *child in _childNodes) {
	while ((child = [enumerator nextObject])) {
		OFXMLElement *item =
		    [OFXMLElement elementWithName: @"item"
					namespace: XMPP_NS_DISCO_ITEMS];

		[item addAttributeWithName: @"jid"
			       stringValue: [[child JID] fullJID]];
		if ([child node] != nil)
158
159
160
161
162
163
164
165

166
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
208
209
210
155
156
157
158
159
160
161

162
163
164
165
166



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







-
+




-
-
-






-
+
-















-
+
-













	}

	[connection sendStanza: resultIQ];

	return true;
}

- (bool)XMPP_handleInfoIQ: (XMPPIQ *)IQ
- (bool)xmpp_handleInfoIQ: (XMPPIQ *)IQ
	       connection: (XMPPConnection *)connection
{
	XMPPIQ *resultIQ;
	OFXMLElement *response;
	OFEnumerator *enumerator;
	OFString *feature;
	XMPPDiscoIdentity *identity;

	resultIQ = [IQ resultIQ];
	response = [OFXMLElement elementWithName: @"query"
				       namespace: XMPP_NS_DISCO_INFO];
	[resultIQ addChild: response];

	enumerator = [_identities objectEnumerator];
	for (XMPPDiscoIdentity *identity in _identities) {
	while ((identity = [enumerator nextObject])) {
		OFXMLElement *identityElement =
		    [OFXMLElement elementWithName: @"identity"
					namespace: XMPP_NS_DISCO_INFO];

		[identityElement addAttributeWithName: @"category"
					  stringValue: [identity category]];
		[identityElement addAttributeWithName: @"type"
					  stringValue: [identity type]];
		if ([identity name] != nil)
			[identityElement addAttributeWithName: @"name"
						  stringValue: [identity name]];

		[response addChild: identityElement];
	}

	enumerator = [_features objectEnumerator];
	for (OFString *feature in _features) {
	while ((feature = [enumerator nextObject])) {
		OFXMLElement *featureElement =
		    [OFXMLElement elementWithName: @"feature"
					namespace: XMPP_NS_DISCO_INFO];
		[featureElement addAttributeWithName: @"var"
					 stringValue: feature];
		[response addChild: featureElement];
	}

	[connection sendStanza: resultIQ];

	return true;
}
@end

Modified src/XMPPExceptions.h from [25d94540d0] to [48abd1b541].

46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62

63
64
65
66
67
68
69
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69







-
+








-
+







 *
 * @param connection The connection that received the data responsible
 *	  for this exception
 * @return A new XMPPException
 */
+ (instancetype)exceptionWithConnection: (nullable XMPPConnection *)connection;

- init OF_UNAVAILABLE;
- (instancetype)init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated XMPPException.
 *
 * @param connection The connection that received the data responsible
 *	  for this exception
 * @return An initialized XMPPException
 */
- initWithConnection: (nullable XMPPConnection *)connection
- (instancetype)initWithConnection: (nullable XMPPConnection *)connection
    OF_DESIGNATED_INITIALIZER;
@end

/*!
 * @brief An exception indicating a stream error was received
 */
@interface XMPPStreamErrorException: XMPPException
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
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







-
+
+









-
-
-
+
+
+
+







 * @param reason The descriptive free-form text specified by the stream error
 * @return A new XMPPStreamErrorException
 */
+ (instancetype)exceptionWithConnection: (nullable XMPPConnection *)connection
			      condition: (OFString *)condition
				 reason: (OFString *)reason;

- initWithConnection: (nullable XMPPConnection *)connection OF_UNAVAILABLE;
- (instancetype)initWithConnection: (nullable XMPPConnection *)connection
    OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated XMPPStreamErrorException.
 *
 * @param connection The connection that received the stream error
 * @param condition The defined error condition specified by the stream error
 * @param reason The descriptive free-form text specified by the stream error
 * @return An initialized XMPPStreamErrorException
 */
- initWithConnection: (nullable XMPPConnection *)connection
	   condition: (OFString *)condition
	      reason: (OFString *)reason OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithConnection: (nullable XMPPConnection *)connection
			 condition: (OFString *)condition
			    reason: (OFString *)reason
    OF_DESIGNATED_INITIALIZER;
@end

/*!
 * @brief An exception indicating a stringprep profile
 *	  did not apply to a string
 */
@interface XMPPStringPrepFailedException: XMPPException
135
136
137
138
139
140
141
142


143
144
145
146
147
148
149
150
151
152
153
154




155
156
157
158
159
160
161
137
138
139
140
141
142
143

144
145
146
147
148
149
150
151
152
153
154



155
156
157
158
159
160
161
162
163
164
165







-
+
+









-
-
-
+
+
+
+







 * @param string The string that failed the stringprep profile
 * @return A new XMPPStringPrepFailedException
 */
+ (instancetype)exceptionWithConnection: (nullable XMPPConnection *)connection
				profile: (OFString *)profile
				 string: (OFString *)string;

- initWithConnection: (nullable XMPPConnection *)connection OF_UNAVAILABLE;
- (instancetype)initWithConnection: (nullable XMPPConnection *)connection
    OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated XMPPStringPrepFailedException.
 *
 * @param connection The connection the string relates to
 * @param profile The name of the stringprep profile that did not apply
 * @param string The string that failed the stringprep profile
 * @return An initialized XMPPStringPrepFailedException
 */
- initWithConnection: (nullable XMPPConnection *)connection
	     profile: (OFString *)profile
	      string: (OFString *)string OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithConnection: (nullable XMPPConnection *)connection
			   profile: (OFString *)profile
			    string: (OFString *)string
    OF_DESIGNATED_INITIALIZER;
@end

/*!
 * @brief An exception indicating IDNA translation of a string failed
 */
@interface XMPPIDNATranslationFailedException: XMPPException
{
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
184
185
186
187
188
189
190

191
192
193
194
195
196
197
198
199
200
201



202
203
204
205
206
207
208
209
210
211







-
+
+









-
-
-
+
+
+







 * @param string The string that could not be translated
 * @return A new XMPPIDNATranslationFailedException
 */
+ (instancetype)exceptionWithConnection: (nullable XMPPConnection *)connection
			      operation: (OFString *)operation
				 string: (OFString *)string;

- initWithConnection: (nullable XMPPConnection *)connection OF_UNAVAILABLE;
- (instancetype)initWithConnection: (nullable XMPPConnection *)connection
    OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated XMPPIDNATranslationFailedException.
 *
 * @param connection The connection the string relates to
 * @param operation The name of the stringprep profile that did not apply
 * @param string The string that could not be translated
 * @return An initialized XMPPIDNATranslationFailedException
 */
- initWithConnection: (nullable XMPPConnection *)connection
	   operation: (OFString *)operation
	      string: (OFString *)string;
- (instancetype)initWithConnection: (nullable XMPPConnection *)connection
			 operation: (OFString *)operation
			    string: (OFString *)string;
@end

/*!
 * @brief An exception indicating authentication failed
 */
@interface XMPPAuthFailedException: XMPPException
{
218
219
220
221
222
223
224
225


226
227
228
229
230
231
232
233
234
235



236
237
238
223
224
225
226
227
228
229

230
231
232
233
234
235
236
237
238
239


240
241
242
243
244
245







-
+
+








-
-
+
+
+



 * @param connection The connection that could not be authenticated
 * @param reason The reason the authentication failed
 * @return A new XMPPAuthFailedException
 */
+ (instancetype)exceptionWithConnection: (nullable XMPPConnection *)connection
				 reason: (OFString *)reason;

- initWithConnection: (nullable XMPPConnection *)connection OF_UNAVAILABLE;
- (instancetype)initWithConnection: (nullable XMPPConnection *)connection
    OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated XMPPAuthFailedException.
 *
 * @param connection The connection that could not be authenticated
 * @param reason The reason the authentication failed
 * @return An initialized XMPPAuthFailedException
 */
- initWithConnection: (nullable XMPPConnection *)connection
	      reason: (OFString *)reason OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithConnection: (nullable XMPPConnection *)connection
			    reason: (OFString *)reason
    OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Modified src/XMPPExceptions.m from [b482b72e53] to [fca11f7c33].

34
35
36
37
38
39
40
41

42
43
44
45
46

47
48
49
50
51
52
53
34
35
36
37
38
39
40

41
42
43
44
45

46
47
48
49
50
51
52
53







-
+




-
+







@synthesize connection = _connection;

+ (instancetype)exceptionWithConnection: (XMPPConnection *)connection
{
	return [[[self alloc] initWithConnection: connection] autorelease];
}

- init
- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- initWithConnection: (XMPPConnection *)connection
- (instancetype)initWithConnection: (XMPPConnection *)connection
{
	self = [super init];

	@try {
		_connection = [connection retain];
	} @catch (id e) {
		[self release];
73
74
75
76
77
78
79
80

81
82
83
84
85
86
87



88
89
90
91
92
93
94
73
74
75
76
77
78
79

80
81
82
83
84



85
86
87
88
89
90
91
92
93
94







-
+




-
-
-
+
+
+







				 reason: (OFString *)reason;
{
	return [[[self alloc] initWithConnection: connection
				       condition: condition
					  reason: reason] autorelease];
}

- initWithConnection: (XMPPConnection *)connection
- (instancetype)initWithConnection: (XMPPConnection *)connection
{
	OF_INVALID_INIT_METHOD
}

- initWithConnection: (XMPPConnection *)connection
	   condition: (OFString *)condition
	      reason: (OFString *)reason
- (instancetype)initWithConnection: (XMPPConnection *)connection
			 condition: (OFString *)condition
			    reason: (OFString *)reason
{
	self = [super initWithConnection: connection];

	@try {
		_condition = [condition copy];
		_reason = [reason copy];
	} @catch (id e) {
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136



137
138
139
140
141
142
143
122
123
124
125
126
127
128

129
130
131
132
133



134
135
136
137
138
139
140
141
142
143







-
+




-
-
-
+
+
+







				 string: (OFString *)string
{
	return [[[self alloc] initWithConnection: connection
					 profile: profile
					  string: string] autorelease];
}

- initWithConnection: (XMPPConnection *)connection
- (instancetype)initWithConnection: (XMPPConnection *)connection
{
	OF_INVALID_INIT_METHOD
}

- initWithConnection: (XMPPConnection *)connection
	     profile: (OFString *)profile
	      string: (OFString *)string
- (instancetype)initWithConnection: (XMPPConnection *)connection
			   profile: (OFString *)profile
			    string: (OFString *)string
{
	self = [super initWithConnection: connection];

	@try {
		_profile = [profile copy];
		_string = [string copy];
	} @catch (id e) {
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186



187
188
189
190
191
192
193
172
173
174
175
176
177
178

179
180
181
182
183



184
185
186
187
188
189
190
191
192
193







-
+




-
-
-
+
+
+







				 string: (OFString *)string
{
	return [[[self alloc] initWithConnection: connection
				       operation: operation
					  string: string] autorelease];
}

- initWithConnection: (XMPPConnection *)connection
- (instancetype)initWithConnection: (XMPPConnection *)connection
{
	OF_INVALID_INIT_METHOD
}

- initWithConnection: (XMPPConnection *)connection
	   operation: (OFString *)operation
	      string: (OFString *)string
- (instancetype)initWithConnection: (XMPPConnection *)connection
			 operation: (OFString *)operation
			    string: (OFString *)string
{
	self = [super initWithConnection: connection];

	@try {
		_operation = [operation copy];
		_string = [string copy];
	} @catch (id e) {
219
220
221
222
223
224
225
226

227
228
229
230
231
232


233
234
235
236
237
238
239
219
220
221
222
223
224
225

226
227
228
229
230


231
232
233
234
235
236
237
238
239







-
+




-
-
+
+







+ (instancetype)exceptionWithConnection: (XMPPConnection *)connection
				 reason: (OFString *)reason;
{
	return [[[self alloc] initWithConnection: connection
					  reason: reason] autorelease];
}

- initWithConnection: (XMPPConnection *)connection
- (instancetype)initWithConnection: (XMPPConnection *)connection
{
	OF_INVALID_INIT_METHOD
}

- initWithConnection: (XMPPConnection *)connection
	      reason: (OFString *)reason
- (instancetype)initWithConnection: (XMPPConnection *)connection
			    reason: (OFString *)reason
{
	self = [super initWithConnection: connection];

	@try {
		_reason = [reason copy];
	} @catch (id e) {
		[self release];

Modified src/XMPPFileStorage.h from [7e93a8c354] to [a109a79832].

30
31
32
33
34
35
36
37
38


39
40
41
30
31
32
33
34
35
36


37
38
39
40
41







-
-
+
+




@interface XMPPFileStorage: OFObject <XMPPStorage>
{
	OFString *_file;
	OFMutableDictionary *_data;
}

- init OF_UNAVAILABLE;
- initWithFile: (OFString *)file;
- (instancetype)init OF_UNAVAILABLE;
- (instancetype)initWithFile: (OFString *)file;
@end

OF_ASSUME_NONNULL_END

Modified src/XMPPFileStorage.m from [f0bb23330d] to [9ba65db3b3].

34
35
36
37
38
39
40
41

42
43
44
45
46

47
48
49
50
51
52
53
34
35
36
37
38
39
40

41
42
43
44
45

46
47
48
49
50
51
52
53







-
+




-
+







#import <ObjFW/OFAutoreleasePool.h>

#import <ObjFW/OFNotImplementedException.h>

#import "XMPPFileStorage.h"

@implementation XMPPFileStorage
- init
- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- initWithFile: (OFString *)file
- (instancetype)initWithFile: (OFString *)file
{
	self = [super init];

	@try {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

		_file = [file copy];
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
76
77
78
79
80
81
82

83
84
85
86
87


88
89

90
91
92
93
94
95
96
97







-
+




-
-


-
+







}

- (void)save
{
	[[_data messagePackRepresentation] writeToFile: _file];
}

- (void)XMPP_setObject: (id)object
- (void)xmpp_setObject: (id)object
	       forPath: (OFString *)path
{
	OFArray *pathComponents = [path componentsSeparatedByString: @"."];
	OFMutableDictionary *iter = _data;
	OFEnumerator *enumerator = [pathComponents objectEnumerator];
	OFString *component;
	size_t i = 0, components = [pathComponents count];

	while ((component = [enumerator nextObject]) != nil) {
	for (OFString *component in pathComponents) {
		if (i++ == components - 1)
			continue;

		OFMutableDictionary *iter2 = [iter objectForKey: component];

		if (iter2 == nil) {
			iter2 = [OFMutableDictionary dictionary];
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
137
138
139
140

141
142
143
144
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160
161
162
163

164
165
166
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
208
209

210
211
212
213
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230
231
232

233
234
235
236
237
238
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
137

138
139
140
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160

161
162
163
164
165
166
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
208
209
210
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229

230
231
232
233
234
235
236







-
+














-
+










-
+











-
+










-
+











-
+










-
+











-
+










-
+











-
+










-
+






	if (object != nil)
		[iter setObject: object
			 forKey: [pathComponents lastObject]];
	else
		[iter removeObjectForKey: [pathComponents lastObject]];
}

- (id)XMPP_objectForPath: (OFString *)path
- (id)xmpp_objectForPath: (OFString *)path
{
	id object = _data;

	for (OFString *component in [path componentsSeparatedByString: @"."])
		object = [object objectForKey: component];

	return object;
}

- (void)setStringValue: (OFString *)string
	       forPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();

	[self XMPP_setObject: string
	[self xmpp_setObject: string
		     forPath: path];

	objc_autoreleasePoolPop(pool);
}

- (OFString *)stringValueForPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	OFString *string;

	string = [self XMPP_objectForPath: path];
	string = [self xmpp_objectForPath: path];

	objc_autoreleasePoolPop(pool);

	return string;
}

- (void)setBooleanValue: (bool)boolean
		forPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();

	[self XMPP_setObject: [OFNumber numberWithBool: boolean]
	[self xmpp_setObject: [OFNumber numberWithBool: boolean]
		     forPath: path];

	objc_autoreleasePoolPop(pool);
}

- (bool)booleanValueForPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	bool boolean;

	boolean = [[self XMPP_objectForPath: path] boolValue];
	boolean = [[self xmpp_objectForPath: path] boolValue];

	objc_autoreleasePoolPop(pool);

	return boolean;
}

- (void)setIntegerValue: (intmax_t)integer
		forPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();

	[self XMPP_setObject: [OFNumber numberWithIntMax: integer]
	[self xmpp_setObject: [OFNumber numberWithIntMax: integer]
		     forPath: path];

	objc_autoreleasePoolPop(pool);
}

- (intmax_t)integerValueForPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	intmax_t integer;

	integer = [[self XMPP_objectForPath: path] intMaxValue];
	integer = [[self xmpp_objectForPath: path] intMaxValue];

	objc_autoreleasePoolPop(pool);

	return integer;
}

- (void)setArray: (OFArray *)array
	 forPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();

	[self XMPP_setObject: array
	[self xmpp_setObject: array
		     forPath: path];

	objc_autoreleasePoolPop(pool);
}

- (OFArray *)arrayForPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	OFArray *array;

	array = [self XMPP_objectForPath: path];
	array = [self xmpp_objectForPath: path];

	objc_autoreleasePoolPop(pool);

	return array;
}

- (void)setDictionary: (OFDictionary *)dictionary
	      forPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();

	[self XMPP_setObject: dictionary
	[self xmpp_setObject: dictionary
		     forPath: path];

	objc_autoreleasePoolPop(pool);
}

- (OFDictionary *)dictionaryForPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	OFDictionary *dictionary;

	dictionary = [self XMPP_objectForPath: path];
	dictionary = [self xmpp_objectForPath: path];

	objc_autoreleasePoolPop(pool);

	return dictionary;
}
@end

Modified src/XMPPIQ.h from [6b12f9e135] to [bbf1907353].

43
44
45
46
47
48
49
50
51


52
53
54
55
56
57
58
43
44
45
46
47
48
49


50
51
52
53
54
55
56
57
58







-
-
+
+







 * @brief Initializes an already allocated XMPPIQ with the specified type and
 *	  ID.
 *
 * @param type The value for the stanza's type attribute
 * @param ID The value for the stanza's id attribute
 * @return An initialized XMPPIQ
 */
- initWithType: (OFString *)type
	    ID: (OFString *)ID;
- (instancetype)initWithType: (OFString *)type
			  ID: (OFString *)ID;

/*!
 * @brief Generates a result IQ for the receiving object.
 *
 * @return A new autoreleased XMPPIQ
 */
- (XMPPIQ *)resultIQ;

Modified src/XMPPIQ.m from [5b0d1922ef] to [ad1a9ae862].

32
33
34
35
36
37
38
39
40


41
42
43
44
45
46
47
32
33
34
35
36
37
38


39
40
41
42
43
44
45
46
47







-
-
+
+







+ (instancetype)IQWithType: (OFString *)type
			ID: (OFString *)ID
{
	return [[[self alloc] initWithType: type
					ID: ID] autorelease];
}

- initWithType: (OFString *)type
	    ID: (OFString *)ID
- (instancetype)initWithType: (OFString *)type
			  ID: (OFString *)ID
{
	self = [super initWithName: @"iq"
			      type: type
				ID: ID];

	@try {
		if (![type isEqual: @"get"] && ![type isEqual: @"set"] &&

Modified src/XMPPJID.h from [0c0144bead] to [553453d89a].

65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79







-
+








/*!
 * @brief Initializes an already allocated XMPPJID with a string.
 *
 * @param string The string to parse into a JID object
 * @return A initialized XMPPJID
 */
- initWithString: (OFString *)string;
- (instancetype)initWithString: (OFString *)string;

/*!
 * @brief Returns the bare JID.
 *
 * @return An OFString containing the bare JID
 */
- (OFString *)bareJID;

Modified src/XMPPJID.m from [bccd623ec3] to [bbdbb91e37].

41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
41
42
43
44
45
46
47

48
49
50
51
52
53
54
55







-
+







}

+ (instancetype)JIDWithString: (OFString *)string
{
	return [[[self alloc] initWithString: string] autorelease];
}

- initWithString: (OFString *)string
- (instancetype)initWithString: (OFString *)string
{
	size_t nodesep, resourcesep;

	self = [super init];

	if (string == nil) {
		[self release];

Modified src/XMPPMessage.h from [689e64d8e4] to [68fdf72948].

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
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







-
+







-
+









-
-
+
+




/*!
 * @brief Initializes an already allocated XMPPMessage with the specified ID.
 *
 * @param ID The value for the stanza's id attribute
 * @return A initialized XMPPMessage
 */
- initWithID: (nullable OFString *)ID;
- (instancetype)initWithID: (nullable OFString *)ID;

/*!
 * @brief Initializes an already allocated XMPPMessage with the specified type.
 *
 * @param type The value for the stanza's type attribute
 * @return A initialized XMPPMessage
 */
- initWithType: (nullable OFString *)type;
- (instancetype)initWithType: (nullable OFString *)type;

/*!
 * @brief Initializes an already allocated XMPPMessage with the specified type
 *	  and ID.
 *
 * @param type The value for the stanza's type attribute
 * @param ID The value for the stanza's id attribute
 * @return A initialized XMPPMessage
 */
- initWithType: (nullable OFString *)type
	    ID: (nullable OFString *)ID OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithType: (nullable OFString *)type
			  ID: (nullable OFString *)ID OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Modified src/XMPPMessage.m from [64ae4d9271] to [0597191c86].

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
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







-
+





-
+





-
+





-
-
+
+







+ (instancetype)messageWithType: (OFString *)type
			     ID: (OFString *)ID
{
	return [[[self alloc] initWithType: type
					ID: ID] autorelease];
}

- init
- (instancetype)init
{
	return [self initWithType: nil
			       ID: nil];
}

- initWithID: (OFString *)ID
- (instancetype)initWithID: (OFString *)ID
{
	return [self initWithType: nil
			       ID: ID];
}

- initWithType: (OFString *)type
- (instancetype)initWithType: (OFString *)type
{
	return [self initWithType: type
			       ID: nil];
}

- initWithType: (OFString *)type
	    ID: (OFString *)ID
- (instancetype)initWithType: (OFString *)type
			  ID: (OFString *)ID
{
	return [super initWithName: @"message"
			      type: type
				ID: ID];
}

- (void)setBody: (OFString *)body

Modified src/XMPPMulticastDelegate.m from [c39dfbfb88] to [1ca8e290a2].

26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40







-
+








#import <ObjFW/ObjFW.h>
#import <ObjFW/OFData.h>

#import "XMPPMulticastDelegate.h"

@implementation XMPPMulticastDelegate
- init
- (instancetype)init
{
	self = [super init];

	@try {
		_delegates = [[OFMutableData alloc]
		    initWithItemSize: sizeof(id)];
	} @catch (id e) {

Modified src/XMPPPresence.h from [88a5ae6746] to [5ef3079598].

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
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







-
+







-
+









-
-
+
+




/*!
 * @brief Initializes an already allocated XMPPPresence with the specified ID.
 *
 * @param ID The value for the stanza's id attribute
 * @return A initialized XMPPPresence
 */
- initWithID: (nullable OFString *)ID;
- (instancetype)initWithID: (nullable OFString *)ID;

/*!
 * @brief Initializes an already allocated XMPPPresence with the specified type.
 *
 * @param type The value for the stanza's type attribute
 * @return A initialized XMPPPresence
 */
- initWithType: (nullable OFString *)type;
- (instancetype)initWithType: (nullable OFString *)type;

/*!
 * @brief Initializes an already allocated XMPPPresence with the specified type
 *	  and ID.
 *
 * @param type The value for the stanza's type attribute
 * @param ID The value for the stanza's id attribute
 * @return A initialized XMPPPresence
 */
- initWithType: (nullable OFString *)type
	    ID: (nullable OFString *)ID;
- (instancetype)initWithType: (nullable OFString *)type
			  ID: (nullable OFString *)ID;
@end

OF_ASSUME_NONNULL_END

Modified src/XMPPPresence.m from [1dc363089f] to [9a279f26c4].

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
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







-
+





-
+





-
+





-
-
+
+






-
+







+ (instancetype)presenceWithType: (OFString *)type
			      ID: (OFString *)ID
{
	return [[[self alloc] initWithType: type
					ID: ID] autorelease];
}

- init
- (instancetype)init
{
	return [self initWithType: nil
			       ID: nil];
}

- initWithID: (OFString *)ID
- (instancetype)initWithID: (OFString *)ID
{
	return [self initWithType: nil
			       ID: ID];
}

- initWithType: (OFString *)type
- (instancetype)initWithType: (OFString *)type
{
	return [self initWithType: type
			       ID: nil];
}

- initWithType: (OFString *)type
	    ID: (OFString *)ID
- (instancetype)initWithType: (OFString *)type
			  ID: (OFString *)ID
{
	return [super initWithName: @"presence"
			      type: type
				ID: ID];
}

- initWithElement: (OFXMLElement *)element
- (instancetype)initWithElement: (OFXMLElement *)element
{
	self = [super initWithElement: element];

	@try {
		OFXMLElement *subElement;

		if ((subElement = [element elementForName: @"show"

Modified src/XMPPRoster.h from [c49c440cdc] to [25b548eff0].

84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
99
100


101
102
103
104
105
106
107
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







-
+








-
+
+







/*!
 * @brief The list of contacts as an OFDictionary with the bare JID as a string
 *	  as key.
 */
@property (readonly, nonatomic)
    OFDictionary OF_GENERIC(OFString *, XMPPRosterItem *) *rosterItems;

- init OF_UNAVAILABLE;
- (instancetype)init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated XMPPRoster.
 *
 * @param connection The connection roster related stanzas are send and
 *		     received over
 * @return An initialized XMPPRoster
 */
- initWithConnection: (XMPPConnection *)connection OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithConnection: (XMPPConnection *)connection
    OF_DESIGNATED_INITIALIZER;

/*!
 * @brief Requests the roster from the server.
 */
- (void)requestRoster;

/*!

Modified src/XMPPRoster.m from [c71e60e8a8] to [8b3fa48bcd].

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
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







-
-
+
+

-
+








-
+




-
+







#import "XMPPJID.h"
#import "XMPPMulticastDelegate.h"
#import "namespaces.h"

OF_ASSUME_NONNULL_BEGIN

@interface XMPPRoster ()
- (void)XMPP_updateRosterItem: (XMPPRosterItem *)rosterItem;
- (void)XMPP_handleInitialRosterForConnection: (XMPPConnection *)connection
- (void)xmpp_updateRosterItem: (XMPPRosterItem *)rosterItem;
- (void)xmpp_handleInitialRosterForConnection: (XMPPConnection *)connection
					   IQ: (XMPPIQ *)IQ;
- (XMPPRosterItem *)XMPP_rosterItemWithXMLElement: (OFXMLElement *)element;
- (XMPPRosterItem *)xmpp_rosterItemWithXMLElement: (OFXMLElement *)element;
@end

OF_ASSUME_NONNULL_END

@implementation XMPPRoster
@synthesize connection = _connection, dataStorage = _dataStorage;
@synthesize rosterItems = _rosterItems;

- init
- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- initWithConnection: (XMPPConnection *)connection
- (instancetype)initWithConnection: (XMPPConnection *)connection
{
	self = [super init];

	@try {
		_rosterItems = [[OFMutableDictionary alloc] init];
		_connection = connection;
		[_connection addDelegate: self];
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124







-
+







				stringValue: ver];
	}

	[iq addChild: query];

	[_connection sendIQ: iq
	     callbackTarget: self
		   selector: @selector(XMPP_handleInitialRosterForConnection:
		   selector: @selector(xmpp_handleInitialRosterForConnection:
				IQ:)];
}

- (bool)connection: (XMPPConnection *)connection
      didReceiveIQ: (XMPPIQ *)IQ
{
	OFXMLElement *rosterElement;
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154

155
156
157
158
159
160
161
140
141
142
143
144
145
146

147
148
149
150
151
152
153

154
155
156
157
158
159
160
161







-
+






-
+







	if (origin != nil && ![origin isEqual: [[connection JID] bareJID]])
		return false;

	element = [rosterElement elementForName: @"item"
				      namespace: XMPP_NS_ROSTER];

	if (element != nil) {
		rosterItem = [self XMPP_rosterItemWithXMLElement: element];
		rosterItem = [self xmpp_rosterItemWithXMLElement: element];

		[_delegates broadcastSelector: @selector(
						   roster:didReceiveRosterItem:)
				   withObject: self
				   withObject: rosterItem];

		[self XMPP_updateRosterItem: rosterItem];
		[self xmpp_updateRosterItem: rosterItem];
	}

	if ([_connection supportsRosterVersioning]) {
		OFString *ver =
		    [[rosterElement attributeForName: @"ver"] stringValue];
		[_dataStorage setStringValue: ver
				     forPath: @"roster.ver"];
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
176
177
178
179
180
181
182


183
184
185
186
187
188
189

190

191
192
193
194
195
196
197







-
-







-
+
-







{
	XMPPIQ *IQ = [XMPPIQ IQWithType: @"set"
				     ID: [_connection generateStanzaID]];
	OFXMLElement *query = [OFXMLElement elementWithName: @"query"
						  namespace: XMPP_NS_ROSTER];
	OFXMLElement *item = [OFXMLElement elementWithName: @"item"
						 namespace: XMPP_NS_ROSTER];
	OFEnumerator *enumerator;
	OFString *group;

	[item addAttributeWithName: @"jid"
		       stringValue: [[rosterItem JID] bareJID]];
	if ([rosterItem name] != nil)
		[item addAttributeWithName: @"name"
			       stringValue: [rosterItem name]];

	enumerator = [[rosterItem groups] objectEnumerator];
	for (OFString *group in [rosterItem groups])
	while ((group = [enumerator nextObject]) != nil)
		[item addChild: [OFXMLElement elementWithName: @"group"
						    namespace: XMPP_NS_ROSTER
						  stringValue: group]];

	[query addChild: item];
	[IQ addChild: query];

236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247







-
+







	if (_rosterRequested)
		/* FIXME: Find a better exception! */
		@throw [OFInvalidArgumentException exception];

	_dataStorage = dataStorage;
}

- (void)XMPP_updateRosterItem: (XMPPRosterItem *)rosterItem
- (void)xmpp_updateRosterItem: (XMPPRosterItem *)rosterItem
{
	if ([_connection supportsRosterVersioning]) {
		OFMutableDictionary *items = [[[_dataStorage dictionaryForPath:
		    @"roster.items"] mutableCopy] autorelease];

		if (items == nil)
			items = [OFMutableDictionary dictionary];
276
277
278
279
280
281
282
283

284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309



310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328


329
330
331
332
333
334
335
336
337
338
339
273
274
275
276
277
278
279

280
281
282


283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301



302
303
304

305
306
307
308
309
310
311
312

313
314
315
316
317
318
319
320


321
322




323
324
325
326
327
328
329







-
+


-
-



















-
-
-
+
+
+
-








-
+







-
-
+
+
-
-
-
-







	if (![[rosterItem subscription] isEqual: @"remove"])
		[_rosterItems setObject: rosterItem
				 forKey: [[rosterItem JID] bareJID]];
	else
		[_rosterItems removeObjectForKey: [[rosterItem JID] bareJID]];
}

- (XMPPRosterItem *)XMPP_rosterItemWithXMLElement: (OFXMLElement *)element
- (XMPPRosterItem *)xmpp_rosterItemWithXMLElement: (OFXMLElement *)element
{
	OFString *subscription;
	OFEnumerator *groupEnumerator;
	OFXMLElement *groupElement;
	OFMutableArray *groups = [OFMutableArray array];
	XMPPRosterItem *rosterItem = [XMPPRosterItem rosterItem];
	[rosterItem setJID: [XMPPJID JIDWithString:
	    [[element attributeForName: @"jid"] stringValue]]];
	[rosterItem setName:
	    [[element attributeForName: @"name"] stringValue]];

	subscription = [[element attributeForName:
	    @"subscription"] stringValue];

	if (![subscription isEqual: @"none"] &&
	    ![subscription isEqual: @"to"] &&
	    ![subscription isEqual: @"from"] &&
	    ![subscription isEqual: @"both"] &&
	    ![subscription isEqual: @"remove"])
		subscription = @"none";

	[rosterItem setSubscription: subscription];

	groupEnumerator = [[element
	    elementsForName: @"group"
		  namespace: XMPP_NS_ROSTER] objectEnumerator];
	for (OFXMLElement *groupElement in
	    [element elementsForName: @"group"
			   namespace: XMPP_NS_ROSTER])
	while ((groupElement = [groupEnumerator nextObject]) != nil)
		[groups addObject: [groupElement stringValue]];

	if ([groups count] > 0)
		[rosterItem setGroups: groups];

	return rosterItem;
}

- (void)XMPP_handleInitialRosterForConnection: (XMPPConnection *)connection
- (void)xmpp_handleInitialRosterForConnection: (XMPPConnection *)connection
					   IQ: (XMPPIQ *)IQ
{
	OFXMLElement *rosterElement = [IQ elementForName: @"query"
					       namespace: XMPP_NS_ROSTER];

	if ([connection supportsRosterVersioning]) {
		if (rosterElement == nil) {
			OFDictionary *items = [_dataStorage
			    dictionaryForPath: @"roster.items"];
			for (OFDictionary *item in
			    [_dataStorage dictionaryForPath: @"roster.items"]) {
			OFEnumerator *enumerator = [items objectEnumerator];
			OFDictionary *item;

			while ((item = [enumerator nextObject]) != nil) {
				XMPPRosterItem *rosterItem;
				XMPPJID *JID;

				rosterItem = [XMPPRosterItem rosterItem];
				JID = [XMPPJID JIDWithString:
					  [item objectForKey: @"JID"]];
				[rosterItem setJID: JID];
356
357
358
359
360
361
362
363

364
365

366
367
368
369
370
371
372
346
347
348
349
350
351
352

353
354

355
356
357
358
359
360
361
362







-
+

-
+







		void *pool = objc_autoreleasePoolPush();
		XMPPRosterItem *rosterItem;

		if (![[element name] isEqual: @"item"] ||
		    ![[element namespace] isEqual: XMPP_NS_ROSTER])
			continue;

		rosterItem = [self XMPP_rosterItemWithXMLElement: element];
		rosterItem = [self xmpp_rosterItemWithXMLElement: element];

		[self XMPP_updateRosterItem: rosterItem];
		[self xmpp_updateRosterItem: rosterItem];

		objc_autoreleasePoolPop(pool);
	}

	if ([connection supportsRosterVersioning] && rosterElement != nil) {
		OFString *ver =
		    [[rosterElement attributeForName: @"ver"] stringValue];

Modified src/XMPPSCRAMAuth.h from [4305196952] to [731041c89d].

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
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







-
-
-
-
-
+
+
+
+
+












-
-
-
-
-
+
+
+
+
+













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



+ (instancetype)SCRAMAuthWithAuthzid: (nullable OFString *)authzid
			     authcid: (nullable OFString *)authcid
			    password: (nullable OFString *)password
			  connection: (XMPPConnection *)connection
				hash: (Class)hash
		       plusAvailable: (bool)plusAvailable;

- initWithAuthcid: (nullable OFString *)authcid
	 password: (nullable OFString *)password OF_UNAVAILABLE;
- initWithAuthzid: (nullable OFString *)authzid
	  authcid: (nullable OFString *)authcid
	 password: (nullable OFString *)password OF_UNAVAILABLE;
- (instancetype)initWithAuthcid: (nullable OFString *)authcid
		       password: (nullable OFString *)password OF_UNAVAILABLE;
- (instancetype)initWithAuthzid: (nullable OFString *)authzid
			authcid: (nullable OFString *)authcid
		       password: (nullable OFString *)password OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated XMPPSCRAMAuth with an authcid and
 *	  password.
 *
 * @param authcid The authcid to authenticate with
 * @param password The password to authenticate with
 * @param connection The connection over which authentication is done
 * @param hash The class to use for calulating hashes
 * @param plusAvailable Whether the PLUS variant was offered
 * @return A initialized XMPPSCRAMAuth
 */
- initWithAuthcid: (nullable OFString *)authcid
	 password: (nullable OFString *)password
       connection: (XMPPConnection *)connection
	     hash: (Class)hash
    plusAvailable: (bool)plusAvailable;
- (instancetype)initWithAuthcid: (nullable OFString *)authcid
		       password: (nullable OFString *)password
		     connection: (XMPPConnection *)connection
			   hash: (Class)hash
		  plusAvailable: (bool)plusAvailable;

/*!
 * @brief Initializes an already allocated XMPPSCRAMAuth with a authzid,
 *	  authcid and password.
 *
 * @param authzid The authzid to get authorization for
 * @param authcid The authcid to authenticate with
 * @param password The password to authenticate with
 * @param connection The connection over which authentication is done
 * @param hash The class to use for calulating hashes
 * @param plusAvailable Whether the PLUS variant was offered
 * @return A initialized XMPPSCRAMAuth
 */
- initWithAuthzid: (nullable OFString *)authzid
	  authcid: (nullable OFString *)authcid
	 password: (nullable OFString *)password
       connection: (XMPPConnection *)connection
	     hash: (Class)hash
    plusAvailable: (bool)plusAvailable OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithAuthzid: (nullable OFString *)authzid
			authcid: (nullable OFString *)authcid
		       password: (nullable OFString *)password
		     connection: (XMPPConnection *)connection
			   hash: (Class)hash
		  plusAvailable: (bool)plusAvailable OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Modified src/XMPPSCRAMAuth.m from [64601fbc72] to [b361a2cc27].

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
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







-
-

-
-
+
+

-
+


-
-
+
+


-
-








#import "XMPPSCRAMAuth.h"
#import "XMPPExceptions.h"

#define HMAC_IPAD 0x36
#define HMAC_OPAD 0x5c

OF_ASSUME_NONNULL_BEGIN

@interface XMPPSCRAMAuth ()
- (OFString *)XMPP_genNonce;
- (const uint8_t *)XMPP_HMACWithKey: (OFData *)key
- (OFString *)xmpp_genNonce;
- (const uint8_t *)xmpp_HMACWithKey: (OFData *)key
			       data: (OFData *)data;
- (OFData *)XMPP_hiWithData: (OFData *)str
- (OFData *)xmpp_hiWithData: (OFData *)str
		       salt: (OFData *)salt
	     iterationCount: (intmax_t)i;
- (OFData *)XMPP_parseServerFirstMessage: (OFData *)data;
- (OFData *)XMPP_parseServerFinalMessage: (OFData *)data;
- (OFData *)xmpp_parseServerFirstMessage: (OFData *)data;
- (OFData *)xmpp_parseServerFinalMessage: (OFData *)data;
@end

OF_ASSUME_NONNULL_END

@implementation XMPPSCRAMAuth
+ (instancetype)SCRAMAuthWithAuthcid: (OFString *)authcid
			    password: (OFString *)password
			  connection: (XMPPConnection *)connection
				hash: (Class)hash
		       plusAvailable: (bool)plusAvailable
{
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
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







-
-
-
-
-
+
+
+
+
+









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







				      authcid: authcid
				     password: password
				   connection: connection
					 hash: hash
				plusAvailable: plusAvailable] autorelease];
}

- initWithAuthcid: (OFString *)authcid
	 password: (OFString *)password
       connection: (XMPPConnection *)connection
	     hash: (Class)hash
    plusAvailable: (bool)plusAvailable
- (instancetype)initWithAuthcid: (OFString *)authcid
		       password: (OFString *)password
		     connection: (XMPPConnection *)connection
			   hash: (Class)hash
		  plusAvailable: (bool)plusAvailable
{
	return [self initWithAuthzid: nil
			     authcid: authcid
			    password: password
			  connection: connection
				hash: hash
		       plusAvailable: plusAvailable];
}

- initWithAuthzid: (OFString *)authzid
	  authcid: (OFString *)authcid
	 password: (OFString *)password
       connection: (XMPPConnection *)connection
	     hash: (Class)hash
    plusAvailable: (bool)plusAvailable
- (instancetype)initWithAuthzid: (OFString *)authzid
			authcid: (OFString *)authcid
		       password: (OFString *)password
		     connection: (XMPPConnection *)connection
			   hash: (Class)hash
		  plusAvailable: (bool)plusAvailable
{
	self = [super initWithAuthzid: authzid
			      authcid: authcid
			     password: password];

	_hashType = hash;
	_plusAvailable = plusAvailable;
175
176
177
178
179
180
181
182

183
184
185
186
187
188
189
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185







-
+







		_GS2Header = [[OFString alloc]
		    initWithFormat: @"%@,a=%@,",
				    (_plusAvailable ? @"p=tls-unique" : @"y"),
				    _authzid];
	else
		_GS2Header = (_plusAvailable ? @"p=tls-unique,," : @"y,,");

	_cNonce = [[self XMPP_genNonce] retain];
	_cNonce = [[self xmpp_genNonce] retain];

	[_clientFirstMessageBare release];
	_clientFirstMessageBare = nil;
	_clientFirstMessageBare = [[OFString alloc]
	    initWithFormat: @"n=%@,r=%@", _authcid, _cNonce];

	[ret addItems: [_GS2Header UTF8String]
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
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
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


221
222
223
224
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







-
+

-
+







-
+








-
-










-
-
-
+
+
+

-
-
+
+
-
-
-
+
+

-
+








-
+


-
+








- (OFData *)continueWithData: (OFData *)data
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFData *ret;

	if (!_serverSignature)
		ret = [self XMPP_parseServerFirstMessage: data];
		ret = [self xmpp_parseServerFirstMessage: data];
	else
		ret = [self XMPP_parseServerFinalMessage: data];
		ret = [self xmpp_parseServerFinalMessage: data];

	[ret retain];
	[pool release];

	return [ret autorelease];
}

- (OFData *)XMPP_parseServerFirstMessage: (OFData *)data
- (OFData *)xmpp_parseServerFirstMessage: (OFData *)data
{
	size_t i;
	const uint8_t *clientKey, *serverKey, *clientSignature;
	intmax_t iterCount = 0;
	id <OFCryptoHash> hash;
	OFMutableData *ret, *authMessage, *tmpArray;
	OFData *salt = nil, *saltedPassword;
	OFString *tmpString, *sNonce = nil;
	OFEnumerator *enumerator;
	OFString *comp;
	enum {
		GOT_SNONCE    = 0x01,
		GOT_SALT      = 0x02,
		GOT_ITERCOUNT = 0x04
	} got = 0;

	hash = [[[_hashType alloc] init] autorelease];
	ret = [OFMutableData data];
	authMessage = [OFMutableData data];

	OFString *chal = [OFString stringWithUTF8String: [data items]
						 length: [data count] *
							 [data itemSize]];
	OFString *challenge = [OFString stringWithUTF8String: [data items]
						      length: [data count] *
							      [data itemSize]];

	enumerator =
	    [[chal componentsSeparatedByString: @","] objectEnumerator];
	for (OFString *component in
	    [challenge componentsSeparatedByString: @","]) {
	while ((comp = [enumerator nextObject]) != nil) {
		OFString *entry = [comp substringWithRange:
		    of_range(2, [comp length] - 2)];
		OFString *entry = [component substringWithRange:
		    of_range(2, [component length] - 2)];

		if ([comp hasPrefix: @"r="]) {
		if ([component hasPrefix: @"r="]) {
			if (![entry hasPrefix: _cNonce])
				@throw [XMPPAuthFailedException
				    exceptionWithConnection: nil
						     reason: @"Received wrong "
							     @"nonce"];

			sNonce = entry;
			got |= GOT_SNONCE;
		} else if ([comp hasPrefix: @"s="]) {
		} else if ([component hasPrefix: @"s="]) {
			salt = [OFData dataWithBase64EncodedString: entry];
			got |= GOT_SALT;
		} else if ([comp hasPrefix: @"i="]) {
		} else if ([component hasPrefix: @"i="]) {
			iterCount = [entry decimalValue];
			got |= GOT_ITERCOUNT;
		}
	}

	if (got != (GOT_SNONCE | GOT_SALT | GOT_ITERCOUNT))
		@throw [OFInvalidServerReplyException exception];
289
290
291
292
293
294
295
296

297
298
299
300
301
302
303
282
283
284
285
286
287
288

289
290
291
292
293
294
295
296







-
+








	/*
	 * IETF RFC 5802:
	 * SaltedPassword := Hi(Normalize(password), salt, i)
	 */
	tmpArray = [OFMutableData dataWithItems: [_password UTF8String]
					  count: [_password UTF8StringLength]];
	saltedPassword = [self XMPP_hiWithData: tmpArray
	saltedPassword = [self xmpp_hiWithData: tmpArray
					  salt: salt
				iterationCount: iterCount];

	/*
	 * IETF RFC 5802:
	 * AuthMessage := client-first-message-bare + "," +
	 *		  server-first-message + "," +
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351
352
353
354
355
356

357
358
359
360
361
362
363
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356







-
+















-
+







-
+












-
+







	[authMessage addItems: [ret items]
			count: [ret count]];

	/*
	 * IETF RFC 5802:
	 * ClientKey := HMAC(SaltedPassword, "Client Key")
	 */
	clientKey = [self XMPP_HMACWithKey: saltedPassword
	clientKey = [self xmpp_HMACWithKey: saltedPassword
				      data: [OFData dataWithItems: "Client Key"
							    count: 10]];

	/*
	 * IETF RFC 5802:
	 * StoredKey := H(ClientKey)
	 */
	[hash updateWithBuffer: (void *)clientKey
			length: [_hashType digestSize]];

	/*
	 * IETF RFC 5802:
	 * ClientSignature := HMAC(StoredKey, AuthMessage)
	 */
	clientSignature = [self
	    XMPP_HMACWithKey: [OFData dataWithItems: [hash digest]
	    xmpp_HMACWithKey: [OFData dataWithItems: [hash digest]
					      count: [_hashType digestSize]]
			data: authMessage];

	/*
	 * IETF RFC 5802:
	 * ServerKey := HMAC(SaltedPassword, "Server Key")
	 */
	serverKey = [self XMPP_HMACWithKey: saltedPassword
	serverKey = [self xmpp_HMACWithKey: saltedPassword
				      data: [OFData dataWithItems: "Server Key"
							    count: 10]];

	/*
	 * IETF RFC 5802:
	 * ServerSignature := HMAC(ServerKey, AuthMessage)
	 */
	tmpArray = [OFMutableData dataWithItems: serverKey
					  count: [_hashType digestSize]];

	[_serverSignature release];
	_serverSignature = [[OFData alloc]
	    initWithItems: [self XMPP_HMACWithKey: tmpArray
	    initWithItems: [self xmpp_HMACWithKey: tmpArray
					     data: authMessage]
		    count: [_hashType digestSize]];

	/*
	 * IETF RFC 5802:
	 * ClientProof := ClientKey XOR ClientSignature
	 */
374
375
376
377
378
379
380
381

382
383
384
385
386
387
388
367
368
369
370
371
372
373

374
375
376
377
378
379
380
381







-
+







	tmpString = [tmpArray stringByBase64Encoding];
	[ret addItems: [tmpString UTF8String]
		count: [tmpString UTF8StringLength]];

	return ret;
}

- (OFData *)XMPP_parseServerFinalMessage: (OFData *)data
- (OFData *)xmpp_parseServerFinalMessage: (OFData *)data
{
	OFString *mess, *value;

	/*
	 * server-final-message already received,
	 * we were just waiting for the last word from the server
	 */
403
404
405
406
407
408
409
410

411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431

432
433
434
435
436
437
438
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423

424
425
426
427
428
429
430
431







-
+




















-
+







	} else
		@throw [XMPPAuthFailedException exceptionWithConnection: nil
								 reason: value];

	return nil;
}

- (OFString *)XMPP_genNonce
- (OFString *)xmpp_genNonce
{
	uint8_t buf[64];
	size_t i;

	assert(RAND_pseudo_bytes(buf, 64) >= 0);

	for (i = 0; i < 64; i++) {
		// Restrict salt to printable range, but do not include '~'...
		buf[i] = (buf[i] % ('~' - '!')) + '!';

		// ...so we can use it to replace ','
		if (buf[i] == ',')
			buf[i] = '~';
	}

	return [OFString stringWithCString: (char *)buf
				  encoding: OF_STRING_ENCODING_ASCII
				    length: 64];
}

- (const uint8_t *)XMPP_HMACWithKey: (OFData *)key
- (const uint8_t *)xmpp_HMACWithKey: (OFData *)key
			       data: (OFData *)data
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableData *k = [OFMutableData data];
	size_t i, kSize, blockSize = [_hashType blockSize];
	uint8_t *kI = NULL, *kO = NULL;
	id <OFCryptoHash> hashI, hashO;
480
481
482
483
484
485
486
487

488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508

509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524

525
526
527
528
529
530
531
473
474
475
476
477
478
479

480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500

501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516

517
518
519
520
521
522
523
524







-
+




















-
+















-
+







	[hashO retain];

	objc_autoreleasePoolPop(pool);

	return [[hashO autorelease] digest];
}

- (OFData *)XMPP_hiWithData: (OFData *)str
- (OFData *)xmpp_hiWithData: (OFData *)str
		       salt: (OFData *)salt
	     iterationCount: (intmax_t)i
{
	void *pool = objc_autoreleasePoolPush();
	size_t digestSize = [_hashType digestSize];
	uint8_t *result = NULL;
	const uint8_t *u, *uOld;
	intmax_t j, k;
	OFMutableData *salty, *tmp;
	OFData *ret;

	result = [self allocMemoryWithSize: digestSize];

	@try {
		memset(result, 0, digestSize);

		salty = [[salt mutableCopy] autorelease];
		[salty addItems: "\0\0\0\1"
			  count: 4];

		uOld = [self XMPP_HMACWithKey: str
		uOld = [self xmpp_HMACWithKey: str
					 data: salty];

		for (j = 0; j < digestSize; j++)
			result[j] ^= uOld[j];

		for (j = 0; j < i - 1; j++) {
			tmp = [[OFMutableData alloc] init];
			[tmp addItems: uOld
				count: digestSize];

			/* releases uOld and previous tmp */
			objc_autoreleasePoolPop(pool);
			pool = objc_autoreleasePoolPush();
			[tmp autorelease];

			u = [self XMPP_HMACWithKey: str
			u = [self xmpp_HMACWithKey: str
					      data: tmp];

			for (k = 0; k < digestSize; k++)
				result[k] ^= u[k];

			uOld = u;
		}

Modified src/XMPPStanza.h from [2122dfccd9] to [832de87656].

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
137
138
139
140
141


142
143
144
145
146
147
148
149
150
151
152


153
154
155
156
157
158
159
160
161
162
163
164
165



166
167
168
169
170
171
172
173

174
175
176
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
137
138
139


140
141
142
143
144
145
146
147
148
149
150


151
152
153
154
155
156
157
158
159
160
161
162



163
164
165
166
167
168
169
170
171
172

173
174
175
176







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







-
+









-
-
+
+









-
-
+
+










-
-
-
+
+
+







-
+



 * @brief Creates a new autoreleased XMPPStanza from an OFXMLElement.
 *
 * @param element The element to base the XMPPStanza on
 * @return A new autoreleased XMPPStanza
 */
+ (instancetype)stanzaWithElement: (OFXMLElement *)element;

- initWithName: (OFString *)name
   stringValue: (nullable OFString *)stringValue OF_UNAVAILABLE;
- initWithName: (OFString *)name
     namespace: (nullable OFString *)namespace OF_UNAVAILABLE;
- initWithName: (OFString *)name
     namespace: (nullable OFString *)namespace
   stringValue: (nullable OFString *)stringValue OF_UNAVAILABLE;
- initWithXMLString: (OFString *)string OF_UNAVAILABLE;
- initWithFile: (OFString *)path OF_UNAVAILABLE;
- (instancetype)initWithName: (OFString *)name
		 stringValue: (nullable OFString *)stringValue OF_UNAVAILABLE;
- (instancetype)initWithName: (OFString *)name
		   namespace: (nullable OFString *)namespace OF_UNAVAILABLE;
- (instancetype)initWithName: (OFString *)name
		   namespace: (nullable OFString *)namespace
		 stringValue: (nullable OFString *)stringValue OF_UNAVAILABLE;
- (instancetype)initWithXMLString: (OFString *)string OF_UNAVAILABLE;
- (instancetype)initWithFile: (OFString *)path OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated XMPPStanza with the specified name.
 *
 * @param name The stanza's name (one of iq, message or presence)
 * @return A initialized XMPPStanza
 */
- initWithName: (OFString *)name;
- (instancetype)initWithName: (OFString *)name;

/*!
 * @brief Initializes an already allocated XMPPStanza with the specified name
 *	  and type.
 *
 * @param name The stanza's name (one of iq, message or presence)
 * @param type The value for the stanza's type attribute
 * @return A initialized XMPPStanza
 */
- initWithName: (OFString *)name
	  type: (nullable OFString *)type;
- (instancetype)initWithName: (OFString *)name
			type: (nullable OFString *)type;

/*!
 * @brief Initializes an already allocated XMPPStanza with the specified name
 *	  and ID.
 *
 * @param name The stanza's name (one of iq, message or presence)
 * @param ID The value for the stanza's id attribute
 * @return A initialized XMPPStanza
 */
- initWithName: (OFString *)name
	    ID: (nullable OFString *)ID;
- (instancetype)initWithName: (OFString *)name
			  ID: (nullable OFString *)ID;

/*!
 * @brief Initializes an already allocated XMPPStanza with the specified name,
 *	  type and ID.
 *
 * @param name The stanza's name (one of iq, message or presence)
 * @param type The value for the stanza's type attribute
 * @param ID The value for the stanza's id attribute
 * @return A initialized XMPPStanza
 */
- initWithName: (OFString *)name
	  type: (nullable OFString *)type
	    ID: (nullable OFString *)ID;
- (instancetype)initWithName: (OFString *)name
			type: (nullable OFString *)type
			  ID: (nullable OFString *)ID;

/*!
 * @brief Initializes an already allocated XMPPStanza based on a OFXMLElement.
 *
 * @param element The element to base the XMPPStanza on
 * @return A initialized XMPPStanza
 */
- initWithElement: (OFXMLElement *)element;
- (instancetype)initWithElement: (OFXMLElement *)element;
@end

OF_ASSUME_NONNULL_END

Modified src/XMPPStanza.m from [813b227b64] to [5747db70b5].

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
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
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
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







-
-
-
+
+
+
+
+
+
+
+




-
+




-
-
-
-
-
-
+






-
-
+
+






-
-
+
+






-
-
-
+
+
+







}

+ (instancetype)stanzaWithElement: (OFXMLElement *)element
{
	return [[[self alloc] initWithElement: element] autorelease];
}

- initWithName: (OFString *)name
     namespace: (nullable OFString *)namespace
   stringValue: (nullable OFString *)stringValue
- (instancetype)initWithName: (OFString *)name
		   namespace: (nullable OFString *)namespace
		 stringValue: (nullable OFString *)stringValue
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithXMLString: (OFString *)string
{
	OF_INVALID_INIT_METHOD
}

- initWithXMLString: (OFString *)string
- (instancetype)initWithFile: (OFString *)path
{
	OF_INVALID_INIT_METHOD
}

- initWithFile: (OFString *)path
{
	OF_INVALID_INIT_METHOD
}

- initWithName: (OFString *)name
- (instancetype)initWithName: (OFString *)name
{
	return [self initWithName: name
			     type: nil
			       ID: nil];
}

- initWithName: (OFString *)name
	  type: (OFString *)type
- (instancetype)initWithName: (OFString *)name
			type: (OFString *)type
{
	return [self initWithName: name
			     type: type
			       ID: nil];
}

- initWithName: (OFString *)name
	    ID: (OFString *)ID
- (instancetype)initWithName: (OFString *)name
			  ID: (OFString *)ID
{
	return [self initWithName: name
			     type: nil
			       ID: ID];
}

- initWithName: (OFString *)name
	  type: (OFString *)type
	    ID: (OFString *)ID
- (instancetype)initWithName: (OFString *)name
			type: (OFString *)type
			  ID: (OFString *)ID
{
	self = [super initWithName: name
			 namespace: XMPP_NS_CLIENT
		       stringValue: nil];

	@try {
		if (![name isEqual: @"iq"] && ![name isEqual: @"message"] &&
132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146







-
+







		[self release];
		@throw e;
	}

	return self;
}

- initWithElement: (OFXMLElement *)element
- (instancetype)initWithElement: (OFXMLElement *)element
{
	self = [super initWithElement: element];

	@try {
		OFXMLAttribute *attribute;

		if ((attribute = [element attributeForName: @"from"]))

Modified src/XMPPStreamManagement.h from [eba4bbe440] to [e3339cbb01].

27
28
29
30
31
32
33
34
35


36
37
38
27
28
29
30
31
32
33


34
35
36
37
38







-
-
+
+




@interface XMPPStreamManagement: OFObject <XMPPConnectionDelegate>
{
	XMPPConnection *_connection;
	uint32_t _receivedCount;
}

- init OF_UNAVAILABLE;
- initWithConnection: (XMPPConnection *)connection;
- (instancetype)init OF_UNAVAILABLE;
- (instancetype)initWithConnection: (XMPPConnection *)connection;
@end

OF_ASSUME_NONNULL_END

Modified src/XMPPStreamManagement.m from [57b85a948f] to [42b7f06f4f].

22
23
24
25
26
27
28
29

30
31
32
33
34

35
36
37
38
39
40
41
22
23
24
25
26
27
28

29
30
31
32
33

34
35
36
37
38
39
40
41







-
+




-
+








#include <inttypes.h>

#import "XMPPStreamManagement.h"
#import "namespaces.h"

@implementation XMPPStreamManagement
- init
- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- initWithConnection: (XMPPConnection *)connection
- (instancetype)initWithConnection: (XMPPConnection *)connection
{
	self = [super init];

	@try {
		_connection = connection;
		[_connection addDelegate: self];
	} @catch (id e) {