blob: f29489f89ee04d7fa5365d207fd5790b4116f293 [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
Nanang Izzuddina62ffc92011-05-05 06:14:19 +00003 * Copyright (C) 2008-2011 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
Sauw Ming5c2f6da2011-02-11 07:39:14 +0000184/**
185 * Add a list of headers to the subscription instance. The list of headers
186 * will be added to outgoing presence subscription requests.
187 *
188 * @param sub Subscription instance.
189 * @param hdr_list List of headers to be added.
190 *
191 * @return PJ_SUCCESS on success.
192 */
193PJ_DECL(pj_status_t) pjsip_pres_add_header( pjsip_evsub *sub,
194 const pjsip_hdr *hdr_list );
195
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000196
197/**
Benny Prijono834aee32006-02-19 01:38:06 +0000198 * Accept the incoming subscription request by sending 2xx response to
199 * incoming SUBSCRIBE request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000200 *
Benny Prijono834aee32006-02-19 01:38:06 +0000201 * @param sub Server subscription instance.
202 * @param rdata The incoming subscription request message.
203 * @param st_code Status code, which MUST be final response.
204 * @param hdr_list Optional list of headers to be added in the response.
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_accept( pjsip_evsub *sub,
209 pjsip_rx_data *rdata,
210 int st_code,
211 const pjsip_hdr *hdr_list );
212
213
214
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000215
216/**
Benny Prijono834aee32006-02-19 01:38:06 +0000217 * For notifier, create NOTIFY request to subscriber, and set the state
218 * of the subscription. Application MUST set the presence status to the
219 * appropriate state (by calling #pjsip_pres_set_status()) before calling
220 * this function.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000221 *
Benny Prijono834aee32006-02-19 01:38:06 +0000222 * @param sub The server subscription (notifier) instance.
223 * @param state New state to set.
224 * @param state_str The state string name, if state contains value other
225 * than active, pending, or terminated. Otherwise this
226 * argument is ignored.
227 * @param reason Specify reason if new state is terminated, otherwise
228 * put NULL.
229 * @param p_tdata Pointer to receive the request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000230 *
Benny Prijono834aee32006-02-19 01:38:06 +0000231 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000232 */
Benny Prijono834aee32006-02-19 01:38:06 +0000233PJ_DECL(pj_status_t) pjsip_pres_notify( pjsip_evsub *sub,
234 pjsip_evsub_state state,
235 const pj_str_t *state_str,
236 const pj_str_t *reason,
237 pjsip_tx_data **p_tdata);
238
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000239
240/**
Benny Prijono834aee32006-02-19 01:38:06 +0000241 * Create NOTIFY request to reflect current subscription status.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000242 *
Benny Prijono834aee32006-02-19 01:38:06 +0000243 * @param sub Server subscription object.
244 * @param p_tdata Pointer to receive request.
245 *
246 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000247 */
Benny Prijono834aee32006-02-19 01:38:06 +0000248PJ_DECL(pj_status_t) pjsip_pres_current_notify( pjsip_evsub *sub,
249 pjsip_tx_data **p_tdata );
250
251
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000252
253/**
Benny Prijono26ff9062006-02-21 23:47:00 +0000254 * Send request message that was previously created with initiate(), notify(),
255 * or current_notify(). Application may also send request created with other
256 * functions, e.g. authentication. But the request MUST be either request
257 * that creates/refresh subscription or NOTIFY request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000258 *
Benny Prijono834aee32006-02-19 01:38:06 +0000259 * @param sub The subscription object.
260 * @param tdata Request message to be sent.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000261 *
Benny Prijono834aee32006-02-19 01:38:06 +0000262 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000263 */
Benny Prijono834aee32006-02-19 01:38:06 +0000264PJ_DECL(pj_status_t) pjsip_pres_send_request( pjsip_evsub *sub,
265 pjsip_tx_data *tdata );
266
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000267
268/**
Benny Prijono834aee32006-02-19 01:38:06 +0000269 * Get the presence status. Client normally would call this function
270 * after receiving NOTIFY request from server.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000271 *
Benny Prijono834aee32006-02-19 01:38:06 +0000272 * @param sub The client or server subscription.
273 * @param status The structure to receive presence status.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000274 *
Benny Prijono834aee32006-02-19 01:38:06 +0000275 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000276 */
Benny Prijono834aee32006-02-19 01:38:06 +0000277PJ_DECL(pj_status_t) pjsip_pres_get_status( pjsip_evsub *sub,
278 pjsip_pres_status *status );
279
280
281/**
282 * Set the presence status. This operation is only valid for server
283 * subscription. After calling this function, application would need to
284 * send NOTIFY request to client.
285 *
286 * @param sub The server subscription.
287 * @param status Status to be set.
288 *
289 * @return PJ_SUCCESS on success.
290 */
291PJ_DECL(pj_status_t) pjsip_pres_set_status( pjsip_evsub *sub,
292 const pjsip_pres_status *status );
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000293
294
295/**
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000296 * This is a utility function to create PIDF message body from PJSIP
297 * presence status (pjsip_pres_status).
298 *
299 * @param pool The pool to allocate memory for the message body.
300 * @param status Presence status to be converted into PIDF message
301 * body.
302 * @param entity The entity ID, which normally is equal to the
303 * presentity ID publishing this presence info.
304 * @param p_body Pointer to receive the SIP message body.
305 *
306 * @return PJ_SUCCESS on success.
307 */
308PJ_DECL(pj_status_t) pjsip_pres_create_pidf( pj_pool_t *pool,
309 const pjsip_pres_status *status,
310 const pj_str_t *entity,
311 pjsip_msg_body **p_body );
312
313
314/**
315 * This is a utility function to create X-PIDF message body from PJSIP
316 * presence status (pjsip_pres_status).
317 *
318 * @param pool The pool to allocate memory for the message body.
319 * @param status Presence status to be converted into X-PIDF message
320 * body.
321 * @param entity The entity ID, which normally is equal to the
322 * presentity ID publishing this presence info.
323 * @param p_body Pointer to receive the SIP message body.
324 *
325 * @return PJ_SUCCESS on success.
326 */
327PJ_DECL(pj_status_t) pjsip_pres_create_xpidf(pj_pool_t *pool,
328 const pjsip_pres_status *status,
329 const pj_str_t *entity,
330 pjsip_msg_body **p_body );
331
332
333
334/**
335 * This is a utility function to parse PIDF body into PJSIP presence status.
336 *
337 * @param rdata The incoming SIP message containing the PIDF body.
338 * @param pool Pool to allocate memory to copy the strings into
339 * the presence status structure.
340 * @param status The presence status to be initialized.
341 *
342 * @return PJ_SUCCESS on success.
Benny Prijonof279c092010-10-12 11:35:55 +0000343 *
344 * @see pjsip_pres_parse_pidf2()
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000345 */
346PJ_DECL(pj_status_t) pjsip_pres_parse_pidf(pjsip_rx_data *rdata,
347 pj_pool_t *pool,
348 pjsip_pres_status *status);
349
Benny Prijonof279c092010-10-12 11:35:55 +0000350/**
351 * This is a utility function to parse PIDF body into PJSIP presence status.
352 *
353 * @param body Text body, with one extra space at the end to place
354 * NULL character temporarily during parsing.
355 * @param body_len Length of the body, not including the NULL termination
356 * character.
357 * @param pool Pool to allocate memory to copy the strings into
358 * the presence status structure.
359 * @param status The presence status to be initialized.
360 *
361 * @return PJ_SUCCESS on success.
362 *
363 * @see pjsip_pres_parse_pidf()
364 */
365PJ_DECL(pj_status_t) pjsip_pres_parse_pidf2(char *body, unsigned body_len,
366 pj_pool_t *pool,
367 pjsip_pres_status *status);
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000368
369
370/**
371 * This is a utility function to parse X-PIDF body into PJSIP presence status.
372 *
373 * @param rdata The incoming SIP message containing the X-PIDF body.
374 * @param pool Pool to allocate memory to copy the strings into
375 * the presence status structure.
376 * @param status The presence status to be initialized.
377 *
378 * @return PJ_SUCCESS on success.
Benny Prijonof279c092010-10-12 11:35:55 +0000379 *
380 * @see pjsip_pres_parse_xpidf2()
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000381 */
382PJ_DECL(pj_status_t) pjsip_pres_parse_xpidf(pjsip_rx_data *rdata,
383 pj_pool_t *pool,
384 pjsip_pres_status *status);
385
386
Benny Prijonof279c092010-10-12 11:35:55 +0000387/**
388 * This is a utility function to parse X-PIDF body into PJSIP presence status.
389 *
390 * @param body Text body, with one extra space at the end to place
391 * NULL character temporarily during parsing.
392 * @param body_len Length of the body, not including the NULL termination
393 * character.
394 * @param pool Pool to allocate memory to copy the strings into
395 * the presence status structure.
396 * @param status The presence status to be initialized.
397 *
398 * @return PJ_SUCCESS on success.
399 *
400 * @see pjsip_pres_parse_xpidf()
401 */
402PJ_DECL(pj_status_t) pjsip_pres_parse_xpidf2(char *body, unsigned body_len,
403 pj_pool_t *pool,
404 pjsip_pres_status *status);
405
406
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000407
408/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000409 * @}
410 */
411
412PJ_END_DECL
413
414
415#endif /* __PJSIP_SIMPLE_PRESENCE_H__ */