ObjXMPP  Check-in [2f8a95152e]

Overview
Comment:Port to ObjC 1.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2f8a95152e6d5ad68007c1cc4d23c61dd434c9ac2e081fabccfc889dbf975716
User & Date: js on 2011-03-29 01:46:20
Other Links: manifest | tags
Context
2011-03-29
01:51
Import <bsd/stdlib.h> if not on a BSD system. Still needs LIBS=-lbsd. check-in: 168813e54d user: js tags: trunk
01:46
Port to ObjC 1. check-in: 2f8a95152e user: js tags: trunk
00:04
Get rid of unused variable useTLS. check-in: c6162edb52 user: js tags: trunk
Changes

Modified ObjXMPP.xcodeproj/project.pbxproj from [b60ab9486b] to [4b39058b85].

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
		4BC55A011337AC1800E345C7 /* XMPPStanza.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC559FE1337AC1800E345C7 /* XMPPStanza.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4BC55A021337AC1800E345C7 /* XMPPStanza.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BC559FF1337AC1800E345C7 /* XMPPStanza.m */; };
		4BD0AB16134129B900445289 /* ObjOpenSSL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BD0AB15134129B900445289 /* ObjOpenSSL.framework */; };
		4BD9BF59134003F700DAB43A /* XMPPRosterItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD9BF57134003F700DAB43A /* XMPPRosterItem.h */; };
		4BD9BF5A134003F700DAB43A /* XMPPRosterItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BD9BF58134003F700DAB43A /* XMPPRosterItem.m */; };
		4BDEF8071340B240000156D1 /* XMPPRoster.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BDEF8051340B240000156D1 /* XMPPRoster.h */; };
		4BDEF8081340B240000156D1 /* XMPPRoster.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BDEF8061340B240000156D1 /* XMPPRoster.m */; };
		4BF459B91340DE3600701BCC /* XMPPRoster_private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BF459B81340DE3600701BCC /* XMPPRoster_private.h */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
		4B1295DE1337BD2D00154B25 /* CopyFiles */ = {
			isa = PBXCopyFilesBuildPhase;
			buildActionMask = 2147483647;
			dstPath = /usr/share/man/man1/;







<







33
34
35
36
37
38
39

40
41
42
43
44
45
46
		4BC55A011337AC1800E345C7 /* XMPPStanza.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC559FE1337AC1800E345C7 /* XMPPStanza.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4BC55A021337AC1800E345C7 /* XMPPStanza.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BC559FF1337AC1800E345C7 /* XMPPStanza.m */; };
		4BD0AB16134129B900445289 /* ObjOpenSSL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BD0AB15134129B900445289 /* ObjOpenSSL.framework */; };
		4BD9BF59134003F700DAB43A /* XMPPRosterItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD9BF57134003F700DAB43A /* XMPPRosterItem.h */; };
		4BD9BF5A134003F700DAB43A /* XMPPRosterItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BD9BF58134003F700DAB43A /* XMPPRosterItem.m */; };
		4BDEF8071340B240000156D1 /* XMPPRoster.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BDEF8051340B240000156D1 /* XMPPRoster.h */; };
		4BDEF8081340B240000156D1 /* XMPPRoster.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BDEF8061340B240000156D1 /* XMPPRoster.m */; };

/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
		4B1295DE1337BD2D00154B25 /* CopyFiles */ = {
			isa = PBXCopyFilesBuildPhase;
			buildActionMask = 2147483647;
			dstPath = /usr/share/man/man1/;
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
		4BC559FF1337AC1800E345C7 /* XMPPStanza.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPStanza.m; path = src/XMPPStanza.m; sourceTree = SOURCE_ROOT; };
		4BC55A051337ADA800E345C7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; };
		4BD0AB15134129B900445289 /* ObjOpenSSL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjOpenSSL.framework; path = ../ObjOpenSSL/build/Debug/ObjOpenSSL.framework; sourceTree = "<group>"; };
		4BD9BF57134003F700DAB43A /* XMPPRosterItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPRosterItem.h; path = src/XMPPRosterItem.h; sourceTree = SOURCE_ROOT; };
		4BD9BF58134003F700DAB43A /* XMPPRosterItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPRosterItem.m; path = src/XMPPRosterItem.m; sourceTree = SOURCE_ROOT; };
		4BDEF8051340B240000156D1 /* XMPPRoster.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPRoster.h; path = src/XMPPRoster.h; sourceTree = SOURCE_ROOT; };
		4BDEF8061340B240000156D1 /* XMPPRoster.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPRoster.m; path = src/XMPPRoster.m; sourceTree = SOURCE_ROOT; };
		4BF459B81340DE3600701BCC /* XMPPRoster_private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPRoster_private.h; path = src/XMPPRoster_private.h; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
		4B1295DD1337BD2D00154B25 /* Frameworks */ = {
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 2147483647;
			files = (







<







79
80
81
82
83
84
85

86
87
88
89
90
91
92
		4BC559FF1337AC1800E345C7 /* XMPPStanza.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPStanza.m; path = src/XMPPStanza.m; sourceTree = SOURCE_ROOT; };
		4BC55A051337ADA800E345C7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; };
		4BD0AB15134129B900445289 /* ObjOpenSSL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjOpenSSL.framework; path = ../ObjOpenSSL/build/Debug/ObjOpenSSL.framework; sourceTree = "<group>"; };
		4BD9BF57134003F700DAB43A /* XMPPRosterItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPRosterItem.h; path = src/XMPPRosterItem.h; sourceTree = SOURCE_ROOT; };
		4BD9BF58134003F700DAB43A /* XMPPRosterItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPRosterItem.m; path = src/XMPPRosterItem.m; sourceTree = SOURCE_ROOT; };
		4BDEF8051340B240000156D1 /* XMPPRoster.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPRoster.h; path = src/XMPPRoster.h; sourceTree = SOURCE_ROOT; };
		4BDEF8061340B240000156D1 /* XMPPRoster.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPRoster.m; path = src/XMPPRoster.m; sourceTree = SOURCE_ROOT; };

/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
		4B1295DD1337BD2D00154B25 /* Frameworks */ = {
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 2147483647;
			files = (
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
				4BC559E41337AC0900E345C7 /* XMPPMessage.h */,
				4BC559E51337AC0900E345C7 /* XMPPMessage.m */,
				4BC559E61337AC0900E345C7 /* XMPPPLAINAuth.h */,
				4BC559E71337AC0900E345C7 /* XMPPPLAINAuth.m */,
				4BC559E81337AC0900E345C7 /* XMPPPresence.h */,
				4BC559E91337AC0900E345C7 /* XMPPPresence.m */,
				4BDEF8051340B240000156D1 /* XMPPRoster.h */,
				4BF459B81340DE3600701BCC /* XMPPRoster_private.h */,
				4BDEF8061340B240000156D1 /* XMPPRoster.m */,
				4BD9BF57134003F700DAB43A /* XMPPRosterItem.h */,
				4BD9BF58134003F700DAB43A /* XMPPRosterItem.m */,
				4BC559EA1337AC0900E345C7 /* XMPPSCRAMAuth.h */,
				4BC559FD1337AC1800E345C7 /* XMPPSCRAMAuth.m */,
				4BC559FE1337AC1800E345C7 /* XMPPStanza.h */,
				4BC559FF1337AC1800E345C7 /* XMPPStanza.m */,







<







160
161
162
163
164
165
166

167
168
169
170
171
172
173
				4BC559E41337AC0900E345C7 /* XMPPMessage.h */,
				4BC559E51337AC0900E345C7 /* XMPPMessage.m */,
				4BC559E61337AC0900E345C7 /* XMPPPLAINAuth.h */,
				4BC559E71337AC0900E345C7 /* XMPPPLAINAuth.m */,
				4BC559E81337AC0900E345C7 /* XMPPPresence.h */,
				4BC559E91337AC0900E345C7 /* XMPPPresence.m */,
				4BDEF8051340B240000156D1 /* XMPPRoster.h */,

				4BDEF8061340B240000156D1 /* XMPPRoster.m */,
				4BD9BF57134003F700DAB43A /* XMPPRosterItem.h */,
				4BD9BF58134003F700DAB43A /* XMPPRosterItem.m */,
				4BC559EA1337AC0900E345C7 /* XMPPSCRAMAuth.h */,
				4BC559FD1337AC1800E345C7 /* XMPPSCRAMAuth.m */,
				4BC559FE1337AC1800E345C7 /* XMPPStanza.h */,
				4BC559FF1337AC1800E345C7 /* XMPPStanza.m */,
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
				4BC559F61337AC0900E345C7 /* XMPPMessage.h in Headers */,
				4BC559F81337AC0900E345C7 /* XMPPPLAINAuth.h in Headers */,
				4BC559FA1337AC0900E345C7 /* XMPPPresence.h in Headers */,
				4BC559FC1337AC0900E345C7 /* XMPPSCRAMAuth.h in Headers */,
				4BC55A011337AC1800E345C7 /* XMPPStanza.h in Headers */,
				4BD9BF59134003F700DAB43A /* XMPPRosterItem.h in Headers */,
				4BDEF8071340B240000156D1 /* XMPPRoster.h in Headers */,
				4BF459B91340DE3600701BCC /* XMPPRoster_private.h in Headers */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXHeadersBuildPhase section */

/* Begin PBXNativeTarget section */
		4B1295DF1337BD2D00154B25 /* ObjXMPPTests */ = {







<







199
200
201
202
203
204
205

206
207
208
209
210
211
212
				4BC559F61337AC0900E345C7 /* XMPPMessage.h in Headers */,
				4BC559F81337AC0900E345C7 /* XMPPPLAINAuth.h in Headers */,
				4BC559FA1337AC0900E345C7 /* XMPPPresence.h in Headers */,
				4BC559FC1337AC0900E345C7 /* XMPPSCRAMAuth.h in Headers */,
				4BC55A011337AC1800E345C7 /* XMPPStanza.h in Headers */,
				4BD9BF59134003F700DAB43A /* XMPPRosterItem.h in Headers */,
				4BDEF8071340B240000156D1 /* XMPPRoster.h in Headers */,

			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXHeadersBuildPhase section */

/* Begin PBXNativeTarget section */
		4B1295DF1337BD2D00154B25 /* ObjXMPPTests */ = {

Modified src/Makefile from [942a976e26] to [57b35db95f].

1
2
3
4
5
6
all:
	objfw-compile -Wall -g --lib 0.0 -o objxmpp *.m \
		`pkg-config --cflags --libs libidn` -lobjopenssl

clean:
	rm -f *.o *.so *.dylib *.dll

|




1
2
3
4
5
6
all:
	objfw-compile -Wall -Werror -g --lib 0.0 -o objxmpp *.m \
		`pkg-config --cflags --libs libidn` -lobjopenssl

clean:
	rm -f *.o *.so *.dylib *.dll

Modified src/XMPPAuthenticator.h from [d4a2643832] to [cf4b0ef3fa].

23
24
25
26
27
28
29
30
31
32
33
34
35
36



37

38

39

40
41
42
43
44
45
46
#import <ObjFW/ObjFW.h>

/**
 * \brief A base class for classes implementing authentication mechanisms
 */
@interface XMPPAuthenticator: OFObject
{
	/// The authzid to get authorization for
	OFString *authzid;
	/// The authcid to authenticate with
	OFString *authcid;
	/// The password to authenticate with
	OFString *password;
}



@property (copy) OFString *authzid;

@property (copy) OFString *authcid;

@property (copy) OFString *password;


/**
 * Initializes an already allocated XMPPAuthenticator with an authcid
 * and password.
 *
 * \param authcid The authcid to authenticate with
 * \param password The password to authenticate with







<

<

<


>
>
>

>

>

>







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
#import <ObjFW/ObjFW.h>

/**
 * \brief A base class for classes implementing authentication mechanisms
 */
@interface XMPPAuthenticator: OFObject
{

	OFString *authzid;

	OFString *authcid;

	OFString *password;
}

#ifdef OF_HAVE_PROPERTIES
/// The authzid to get authorization for
@property (copy) OFString *authzid;
/// The authcid to authenticate with
@property (copy) OFString *authcid;
/// The password to authenticate with
@property (copy) OFString *password;
#endif

/**
 * Initializes an already allocated XMPPAuthenticator with an authcid
 * and password.
 *
 * \param authcid The authcid to authenticate with
 * \param password The password to authenticate with
75
76
77
78
79
80
81







82

/**
 * Checks whether the servers final message was valid
 *
 * \param  message The servers final message
 */
- (void)parseServerFinalMessage: (OFDataArray*)message;







@end







>
>
>
>
>
>
>

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

/**
 * Checks whether the servers final message was valid
 *
 * \param  message The servers final message
 */
- (void)parseServerFinalMessage: (OFDataArray*)message;

- (void)setAuthzid: (OFString*)authzid;
- (OFString*)authzid;
- (void)setAuthcid: (OFString*)authcid;
- (OFString*)authcid;
- (void)setPassword: (OFString*)password;
- (OFString*)password;
@end

Modified src/XMPPAuthenticator.m from [6b8d4dd60e] to [9855270d5d].

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "XMPPAuthenticator.h"

@implementation XMPPAuthenticator
@synthesize authzid;
@synthesize authcid;
@synthesize password;

- initWithAuthcid: (OFString*)authcid_
	 password: (OFString*)password_
{
	return [self initWithAuthzid: nil
			     authcid: authcid_
			    password: password_];
}







<
<
<
<







19
20
21
22
23
24
25




26
27
28
29
30
31
32
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "XMPPAuthenticator.h"

@implementation XMPPAuthenticator




- initWithAuthcid: (OFString*)authcid_
	 password: (OFString*)password_
{
	return [self initWithAuthzid: nil
			     authcid: authcid_
			    password: password_];
}
52
53
54
55
56
57
58




































59
60
61
62
63
64
65
{
	[authzid release];
	[authcid release];
	[password release];

	[super dealloc];
}





































- (OFDataArray*)clientFirstMessage
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}








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







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
95
96
97
{
	[authzid release];
	[authcid release];
	[password release];

	[super dealloc];
}

- (void)setAuthzid: (OFString*)authzid_
{
	OFString *old = authzid;
	authzid = [authzid_ copy];
	[old release];
}

- (OFString*)authzid
{
	return [[authzid copy] autorelease];
}

- (void)setAuthcid: (OFString*)authcid_
{
	OFString *old = authcid;
	authcid = [authcid_ copy];
	[old release];
}

- (OFString*)authcid
{
	return [[authcid copy] autorelease];
}

- (void)setPassword: (OFString*)password_
{
	OFString *old = password;
	password = [password_ copy];
	[old release];
}

- (OFString*)password
{
	return [[password copy] autorelease];
}

- (OFDataArray*)clientFirstMessage
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

Modified src/XMPPConnection.h from [d775d14285] to [0ccafcf867].

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
#define XMPP_NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl"
#define XMPP_NS_STARTTLS @"urn:ietf:params:xml:ns:xmpp-tls"
#define XMPP_NS_STANZAS @"urn:ietf:params:xml:ns:xmpp-stanzas"
#define XMPP_NS_SESSION @"urn:ietf:params:xml:ns:xmpp-session"
#define XMPP_NS_STREAM @"http://etherx.jabber.org/streams"

@protocol XMPPConnectionDelegate




@optional

- (void)connectionWasAuthenticated: (XMPPConnection*)conn;
- (void)connection: (XMPPConnection*)conn
     wasBoundToJID: (XMPPJID*)jid;
- (void)connectionDidReceiveRoster: (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

/**
 * \brief A class which abstracts a connection to an XMPP service.
 */
@interface XMPPConnection: OFObject <OFXMLParserDelegate,

    OFXMLElementBuilderDelegate>

{
	OFTCPSocket *sock;
	OFXMLParser *parser;
	OFXMLElementBuilder *elementBuilder;
	OFString *username, *password, *server, *resource;
	XMPPJID *JID;
	uint16_t port;
	id <XMPPConnectionDelegate, OFObject> delegate;
	XMPPAuthenticator *authModule;
	BOOL needsSession;
	unsigned int lastID;
	OFString *bindID, *sessionID, *rosterID;
	XMPPRoster *roster;
}


@property (copy) OFString *username, *password, *server, *resource;
@property (copy, readonly) XMPPJID *JID;
@property (assign) uint16_t port;
@property (retain) id <XMPPConnectionDelegate> delegate;
@property (readonly, retain) XMPPRoster *roster;


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

/**







>
>
>
>

>
















|
>
|
>















>





>







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
95
96
97
98
#define XMPP_NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl"
#define XMPP_NS_STARTTLS @"urn:ietf:params:xml:ns:xmpp-tls"
#define XMPP_NS_STANZAS @"urn:ietf:params:xml:ns:xmpp-stanzas"
#define XMPP_NS_SESSION @"urn:ietf:params:xml:ns:xmpp-session"
#define XMPP_NS_STREAM @"http://etherx.jabber.org/streams"

@protocol XMPPConnectionDelegate
#ifndef XMPP_CONNECTION_M
    <OFObject>
#endif
#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
@optional
#endif
- (void)connectionWasAuthenticated: (XMPPConnection*)conn;
- (void)connection: (XMPPConnection*)conn
     wasBoundToJID: (XMPPJID*)jid;
- (void)connectionDidReceiveRoster: (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

/**
 * \brief A class which abstracts a connection to an XMPP service.
 */
@interface XMPPConnection: OFObject
#ifdef OF_HAVE_OPTONAL_PROTOCOLS
    <OFXMLParserDelegate, OFXMLElementBuilderDelegate>
#endif
{
	OFTCPSocket *sock;
	OFXMLParser *parser;
	OFXMLElementBuilder *elementBuilder;
	OFString *username, *password, *server, *resource;
	XMPPJID *JID;
	uint16_t port;
	id <XMPPConnectionDelegate, OFObject> delegate;
	XMPPAuthenticator *authModule;
	BOOL needsSession;
	unsigned int lastID;
	OFString *bindID, *sessionID, *rosterID;
	XMPPRoster *roster;
}

#ifdef OF_HAVE_PROPERTIES
@property (copy) OFString *username, *password, *server, *resource;
@property (copy, readonly) XMPPJID *JID;
@property (assign) uint16_t port;
@property (retain) id <XMPPConnectionDelegate> delegate;
@property (readonly, retain) XMPPRoster *roster;
#endif

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

/**
105
106
107
108
109
110
111




























112



 */
- (OFString*)generateStanzaID;

/**
 * Requests the roster.
 */
- (void)requestRoster;




























@end










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

>
>
>
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
142
143
144
145
146
147
148
149
150
151
152
 */
- (OFString*)generateStanzaID;

/**
 * Requests the roster.
 */
- (void)requestRoster;

- (void)setUsername: (OFString*)username;
- (OFString*)username;
- (void)setPassword: (OFString*)password;
- (OFString*)password;
- (void)setServer: (OFString*)server;
- (OFString*)server;
- (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_handleStanza: (OFXMLElement*)elem;
- (void)XMPP_sendAuth: (OFString*)name;
- (void)XMPP_handleIQ: (XMPPIQ*)iq;
- (void)XMPP_handleMessage: (XMPPMessage*)msg;
- (void)XMPP_handlePresence: (XMPPPresence*)pres;
- (void)XMPP_handleFeatures: (OFXMLElement*)elem;
- (void)XMPP_sendResourceBind;
- (void)XMPP_handleResourceBind: (XMPPIQ*)iq;
- (void)XMPP_sendSession;
- (void)XMPP_handleSession: (XMPPIQ*)iq;
- (void)XMPP_handleRoster: (XMPPIQ*)iq;
@end

@interface OFObject (XMPPConnectionDelegate) <XMPPConnectionDelegate>
@end

Modified src/XMPPConnection.m from [8c7125d78b] to [a4f8793bd7].

17
18
19
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
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */



#include <assert.h>

#include <stringprep.h>
#include <idna.h>

#import <ObjOpenSSL/SSLSocket.h>

#import "XMPPConnection.h"
#import "XMPPSCRAMAuth.h"
#import "XMPPPLAINAuth.h"
#import "XMPPStanza.h"
#import "XMPPJID.h"
#import "XMPPIQ.h"
#import "XMPPMessage.h"
#import "XMPPPresence.h"
#import "XMPPRoster.h"
#import "XMPPRoster_private.h"
#import "XMPPRosterItem.h"
#import "XMPPExceptions.h"

@interface XMPPConnection ()
- (void)XMPP_startStream;
- (void)XMPP_handleStanza: (OFXMLElement*)elem;
- (void)XMPP_sendAuth: (OFString*)name;
- (void)XMPP_handleIQ: (XMPPIQ*)iq;
- (void)XMPP_handleMessage: (XMPPMessage*)msg;
- (void)XMPP_handlePresence: (XMPPPresence*)pres;
- (void)XMPP_handleFeatures: (OFXMLElement*)elem;
- (void)XMPP_sendResourceBind;
- (void)XMPP_handleResourceBind: (XMPPIQ*)iq;
- (void)XMPP_sendSession;
- (void)XMPP_handleSession: (XMPPIQ*)iq;
- (void)XMPP_handleRoster: (XMPPIQ*)iq;
@end

@implementation XMPPConnection
@synthesize JID, port, delegate, roster;

- init
{
	self = [super init];

	@try {
		sock = [[OFTCPSocket alloc] init];
		parser = [[OFXMLParser alloc] init];
		elementBuilder = [[OFXMLElementBuilder alloc] init];

		port = 5222;

		parser.delegate = self;
		elementBuilder.delegate = self;

		roster = [[XMPPRoster alloc] initWithConnection: self];
	} @catch (id e) {
		[self release];
		@throw e;
	}








>
>
















<



<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
<











|
|







17
18
19
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
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#define XMPP_CONNECTION_M

#include <assert.h>

#include <stringprep.h>
#include <idna.h>

#import <ObjOpenSSL/SSLSocket.h>

#import "XMPPConnection.h"
#import "XMPPSCRAMAuth.h"
#import "XMPPPLAINAuth.h"
#import "XMPPStanza.h"
#import "XMPPJID.h"
#import "XMPPIQ.h"
#import "XMPPMessage.h"
#import "XMPPPresence.h"
#import "XMPPRoster.h"

#import "XMPPRosterItem.h"
#import "XMPPExceptions.h"
















@implementation XMPPConnection


- init
{
	self = [super init];

	@try {
		sock = [[OFTCPSocket alloc] init];
		parser = [[OFXMLParser alloc] init];
		elementBuilder = [[OFXMLElementBuilder alloc] init];

		port = 5222;

		[parser setDelegate: self];
		[elementBuilder setDelegate: self];

		roster = [[XMPPRoster alloc] initWithConnection: self];
	} @catch (id e) {
		[self release];
		@throw e;
	}

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
	OFString *old = server;
	char *srv;
	Idna_rc rc;

	if ((rc = idna_to_ascii_8z([server_ cString],
	    &srv, IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS)
		@throw [XMPPIDNATranslationFailedException
		 newWithClass: isa
		   connection: self
		    operation: @"ToASCII"
		       string: server_];

	@try {
		server = [[OFString alloc] initWithCString: srv];
	} @finally {
		free(srv);
	}








|
|
|
|







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
	OFString *old = server;
	char *srv;
	Idna_rc rc;

	if ((rc = idna_to_ascii_8z([server_ cString],
	    &srv, IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS)
		@throw [XMPPIDNATranslationFailedException
		    newWithClass: isa
		      connection: self
		       operation: @"ToASCII"
			  string: server_];

	@try {
		server = [[OFString alloc] initWithCString: srv];
	} @finally {
		free(srv);
	}

254
255
256
257
258
259
260


261
262
263
264
265
266
267

268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
-    (void)parser: (OFXMLParser*)p
  didStartElement: (OFString*)name
       withPrefix: (OFString*)prefix
	namespace: (OFString*)ns
       attributes: (OFArray*)attrs
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];



	if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] ||
	    ![ns isEqual: XMPP_NS_STREAM]) {
		of_log(@"Did not get expected stream start!");
		assert(0);
	}


	for (OFXMLAttribute *attr in attrs) {
		if ([attr.name isEqual: @"from"] &&
		    ![attr.stringValue isEqual: server]) {
			of_log(@"Got invalid from in stream start!");
			assert(0);
		}
	}

	parser.delegate = elementBuilder;

	[pool release];
}

- (void)elementBuilder: (OFXMLElementBuilder*)b
       didBuildElement: (OFXMLElement*)elem
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	elem.defaultNamespace = XMPP_NS_CLIENT;
	[elem setPrefix: @"stream"
	   forNamespace: XMPP_NS_STREAM];

	of_log(@"In:  %@", elem);

	[self XMPP_handleStanza: elem];








>
>







>
|
|
|





|









|







238
239
240
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
269
270
271
272
273
274
275
276
277
278
279
280
-    (void)parser: (OFXMLParser*)p
  didStartElement: (OFString*)name
       withPrefix: (OFString*)prefix
	namespace: (OFString*)ns
       attributes: (OFArray*)attrs
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFEnumerator *enumerator;
	OFXMLAttribute *attr;

	if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] ||
	    ![ns isEqual: XMPP_NS_STREAM]) {
		of_log(@"Did not get expected stream start!");
		assert(0);
	}

	enumerator = [attrs objectEnumerator];
	while ((attr = [enumerator nextObject]) != nil) {
		if ([[attr name] isEqual: @"from"] &&
		    ![[attr stringValue] isEqual: server]) {
			of_log(@"Got invalid from in stream start!");
			assert(0);
		}
	}

	[parser setDelegate: elementBuilder];

	[pool release];
}

- (void)elementBuilder: (OFXMLElementBuilder*)b
       didBuildElement: (OFXMLElement*)elem
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

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

	of_log(@"In:  %@", elem);

	[self XMPP_handleStanza: elem];

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
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
			   @"xmlns='" XMPP_NS_CLIENT @"' "
			   @"xmlns:stream='" XMPP_NS_STREAM @"' "
			   @"version='1.0'>", server];
}

- (void)XMPP_handleStanza: (OFXMLElement*)elem
{
	if ([elem.namespace isEqual: XMPP_NS_CLIENT]) {
		if ([elem.name isEqual: @"iq"]) {
			[self XMPP_handleIQ: [XMPPIQ stanzaWithElement: elem]];
			return;
		}

		if ([elem.name isEqual: @"message"]) {
			[self XMPP_handleMessage:
			    [XMPPMessage stanzaWithElement: elem]];
			return;
		}

		if ([elem.name isEqual: @"presence"]) {
			[self XMPP_handlePresence:
			    [XMPPPresence stanzaWithElement: elem]];
			return;
		}

		assert(0);
	}

	if ([elem.namespace isEqual: XMPP_NS_STREAM]) {
		if ([elem.name isEqual: @"features"]) {
			[self XMPP_handleFeatures: elem];
			return;
		}

		assert(0);
	}

	if ([elem.namespace isEqual: XMPP_NS_STARTTLS]) {
		if ([elem.name isEqual: @"proceed"]) {
			/* FIXME: Catch errors here */
			sock = [[SSLSocket alloc] initWithSocket: sock];

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

		if ([elem.name isEqual: @"failure"])
			/* TODO: Find/create an exception to throw here */
			@throw [OFException newWithClass: isa];

		assert(0);
	}

	if ([elem.namespace isEqual: XMPP_NS_SASL]) {
		if ([elem.name isEqual: @"challenge"]) {
			OFXMLElement *responseTag;
			OFDataArray *challenge =
			    [OFDataArray dataArrayWithBase64EncodedString:
			    [elem.children.firstObject stringValue]];
			OFDataArray *response = [authModule
			    calculateResponseWithChallenge: challenge];

			responseTag = [OFXMLElement
			    elementWithName: @"response"
				  namespace: XMPP_NS_SASL];
			[responseTag addChild:
			    [OFXMLElement elementWithCharacters:
			    [response stringByBase64Encoding]]];

			[self sendStanza: responseTag];
			return;
		}

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

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

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

		if ([elem.name isEqual: @"failure"]) {
			of_log(@"Auth failed!");
			// FIXME: Do more parsing/handling
			@throw [XMPPAuthFailedException
			    newWithClass: isa
			      connection: self
				  reason: elem.stringValue];
		}

		assert(0);
	}

	assert(0);
}

- (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:)])
		handled = [delegate connection: self
				  didReceiveIQ: iq];

	if (!handled) {
		XMPPJID *from = iq.from;
		XMPPJID *to = iq.to;
		OFXMLElement *error;

		[iq setType: @"error"];

		iq.to = from;
		iq.from = to;

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







|
|




|





|








|
|







|
|




|




|






|
|



|














|


|






|




|





|












|




|




|









|
|



|
|
<







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
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
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
428
429
430
			   @"xmlns='" XMPP_NS_CLIENT @"' "
			   @"xmlns:stream='" XMPP_NS_STREAM @"' "
			   @"version='1.0'>", server];
}

- (void)XMPP_handleStanza: (OFXMLElement*)elem
{
	if ([[elem namespace] isEqual: XMPP_NS_CLIENT]) {
		if ([[elem name] isEqual: @"iq"]) {
			[self XMPP_handleIQ: [XMPPIQ stanzaWithElement: elem]];
			return;
		}

		if ([[elem name] isEqual: @"message"]) {
			[self XMPP_handleMessage:
			    [XMPPMessage stanzaWithElement: elem]];
			return;
		}

		if ([[elem name] isEqual: @"presence"]) {
			[self XMPP_handlePresence:
			    [XMPPPresence stanzaWithElement: elem]];
			return;
		}

		assert(0);
	}

	if ([[elem namespace] isEqual: XMPP_NS_STREAM]) {
		if ([[elem name] isEqual: @"features"]) {
			[self XMPP_handleFeatures: elem];
			return;
		}

		assert(0);
	}

	if ([[elem namespace] isEqual: XMPP_NS_STARTTLS]) {
		if ([[elem name] isEqual: @"proceed"]) {
			/* FIXME: Catch errors here */
			sock = [[SSLSocket alloc] initWithSocket: sock];

			/* Stream restart */
			[parser setDelegate: self];
			[self XMPP_startStream];
			return;
		}

		if ([[elem name] isEqual: @"failure"])
			/* TODO: Find/create an exception to throw here */
			@throw [OFException newWithClass: isa];

		assert(0);
	}

	if ([[elem namespace] isEqual: XMPP_NS_SASL]) {
		if ([[elem name] isEqual: @"challenge"]) {
			OFXMLElement *responseTag;
			OFDataArray *challenge =
			    [OFDataArray dataArrayWithBase64EncodedString:
			    [[[elem children] firstObject] stringValue]];
			OFDataArray *response = [authModule
			    calculateResponseWithChallenge: challenge];

			responseTag = [OFXMLElement
			    elementWithName: @"response"
				  namespace: XMPP_NS_SASL];
			[responseTag addChild:
			    [OFXMLElement elementWithCharacters:
			    [response stringByBase64Encoding]]];

			[self sendStanza: responseTag];
			return;
		}

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

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

			/* Stream restart */
			[parser setDelegate: self];
			[self XMPP_startStream];
			return;
		}

		if ([[elem name] isEqual: @"failure"]) {
			of_log(@"Auth failed!");
			// FIXME: Do more parsing/handling
			@throw [XMPPAuthFailedException
			    newWithClass: isa
			      connection: self
				  reason: [elem stringValue]];
		}

		assert(0);
	}

	assert(0);
}

- (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:)])
		handled = [delegate connection: self
				  didReceiveIQ: iq];

	if (!handled) {
		XMPPJID *from = [iq from];
		XMPPJID *to = [iq to];
		OFXMLElement *error;

		[iq setType: @"error"];
		[iq setTo: from];
		[iq setFrom: to];


		error = [OFXMLElement elementWithName: @"error"];
		[error addAttributeWithName: @"type"
				stringValue: @"cancel"];
		[error addChild:
		    [OFXMLElement elementWithName: @"service-unavailable"
					namespace: XMPP_NS_STANZAS]];
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488

489



490
491
492
493
494
495
496
497
498
		[delegate connection: self
		  didReceivePresence: pres];
}

- (void)XMPP_handleFeatures: (OFXMLElement*)elem
{
	OFXMLElement *starttls =
	    [elem elementsForName: @"starttls"
			namespace: XMPP_NS_STARTTLS].firstObject;
	OFXMLElement *bind = [elem elementsForName: @"bind"
					 namespace: XMPP_NS_BIND].firstObject;
	OFXMLElement *session =
	    [elem elementsForName: @"session"
			namespace: XMPP_NS_SESSION].firstObject;
	OFArray *mechs = [elem elementsForName: @"mechanisms"
				     namespace: XMPP_NS_SASL];
	OFMutableArray *mechanisms = [OFMutableArray array];

	if (starttls != nil) {
		[self sendStanza:
		    [OFXMLElement elementWithName: @"starttls"
					namespace: XMPP_NS_STARTTLS]];
		return;
	}

	if (mechs.count > 0) {

		for (OFXMLElement *mech in [mechs.firstObject children])



			[mechanisms addObject:
			    [mech.children.firstObject stringValue]];

		if ([mechanisms containsObject: @"SCRAM-SHA-1"]) {
			authModule = [[XMPPSCRAMAuth alloc]
			    initWithAuthcid: username
				   password: password
				       hash: [OFSHA1Hash class]];
			[self XMPP_sendAuth: @"SCRAM-SHA-1"];







|
|
|
|

|
|











|
>
|
>
>
>

|







449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
		[delegate connection: self
		  didReceivePresence: pres];
}

- (void)XMPP_handleFeatures: (OFXMLElement*)elem
{
	OFXMLElement *starttls =
	    [[elem elementsForName: @"starttls"
			 namespace: XMPP_NS_STARTTLS] firstObject];
	OFXMLElement *bind = [[elem elementsForName: @"bind"
					  namespace: XMPP_NS_BIND] firstObject];
	OFXMLElement *session =
	    [[elem elementsForName: @"session"
			 namespace: XMPP_NS_SESSION] firstObject];
	OFArray *mechs = [elem elementsForName: @"mechanisms"
				     namespace: XMPP_NS_SASL];
	OFMutableArray *mechanisms = [OFMutableArray array];

	if (starttls != nil) {
		[self sendStanza:
		    [OFXMLElement elementWithName: @"starttls"
					namespace: XMPP_NS_STARTTLS]];
		return;
	}

	if ([mechs count] > 0) {
		OFEnumerator *enumerator;
		OFXMLElement *mech;

		enumerator = [[[mechs firstObject] children] objectEnumerator];
		while ((mech = [enumerator nextObject]) != nil)
			[mechanisms addObject:
			    [[[mech children] firstObject] stringValue]];

		if ([mechanisms containsObject: @"SCRAM-SHA-1"]) {
			authModule = [[XMPPSCRAMAuth alloc]
			    initWithAuthcid: username
				   password: password
				       hash: [OFSHA1Hash class]];
			[self XMPP_sendAuth: @"SCRAM-SHA-1"];
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
}

- (void)XMPP_handleResourceBind: (XMPPIQ*)iq
{
	OFXMLElement *bindElem;
	OFXMLElement *jidElem;

	if (![iq.type isEqual: @"result"])
		assert(0);

	bindElem = iq.children.firstObject;

	if (![bindElem.name isEqual: @"bind"] ||
	    ![bindElem.namespace isEqual: XMPP_NS_BIND])
		assert(0);

	jidElem = bindElem.children.firstObject;
	JID = [[XMPPJID alloc] initWithString:
	    [jidElem.children.firstObject stringValue]];

	[bindID release];
	bindID = nil;

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







|


|

|
|


|

|







547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
}

- (void)XMPP_handleResourceBind: (XMPPIQ*)iq
{
	OFXMLElement *bindElem;
	OFXMLElement *jidElem;

	if (![[iq type] isEqual: @"result"])
		assert(0);

	bindElem = [[iq children] firstObject];

	if (![[bindElem name] isEqual: @"bind"] ||
	    ![[bindElem namespace] isEqual: XMPP_NS_BIND])
		assert(0);

	jidElem = [[bindElem children] firstObject];
	JID = [[XMPPJID alloc] initWithString:
	    [[[jidElem children] firstObject] stringValue]];

	[bindID release];
	bindID = nil;

	if (needsSession) {
		[self XMPP_sendSession];
		return;
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
	[iq addChild: [OFXMLElement elementWithName: @"session"
					  namespace: XMPP_NS_SESSION]];
	[self sendStanza: iq];
}

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

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

	[sessionID release];







|







587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
	[iq addChild: [OFXMLElement elementWithName: @"session"
					  namespace: XMPP_NS_SESSION]];
	[self sendStanza: iq];
}

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

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

	[sessionID release];
626
627
628
629
630
631
632


633
634
635
636
637
638
639
640
641
642
643

644
645


646
647
648
649
650
651
652
653

654
655
656
657
658
659
660

661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
































677



































					  namespace: XMPP_NS_ROSTER]];
	[self sendStanza: iq];
}

- (void)XMPP_handleRoster: (XMPPIQ*)iq
{
	OFXMLElement *rosterElem;



	if (![iq.type isEqual: @"result"])
		assert(0);

	rosterElem = iq.children.firstObject;

	if (![rosterElem.name isEqual: @"query"] ||
	    ![rosterElem.namespace isEqual: XMPP_NS_ROSTER])
		assert(0);

	for (OFXMLElement *elem in rosterElem.children) {

		XMPPRosterItem *rosterItem;
		OFMutableArray *groups = [OFMutableArray array];



		if (![elem.name isEqual: @"item"] ||
		    ![elem.ns isEqual: XMPP_NS_ROSTER])
			continue;

		rosterItem = [XMPPRosterItem rosterItem];
		rosterItem.JID = [XMPPJID JIDWithString:
		    [elem attributeForName: @"jid"].stringValue];

		rosterItem.name = [elem attributeForName: @"name"].stringValue;
		rosterItem.subscription =
		    [elem attributeForName: @"subscription"].stringValue;

		for (OFXMLElement *groupElem in
		     [elem elementsForName: @"group"
				 namespace: XMPP_NS_ROSTER])

			[groups addObject:
			    [groupElem.children.firstObject stringValue]];

		if (groups.count > 0)
			rosterItem.groups = groups;

		[roster XMPP_addRosterItem: rosterItem];
	}

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

	[rosterID release];
	rosterID = nil;
}
































@end










































>
>

|


|

|
|


|
>


>
>

|
|



|
|
>
|
|
|

|
|
|
>

|

|
|











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

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
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
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
					  namespace: XMPP_NS_ROSTER]];
	[self sendStanza: iq];
}

- (void)XMPP_handleRoster: (XMPPIQ*)iq
{
	OFXMLElement *rosterElem;
	OFEnumerator *enumerator;
	OFXMLElement *elem;

	if (![[iq type] isEqual: @"result"])
		assert(0);

	rosterElem = [[iq children] firstObject];

	if (![[rosterElem name] isEqual: @"query"] ||
	    ![[rosterElem namespace] isEqual: XMPP_NS_ROSTER])
		assert(0);

	enumerator = [[rosterElem children] objectEnumerator];
	while ((elem = [enumerator nextObject]) != nil) {
		XMPPRosterItem *rosterItem;
		OFMutableArray *groups = [OFMutableArray array];
		OFEnumerator *groupEnumerator;
		OFXMLElement *groupElem;

		if (![[elem name] isEqual: @"item"] ||
		    ![[elem namespace] isEqual: XMPP_NS_ROSTER])
			continue;

		rosterItem = [XMPPRosterItem rosterItem];
		[rosterItem setJID: [XMPPJID JIDWithString:
		    [[elem attributeForName: @"jid"] stringValue]]];
		[rosterItem setName:
		    [[elem attributeForName: @"name"] stringValue]];
		[rosterItem setSubscription:
		    [[elem attributeForName: @"subscription"] stringValue]];

		groupEnumerator =
		    [[elem elementsForName: @"group"
				 namespace: XMPP_NS_ROSTER] objectEnumerator];
		while ((groupElem = [groupEnumerator nextObject]) != nil)
			[groups addObject:
			    [[[groupElem children] firstObject] stringValue]];

		if ([groups count] > 0)
			[rosterItem setGroups: groups];

		[roster XMPP_addRosterItem: rosterItem];
	}

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

	[rosterID release];
	rosterID = nil;
}

- (XMPPJID*)JID
{
	return [[JID copy] autorelease];
}

- (void)setPort: (uint16_t)port_
{
	port = port_;
}

- (uint16_t)port
{
	return port;
}

- (void)setDelegate: (id <XMPPConnectionDelegate>)delegate_
{
	id old = delegate;
	delegate = [(id)delegate_ retain];
	[old release];
}

- (id <XMPPConnectionDelegate>)delegate
{
	return [[delegate retain] autorelease];
}

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

@implementation OFObject (XMPPConnectionDelegate)
- (void)connectionWasAuthenticated: (XMPPConnection*)conn
{
}

- (void)connection: (XMPPConnection*)conn
     wasBoundToJID: (XMPPJID*)jid
{
}

- (void)connectionDidReceiveRoster: (XMPPConnection*)conn
{
}

- (BOOL)connection: (XMPPConnection*)conn
      didReceiveIQ: (XMPPIQ*)iq
{
	return NO;
}

-   (void)connection: (XMPPConnection*)conn
  didReceivePresence: (XMPPPresence*)pres
{
}

-  (void)connection: (XMPPConnection*)conn
  didReceiveMessage: (XMPPMessage*)msg
{
}

- (void)connectionWasClosed: (XMPPConnection*)conn
{
}
@end

Modified src/XMPPExceptions.h from [e4ea710d7a] to [2a495c565d].

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
@class XMPPAuthenticator;

@interface XMPPException: OFException
{
	XMPPConnection *connection;
}


@property (readonly, nonatomic) XMPPConnection *connection;


+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn;
- initWithClass: (Class)class_
     connection: (XMPPConnection*)conn;

@end

@interface XMPPStringPrepFailedException: XMPPException
{
	OFString *profile;
	OFString *string;
}


@property (readonly, nonatomic) OFString *profile, *string;


+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
       profile: (OFString*)profile
	string: (OFString*)string;
- initWithClass: (Class)class_
     connection: (XMPPConnection*)conn
	profile: (OFString*)profile
	 string: (OFString*)string;


@end

@interface XMPPIDNATranslationFailedException: XMPPException
{
	OFString *operation;
	OFString *string;
}


@property (readonly, nonatomic) OFString *operation, *string;


+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
     operation: (OFString*)operation
	string: (OFString*)string;
- initWithClass: (Class)class_
     connection: (XMPPConnection*)conn
      operation: (OFString*)operation
	 string: (OFString*)string;


@end

@interface XMPPAuthFailedException: XMPPException
{
	OFString *reason;
}


@property (readonly, nonatomic) OFString *reason;


+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
	reason: (OFString*)reason_;
- initWithClass: (Class)class_
     connection: (XMPPConnection*)conn
	 reason: (OFString*)reason_;

@end







>

>





>








>

>









>
>








>

>









>
>







>

>







>

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
95
96
97
98
99
100
101
102
103
104
@class XMPPAuthenticator;

@interface XMPPException: OFException
{
	XMPPConnection *connection;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, nonatomic) XMPPConnection *connection;
#endif

+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn;
- initWithClass: (Class)class_
     connection: (XMPPConnection*)conn;
- (XMPPConnection*)connection;
@end

@interface XMPPStringPrepFailedException: XMPPException
{
	OFString *profile;
	OFString *string;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, nonatomic) OFString *profile, *string;
#endif

+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
       profile: (OFString*)profile
	string: (OFString*)string;
- initWithClass: (Class)class_
     connection: (XMPPConnection*)conn
	profile: (OFString*)profile
	 string: (OFString*)string;
- (OFString*)profile;
- (OFString*)string;
@end

@interface XMPPIDNATranslationFailedException: XMPPException
{
	OFString *operation;
	OFString *string;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, nonatomic) OFString *operation, *string;
#endif

+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
     operation: (OFString*)operation
	string: (OFString*)string;
- initWithClass: (Class)class_
     connection: (XMPPConnection*)conn
      operation: (OFString*)operation
	 string: (OFString*)string;
- (OFString*)operation;
- (OFString*)string;
@end

@interface XMPPAuthFailedException: XMPPException
{
	OFString *reason;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, nonatomic) OFString *reason;
#endif

+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
	reason: (OFString*)reason_;
- initWithClass: (Class)class_
     connection: (XMPPConnection*)conn
	 reason: (OFString*)reason_;
- (OFString*)reason;
@end

Modified src/XMPPExceptions.m from [e5e54a18a7] to [95ac10b065].

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "XMPPExceptions.h"

@implementation XMPPException
@synthesize connection;

+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
{
	return [[self alloc] initWithClass: class_
				connection: conn];
}








<
<







19
20
21
22
23
24
25


26
27
28
29
30
31
32
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "XMPPExceptions.h"

@implementation XMPPException


+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
{
	return [[self alloc] initWithClass: class_
				connection: conn];
}

68
69
70
71
72
73
74





75
76
77
78
79
80
81
82
83
84
85
86
		return description;

	description = [[OFString alloc] initWithFormat:
	    @"An exception occurred in class %@!", inClass];

	return description;
}





@end

@implementation XMPPStringPrepFailedException
@synthesize profile, string;

+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
       profile: (OFString*)profile
	string: (OFString*)string
{
	return [[self alloc] initWithClass: class_
				connection: conn







>
>
>
>
>



<
<







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


81
82
83
84
85
86
87
		return description;

	description = [[OFString alloc] initWithFormat:
	    @"An exception occurred in class %@!", inClass];

	return description;
}

- (XMPPConnection*)connection
{
	return connection;
}
@end

@implementation XMPPStringPrepFailedException


+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
       profile: (OFString*)profile
	string: (OFString*)string
{
	return [[self alloc] initWithClass: class_
				connection: conn
131
132
133
134
135
136
137










138
139
140
141
142
143
144
145
146
147
148
149

	description = [[OFString alloc] initWithFormat:
	    @"Stringprep with profile %@ failed on string '%@'!",
	    profile, string];

	return description;
}










@end

@implementation XMPPIDNATranslationFailedException
@synthesize operation, string;

+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
     operation: (OFString*)operation
	string: (OFString*)string
{
	return [[self alloc] initWithClass: class_
				connection: conn







>
>
>
>
>
>
>
>
>
>



<
<







132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151


152
153
154
155
156
157
158

	description = [[OFString alloc] initWithFormat:
	    @"Stringprep with profile %@ failed on string '%@'!",
	    profile, string];

	return description;
}

- (OFString*)profile
{
	return profile;
}

- (OFString*)string
{
	return string;
}
@end

@implementation XMPPIDNATranslationFailedException


+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
     operation: (OFString*)operation
	string: (OFString*)string
{
	return [[self alloc] initWithClass: class_
				connection: conn
193
194
195
196
197
198
199










200
201
202
203
204
205
206
207
208
209
210
211
		return description;

	description = [[OFString alloc] initWithFormat:
	    @"IDNA operation %@ failed on string '%@'!", operation, string];

	return description;
}










@end

@implementation XMPPAuthFailedException
@synthesize reason;

+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
	reason: (OFString*)reason_;
{
	return [[self alloc] initWithClass: class_
				connection: conn
				    reason: reason_];







>
>
>
>
>
>
>
>
>
>



<
<







202
203
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
		return description;

	description = [[OFString alloc] initWithFormat:
	    @"IDNA operation %@ failed on string '%@'!", operation, string];

	return description;
}

- (OFString*)operation
{
	return operation;
}

- (OFString*)string
{
	return string;
}
@end

@implementation XMPPAuthFailedException


+ newWithClass: (Class)class_
    connection: (XMPPConnection*)conn
	reason: (OFString*)reason_;
{
	return [[self alloc] initWithClass: class_
				connection: conn
				    reason: reason_];
250
251
252
253
254
255
256





257
		return description;

	description = [[OFString alloc] initWithFormat:
	    @"Authentication failed. Reason: %@!", reason];

	return description;
}





@end







>
>
>
>
>

267
268
269
270
271
272
273
274
275
276
277
278
279
		return description;

	description = [[OFString alloc] initWithFormat:
	    @"Authentication failed. Reason: %@!", reason];

	return description;
}

- (OFString*)reason
{
	return reason;
}
@end

Modified src/XMPPJID.h from [77ccbb27f8] to [0a05a907db].

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
#import <ObjFW/ObjFW.h>

/**
 * \brief A class for easy handling of JIDs.
 */
@interface XMPPJID: OFObject <OFCopying>
{
	/// The JID's localpart
	OFString *node;
	/// The JID's domainpart
	OFString *domain;
	/// The JID's resourcepart
	OFString *resource;
}



@property (copy) OFString *node;

@property (copy) OFString *domain;

@property (copy) OFString *resource;


/**
 * Creates a new autoreleased XMPPJID.
 *
 * \return A new autoreleased XMPPJID
 */
+ JID;







<

<

<



>
>

>

>

>







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
#import <ObjFW/ObjFW.h>

/**
 * \brief A class for easy handling of JIDs.
 */
@interface XMPPJID: OFObject <OFCopying>
{

	OFString *node;

	OFString *domain;

	OFString *resource;
}

#ifdef OF_HAVE_PROPERTIES
/// The JID's localpart
@property (copy) OFString *node;
/// The JID's domainpart
@property (copy) OFString *domain;
/// The JID's resourcepart
@property (copy) OFString *resource;
#endif

/**
 * Creates a new autoreleased XMPPJID.
 *
 * \return A new autoreleased XMPPJID
 */
+ JID;
68
69
70
71
72
73
74







75
 */
- (OFString*)bareJID;

/**
 * \return An OFString containing the full JID
 */
- (OFString*)fullJID;







@end







>
>
>
>
>
>
>

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 */
- (OFString*)bareJID;

/**
 * \return An OFString containing the full JID
 */
- (OFString*)fullJID;

- (void)setNode: (OFString*)node;
- (OFString*)node;
- (void)setDomain: (OFString*)domain;
- (OFString*)domain;
- (void)setResource: (OFString*)resource;
- (OFString*)resource;
@end

Modified src/XMPPRoster.h from [00bb9602be] to [6e37e7971b].

28
29
30
31
32
33
34

35
36
37
38
39
40
@interface XMPPRoster: OFObject
{
	XMPPConnection *connection;
	OFMutableDictionary *groups;
}

- initWithConnection: (XMPPConnection*)conn;

- (OFArray*)groups;
- (OFArray*)rosterItemsInGroup: (OFString*)group;
- (void)addRosterItem: (XMPPRosterItem*)rosterItem;
- (void)updateRosterItem: (XMPPRosterItem*)rosterItem;
- (void)deleteRosterItem: (XMPPRosterItem*)rosterItem;
@end







>






28
29
30
31
32
33
34
35
36
37
38
39
40
41
@interface XMPPRoster: OFObject
{
	XMPPConnection *connection;
	OFMutableDictionary *groups;
}

- initWithConnection: (XMPPConnection*)conn;
- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem;
- (OFArray*)groups;
- (OFArray*)rosterItemsInGroup: (OFString*)group;
- (void)addRosterItem: (XMPPRosterItem*)rosterItem;
- (void)updateRosterItem: (XMPPRosterItem*)rosterItem;
- (void)deleteRosterItem: (XMPPRosterItem*)rosterItem;
@end

Modified src/XMPPRoster.m from [cafcc94476] to [401105b7c9].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "XMPPRoster.h"
#import "XMPPRoster_private.h"
#import "XMPPRosterItem.h"
#import "XMPPConnection.h"
#import "XMPPIQ.h"
#import "XMPPJID.h"

@implementation XMPPRoster
- initWithConnection: (XMPPConnection*)conn







<







17
18
19
20
21
22
23

24
25
26
27
28
29
30
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "XMPPRoster.h"

#import "XMPPRosterItem.h"
#import "XMPPConnection.h"
#import "XMPPIQ.h"
#import "XMPPJID.h"

@implementation XMPPRoster
- initWithConnection: (XMPPConnection*)conn
48
49
50
51
52
53
54
55

56



57
58
59
60
61
62
63
	[connection release];

	[super dealloc];
}

- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem
{
	if (rosterItem.groups.count > 0) {

		for (OFString *group in rosterItem.groups) {



			OFMutableArray *rosterGroup =
			    [groups objectForKey: group];

			if (rosterGroup == nil) {
				rosterGroup = [OFMutableArray array];
				[groups setObject: rosterGroup
					   forKey: group];







|
>
|
>
>
>







47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
	[connection release];

	[super dealloc];
}

- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem
{
	if ([[rosterItem groups] count] > 0) {
		OFEnumerator *enumerator;
		OFString *group;

		enumerator = [[rosterItem groups] objectEnumerator];
		while ((group = [enumerator nextObject]) != nil) {
			OFMutableArray *rosterGroup =
			    [groups objectForKey: group];

			if (rosterGroup == nil) {
				rosterGroup = [OFMutableArray array];
				[groups setObject: rosterGroup
					   forKey: group];
77
78
79
80
81
82
83


84
85

86
87
88
89
90
91
92
		[rosterGroup addObject: rosterItem];
	}
}

- (OFArray*)groups
{
	OFMutableArray *ret = [OFMutableArray array];



	for (OFString *group in groups)

		[ret addObject: group];

	ret->isa = [OFArray class];
	return ret;
}

- (OFArray*)rosterItemsInGroup: (OFString*)group







>
>

|
>







80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
		[rosterGroup addObject: rosterItem];
	}
}

- (OFArray*)groups
{
	OFMutableArray *ret = [OFMutableArray array];
	OFEnumerator *enumerator;
	OFString *group;

	enumerator = [groups keyEnumerator];
	while ((group = [enumerator nextObject]) != nil)
		[ret addObject: group];

	ret->isa = [OFArray class];
	return ret;
}

- (OFArray*)rosterItemsInGroup: (OFString*)group
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
142
143
144
145
146
147
148
149
150
{
	XMPPIQ *iq = [XMPPIQ IQWithType: @"set"
				     ID: [connection generateStanzaID]];
	OFXMLElement *query = [OFXMLElement elementWithName: @"query"
						  namespace: XMPP_NS_ROSTER];
	OFXMLElement *item = [OFXMLElement elementWithName: @"item"
						 namespace: XMPP_NS_ROSTER];



	[item addAttributeWithName: @"jid"
		       stringValue: rosterItem.JID.bareJID];
	if (rosterItem.name != nil)
		[item addAttributeWithName: @"name"
			       stringValue: rosterItem.name];

	for (OFString *group in rosterItem.groups)

		[item addChild: [OFXMLElement elementWithName: @"group"
						    namespace: XMPP_NS_ROSTER
						  stringValue: group]];

	[query addChild: item];
	[iq addChild: query];

	[connection sendStanza: iq];
}

- (void)deleteRosterItem: (XMPPRosterItem*)rosterItem
{
	XMPPIQ *iq = [XMPPIQ IQWithType: @"set"
				     ID: [connection generateStanzaID]];
	OFXMLElement *query = [OFXMLElement elementWithName: @"query"
						  namespace: XMPP_NS_ROSTER];
	OFXMLElement *item = [OFXMLElement elementWithName: @"item"
						 namespace: XMPP_NS_ROSTER];

	[item addAttributeWithName: @"jid"
		       stringValue: rosterItem.JID.bareJID];
	[item addAttributeWithName: @"subscription"
		       stringValue: @"remove"];

	[query addChild: item];
	[iq addChild: query];

	[connection sendStanza: iq];
}
@end







>
>


|
|

|

|
>




















|









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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
{
	XMPPIQ *iq = [XMPPIQ IQWithType: @"set"
				     ID: [connection generateStanzaID]];
	OFXMLElement *query = [OFXMLElement elementWithName: @"query"
						  namespace: XMPP_NS_ROSTER];
	OFXMLElement *item = [OFXMLElement elementWithName: @"item"
						 namespace: XMPP_NS_ROSTER];
	OFEnumerator *enumerator;
	OFString *group;

	[item addAttributeWithName: @"jid"
		       stringValue: [[rosterItem JID] bareJID]];
	if ([rosterItem name] != nil)
		[item addAttributeWithName: @"name"
			       stringValue: [rosterItem name]];

	enumerator = [[rosterItem groups] objectEnumerator];
	while ((group = [enumerator nextObject]) != nil)
		[item addChild: [OFXMLElement elementWithName: @"group"
						    namespace: XMPP_NS_ROSTER
						  stringValue: group]];

	[query addChild: item];
	[iq addChild: query];

	[connection sendStanza: iq];
}

- (void)deleteRosterItem: (XMPPRosterItem*)rosterItem
{
	XMPPIQ *iq = [XMPPIQ IQWithType: @"set"
				     ID: [connection generateStanzaID]];
	OFXMLElement *query = [OFXMLElement elementWithName: @"query"
						  namespace: XMPP_NS_ROSTER];
	OFXMLElement *item = [OFXMLElement elementWithName: @"item"
						 namespace: XMPP_NS_ROSTER];

	[item addAttributeWithName: @"jid"
		       stringValue: [[rosterItem JID] bareJID]];
	[item addAttributeWithName: @"subscription"
		       stringValue: @"remove"];

	[query addChild: item];
	[iq addChild: query];

	[connection sendStanza: iq];
}
@end

Modified src/XMPPRosterItem.h from [710a1a3d37] to [3813168f1c].

28
29
30
31
32
33
34

35
36
37
38

39
40








41
{
	XMPPJID *JID;
	OFString *name;
	OFString *subscription;
	OFArray *groups;
}


@property (copy) XMPPJID *JID;
@property (copy) OFString *name;
@property (copy) OFString *subscription;
@property (copy) OFArray *groups;


+ rosterItem;








@end







>




>


>
>
>
>
>
>
>
>

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{
	XMPPJID *JID;
	OFString *name;
	OFString *subscription;
	OFArray *groups;
}

#ifdef OF_HAVE_PROPERTIES
@property (copy) XMPPJID *JID;
@property (copy) OFString *name;
@property (copy) OFString *subscription;
@property (copy) OFArray *groups;
#endif

+ rosterItem;
- (void)setJID: (XMPPJID*)JID;
- (XMPPJID*)JID;
- (void)setName: (OFString*)name;
- (OFString*)name;
- (void)setSubscription: (OFString*)subscription;
- (OFString*)subscription;
- (void)setGroups: (OFArray*)groups;
- (OFArray*)groups;
@end

Modified src/XMPPRosterItem.m from [f9f8c64e09] to [55445a1531].

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










32
33
34
35
36
37
38
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "XMPPRosterItem.h"

@implementation XMPPRosterItem
@synthesize JID, name, subscription, groups;

+ rosterItem
{
	return [[[self alloc] init] autorelease];
}











- copy
{
	XMPPRosterItem *new = [[XMPPRosterItem alloc] init];

	@try {
		new->JID = [JID copy];







<
<




>
>
>
>
>
>
>
>
>
>







19
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
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "XMPPRosterItem.h"

@implementation XMPPRosterItem


+ rosterItem
{
	return [[[self alloc] init] autorelease];
}

- (void)dealloc
{
	[JID release];
	[name release];
	[subscription release];
	[groups release];

	[super dealloc];
}

- copy
{
	XMPPRosterItem *new = [[XMPPRosterItem alloc] init];

	@try {
		new->JID = [JID copy];
49
50
51
52
53
54
55
















































56

- (OFString*)description
{
	return [OFString stringWithFormat: @"<XMPPRosterItem, JID=%@, name=%@, "
					   @"subscription=%@, groups=%@>",
					   JID, name, subscription, groups];
}
















































@end







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

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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

- (OFString*)description
{
	return [OFString stringWithFormat: @"<XMPPRosterItem, JID=%@, name=%@, "
					   @"subscription=%@, groups=%@>",
					   JID, name, subscription, groups];
}

- (void)setJID: (XMPPJID*)JID_
{
	XMPPJID *old = JID;
	JID = [JID_ copy];
	[old release];
}

- (XMPPJID*)JID
{
	return [[JID copy] autorelease];
}

- (void)setName: (OFString*)name_
{
	OFString *old = name;
	name = [name_ copy];
	[old release];
}

- (OFString*)name
{
	return [[name copy] autorelease];
}

- (void)setSubscription: (OFString*)subscription_
{
	OFString *old = subscription;
	subscription = [subscription_ copy];
	[old release];
}

- (OFString*)subscription
{
	return [[subscription copy] autorelease];
}

- (void)setGroups: (OFArray*)groups_
{
	OFArray *old = groups;
	groups = [groups_ copy];
	[old release];
}

- (OFArray*)groups
{
	return [[groups copy] autorelease];
}
@end

Deleted src/XMPPRoster_private.h version [222f4a0c5c].

Modified src/XMPPSCRAMAuth.h from [0cd4b1aae7] to [888f15c064].

84
85
86
87
88
89
90







91
 * \param hash The class to use for calulating hashes
 * \return A initialized XMPPSCRAMAuth
 */
- initWithAuthzid: (OFString*)authzid
	  authcid: (OFString*)authcid
	 password: (OFString*)password
	     hash: (Class)hash;







@end







>
>
>
>
>
>
>

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 * \param hash The class to use for calulating hashes
 * \return A initialized XMPPSCRAMAuth
 */
- initWithAuthzid: (OFString*)authzid
	  authcid: (OFString*)authcid
	 password: (OFString*)password
	     hash: (Class)hash;

- (OFString*)XMPP_genNonce;
- (uint8_t*)XMPP_HMACWithKey: (OFDataArray*)key
			data: (OFDataArray*)data;
- (OFDataArray*)XMPP_hiWithData: (OFDataArray *)str
			   salt: (OFDataArray *)salt_
		 iterationCount: (intmax_t)i;
@end

Modified src/XMPPSCRAMAuth.m from [0de8efa633] to [a71d5f22e6].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#define HMAC_IPAD 0x36
#define HMAC_OPAD 0x5c

#ifndef HAVE_ARC4RANDOM_UNIFORM
extern uint32_t arc4random_uniform(uint32_t);
#endif

@interface XMPPSCRAMAuth ()
- (OFString*)XMPP_genNonce;
- (uint8_t*)XMPP_HMACWithKey: (OFDataArray*)key
			data: (OFDataArray*)data;
- (OFDataArray*)XMPP_hiWithData: (OFDataArray *)str
			   salt: (OFDataArray *)salt_
		 iterationCount: (intmax_t)i;
@end

@implementation XMPPSCRAMAuth
+ SCRAMAuthWithAuthcid: (OFString*)authcid
	      password: (OFString*)password
		  hash: (Class)hash;
{
	return [[[self alloc] initWithAuthcid: authcid
				     password: password







<
<
<
<
<
<
<
<
<







29
30
31
32
33
34
35









36
37
38
39
40
41
42
#define HMAC_IPAD 0x36
#define HMAC_OPAD 0x5c

#ifndef HAVE_ARC4RANDOM_UNIFORM
extern uint32_t arc4random_uniform(uint32_t);
#endif










@implementation XMPPSCRAMAuth
+ SCRAMAuthWithAuthcid: (OFString*)authcid
	      password: (OFString*)password
		  hash: (Class)hash;
{
	return [[[self alloc] initWithAuthcid: authcid
				     password: password
168
169
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
	size_t i;
	uint8_t *clientKey, *serverKey, *clientSignature;
	intmax_t iterCount;
	OFHash *hash;
	OFDataArray *ret, *authMessage, *tmpArray, *salt, *saltedPassword;
	OFString *tmpString, *sNonce;
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];


	enum {
		GOT_SNONCE, GOT_SALT, GOT_ITERCOUNT
	} got = 0;

	hash = [[[hashType alloc] init] autorelease];
	ret = [OFDataArray dataArrayWithItemSize: 1];
	authMessage = [OFDataArray dataArrayWithItemSize: 1];

	OFString *chal = [OFString stringWithCString: [challenge cArray]
					      length: [challenge count] *
						      [challenge itemSize]];


	for (OFString *comp in [chal componentsSeparatedByString: @","]) {

		OFString *entry = [comp substringFromIndex: 2
						   toIndex: [comp length]];

		if ([comp hasPrefix: @"r="]) {
			if (![entry hasPrefix: cNonce])
				@throw [XMPPAuthFailedException
				    newWithClass: isa







>
>












>
|
>







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
184
185
186
187
188
189
	size_t i;
	uint8_t *clientKey, *serverKey, *clientSignature;
	intmax_t iterCount;
	OFHash *hash;
	OFDataArray *ret, *authMessage, *tmpArray, *salt, *saltedPassword;
	OFString *tmpString, *sNonce;
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFEnumerator *enumerator;
	OFString *comp;
	enum {
		GOT_SNONCE, GOT_SALT, GOT_ITERCOUNT
	} got = 0;

	hash = [[[hashType alloc] init] autorelease];
	ret = [OFDataArray dataArrayWithItemSize: 1];
	authMessage = [OFDataArray dataArrayWithItemSize: 1];

	OFString *chal = [OFString stringWithCString: [challenge cArray]
					      length: [challenge count] *
						      [challenge itemSize]];

	enumerator =
	    [[chal componentsSeparatedByString: @","] objectEnumerator];
	while ((comp = [enumerator nextObject]) != nil) {
		OFString *entry = [comp substringFromIndex: 2
						   toIndex: [comp length]];

		if ([comp hasPrefix: @"r="]) {
			if (![entry hasPrefix: cNonce])
				@throw [XMPPAuthFailedException
				    newWithClass: isa
369
370
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
428
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFDataArray *k = [OFDataArray dataArrayWithItemSize: 1];
	size_t i, kSize, blockSize = [hashType blockSize];
	uint8_t *kCArray, *kI = NULL, *kO = NULL;
	OFHash *hash;

	if (key.itemSize * key.count > blockSize) {
		hash = [[[hashType alloc] init] autorelease];
		[hash updateWithBuffer: [key cArray]
				ofSize: key.itemSize * key.count];
		[k addNItems: [hashType digestSize]
		  fromCArray: [hash digest]];
	} else
		[k addNItems: key.itemSize * key.count
		  fromCArray: [key cArray]];

	@try {
		kI = [self allocMemoryWithSize: blockSize * sizeof(uint8_t)];
		memset(kI, HMAC_IPAD, blockSize * sizeof(uint8_t));

		kO = [self allocMemoryWithSize: blockSize * sizeof(uint8_t)];
		memset(kO, HMAC_OPAD, blockSize * sizeof(uint8_t));

		kCArray = [k cArray];
		kSize = k.count;
		for (i = 0; i < kSize; i++) {
			kI[i] ^= kCArray[i];
			kO[i] ^= kCArray[i];
		}

		k = [OFDataArray dataArrayWithItemSize: 1];
		[k addNItems: blockSize
		  fromCArray: kI];
		[k addNItems: data.itemSize * data.count
		  fromCArray: [data cArray]];

		hash = [[[hashType alloc] init] autorelease];
		[hash updateWithBuffer: [k cArray]
				ofSize: k.count];
		k = [OFDataArray dataArrayWithItemSize: 1];
		[k addNItems: blockSize
		  fromCArray: kO];
		[k addNItems: [hashType digestSize]
		   fromCArray: [hash digest]];
	} @finally {
		[self freeMemory: kI];
		[self freeMemory: kO];
	}

	hash = [[[hashType alloc] init] autorelease];
	[hash updateWithBuffer: [k cArray]
			ofSize: k.count];

	[hash retain];
	[pool release];

	return [hash digest];
}








|


|



|










|








|




|












|







364
365
366
367
368
369
370
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
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFDataArray *k = [OFDataArray dataArrayWithItemSize: 1];
	size_t i, kSize, blockSize = [hashType blockSize];
	uint8_t *kCArray, *kI = NULL, *kO = NULL;
	OFHash *hash;

	if ([key itemSize] * [key count] > blockSize) {
		hash = [[[hashType alloc] init] autorelease];
		[hash updateWithBuffer: [key cArray]
				ofSize: [key itemSize] * [key count]];
		[k addNItems: [hashType digestSize]
		  fromCArray: [hash digest]];
	} else
		[k addNItems: [key itemSize] * [key count]
		  fromCArray: [key cArray]];

	@try {
		kI = [self allocMemoryWithSize: blockSize * sizeof(uint8_t)];
		memset(kI, HMAC_IPAD, blockSize * sizeof(uint8_t));

		kO = [self allocMemoryWithSize: blockSize * sizeof(uint8_t)];
		memset(kO, HMAC_OPAD, blockSize * sizeof(uint8_t));

		kCArray = [k cArray];
		kSize = [k count];
		for (i = 0; i < kSize; i++) {
			kI[i] ^= kCArray[i];
			kO[i] ^= kCArray[i];
		}

		k = [OFDataArray dataArrayWithItemSize: 1];
		[k addNItems: blockSize
		  fromCArray: kI];
		[k addNItems: [data itemSize] * [data count]
		  fromCArray: [data cArray]];

		hash = [[[hashType alloc] init] autorelease];
		[hash updateWithBuffer: [k cArray]
				ofSize: [k count]];
		k = [OFDataArray dataArrayWithItemSize: 1];
		[k addNItems: blockSize
		  fromCArray: kO];
		[k addNItems: [hashType digestSize]
		   fromCArray: [hash digest]];
	} @finally {
		[self freeMemory: kI];
		[self freeMemory: kO];
	}

	hash = [[[hashType alloc] init] autorelease];
	[hash updateWithBuffer: [k cArray]
			ofSize: [k count]];

	[hash retain];
	[pool release];

	return [hash digest];
}

Modified src/XMPPStanza.h from [b70c08218e] to [1377ddf174].

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
@class XMPPJID;

/**
 * \brief A class describing an XMPP Stanza.
 */
@interface XMPPStanza: OFXMLElement
{
	/// The value of the stanza's from attribute
	XMPPJID *from;
	/// The value of the stanza's to attribute
	XMPPJID *to;
	/// The value of the stanza's type attribute
	OFString *type;
	/// The value of the stanza's id attribute
	OFString *ID;
}



@property (copy) XMPPJID *from;

@property (copy) XMPPJID *to;

@property (copy) OFString *type;

@property (copy) OFString *ID;


/**
 * Creates a new autoreleased XMPPStanza with the specified name.
 *
 * \param name The stanza's name (one of iq, message or presence)
 * \return A new autoreleased XMPPStanza
 */







<

<

<

<



>
>

>

>

>

>







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
@class XMPPJID;

/**
 * \brief A class describing an XMPP Stanza.
 */
@interface XMPPStanza: OFXMLElement
{

	XMPPJID *from;

	XMPPJID *to;

	OFString *type;

	OFString *ID;
}

#ifdef OF_HAVE_PROPERTIES
/// The value of the stanza's from attribute
@property (copy) XMPPJID *from;
/// The value of the stanza's to attribute
@property (copy) XMPPJID *to;
/// The value of the stanza's type attribute
@property (copy) OFString *type;
/// The value of the stanza's id attribute
@property (copy) OFString *ID;
#endif

/**
 * Creates a new autoreleased XMPPStanza with the specified name.
 *
 * \param name The stanza's name (one of iq, message or presence)
 * \return A new autoreleased XMPPStanza
 */
137
138
139
140
141
142
143









144
/**
 * Initializes an already allocated XMPPStanza based on a OFXMLElement
 *
 * \param elem The element to base the XMPPStanza on
 * \return A initialized XMPPStanza
 */
- initWithElement: (OFXMLElement*)elem;









@end







>
>
>
>
>
>
>
>
>

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
 * Initializes an already allocated XMPPStanza based on a OFXMLElement
 *
 * \param elem The element to base the XMPPStanza on
 * \return A initialized XMPPStanza
 */
- initWithElement: (OFXMLElement*)elem;

- (void)setFrom: (XMPPJID*)from;
- (XMPPJID*)from;
- (void)setTo: (XMPPJID*)to;
- (XMPPJID*)to;
- (void)setType: (OFString*)type;
- (OFString*)type;
- (void)setID: (OFString*)ID;
- (OFString*)ID;
@end

Modified src/XMPPStanza.m from [9926f881b4] to [3e896b294c].

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
129
130
131
132

133
134
135
136
137
138
139
		if (![name_ isEqual: @"iq"] && ![name_ isEqual: @"message"] &&
		    ![name_ isEqual: @"presence"])
			@throw [OFInvalidArgumentException newWithClass: isa
							       selector: _cmd];

		[self setDefaultNamespace: @"jabber:client"];

		if (type_)
			[self setType: type_];

		if (ID_)
			[self setID: ID_];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithElement: (OFXMLElement*)elem
{
	self = [super initWithName: elem.name
			 namespace: elem.namespace];

	@try {

		for (OFXMLAttribute *attr in elem.attributes) {




			if ([attr.name isEqual: @"from"])
				[self setFrom: [XMPPJID JIDWithString:
				    [attr stringValue]]];
			else if ([attr.name isEqual: @"to"])
				[self setTo: [XMPPJID JIDWithString:
				    [attr stringValue]]];
			else if ([attr.name isEqual: @"type"])
				[self setType: [attr stringValue]];
			else if ([attr.name isEqual: @"id"])
				[self setID: [attr stringValue]];
			else
				[self addAttribute: attr];
		}

		for (OFXMLElement *el in elem.children)

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

	return self;







|


|











|
|


>
|
>
>
>
>
|


|


|

|





|
>







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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
		if (![name_ isEqual: @"iq"] && ![name_ isEqual: @"message"] &&
		    ![name_ isEqual: @"presence"])
			@throw [OFInvalidArgumentException newWithClass: isa
							       selector: _cmd];

		[self setDefaultNamespace: @"jabber:client"];

		if (type_ != nil)
			[self setType: type_];

		if (ID_ != nil)
			[self setID: ID_];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithElement: (OFXMLElement*)elem
{
	self = [super initWithName: [elem name]
			 namespace: [elem namespace]];

	@try {
		OFEnumerator *enumerator;
		OFXMLAttribute *attr;
		OFXMLElement *el;

		enumerator = [[elem attributes] objectEnumerator];
		while ((attr = [enumerator nextObject]) != nil) {
			if ([[attr name] isEqual: @"from"])
				[self setFrom: [XMPPJID JIDWithString:
				    [attr stringValue]]];
			else if ([[attr name] isEqual: @"to"])
				[self setTo: [XMPPJID JIDWithString:
				    [attr stringValue]]];
			else if ([[attr name] isEqual: @"type"])
				[self setType: [attr stringValue]];
			else if ([[attr name] isEqual: @"id"])
				[self setID: [attr stringValue]];
			else
				[self addAttribute: attr];
		}

		enumerator = [[elem children] objectEnumerator];
		while ((el = [enumerator nextObject]) != nil)
			[self addChild: el];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
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
184
185
186
187
	from = [from_ copy];
	[old release];

	[self removeAttributeForName: @"from"];

	if (from_ != nil)
		[self addAttributeWithName: @"from"
			       stringValue: from_.fullJID];
}

- (XMPPJID*)from
{
	return [[from copy] autorelease];
}

- (void)setTo: (XMPPJID*)to_
{
	XMPPJID *old = to;
	to = [to_ copy];
	[old release];

	[self removeAttributeForName: @"to"];

	if (to_ != nil)
		[self addAttributeWithName: @"to"
			       stringValue: to_.fullJID];
}

- (XMPPJID*)to
{
	return [[to copy] autorelease];
}








|

















|







161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
	from = [from_ copy];
	[old release];

	[self removeAttributeForName: @"from"];

	if (from_ != nil)
		[self addAttributeWithName: @"from"
			       stringValue: [from_ fullJID]];
}

- (XMPPJID*)from
{
	return [[from copy] autorelease];
}

- (void)setTo: (XMPPJID*)to_
{
	XMPPJID *old = to;
	to = [to_ copy];
	[old release];

	[self removeAttributeForName: @"to"];

	if (to_ != nil)
		[self addAttributeWithName: @"to"
			       stringValue: [to_ fullJID]];
}

- (XMPPJID*)to
{
	return [[to copy] autorelease];
}

Modified tests/test.m from [fff72eb7c7] to [4765f2a59a].

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
95
96
97
98
99
100
101
102
103
104
#import "XMPPJID.h"
#import "XMPPStanza.h"
#import "XMPPIQ.h"
#import "XMPPMessage.h"
#import "XMPPPresence.h"
#import "XMPPRoster.h"

@interface AppDelegate: OFObject <OFApplicationDelegate, XMPPConnectionDelegate>



@end

OF_APPLICATION_DELEGATE(AppDelegate)

@implementation AppDelegate
- (void)applicationDidFinishLaunching
{
	XMPPConnection *conn;
	OFArray *arguments = [OFApplication arguments];

	XMPPPresence *pres = [XMPPPresence presence];
	[pres addShow: @"chat"];
	[pres addStatus: @"Bored"];
	[pres addPriority: 20];
	pres.to = [XMPPJID JIDWithString: @"alice@example.com"];
	pres.from = [XMPPJID JIDWithString: @"bob@example.org"];
	assert([[pres stringValue] isEqual: @"<presence to='alice@example.com' "
	    @"from='bob@example.org'><show>chat</show>"
	    @"<status>Bored</status><priority>20</priority>"
	    @"</presence>"]);

	XMPPMessage *msg = [XMPPMessage messageWithType: @"chat"];
	[msg addBody: @"Hello everyone"];
	msg.to = [XMPPJID JIDWithString: @"jdev@conference.jabber.org"];
	msg.from = [XMPPJID JIDWithString: @"alice@example.com"];
	assert([[msg stringValue] isEqual: @"<message type='chat' "
	    @"to='jdev@conference.jabber.org' "
	    @"from='alice@example.com'><body>Hello everyone</body>"
	    @"</message>"]);

	XMPPIQ *iq = [XMPPIQ IQWithType: @"set" ID: @"128"];
	iq.to = [XMPPJID JIDWithString: @"juliet@capulet.lit"];
	iq.from = [XMPPJID JIDWithString: @"romeo@montague.lit"];
	assert([[iq stringValue] isEqual: @"<iq type='set' id='128' "
	    @"to='juliet@capulet.lit' "
	    @"from='romeo@montague.lit'/>"]);

	OFXMLElement *elem = [OFXMLElement elementWithName: @"iq"];
	[elem addAttributeWithName: @"from" stringValue: @"bob@localhost"];

	[elem addAttributeWithName: @"to" stringValue: @"alice@localhost"];

	[elem addAttributeWithName: @"type" stringValue: @"get"];

	[elem addAttributeWithName: @"id" stringValue: @"42"];

	XMPPStanza *stanza = [XMPPStanza stanzaWithElement: elem];
	assert([[elem stringValue] isEqual: [stanza stringValue]]);
	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.delegate = self;

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

	[conn setServer: [arguments objectAtIndex: 0]];
	[conn setUsername: [arguments objectAtIndex: 1]];
	[conn setPassword: [arguments objectAtIndex: 2]];
	[conn setResource: @"ObjXMPP"];
	[conn setUseTLS: NO];

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







|
>
>
>














|
|







|
|






|
|





|
>
|
>
|
>
|
>



|
|


|

|








<







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
95
96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
#import "XMPPJID.h"
#import "XMPPStanza.h"
#import "XMPPIQ.h"
#import "XMPPMessage.h"
#import "XMPPPresence.h"
#import "XMPPRoster.h"

@interface AppDelegate: OFObject
#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
    <OFApplicationDelegate, XMPPConnectionDelegate>
#endif
@end

OF_APPLICATION_DELEGATE(AppDelegate)

@implementation AppDelegate
- (void)applicationDidFinishLaunching
{
	XMPPConnection *conn;
	OFArray *arguments = [OFApplication arguments];

	XMPPPresence *pres = [XMPPPresence presence];
	[pres addShow: @"chat"];
	[pres addStatus: @"Bored"];
	[pres addPriority: 20];
	[pres setTo: [XMPPJID JIDWithString: @"alice@example.com"]];
	[pres setFrom: [XMPPJID JIDWithString: @"bob@example.org"]];
	assert([[pres stringValue] isEqual: @"<presence to='alice@example.com' "
	    @"from='bob@example.org'><show>chat</show>"
	    @"<status>Bored</status><priority>20</priority>"
	    @"</presence>"]);

	XMPPMessage *msg = [XMPPMessage messageWithType: @"chat"];
	[msg addBody: @"Hello everyone"];
	[msg setTo: [XMPPJID JIDWithString: @"jdev@conference.jabber.org"]];
	[msg setFrom: [XMPPJID JIDWithString: @"alice@example.com"]];
	assert([[msg stringValue] isEqual: @"<message type='chat' "
	    @"to='jdev@conference.jabber.org' "
	    @"from='alice@example.com'><body>Hello everyone</body>"
	    @"</message>"]);

	XMPPIQ *iq = [XMPPIQ IQWithType: @"set" ID: @"128"];
	[iq setTo: [XMPPJID JIDWithString: @"juliet@capulet.lit"]];
	[iq setFrom: [XMPPJID JIDWithString: @"romeo@montague.lit"]];
	assert([[iq stringValue] isEqual: @"<iq type='set' id='128' "
	    @"to='juliet@capulet.lit' "
	    @"from='romeo@montague.lit'/>"]);

	OFXMLElement *elem = [OFXMLElement elementWithName: @"iq"];
	[elem addAttributeWithName: @"from"
		       stringValue: @"bob@localhost"];
	[elem addAttributeWithName: @"to"
		       stringValue: @"alice@localhost"];
	[elem addAttributeWithName: @"type"
		       stringValue: @"get"];
	[elem addAttributeWithName: @"id"
		       stringValue: @"42"];
	XMPPStanza *stanza = [XMPPStanza stanzaWithElement: elem];
	assert([[elem stringValue] isEqual: [stanza stringValue]]);
	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];

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

	[conn setServer: [arguments objectAtIndex: 0]];
	[conn setUsername: [arguments objectAtIndex: 1]];
	[conn setPassword: [arguments objectAtIndex: 2]];
	[conn setResource: @"ObjXMPP"];


	[conn connect];
	@try {
		[conn handleConnection];
	} @catch (id e) {
		of_log(@"%@", e);
	}
116
117
118
119
120
121
122


123
124

125
126
127
128
129
130
131
132
133
134

	[conn requestRoster];
}

- (void)connectionDidReceiveRoster :(XMPPConnection*)conn
{
	XMPPPresence *pres;



	of_log(@"Got roster! Groups: %@", conn.roster.groups);

	for (OFString *group in conn.roster.groups)
		of_log(@"Group %@: %@", group,
		    [conn.roster rosterItemsInGroup: group]);

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

	[conn sendStanza: pres];
}







>
>

|
>
|

|







122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

	[conn requestRoster];
}

- (void)connectionDidReceiveRoster :(XMPPConnection*)conn
{
	XMPPPresence *pres;
	OFEnumerator *enumerator;
	OFString *group;

	of_log(@"Got roster! Groups: %@", [[conn roster] groups]);
	enumerator = [[[conn roster] groups] objectEnumerator];
	while ((group = [enumerator nextObject]) != nil)
		of_log(@"Group %@: %@", group,
		    [[conn roster] rosterItemsInGroup: group]);

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

	[conn sendStanza: pres];
}