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