ObjXMPP  Check-in [7f939be668]

Overview
Comment:Stop using OFAutoreleasePool
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7f939be6680d5cb981b22d035d031569cc5873818c0af4a964ffc5c6d547d924
User & Date: js on 2017-07-23 11:35:12
Other Links: manifest | tags
Context
2017-07-23
11:57
Change documentation style to ObjFW's style check-in: 764c514b82 user: js tags: trunk
11:35
Stop using OFAutoreleasePool check-in: 7f939be668 user: js tags: trunk
11:19
Adjust to ObjFW changes & small fixes check-in: efaee4fc4c user: js tags: trunk
Changes

Modified src/XMPPConnection.m from [728196e00a] to [6278646a4f].

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
	[self join];

	[_connection handleConnection];
}

- (id)main
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	[_connection connect];

	[self performSelector: @selector(didConnect)
		     onThread: _sourceThread
		waitUntilDone: false];

	[pool release];

	return nil;
}
@end

@implementation XMPPConnection
@synthesize username = _username, resource = _resource, server = _server;







|







|







126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
	[self join];

	[_connection handleConnection];
}

- (id)main
{
	void *pool = objc_autoreleasePoolPush();

	[_connection connect];

	[self performSelector: @selector(didConnect)
		     onThread: _sourceThread
		waitUntilDone: false];

	objc_autoreleasePoolPop(pool);

	return nil;
}
@end

@implementation XMPPConnection
@synthesize username = _username, resource = _resource, server = _server;
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
		_password = nil;

	[old release];
}

- (void)connect
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	XMPPSRVEntry *candidate = nil;
	XMPPSRVLookup *SRVLookup = nil;
	OFEnumerator *enumerator;

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








|







314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
		_password = nil;

	[old release];
}

- (void)connect
{
	void *pool = objc_autoreleasePoolPush();
	XMPPSRVEntry *candidate = nil;
	XMPPSRVLookup *SRVLookup = nil;
	OFEnumerator *enumerator;

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

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
			/* No SRV records -> fall back to A / AAAA record */
			[_socket connectToHost: _domainToASCII
					  port: _port];
	}

	[self XMPP_startStream];

	[pool release];
}

- (void)handleConnection
{
	char *buffer = [self allocMemoryWithSize: BUFFER_LENGTH];

	[_socket asyncReadIntoBuffer: buffer
			      length: BUFFER_LENGTH
			      target: self
			    selector: @selector(stream:didReadIntoBuffer:length:
					  exception:)];
}

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

	[[[[XMPPConnection_ConnectThread alloc]
	    initWithSourceThread: [OFThread currentThread]
		      connection: self] autorelease] start];

	[pool release];
}

-  (bool)XMPP_parseBuffer: (const void *)buffer
		   length: (size_t)length
{
	if ([_socket isAtEndOfStream]) {
		[_delegates broadcastSelector: @selector(connectionWasClosed:)







|















|





|







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
			/* No SRV records -> fall back to A / AAAA record */
			[_socket connectToHost: _domainToASCII
					  port: _port];
	}

	[self XMPP_startStream];

	objc_autoreleasePoolPop(pool);
}

- (void)handleConnection
{
	char *buffer = [self allocMemoryWithSize: BUFFER_LENGTH];

	[_socket asyncReadIntoBuffer: buffer
			      length: BUFFER_LENGTH
			      target: self
			    selector: @selector(stream:didReadIntoBuffer:length:
					  exception:)];
}

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

	[[[[XMPPConnection_ConnectThread alloc]
	    initWithSourceThread: [OFThread currentThread]
		      connection: self] autorelease] start];

	objc_autoreleasePoolPop(pool);
}

-  (bool)XMPP_parseBuffer: (const void *)buffer
		   length: (size_t)length
{
	if ([_socket isAtEndOfStream]) {
		[_delegates broadcastSelector: @selector(connectionWasClosed:)
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546

547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575

576
577
578
579
580
581
582
	[_socket writeString: [element XMLString]];
}

-   (void)sendIQ: (XMPPIQ *)IQ
  callbackTarget: (id)target
	selector: (SEL)selector
{
	OFAutoreleasePool *pool;
	XMPPCallback *callback;
	OFString *ID, *key;

	pool = [[OFAutoreleasePool alloc] init];

	if ((ID = [IQ ID]) == nil) {
		ID = [self generateStanzaID];
		[IQ setID: ID];
	}

	if ((key = [[IQ to] fullJID]) == nil)
		key = [_JID bareJID];
	if (key == nil) // Only happens for resource bind
		key = @"bind";
	key = [key stringByAppendingString: ID];

	callback = [XMPPCallback callbackWithTarget: target
					   selector: selector];
	[_callbacks setObject: callback
		       forKey: key];
	[pool release];


	[self sendStanza: IQ];
}

#ifdef OF_HAVE_BLOCKS
-  (void)sendIQ: (XMPPIQ *)IQ
  callbackBlock: (xmpp_callback_block_t)block
{
	OFAutoreleasePool *pool;
	XMPPCallback *callback;
	OFString *ID, *key;

	pool = [[OFAutoreleasePool alloc] init];

	if ((ID = [IQ ID]) == nil) {
		ID = [self generateStanzaID];
		[IQ setID: ID];
	}

	if ((key = [[IQ to] fullJID]) == nil)
		key = [_JID bareJID];
	if (key == nil) // Connection not yet bound, can't send stanzas
		@throw [OFInvalidArgumentException exception];
	key = [key stringByAppendingString: ID];

	callback = [XMPPCallback callbackWithBlock: block];
	[_callbacks setObject: callback
		       forKey: key];
	[pool release];


	[self sendStanza: IQ];
}
#endif

- (OFString *)generateStanzaID
{







|



<
<















|
>








|



<
<














|
>







518
519
520
521
522
523
524
525
526
527
528


529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557


558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
	[_socket writeString: [element XMLString]];
}

-   (void)sendIQ: (XMPPIQ *)IQ
  callbackTarget: (id)target
	selector: (SEL)selector
{
	void *pool = objc_autoreleasePoolPush();
	XMPPCallback *callback;
	OFString *ID, *key;



	if ((ID = [IQ ID]) == nil) {
		ID = [self generateStanzaID];
		[IQ setID: ID];
	}

	if ((key = [[IQ to] fullJID]) == nil)
		key = [_JID bareJID];
	if (key == nil) // Only happens for resource bind
		key = @"bind";
	key = [key stringByAppendingString: ID];

	callback = [XMPPCallback callbackWithTarget: target
					   selector: selector];
	[_callbacks setObject: callback
		       forKey: key];

	objc_autoreleasePoolPop(pool);

	[self sendStanza: IQ];
}

#ifdef OF_HAVE_BLOCKS
-  (void)sendIQ: (XMPPIQ *)IQ
  callbackBlock: (xmpp_callback_block_t)block
{
	void *pool = objc_autoreleasePoolPush();
	XMPPCallback *callback;
	OFString *ID, *key;



	if ((ID = [IQ ID]) == nil) {
		ID = [self generateStanzaID];
		[IQ setID: ID];
	}

	if ((key = [[IQ to] fullJID]) == nil)
		key = [_JID bareJID];
	if (key == nil) // Connection not yet bound, can't send stanzas
		@throw [OFInvalidArgumentException exception];
	key = [key stringByAppendingString: ID];

	callback = [XMPPCallback callbackWithBlock: block];
	[_callbacks setObject: callback
		       forKey: key];

	objc_autoreleasePoolPop(pool);

	[self sendStanza: IQ];
}
#endif

- (OFString *)generateStanzaID
{

Modified src/XMPPFileStorage.m from [8d2b51a333] to [f0bb23330d].

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

	return object;
}

- (void)setStringValue: (OFString *)string
	       forPath: (OFString *)path
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	[self XMPP_setObject: string
		     forPath: path];

	[pool release];
}

- (OFString *)stringValueForPath: (OFString *)path
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFString *string;

	string = [self XMPP_objectForPath: path];

	[pool release];

	return string;
}

- (void)setBooleanValue: (bool)boolean
		forPath: (OFString *)path
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

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

	[pool release];
}

- (bool)booleanValueForPath: (OFString *)path
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	bool boolean;

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

	[pool release];

	return boolean;
}

- (void)setIntegerValue: (intmax_t)integer
		forPath: (OFString *)path
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

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

	[pool release];
}

- (intmax_t)integerValueForPath: (OFString *)path
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	intmax_t integer;

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

	[pool release];

	return integer;
}

- (void)setArray: (OFArray *)array
	 forPath: (OFString *)path
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	[self XMPP_setObject: array
		     forPath: path];

	[pool release];
}

- (OFArray *)arrayForPath: (OFString *)path
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFArray *array;

	array = [self XMPP_objectForPath: path];

	[pool release];

	return array;
}

- (void)setDictionary: (OFDictionary *)dictionary
	      forPath: (OFString *)path
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	[self XMPP_setObject: dictionary
		     forPath: path];

	[pool release];
}

- (OFDictionary *)dictionaryForPath: (OFString *)path
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFDictionary *dictionary;

	dictionary = [self XMPP_objectForPath: path];

	[pool release];

	return dictionary;
}
@end







|




|




|




|







|




|




|




|







|




|




|




|







|




|




|




|







|




|




|




|




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

	return object;
}

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

	[self XMPP_setObject: string
		     forPath: path];

	objc_autoreleasePoolPop(pool);
}

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

	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]
		     forPath: path];

	objc_autoreleasePoolPop(pool);
}

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

	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]
		     forPath: path];

	objc_autoreleasePoolPop(pool);
}

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

	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
		     forPath: path];

	objc_autoreleasePoolPop(pool);
}

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

	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
		     forPath: path];

	objc_autoreleasePoolPop(pool);
}

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

	dictionary = [self XMPP_objectForPath: path];

	objc_autoreleasePoolPop(pool);

	return dictionary;
}
@end

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

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

- (XMPPIQ *)errorIQWithType: (OFString *)type
		  condition: (OFString *)condition
		       text: (OFString *)text
{
	XMPPIQ *ret = [XMPPIQ IQWithType: @"error"
				      ID: [self ID]];
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFXMLElement *error = [OFXMLElement elementWithName: @"error"
						  namespace: XMPP_NS_CLIENT];

	[error addAttributeWithName: @"type"
			stringValue: type];
	[error addChild: [OFXMLElement elementWithName: condition
					     namespace: XMPP_NS_STANZAS]];
	if (text)
		[error addChild: [OFXMLElement elementWithName: @"text"
						     namespace: XMPP_NS_STANZAS
						   stringValue: text]];
	[ret addChild: error];
	[ret setTo: [self from]];
	[ret setFrom: nil];

	[pool release];

	return ret;
}

- (XMPPIQ *)errorIQWithType: (OFString *)type
		  condition: (OFString *)condition
{
	return [self errorIQWithType: type
			   condition: condition
				text: nil];
}
@end







|















|












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

- (XMPPIQ *)errorIQWithType: (OFString *)type
		  condition: (OFString *)condition
		       text: (OFString *)text
{
	XMPPIQ *ret = [XMPPIQ IQWithType: @"error"
				      ID: [self ID]];
	void *pool = objc_autoreleasePoolPush();
	OFXMLElement *error = [OFXMLElement elementWithName: @"error"
						  namespace: XMPP_NS_CLIENT];

	[error addAttributeWithName: @"type"
			stringValue: type];
	[error addChild: [OFXMLElement elementWithName: condition
					     namespace: XMPP_NS_STANZAS]];
	if (text)
		[error addChild: [OFXMLElement elementWithName: @"text"
						     namespace: XMPP_NS_STANZAS
						   stringValue: text]];
	[ret addChild: error];
	[ret setTo: [self from]];
	[ret setFrom: nil];

	objc_autoreleasePoolPop(pool);

	return ret;
}

- (XMPPIQ *)errorIQWithType: (OFString *)type
		  condition: (OFString *)condition
{
	return [self errorIQWithType: type
			   condition: condition
				text: nil];
}
@end

Modified src/XMPPMulticastDelegate.m from [067d646987] to [c39dfbfb88].

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
		return;
	}
}

- (bool)broadcastSelector: (SEL)selector
	       withObject: (id)object
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMutableData *currentDelegates = [[_delegates copy] autorelease];
	id *items = [currentDelegates items];
	size_t i, count = [currentDelegates count];
	bool handled = false;

	for (i = 0; i < count; i++) {
		id responder = items[i];

		if (![responder respondsToSelector: selector])
			continue;

		bool (*imp)(id, SEL, id) = (bool(*)(id, SEL, id))
		    [responder methodForSelector: selector];

		handled |= imp(responder, selector, object);
	}

	[pool release];

	return handled;
}

- (bool)broadcastSelector: (SEL)selector
	       withObject: (id)object1
	       withObject: (id)object2
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMutableData *currentDelegates = [[_delegates copy] autorelease];
	id *items = [currentDelegates items];
	size_t i, count = [currentDelegates count];
	bool handled = false;

	for (i = 0; i < count; i++) {
		id responder = items[i];

		if (![responder respondsToSelector: selector])
			continue;

		bool (*imp)(id, SEL, id, id) = (bool(*)(id, SEL, id, id))
		    [responder methodForSelector: selector];

		handled |= imp(responder, selector, object1, object2);
	}

	[pool release];

	return handled;
}
@end







|

















|








|

















|




70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
		return;
	}
}

- (bool)broadcastSelector: (SEL)selector
	       withObject: (id)object
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableData *currentDelegates = [[_delegates copy] autorelease];
	id *items = [currentDelegates items];
	size_t i, count = [currentDelegates count];
	bool handled = false;

	for (i = 0; i < count; i++) {
		id responder = items[i];

		if (![responder respondsToSelector: selector])
			continue;

		bool (*imp)(id, SEL, id) = (bool(*)(id, SEL, id))
		    [responder methodForSelector: selector];

		handled |= imp(responder, selector, object);
	}

	objc_autoreleasePoolPop(pool);

	return handled;
}

- (bool)broadcastSelector: (SEL)selector
	       withObject: (id)object1
	       withObject: (id)object2
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableData *currentDelegates = [[_delegates copy] autorelease];
	id *items = [currentDelegates items];
	size_t i, count = [currentDelegates count];
	bool handled = false;

	for (i = 0; i < count; i++) {
		id responder = items[i];

		if (![responder respondsToSelector: selector])
			continue;

		bool (*imp)(id, SEL, id, id) = (bool(*)(id, SEL, id, id))
		    [responder methodForSelector: selector];

		handled |= imp(responder, selector, object1, object2);
	}

	objc_autoreleasePoolPop(pool);

	return handled;
}
@end

Modified src/XMPPRoster.m from [7642c78519] to [c71e60e8a8].

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
			}
		} else
			[_dataStorage setDictionary: nil
					    forPath: @"roster.items"];
	}

	for (OFXMLElement *element in [rosterElement children]) {
		OFAutoreleasePool *pool;
		XMPPRosterItem *rosterItem;

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

		pool = [[OFAutoreleasePool alloc] init];
		rosterItem = [self XMPP_rosterItemWithXMLElement: element];

		[self XMPP_updateRosterItem: rosterItem];
		[pool release];

	}

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







|






<



|
>







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
			}
		} else
			[_dataStorage setDictionary: nil
					    forPath: @"roster.items"];
	}

	for (OFXMLElement *element in [rosterElement children]) {
		void *pool = objc_autoreleasePoolPush();
		XMPPRosterItem *rosterItem;

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


		rosterItem = [self XMPP_rosterItemWithXMLElement: element];

		[self XMPP_updateRosterItem: rosterItem];

		objc_autoreleasePoolPop(pool);
	}

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

Modified src/XMPPSCRAMAuth.m from [ee42191b66] to [b84765f635].

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
				  encoding: OF_STRING_ENCODING_ASCII
				    length: 64];
}

- (const uint8_t *)XMPP_HMACWithKey: (OFData *)key
			       data: (OFData *)data
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMutableData *k = [OFMutableData data];
	size_t i, kSize, blockSize = [_hashType blockSize];
	uint8_t *kI = NULL, *kO = NULL;
	id <OFCryptoHash> hashI, hashO;

	if ([key itemSize] * [key count] > blockSize) {
		hashI = [[[_hashType alloc] init] autorelease];







|







429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
				  encoding: OF_STRING_ENCODING_ASCII
				    length: 64];
}

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

	if ([key itemSize] * [key count] > blockSize) {
		hashI = [[[_hashType alloc] init] autorelease];
476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
				 length: [_hashType digestSize]];
	} @finally {
		[self freeMemory: kI];
		[self freeMemory: kO];
	}

	[hashO retain];
	[pool release];


	return [[hashO autorelease] digest];
}

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

	result = [self allocMemoryWithSize: digestSize];







|
>








|







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
				 length: [_hashType digestSize]];
	} @finally {
		[self freeMemory: kI];
		[self freeMemory: kO];
	}

	[hashO retain];

	objc_autoreleasePoolPop(pool);

	return [[hashO autorelease] digest];
}

- (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, *ret;

	result = [self allocMemoryWithSize: digestSize];
512
513
514
515
516
517
518
519


520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538

539
540
541
542
			result[j] ^= uOld[j];

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

			[pool releaseObjects]; // releases uOld and previous tmp


			[tmp autorelease];

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

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

			uOld = u;
		}

		ret = [OFMutableData dataWithItems: result
					     count: digestSize];
	} @finally {
		[self freeMemory: result];
	}

	[ret retain];
	[pool release];


	return [ret autorelease];
}
@end







|
>
>


















|
>




513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
			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
					      data: tmp];

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

			uOld = u;
		}

		ret = [OFMutableData dataWithItems: result
					     count: digestSize];
	} @finally {
		[self freeMemory: result];
	}

	[ret retain];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}
@end

Modified src/XMPPSRVLookup.m from [e13fa9dc89] to [d3b6deb6f8].

178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
	[_domain release];

	[super dealloc];
}

- (void)XMPP_lookup
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	unsigned char *answer = NULL;
	size_t pageSize = [OFSystemInfo pageSize];
	OFString *request;

	request = [OFString stringWithFormat: @"_xmpp-client._tcp.%@", _domain];

	@try {







|







178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
	[_domain release];

	[super dealloc];
}

- (void)XMPP_lookup
{
	void *pool = objc_autoreleasePoolPush();
	unsigned char *answer = NULL;
	size_t pageSize = [OFSystemInfo pageSize];
	OFString *request;

	request = [OFString stringWithFormat: @"_xmpp-client._tcp.%@", _domain];

	@try {
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
	} @finally {
		[self freeMemory: answer];
#ifdef HAVE_RES_NDESTROY
		res_ndestroy(&_resState);
#endif
	}

	[pool release];
}

- (void)XMPP_addEntry: (XMPPSRVEntry *)entry
{
	OFAutoreleasePool *pool;
	OFList *subList;
	of_list_object_t *iter;

	/* Look if there already is a list with the priority */
	for (iter = [_list firstListObject]; iter != NULL; iter = iter->next) {
		XMPPSRVEntry *first = [iter->object firstObject];








|




|







231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
	} @finally {
		[self freeMemory: answer];
#ifdef HAVE_RES_NDESTROY
		res_ndestroy(&_resState);
#endif
	}

	objc_autoreleasePoolPop(pool);
}

- (void)XMPP_addEntry: (XMPPSRVEntry *)entry
{
	void *pool = objc_autoreleasePoolPush();
	OFList *subList;
	of_list_object_t *iter;

	/* Look if there already is a list with the priority */
	for (iter = [_list firstListObject]; iter != NULL; iter = iter->next) {
		XMPPSRVEntry *first = [iter->object firstObject];

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
		}

		/* We can't have one if the priority is already bigger */
		if ([first priority] > [entry priority])
			break;
	}

	pool = [[OFAutoreleasePool alloc] init];

	subList = [OFList list];
	[subList appendObject: entry];

	if (iter != NULL)
		[_list insertObject: subList
		   beforeListObject: iter];
	else
		[_list appendObject: subList];

	[pool release];
}

- (OFEnumerator *)objectEnumerator
{
	return [[[XMPPSRVEnumerator alloc] initWithList: _list] autorelease];
}
@end







<
<









|







262
263
264
265
266
267
268


269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
		}

		/* We can't have one if the priority is already bigger */
		if ([first priority] > [entry priority])
			break;
	}



	subList = [OFList list];
	[subList appendObject: entry];

	if (iter != NULL)
		[_list insertObject: subList
		   beforeListObject: iter];
	else
		[_list appendObject: subList];

	objc_autoreleasePoolPop(pool);
}

- (OFEnumerator *)objectEnumerator
{
	return [[[XMPPSRVEnumerator alloc] initWithList: _list] autorelease];
}
@end