6
6
#import " NSData+XMPP.h"
7
7
#import " DDList.h"
8
8
9
+ #import < objc/runtime.h>
9
10
#import < libkern/OSAtomic.h>
10
11
11
12
#if TARGET_OS_IPHONE
@@ -1758,7 +1759,6 @@ - (void)sendIQ:(XMPPIQ *)iq withTag:(long)tag
1758
1759
NSAssert (dispatch_get_current_queue() == xmppQueue, @"Invoked on incorrect queue");
1759
1760
NSAssert (state == STATE_XMPP_CONNECTED, @" Invoked with incorrect state" );
1760
1761
1761
-
1762
1762
// We're getting ready to send an IQ.
1763
1763
// We need to notify delegates of this action to allow them to optionally alter the IQ element.
1764
1764
@@ -1781,27 +1781,46 @@ - (void)sendIQ:(XMPPIQ *)iq withTag:(long)tag
1781
1781
dispatch_queue_t concurrentQueue = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 );
1782
1782
dispatch_async (concurrentQueue, ^{ @autoreleasepool {
1783
1783
1784
- // Allow delegates to modify outgoing element
1784
+ // Allow delegates to modify and/or filter outgoing element
1785
+
1786
+ __block XMPPIQ *modifiedIQ = iq;
1785
1787
1786
1788
id del;
1787
1789
dispatch_queue_t dq;
1788
1790
1789
- while ([delegateEnumerator getNextDelegate: &del delegateQueue: &dq forSelector: selector])
1791
+ while (modifiedIQ && [delegateEnumerator getNextDelegate: &del delegateQueue: &dq forSelector: selector])
1790
1792
{
1793
+ #if DEBUG
1794
+ {
1795
+ char methodReturnType[32 ];
1796
+
1797
+ Method method = class_getInstanceMethod ([del class ], selector);
1798
+ method_getReturnType (method, methodReturnType, sizeof (methodReturnType));
1799
+
1800
+ if (strcmp (methodReturnType, @encode (XMPPIQ*)) != 0 )
1801
+ {
1802
+ NSAssert (NO , @" Method xmppStream:willSendIQ: is no longer void (see XMPPStream.h). "
1803
+ @" Culprit = %@ " , NSStringFromClass ([del class ]));
1804
+ }
1805
+ }
1806
+ #endif
1807
+
1791
1808
dispatch_sync (dq, ^{ @autoreleasepool {
1792
1809
1793
- [del xmppStream: self willSendIQ: iq ];
1810
+ modifiedIQ = [del xmppStream: self willSendIQ: modifiedIQ ];
1794
1811
1795
1812
}});
1796
1813
}
1797
1814
1798
- dispatch_async (xmppQueue, ^{ @autoreleasepool {
1799
-
1800
- if (state == STATE_XMPP_CONNECTED) {
1801
- [self continueSendIQ: iq withTag: tag];
1802
- }
1803
- }});
1804
-
1815
+ if (modifiedIQ)
1816
+ {
1817
+ dispatch_async (xmppQueue, ^{ @autoreleasepool {
1818
+
1819
+ if (state == STATE_XMPP_CONNECTED) {
1820
+ [self continueSendIQ: modifiedIQ withTag: tag];
1821
+ }
1822
+ }});
1823
+ }
1805
1824
}});
1806
1825
}
1807
1826
}
@@ -1811,7 +1830,6 @@ - (void)sendMessage:(XMPPMessage *)message withTag:(long)tag
1811
1830
NSAssert (dispatch_get_current_queue() == xmppQueue, @"Invoked on incorrect queue");
1812
1831
NSAssert (state == STATE_XMPP_CONNECTED, @" Invoked with incorrect state" );
1813
1832
1814
-
1815
1833
// We're getting ready to send a message.
1816
1834
// We need to notify delegates of this action to allow them to optionally alter the message element.
1817
1835
@@ -1836,25 +1854,44 @@ - (void)sendMessage:(XMPPMessage *)message withTag:(long)tag
1836
1854
1837
1855
// Allow delegates to modify outgoing element
1838
1856
1857
+ __block XMPPMessage *modifiedMessage = message;
1858
+
1839
1859
id del;
1840
1860
dispatch_queue_t dq;
1841
1861
1842
- while ([delegateEnumerator getNextDelegate: &del delegateQueue: &dq forSelector: selector])
1862
+ while (modifiedMessage && [delegateEnumerator getNextDelegate: &del delegateQueue: &dq forSelector: selector])
1843
1863
{
1864
+ #if DEBUG
1865
+ {
1866
+ char methodReturnType[32 ];
1867
+
1868
+ Method method = class_getInstanceMethod ([del class ], selector);
1869
+ method_getReturnType (method, methodReturnType, sizeof (methodReturnType));
1870
+
1871
+ if (strcmp (methodReturnType, @encode (XMPPMessage*)) != 0 )
1872
+ {
1873
+ NSAssert (NO , @" Method xmppStream:willSendMessage: is no longer void (see XMPPStream.h). "
1874
+ @" Culprit = %@ " , NSStringFromClass ([del class ]));
1875
+ }
1876
+ }
1877
+ #endif
1878
+
1844
1879
dispatch_sync (dq, ^{ @autoreleasepool {
1845
1880
1846
- [del xmppStream: self willSendMessage: message ];
1881
+ modifiedMessage = [del xmppStream: self willSendMessage: modifiedMessage ];
1847
1882
1848
1883
}});
1849
1884
}
1850
1885
1851
- dispatch_async (xmppQueue, ^{ @autoreleasepool {
1852
-
1853
- if (state == STATE_XMPP_CONNECTED) {
1854
- [self continueSendMessage: message withTag: tag];
1855
- }
1856
- }});
1857
-
1886
+ if (modifiedMessage)
1887
+ {
1888
+ dispatch_async (xmppQueue, ^{ @autoreleasepool {
1889
+
1890
+ if (state == STATE_XMPP_CONNECTED) {
1891
+ [self continueSendMessage: modifiedMessage withTag: tag];
1892
+ }
1893
+ }});
1894
+ }
1858
1895
}});
1859
1896
}
1860
1897
}
@@ -1864,7 +1901,6 @@ - (void)sendPresence:(XMPPPresence *)presence withTag:(long)tag
1864
1901
NSAssert (dispatch_get_current_queue() == xmppQueue, @"Invoked on incorrect queue");
1865
1902
NSAssert (state == STATE_XMPP_CONNECTED, @" Invoked with incorrect state" );
1866
1903
1867
-
1868
1904
// We're getting ready to send a presence element.
1869
1905
// We need to notify delegates of this action to allow them to optionally alter the presence element.
1870
1906
@@ -1889,25 +1925,44 @@ - (void)sendPresence:(XMPPPresence *)presence withTag:(long)tag
1889
1925
1890
1926
// Allow delegates to modify outgoing element
1891
1927
1928
+ __block XMPPPresence *modifiedPresence = presence;
1929
+
1892
1930
id del;
1893
1931
dispatch_queue_t dq;
1894
1932
1895
- while ([delegateEnumerator getNextDelegate: &del delegateQueue: &dq forSelector: selector])
1933
+ while (modifiedPresence && [delegateEnumerator getNextDelegate: &del delegateQueue: &dq forSelector: selector])
1896
1934
{
1935
+ #if DEBUG
1936
+ {
1937
+ char methodReturnType[32 ];
1938
+
1939
+ Method method = class_getInstanceMethod ([del class ], selector);
1940
+ method_getReturnType (method, methodReturnType, sizeof (methodReturnType));
1941
+
1942
+ if (strcmp (methodReturnType, @encode (XMPPPresence*)) != 0 )
1943
+ {
1944
+ NSAssert (NO , @" Method xmppStream:willSendPresence: is no longer void (see XMPPStream.h). "
1945
+ @" Culprit = %@ " , NSStringFromClass ([del class ]));
1946
+ }
1947
+ }
1948
+ #endif
1949
+
1897
1950
dispatch_sync (dq, ^{ @autoreleasepool {
1898
1951
1899
- [del xmppStream: self willSendPresence: presence ];
1952
+ modifiedPresence = [del xmppStream: self willSendPresence: modifiedPresence ];
1900
1953
1901
1954
}});
1902
1955
}
1903
1956
1904
- dispatch_async (xmppQueue, ^{ @autoreleasepool {
1905
-
1906
- if (state == STATE_XMPP_CONNECTED) {
1907
- [self continueSendPresence: presence withTag: tag];
1908
- }
1909
- }});
1910
-
1957
+ if (modifiedPresence)
1958
+ {
1959
+ dispatch_async (xmppQueue, ^{ @autoreleasepool {
1960
+
1961
+ if (state == STATE_XMPP_CONNECTED) {
1962
+ [self continueSendPresence: presence withTag: tag];
1963
+ }
1964
+ }});
1965
+ }
1911
1966
}});
1912
1967
}
1913
1968
}
@@ -2047,6 +2102,8 @@ - (void)sendElement:(NSXMLElement *)element withTag:(long)tag
2047
2102
**/
2048
2103
- (void )sendElement : (NSXMLElement *)element
2049
2104
{
2105
+ if (element == nil ) return ;
2106
+
2050
2107
dispatch_block_t block = ^{ @autoreleasepool {
2051
2108
2052
2109
if (state == STATE_XMPP_CONNECTED)
@@ -2070,6 +2127,8 @@ - (void)sendElement:(NSXMLElement *)element
2070
2127
**/
2071
2128
- (void )sendElement : (NSXMLElement *)element andGetReceipt : (XMPPElementReceipt **)receiptPtr
2072
2129
{
2130
+ if (element == nil ) return ;
2131
+
2073
2132
if (receiptPtr == nil )
2074
2133
{
2075
2134
[self sendElement: element];
0 commit comments