PageRenderTime 61ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/mesageTableView/mesageTableView/XMPP/Extensions/XEP-0060/XMPPPubSub.h

https://gitlab.com/Mr.Tomato/messageTableView
C Header | 344 lines | 53 code | 26 blank | 265 comment | 0 complexity | b3318fb6458fb62815eb2b748e5fa9ed MD5 | raw file
  1. #import <Foundation/Foundation.h>
  2. #import "XMPP.h"
  3. #define _XMPP_PUB_SUB_H
  4. @interface XMPPPubSub : XMPPModule
  5. /**
  6. * Returns whether or not the given message is a PubSub event message.
  7. **/
  8. + (BOOL)isPubSubMessage:(XMPPMessage *)message;
  9. /**
  10. * Creates a PubSub module with the JID of the PubSub service.
  11. * This JID will be the 'to' attribute of outgoing <iq/> element(s).
  12. *
  13. * If you're creating a PEP module, you should pass nil as the serviceJID.
  14. * If you're creating a normal PubSub module, you should pass the JID of the PubSub service.
  15. *
  16. * If you're connected to server 'domain.tld', then the PubSub JID is typically something like 'pubsub.domain.tld'.
  17. * However, the exact format of the JID varies from server to server, and is often configurable.
  18. * If you don't know the PubSub JID beforehand, you may need to use service discovery to find it.
  19. **/
  20. - (id)initWithServiceJID:(XMPPJID *)aServiceJID;
  21. - (id)initWithServiceJID:(XMPPJID *)aServiceJID dispatchQueue:(dispatch_queue_t)queue;
  22. /**
  23. * The JID of the PubSub server the module is to communicate with.
  24. **/
  25. @property (nonatomic, strong, readonly) XMPPJID *serviceJID;
  26. /**
  27. * Sends a subscription request for the given node name.
  28. *
  29. * @param node
  30. *
  31. * The name of the node to subscribe to.
  32. * This may be a leaf node or, if supported by the server, a collection node.
  33. *
  34. * @param myBareOrFullJid
  35. *
  36. * When you subscribe to a PubSub node, you can subscribe with either
  37. * your bare jid (username@domain.tld) or your full jid (username@domain.tld/resource).
  38. *
  39. * If you subscribe with your bare jid, then all resources are subscribed.
  40. * For example, if you subscribe to "/MyTown/CornerCoffeeShop" with your bare jid,
  41. * then your "home" resource will be subscribed, as well as your "work" and "mobile" resources.
  42. * No matter what device you sign into your account with, you'll receive pubsub updates.
  43. *
  44. * Contrast this with subscribing with your full jid. This subscribes you only for the current resource.
  45. * Using the example from above, only the "home" resource would receive pubsub updates for the node.
  46. *
  47. * If you don't pass a JID, the method defaults to using the full JID.
  48. *
  49. * @param options
  50. *
  51. * The optional options dictionary allows you to provide the subscription options in the subscription stanza.
  52. * This corresponds to XEP-0060, Section 6.3.7: Subscribe and Configure
  53. *
  54. * To use example 71 from the spec, you would pass the following dictionary:
  55. *
  56. * @{ @"pubsub#deliver" : @(YES),
  57. * @"pubsub#digest" : @(NO),
  58. * @"pubsub#include_body" : @(NO),
  59. * @"pubsub#show-values" : @[ @"chat", @"online", @"away" ] }
  60. *
  61. * @return uuid
  62. *
  63. * The return value is the unique elementID of the IQ stanza that was sent.
  64. *
  65. * The server's response to the request will be reported via the appropriate delegate methods.
  66. *
  67. * @see xmppPubSub:didSubscribeToNode:withResult:
  68. * @see xmppPubSub:didNotSubscribeToNode:withError:
  69. **/
  70. - (NSString *)subscribeToNode:(NSString *)node;
  71. - (NSString *)subscribeToNode:(NSString *)node withJID:(XMPPJID *)myBareOrFullJid;
  72. - (NSString *)subscribeToNode:(NSString *)node withJID:(XMPPJID *)myBareOrFullJid options:(NSDictionary *)options;
  73. /**
  74. * Sends an unsubscribe request for the given node name.
  75. *
  76. * @param node
  77. *
  78. * The name of the node to unsubscribe from.
  79. * This should be the same node name you used when you subscribed.
  80. *
  81. * @param myBareOrFullJid
  82. *
  83. * The appropriate jid that matches the subscription.
  84. * This should be the same jid you used when you subscribed.
  85. *
  86. * If you don't pass a JID, the method defaults to using the full JID.
  87. *
  88. * @param subid
  89. *
  90. * If a subscription identifier (subid) is associated with the subscription,
  91. * the unsubscribe request may be required to include the appropriate 'subid' attribute.
  92. * The subid value was returned by the server in the original subscribe response,
  93. * and can also be obtained by retrieving the subscription(s) from the server.
  94. *
  95. * XMPPIQ+XEP_0060 has a category method named "pubsubid" which conveniently
  96. * extracts the subid value from a subscription response.
  97. *
  98. * @return uuid
  99. *
  100. * The return value is the unique elementID of the IQ stanza that was sent.
  101. *
  102. * The server's response to the request will be reported via the appropriate delegate methods.
  103. *
  104. * @see xmppPubSub:didUnsubscribeFromNode:withResult:
  105. * @see xmppPubSub:didNotUnsubscribeFromNode:(NSString *)node withError:
  106. **/
  107. - (NSString *)unsubscribeFromNode:(NSString *)node;
  108. - (NSString *)unsubscribeFromNode:(NSString *)node withJID:(XMPPJID *)myBareOrFullJid;
  109. - (NSString *)unsubscribeFromNode:(NSString *)node withJID:(XMPPJID *)myBareOrFullJid subid:(NSString *)subid;
  110. /**
  111. * Fetches the current PubSub subscriptions from the server.
  112. * You can fetch all subscriptions, or just subscriptions for a particular node.
  113. *
  114. * Keep in mind that your PubSub subscriptions don't typically disappear when you disconnect.
  115. * That is, your subscriptions remain intact as the client connects and disconnects.
  116. *
  117. * @param node
  118. *
  119. * Optional node name if you wish to only retrieve subscriptions for a particular node.
  120. *
  121. * @return uuid
  122. *
  123. * The return value is the unique elementID of the IQ stanza that was sent.
  124. *
  125. * The server's response to the request will be reported via the appropriate delegate methods.
  126. *
  127. * @see xmppPubSub:didRetrieveSubscriptions:
  128. * @see xmppPubSub:didNotRetrieveSubscriptions:
  129. *
  130. * @see xmppPubSub:didRetrieveSubscriptions:forNode:
  131. * @see xmppPubSub:didNotRetrieveSubscriptions:forNode:
  132. **/
  133. - (NSString *)retrieveSubscriptions;
  134. - (NSString *)retrieveSubscriptionsForNode:(NSString *)node;
  135. /**
  136. * @param node
  137. *
  138. * The name of the subscibed node for to configure the subscription.
  139. * This should be the same node name you used when you subscribed.
  140. *
  141. * @param myBareOrFullJid
  142. *
  143. * The appropriate jid that matches the subscription.
  144. * This should be the same jid you used when you subscribed.
  145. *
  146. * If you don't pass a JID, the method defaults to using the full JID.
  147. *
  148. * @param subid
  149. *
  150. * If a subscription identifier (subid) is associated with the subscription,
  151. * the configure request may be required to include the appropriate 'subid' attribute.
  152. * The subid value was returned by the server in the original subscribe response,
  153. * and can also be obtained by retrieving the subscription(s) from the server.
  154. *
  155. * XMPPIQ+XEP_0060 has a category method named "pubsubid" which conveniently
  156. * extracts the subid value from a subscription response.
  157. *
  158. * @return uuid
  159. *
  160. * The return value is the unique elementID of the IQ stanza that was sent.
  161. *
  162. * The server's response to the request will be reported via the appropriate delegate methods.
  163. *
  164. * @see xmppPubSub:didConfigureSubscriptionToNode:withResult:
  165. * @see xmppPubSub:didNotConfigureSubscriptionToNode:withError:
  166. **/
  167. - (NSString *)configureSubscriptionToNode:(NSString *)node
  168. withJID:(XMPPJID *)myBareOrFullJid
  169. subid:(NSString *)subid
  170. options:(NSDictionary *)options;
  171. /**
  172. * Publishes the entry to the given node.
  173. *
  174. * If the server supports automatic node creation, and the node does not yet exist,
  175. * the server may automatically create the node with the default configuration.
  176. *
  177. * @param node
  178. *
  179. * The name of the node to publish to.
  180. *
  181. * @param entry
  182. *
  183. * The entry you wish to publish.
  184. * This is the xml tree that will go inside the <item/>.
  185. *
  186. * @param itemID
  187. *
  188. * This corresponds to the unique id of the published item.
  189. * If you pass the same itemID as a previously published item, then the new entry will replace the old one.
  190. * If you don't pass an itemID, the the server will automatically generate a unique itemID for you.
  191. *
  192. * @param options
  193. *
  194. * You may optionally pass publish options as well.
  195. * This corresponds with section 7.1.5 of XEP-0060.
  196. * Options are passed as a dictionary of key:value(s) pairs.
  197. *
  198. * For example, if you wanted to include the following publish options (from XEP-0223):
  199. * <publish-options>
  200. * <x xmlns='jabber:x:data' type='submit'>
  201. * <field var='FORM_TYPE' type='hidden'>
  202. * <value>http://jabber.org/protocol/pubsub#publish-options</value>
  203. * </field>
  204. * <field var='pubsub#persist_items'>
  205. * <value>true</value>
  206. * </field>
  207. * <field var='pubsub#access_model'>
  208. * <value>whitelist</value>
  209. * </field>
  210. * </x>
  211. * </publish-options>
  212. *
  213. * Then you would simply pass the following dictionary:
  214. * @{ @"pubsub#persist_items" : @(YES),
  215. * @"pubsub#access_model " : @"whitelist" }
  216. *
  217. * @return uuid
  218. *
  219. * The return value is the unique elementID of the IQ stanza that was sent.
  220. *
  221. * The server's response to the request will be reported via the appropriate delegate methods.
  222. *
  223. * @see xmppPubSub:didPublishToNode:withResult:
  224. * @see xmppPubSub:didNotPublishToNode:withError:
  225. **/
  226. - (NSString *)publishToNode:(NSString *)node entry:(NSXMLElement *)entry;
  227. - (NSString *)publishToNode:(NSString *)node entry:(NSXMLElement *)entry withItemID:(NSString *)itemId;
  228. - (NSString *)publishToNode:(NSString *)node
  229. entry:(NSXMLElement *)entry
  230. withItemID:(NSString *)itemId
  231. options:(NSDictionary *)options;
  232. /**
  233. * Creates the given node with optional options.
  234. *
  235. * @param node
  236. *
  237. * The name of the node to create.
  238. *
  239. * @param options
  240. *
  241. * You may optionally pass configure options as well.
  242. * This corresponds with section 8.1.3 of XEP-0060.
  243. * Options are passed as a dictionary of key:value(s) pairs.
  244. *
  245. * @return uuid
  246. *
  247. * The return value is the unique elementID of the IQ stanza that was sent.
  248. *
  249. * The server's response to the request will be reported via the appropriate delegate methods.
  250. *
  251. * @see xmppPubSub:didCreateNode:withIQ:
  252. * @see xmppPubSub:didNotCreateNode:withError:
  253. **/
  254. - (NSString *)createNode:(NSString *)node;
  255. - (NSString *)createNode:(NSString *)node withOptions:(NSDictionary *)options;
  256. /**
  257. * Deletes the given node.
  258. *
  259. * @param node
  260. *
  261. * The name of the node to delete.
  262. * This should be the same node name you used when you created it.
  263. *
  264. * @return uuid
  265. *
  266. * The return value is the unique elementID of the IQ stanza that was sent.
  267. *
  268. * The server's response to the request will be reported via the appropriate delegate methods.
  269. *
  270. * @see xmppPubSub:didDeleteNode:withIQ:
  271. * @see xmppPubSub:didNotDeleteNode:withError:
  272. **/
  273. - (NSString *)deleteNode:(NSString *)node;
  274. /**
  275. * Configures the given node.
  276. *
  277. * @param node
  278. *
  279. * The name of the node to configure.
  280. * This should be the same node name you used when you created it.
  281. *
  282. * @param options
  283. *
  284. * Options are passed as a dictionary of key:value(s) pairs.
  285. *
  286. * @return uuid
  287. *
  288. * The return value is the unique elementID of the IQ stanza that was sent.
  289. *
  290. * The server's response to the request will be reported via the appropriate delegate methods.
  291. *
  292. * @see xmppPubSub:didConfigureNode:withIQ:
  293. * @see xmppPubSub:didNotConfigureNode:withError:
  294. **/
  295. - (NSString *)configureNode:(NSString *)node withOptions:(NSDictionary *)options;
  296. @end
  297. @protocol XMPPPubSubDelegate
  298. @optional
  299. - (void)xmppPubSub:(XMPPPubSub *)sender didSubscribeToNode:(NSString *)node withResult:(XMPPIQ *)iq;
  300. - (void)xmppPubSub:(XMPPPubSub *)sender didNotSubscribeToNode:(NSString *)node withError:(XMPPIQ *)iq;
  301. - (void)xmppPubSub:(XMPPPubSub *)sender didUnsubscribeFromNode:(NSString *)node withResult:(XMPPIQ *)iq;
  302. - (void)xmppPubSub:(XMPPPubSub *)sender didNotUnsubscribeFromNode:(NSString *)node withError:(XMPPIQ *)iq;
  303. - (void)xmppPubSub:(XMPPPubSub *)sender didRetrieveSubscriptions:(XMPPIQ *)iq;
  304. - (void)xmppPubSub:(XMPPPubSub *)sender didNotRetrieveSubscriptions:(XMPPIQ *)iq;
  305. - (void)xmppPubSub:(XMPPPubSub *)sender didRetrieveSubscriptions:(XMPPIQ *)iq forNode:(NSString *)node;
  306. - (void)xmppPubSub:(XMPPPubSub *)sender didNotRetrieveSubscriptions:(XMPPIQ *)iq forNode:(NSString *)node;
  307. - (void)xmppPubSub:(XMPPPubSub *)sender didConfigureSubscriptionToNode:(NSString *)node withResult:(XMPPIQ *)iq;
  308. - (void)xmppPubSub:(XMPPPubSub *)sender didNotConfigureSubscriptionToNode:(NSString *)node withError:(XMPPIQ *)iq;
  309. - (void)xmppPubSub:(XMPPPubSub *)sender didPublishToNode:(NSString *)node withResult:(XMPPIQ *)iq;
  310. - (void)xmppPubSub:(XMPPPubSub *)sender didNotPublishToNode:(NSString *)node withError:(XMPPIQ *)iq;
  311. - (void)xmppPubSub:(XMPPPubSub *)sender didCreateNode:(NSString *)node withResult:(XMPPIQ *)iq;
  312. - (void)xmppPubSub:(XMPPPubSub *)sender didNotCreateNode:(NSString *)node withError:(XMPPIQ *)iq;
  313. - (void)xmppPubSub:(XMPPPubSub *)sender didDeleteNode:(NSString *)node withResult:(XMPPIQ *)iq;
  314. - (void)xmppPubSub:(XMPPPubSub *)sender didNotDeleteNode:(NSString *)node withError:(XMPPIQ *)iq;
  315. - (void)xmppPubSub:(XMPPPubSub *)sender didConfigureNode:(NSString *)node withResult:(XMPPIQ *)iq;
  316. - (void)xmppPubSub:(XMPPPubSub *)sender didNotConfigureNode:(NSString *)node withError:(XMPPIQ *)iq;
  317. - (void)xmppPubSub:(XMPPPubSub *)sender didReceiveMessage:(XMPPMessage *)message;
  318. @end