ObjXMPP  Check-in [69ecc12d18]

Overview
Comment:Add multicast delegates.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 69ecc12d18cb01fae6fd771c196c6e3a78bae09492feea5bdf001660d2b745a8
User & Date: js on 2012-01-26 23:23:04
Other Links: manifest | tags
Context
2012-01-28
00:43
Decouple XMPPRoster and XMPPConnection check-in: 128dcb8343 user: florob@babelmonkeys.de tags: trunk
2012-01-26
23:23
Add multicast delegates. check-in: 69ecc12d18 user: js tags: trunk
23:03
Fix a retain cycle. check-in: ec22f66cb0 user: js tags: trunk
Changes

Modified .hgignore from [a244c6678b] to [9951009680].

8
9
10
11
12
13
14

15
16
17
18
19
20
21
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22







+







autom4te.cache
build
buildsys.mk
config.h.in
config.log
config.status
configure
DerivedData
docs
extra.mk
ObjXMPP.xcodeproj/*.mode1v3
ObjXMPP.xcodeproj/*.pbxuser
ObjXMPP.xcodeproj/project.xcworkspace
ObjXMPP.xcodeproj/xcuserdata
tests/tests

Modified ObjXMPP.xcodeproj/project.pbxproj from [f6dd9d2300] to [4f8b0f0ad0].

12
13
14
15
16
17
18


19
20
21
22
23
24
25
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27







+
+







		4B1295F11337C37E00154B25 /* ObjXMPP.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BC559911337A65400E345C7 /* ObjXMPP.framework */; };
		4B1295F21337C3CF00154B25 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BC559D61337ABD300E345C7 /* ObjFW.framework */; };
		4B19F57A14D17082005D52DC /* XMPPCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B19F57614D17081005D52DC /* XMPPCallback.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B19F57B14D17082005D52DC /* XMPPCallback.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B19F57714D17081005D52DC /* XMPPCallback.m */; };
		4B19F57C14D17082005D52DC /* XMPPEXTERNALAuth.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B19F57814D17081005D52DC /* XMPPEXTERNALAuth.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B19F57D14D17082005D52DC /* XMPPEXTERNALAuth.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B19F57914D17081005D52DC /* XMPPEXTERNALAuth.m */; };
		4B19F5A314D1779E005D52DC /* ObjOpenSSL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B19F5A214D1779E005D52DC /* ObjOpenSSL.framework */; };
		4B19F5D114D20B01005D52DC /* XMPPMulticastDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B19F5CF14D20B01005D52DC /* XMPPMulticastDelegate.h */; };
		4B19F5D214D20B01005D52DC /* XMPPMulticastDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B19F5D014D20B01005D52DC /* XMPPMulticastDelegate.m */; };
		4B4844F5138BBC7500EB48A5 /* XMPPSRVLookup.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B4844F3138BBC7400EB48A5 /* XMPPSRVLookup.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B4844F6138BBC7500EB48A5 /* XMPPSRVLookup.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B4844F4138BBC7500EB48A5 /* XMPPSRVLookup.m */; };
		4B484501138BBEEB00EB48A5 /* libresolv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B484500138BBEEB00EB48A5 /* libresolv.dylib */; };
		4BC559D71337ABD300E345C7 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BC559D61337ABD300E345C7 /* ObjFW.framework */; };
		4BC559EC1337AC0900E345C7 /* XMPPAuthenticator.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC559DA1337AC0900E345C7 /* XMPPAuthenticator.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4BC559ED1337AC0900E345C7 /* XMPPAuthenticator.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BC559DB1337AC0900E345C7 /* XMPPAuthenticator.m */; };
		4BC559EE1337AC0900E345C7 /* XMPPConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC559DC1337AC0900E345C7 /* XMPPConnection.h */; settings = {ATTRIBUTES = (Public, ); }; };
64
65
66
67
68
69
70


71
72
73
74
75
76
77
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81







+
+







		4B1295E01337BD2D00154B25 /* ObjXMPPTests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ObjXMPPTests; sourceTree = BUILT_PRODUCTS_DIR; };
		4B1295EE1337BD5F00154B25 /* test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = test.m; path = tests/test.m; sourceTree = SOURCE_ROOT; };
		4B19F57614D17081005D52DC /* XMPPCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPCallback.h; path = src/XMPPCallback.h; sourceTree = SOURCE_ROOT; };
		4B19F57714D17081005D52DC /* XMPPCallback.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPCallback.m; path = src/XMPPCallback.m; sourceTree = SOURCE_ROOT; };
		4B19F57814D17081005D52DC /* XMPPEXTERNALAuth.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPEXTERNALAuth.h; path = src/XMPPEXTERNALAuth.h; sourceTree = SOURCE_ROOT; };
		4B19F57914D17081005D52DC /* XMPPEXTERNALAuth.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPEXTERNALAuth.m; path = src/XMPPEXTERNALAuth.m; sourceTree = SOURCE_ROOT; };
		4B19F5A214D1779E005D52DC /* ObjOpenSSL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjOpenSSL.framework; path = /Library/Frameworks/ObjOpenSSL.framework; sourceTree = "<group>"; };
		4B19F5CF14D20B01005D52DC /* XMPPMulticastDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPMulticastDelegate.h; path = src/XMPPMulticastDelegate.h; sourceTree = SOURCE_ROOT; };
		4B19F5D014D20B01005D52DC /* XMPPMulticastDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPMulticastDelegate.m; path = src/XMPPMulticastDelegate.m; sourceTree = SOURCE_ROOT; };
		4B4844F3138BBC7400EB48A5 /* XMPPSRVLookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPSRVLookup.h; path = src/XMPPSRVLookup.h; sourceTree = SOURCE_ROOT; };
		4B4844F4138BBC7500EB48A5 /* XMPPSRVLookup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPSRVLookup.m; path = src/XMPPSRVLookup.m; sourceTree = SOURCE_ROOT; };
		4B484500138BBEEB00EB48A5 /* libresolv.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libresolv.dylib; path = usr/lib/libresolv.dylib; sourceTree = SDKROOT; };
		4BC559911337A65400E345C7 /* ObjXMPP.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ObjXMPP.framework; sourceTree = BUILT_PRODUCTS_DIR; };
		4BC559D61337ABD300E345C7 /* ObjFW.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjFW.framework; path = ../../../../Library/Frameworks/ObjFW.framework; sourceTree = "<group>"; };
		4BC559DA1337AC0900E345C7 /* XMPPAuthenticator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPAuthenticator.h; path = src/XMPPAuthenticator.h; sourceTree = SOURCE_ROOT; };
		4BC559DB1337AC0900E345C7 /* XMPPAuthenticator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPAuthenticator.m; path = src/XMPPAuthenticator.m; sourceTree = SOURCE_ROOT; };
184
185
186
187
188
189
190


191
192
193
194
195
196
197
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203







+
+







				4B19F57914D17081005D52DC /* XMPPEXTERNALAuth.m */,
				4BC559E01337AC0900E345C7 /* XMPPIQ.h */,
				4BC559E11337AC0900E345C7 /* XMPPIQ.m */,
				4BC559E21337AC0900E345C7 /* XMPPJID.h */,
				4BC559E31337AC0900E345C7 /* XMPPJID.m */,
				4BC559E41337AC0900E345C7 /* XMPPMessage.h */,
				4BC559E51337AC0900E345C7 /* XMPPMessage.m */,
				4B19F5CF14D20B01005D52DC /* XMPPMulticastDelegate.h */,
				4B19F5D014D20B01005D52DC /* XMPPMulticastDelegate.m */,
				4BC559E61337AC0900E345C7 /* XMPPPLAINAuth.h */,
				4BC559E71337AC0900E345C7 /* XMPPPLAINAuth.m */,
				4BC559E81337AC0900E345C7 /* XMPPPresence.h */,
				4BC559E91337AC0900E345C7 /* XMPPPresence.m */,
				4BDEF8051340B240000156D1 /* XMPPRoster.h */,
				4BDEF8061340B240000156D1 /* XMPPRoster.m */,
				4BD9BF57134003F700DAB43A /* XMPPRosterItem.h */,
235
236
237
238
239
240
241

242
243
244
245
246
247
248
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255







+







				4BC559FA1337AC0900E345C7 /* XMPPPresence.h in Headers */,
				4BDEF8071340B240000156D1 /* XMPPRoster.h in Headers */,
				4BD9BF59134003F700DAB43A /* XMPPRosterItem.h in Headers */,
				4BC559FC1337AC0900E345C7 /* XMPPSCRAMAuth.h in Headers */,
				4B4844F5138BBC7500EB48A5 /* XMPPSRVLookup.h in Headers */,
				4BC55A011337AC1800E345C7 /* XMPPStanza.h in Headers */,
				4B01D020137C7E7D005624EA /* namespaces.h in Headers */,
				4B19F5D114D20B01005D52DC /* XMPPMulticastDelegate.h in Headers */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXHeadersBuildPhase section */

/* Begin PBXNativeTarget section */
		4B1295DF1337BD2D00154B25 /* ObjXMPPTests */ = {
340
341
342
343
344
345
346

347
348
349
350
351
352
353
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361







+







				4BC559F91337AC0900E345C7 /* XMPPPLAINAuth.m in Sources */,
				4BC559FB1337AC0900E345C7 /* XMPPPresence.m in Sources */,
				4BC55A001337AC1800E345C7 /* XMPPSCRAMAuth.m in Sources */,
				4BC55A021337AC1800E345C7 /* XMPPStanza.m in Sources */,
				4BD9BF5A134003F700DAB43A /* XMPPRosterItem.m in Sources */,
				4BDEF8081340B240000156D1 /* XMPPRoster.m in Sources */,
				4B4844F6138BBC7500EB48A5 /* XMPPSRVLookup.m in Sources */,
				4B19F5D214D20B01005D52DC /* XMPPMulticastDelegate.m in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXSourcesBuildPhase section */

/* Begin XCBuildConfiguration section */
		4B1295EA1337BD2D00154B25 /* Debug */ = {

Modified src/Makefile from [fd40e02aba] to [91e4f33c74].

9
10
11
12
13
14
15

16
17
18
19
20
21
22
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23







+







       XMPPCallback.m		\
       XMPPConnection.m		\
       XMPPExceptions.m		\
       XMPPEXTERNALAuth.m	\
       XMPPIQ.m			\
       XMPPJID.m		\
       XMPPMessage.m		\
       XMPPMulticastDelegate.m	\
       XMPPPLAINAuth.m		\
       XMPPPresence.m		\
       XMPPRoster.m		\
       XMPPRosterItem.m		\
       XMPPSCRAMAuth.m		\
       XMPPSRVLookup.m		\
       XMPPStanza.m

Modified src/XMPPConnection.h from [191f094bce] to [2a38027c58].

1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







/*
 * Copyright (c) 2010, 2011, Jonathan Schleifer <js@webkeks.org>
 * Copyright (c) 2010, 2011, 2012, Jonathan Schleifer <js@webkeks.org>
 * Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
 *
 * https://webkeks.org/hg/objxmpp/
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice is present in all copies.
28
29
30
31
32
33
34

35
36
37
38
39
40
41
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42







+







@class XMPPIQ;
@class XMPPMessage;
@class XMPPPresence;
@class XMPPAuthenticator;
@class XMPPRoster;
@class XMPPRosterItem;
@class SSLSocket;
@class XMPPMulticastDelegate;

@protocol XMPPConnectionDelegate
#ifndef XMPP_CONNECTION_M
    <OFObject>
#endif
#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
@optional
73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107














108
109
110
111
112
113
114
74
75
76
77
78
79
80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
100
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







-
+














-












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







	OFXMLParser *parser, *oldParser;
	OFXMLElementBuilder *elementBuilder, *oldElementBuilder;
	OFString *username, *password, *server, *resource;
	OFString *privateKeyFile, *certificateFile;
	OFString *domain, *domainToASCII;
	XMPPJID *JID;
	uint16_t port;
	id <XMPPConnectionDelegate, OFObject> delegate;
	XMPPMulticastDelegate *delegates;
	OFMutableDictionary *callbacks;
	XMPPAuthenticator *authModule;
	BOOL streamOpen;
	BOOL needsSession;
	BOOL encryptionRequired, encrypted;
	unsigned int lastID;
	XMPPRoster *roster;
}

#ifdef OF_HAVE_PROPERTIES
@property (copy) OFString *username, *password, *server, *domain, *resource;
@property (copy) OFString *privateKeyFile, *certificateFile;
@property (copy, readonly) XMPPJID *JID;
@property (assign) uint16_t port;
@property (assign) id <XMPPConnectionDelegate> delegate;
@property (readonly, retain) XMPPRoster *roster;
@property (readonly, retain, getter=socket) OFTCPSocket *sock;
@property (assign) BOOL encryptionRequired;
@property (readonly) BOOL encrypted;
@property (readonly) BOOL streamOpen;
#endif

/**
 * \return A new autoreleased XMPPConnection
 */
+ connection;

/**
 * Adds the specified delegate.
 *
 * \param delegate The delegate to add
 */
- (void)addDelegate: (id <XMPPConnectionDelegate>)delegate;

/**
 * Removes the specified delegate.
 *
 * \param delegate The delegate to remove
 */
- (void)removeDelegate: (id <XMPPConnectionDelegate>)delegate;

/**
 * Connects to the XMPP service.
 */
- (void)connect;

/**
 * Closes the stream to the XMPP service
170
171
172
173
174
175
176
177
178
179



180
181
182
183
184
185
186
187
188


189
190
191
192
193
194
195
184
185
186
187
188
189
190



191
192
193
194
195
196
197
198
199
200


201
202
203
204
205
206
207
208
209







-
-
-
+
+
+







-
-
+
+







/**
 * Sends an XMPPIQ, registering a callback method
 *
 * \param object The object that contains the callback method
 * \param selector The selector of the callback method,
 *		   must take exactly one parameter of type XMPPIQ*
 */
-     (void)sendIQ: (XMPPIQ*)iq
withCallbackObject: (id)object
	  selector: (SEL)selector;
-	(void)sendIQ: (XMPPIQ*)iq
  withCallbackObject: (id)object
	    selector: (SEL)selector;

#ifdef OF_HAVE_BLOCKS
/**
 * Sends an XMPPIQ, registering a callback block
 *
 * \param callback The callback block
 */
-    (void)sendIQ: (XMPPIQ*)iq
withCallbackBlock: (void(^)(XMPPIQ*))callback;
-      (void)sendIQ: (XMPPIQ*)iq
  withCallbackBlock: (void(^)(XMPPIQ*))block;
#endif

/**
 * Generates a new, unique stanza ID.
 *
 * \return A new, generated, unique stanza ID.
 */
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231

232
233
234
235
218
219
220
221
222
223
224


225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248







-
-



















+




- (void)setDomain: (OFString*)domain;
- (OFString*)domain;
- (void)setResource: (OFString*)resource;
- (OFString*)resource;
- (XMPPJID*)JID;
- (void)setPort: (uint16_t)port;
- (uint16_t)port;
- (void)setDelegate: (id <XMPPConnectionDelegate>)delegate;
- (id <XMPPConnectionDelegate>)delegate;
- (XMPPRoster*)roster;

- (void)XMPP_startStream;
- (void)XMPP_handleStream: (OFXMLElement*)element;
- (void)XMPP_handleTLS: (OFXMLElement*)element;
- (void)XMPP_handleSASL: (OFXMLElement*)element;
- (void)XMPP_handleStanza: (OFXMLElement*)element;
- (void)XMPP_sendAuth: (OFString*)authName;
- (void)XMPP_sendResourceBind;
- (void)XMPP_sendStreamError: (OFString*)condition
			text: (OFString*)text;
- (void)XMPP_handleIQ: (XMPPIQ*)iq;
- (void)XMPP_handleMessage: (XMPPMessage*)message;
- (void)XMPP_handlePresence: (XMPPPresence*)presence;
- (void)XMPP_handleFeatures: (OFXMLElement*)element;
- (void)XMPP_handleResourceBind: (XMPPIQ*)iq;
- (void)XMPP_sendSession;
- (void)XMPP_handleSession: (XMPPIQ*)iq;
- (OFString*)XMPP_IDNAToASCII: (OFString*)domain;
- (XMPPMulticastDelegate*)XMPP_delegates;
@end

@interface OFObject (XMPPConnectionDelegate) <XMPPConnectionDelegate>
@end

Modified src/XMPPConnection.m from [677aa509d2] to [17919bf855].

1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







/*
 * Copyright (c) 2010, 2011, Jonathan Schleifer <js@webkeks.org>
 * Copyright (c) 2010, 2011, 2012, Jonathan Schleifer <js@webkeks.org>
 * Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
 *
 * https://webkeks.org/hg/objxmpp/
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice is present in all copies.
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
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







+


















+







#import "XMPPStanza.h"
#import "XMPPJID.h"
#import "XMPPIQ.h"
#import "XMPPMessage.h"
#import "XMPPPresence.h"
#import "XMPPRoster.h"
#import "XMPPRosterItem.h"
#import "XMPPMulticastDelegate.h"
#import "XMPPExceptions.h"
#import "namespaces.h"

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

- init
{
	self = [super init];

	@try {
		sock = [[OFTCPSocket alloc] init];
		port = 5222;
		encrypted = NO;
		streamOpen = NO;
		delegates = [[XMPPMulticastDelegate alloc] init];
		callbacks = [[OFMutableDictionary alloc] init];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
85
86
87
88
89
90
91

92
93
94
95
96
97
98
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101







+







	[password release];
	[privateKeyFile release];
	[certificateFile release];
	[server release];
	[domain release];
	[resource release];
	[JID release];
	[delegates release];
	[callbacks release];
	[authModule release];
	[roster release];

	[super dealloc];
}

300
301
302
303
304
305
306
307
308
309



310
311
312
313
314
315
316
303
304
305
306
307
308
309



310
311
312
313
314
315
316
317
318
319







-
-
-
+
+
+







			return;
	}
}

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

	[parser parseBuffer: buffer
		 withLength: length];

	[oldParser release];
371
372
373
374
375
376
377
378
379
380
381



382
383
384
385
386
387
388
389
390
391
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
424
425
426
427
374
375
376
377
378
379
380




381
382
383
384
385
386
387
388
389
390
391




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
424
425
426
427
428
429







-
-
-
-
+
+
+








-
-
-
-
+
+
+
+
+

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





-
+

-
-
-
-
+
+
+
+
+

+
+
-
+
-
-
+
-
-
+
-







		@throw [SSLInvalidCertificateException
		    exceptionWithClass: isa
				reason: @"No matching identifier"];
}

- (void)sendStanza: (OFXMLElement*)element
{
	if ([delegate respondsToSelector:
	    @selector(connection:didSendElement:)])
		[delegate connection: self
		      didSendElement: element];
	[delegates broadcastSelector: @selector(connection:didSendElement:)
		       forConnection: self
			  withObject: element];

	[sock writeString: [element XMLString]];
}

-	(void)sendIQ: (XMPPIQ*)iq
  withCallbackObject: (id)object
	    selector: (SEL)selector
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	@try {
		if (![iq ID])
			[iq setID: [self generateStanzaID]];
	OFAutoreleasePool *pool;
	XMPPCallback *callback;

	if (![iq ID])
		[iq setID: [self generateStanzaID]];

		[callbacks setObject: [XMPPCallback
					 callbackWithCallbackObject: object
							   selector: selector]
			      forKey: [iq ID]];
	pool = [[OFAutoreleasePool alloc] init];
	callback = [XMPPCallback callbackWithCallbackObject: object
						   selector: selector];
	[callbacks setObject: callback
		      forKey: [iq ID]];
	} @finally {
		[pool release];
	}
	[pool release];


	[self sendStanza: iq];
}

#ifdef OF_HAVE_BLOCKS
-      (void)sendIQ: (XMPPIQ*)iq
  withCallbackBlock: (xmpp_callback_block_t)callback;
  withCallbackBlock: (xmpp_callback_block_t)block;
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	@try {
		if (![iq ID])
			[iq setID: [self generateStanzaID]];
	OFAutoreleasePool *pool;
	XMPPCallback *callback;

	if (![iq ID])
		[iq setID: [self generateStanzaID]];

	pool = [[OFAutoreleasePool alloc] init];
	callback = [XMPPCallback callbackWithCallbackBlock: block];
		[callbacks setObject: [XMPPCallback
	[callbacks setObject: callback
					  callbackWithCallbackBlock: callback]
			      forKey: [iq ID]];
		      forKey: [iq ID]];
	} @finally {
		[pool release];
	[pool release];
	}

	[self sendStanza: iq];
}
#endif

- (OFString*)generateStanzaID
{
482
483
484
485
486
487
488
489
490
491
492



493
494
495
496
497
498
499
484
485
486
487
488
489
490




491
492
493
494
495
496
497
498
499
500







-
-
-
-
+
+
+







	if ([element name] == nil)
		return;

	[element setDefaultNamespace: XMPP_NS_CLIENT];
	[element setPrefix: @"stream"
	      forNamespace: XMPP_NS_STREAM];

	if ([delegate respondsToSelector:
	    @selector(connection:didReceiveElement:)])
		[delegate connection: self
		   didReceiveElement: element];
	[delegates broadcastSelector: @selector(connection:didReceiveElement:)
		       forConnection: self
			  withObject: element];

	if ([[element namespace] isEqual: XMPP_NS_CLIENT])
		[self XMPP_handleStanza: element];

	if ([[element namespace] isEqual: XMPP_NS_STREAM])
		[self XMPP_handleStream: element];

688
689
690
691
692
693
694
695
696
697



698
699
700
701
702
703
704
705
706
707
708
709



710
711
712
713
714
715
716
689
690
691
692
693
694
695



696
697
698
699
700
701
702
703
704
705
706
707



708
709
710
711
712
713
714
715
716
717







-
-
-
+
+
+









-
-
-
+
+
+








- (void)XMPP_handleTLS: (OFXMLElement*)element
{
	if ([[element name] isEqual: @"proceed"]) {
		/* FIXME: Catch errors here */
		SSLSocket *newSock;

		if ([delegate respondsToSelector:
		    @selector(connectionWillUpgradeToTLS:)])
			[delegate connectionWillUpgradeToTLS: self];
		[delegates broadcastSelector: @selector(
						  connectionWillUpgradeToTLS:)
			       forConnection: self];

		newSock = [[SSLSocket alloc] initWithSocket: sock
					     privateKeyFile: privateKeyFile
					    certificateFile: certificateFile];
		[sock release];
		sock = newSock;

		encrypted = YES;

		if ([delegate respondsToSelector:
		    @selector(connectionDidUpgradeToTLS:)])
			[delegate connectionDidUpgradeToTLS: self];
		[delegates broadcastSelector: @selector(
						  connectionDidUpgradeToTLS:)
			       forConnection: self];

		/* Stream restart */
		[self XMPP_startStream];

		return;
	}

744
745
746
747
748
749
750
751
752
753



754
755
756
757
758
759
760
745
746
747
748
749
750
751



752
753
754
755
756
757
758
759
760
761







-
-
-
+
+
+







		return;
	}

	if ([[element name] isEqual: @"success"]) {
		[authModule continueWithData: [OFDataArray
		    dataArrayWithBase64EncodedString: [element stringValue]]];

		if ([delegate respondsToSelector:
		    @selector(connectionWasAuthenticated:)])
			[delegate connectionWasAuthenticated: self];
		[delegates broadcastSelector: @selector(
						  connectionWWasAuthenticated:)
			       forConnection: self];

		/* Stream restart */
		[self XMPP_startStream];

		return;
	}

782
783
784
785
786
787
788

789
790
791



792
793
794
795
796
797
798
799
800
801
802
803
804
805



806
807
808
809
810
811
812
813



814
815
816
817
818
819
820
783
784
785
786
787
788
789
790



791
792
793
794
795
796
797
798
799
800
801
802
803




804
805
806
807
808
809
810




811
812
813
814
815
816
817
818
819
820







+
-
-
-
+
+
+










-
-
-
-
+
+
+




-
-
-
-
+
+
+







	}

	if ([iq elementForName: @"query"
		     namespace: XMPP_NS_ROSTER])
		if ([roster handleIQ: iq])
			return;

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

	if (!handled && ![[iq type] isEqual: @"error"] &&
	    ![[iq type] isEqual: @"result"]) {
		[self sendStanza: [iq errorIQWithType: @"cancel"
					    condition: @"service-unavailable"]];
	}
}

- (void)XMPP_handleMessage: (XMPPMessage*)message
{
	if ([delegate respondsToSelector:
	     @selector(connection:didReceiveMessage:)])
		[delegate connection: self
		   didReceiveMessage: message];
	[delegates broadcastSelector: @selector(connection:didReceiveMessage:)
		       forConnection: self
			  withObject: message];
}

- (void)XMPP_handlePresence: (XMPPPresence*)presence
{
	if ([delegate respondsToSelector:
	     @selector(connection:didReceivePresence:)])
		[delegate connection: self
		  didReceivePresence: presence];
	[delegates broadcastSelector: @selector(connection:didReceivePresence:)
		       forConnection: self
			  withObject: presence];
}

- (void)XMPP_handleFeatures: (OFXMLElement*)element
{
	OFXMLElement *starttls = [element elementForName: @"starttls"
					       namespace: XMPP_NS_STARTTLS];
	OFXMLElement *bind = [element elementForName: @"bind"
975
976
977
978
979
980
981
982
983
984



985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007



1008
1009
1010
1011
1012
1013
1014
975
976
977
978
979
980
981



982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004



1005
1006
1007
1008
1009
1010
1011
1012
1013
1014







-
-
-
+
+
+




















-
-
-
+
+
+







	JID = [[XMPPJID alloc] initWithString: [jidElement stringValue]];

	if (needsSession) {
		[self XMPP_sendSession];
		return;
	}

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

- (void)XMPP_sendSession
{
	XMPPIQ *iq;

	iq = [XMPPIQ IQWithType: @"set"
			     ID: [self generateStanzaID]];
	[iq addChild: [OFXMLElement elementWithName: @"session"
					  namespace: XMPP_NS_SESSION]];
	[self		sendIQ: iq
	    withCallbackObject: self
		      selector: @selector(XMPP_handleSession:)];
}

- (void)XMPP_handleSession: (XMPPIQ*)iq
{
	if (![[iq type] isEqual: @"result"])
		assert(0);

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

- (OFString*)XMPP_IDNAToASCII: (OFString*)domain_
{
	OFString *ret;
	char *cDomain;
	Idna_rc rc;
1041
1042
1043
1044
1045
1046
1047
1048

1049
1050

1051
1052
1053

1054





1055

1056
1057
1058
1059
1060
1061
1062
1041
1042
1043
1044
1045
1046
1047

1048
1049

1050
1051
1052

1053
1054
1055
1056
1057
1058
1059

1060
1061
1062
1063
1064
1065
1066
1067







-
+

-
+


-
+

+
+
+
+
+
-
+







}

- (uint16_t)port
{
	return port;
}

- (void)setDelegate: (id <XMPPConnectionDelegate>)delegate_
- (void)addDelegate: (id <XMPPConnectionDelegate>)delegate
{
	delegate = (id <XMPPConnectionDelegate, OFObject>)delegate_;
	[delegates addDelegate: delegate];
}

- (id <XMPPConnectionDelegate>)delegate
- (void)removeDelegate: (id <XMPPConnectionDelegate>)delegate
{
	[delegates removeDelegate: delegate];
}

- (XMPPMulticastDelegate*)XMPP_delegates
{
	return delegate;
	return delegates;
}

- (XMPPRoster*)roster
{
	return [[roster retain] autorelease];
}
@end

Added src/XMPPMulticastDelegate.h version [44c939a254].

Added src/XMPPMulticastDelegate.m version [405f29fa95].

Modified src/XMPPRoster.m from [a02f686076] to [357151968c].

27
28
29
30
31
32
33

34
35
36
37
38
39
40
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41







+







#include <assert.h>

#import "XMPPRoster.h"
#import "XMPPRosterItem.h"
#import "XMPPConnection.h"
#import "XMPPIQ.h"
#import "XMPPJID.h"
#import "XMPPMulticastDelegate.h"
#import "namespaces.h"

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

153
154
155
156
157
158
159
160
161
162
163








164
165
166
167
168
169
170


171
172

173
174
175
176
177
178
179
154
155
156
157
158
159
160




161
162
163
164
165
166
167
168
169
170
171
172
173


174
175


176
177
178
179
180
181
182
183







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





-
-
+
+
-
-
+







			[rosterItem setGroups: groups];

		if ([subscription isEqual: @"remove"])
			[self XMPP_deleteRosterItem: rosterItem];
		else
			[self XMPP_addRosterItem: rosterItem];

		if (isPush && [[connection delegate] respondsToSelector:
		    @selector(connection:didReceiveRosterItem:)])
			[[connection delegate] connection: connection
				     didReceiveRosterItem: rosterItem];
		if (isPush) {
			SEL sel = @selector(connection:didReceiveRosterItem:);

			[[connection XMPP_delegates]
			    broadcastSelector: sel
				forConnection: connection
				   withObject: rosterItem];
		}
	}

	if (isPush) {
		[connection sendStanza: [iq resultIQ]];
	} else {
		if ([[connection delegate] respondsToSelector:
		     @selector(connectionDidReceiveRoster:)])
		[[connection XMPP_delegates]
		    broadcastSelector: @selector(connectionDidReceiveRoster:)
			[[connection delegate]
			    connectionDidReceiveRoster: connection];
			forConnection: connection];

		[rosterID release];
		rosterID = nil;
	}

	return YES;
}

Modified tests/test.m from [2ccadc96fb] to [6b509f1c6b].

87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101







-
+







	XMPPStanza *stanza = [XMPPStanza stanzaWithElement: elem];
	assert([[elem XMLString] isEqual: [stanza XMLString]]);
	assert(([[OFString stringWithFormat: @"%@, %@, %@, %@",
	    [[stanza from] fullJID], [[stanza to] fullJID], [stanza type],
	    [stanza ID]] isEqual: @"bob@localhost, alice@localhost, get, 42"]));

	conn = [[XMPPConnection alloc] init];
	[conn setDelegate: self];
	[conn addDelegate: self];

	if ([arguments count] != 3) {
		of_log(@"Invalid count of command line arguments!");
		[OFApplication terminateWithStatus: 1];
	}

	[conn setDomain: [arguments objectAtIndex: 0]];