OLD | NEW |
(Empty) | |
| 1 // Copyright 2004 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef WEBRTC_LIBJINGLE_XMPP_ROSTERMODULE_H_ |
| 6 #define WEBRTC_LIBJINGLE_XMPP_ROSTERMODULE_H_ |
| 7 |
| 8 #include "third_party/libjingle_xmpp/xmpp/module.h" |
| 9 |
| 10 namespace buzz { |
| 11 |
| 12 class XmppRosterModule; |
| 13 |
| 14 // The main way you initialize and use the module would be like this: |
| 15 // XmppRosterModule *roster_module = XmppRosterModule::Create(); |
| 16 // roster_module->RegisterEngine(engine); |
| 17 // roster_module->BroadcastPresence(); |
| 18 // roster_module->RequestRosterUpdate(); |
| 19 |
| 20 //! This enum captures the valid values for the show attribute in a presence |
| 21 //! stanza |
| 22 enum XmppPresenceShow |
| 23 { |
| 24 XMPP_PRESENCE_CHAT = 0, |
| 25 XMPP_PRESENCE_DEFAULT = 1, |
| 26 XMPP_PRESENCE_AWAY = 2, |
| 27 XMPP_PRESENCE_XA = 3, |
| 28 XMPP_PRESENCE_DND = 4, |
| 29 }; |
| 30 |
| 31 //! These are the valid subscription states in a roster contact. This |
| 32 //! represents the combination of the subscription and ask attributes |
| 33 enum XmppSubscriptionState |
| 34 { |
| 35 XMPP_SUBSCRIPTION_NONE = 0, |
| 36 XMPP_SUBSCRIPTION_NONE_ASKED = 1, |
| 37 XMPP_SUBSCRIPTION_TO = 2, |
| 38 XMPP_SUBSCRIPTION_FROM = 3, |
| 39 XMPP_SUBSCRIPTION_FROM_ASKED = 4, |
| 40 XMPP_SUBSCRIPTION_BOTH = 5, |
| 41 }; |
| 42 |
| 43 //! These represent the valid types of presence stanzas for managing |
| 44 //! subscriptions |
| 45 enum XmppSubscriptionRequestType |
| 46 { |
| 47 XMPP_REQUEST_SUBSCRIBE = 0, |
| 48 XMPP_REQUEST_UNSUBSCRIBE = 1, |
| 49 XMPP_REQUEST_SUBSCRIBED = 2, |
| 50 XMPP_REQUEST_UNSUBSCRIBED = 3, |
| 51 }; |
| 52 |
| 53 enum XmppPresenceAvailable { |
| 54 XMPP_PRESENCE_UNAVAILABLE = 0, |
| 55 XMPP_PRESENCE_AVAILABLE = 1, |
| 56 XMPP_PRESENCE_ERROR = 2, |
| 57 }; |
| 58 |
| 59 enum XmppPresenceConnectionStatus { |
| 60 XMPP_CONNECTION_STATUS_UNKNOWN = 0, |
| 61 // Status set by the server while the user is being rung. |
| 62 XMPP_CONNECTION_STATUS_CONNECTING = 1, |
| 63 // Status set by the client when the user has accepted the ring but before |
| 64 // the client has joined the call. |
| 65 XMPP_CONNECTION_STATUS_JOINING = 2, |
| 66 // Status set by the client as part of joining the call. |
| 67 XMPP_CONNECTION_STATUS_CONNECTED = 3, |
| 68 XMPP_CONNECTION_STATUS_HANGUP = 4, |
| 69 }; |
| 70 |
| 71 //! Presence Information |
| 72 //! This class stores both presence information for outgoing presence and is |
| 73 //! returned by methods in XmppRosterModule to represent recieved incoming |
| 74 //! presence information. When this class is writeable (non-const) then each |
| 75 //! update to any property will set the inner xml. Setting the raw_xml will |
| 76 //! rederive all of the other properties. |
| 77 class XmppPresence { |
| 78 public: |
| 79 virtual ~XmppPresence() {} |
| 80 |
| 81 //! Create a new Presence |
| 82 //! This is typically only used when sending a directed presence |
| 83 static XmppPresence* Create(); |
| 84 |
| 85 //! The Jid of for the presence information. |
| 86 //! Typically this will be a full Jid with resource specified. |
| 87 virtual const Jid jid() const = 0; |
| 88 |
| 89 //! Is the contact available? |
| 90 virtual XmppPresenceAvailable available() const = 0; |
| 91 |
| 92 //! Sets if the user is available or not |
| 93 virtual XmppReturnStatus set_available(XmppPresenceAvailable available) = 0; |
| 94 |
| 95 //! The show value of the presence info |
| 96 virtual XmppPresenceShow presence_show() const = 0; |
| 97 |
| 98 //! Set the presence show value |
| 99 virtual XmppReturnStatus set_presence_show(XmppPresenceShow show) = 0; |
| 100 |
| 101 //! The Priority of the presence info |
| 102 virtual int priority() const = 0; |
| 103 |
| 104 //! Set the priority of the presence |
| 105 virtual XmppReturnStatus set_priority(int priority) = 0; |
| 106 |
| 107 //! The plain text status of the presence info. |
| 108 //! If there are multiple status because of language, this will either be a |
| 109 //! status that is not tagged for language or the first available |
| 110 virtual const std::string status() const = 0; |
| 111 |
| 112 //! Sets the status for the presence info. |
| 113 //! If there is more than one status present already then this will remove |
| 114 //! them all and replace it with one status element we no specified language |
| 115 virtual XmppReturnStatus set_status(const std::string& status) = 0; |
| 116 |
| 117 //! The connection status |
| 118 virtual XmppPresenceConnectionStatus connection_status() const = 0; |
| 119 |
| 120 //! The focus obfuscated GAIA id |
| 121 virtual const std::string google_user_id() const = 0; |
| 122 |
| 123 //! The nickname in the presence |
| 124 virtual const std::string nickname() const = 0; |
| 125 |
| 126 //! The raw xml of the presence update |
| 127 virtual const XmlElement* raw_xml() const = 0; |
| 128 |
| 129 //! Sets the raw presence stanza for the presence update |
| 130 //! This will cause all other data items in this structure to be rederived |
| 131 virtual XmppReturnStatus set_raw_xml(const XmlElement * xml) = 0; |
| 132 }; |
| 133 |
| 134 //! A contact as given by the server |
| 135 class XmppRosterContact { |
| 136 public: |
| 137 virtual ~XmppRosterContact() {} |
| 138 |
| 139 //! Create a new roster contact |
| 140 //! This is typically only used when doing a roster update/add |
| 141 static XmppRosterContact* Create(); |
| 142 |
| 143 //! The jid for the contact. |
| 144 //! Typically this will be a bare Jid. |
| 145 virtual const Jid jid() const = 0; |
| 146 |
| 147 //! Sets the jid for the roster contact update |
| 148 virtual XmppReturnStatus set_jid(const Jid& jid) = 0; |
| 149 |
| 150 //! The name (nickname) stored for this contact |
| 151 virtual const std::string name() const = 0; |
| 152 |
| 153 //! Sets the name |
| 154 virtual XmppReturnStatus set_name(const std::string& name) = 0; |
| 155 |
| 156 //! The Presence subscription state stored on the server for this contact |
| 157 //! This is never settable and will be ignored when generating a roster |
| 158 //! add/update request |
| 159 virtual XmppSubscriptionState subscription_state() const = 0; |
| 160 |
| 161 //! The number of Groups applied to this contact |
| 162 virtual size_t GetGroupCount() const = 0; |
| 163 |
| 164 //! Gets a Group applied to the contact based on index. |
| 165 //! range |
| 166 virtual const std::string GetGroup(size_t index) const = 0; |
| 167 |
| 168 //! Adds a group to this contact. |
| 169 //! This will return a bad argument error if the group is already there. |
| 170 virtual XmppReturnStatus AddGroup(const std::string& group) = 0; |
| 171 |
| 172 //! Removes a group from the contact. |
| 173 //! This will return an error if the group cannot be found in the group list. |
| 174 virtual XmppReturnStatus RemoveGroup(const std::string& group) = 0; |
| 175 |
| 176 //! The raw xml for this roster contact |
| 177 virtual const XmlElement* raw_xml() const = 0; |
| 178 |
| 179 //! Sets the raw presence stanza for the contact update/add |
| 180 //! This will cause all other data items in this structure to be rederived |
| 181 virtual XmppReturnStatus set_raw_xml(const XmlElement * xml) = 0; |
| 182 }; |
| 183 |
| 184 //! The XmppRosterHandler is an interface for callbacks from the module |
| 185 class XmppRosterHandler { |
| 186 public: |
| 187 virtual ~XmppRosterHandler() {} |
| 188 |
| 189 //! A request for a subscription has come in. |
| 190 //! Typically, the UI will ask the user if it is okay to let the requester |
| 191 //! get presence notifications for the user. The response is send back |
| 192 //! by calling ApproveSubscriber or CancelSubscriber. |
| 193 virtual void SubscriptionRequest(XmppRosterModule* roster, |
| 194 const Jid& requesting_jid, |
| 195 XmppSubscriptionRequestType type, |
| 196 const XmlElement* raw_xml) = 0; |
| 197 |
| 198 //! Some type of presence error has occured |
| 199 virtual void SubscriptionError(XmppRosterModule* roster, |
| 200 const Jid& from, |
| 201 const XmlElement* raw_xml) = 0; |
| 202 |
| 203 virtual void RosterError(XmppRosterModule* roster, |
| 204 const XmlElement* raw_xml) = 0; |
| 205 |
| 206 //! New presence information has come in |
| 207 //! The user is notified with the presence object directly. This info is also |
| 208 //! added to the store accessable from the engine. |
| 209 virtual void IncomingPresenceChanged(XmppRosterModule* roster, |
| 210 const XmppPresence* presence) = 0; |
| 211 |
| 212 //! A contact has changed |
| 213 //! This indicates that the data for a contact may have changed. No |
| 214 //! contacts have been added or removed. |
| 215 virtual void ContactChanged(XmppRosterModule* roster, |
| 216 const XmppRosterContact* old_contact, |
| 217 size_t index) = 0; |
| 218 |
| 219 //! A set of contacts have been added |
| 220 //! These contacts may have been added in response to the original roster |
| 221 //! request or due to a "roster push" from the server. |
| 222 virtual void ContactsAdded(XmppRosterModule* roster, |
| 223 size_t index, size_t number) = 0; |
| 224 |
| 225 //! A contact has been removed |
| 226 //! This contact has been removed form the list. |
| 227 virtual void ContactRemoved(XmppRosterModule* roster, |
| 228 const XmppRosterContact* removed_contact, |
| 229 size_t index) = 0; |
| 230 |
| 231 }; |
| 232 |
| 233 //! An XmppModule for handle roster and presence functionality |
| 234 class XmppRosterModule : public XmppModule { |
| 235 public: |
| 236 //! Creates a new XmppRosterModule |
| 237 static XmppRosterModule * Create(); |
| 238 virtual ~XmppRosterModule() {} |
| 239 |
| 240 //! Sets the roster handler (callbacks) for the module |
| 241 virtual XmppReturnStatus set_roster_handler(XmppRosterHandler * handler) = 0; |
| 242 |
| 243 //! Gets the roster handler for the module |
| 244 virtual XmppRosterHandler* roster_handler() = 0; |
| 245 |
| 246 // USER PRESENCE STATE ------------------------------------------------------- |
| 247 |
| 248 //! Gets the aggregate outgoing presence |
| 249 //! This object is non-const and be edited directly. No update is sent |
| 250 //! to the server until a Broadcast is sent |
| 251 virtual XmppPresence* outgoing_presence() = 0; |
| 252 |
| 253 //! Broadcasts that the user is available. |
| 254 //! Nothing with respect to presence is sent until this is called. |
| 255 virtual XmppReturnStatus BroadcastPresence() = 0; |
| 256 |
| 257 //! Sends a directed presence to a Jid |
| 258 //! Note that the client doesn't store where directed presence notifications |
| 259 //! have been sent. The server can keep the appropriate state |
| 260 virtual XmppReturnStatus SendDirectedPresence(const XmppPresence* presence, |
| 261 const Jid& to_jid) = 0; |
| 262 |
| 263 // INCOMING PRESENCE STATUS -------------------------------------------------- |
| 264 |
| 265 //! Returns the number of incoming presence data recorded |
| 266 virtual size_t GetIncomingPresenceCount() = 0; |
| 267 |
| 268 //! Returns an incoming presence datum based on index |
| 269 virtual const XmppPresence* GetIncomingPresence(size_t index) = 0; |
| 270 |
| 271 //! Gets the number of presence data for a bare Jid |
| 272 //! There may be a datum per resource |
| 273 virtual size_t GetIncomingPresenceForJidCount(const Jid& jid) = 0; |
| 274 |
| 275 //! Returns a single presence data for a Jid based on index |
| 276 virtual const XmppPresence* GetIncomingPresenceForJid(const Jid& jid, |
| 277 size_t index) = 0; |
| 278 |
| 279 // ROSTER MANAGEMENT --------------------------------------------------------- |
| 280 |
| 281 //! Requests an update of the roster from the server |
| 282 //! This must be called to initialize the client side cache of the roster |
| 283 //! After this is sent the server should keep this module apprised of any |
| 284 //! changes. |
| 285 virtual XmppReturnStatus RequestRosterUpdate() = 0; |
| 286 |
| 287 //! Returns the number of contacts in the roster |
| 288 virtual size_t GetRosterContactCount() = 0; |
| 289 |
| 290 //! Returns a contact by index |
| 291 virtual const XmppRosterContact* GetRosterContact(size_t index) = 0; |
| 292 |
| 293 //! Finds a contact by Jid |
| 294 virtual const XmppRosterContact* FindRosterContact(const Jid& jid) = 0; |
| 295 |
| 296 //! Send a request to the server to add a contact |
| 297 //! Note that the contact won't show up in the roster until the server can |
| 298 //! respond. This happens async when the socket is being serviced |
| 299 virtual XmppReturnStatus RequestRosterChange( |
| 300 const XmppRosterContact* contact) = 0; |
| 301 |
| 302 //! Request that the server remove a contact |
| 303 //! The jabber protocol specifies that the server should also cancel any |
| 304 //! subscriptions when this is done. Like adding, this contact won't be |
| 305 //! removed until the server responds. |
| 306 virtual XmppReturnStatus RequestRosterRemove(const Jid& jid) = 0; |
| 307 |
| 308 // SUBSCRIPTION MANAGEMENT --------------------------------------------------- |
| 309 |
| 310 //! Request a subscription to presence notifications form a Jid |
| 311 virtual XmppReturnStatus RequestSubscription(const Jid& jid) = 0; |
| 312 |
| 313 //! Cancel a subscription to presence notifications from a Jid |
| 314 virtual XmppReturnStatus CancelSubscription(const Jid& jid) = 0; |
| 315 |
| 316 //! Approve a request to deliver presence notifications to a jid |
| 317 virtual XmppReturnStatus ApproveSubscriber(const Jid& jid) = 0; |
| 318 |
| 319 //! Deny or cancel presence notification deliver to a jid |
| 320 virtual XmppReturnStatus CancelSubscriber(const Jid& jid) = 0; |
| 321 }; |
| 322 |
| 323 } |
| 324 |
| 325 #endif // WEBRTC_LIBJINGLE_XMPP_ROSTERMODULE_H_ |
OLD | NEW |