ObjXMPP  Check-in [109b15316d]

Overview
Comment:Add stanza classes XMPPStanza, XMPPIQ, XMPPMessage and XMPPPresence
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 109b15316d89ab7714ce3997c438846918b4f223f981b260f8fd5c7dad3ab035
User & Date: florob@babelmonkeys.de on 2011-02-10 02:54:08
Other Links: manifest | tags
Context
2011-02-10
15:36
Handle resource binding check-in: 28b1848edc user: florob@babelmonkeys.de tags: trunk
02:54
Add stanza classes XMPPStanza, XMPPIQ, XMPPMessage and XMPPPresence check-in: 109b15316d user: florob@babelmonkeys.de tags: trunk
2011-02-08
19:45
Initial commit. check-in: acb2c5cbf0 user: js tags: trunk
Changes

Modified XMPPConnection.m from [376ec31f52] to [65b3fffac0].

1

2
3
4
5
6
7
8
#import "XMPPConnection.h"


#define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind"
#define NS_CLIENT @"jabber:client"
#define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl"
#define NS_STREAM @"http://etherx.jabber.org/streams"

@implementation XMPPConnection

>







1
2
3
4
5
6
7
8
9
#import "XMPPConnection.h"
#import "XMPPStanza.h"

#define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind"
#define NS_CLIENT @"jabber:client"
#define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl"
#define NS_STREAM @"http://etherx.jabber.org/streams"

@implementation XMPPConnection
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
	    [message stringByBase64Encoding]]];

	[sock writeString: [authTag stringValue]];
}

- (void)_sendResourceBind
{
	OFXMLElement *iq = [OFXMLElement elementWithName: @"iq"];
	[iq addAttributeWithName: @"type" stringValue: @"set"];
	[iq addChild: [OFXMLElement elementWithName: @"bind"
					  namespace: NS_BIND]];

	[sock writeString: [iq stringValue]];
}

- (void)_handleFeatures: (OFXMLElement*)elem







<
|







132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
	    [message stringByBase64Encoding]]];

	[sock writeString: [authTag stringValue]];
}

- (void)_sendResourceBind
{

	XMPPIQ *iq = [XMPPIQ IQWithType: @"set" ID: @"bind0"];
	[iq addChild: [OFXMLElement elementWithName: @"bind"
					  namespace: NS_BIND]];

	[sock writeString: [iq stringValue]];
}

- (void)_handleFeatures: (OFXMLElement*)elem

Added XMPPStanza.h version [ea5e90b255].



















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
#import <ObjFW/ObjFW.h>

@interface XMPPStanza: OFXMLElement
{
	OFString *from;
	OFString *to;
	OFString *type;
	OFString *ID;
}

@property (copy) OFString *from;
@property (copy) OFString *to;
@property (copy) OFString *type;
@property (copy) OFString *ID;

+ stanzaWithName: (OFString*)name;
+ stanzaWithElement: (OFXMLElement*)elem;

- initWithName: (OFString*)name;
- initWithElement: (OFXMLElement*)elem;
@end

@interface XMPPIQ: XMPPStanza
{
}

+ IQWithType: (OFString*)type_
	  ID: (OFString*)ID_;
@end

@interface XMPPMessage: XMPPStanza
{
}

+ message;
+ messageWithID: (OFString*)ID_;
+ messageWithType: (OFString*)type_;
+ messageWithType: (OFString*)type_
	       ID: (OFString*)ID_;

- (void)addBody: (OFString*)body;
@end

@interface XMPPPresence: XMPPStanza
{
}

+ presence;
+ presenceWithID: (OFString*)ID_;
+ presenceWithType: (OFString*)type_;
+ presenceWithType: (OFString*)type_
		ID: (OFString*)ID_;

- (void)addShow: (OFString*)show;
- (void)addStatus: (OFString*)status;
- (void)addPriority: (char)priority;
@end

Added XMPPStanza.m version [aa9b33c527].











































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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
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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#import "XMPPStanza.h"

@implementation XMPPStanza
@synthesize from;
@synthesize to;
@synthesize type;
@synthesize ID;

+ stanzaWithName: (OFString*)name
{
	return [[[self alloc] initWithName: name] autorelease];
}

+ stanzaWithElement: (OFXMLElement*)elem {
	return [[[self alloc] initWithElement: elem] autorelease];
}

- initWithName: (OFString*)name_
{
	if (!([name_ isEqual: @"iq"] ||
	      [name_ isEqual: @"message"] ||
	      [name_ isEqual: @"presence"]))
		of_log(@"Invalid stanza name!");

	self = [super initWithName: name_];
	[self setDefaultNamespace: @"jabber:client"];

	from = [[OFString alloc] init];
	to = [[OFString alloc] init];
	type = [[OFString alloc] init];
	ID = [[OFString alloc] init];

	return self;
}

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

	from = [[OFString alloc] init];
	to = [[OFString alloc] init];
	type = [[OFString alloc] init];
	ID = [[OFString alloc] init];

	OFXMLAttribute *attr;

	for (attr in elem.attributes) {
		if ([attr.name isEqual: @"from"]) {
			[self setFrom: [attr stringValue]];
		} else if ([attr.name isEqual: @"to"]) {
			[self setTo: [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];
		}
	}

	OFXMLElement *el;

	for (el in elem.children) {
		[self addChild: el];
	}

	return self;
}

- (void)dealloc
{
	[from release];
	[to release];
	[type release];
	[ID release];

	[super dealloc];
}

- (void)setFrom: (OFString*)from_
{
	OFString* old = from;
	from = [from_ copy];
	[old release];
	[self addAttributeWithName: @"from" stringValue: from_];
}

- (void)setTo: (OFString*)to_
{
	OFString* old = to;
	to = [to_ copy];
	[old release];
	[self addAttributeWithName: @"to" stringValue: to];
}

- (void)setType: (OFString*)type_
{
	OFString* old = type;
	type = [type_ copy];
	[old release];
	[self addAttributeWithName: @"type" stringValue: type];
}

- (void)setID: (OFString*)ID_
{
	OFString* old = ID;
	ID = [ID_ copy];
	[old release];
	[self addAttributeWithName: @"id" stringValue: ID];
}
@end

@implementation XMPPIQ
+ IQWithType: (OFString*)type_
	  ID: (OFString*)ID_
{
	if (!([type_ isEqual: @"get"] ||
	      [type_ isEqual: @"set"] ||
	      [type_ isEqual: @"result"] ||
	      [type_ isEqual: @"error"]))
		of_log(@"Invalid IQ type!");

	id ret;
	ret = [[[self alloc] initWithName: @"iq"] autorelease];
	[ret setType: type_];
	[ret setID: ID_];
	return ret;
}
@end

@implementation XMPPMessage
+ message
{
	return [self messageWithType: nil ID: nil];
}

+ messageWithID: (OFString*)ID_
{
	return [self messageWithType: nil ID: ID_];
}

+ messageWithType: (OFString*)type_
{
	return [self messageWithType: type_ ID: nil];
}

+ messageWithType: (OFString*)type_
	       ID: (OFString*)ID_
{
	id ret;
	ret = [[[self alloc] initWithName: @"message"] autorelease];
	if (type_)
		[ret setType: type_];
	if (ID_)
		[ret setID: ID_];
	return ret;
}

- (void)addBody: (OFString*)body
{
	[self addChild: [OFXMLElement elementWithName: @"body"
					  stringValue: body]];
}
@end

@implementation XMPPPresence
+ presence
{
	return [self presenceWithType: nil ID: nil];
}

+ presenceWithID: (OFString*)ID_
{
	return [self presenceWithType: nil ID: ID_];
}

+ presenceWithType: (OFString*)type_
{
	return [self presenceWithType: type_ ID: nil];
}

+ presenceWithType: (OFString*)type_
		ID: (OFString*)ID_
{
	id ret;
	ret = [[[self alloc] initWithName: @"presence"] autorelease];
	if (type_)
		[ret setType: type_];
	if (ID_)
		[ret setID: ID_];
	return ret;
}

- (void)addShow: (OFString*)show
{
	[self addChild: [OFXMLElement elementWithName: @"show"
					  stringValue: show]];
}

- (void)addStatus: (OFString*)status
{
	[self addChild: [OFXMLElement elementWithName: @"status"
					  stringValue: status]];
}

- (void)addPriority: (char)priority
{
	OFString* prio = [OFString stringWithFormat: @"%d", priority];
	[self addChild: [OFXMLElement elementWithName: @"priority"
					  stringValue: prio]];
}
@end

Added XMPPStanza.o version [00d9730d3b].

cannot compute difference between binary files

Modified test.m from [6897d0dd8c] to [3f14c4e76b].

1

2

3
4
5
6
7
8
9
10
11
12
13
14
15
16






































17
18
19
20
21
22
23
#include <ObjFW/ObjFW.h>

#import "XMPPConnection.h"


@interface AppDelegate: OFObject
{
	XMPPConnection *conn;
}
@end

OF_APPLICATION_DELEGATE(AppDelegate)

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







































	conn = [[XMPPConnection alloc] init];

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

|
>

>














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







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
#include <assert.h>
#import <ObjFW/ObjFW.h>
#import "XMPPConnection.h"
#import "XMPPStanza.h"

@interface AppDelegate: OFObject
{
	XMPPConnection *conn;
}
@end

OF_APPLICATION_DELEGATE(AppDelegate)

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

	XMPPPresence *pres = [XMPPPresence presence];
	[pres addShow: @"chat"];
	[pres addStatus: @"Bored"];
	[pres addPriority: 20];
	pres.to = @"alice@example.com";
	pres.from = @"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 = @"jdev@conference.jabber.org";
	msg.from = @"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 = @"juliet@capulet.lit";
	iq.from = @"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,
			stanza.to, stanza.type, stanza.ID]
			isEqual: @"bob@localhost, alice@localhost, get, 42"]));

	conn = [[XMPPConnection alloc] init];

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