ObjXMPP  Check-in [1ee9a1a87a]

Overview
Comment:XMPPMulticastDelegate: Handle modifications of the delegates array
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1ee9a1a87aac45d97ac74113ab20b3f0c718f1bbad93653c2448b991bd448ae5
User & Date: florob@babelmonkeys.de on 2013-03-27 00:30:59
Other Links: manifest | tags
Context
2013-03-31
10:16
Adjust to ObjOpenSSL changes. check-in: 7d9b6a0cdf user: js tags: trunk
2013-03-27
00:30
XMPPMulticastDelegate: Handle modifications of the delegates array check-in: 1ee9a1a87a user: florob@babelmonkeys.de tags: trunk
2013-03-26
18:11
Fix a use after free() bug in XMPPSCRAMAuth check-in: aa2fb6642f user: florob@babelmonkeys.de tags: trunk
Changes

Modified src/XMPPMulticastDelegate.h from [6630339e62] to [ec802f6688].

26
27
28
29
30
31
32

33
34
35
36
37
38
39

/**
 * \brief A class to provide multiple delegates in a single class
 */
@interface XMPPMulticastDelegate: OFObject
{
	OFDataArray *_delegates;

}

/**
 * \brief Adds a delegate which should receive the broadcasts.
 *
 * \param delegate The delegate to add
 */







>







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

/**
 * \brief A class to provide multiple delegates in a single class
 */
@interface XMPPMulticastDelegate: OFObject
{
	OFDataArray *_delegates;
	size_t handlerIndex;
}

/**
 * \brief Adds a delegate which should receive the broadcasts.
 *
 * \param delegate The delegate to add
 */

Modified src/XMPPMulticastDelegate.m from [0321dd1eed] to [8c2482d4cf].

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

- (void)removeDelegate: (id)delegate
{
	id *items = [_delegates items];
	size_t i, count = [_delegates count];

	for (i = 0; i < count; i++) {
		if (items[i] == delegate) {


			[_delegates removeItemAtIndex: i];


			return;
		}
	}
}

- (BOOL)broadcastSelector: (SEL)selector
	       withObject: (id)object
{

	id *items = [_delegates items];
	size_t i, count = [_delegates count];
	BOOL handled = NO;

	for (i = 0; i < count; i++) {

		if (![items[i] respondsToSelector: selector])
			continue;

		BOOL (*imp)(id, SEL, id) = (BOOL(*)(id, SEL, id))
		    [items[i] methodForSelector: selector];

		handled |= imp(items[i], selector, object);




	}

	return handled;
}

- (BOOL)broadcastSelector: (SEL)selector
	       withObject: (id)object1
	       withObject: (id)object2
{

	id *items = [_delegates items];
	size_t i, count = [_delegates count];
	BOOL handled = NO;

	for (i = 0; i < count; i++) {

		if (![items[i] respondsToSelector: selector])
			continue;

		BOOL (*imp)(id, SEL, id, id) = (BOOL(*)(id, SEL, id, id))
		    [items[i] methodForSelector: selector];

		handled |= imp(items[i], selector, object1, object2);




	}

	return handled;
}
@end







|
>
>
|
>
>
|
<






>

<


|
>
|



|

|
>
>
>
>









>

<


|
>
|



|

|
>
>
>
>





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

- (void)removeDelegate: (id)delegate
{
	id *items = [_delegates items];
	size_t i, count = [_delegates count];

	for (i = 0; i < count; i++) {
		if (items[i] != delegate)
			continue;

		[_delegates removeItemAtIndex: i];
		if (i <= handlerIndex)
			handlerIndex--;
		return;

	}
}

- (BOOL)broadcastSelector: (SEL)selector
	       withObject: (id)object
{
	size_t count = [_delegates count];
	id *items = [_delegates items];

	BOOL handled = NO;

	for (handlerIndex = 0; handlerIndex < count; handlerIndex++) {
		id responder = items[handlerIndex];
		if (![responder respondsToSelector: selector])
			continue;

		BOOL (*imp)(id, SEL, id) = (BOOL(*)(id, SEL, id))
		    [responder methodForSelector: selector];

		handled |= imp(responder, selector, object);
		// Update count and items, since the handler might have
		// changed them.
		count = [_delegates count];
		items = [_delegates items];
	}

	return handled;
}

- (BOOL)broadcastSelector: (SEL)selector
	       withObject: (id)object1
	       withObject: (id)object2
{
	size_t count = [_delegates count];
	id *items = [_delegates items];

	BOOL handled = NO;

	for (handlerIndex = 0; handlerIndex < count; handlerIndex++) {
		id responder = items[handlerIndex];
		if (![responder respondsToSelector: selector])
			continue;

		BOOL (*imp)(id, SEL, id, id) = (BOOL(*)(id, SEL, id, id))
		    [responder methodForSelector: selector];

		handled |= imp(responder, selector, object1, object2);
		// Update count and items, since the handler might have
		// changed them.
		count = [_delegates count];
		items = [_delegates items];
	}

	return handled;
}
@end