You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

343 lines
13 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2004--2005, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef _rostermodule_h_
  28. #define _rostermodule_h_
  29. #include "talk/xmpp/module.h"
  30. namespace buzz {
  31. class XmppRosterModule;
  32. // The main way you initialize and use the module would be like this:
  33. // XmppRosterModule *roster_module = XmppRosterModule::Create();
  34. // roster_module->RegisterEngine(engine);
  35. // roster_module->BroadcastPresence();
  36. // roster_module->RequestRosterUpdate();
  37. //! This enum captures the valid values for the show attribute in a presence
  38. //! stanza
  39. enum XmppPresenceShow
  40. {
  41. XMPP_PRESENCE_CHAT = 0,
  42. XMPP_PRESENCE_DEFAULT = 1,
  43. XMPP_PRESENCE_AWAY = 2,
  44. XMPP_PRESENCE_XA = 3,
  45. XMPP_PRESENCE_DND = 4,
  46. };
  47. //! These are the valid subscription states in a roster contact. This
  48. //! represents the combination of the subscription and ask attributes
  49. enum XmppSubscriptionState
  50. {
  51. XMPP_SUBSCRIPTION_NONE = 0,
  52. XMPP_SUBSCRIPTION_NONE_ASKED = 1,
  53. XMPP_SUBSCRIPTION_TO = 2,
  54. XMPP_SUBSCRIPTION_FROM = 3,
  55. XMPP_SUBSCRIPTION_FROM_ASKED = 4,
  56. XMPP_SUBSCRIPTION_BOTH = 5,
  57. };
  58. //! These represent the valid types of presence stanzas for managing
  59. //! subscriptions
  60. enum XmppSubscriptionRequestType
  61. {
  62. XMPP_REQUEST_SUBSCRIBE = 0,
  63. XMPP_REQUEST_UNSUBSCRIBE = 1,
  64. XMPP_REQUEST_SUBSCRIBED = 2,
  65. XMPP_REQUEST_UNSUBSCRIBED = 3,
  66. };
  67. enum XmppPresenceAvailable {
  68. XMPP_PRESENCE_UNAVAILABLE = 0,
  69. XMPP_PRESENCE_AVAILABLE = 1,
  70. XMPP_PRESENCE_ERROR = 2,
  71. };
  72. enum XmppPresenceConnectionStatus {
  73. XMPP_CONNECTION_STATUS_UNKNOWN = 0,
  74. XMPP_CONNECTION_STATUS_CONNECTING = 1,
  75. XMPP_CONNECTION_STATUS_CONNECTED = 2,
  76. XMPP_CONNECTION_STATUS_HANGUP = 3,
  77. };
  78. //! Presence Information
  79. //! This class stores both presence information for outgoing presence and is
  80. //! returned by methods in XmppRosterModule to represent recieved incoming
  81. //! presence information. When this class is writeable (non-const) then each
  82. //! update to any property will set the inner xml. Setting the raw_xml will
  83. //! rederive all of the other properties.
  84. class XmppPresence {
  85. public:
  86. virtual ~XmppPresence() {}
  87. //! Create a new Presence
  88. //! This is typically only used when sending a directed presence
  89. static XmppPresence* Create();
  90. //! The Jid of for the presence information.
  91. //! Typically this will be a full Jid with resource specified.
  92. virtual const Jid jid() const = 0;
  93. //! Is the contact available?
  94. virtual XmppPresenceAvailable available() const = 0;
  95. //! Sets if the user is available or not
  96. virtual XmppReturnStatus set_available(XmppPresenceAvailable available) = 0;
  97. //! The show value of the presence info
  98. virtual XmppPresenceShow presence_show() const = 0;
  99. //! Set the presence show value
  100. virtual XmppReturnStatus set_presence_show(XmppPresenceShow show) = 0;
  101. //! The Priority of the presence info
  102. virtual int priority() const = 0;
  103. //! Set the priority of the presence
  104. virtual XmppReturnStatus set_priority(int priority) = 0;
  105. //! The plain text status of the presence info.
  106. //! If there are multiple status because of language, this will either be a
  107. //! status that is not tagged for language or the first available
  108. virtual const std::string status() const = 0;
  109. //! Sets the status for the presence info.
  110. //! If there is more than one status present already then this will remove
  111. //! them all and replace it with one status element we no specified language
  112. virtual XmppReturnStatus set_status(const std::string& status) = 0;
  113. //! The connection status
  114. virtual XmppPresenceConnectionStatus connection_status() const = 0;
  115. //! The focus obfuscated GAIA id
  116. virtual const std::string google_user_id() const = 0;
  117. //! The nickname in the presence
  118. virtual const std::string nickname() const = 0;
  119. //! The raw xml of the presence update
  120. virtual const XmlElement* raw_xml() const = 0;
  121. //! Sets the raw presence stanza for the presence update
  122. //! This will cause all other data items in this structure to be rederived
  123. virtual XmppReturnStatus set_raw_xml(const XmlElement * xml) = 0;
  124. };
  125. //! A contact as given by the server
  126. class XmppRosterContact {
  127. public:
  128. virtual ~XmppRosterContact() {}
  129. //! Create a new roster contact
  130. //! This is typically only used when doing a roster update/add
  131. static XmppRosterContact* Create();
  132. //! The jid for the contact.
  133. //! Typically this will be a bare Jid.
  134. virtual const Jid jid() const = 0;
  135. //! Sets the jid for the roster contact update
  136. virtual XmppReturnStatus set_jid(const Jid& jid) = 0;
  137. //! The name (nickname) stored for this contact
  138. virtual const std::string name() const = 0;
  139. //! Sets the name
  140. virtual XmppReturnStatus set_name(const std::string& name) = 0;
  141. //! The Presence subscription state stored on the server for this contact
  142. //! This is never settable and will be ignored when generating a roster
  143. //! add/update request
  144. virtual XmppSubscriptionState subscription_state() const = 0;
  145. //! The number of Groups applied to this contact
  146. virtual size_t GetGroupCount() const = 0;
  147. //! Gets a Group applied to the contact based on index.
  148. //! range
  149. virtual const std::string GetGroup(size_t index) const = 0;
  150. //! Adds a group to this contact.
  151. //! This will return a bad argument error if the group is already there.
  152. virtual XmppReturnStatus AddGroup(const std::string& group) = 0;
  153. //! Removes a group from the contact.
  154. //! This will return an error if the group cannot be found in the group list.
  155. virtual XmppReturnStatus RemoveGroup(const std::string& group) = 0;
  156. //! The raw xml for this roster contact
  157. virtual const XmlElement* raw_xml() const = 0;
  158. //! Sets the raw presence stanza for the contact update/add
  159. //! This will cause all other data items in this structure to be rederived
  160. virtual XmppReturnStatus set_raw_xml(const XmlElement * xml) = 0;
  161. };
  162. //! The XmppRosterHandler is an interface for callbacks from the module
  163. class XmppRosterHandler {
  164. public:
  165. virtual ~XmppRosterHandler() {}
  166. //! A request for a subscription has come in.
  167. //! Typically, the UI will ask the user if it is okay to let the requester
  168. //! get presence notifications for the user. The response is send back
  169. //! by calling ApproveSubscriber or CancelSubscriber.
  170. virtual void SubscriptionRequest(XmppRosterModule* roster,
  171. const Jid& requesting_jid,
  172. XmppSubscriptionRequestType type,
  173. const XmlElement* raw_xml) = 0;
  174. //! Some type of presence error has occured
  175. virtual void SubscriptionError(XmppRosterModule* roster,
  176. const Jid& from,
  177. const XmlElement* raw_xml) = 0;
  178. virtual void RosterError(XmppRosterModule* roster,
  179. const XmlElement* raw_xml) = 0;
  180. //! New presence information has come in
  181. //! The user is notified with the presence object directly. This info is also
  182. //! added to the store accessable from the engine.
  183. virtual void IncomingPresenceChanged(XmppRosterModule* roster,
  184. const XmppPresence* presence) = 0;
  185. //! A contact has changed
  186. //! This indicates that the data for a contact may have changed. No
  187. //! contacts have been added or removed.
  188. virtual void ContactChanged(XmppRosterModule* roster,
  189. const XmppRosterContact* old_contact,
  190. size_t index) = 0;
  191. //! A set of contacts have been added
  192. //! These contacts may have been added in response to the original roster
  193. //! request or due to a "roster push" from the server.
  194. virtual void ContactsAdded(XmppRosterModule* roster,
  195. size_t index, size_t number) = 0;
  196. //! A contact has been removed
  197. //! This contact has been removed form the list.
  198. virtual void ContactRemoved(XmppRosterModule* roster,
  199. const XmppRosterContact* removed_contact,
  200. size_t index) = 0;
  201. };
  202. //! An XmppModule for handle roster and presence functionality
  203. class XmppRosterModule : public XmppModule {
  204. public:
  205. //! Creates a new XmppRosterModule
  206. static XmppRosterModule * Create();
  207. virtual ~XmppRosterModule() {}
  208. //! Sets the roster handler (callbacks) for the module
  209. virtual XmppReturnStatus set_roster_handler(XmppRosterHandler * handler) = 0;
  210. //! Gets the roster handler for the module
  211. virtual XmppRosterHandler* roster_handler() = 0;
  212. // USER PRESENCE STATE -------------------------------------------------------
  213. //! Gets the aggregate outgoing presence
  214. //! This object is non-const and be edited directly. No update is sent
  215. //! to the server until a Broadcast is sent
  216. virtual XmppPresence* outgoing_presence() = 0;
  217. //! Broadcasts that the user is available.
  218. //! Nothing with respect to presence is sent until this is called.
  219. virtual XmppReturnStatus BroadcastPresence() = 0;
  220. //! Sends a directed presence to a Jid
  221. //! Note that the client doesn't store where directed presence notifications
  222. //! have been sent. The server can keep the appropriate state
  223. virtual XmppReturnStatus SendDirectedPresence(const XmppPresence* presence,
  224. const Jid& to_jid) = 0;
  225. // INCOMING PRESENCE STATUS --------------------------------------------------
  226. //! Returns the number of incoming presence data recorded
  227. virtual size_t GetIncomingPresenceCount() = 0;
  228. //! Returns an incoming presence datum based on index
  229. virtual const XmppPresence* GetIncomingPresence(size_t index) = 0;
  230. //! Gets the number of presence data for a bare Jid
  231. //! There may be a datum per resource
  232. virtual size_t GetIncomingPresenceForJidCount(const Jid& jid) = 0;
  233. //! Returns a single presence data for a Jid based on index
  234. virtual const XmppPresence* GetIncomingPresenceForJid(const Jid& jid,
  235. size_t index) = 0;
  236. // ROSTER MANAGEMENT ---------------------------------------------------------
  237. //! Requests an update of the roster from the server
  238. //! This must be called to initialize the client side cache of the roster
  239. //! After this is sent the server should keep this module apprised of any
  240. //! changes.
  241. virtual XmppReturnStatus RequestRosterUpdate() = 0;
  242. //! Returns the number of contacts in the roster
  243. virtual size_t GetRosterContactCount() = 0;
  244. //! Returns a contact by index
  245. virtual const XmppRosterContact* GetRosterContact(size_t index) = 0;
  246. //! Finds a contact by Jid
  247. virtual const XmppRosterContact* FindRosterContact(const Jid& jid) = 0;
  248. //! Send a request to the server to add a contact
  249. //! Note that the contact won't show up in the roster until the server can
  250. //! respond. This happens async when the socket is being serviced
  251. virtual XmppReturnStatus RequestRosterChange(
  252. const XmppRosterContact* contact) = 0;
  253. //! Request that the server remove a contact
  254. //! The jabber protocol specifies that the server should also cancel any
  255. //! subscriptions when this is done. Like adding, this contact won't be
  256. //! removed until the server responds.
  257. virtual XmppReturnStatus RequestRosterRemove(const Jid& jid) = 0;
  258. // SUBSCRIPTION MANAGEMENT ---------------------------------------------------
  259. //! Request a subscription to presence notifications form a Jid
  260. virtual XmppReturnStatus RequestSubscription(const Jid& jid) = 0;
  261. //! Cancel a subscription to presence notifications from a Jid
  262. virtual XmppReturnStatus CancelSubscription(const Jid& jid) = 0;
  263. //! Approve a request to deliver presence notifications to a jid
  264. virtual XmppReturnStatus ApproveSubscriber(const Jid& jid) = 0;
  265. //! Deny or cancel presence notification deliver to a jid
  266. virtual XmppReturnStatus CancelSubscriber(const Jid& jid) = 0;
  267. };
  268. }
  269. #endif