ObjXMPP  Check-in [7f10dd9950]

Overview
Comment:Make method names more consistent with ObjFW.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7f10dd99508abd97c9b28db2f4b2e044aa832574f49b4df17741367ae0ebe869
User & Date: js on 2012-12-13 22:09:30
Other Links: manifest | tags
Context
2012-12-13
22:29
Add -[asyncConnectAndHandle]. check-in: 2dcf26fbc9 user: js tags: trunk
22:09
Make method names more consistent with ObjFW. check-in: 7f10dd9950 user: js tags: trunk
21:20
XMPPRoster: Notify delegates before updating roster check-in: bc252638ef user: florob@babelmonkeys.de tags: trunk
Changes

Modified src/XMPPCallback.h from [4a460eddf0] to [aac49145b2].

27
28
29
30
31
32
33
34

35



36
37
38
39
40


41
42
43
44
45
46




47
48
49
50
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







-
+

+
+
+



-
-
+
+


-
-
-
-
+
+
+
+





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

@interface XMPPCallback: OFObject
{
	id object;
	id target;
	SEL selector;
#ifdef OF_HAVE_BLOCKS
	xmpp_callback_block_t block;
#endif
}

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

+ callbackWithCallbackObject: (id)object
		    selector: (SEL)selector;
- initWithCallbackObject: (id)object
		selector: (SEL)selector;
+ callbackWithTarget: (id)target
	    selector: (SEL)selector;
- initWithTarget: (id)target
	selector: (SEL)selector;

- (void)runWithIQ: (XMPPIQ*)iq
       connection: (XMPPConnection*)connection;
@end

Modified src/XMPPCallback.m from [c6e609221e] to [2e45d71ec9].

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







-
+

-
+


-
+



+
-
+
+
+
+
+





-
-
+
+

-
-
+
+


-
-
+
+



-
+







+
+
+
+
+







-
-
+
+


-
+




# include "config.h"
#endif

#import "XMPPCallback.h"

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

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

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

	return self;
}
#endif

+ callbackWithCallbackObject: (id)object_
		    selector: (SEL)selector_
+ callbackWithTarget: (id)target
	    selector: (SEL)selector
{
	return [[[self alloc] initWithCallbackObject: object_
					    selector: selector_] autorelease];
	return [[[self alloc] initWithTarget: target
				    selector: selector] autorelease];
}

- initWithCallbackObject: (id)object_
		selector: (SEL)selector_
- initWithTarget: (id)target_
	selector: (SEL)selector_
{
	self = [super init];

	object = object_;
	target = [target_ retain];
	selector = selector_;

	return self;
}

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

	[super dealloc];
}

- (void)runWithIQ: (XMPPIQ*)iq
       connection: (XMPPConnection*)connection
{
#ifdef OF_HAVE_BLOCKS
	if ([object isKindOfClass: [OFBlock class]])
		((xmpp_callback_block_t)object)(connection, iq);
	if (block != NULL)
		block(connection, iq);
	else
#endif
		[object performSelector: selector
		[target performSelector: selector
			     withObject: connection
			     withObject: iq];
}
@end

Modified src/XMPPConnection.h from [bd3a4d49ca] to [12411aa95c].

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







-
-
-
+
+
+







-
-
+
+







/**
 * \brief Sends an XMPPIQ, registering a callback method.
 *
 * \param object The object that contains the callback method
 * \param selector The selector of the callback method,
 *		   must take exactly one parameter of type XMPPIQ*
 */
-	(void)sendIQ: (XMPPIQ*)iq
  withCallbackObject: (id)object
	    selector: (SEL)selector;
-   (void)sendIQ: (XMPPIQ*)iq
  callbackTarget: (id)target
	selector: (SEL)selector;

#ifdef OF_HAVE_BLOCKS
/**
 * \brief Sends an XMPPIQ, registering a callback block.
 *
 * \param callback The callback block
 */
-      (void)sendIQ: (XMPPIQ*)iq
  withCallbackBlock: (xmpp_callback_block_t)block;
-  (void)sendIQ: (XMPPIQ*)iq
  callbackBlock: (xmpp_callback_block_t)block;
#endif

/**
 * \brief Generates a new, unique stanza ID.
 *
 * \return A new, generated, unique stanza ID.
 */
366
367
368
369
370
371
372
373

374
375
376

377
378
379
380
366
367
368
369
370
371
372

373
374
375

376
377
378
379
380







-
+


-
+




- (void)XMPP_sendStreamError: (OFString*)condition
			text: (OFString*)text;
- (void)XMPP_handleIQ: (XMPPIQ*)iq;
- (void)XMPP_handleMessage: (XMPPMessage*)message;
- (void)XMPP_handlePresence: (XMPPPresence*)presence;
- (void)XMPP_handleFeatures: (OFXMLElement*)element;
- (void)XMPP_handleResourceBindForConnection: (XMPPConnection*)connection
				      withIQ: (XMPPIQ*)iq;
					  IQ: (XMPPIQ*)iq;
- (void)XMPP_sendSession;
- (void)XMPP_handleSessionForConnection: (XMPPConnection*)connection
				 withIQ: (XMPPIQ*)iq;
				     IQ: (XMPPIQ*)iq;
- (OFString*)XMPP_IDNAToASCII: (OFString*)domain;
- (XMPPMulticastDelegate*)XMPP_delegates;
/// \endcond
@end

Modified src/XMPPConnection.m from [b0f0c109e0] to [5b10968439].

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
499
500
501
502
503

504
505
506
507
508
509
510
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
499
500
501
502

503
504
505
506
507
508
509
510







-
-
-
+
+
+








-
-
+
+








-
-
+
+








-
+







	[delegates broadcastSelector: @selector(connection:didSendElement:)
			  withObject: self
			  withObject: element];

	[sock writeString: [element XMLString]];
}

-	(void)sendIQ: (XMPPIQ*)iq
  withCallbackObject: (id)object
	    selector: (SEL)selector
-   (void)sendIQ: (XMPPIQ*)iq
  callbackTarget: (id)target
	selector: (SEL)selector
{
	OFAutoreleasePool *pool;
	XMPPCallback *callback;

	if (![iq ID])
		[iq setID: [self generateStanzaID]];

	pool = [[OFAutoreleasePool alloc] init];
	callback = [XMPPCallback callbackWithCallbackObject: object
						   selector: selector];
	callback = [XMPPCallback callbackWithTarget: target
					   selector: selector];
	[callbacks setObject: callback
		      forKey: [iq ID]];
	[pool release];

	[self sendStanza: iq];
}

#ifdef OF_HAVE_BLOCKS
-      (void)sendIQ: (XMPPIQ*)iq
  withCallbackBlock: (xmpp_callback_block_t)block;
-  (void)sendIQ: (XMPPIQ*)iq
  callbackBlock: (xmpp_callback_block_t)block
{
	OFAutoreleasePool *pool;
	XMPPCallback *callback;

	if (![iq ID])
		[iq setID: [self generateStanzaID]];

	pool = [[OFAutoreleasePool alloc] init];
	callback = [XMPPCallback callbackWithCallbackBlock: block];
	callback = [XMPPCallback callbackWithBlock: block];
	[callbacks setObject: callback
		      forKey: [iq ID]];
	[pool release];

	[self sendStanza: iq];
}
#endif
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044




1045
1046
1047
1048
1049
1050
1051
1034
1035
1036
1037
1038
1039
1040




1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051







-
-
-
-
+
+
+
+







	if (resource != nil)
		[bind addChild: [OFXMLElement elementWithName: @"resource"
						    namespace: XMPP_NS_BIND
						  stringValue: resource]];

	[iq addChild: bind];

	[self		sendIQ: iq
	    withCallbackObject: self
		      selector: @selector(XMPP_handleResourceBindForConnection:
				    withIQ:)];
	[self	    sendIQ: iq
	    callbackTarget: self
		  selector: @selector(XMPP_handleResourceBindForConnection:
				IQ:)];
}

- (void)XMPP_sendStreamError: (OFString*)condition
			text: (OFString*)text
{
	OFXMLElement *error = [OFXMLElement
	    elementWithName: @"error"
1061
1062
1063
1064
1065
1066
1067
1068

1069
1070
1071
1072
1073
1074
1075
1061
1062
1063
1064
1065
1066
1067

1068
1069
1070
1071
1072
1073
1074
1075







-
+







			stringValue: text]];
	[parser setDelegate: nil];
	[self sendStanza: error];
	[self close];
}

- (void)XMPP_handleResourceBindForConnection: (XMPPConnection*)connection
				      withIQ: (XMPPIQ*)iq
					  IQ: (XMPPIQ*)iq
{
	OFXMLElement *bindElement;
	OFXMLElement *jidElement;

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

	bindElement = [iq elementForName: @"bind"
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104



1105
1106
1107
1108
1109

1110
1111
1112
1113
1114
1115
1116
1095
1096
1097
1098
1099
1100
1101



1102
1103
1104

1105
1106
1107

1108
1109
1110
1111
1112
1113
1114
1115







-
-
-
+
+
+
-



-
+







{
	XMPPIQ *iq;

	iq = [XMPPIQ IQWithType: @"set"
			     ID: [self generateStanzaID]];
	[iq addChild: [OFXMLElement elementWithName: @"session"
					  namespace: XMPP_NS_SESSION]];
	[self		sendIQ: iq
	    withCallbackObject: self
		      selector: @selector(
	[self	    sendIQ: iq
	    callbackTarget: self
		  selector: @selector(XMPP_handleSessionForConnection:IQ:)];
				    XMPP_handleSessionForConnection:withIQ:)];
}

- (void)XMPP_handleSessionForConnection: (XMPPConnection*)connection
				 withIQ: (XMPPIQ*)iq
				     IQ: (XMPPIQ*)iq
{
	if (![[iq type] isEqual: @"result"])
		assert(0);

	[delegates broadcastSelector: @selector(connection:wasBoundToJID:)
			  withObject: self
			  withObject: JID];

Modified src/XMPPRoster.h from [fe26501170] to [dde2cb56af].

152
153
154
155
156
157
158
159

160
161
162
152
153
154
155
156
157
158

159
160
161
162







-
+




- (void)setDataStorage: (id <XMPPStorage>)dataStorage;
- (id <XMPPStorage>)dataStorage;

/// \cond internal
- (void)XMPP_updateRosterItem: (XMPPRosterItem*)rosterItem;
- (void)XMPP_handleInitialRosterForConnection: (XMPPConnection*)connection
				       withIQ: (XMPPIQ*)iq;
					   IQ: (XMPPIQ*)iq;
- (XMPPRosterItem*)XMPP_rosterItemWithXMLElement: (OFXMLElement*)element;
/// \endcond
@end

Modified src/XMPPRoster.m from [22f6723529] to [3d07ff17e7].

93
94
95
96
97
98
99
100
101
102
103




104
105
106
107
108
109
110
93
94
95
96
97
98
99




100
101
102
103
104
105
106
107
108
109
110







-
-
-
-
+
+
+
+








		[query addAttributeWithName: @"ver"
				stringValue: ver];
	}

	[iq addChild: query];

	[connection     sendIQ: iq
	    withCallbackObject: self
		      selector: @selector(XMPP_handleInitialRosterForConnection:
			withIQ:)];
	[connection sendIQ: iq
	    callbackTarget: self
		  selector: @selector(XMPP_handleInitialRosterForConnection:
				IQ:)];
}

- (BOOL)connection: (XMPPConnection*)connection_
      didReceiveIQ: (XMPPIQ*)iq
{
	OFXMLElement *rosterElement;
	OFXMLElement *element;
302
303
304
305
306
307
308
309

310
311
312
313
314
315
316
302
303
304
305
306
307
308

309
310
311
312
313
314
315
316







-
+







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

	return rosterItem;
}

- (void)XMPP_handleInitialRosterForConnection: (XMPPConnection*)connection_
				       withIQ: (XMPPIQ*)iq
					   IQ: (XMPPIQ*)iq
{
	OFXMLElement *rosterElement;
	OFEnumerator *enumerator;
	OFXMLElement *element;
	XMPPRosterItem *rosterItem;

	rosterElement = [iq elementForName: @"query"

Modified tests/test.m from [99762e7332] to [7aaba010fc].

165
166
167
168
169
170
171
172
173


174
175
176
177
178
179
180
165
166
167
168
169
170
171


172
173
174
175
176
177
178
179
180







-
-
+
+







	[conn sendStanza: pres];

#ifdef OF_HAVE_BLOCKS
	XMPPIQ *iq = [XMPPIQ IQWithType: @"get"
				     ID: [conn generateStanzaID]];
	[iq addChild: [OFXMLElement elementWithName: @"ping"
					  namespace: @"urn:xmpp:ping"]];
	[conn	       sendIQ: iq
	    withCallbackBlock: ^ (XMPPConnection *c, XMPPIQ *resp) {
	[conn	   sendIQ: iq
	    callbackBlock: ^ (XMPPConnection *c, XMPPIQ *resp) {
		of_log(@"Ping response: %@", resp);
	}];
#endif
}

- (void)connectionDidUpgradeToTLS: (XMPPConnection*)conn_
{