ObjXMPP  Check-in [1d031d8de7]

Overview
Comment:Make status/show/priority of XMPPPresence properties
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1d031d8de74e2bf99116bd6194c9ec7e43ff097f3681333a98d1a8093d3b2282
User & Date: florob@babelmonkeys.de on 2013-01-08 23:36:21
Other Links: manifest | tags
Context
2013-01-09
18:32
Remove redundant IDNAToASCII check-in: 9532fc55fb user: florob@babelmonkeys.de tags: trunk
2013-01-08
23:36
Make status/show/priority of XMPPPresence properties check-in: 1d031d8de7 user: florob@babelmonkeys.de tags: trunk
2013-01-06
18:42
Implement isEqual: for XMPPJID check-in: 134ef1fe81 user: florob@babelmonkeys.de tags: trunk
Changes

Modified src/XMPPPresence.h from [507e41c1d1] to [308cf467b3].

23
24
25
26
27
28
29













30
31
32
33
34
35
36

#import "XMPPStanza.h"

/**
 * \brief A class describing a presence stanza.
 */
@interface XMPPPresence: XMPPStanza













/**
 * \brief Creates a new autoreleased XMPPPresence.
 *
 * \return A new autoreleased XMPPPresence
 */
+ presence;








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







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 "XMPPStanza.h"

/**
 * \brief A class describing a presence stanza.
 */
@interface XMPPPresence: XMPPStanza
{
/// \cond internal
	OFString *status;
	OFString *show;
	OFNumber *priority;
/// \endcond
}
#ifdef OF_HAVE_PROPERTIES
@property (copy) OFString *status;
@property (copy) OFString *show;
@property (copy) OFNumber *priority;
#endif

/**
 * \brief Creates a new autoreleased XMPPPresence.
 *
 * \return A new autoreleased XMPPPresence
 */
+ presence;

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
 * \param ID The value for the stanza's id attribute
 * \return A initialized XMPPPresence
 */
- initWithType: (OFString*)type
	    ID: (OFString*)ID;

/**
 * \brief Adds a show element to the presence stanza.
 *
 * \param show The text content of the show element
 */
- (void)addShow: (OFString*)show;

/**





 * \brief Adds a status element to the presence stanza.


 *
 * \param status The text content of the status element
 */
- (void)addStatus: (OFString*)status;

/**





 * \brief Adds a priority element to the presence stanza.


 *







 * \param priority The text content of the priority element
 */
- (void)addPriority: (int8_t)priority;
@end







|



|


>
>
>
>
>
|
>
>



|


>
>
>
>
>
|
>
>

>
>
>
>
>
>
>
|

|

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
 * \param ID The value for the stanza's id attribute
 * \return A initialized XMPPPresence
 */
- initWithType: (OFString*)type
	    ID: (OFString*)ID;

/**
 * \brief Sets/Adds the show element of the presence stanza.
 *
 * \param show The text content of the show element
 */
- (void)setShow: (OFString*)show;

/**
 * \brief Returns the text content of the show element of the presence stanza.
 *
 * \return The text content of the show element of the presence stanza.
 */
- (OFString*)show;

/**
 * \brief Sets/Adds the status element of the presence stanza.
 *
 * \param status The text content of the status element
 */
- (void)setStatus: (OFString*)status;

/**
 * \brief Returns the text content of the status element of the presence stanza.
 *
 * \return The text content of the status element of the presence stanza.
 */
- (OFString*)status;

/**
 * \brief Sets/Adds the priority element of the presence stanza.
 *
 * \param priority The numeric content of the priority element
 */
- (void)setPriority: (OFNumber*)priority;

/**
 * \brief Returns the numeric content of the priority element of the presence stanza.
 *
 * \return The numeric content of the priority element of the presence stanza.
 */
- (OFNumber*)priority;
@end

Modified src/XMPPPresence.m from [0949a5ed60] to [b2990bd4cd].

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
- initWithType: (OFString*)type_
	    ID: (OFString*)ID_
{
	return [super initWithName: @"presence"
			      type: type_
				ID: ID_];
}










- (OFString*)type
{
	if (type == nil)
		return @"available";

	return [[type copy] autorelease];
}

- (void)addShow: (OFString*)show
{







	[self addChild: [OFXMLElement elementWithName: @"show"
					    namespace: XMPP_NS_CLIENT
					  stringValue: show]];
}








- (void)addStatus: (OFString*)status
{







	[self addChild: [OFXMLElement elementWithName: @"status"
					    namespace: XMPP_NS_CLIENT
					  stringValue: status]];
}


- (void)addPriority: (int8_t)priority

{



















	OFString* prio = [OFString stringWithFormat: @"%" @PRId8, priority];
	[self addChild: [OFXMLElement elementWithName: @"priority"
					    namespace: XMPP_NS_CLIENT
					  stringValue: prio]];







}
@end







>
>
>
>
>
>
>
>
>









|

>
>
>
>
>
>
>
|
|
|
|
>
|
>
>
>
>
>
>
|

>
>
>
>
>
>
>
|
|
|
|
>
|
|
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|


|
>
>
>
>
>
>
>


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
- initWithType: (OFString*)type_
	    ID: (OFString*)ID_
{
	return [super initWithName: @"presence"
			      type: type_
				ID: ID_];
}

- (void)dealloc
{
	[status release];
	[show release];
	[priority release];

	[super dealloc];
}

- (OFString*)type
{
	if (type == nil)
		return @"available";

	return [[type copy] autorelease];
}

- (void)setShow: (OFString*)show_
{
	OFXMLElement *oldShow = [self elementForName: @"show"
					   namespace: XMPP_NS_CLIENT];

	if (oldShow != nil)
		[self removeChild: oldShow];

	if (show_ != nil)
		[self addChild: [OFXMLElement elementWithName: @"show"
						    namespace: XMPP_NS_CLIENT
						  stringValue: show_]];

	OF_SETTER(show, show_, YES, 1);
}

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

- (void)setStatus: (OFString*)status_
{
	OFXMLElement *oldStatus = [self elementForName: @"status"
					     namespace: XMPP_NS_CLIENT];

	if (oldStatus != nil)
		[self removeChild: oldStatus];

	if (status_ != nil)
		[self addChild: [OFXMLElement elementWithName: @"status"
						    namespace: XMPP_NS_CLIENT
						  stringValue: status_]];

	OF_SETTER(status, status_, YES, 1);
}

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

- (void)setPriority: (OFNumber*)priority_
{
	intmax_t prio = [priority_ intMaxValue];

	if ((prio < -128) || (prio > 127))
		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]
			      selector: _cmd];

	OFXMLElement *oldPriority = [self elementForName: @"priority"
					       namespace: XMPP_NS_CLIENT];

	if (oldPriority != nil)
		[self removeChild: oldPriority];

	OFString* priority_s =
	    [OFString stringWithFormat: @"%" @PRId8, [priority_ int8Value]];
	[self addChild: [OFXMLElement elementWithName: @"priority"
					    namespace: XMPP_NS_CLIENT
					  stringValue: priority_s]];

	OF_SETTER(priority, priority_, YES, 1);
}

- (OFString*)priority
{
	return [[priority copy] autorelease];
}
@end

Modified tests/test.m from [274beaa27a] to [f57acb5efb].

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

@implementation AppDelegate
- (void)applicationDidFinishLaunching
{
	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 XMLString] isEqual: @"<presence to='alice@example.com' "
	    @"from='bob@example.org'><show>chat</show>"
	    @"<status>Bored</status><priority>20</priority>"
	    @"</presence>"]);








|
|
|







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

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

	XMPPPresence *pres = [XMPPPresence presence];
	[pres setShow: @"chat"];
	[pres setStatus: @"Bored"];
	[pres setPriority: [OFNumber numberWithInt8: 20]];
	[pres setTo: [XMPPJID JIDWithString: @"alice@example.com"]];
	[pres setFrom: [XMPPJID JIDWithString: @"bob@example.org"]];
	assert([[pres XMLString] isEqual: @"<presence to='alice@example.com' "
	    @"from='bob@example.org'><show>chat</show>"
	    @"<status>Bored</status><priority>20</priority>"
	    @"</presence>"]);

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
- (void)rosterWasReceived: (XMPPRoster*)roster_
{
	XMPPPresence *pres;

	of_log(@"Got roster: %@", [roster_ rosterItems]);

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

	[conn sendStanza: pres];

#ifdef OF_HAVE_BLOCKS
	XMPPIQ *iq = [XMPPIQ IQWithType: @"get"
				     ID: [conn generateStanzaID]];
	[iq addChild: [OFXMLElement elementWithName: @"ping"







|
|







150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
- (void)rosterWasReceived: (XMPPRoster*)roster_
{
	XMPPPresence *pres;

	of_log(@"Got roster: %@", [roster_ rosterItems]);

	pres = [XMPPPresence presence];
	[pres setPriority: [OFNumber numberWithInt8: 10]];
	[pres setStatus: @"ObjXMPP test is working!"];

	[conn sendStanza: pres];

#ifdef OF_HAVE_BLOCKS
	XMPPIQ *iq = [XMPPIQ IQWithType: @"get"
				     ID: [conn generateStanzaID]];
	[iq addChild: [OFXMLElement elementWithName: @"ping"