XMPPPubSub.h
14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
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
#import <Foundation/Foundation.h>
#import "XMPP.h"
#define _XMPP_PUB_SUB_H
@interface XMPPPubSub : XMPPModule
/**
* Returns whether or not the given message is a PubSub event message.
**/
+ (BOOL)isPubSubMessage:(XMPPMessage *)message;
/**
* Creates a PubSub module with the JID of the PubSub service.
* This JID will be the 'to' attribute of outgoing <iq/> element(s).
*
* If you're creating a PEP module, you should pass nil as the serviceJID.
* If you're creating a normal PubSub module, you should pass the JID of the PubSub service.
*
* If you're connected to server 'domain.tld', then the PubSub JID is typically something like 'pubsub.domain.tld'.
* However, the exact format of the JID varies from server to server, and is often configurable.
* If you don't know the PubSub JID beforehand, you may need to use service discovery to find it.
**/
- (id)initWithServiceJID:(XMPPJID *)aServiceJID;
- (id)initWithServiceJID:(XMPPJID *)aServiceJID dispatchQueue:(dispatch_queue_t)queue;
/**
* The JID of the PubSub server the module is to communicate with.
**/
@property (nonatomic, strong, readonly) XMPPJID *serviceJID;
/**
* Sends a subscription request for the given node name.
*
* @param node
*
* The name of the node to subscribe to.
* This may be a leaf node or, if supported by the server, a collection node.
*
* @param myBareOrFullJid
*
* When you subscribe to a PubSub node, you can subscribe with either
* your bare jid (username@domain.tld) or your full jid (username@domain.tld/resource).
*
* If you subscribe with your bare jid, then all resources are subscribed.
* For example, if you subscribe to "/MyTown/CornerCoffeeShop" with your bare jid,
* then your "home" resource will be subscribed, as well as your "work" and "mobile" resources.
* No matter what device you sign into your account with, you'll receive pubsub updates.
*
* Contrast this with subscribing with your full jid. This subscribes you only for the current resource.
* Using the example from above, only the "home" resource would receive pubsub updates for the node.
*
* If you don't pass a JID, the method defaults to using the full JID.
*
* @param options
*
* The optional options dictionary allows you to provide the subscription options in the subscription stanza.
* This corresponds to XEP-0060, Section 6.3.7: Subscribe and Configure
*
* To use example 71 from the spec, you would pass the following dictionary:
*
* @{ @"pubsub#deliver" : @(YES),
* @"pubsub#digest" : @(NO),
* @"pubsub#include_body" : @(NO),
* @"pubsub#show-values" : @[ @"chat", @"online", @"away" ] }
*
* @return uuid
*
* The return value is the unique elementID of the IQ stanza that was sent.
*
* The server's response to the request will be reported via the appropriate delegate methods.
*
* @see xmppPubSub:didSubscribeToNode:withResult:
* @see xmppPubSub:didNotSubscribeToNode:withError:
**/
- (NSString *)subscribeToNode:(NSString *)node;
- (NSString *)subscribeToNode:(NSString *)node withJID:(XMPPJID *)myBareOrFullJid;
- (NSString *)subscribeToNode:(NSString *)node withJID:(XMPPJID *)myBareOrFullJid options:(NSDictionary *)options;
/**
* Sends an unsubscribe request for the given node name.
*
* @param node
*
* The name of the node to unsubscribe from.
* This should be the same node name you used when you subscribed.
*
* @param myBareOrFullJid
*
* The appropriate jid that matches the subscription.
* This should be the same jid you used when you subscribed.
*
* If you don't pass a JID, the method defaults to using the full JID.
*
* @param subid
*
* If a subscription identifier (subid) is associated with the subscription,
* the unsubscribe request may be required to include the appropriate 'subid' attribute.
* The subid value was returned by the server in the original subscribe response,
* and can also be obtained by retrieving the subscription(s) from the server.
*
* XMPPIQ+XEP_0060 has a category method named "pubsubid" which conveniently
* extracts the subid value from a subscription response.
*
* @return uuid
*
* The return value is the unique elementID of the IQ stanza that was sent.
*
* The server's response to the request will be reported via the appropriate delegate methods.
*
* @see xmppPubSub:didUnsubscribeFromNode:withResult:
* @see xmppPubSub:didNotUnsubscribeFromNode:(NSString *)node withError:
**/
- (NSString *)unsubscribeFromNode:(NSString *)node;
- (NSString *)unsubscribeFromNode:(NSString *)node withJID:(XMPPJID *)myBareOrFullJid;
- (NSString *)unsubscribeFromNode:(NSString *)node withJID:(XMPPJID *)myBareOrFullJid subid:(NSString *)subid;
/**
* Fetches the current PubSub subscriptions from the server.
* You can fetch all subscriptions, or just subscriptions for a particular node.
*
* Keep in mind that your PubSub subscriptions don't typically disappear when you disconnect.
* That is, your subscriptions remain intact as the client connects and disconnects.
*
* @param node
*
* Optional node name if you wish to only retrieve subscriptions for a particular node.
*
* @return uuid
*
* The return value is the unique elementID of the IQ stanza that was sent.
*
* The server's response to the request will be reported via the appropriate delegate methods.
*
* @see xmppPubSub:didRetrieveSubscriptions:
* @see xmppPubSub:didNotRetrieveSubscriptions:
*
* @see xmppPubSub:didRetrieveSubscriptions:forNode:
* @see xmppPubSub:didNotRetrieveSubscriptions:forNode:
**/
- (NSString *)retrieveSubscriptions;
- (NSString *)retrieveSubscriptionsForNode:(NSString *)node;
/**
* @param node
*
* The name of the subscibed node for to configure the subscription.
* This should be the same node name you used when you subscribed.
*
* @param myBareOrFullJid
*
* The appropriate jid that matches the subscription.
* This should be the same jid you used when you subscribed.
*
* If you don't pass a JID, the method defaults to using the full JID.
*
* @param subid
*
* If a subscription identifier (subid) is associated with the subscription,
* the configure request may be required to include the appropriate 'subid' attribute.
* The subid value was returned by the server in the original subscribe response,
* and can also be obtained by retrieving the subscription(s) from the server.
*
* XMPPIQ+XEP_0060 has a category method named "pubsubid" which conveniently
* extracts the subid value from a subscription response.
*
* @return uuid
*
* The return value is the unique elementID of the IQ stanza that was sent.
*
* The server's response to the request will be reported via the appropriate delegate methods.
*
* @see xmppPubSub:didConfigureSubscriptionToNode:withResult:
* @see xmppPubSub:didNotConfigureSubscriptionToNode:withError:
**/
- (NSString *)configureSubscriptionToNode:(NSString *)node
withJID:(XMPPJID *)myBareOrFullJid
subid:(NSString *)subid
options:(NSDictionary *)options;
/**
* Publishes the entry to the given node.
*
* If the server supports automatic node creation, and the node does not yet exist,
* the server may automatically create the node with the default configuration.
*
* @param node
*
* The name of the node to publish to.
*
* @param entry
*
* The entry you wish to publish.
* This is the xml tree that will go inside the <item/>.
*
* @param itemID
*
* This corresponds to the unique id of the published item.
* If you pass the same itemID as a previously published item, then the new entry will replace the old one.
* If you don't pass an itemID, the the server will automatically generate a unique itemID for you.
*
* @param options
*
* You may optionally pass publish options as well.
* This corresponds with section 7.1.5 of XEP-0060.
* Options are passed as a dictionary of key:value(s) pairs.
*
* For example, if you wanted to include the following publish options (from XEP-0223):
* <publish-options>
* <x xmlns='jabber:x:data' type='submit'>
* <field var='FORM_TYPE' type='hidden'>
* <value>http://jabber.org/protocol/pubsub#publish-options</value>
* </field>
* <field var='pubsub#persist_items'>
* <value>true</value>
* </field>
* <field var='pubsub#access_model'>
* <value>whitelist</value>
* </field>
* </x>
* </publish-options>
*
* Then you would simply pass the following dictionary:
* @{ @"pubsub#persist_items" : @(YES),
* @"pubsub#access_model " : @"whitelist" }
*
* @return uuid
*
* The return value is the unique elementID of the IQ stanza that was sent.
*
* The server's response to the request will be reported via the appropriate delegate methods.
*
* @see xmppPubSub:didPublishToNode:withResult:
* @see xmppPubSub:didNotPublishToNode:withError:
**/
- (NSString *)publishToNode:(NSString *)node entry:(NSXMLElement *)entry;
- (NSString *)publishToNode:(NSString *)node entry:(NSXMLElement *)entry withItemID:(NSString *)itemId;
- (NSString *)publishToNode:(NSString *)node
entry:(NSXMLElement *)entry
withItemID:(NSString *)itemId
options:(NSDictionary *)options;
/**
* Creates the given node with optional options.
*
* @param node
*
* The name of the node to create.
*
* @param options
*
* You may optionally pass configure options as well.
* This corresponds with section 8.1.3 of XEP-0060.
* Options are passed as a dictionary of key:value(s) pairs.
*
* @return uuid
*
* The return value is the unique elementID of the IQ stanza that was sent.
*
* The server's response to the request will be reported via the appropriate delegate methods.
*
* @see xmppPubSub:didCreateNode:withIQ:
* @see xmppPubSub:didNotCreateNode:withError:
**/
- (NSString *)createNode:(NSString *)node;
- (NSString *)createNode:(NSString *)node withOptions:(NSDictionary *)options;
/**
* Deletes the given node.
*
* @param node
*
* The name of the node to delete.
* This should be the same node name you used when you created it.
*
* @return uuid
*
* The return value is the unique elementID of the IQ stanza that was sent.
*
* The server's response to the request will be reported via the appropriate delegate methods.
*
* @see xmppPubSub:didDeleteNode:withIQ:
* @see xmppPubSub:didNotDeleteNode:withError:
**/
- (NSString *)deleteNode:(NSString *)node;
/**
* Configures the given node.
*
* @param node
*
* The name of the node to configure.
* This should be the same node name you used when you created it.
*
* @param options
*
* Options are passed as a dictionary of key:value(s) pairs.
*
* @return uuid
*
* The return value is the unique elementID of the IQ stanza that was sent.
*
* The server's response to the request will be reported via the appropriate delegate methods.
*
* @see xmppPubSub:didConfigureNode:withIQ:
* @see xmppPubSub:didNotConfigureNode:withError:
**/
- (NSString *)configureNode:(NSString *)node withOptions:(NSDictionary *)options;
/**
* Retrieves items from given node.
*
* @param node
*
* The name of the node to retrieve items from.
* This should be the same node name you used when you created it.
*
* @param withItemIDs
*
* This corresponds to a list of unique ids of previously published items.
* The server will return the previously published items for those that exists.
* If none of the items exists, an empty items list will be returned.
* If you don't pass any itemIDs, the server will retrieve all items on the given node
*
* @return uuid
*
* The return value is the unique elementID of the IQ stanza that was sent.
*
* The server's response to the request will be reported via the appropriate delegate methods.
*
* @see xmppPubSub:didRetrieveItems:fromNode:
* @see xmppPubSub:didNotRetrieveItems:fromNode:
**/
- (NSString *)retrieveItemsFromNode:(NSString *)node;
- (NSString *)retrieveItemsFromNode:(NSString *)node withItemIDs:(NSArray *)itemIds;
@end
@protocol XMPPPubSubDelegate
@optional
- (void)xmppPubSub:(XMPPPubSub *)sender didSubscribeToNode:(NSString *)node withResult:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didNotSubscribeToNode:(NSString *)node withError:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didUnsubscribeFromNode:(NSString *)node withResult:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didNotUnsubscribeFromNode:(NSString *)node withError:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didRetrieveSubscriptions:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didNotRetrieveSubscriptions:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didRetrieveSubscriptions:(XMPPIQ *)iq forNode:(NSString *)node;
- (void)xmppPubSub:(XMPPPubSub *)sender didNotRetrieveSubscriptions:(XMPPIQ *)iq forNode:(NSString *)node;
- (void)xmppPubSub:(XMPPPubSub *)sender didConfigureSubscriptionToNode:(NSString *)node withResult:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didNotConfigureSubscriptionToNode:(NSString *)node withError:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didPublishToNode:(NSString *)node withResult:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didNotPublishToNode:(NSString *)node withError:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didCreateNode:(NSString *)node withResult:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didNotCreateNode:(NSString *)node withError:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didDeleteNode:(NSString *)node withResult:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didNotDeleteNode:(NSString *)node withError:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didConfigureNode:(NSString *)node withResult:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didNotConfigureNode:(NSString *)node withError:(XMPPIQ *)iq;
- (void)xmppPubSub:(XMPPPubSub *)sender didRetrieveItems:(XMPPIQ *)iq fromNode:(NSString *)node;
- (void)xmppPubSub:(XMPPPubSub *)sender didNotRetrieveItems:(XMPPIQ *)iq fromNode:(NSString *)node;
- (void)xmppPubSub:(XMPPPubSub *)sender didReceiveMessage:(XMPPMessage *)message;
@end