blob: eaf8ba8681f46af80c7880ec3d538f2155557686 [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
Benny Prijono32177c02008-06-20 22:44:47 +00004 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono5dcb38d2005-11-21 01:55:47 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#ifndef __PJSIP_SIMPLE_PRESENCE_H__
21#define __PJSIP_SIMPLE_PRESENCE_H__
22
23/**
24 * @file presence.h
25 * @brief SIP Extension for Presence (RFC 3856)
26 */
Benny Prijono834aee32006-02-19 01:38:06 +000027#include <pjsip-simple/evsub.h>
28#include <pjsip-simple/pidf.h>
29#include <pjsip-simple/xpidf.h>
Benny Prijono4461c7d2007-08-25 13:36:15 +000030#include <pjsip-simple/rpid.h>
Benny Prijono5dcb38d2005-11-21 01:55:47 +000031
32
33PJ_BEGIN_DECL
34
35
36/**
37 * @defgroup PJSIP_SIMPLE_PRES SIP Extension for Presence (RFC 3856)
38 * @ingroup PJSIP_SIMPLE
Benny Prijono312aff92006-06-17 04:08:30 +000039 * @brief Support for SIP Extension for Presence (RFC 3856)
Benny Prijono5dcb38d2005-11-21 01:55:47 +000040 * @{
41 *
42 * This module contains the implementation of SIP Presence Extension as
43 * described in RFC 3856. It uses the SIP Event Notification framework
Benny Prijono834aee32006-02-19 01:38:06 +000044 * (evsub.h) and extends the framework by implementing "presence"
Benny Prijono5dcb38d2005-11-21 01:55:47 +000045 * event package.
46 */
47
Benny Prijono834aee32006-02-19 01:38:06 +000048
49
Benny Prijono5dcb38d2005-11-21 01:55:47 +000050/**
Benny Prijono834aee32006-02-19 01:38:06 +000051 * Initialize the presence module and register it as endpoint module and
52 * package to the event subscription module.
53 *
54 * @param endpt The endpoint instance.
55 * @param mod_evsub The event subscription module instance.
56 *
57 * @return PJ_SUCCESS if the module is successfully
58 * initialized and registered to both endpoint
59 * and the event subscription module.
Benny Prijono5dcb38d2005-11-21 01:55:47 +000060 */
Benny Prijono834aee32006-02-19 01:38:06 +000061PJ_DECL(pj_status_t) pjsip_pres_init_module(pjsip_endpoint *endpt,
62 pjsip_module *mod_evsub);
63
64
65/**
66 * Get the presence module instance.
67 *
68 * @return The presence module instance.
69 */
70PJ_DECL(pjsip_module*) pjsip_pres_instance(void);
71
72
Benny Prijono312aff92006-06-17 04:08:30 +000073/**
74 * Maximum presence status info.
75 */
Benny Prijono834aee32006-02-19 01:38:06 +000076#define PJSIP_PRES_STATUS_MAX_INFO 8
77
Benny Prijono4461c7d2007-08-25 13:36:15 +000078
Benny Prijono834aee32006-02-19 01:38:06 +000079/**
80 * This structure describes presence status of a presentity.
81 */
82struct pjsip_pres_status
Benny Prijono5dcb38d2005-11-21 01:55:47 +000083{
Benny Prijono834aee32006-02-19 01:38:06 +000084 unsigned info_cnt; /**< Number of info in the status. */
85 struct {
Benny Prijono5dcb38d2005-11-21 01:55:47 +000086
Benny Prijono834aee32006-02-19 01:38:06 +000087 pj_bool_t basic_open; /**< Basic status/availability. */
Benny Prijono4461c7d2007-08-25 13:36:15 +000088 pjrpid_element rpid; /**< Optional RPID info. */
89
Benny Prijono834aee32006-02-19 01:38:06 +000090 pj_str_t id; /**< Tuple id. */
91 pj_str_t contact; /**< Optional contact address. */
92
Benny Prijono28add7e2009-06-15 16:03:40 +000093 pj_xml_node *tuple_node; /**< Pointer to tuple XML node of
94 parsed PIDF body received from
95 remote agent. Only valid for
96 client subscription. If the
97 last received NOTIFY request
98 does not contain any PIDF body,
99 this valud will be set to NULL */
100
Benny Prijono834aee32006-02-19 01:38:06 +0000101 } info[PJSIP_PRES_STATUS_MAX_INFO]; /**< Array of info. */
102
103 pj_bool_t _is_valid; /**< Internal flag. */
104};
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000105
106
107/**
Benny Prijono834aee32006-02-19 01:38:06 +0000108 * @see pjsip_pres_status
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000109 */
Benny Prijono834aee32006-02-19 01:38:06 +0000110typedef struct pjsip_pres_status pjsip_pres_status;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000111
112
113/**
Benny Prijono834aee32006-02-19 01:38:06 +0000114 * Create presence client subscription session.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000115 *
Benny Prijono834aee32006-02-19 01:38:06 +0000116 * @param dlg The underlying dialog to use.
117 * @param user_cb Pointer to callbacks to receive presence subscription
118 * events.
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000119 * @param options Option flags. Currently only PJSIP_EVSUB_NO_EVENT_ID
120 * is recognized.
Benny Prijono834aee32006-02-19 01:38:06 +0000121 * @param p_evsub Pointer to receive the presence subscription
122 * session.
123 *
124 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000125 */
Benny Prijono834aee32006-02-19 01:38:06 +0000126PJ_DECL(pj_status_t) pjsip_pres_create_uac( pjsip_dialog *dlg,
127 const pjsip_evsub_user *user_cb,
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000128 unsigned options,
Benny Prijono834aee32006-02-19 01:38:06 +0000129 pjsip_evsub **p_evsub );
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000130
131
132/**
Benny Prijono834aee32006-02-19 01:38:06 +0000133 * Create presence server subscription session.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000134 *
Benny Prijono834aee32006-02-19 01:38:06 +0000135 * @param dlg The underlying dialog to use.
136 * @param user_cb Pointer to callbacks to receive presence subscription
137 * events.
138 * @param rdata The incoming SUBSCRIBE request that creates the event
139 * subscription.
140 * @param p_evsub Pointer to receive the presence subscription
141 * session.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000142 *
Benny Prijono834aee32006-02-19 01:38:06 +0000143 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000144 */
Benny Prijono834aee32006-02-19 01:38:06 +0000145PJ_DECL(pj_status_t) pjsip_pres_create_uas( pjsip_dialog *dlg,
146 const pjsip_evsub_user *user_cb,
147 pjsip_rx_data *rdata,
148 pjsip_evsub **p_evsub );
149
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000150
151/**
Benny Prijonod4e0abd2006-03-05 11:53:36 +0000152 * Forcefully destroy the presence subscription. This function should only
153 * be called on special condition, such as when the subscription
154 * initialization has failed. For other conditions, application MUST terminate
155 * the subscription by sending the appropriate un(SUBSCRIBE) or NOTIFY.
156 *
157 * @param sub The presence subscription.
158 * @param notify Specify whether the state notification callback
159 * should be called.
160 *
161 * @return PJ_SUCCESS if subscription session has been destroyed.
162 */
163PJ_DECL(pj_status_t) pjsip_pres_terminate( pjsip_evsub *sub,
164 pj_bool_t notify );
165
166
167
168/**
Benny Prijono834aee32006-02-19 01:38:06 +0000169 * Call this function to create request to initiate presence subscription, to
170 * refresh subcription, or to request subscription termination.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000171 *
Benny Prijono834aee32006-02-19 01:38:06 +0000172 * @param sub Client subscription instance.
173 * @param expires Subscription expiration. If the value is set to zero,
174 * this will request unsubscription.
175 * @param p_tdata Pointer to receive the request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000176 *
Benny Prijono834aee32006-02-19 01:38:06 +0000177 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000178 */
Benny Prijono834aee32006-02-19 01:38:06 +0000179PJ_DECL(pj_status_t) pjsip_pres_initiate( pjsip_evsub *sub,
180 pj_int32_t expires,
181 pjsip_tx_data **p_tdata);
182
183
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000184
185/**
Benny Prijono834aee32006-02-19 01:38:06 +0000186 * Accept the incoming subscription request by sending 2xx response to
187 * incoming SUBSCRIBE request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000188 *
Benny Prijono834aee32006-02-19 01:38:06 +0000189 * @param sub Server subscription instance.
190 * @param rdata The incoming subscription request message.
191 * @param st_code Status code, which MUST be final response.
192 * @param hdr_list Optional list of headers to be added in the response.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000193 *
Benny Prijono834aee32006-02-19 01:38:06 +0000194 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000195 */
Benny Prijono834aee32006-02-19 01:38:06 +0000196PJ_DECL(pj_status_t) pjsip_pres_accept( pjsip_evsub *sub,
197 pjsip_rx_data *rdata,
198 int st_code,
199 const pjsip_hdr *hdr_list );
200
201
202
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000203
204/**
Benny Prijono834aee32006-02-19 01:38:06 +0000205 * For notifier, create NOTIFY request to subscriber, and set the state
206 * of the subscription. Application MUST set the presence status to the
207 * appropriate state (by calling #pjsip_pres_set_status()) before calling
208 * this function.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000209 *
Benny Prijono834aee32006-02-19 01:38:06 +0000210 * @param sub The server subscription (notifier) instance.
211 * @param state New state to set.
212 * @param state_str The state string name, if state contains value other
213 * than active, pending, or terminated. Otherwise this
214 * argument is ignored.
215 * @param reason Specify reason if new state is terminated, otherwise
216 * put NULL.
217 * @param p_tdata Pointer to receive the request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000218 *
Benny Prijono834aee32006-02-19 01:38:06 +0000219 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000220 */
Benny Prijono834aee32006-02-19 01:38:06 +0000221PJ_DECL(pj_status_t) pjsip_pres_notify( pjsip_evsub *sub,
222 pjsip_evsub_state state,
223 const pj_str_t *state_str,
224 const pj_str_t *reason,
225 pjsip_tx_data **p_tdata);
226
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000227
228/**
Benny Prijono834aee32006-02-19 01:38:06 +0000229 * Create NOTIFY request to reflect current subscription status.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000230 *
Benny Prijono834aee32006-02-19 01:38:06 +0000231 * @param sub Server subscription object.
232 * @param p_tdata Pointer to receive request.
233 *
234 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000235 */
Benny Prijono834aee32006-02-19 01:38:06 +0000236PJ_DECL(pj_status_t) pjsip_pres_current_notify( pjsip_evsub *sub,
237 pjsip_tx_data **p_tdata );
238
239
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000240
241/**
Benny Prijono26ff9062006-02-21 23:47:00 +0000242 * Send request message that was previously created with initiate(), notify(),
243 * or current_notify(). Application may also send request created with other
244 * functions, e.g. authentication. But the request MUST be either request
245 * that creates/refresh subscription or NOTIFY request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000246 *
Benny Prijono834aee32006-02-19 01:38:06 +0000247 * @param sub The subscription object.
248 * @param tdata Request message to be sent.
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_send_request( pjsip_evsub *sub,
253 pjsip_tx_data *tdata );
254
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000255
256/**
Benny Prijono834aee32006-02-19 01:38:06 +0000257 * Get the presence status. Client normally would call this function
258 * after receiving NOTIFY request from server.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000259 *
Benny Prijono834aee32006-02-19 01:38:06 +0000260 * @param sub The client or server subscription.
261 * @param status The structure to receive presence status.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000262 *
Benny Prijono834aee32006-02-19 01:38:06 +0000263 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000264 */
Benny Prijono834aee32006-02-19 01:38:06 +0000265PJ_DECL(pj_status_t) pjsip_pres_get_status( pjsip_evsub *sub,
266 pjsip_pres_status *status );
267
268
269/**
270 * Set the presence status. This operation is only valid for server
271 * subscription. After calling this function, application would need to
272 * send NOTIFY request to client.
273 *
274 * @param sub The server subscription.
275 * @param status Status to be set.
276 *
277 * @return PJ_SUCCESS on success.
278 */
279PJ_DECL(pj_status_t) pjsip_pres_set_status( pjsip_evsub *sub,
280 const pjsip_pres_status *status );
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000281
282
283/**
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000284 * This is a utility function to create PIDF message body from PJSIP
285 * presence status (pjsip_pres_status).
286 *
287 * @param pool The pool to allocate memory for the message body.
288 * @param status Presence status to be converted into PIDF message
289 * body.
290 * @param entity The entity ID, which normally is equal to the
291 * presentity ID publishing this presence info.
292 * @param p_body Pointer to receive the SIP message body.
293 *
294 * @return PJ_SUCCESS on success.
295 */
296PJ_DECL(pj_status_t) pjsip_pres_create_pidf( pj_pool_t *pool,
297 const pjsip_pres_status *status,
298 const pj_str_t *entity,
299 pjsip_msg_body **p_body );
300
301
302/**
303 * This is a utility function to create X-PIDF message body from PJSIP
304 * presence status (pjsip_pres_status).
305 *
306 * @param pool The pool to allocate memory for the message body.
307 * @param status Presence status to be converted into X-PIDF message
308 * body.
309 * @param entity The entity ID, which normally is equal to the
310 * presentity ID publishing this presence info.
311 * @param p_body Pointer to receive the SIP message body.
312 *
313 * @return PJ_SUCCESS on success.
314 */
315PJ_DECL(pj_status_t) pjsip_pres_create_xpidf(pj_pool_t *pool,
316 const pjsip_pres_status *status,
317 const pj_str_t *entity,
318 pjsip_msg_body **p_body );
319
320
321
322/**
323 * This is a utility function to parse PIDF body into PJSIP presence status.
324 *
325 * @param rdata The incoming SIP message containing the PIDF body.
326 * @param pool Pool to allocate memory to copy the strings into
327 * the presence status structure.
328 * @param status The presence status to be initialized.
329 *
330 * @return PJ_SUCCESS on success.
Benny Prijonof279c092010-10-12 11:35:55 +0000331 *
332 * @see pjsip_pres_parse_pidf2()
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000333 */
334PJ_DECL(pj_status_t) pjsip_pres_parse_pidf(pjsip_rx_data *rdata,
335 pj_pool_t *pool,
336 pjsip_pres_status *status);
337
Benny Prijonof279c092010-10-12 11:35:55 +0000338/**
339 * This is a utility function to parse PIDF body into PJSIP presence status.
340 *
341 * @param body Text body, with one extra space at the end to place
342 * NULL character temporarily during parsing.
343 * @param body_len Length of the body, not including the NULL termination
344 * character.
345 * @param pool Pool to allocate memory to copy the strings into
346 * the presence status structure.
347 * @param status The presence status to be initialized.
348 *
349 * @return PJ_SUCCESS on success.
350 *
351 * @see pjsip_pres_parse_pidf()
352 */
353PJ_DECL(pj_status_t) pjsip_pres_parse_pidf2(char *body, unsigned body_len,
354 pj_pool_t *pool,
355 pjsip_pres_status *status);
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000356
357
358/**
359 * This is a utility function to parse X-PIDF body into PJSIP presence status.
360 *
361 * @param rdata The incoming SIP message containing the X-PIDF body.
362 * @param pool Pool to allocate memory to copy the strings into
363 * the presence status structure.
364 * @param status The presence status to be initialized.
365 *
366 * @return PJ_SUCCESS on success.
Benny Prijonof279c092010-10-12 11:35:55 +0000367 *
368 * @see pjsip_pres_parse_xpidf2()
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000369 */
370PJ_DECL(pj_status_t) pjsip_pres_parse_xpidf(pjsip_rx_data *rdata,
371 pj_pool_t *pool,
372 pjsip_pres_status *status);
373
374
Benny Prijonof279c092010-10-12 11:35:55 +0000375/**
376 * This is a utility function to parse X-PIDF body into PJSIP presence status.
377 *
378 * @param body Text body, with one extra space at the end to place
379 * NULL character temporarily during parsing.
380 * @param body_len Length of the body, not including the NULL termination
381 * character.
382 * @param pool Pool to allocate memory to copy the strings into
383 * the presence status structure.
384 * @param status The presence status to be initialized.
385 *
386 * @return PJ_SUCCESS on success.
387 *
388 * @see pjsip_pres_parse_xpidf()
389 */
390PJ_DECL(pj_status_t) pjsip_pres_parse_xpidf2(char *body, unsigned body_len,
391 pj_pool_t *pool,
392 pjsip_pres_status *status);
393
394
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000395
396/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000397 * @}
398 */
399
400PJ_END_DECL
401
402
403#endif /* __PJSIP_SIMPLE_PRESENCE_H__ */