ObjXMPP  Check-in [71cf6454e4]

Overview
Comment:Handle the connection in the run loop.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 71cf6454e4866e52ba6671286e5849b3e277a73cddd6cbc56f1f2164917167bb
User & Date: js on 2012-09-20 00:35:14
Other Links: manifest | tags
Context
2012-10-14
11:04
Adjust to recent ObjFW changes. check-in: 1a040269e5 user: js tags: trunk
2012-09-20
00:35
Handle the connection in the run loop. check-in: 71cf6454e4 user: js tags: trunk
2012-08-10
12:08
Add very basic Stream Management (XEP-0198) support check-in: a618f77f45 user: js tags: trunk
Changes

Modified src/XMPPConnection.h from [1fc410e031] to [ee35dc40be].

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
 *		 certificate is not valid (otherwise, it does not touch it).
 *		 Passing NULL means the reason is not stored anywhere.
 * \return Whether the certificate is valid
 */
- (BOOL)checkCertificateAndGetReason: (OFString**)reason;

/**
 * \brief Starts a loop handling incomming data.
 */
- (void)handleConnection;

/**
 * \brief Parses the specified buffer.
 *
 * This is useful for handling multiple connections at once.
 *
 * \param buffer The buffer to parse
 * \param length The length of the buffer. If length is 0, it is assumed that
 *		 the connection was closed.
 */
- (void)parseBuffer: (const char*)buffer
	     length: (size_t)length;

/**
 * \brief Returns the socket used by the XMPPConnection.
 *
 * \return The socket used by the XMPPConnection
 */







|












|







241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
 *		 certificate is not valid (otherwise, it does not touch it).
 *		 Passing NULL means the reason is not stored anywhere.
 * \return Whether the certificate is valid
 */
- (BOOL)checkCertificateAndGetReason: (OFString**)reason;

/**
 * \brief Adds the connection to the run loop.
 */
- (void)handleConnection;

/**
 * \brief Parses the specified buffer.
 *
 * This is useful for handling multiple connections at once.
 *
 * \param buffer The buffer to parse
 * \param length The length of the buffer. If length is 0, it is assumed that
 *		 the connection was closed.
 */
- (void)parseBuffer: (const void*)buffer
	     length: (size_t)length;

/**
 * \brief Returns the socket used by the XMPPConnection.
 *
 * \return The socket used by the XMPPConnection
 */

Modified src/XMPPConnection.m from [934072be7a] to [efe09bc35c].

51
52
53
54
55
56
57


58
59
60
61
62
63
64
#import "XMPPPresence.h"
#import "XMPPMulticastDelegate.h"
#import "XMPPExceptions.h"
#import "XMPPXMLElementBuilder.h"
#import "namespaces.h"

#import <ObjFW/macros.h>



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








>
>







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
	[self XMPP_startStream];

	[pool release];
}

- (void)handleConnection
{
	char buffer[512];

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

		[self parseBuffer: buffer
			   length: length];

		if (length < 1)
			return;
	}
}

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

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

	}










	[oldParser release];
	[oldElementBuilder release];

	oldParser = nil;
	oldElementBuilder = nil;
}




























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

- (BOOL)encryptionRequired







|

<
|
|
|
<
<
|
<
<
|
|
<
|
|

|


|




|




>


>
>
>
>
>
>
>
>
>






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







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 = [self allocMemoryWithSize: BUFFER_LENGTH];


	[sock asyncReadIntoBuffer: buffer
			   length: BUFFER_LENGTH
			   target: self


			 selector: @selector(stream:didReadIntoBuffer:length:)];


}


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

	@try {
		[parser parseBuffer: buffer
			     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

Modified tests/test.m from [4505fb0d79] to [99762e7332].

142
143
144
145
146
147
148

149
150
151
152
153
154
155
156
	of_log(@"Auth successful");
}

- (void)connection: (XMPPConnection*)conn_
     wasBoundToJID: (XMPPJID*)jid
{
	of_log(@"Bound to JID: %@", [jid fullJID]);

	of_log(@"Supports SM: %@", [conn_ supportsStreamManagement] ? @"YES" : @"NO");

	[roster requestRoster];
}

- (void)rosterWasReceived: (XMPPRoster*)roster_
{
	XMPPPresence *pres;







>
|







142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
	of_log(@"Auth successful");
}

- (void)connection: (XMPPConnection*)conn_
     wasBoundToJID: (XMPPJID*)jid
{
	of_log(@"Bound to JID: %@", [jid fullJID]);
	of_log(@"Supports SM: %@",
	    [conn_ supportsStreamManagement] ? @"YES" : @"NO");

	[roster requestRoster];
}

- (void)rosterWasReceived: (XMPPRoster*)roster_
{
	XMPPPresence *pres;