ObjXMPP  Check-in [f4868153e6]

Overview
Comment:Send an error reply for unhandled IQ stanzas.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f4868153e6c6cdea5fdf8a7f7d0f4b3ac2c3a66d13c176df3c976ce653ef344a
User & Date: js on 2011-03-21 20:36:59
Other Links: manifest | tags
Context
2011-03-21
23:37
Properly handle roster items which are in multiple groups. check-in: b9354d7713 user: js tags: trunk
20:36
Send an error reply for unhandled IQ stanzas. check-in: f4868153e6 user: js tags: trunk
19:51
Request and handle roster. check-in: b74a310cc3 user: js tags: trunk
Changes

Modified src/XMPPConnection.h from [eb4dbab3f1] to [f58e7a76cd].

32
33
34
35
36
37
38
39

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

39
40
41
42
43
44
45
46







-
+








@protocol XMPPConnectionDelegate
@optional
- (void)connectionWasAuthenticated: (XMPPConnection*)conn;
- (void)connection: (XMPPConnection*)conn
     wasBoundToJID: (XMPPJID*)jid;
- (void)connectionDidReceiveRoster: (XMPPConnection*)conn;
- (void)connection: (XMPPConnection*)conn
- (BOOL)connection: (XMPPConnection*)conn
      didReceiveIQ: (XMPPIQ*)iq;
-   (void)connection: (XMPPConnection*)conn
  didReceivePresence: (XMPPPresence*)pres;
-  (void)connection: (XMPPConnection*)conn
  didReceiveMessage: (XMPPMessage*)msg;
- (void)connectionWasClosed: (XMPPConnection*)conn;
@end

Modified src/XMPPConnection.m from [374e4b1629] to [072b3550d7].

39
40
41
42
43
44
45

46
47
48
49
50
51
52
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53







+







#import "XMPPExceptions.h"

#define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind"
#define NS_CLIENT @"jabber:client"
#define NS_ROSTER @"jabber:iq:roster"
#define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl"
#define NS_STARTTLS @"urn:ietf:params:xml:ns:xmpp-tls"
#define NS_STANZAS @"urn:ietf:params:xml:ns:xmpp-stanzas"
#define NS_SESSION @"urn:ietf:params:xml:ns:xmpp-session"
#define NS_STREAM @"http://etherx.jabber.org/streams"

@interface XMPPConnection ()
- (void)XMPP_startStream;
- (void)XMPP_sendAuth: (OFString*)name;
- (void)XMPP_handleFeatures: (OFXMLElement*)elem;
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
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
447
448
449
450
451
452
453
454







+
+
















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







			   @"<stream:stream to='%@' xmlns='" NS_CLIENT @"' "
			   @"xmlns:stream='" NS_STREAM @"' "
			   @"version='1.0'>", server];
}

- (void)XMPP_handleIQ: (XMPPIQ*)iq
{
	BOOL handled = NO;

	if ([iq.ID isEqual: bindID]) {
		[self XMPP_handleResourceBind: iq];
		return;
	}

	if ([iq.ID isEqual: sessionID]) {
		[self XMPP_handleSession: iq];
		return;
	}

	if ([iq.ID isEqual: rosterID]) {
		[self XMPP_handleRoster: iq];
		return;
	}

	if ([delegate respondsToSelector: @selector(connection:didReceiveIQ:)])
		[delegate connection: self
			didReceiveIQ: iq];
		handled = [delegate connection: self
				  didReceiveIQ: iq];

	if (!handled) {
		OFString *from = [iq attributeForName: @"from"].stringValue;
		OFString *to = [iq attributeForName: @"to"].stringValue;
		OFXMLElement *error;

		[iq setType: @"error"];

		[iq removeAttributeForName: @"from"];
		[iq removeAttributeForName: @"to"];

		if (from != nil)
			[iq addAttributeWithName: @"to"
				     stringValue: from];
		if (to != nil)
			[iq addAttributeWithName: @"from"
				     stringValue: to];

		error = [OFXMLElement elementWithName: @"error"];
		[error addAttributeWithName: @"type"
				stringValue: @"cancel"];
		[error addChild:
		    [OFXMLElement elementWithName: @"service-unavailable"
					namespace: NS_STANZAS]];
		[iq addChild: error];

		[self sendStanza: iq];
	}
}

- (void)XMPP_handleMessage: (XMPPMessage*)msg
{
	if ([delegate respondsToSelector:
	     @selector(connection:didReceiveMessage:)])
		[delegate connection: self

Modified tests/test.m from [05cdbc9644] to [0b259b0e5c].

125
126
127
128
129
130
131
132

133
134
135


136
137
138
139
140
141
142
125
126
127
128
129
130
131

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







-
+



+
+







	pres = [XMPPPresence presence];
	[pres addPriority: 10];
	[pres addStatus: @"ObjXMPP test is working!"];

	[conn sendStanza: pres];
}

- (void)connection: (XMPPConnection*)conn
- (BOOL)connection: (XMPPConnection*)conn
      didReceiveIQ: (XMPPIQ*)iq
{
	of_log(@"IQ: %@", iq);

	return NO;
}

-  (void)connection: (XMPPConnection*)conn
  didReceiveMessage: (XMPPMessage*)msg
{
	of_log(@"Message: %@", msg);
}