ObjXMPP  Check-in [15c050df49]

Overview
Comment:Move auth and bound handling to delegate.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 15c050df4982c7dc78bb9d431a33a0ceada54f0f973004d0cfc082a07ae54f4c
User & Date: js on 2011-03-21 14:44:42
Other Links: manifest | tags
Context
2011-03-21
15:15
Request session and send initial presence in tests. check-in: ae80606d3d user: js tags: trunk
14:44
Move auth and bound handling to delegate. check-in: 15c050df49 user: js tags: trunk
13:56
Make use of optional protocols. check-in: 57b5811d80 user: js tags: trunk
Changes

Modified src/XMPPConnection.h from [06bcbbdead] to [5712350844].

28
29
30
31
32
33
34

35


36
37
38
39
40
41

42
43
44
45
46
47
48
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51







+
-
+
+






+







@class XMPPIQ;
@class XMPPMessage;
@class XMPPPresence;
@class XMPPAuthenticator;

@protocol XMPPConnectionDelegate
@optional
- (void)connectionWasAuthenticated: (XMPPConnection*)conn;
- (void)connectionWasClosed: (XMPPConnection*)conn;
- (void)connection: (XMPPConnection*)conn
     wasBoundToJID: (XMPPJID*)jid;
- (void)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

/**
 * \brief A class which abstracts a connection to an XMPP service.
 */
@interface XMPPConnection: OFObject <OFXMLParserDelegate,
    OFXMLElementBuilderDelegate>
60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77







-
+







	OFString *resource;
	/// The JID bound to this connection (this is determined by the server)
	XMPPJID *JID;
	/// The port to connect to
	short port;
	/// Whether to use TLS
	BOOL useTLS;
	id <XMPPConnectionDelegate> delegate;
	id <XMPPConnectionDelegate, OFObject> delegate;
	XMPPAuthenticator *authModule;
}

@property (copy) OFString *username;
@property (copy) OFString *password;
@property (copy) OFString *server;
@property (copy) OFString *resource;

Modified src/XMPPConnection.m from [b2823f282f] to [bdd589660a].

187
188
189
190
191
192
193
194


195
196
197
198
199
200
201
187
188
189
190
191
192
193

194
195
196
197
198
199
200
201
202







-
+
+







{
	char buf[512];

	for (;;) {
		size_t len = [sock readNBytes: 512
				   intoBuffer: buf];

		if (len < 1)
		if (len < 1 && [delegate respondsToSelector:
		    @selector(connectionWasClosed:)])
			[delegate connectionWasClosed: self];

		[of_stdout writeNBytes: len
			    fromBuffer: buf];
		[parser parseBuffer: buf
			   withSize: len];
	}
262
263
264
265
266
267
268
269





270
271
272
273
274
275
276
263
264
265
266
267
268
269

270
271
272
273
274
275
276
277
278
279
280
281







-
+
+
+
+
+







	OFXMLElement *bindElem = iq.children.firstObject;

	if ([bindElem.name isEqual: @"bind"] &&
	    [bindElem.namespace isEqual: NS_BIND]) {
		OFXMLElement *jidElem = bindElem.children.firstObject;
		JID = [[XMPPJID alloc] initWithString:
		    [jidElem.children.firstObject stringValue]];
		of_log(@"Bound to JID: %@", [JID fullJID]);

		if ([delegate respondsToSelector:
		    @selector(connection:wasBoundToJID:)])
			[delegate connection: self
			       wasBoundToJID: JID];
	}
}

- (void)_handleFeatures: (OFXMLElement*)elem
{
	OFXMLElement *starttls = [elem
	    elementsForName: @"starttls"
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
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







+
-
-
+
+




+
+
-
-
+
+




+
+
-
-
+
+







{
	// FIXME: More checking!
	if ([iq.ID isEqual: @"bind0"] && [iq.type isEqual: @"result"]) {
		[self _handleResourceBind: iq];
		return;
	}

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

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

- (void)_handlePresence: (XMPPPresence*)pres
{
	if ([delegate respondsToSelector:
	    @selector(connection:didReceivePresence:)])
	[delegate connection: self
	  didReceivePresence: pres];
		[delegate connection: self
		  didReceivePresence: pres];
}

- (void)elementBuilder: (OFXMLElementBuilder*)b
       didBuildElement: (OFXMLElement*)elem
{
	elem.defaultNamespace = NS_CLIENT;
	[elem setPrefix: @"stream"
404
405
406
407
408
409
410
411




412
413
414
415
416
417
418
414
415
416
417
418
419
420

421
422
423
424
425
426
427
428
429
430
431







-
+
+
+
+







			return;
		}

		if ([elem.name isEqual: @"success"]) {
			[authModule parseServerFinalMessage:
			    [OFDataArray dataArrayWithBase64EncodedString:
				[elem.children.firstObject stringValue]]];
			of_log(@"Auth successful");

			if ([delegate respondsToSelector:
			    @selector(connectionWasAuthenticated:)])
				[delegate connectionWasAuthenticated: self];

			/* Stream restart */
			parser.delegate = self;
			[self _startStream];
			return;
		}

Modified tests/test.m from [ddd6016310] to [8016af6ff2].

101
102
103
104
105
106
107
108

109


110





111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129





130
101
102
103
104
105
106
107

108
109
110
111

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141







-
+

+
+
-
+
+
+
+
+



















+
+
+
+
+

	@try {
		[conn handleConnection];
	} @catch (id e) {
		of_log(@"%@", e);
	}
}

- (void)connectionWasClosed: (XMPPConnection*)conn
- (void)connectionWasAuthenticated: (XMPPConnection*)conn
{
	of_log(@"Auth successful");
}
	of_log(@"Connection was closed!");

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

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

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

-   (void)connection: (XMPPConnection*)conn
  didReceivePresence: (XMPPPresence*)pres
{
	of_log(@"Presence: %@", pres);
}

- (void)connectionWasClosed: (XMPPConnection*)conn
{
	of_log(@"Connection was closed!");
}
@end