Skip to content

Commit 751a248

Browse files
committed
Merge pull request robbiehanson#289 from phetsana/XEP-0191
XEP-0191: Blocking Command
2 parents 75a5833 + a3824b3 commit 751a248

File tree

2 files changed

+770
-0
lines changed

2 files changed

+770
-0
lines changed

Extensions/XEP-0191/XMPPBlocking.h

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#import <Foundation/Foundation.h>
2+
#import "XMPPModule.h"
3+
4+
#if TARGET_OS_IPHONE
5+
#import "DDXML.h"
6+
#endif
7+
8+
#define _XMPP_BLOCKING_H
9+
10+
@class XMPPIQ;
11+
12+
extern NSString *const XMPPBlockingErrorDomain;
13+
14+
typedef enum XMPPBlockingErrorCode
15+
{
16+
XMPPBlockingQueryTimeout, // No response from server
17+
XMPPBlockingDisconnect, // XMPP disconnection
18+
19+
} XMPPBlockingErrorCode;
20+
21+
@interface XMPPBlocking : XMPPModule
22+
{
23+
BOOL autoRetrieveBlockingListItems;
24+
BOOL autoClearBlockingListInfo;
25+
26+
NSMutableDictionary *blockingDict;
27+
28+
NSMutableDictionary *pendingQueries;
29+
}
30+
31+
/**
32+
* Whether or not the module should automatically retrieve the blocking list rules.
33+
* If this property is enabled, then the rules for each blocking list are automatically fetched.
34+
*
35+
* In other words, if the blocking list names are fetched (either automatically, or via retrieveListItems),
36+
* then the module will automatically fetch the associated rules.
37+
*
38+
* The default value is YES.
39+
**/
40+
@property (readwrite, assign) BOOL autoRetrieveBlockingListItems;
41+
42+
/**
43+
* Whether the module should automatically clear the blocking list info when the client disconnects.
44+
*
45+
* As per the XEP, if there are multiple resources signed in for the user,
46+
* and one resource makes changes to a blocking list, all other resources are "pushed" a notification.
47+
* However, if our client is disconnected when another resource makes the changes,
48+
* then the only way we can find out about the changes are to redownload the blocking lists.
49+
*
50+
* It is recommended to clear the blocking list to assure we have the correct info.
51+
* However, there may be specific situations in which an xmpp client can be sure the blocking list won't change.
52+
*
53+
* The default value is YES.
54+
**/
55+
@property (readwrite, assign) BOOL autoClearBlockingListInfo;
56+
57+
/**
58+
* Blocking dict
59+
*/
60+
@property (readonly, strong) NSMutableDictionary *blockingDict;
61+
62+
/**
63+
* Manual fetch of list names and rules, and manual control over when to clear stored info.
64+
**/
65+
- (void)retrieveBlockingListItems;
66+
- (void)clearBlockingListInfo;
67+
68+
/**
69+
* Returns the blocking list.
70+
*
71+
* The result is an array or blocking items (NSXMLElement's).
72+
**/
73+
- (NSArray*)blockingList;
74+
75+
/**
76+
* Block JID.
77+
*/
78+
- (void)blockJID:(XMPPJID*)xmppJID;
79+
80+
/**
81+
* Unblock JID.
82+
*/
83+
- (void)unblockJID:(XMPPJID*)xmppJID;
84+
85+
/**
86+
* Return whether a jid is in blocking list or not.
87+
*/
88+
- (BOOL)containsJID:(XMPPJID*)xmppJID;
89+
90+
/**
91+
* Unblock all.
92+
*/
93+
- (void)unblockAll;
94+
95+
@end
96+
97+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
98+
#pragma mark -
99+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
100+
101+
@protocol XMPPBlockingDelegate
102+
@optional
103+
104+
/**
105+
* The following delegate methods correspond almost exactly with the action methods of the class.
106+
* There are a few possible ways in which an action could fail:
107+
*
108+
* 1. We receive an error response from the server.
109+
* 2. We receive no response from the server, and the query times out.
110+
* 3. We get disconnected before we receive the response.
111+
*
112+
* In case number 1, the error will be an XMPPIQ of type='error'.
113+
*
114+
* In case number 2 or 3, the error will be an NSError
115+
* with domain=XMPPPrivacyErrorDomain and code from the XMPPBlockingErrorCode enumeration.
116+
**/
117+
118+
- (void)xmppBlocking:(XMPPBlocking *)sender didReceivedBlockingList:(NSArray*)blockingList;
119+
- (void)xmppBlocking:(XMPPBlocking *)sender didNotReceivedBlockingListDueToError:(id)error;
120+
121+
- (void)xmppBlocking:(XMPPBlocking *)sender didReceivePushWithBlockingList:(NSString *)name;
122+
123+
- (void)xmppBlocking:(XMPPBlocking *)sender didBlockJID:(XMPPJID*)xmppJID;
124+
- (void)xmppBlocking:(XMPPBlocking *)sender didNotBlockJID:(XMPPJID*)xmppJID error:(id)error;
125+
126+
- (void)xmppBlocking:(XMPPBlocking *)sender didUnblockJID:(XMPPJID*)xmppJID;
127+
- (void)xmppBlocking:(XMPPBlocking *)sender didNotUnblockJID:(XMPPJID*)xmppJID error:(id)error;
128+
129+
- (void)xmppBlocking:(XMPPBlocking *)sender didUnblockAllWithError:(id)error;
130+
- (void)xmppBlocking:(XMPPBlocking *)sender didNotUnblockAllDueToError:(id)error;
131+
132+
@end

0 commit comments

Comments
 (0)