ObjXMPP  Check-in [cce64dfcd6]

Overview
Comment:Prefix *all* IVars with _.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cce64dfcd66937ceacfeb8192c91a6ea4cd2df4cb7fe9bd4309a380cc5ebe543
User & Date: js on 2013-06-23 20:13:43
Other Links: manifest | tags
Context
2013-06-23
21:41
Use instancetype. check-in: 049768c6ae user: js tags: trunk
20:13
Prefix *all* IVars with _. check-in: cce64dfcd6 user: js tags: trunk
19:57
Get rid of BOOL. check-in: dd2c1286f9 user: js tags: trunk
Changes

Modified src/XMPPAuthenticator.h from [89cf5dd3d3] to [17c15c7939].

23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
23
24
25
26
27
28
29

30


31
32
33
34
35
36
37







-
+
-
-







#import <ObjFW/ObjFW.h>

/**
 * \brief A base class for classes implementing authentication mechanisms
 */
@interface XMPPAuthenticator: OFObject
{
	OFString *_authzid;
	OFString *_authzid, *_authcid, *_password;
	OFString *_authcid;
	OFString *_password;
}

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

Modified src/XMPPCallback.h from [8400224fd5] to [c4e54254ee].

22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44







-
+







-
+








#import <ObjFW/ObjFW.h>

@class XMPPConnection;
@class XMPPIQ;

#ifdef OF_HAVE_BLOCKS
typedef void(^xmpp_callback_block_t)(XMPPConnection*, XMPPIQ*);
typedef void (^xmpp_callback_block_t)(XMPPConnection*, XMPPIQ*);
#endif

@interface XMPPCallback: OFObject
{
	id _target;
	SEL _selector;
#ifdef OF_HAVE_BLOCKS
	xmpp_callback_block_t block;
	xmpp_callback_block_t _block;
#endif
}

#ifdef OF_HAVE_BLOCKS
+ callbackWithBlock: (xmpp_callback_block_t)callback;
- initWithBlock: (xmpp_callback_block_t)callback;
#endif

Modified src/XMPPCallback.m from [c850447926] to [55260bd7bb].

29
30
31
32
33
34
35
36

37
38
39
40
41

42
43
44
45
46
47
48
29
30
31
32
33
34
35

36
37
38
39
40

41
42
43
44
45
46
47
48







-
+




-
+







@implementation XMPPCallback
#ifdef OF_HAVE_BLOCKS
+ callbackWithBlock: (xmpp_callback_block_t)block
{
	return [[(XMPPCallback*)[self alloc] initWithBlock: block] autorelease];
}

- initWithBlock: (xmpp_callback_block_t)block_
- initWithBlock: (xmpp_callback_block_t)block
{
	self = [super init];

	@try {
		block = [block_ copy];
		_block = [block copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
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
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







-
+









-
-
+
+







	return self;
}

- (void)dealloc
{
	[_target release];
#ifdef OF_HAVE_BLOCKS
	[block release];
	[_block release];
#endif

	[super dealloc];
}

- (void)runWithIQ: (XMPPIQ*)iq
       connection: (XMPPConnection*)connection
{
#ifdef OF_HAVE_BLOCKS
	if (block != NULL)
		block(connection, iq);
	if (_block != NULL)
		_block(connection, iq);
	else
#endif
		[_target performSelector: _selector
			      withObject: connection
			      withObject: iq];
}
@end

Modified src/XMPPDiscoIdentity.h from [5d9f1df6e9] to [7a8984a7e1].

23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
23
24
25
26
27
28
29

30


31
32
33
34
35
36
37







-
+
-
-







#import <ObjFW/ObjFW.h>

/**
 * \brief A class describing a Service Discovery Identity
 */
@interface XMPPDiscoIdentity: OFObject <OFComparing>
{
	OFString *_category;
	OFString *_category, *_name, *_type;
	OFString *_name;
	OFString *_type;
}
#ifdef OF_HAVE_PROPERTIES
/// \brief The category of the identity
@property (readonly) OFString *category;
/// \brief The name of the identity, might be unset
@property (readonly) OFString *name;
/// \brief The type of the identity

Modified src/XMPPExceptions.h from [43c3496d04] to [532dca8d2a].

60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
60
61
62
63
64
65
66

67

68
69
70
71
72
73
74







-
+
-







@end

/**
 * \brief An exception indicating a stream error was received
 */
@interface XMPPStreamErrorException: XMPPException
{
	OFString *_condition;
	OFString *_condition, *_reason;
	OFString *_reason;
}

#ifdef OF_HAVE_PROPERTIES
/// \brief The defined error condition specified by the stream error
@property (readonly, assign) OFString *condition;
/// \brief The descriptive free-form text specified by the stream error
@property (readonly, assign) OFString *reason;
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120
104
105
106
107
108
109
110

111

112
113
114
115
116
117
118







-
+
-








/**
 * \brief An exception indicating a stringprep profile
 *	  did not apply to a string
 */
@interface XMPPStringPrepFailedException: XMPPException
{
	OFString *_profile;
	OFString *_profile, *_string;
	OFString *_string;
}

#ifdef OF_HAVE_PROPERTIES
/// \brief The name of the stringprep profile that did not apply
@property (readonly, assign) OFString *profile;
/// \brief The string that failed the stringprep profile
@property (readonly, assign) OFString *string;
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
164
147
148
149
150
151
152
153

154

155
156
157
158
159
160
161







-
+
-







@end

/**
 * \brief An exception indicating IDNA translation of a string failed
 */
@interface XMPPIDNATranslationFailedException: XMPPException
{
	OFString *_operation;
	OFString *_operation, *_string;
	OFString *_string;
}

#ifdef OF_HAVE_PROPERTIES
/// \brief The IDNA translation operation which failed
@property (readonly, assign) OFString *operation;
/// \brief The string that could not be translated
@property (readonly, assign) OFString *string;

Modified src/XMPPJID.h from [bd69f42276] to [bc56489a67].

24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
24
25
26
27
28
29
30

31


32
33
34
35
36
37
38







-
+
-
-







#import <ObjFW/ObjFW.h>

/**
 * \brief A class for easy handling of JIDs.
 */
@interface XMPPJID: OFObject <OFCopying>
{
	OFString *_node;
	OFString *_node, *_domain, *_resource;
	OFString *_domain;
	OFString *_resource;
}

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

Modified src/XMPPPresence.h from [a0f262bf11] to [7a50bb3ff0].

24
25
26
27
28
29
30
31

32
33
34

35
36
37
38
39
40
41
24
25
26
27
28
29
30

31


32
33
34
35
36
37
38
39
40







-
+
-
-

+







#import "XMPPStanza.h"

/**
 * \brief A class describing a presence stanza.
 */
@interface XMPPPresence: XMPPStanza <OFComparing>
{
	OFString *_status;
	OFString *_status, *_show, *_priority;
	OFString *_show;
	OFNumber *_priority;
}

#ifdef OF_HAVE_PROPERTIES
@property (copy) OFString *status;
@property (copy) OFString *show;
@property (copy) OFNumber *priority;
#endif

/**
131
132
133
134
135
136
137
138


139
140
141
142
143
130
131
132
133
134
135
136

137
138
139
140
141
142
143







-
+
+





 * \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.
 * \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/XMPPSRVLookup.h from [648af96410] to [be89ec074f].

79
80
81
82
83
84
85
86
87
88
89




90
91
92
93
79
80
81
82
83
84
85




86
87
88
89
90
91
92
93







-
-
-
-
+
+
+
+





- (void)XMPP_lookup;
- (void)XMPP_addEntry: (XMPPSRVEntry*)item;
@end

@interface XMPPSRVEnumerator: OFEnumerator
{
	OFList *list;
	of_list_object_t *listIter;
	OFList *subListCopy;
	bool done;
	OFList *_list;
	of_list_object_t *_listIter;
	OFList *_subListCopy;
	bool _done;
}

- initWithList: (OFList*)list;
@end

Modified src/XMPPSRVLookup.m from [0f6eec9046] to [9ac2bb0130].

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







-
+




-
+














-
+


-
-
+
+

-
+


-
-
+
+

-
+





-
+





-
+




-
+






-
-
-
+
+
+

-
+

-
-
+
+







-
-
-
-
+
+
+
+


- (OFEnumerator*)objectEnumerator
{
	return [[[XMPPSRVEnumerator alloc] initWithList: _list] autorelease];
}
@end

@implementation XMPPSRVEnumerator
- initWithList: (OFList*)list_
- initWithList: (OFList*)list
{
	self = [super init];

	@try {
		list = [list_ copy];
		_list = [list copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (id)nextObject
{
	XMPPSRVEntry *ret = nil;
	of_list_object_t *iter;
	uint32_t totalWeight = 0;

	if (done)
	if (_done)
		return nil;

	if (listIter == NULL)
		listIter = [list firstListObject];
	if (_listIter == NULL)
		_listIter = [_list firstListObject];

	if (listIter == NULL)
	if (_listIter == NULL)
		return nil;

	if (subListCopy == nil)
		subListCopy = [listIter->object copy];
	if (_subListCopy == nil)
		_subListCopy = [_listIter->object copy];

	for (iter = [subListCopy firstListObject]; iter != NULL;
	for (iter = [_subListCopy firstListObject]; iter != NULL;
	     iter = iter->next) {
		totalWeight += [iter->object weight];
		[iter->object setAccumulatedWeight: totalWeight];
	}

	if ([subListCopy count] > 0)  {
	if ([_subListCopy count] > 0)  {
		uint32_t randomWeight;

		RAND_pseudo_bytes((uint8_t*)&randomWeight, sizeof(uint32_t));
		randomWeight %= (totalWeight + 1);

		for (iter = [subListCopy firstListObject]; iter != NULL;
		for (iter = [_subListCopy firstListObject]; iter != NULL;
		     iter = iter->next) {
			if ([iter->object accumulatedWeight] >= randomWeight) {
				ret = [[iter->object retain] autorelease];

				[subListCopy removeListObject: iter];
				[_subListCopy removeListObject: iter];

				break;
			}
		}
	}

	if ([subListCopy count] == 0) {
		[subListCopy release];
		subListCopy = nil;
	if ([_subListCopy count] == 0) {
		[_subListCopy release];
		_subListCopy = nil;

		listIter = listIter->next;
		_listIter = _listIter->next;

		if (listIter == NULL)
			done = true;
		if (_listIter == NULL)
			_done = true;
	}

	return ret;
}

- (void)reset
{
	listIter = NULL;
	[subListCopy release];
	subListCopy = nil;
	done = false;
	_listIter = NULL;
	[_subListCopy release];
	_subListCopy = nil;
	_done = false;
}
@end

Modified src/XMPPStanza.h from [1aad056cc0] to [7567c50495].

26
27
28
29
30
31
32
33

34
35

36
37
38
39
40
41
42
43
44
26
27
28
29
30
31
32

33


34


35
36
37
38
39
40
41







-
+
-
-
+
-
-







@class XMPPJID;

/**
 * \brief A class describing an XMPP Stanza.
 */
@interface XMPPStanza: OFXMLElement
{
	XMPPJID *_from;
	XMPPJID *_from, *_to;
	XMPPJID *_to;
	OFString *_type;
	OFString *_type, *_ID, *_language;
	OFString *_ID;
	OFString *_language;
}

#ifdef OF_HAVE_PROPERTIES
/// \brief The value of the stanza's from attribute
@property (copy) XMPPJID *from;
/// \brief The value of the stanza's to attribute
@property (copy) XMPPJID *to;

Modified src/XMPPStreamManagement.h from [0d42168440] to [41ce04c91f].

24
25
26
27
28
29
30
31

32
33
34
35
24
25
26
27
28
29
30

31
32
33
34
35







-
+





@interface XMPPStreamManagement: OFObject
#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
    <XMPPConnectionDelegate>
#endif
{
	XMPPConnection *_connection;
	uint32_t receivedCount;
	uint32_t _receivedCount;
}

- initWithConnection: (XMPPConnection*)connection;
@end

Modified src/XMPPStreamManagement.m from [d765d3a204] to [febcd779c1].

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







-
+




-
+

-















-
+







-
+












+
+

-
+
-
-
-
+







-
+



-
+







 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "XMPPStreamManagement.h"
#import "namespaces.h"

@implementation XMPPStreamManagement
- initWithConnection: (XMPPConnection*)connection_
- initWithConnection: (XMPPConnection*)connection
{
	self = [super init];

	@try {
		_connection = connection_;
		_connection = connection;
		[_connection addDelegate: self];
		receivedCount = 0;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_connection removeDelegate: self];

	[super dealloc];
}

- (void)connection: (XMPPConnection*)connection_
- (void)connection: (XMPPConnection*)connection
 didReceiveElement: (OFXMLElement*)element
{
	OFString *elementName = [element name];
	OFString *elementNS = [element namespace];

	if ([elementNS isEqual: XMPP_NS_SM]) {
		if ([elementName isEqual: @"enabled"]) {
			receivedCount = 0;
			_receivedCount = 0;
			return;
		}

		if ([elementName isEqual: @"failed"]) {
			/* TODO: How do we handle this? */
			return;
		}

		if ([elementName isEqual: @"r"]) {
			OFXMLElement *ack =
			    [OFXMLElement elementWithName: @"a"
						namespace: XMPP_NS_SM];
			OFString *stringValue = [OFString
			    stringWithFormat: @"%" PRIu32, _receivedCount];
			[ack addAttributeWithName: @"h"
				      stringValue:
				      stringValue: stringValue];
			    [OFString stringWithFormat: @"%" PRIu32,
				receivedCount]];
			[connection_ sendStanza: ack];
			[connection sendStanza: ack];
		}
	}

	if ([elementNS isEqual: XMPP_NS_CLIENT] &&
	    ([elementName isEqual: @"iq"] ||
	     [elementName isEqual: @"presence"] ||
	     [elementName isEqual: @"message"]))
		receivedCount++;
		_receivedCount++;
}

/* TODO: Count outgoing stanzas here and cache them, send own ACK requests
- (void)connection: (XMPPConnection*)connection_
- (void)connection: (XMPPConnection*)connection
    didSendElement: (OFXMLElement*)element
{
}
*/

- (void)connection: (XMPPConnection*)connection
     wasBoundToJID: (XMPPJID*)JID