ObjXMPP  Diff

Differences From Artifact [d765d3a204]:

To Artifact [febcd779c1]:


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "XMPPStreamManagement.h"
#import "namespaces.h"

@implementation XMPPStreamManagement
- initWithConnection: (XMPPConnection*)connection_
{
	self = [super init];

	@try {
		_connection = connection_;
		[_connection addDelegate: self];
		receivedCount = 0;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_connection removeDelegate: self];

	[super dealloc];
}

- (void)connection: (XMPPConnection*)connection_
 didReceiveElement: (OFXMLElement*)element
{
	OFString *elementName = [element name];
	OFString *elementNS = [element namespace];

	if ([elementNS isEqual: XMPP_NS_SM]) {
		if ([elementName isEqual: @"enabled"]) {
			receivedCount = 0;
			return;
		}

		if ([elementName isEqual: @"failed"]) {
			/* TODO: How do we handle this? */
			return;
		}

		if ([elementName isEqual: @"r"]) {
			OFXMLElement *ack =
			    [OFXMLElement elementWithName: @"a"
						namespace: XMPP_NS_SM];


			[ack addAttributeWithName: @"h"
				      stringValue:
			    [OFString stringWithFormat: @"%" PRIu32,
				receivedCount]];
			[connection_ sendStanza: ack];
		}
	}

	if ([elementNS isEqual: XMPP_NS_CLIENT] &&
	    ([elementName isEqual: @"iq"] ||
	     [elementName isEqual: @"presence"] ||
	     [elementName isEqual: @"message"]))
		receivedCount++;
}

/* TODO: Count outgoing stanzas here and cache them, send own ACK requests
- (void)connection: (XMPPConnection*)connection_
    didSendElement: (OFXMLElement*)element
{
}
*/

- (void)connection: (XMPPConnection*)connection
     wasBoundToJID: (XMPPJID*)JID







|




|

<















|







|












>
>

|
<
<
|







|



|







20
21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "XMPPStreamManagement.h"
#import "namespaces.h"

@implementation XMPPStreamManagement
- initWithConnection: (XMPPConnection*)connection
{
	self = [super init];

	@try {
		_connection = connection;
		[_connection addDelegate: self];

	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_connection removeDelegate: self];

	[super dealloc];
}

- (void)connection: (XMPPConnection*)connection
 didReceiveElement: (OFXMLElement*)element
{
	OFString *elementName = [element name];
	OFString *elementNS = [element namespace];

	if ([elementNS isEqual: XMPP_NS_SM]) {
		if ([elementName isEqual: @"enabled"]) {
			_receivedCount = 0;
			return;
		}

		if ([elementName isEqual: @"failed"]) {
			/* TODO: How do we handle this? */
			return;
		}

		if ([elementName isEqual: @"r"]) {
			OFXMLElement *ack =
			    [OFXMLElement elementWithName: @"a"
						namespace: XMPP_NS_SM];
			OFString *stringValue = [OFString
			    stringWithFormat: @"%" PRIu32, _receivedCount];
			[ack addAttributeWithName: @"h"
				      stringValue: stringValue];


			[connection sendStanza: ack];
		}
	}

	if ([elementNS isEqual: XMPP_NS_CLIENT] &&
	    ([elementName isEqual: @"iq"] ||
	     [elementName isEqual: @"presence"] ||
	     [elementName isEqual: @"message"]))
		_receivedCount++;
}

/* TODO: Count outgoing stanzas here and cache them, send own ACK requests
- (void)connection: (XMPPConnection*)connection
    didSendElement: (OFXMLElement*)element
{
}
*/

- (void)connection: (XMPPConnection*)connection
     wasBoundToJID: (XMPPJID*)JID