blob: 668b723c0aac1f66e3b078d48285e24822655eed [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJSIP_SIMPLE_PRESENCE_H__
20#define __PJSIP_SIMPLE_PRESENCE_H__
21
22/**
23 * @file presence.h
24 * @brief SIP Extension for Presence (RFC 3856)
25 */
Benny Prijono834aee32006-02-19 01:38:06 +000026#include <pjsip-simple/evsub.h>
27#include <pjsip-simple/pidf.h>
28#include <pjsip-simple/xpidf.h>
Benny Prijono5dcb38d2005-11-21 01:55:47 +000029
30
31PJ_BEGIN_DECL
32
33
34/**
35 * @defgroup PJSIP_SIMPLE_PRES SIP Extension for Presence (RFC 3856)
36 * @ingroup PJSIP_SIMPLE
Benny Prijono312aff92006-06-17 04:08:30 +000037 * @brief Support for SIP Extension for Presence (RFC 3856)
Benny Prijono5dcb38d2005-11-21 01:55:47 +000038 * @{
39 *
40 * This module contains the implementation of SIP Presence Extension as
41 * described in RFC 3856. It uses the SIP Event Notification framework
Benny Prijono834aee32006-02-19 01:38:06 +000042 * (evsub.h) and extends the framework by implementing "presence"
Benny Prijono5dcb38d2005-11-21 01:55:47 +000043 * event package.
44 */
45
Benny Prijono834aee32006-02-19 01:38:06 +000046
47
Benny Prijono5dcb38d2005-11-21 01:55:47 +000048/**
Benny Prijono834aee32006-02-19 01:38:06 +000049 * Initialize the presence module and register it as endpoint module and
50 * package to the event subscription module.
51 *
52 * @param endpt The endpoint instance.
53 * @param mod_evsub The event subscription module instance.
54 *
55 * @return PJ_SUCCESS if the module is successfully
56 * initialized and registered to both endpoint
57 * and the event subscription module.
Benny Prijono5dcb38d2005-11-21 01:55:47 +000058 */
Benny Prijono834aee32006-02-19 01:38:06 +000059PJ_DECL(pj_status_t) pjsip_pres_init_module(pjsip_endpoint *endpt,
60 pjsip_module *mod_evsub);
61
62
63/**
64 * Get the presence module instance.
65 *
66 * @return The presence module instance.
67 */
68PJ_DECL(pjsip_module*) pjsip_pres_instance(void);
69
70
Benny Prijono312aff92006-06-17 04:08:30 +000071/**
72 * Maximum presence status info.
73 */
Benny Prijono834aee32006-02-19 01:38:06 +000074#define PJSIP_PRES_STATUS_MAX_INFO 8
75
76/**
77 * This structure describes presence status of a presentity.
78 */
79struct pjsip_pres_status
Benny Prijono5dcb38d2005-11-21 01:55:47 +000080{
Benny Prijono834aee32006-02-19 01:38:06 +000081 unsigned info_cnt; /**< Number of info in the status. */
82 struct {
Benny Prijono5dcb38d2005-11-21 01:55:47 +000083
Benny Prijono834aee32006-02-19 01:38:06 +000084 pj_bool_t basic_open; /**< Basic status/availability. */
85 pj_str_t id; /**< Tuple id. */
86 pj_str_t contact; /**< Optional contact address. */
87
88 } info[PJSIP_PRES_STATUS_MAX_INFO]; /**< Array of info. */
89
90 pj_bool_t _is_valid; /**< Internal flag. */
91};
Benny Prijono5dcb38d2005-11-21 01:55:47 +000092
93
94/**
Benny Prijono834aee32006-02-19 01:38:06 +000095 * @see pjsip_pres_status
Benny Prijono5dcb38d2005-11-21 01:55:47 +000096 */
Benny Prijono834aee32006-02-19 01:38:06 +000097typedef struct pjsip_pres_status pjsip_pres_status;
Benny Prijono5dcb38d2005-11-21 01:55:47 +000098
99
100/**
Benny Prijono834aee32006-02-19 01:38:06 +0000101 * Create presence client subscription session.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000102 *
Benny Prijono834aee32006-02-19 01:38:06 +0000103 * @param dlg The underlying dialog to use.
104 * @param user_cb Pointer to callbacks to receive presence subscription
105 * events.
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000106 * @param options Option flags. Currently only PJSIP_EVSUB_NO_EVENT_ID
107 * is recognized.
Benny Prijono834aee32006-02-19 01:38:06 +0000108 * @param p_evsub Pointer to receive the presence subscription
109 * session.
110 *
111 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000112 */
Benny Prijono834aee32006-02-19 01:38:06 +0000113PJ_DECL(pj_status_t) pjsip_pres_create_uac( pjsip_dialog *dlg,
114 const pjsip_evsub_user *user_cb,
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000115 unsigned options,
Benny Prijono834aee32006-02-19 01:38:06 +0000116 pjsip_evsub **p_evsub );
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000117
118
119/**
Benny Prijono834aee32006-02-19 01:38:06 +0000120 * Create presence server subscription session.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000121 *
Benny Prijono834aee32006-02-19 01:38:06 +0000122 * @param dlg The underlying dialog to use.
123 * @param user_cb Pointer to callbacks to receive presence subscription
124 * events.
125 * @param rdata The incoming SUBSCRIBE request that creates the event
126 * subscription.
127 * @param p_evsub Pointer to receive the presence subscription
128 * session.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000129 *
Benny Prijono834aee32006-02-19 01:38:06 +0000130 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000131 */
Benny Prijono834aee32006-02-19 01:38:06 +0000132PJ_DECL(pj_status_t) pjsip_pres_create_uas( pjsip_dialog *dlg,
133 const pjsip_evsub_user *user_cb,
134 pjsip_rx_data *rdata,
135 pjsip_evsub **p_evsub );
136
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000137
138/**
Benny Prijonod4e0abd2006-03-05 11:53:36 +0000139 * Forcefully destroy the presence subscription. This function should only
140 * be called on special condition, such as when the subscription
141 * initialization has failed. For other conditions, application MUST terminate
142 * the subscription by sending the appropriate un(SUBSCRIBE) or NOTIFY.
143 *
144 * @param sub The presence subscription.
145 * @param notify Specify whether the state notification callback
146 * should be called.
147 *
148 * @return PJ_SUCCESS if subscription session has been destroyed.
149 */
150PJ_DECL(pj_status_t) pjsip_pres_terminate( pjsip_evsub *sub,
151 pj_bool_t notify );
152
153
154
155/**
Benny Prijono834aee32006-02-19 01:38:06 +0000156 * Call this function to create request to initiate presence subscription, to
157 * refresh subcription, or to request subscription termination.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000158 *
Benny Prijono834aee32006-02-19 01:38:06 +0000159 * @param sub Client subscription instance.
160 * @param expires Subscription expiration. If the value is set to zero,
161 * this will request unsubscription.
162 * @param p_tdata Pointer to receive the request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000163 *
Benny Prijono834aee32006-02-19 01:38:06 +0000164 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000165 */
Benny Prijono834aee32006-02-19 01:38:06 +0000166PJ_DECL(pj_status_t) pjsip_pres_initiate( pjsip_evsub *sub,
167 pj_int32_t expires,
168 pjsip_tx_data **p_tdata);
169
170
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000171
172/**
Benny Prijono834aee32006-02-19 01:38:06 +0000173 * Accept the incoming subscription request by sending 2xx response to
174 * incoming SUBSCRIBE request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000175 *
Benny Prijono834aee32006-02-19 01:38:06 +0000176 * @param sub Server subscription instance.
177 * @param rdata The incoming subscription request message.
178 * @param st_code Status code, which MUST be final response.
179 * @param hdr_list Optional list of headers to be added in the response.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000180 *
Benny Prijono834aee32006-02-19 01:38:06 +0000181 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000182 */
Benny Prijono834aee32006-02-19 01:38:06 +0000183PJ_DECL(pj_status_t) pjsip_pres_accept( pjsip_evsub *sub,
184 pjsip_rx_data *rdata,
185 int st_code,
186 const pjsip_hdr *hdr_list );
187
188
189
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000190
191/**
Benny Prijono834aee32006-02-19 01:38:06 +0000192 * For notifier, create NOTIFY request to subscriber, and set the state
193 * of the subscription. Application MUST set the presence status to the
194 * appropriate state (by calling #pjsip_pres_set_status()) before calling
195 * this function.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000196 *
Benny Prijono834aee32006-02-19 01:38:06 +0000197 * @param sub The server subscription (notifier) instance.
198 * @param state New state to set.
199 * @param state_str The state string name, if state contains value other
200 * than active, pending, or terminated. Otherwise this
201 * argument is ignored.
202 * @param reason Specify reason if new state is terminated, otherwise
203 * put NULL.
204 * @param p_tdata Pointer to receive the request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000205 *
Benny Prijono834aee32006-02-19 01:38:06 +0000206 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000207 */
Benny Prijono834aee32006-02-19 01:38:06 +0000208PJ_DECL(pj_status_t) pjsip_pres_notify( pjsip_evsub *sub,
209 pjsip_evsub_state state,
210 const pj_str_t *state_str,
211 const pj_str_t *reason,
212 pjsip_tx_data **p_tdata);
213
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000214
215/**
Benny Prijono834aee32006-02-19 01:38:06 +0000216 * Create NOTIFY request to reflect current subscription status.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000217 *
Benny Prijono834aee32006-02-19 01:38:06 +0000218 * @param sub Server subscription object.
219 * @param p_tdata Pointer to receive request.
220 *
221 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000222 */
Benny Prijono834aee32006-02-19 01:38:06 +0000223PJ_DECL(pj_status_t) pjsip_pres_current_notify( pjsip_evsub *sub,
224 pjsip_tx_data **p_tdata );
225
226
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000227
228/**
Benny Prijono26ff9062006-02-21 23:47:00 +0000229 * Send request message that was previously created with initiate(), notify(),
230 * or current_notify(). Application may also send request created with other
231 * functions, e.g. authentication. But the request MUST be either request
232 * that creates/refresh subscription or NOTIFY request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000233 *
Benny Prijono834aee32006-02-19 01:38:06 +0000234 * @param sub The subscription object.
235 * @param tdata Request message to be sent.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000236 *
Benny Prijono834aee32006-02-19 01:38:06 +0000237 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000238 */
Benny Prijono834aee32006-02-19 01:38:06 +0000239PJ_DECL(pj_status_t) pjsip_pres_send_request( pjsip_evsub *sub,
240 pjsip_tx_data *tdata );
241
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000242
243/**
Benny Prijono834aee32006-02-19 01:38:06 +0000244 * Get the presence status. Client normally would call this function
245 * after receiving NOTIFY request from server.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000246 *
Benny Prijono834aee32006-02-19 01:38:06 +0000247 * @param sub The client or server subscription.
248 * @param status The structure to receive presence status.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000249 *
Benny Prijono834aee32006-02-19 01:38:06 +0000250 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000251 */
Benny Prijono834aee32006-02-19 01:38:06 +0000252PJ_DECL(pj_status_t) pjsip_pres_get_status( pjsip_evsub *sub,
253 pjsip_pres_status *status );
254
255
256/**
257 * Set the presence status. This operation is only valid for server
258 * subscription. After calling this function, application would need to
259 * send NOTIFY request to client.
260 *
261 * @param sub The server subscription.
262 * @param status Status to be set.
263 *
264 * @return PJ_SUCCESS on success.
265 */
266PJ_DECL(pj_status_t) pjsip_pres_set_status( pjsip_evsub *sub,
267 const pjsip_pres_status *status );
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000268
269
270/**
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000271 * This is a utility function to create PIDF message body from PJSIP
272 * presence status (pjsip_pres_status).
273 *
274 * @param pool The pool to allocate memory for the message body.
275 * @param status Presence status to be converted into PIDF message
276 * body.
277 * @param entity The entity ID, which normally is equal to the
278 * presentity ID publishing this presence info.
279 * @param p_body Pointer to receive the SIP message body.
280 *
281 * @return PJ_SUCCESS on success.
282 */
283PJ_DECL(pj_status_t) pjsip_pres_create_pidf( pj_pool_t *pool,
284 const pjsip_pres_status *status,
285 const pj_str_t *entity,
286 pjsip_msg_body **p_body );
287
288
289/**
290 * This is a utility function to create X-PIDF message body from PJSIP
291 * presence status (pjsip_pres_status).
292 *
293 * @param pool The pool to allocate memory for the message body.
294 * @param status Presence status to be converted into X-PIDF message
295 * body.
296 * @param entity The entity ID, which normally is equal to the
297 * presentity ID publishing this presence info.
298 * @param p_body Pointer to receive the SIP message body.
299 *
300 * @return PJ_SUCCESS on success.
301 */
302PJ_DECL(pj_status_t) pjsip_pres_create_xpidf(pj_pool_t *pool,
303 const pjsip_pres_status *status,
304 const pj_str_t *entity,
305 pjsip_msg_body **p_body );
306
307
308
309/**
310 * This is a utility function to parse PIDF body into PJSIP presence status.
311 *
312 * @param rdata The incoming SIP message containing the PIDF body.
313 * @param pool Pool to allocate memory to copy the strings into
314 * the presence status structure.
315 * @param status The presence status to be initialized.
316 *
317 * @return PJ_SUCCESS on success.
318 */
319PJ_DECL(pj_status_t) pjsip_pres_parse_pidf(pjsip_rx_data *rdata,
320 pj_pool_t *pool,
321 pjsip_pres_status *status);
322
323
324
325/**
326 * This is a utility function to parse X-PIDF body into PJSIP presence status.
327 *
328 * @param rdata The incoming SIP message containing the X-PIDF body.
329 * @param pool Pool to allocate memory to copy the strings into
330 * the presence status structure.
331 * @param status The presence status to be initialized.
332 *
333 * @return PJ_SUCCESS on success.
334 */
335PJ_DECL(pj_status_t) pjsip_pres_parse_xpidf(pjsip_rx_data *rdata,
336 pj_pool_t *pool,
337 pjsip_pres_status *status);
338
339
340
341/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000342 * @}
343 */
344
345PJ_END_DECL
346
347
348#endif /* __PJSIP_SIMPLE_PRESENCE_H__ */