ObjXMPP  Diff

Differences From Artifact [934072be7a]:

To Artifact [efe09bc35c]:


51
52
53
54
55
56
57


58
59
60
61
62
63
64
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66







+
+







#import "XMPPPresence.h"
#import "XMPPMulticastDelegate.h"
#import "XMPPExceptions.h"
#import "XMPPXMLElementBuilder.h"
#import "namespaces.h"

#import <ObjFW/macros.h>

#define BUFFER_LENGTH 512

@implementation XMPPConnection
+ connection
{
	return [[[self alloc] init] autorelease];
}

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







-
+

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

-
+


-
+




-
+




+


+
+
+
+
+
+
+
+
+






+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	[self XMPP_startStream];

	[pool release];
}

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

	for (;;) {
		size_t length = [sock readIntoBuffer: buffer
					      length: 512];

	[sock asyncReadIntoBuffer: buffer
			   length: BUFFER_LENGTH
			   target: self
		[self parseBuffer: buffer
			   length: length];

			 selector: @selector(stream:didReadIntoBuffer:length:)];
		if (length < 1)
			return;
	}
}
}


- (void)parseBuffer: (const char*)buffer
	     length: (size_t)length
-  (BOOL)XMPP_parseBuffer: (const void*)buffer
		   length: (size_t)length
{
	if (length < 1) {
	if ([sock isAtEndOfStream]) {
		[delegates broadcastSelector: @selector(connectionWasClosed:)
				  withObject: self];
		return;
		return NO;
	}

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

	return YES;
}

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

	[oldParser release];
	[oldElementBuilder release];

	oldParser = nil;
	oldElementBuilder = nil;
}

-      (BOOL)stream: (OFStream*)stream
  didReadIntoBuffer: (char*)buffer
	     length: (size_t)length
{
	if (![self XMPP_parseBuffer: buffer
			     length: length])
		return NO;

	if (oldParser != nil || oldElementBuilder != nil) {
		[oldParser release];
		[oldElementBuilder release];

		oldParser = nil;
		oldElementBuilder = nil;

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

		return NO;
	}

	return YES;
}

- (OFTCPSocket*)socket
{
	return [[sock retain] autorelease];
}

- (BOOL)encryptionRequired