126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
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];
void *pool = objc_autoreleasePoolPush();
[_connection connect];
[self performSelector: @selector(didConnect)
onThread: _sourceThread
waitUntilDone: false];
[pool release];
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
|
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];
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
|
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];
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
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
void *pool = objc_autoreleasePoolPush();
[[[[XMPPConnection_ConnectThread alloc]
initWithSourceThread: [OFThread currentThread]
connection: self] autorelease] start];
[pool release];
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
|
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
{
OFAutoreleasePool *pool;
void *pool = objc_autoreleasePoolPush();
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];
objc_autoreleasePoolPop(pool);
[self sendStanza: IQ];
}
#ifdef OF_HAVE_BLOCKS
- (void)sendIQ: (XMPPIQ *)IQ
callbackBlock: (xmpp_callback_block_t)block
{
OFAutoreleasePool *pool;
void *pool = objc_autoreleasePoolPush();
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];
objc_autoreleasePoolPop(pool);
[self sendStanza: IQ];
}
#endif
- (OFString *)generateStanzaID
{
|