ObjXMPP  Check-in [e5d6fa6802]

Overview
Comment:Use XMPPJID for from and to.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e5d6fa68020ebf2df1837713b756ba5efe3a1a11aa84eda181f5531cb1982dd4
User & Date: js on 2011-02-19 16:40:41
Other Links: manifest | tags
Context
2011-02-19
22:17
Adapt tests for checking a stanza's JID check-in: 8402175d15 user: florob@babelmonkeys.de tags: trunk
16:40
Use XMPPJID for from and to. check-in: e5d6fa6802 user: js tags: trunk
16:38
Make XMPPJID conform to OFCopying. check-in: 58db21b120 user: js tags: trunk
Changes

Modified src/XMPPStanza.h from [55abb9bbde] to [b70c08218e].

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
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







+
+






-
+

-
+






-
-
+
+







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

@class XMPPJID;

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

@property (copy) OFString *from;
@property (copy) OFString *to;
@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)

Modified src/XMPPStanza.m from [328a61beaa] to [e5a3313b65].

18
19
20
21
22
23
24

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







+







 * 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 "XMPPStanza.h"
#import "XMPPJID.h"

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

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
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







-
-
-
-
+

+
-
+

+
-
+








-
+



















-
+

-
+





-
+


-
+

-
+





-
+




-
+








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

	@try {
		OFXMLAttribute *attr;
		OFXMLElement *el;

		for (attr in elem.attributes) {
		for (OFXMLAttribute *attr in elem.attributes) {
			if ([attr.name isEqual: @"from"])
				[self setFrom: [XMPPJID JIDWithString:
				[self setFrom: [attr stringValue]];
				    [attr stringValue]]];
			else if ([attr.name isEqual: @"to"])
				[self setTo: [XMPPJID JIDWithString:
				[self setTo: [attr stringValue]];
				    [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 (el in elem.children)
		for (OFXMLElement *el in elem.children)
			[self addChild: el];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

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

	[super dealloc];
}

- (void)setFrom: (OFString*)from_
- (void)setFrom: (XMPPJID*)from_
{
	OFString* old = from;
	XMPPJID *old = from;
	from = [from_ copy];
	[old release];

	[self removeAttributeForName: @"from"];
	[self addAttributeWithName: @"from"
		       stringValue: from_];
		       stringValue: from_.fullJID];
}

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

	[self removeAttributeForName: @"to"];
	[self addAttributeWithName: @"to"
		       stringValue: to];
		       stringValue: to_.fullJID];
}

- (void)setType: (OFString*)type_
{
	OFString* old = type;
	OFString *old = type;
	type = [type_ copy];
	[old release];

	[self removeAttributeForName: @"type"];
	[self addAttributeWithName: @"type"
		       stringValue: type];
}

Modified tests/test.m from [a9499ccb3a] to [0d992352d5].

22
23
24
25
26
27
28

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







+







 */

#include <assert.h>

#import <ObjFW/ObjFW.h>

#import "XMPPConnection.h"
#import "XMPPJID.h"
#import "XMPPStanza.h"
#import "XMPPIQ.h"
#import "XMPPMessage.h"
#import "XMPPPresence.h"

@interface AppDelegate: OFObject
{
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
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







-
-
+
+







-
-
+
+






-
-
+
+







{
	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";
	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 = @"jdev@conference.jabber.org";
	msg.from = @"alice@example.com";
	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 = @"juliet@capulet.lit";
	iq.from = @"romeo@montague.lit";
	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"];