blob: ee2805f467ff55b0dee2b351893a39c0d3bdaada [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.
106 * @param p_evsub Pointer to receive the presence subscription
107 * session.
108 *
109 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000110 */
Benny Prijono834aee32006-02-19 01:38:06 +0000111PJ_DECL(pj_status_t) pjsip_pres_create_uac( pjsip_dialog *dlg,
112 const pjsip_evsub_user *user_cb,
113 pjsip_evsub **p_evsub );
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000114
115
116/**
Benny Prijono834aee32006-02-19 01:38:06 +0000117 * Create presence server subscription session.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000118 *
Benny Prijono834aee32006-02-19 01:38:06 +0000119 * @param dlg The underlying dialog to use.
120 * @param user_cb Pointer to callbacks to receive presence subscription
121 * events.
122 * @param rdata The incoming SUBSCRIBE request that creates the event
123 * subscription.
124 * @param p_evsub Pointer to receive the presence subscription
125 * session.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000126 *
Benny Prijono834aee32006-02-19 01:38:06 +0000127 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000128 */
Benny Prijono834aee32006-02-19 01:38:06 +0000129PJ_DECL(pj_status_t) pjsip_pres_create_uas( pjsip_dialog *dlg,
130 const pjsip_evsub_user *user_cb,
131 pjsip_rx_data *rdata,
132 pjsip_evsub **p_evsub );
133
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000134
135/**
Benny Prijonod4e0abd2006-03-05 11:53:36 +0000136 * Forcefully destroy the presence subscription. This function should only
137 * be called on special condition, such as when the subscription
138 * initialization has failed. For other conditions, application MUST terminate
139 * the subscription by sending the appropriate un(SUBSCRIBE) or NOTIFY.
140 *
141 * @param sub The presence subscription.
142 * @param notify Specify whether the state notification callback
143 * should be called.
144 *
145 * @return PJ_SUCCESS if subscription session has been destroyed.
146 */
147PJ_DECL(pj_status_t) pjsip_pres_terminate( pjsip_evsub *sub,
148 pj_bool_t notify );
149
150
151
152/**
Benny Prijono834aee32006-02-19 01:38:06 +0000153 * Call this function to create request to initiate presence subscription, to
154 * refresh subcription, or to request subscription termination.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000155 *
Benny Prijono834aee32006-02-19 01:38:06 +0000156 * @param sub Client subscription instance.
157 * @param expires Subscription expiration. If the value is set to zero,
158 * this will request unsubscription.
159 * @param p_tdata Pointer to receive the request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000160 *
Benny Prijono834aee32006-02-19 01:38:06 +0000161 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000162 */
Benny Prijono834aee32006-02-19 01:38:06 +0000163PJ_DECL(pj_status_t) pjsip_pres_initiate( pjsip_evsub *sub,
164 pj_int32_t expires,
165 pjsip_tx_data **p_tdata);
166
167
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000168
169/**
Benny Prijono834aee32006-02-19 01:38:06 +0000170 * Accept the incoming subscription request by sending 2xx response to
171 * incoming SUBSCRIBE request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000172 *
Benny Prijono834aee32006-02-19 01:38:06 +0000173 * @param sub Server subscription instance.
174 * @param rdata The incoming subscription request message.
175 * @param st_code Status code, which MUST be final response.
176 * @param hdr_list Optional list of headers to be added in the response.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000177 *
Benny Prijono834aee32006-02-19 01:38:06 +0000178 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000179 */
Benny Prijono834aee32006-02-19 01:38:06 +0000180PJ_DECL(pj_status_t) pjsip_pres_accept( pjsip_evsub *sub,
181 pjsip_rx_data *rdata,
182 int st_code,
183 const pjsip_hdr *hdr_list );
184
185
186
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000187
188/**
Benny Prijono834aee32006-02-19 01:38:06 +0000189 * For notifier, create NOTIFY request to subscriber, and set the state
190 * of the subscription. Application MUST set the presence status to the
191 * appropriate state (by calling #pjsip_pres_set_status()) before calling
192 * this function.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000193 *
Benny Prijono834aee32006-02-19 01:38:06 +0000194 * @param sub The server subscription (notifier) instance.
195 * @param state New state to set.
196 * @param state_str The state string name, if state contains value other
197 * than active, pending, or terminated. Otherwise this
198 * argument is ignored.
199 * @param reason Specify reason if new state is terminated, otherwise
200 * put NULL.
201 * @param p_tdata Pointer to receive the request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000202 *
Benny Prijono834aee32006-02-19 01:38:06 +0000203 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000204 */
Benny Prijono834aee32006-02-19 01:38:06 +0000205PJ_DECL(pj_status_t) pjsip_pres_notify( pjsip_evsub *sub,
206 pjsip_evsub_state state,
207 const pj_str_t *state_str,
208 const pj_str_t *reason,
209 pjsip_tx_data **p_tdata);
210
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000211
212/**
Benny Prijono834aee32006-02-19 01:38:06 +0000213 * Create NOTIFY request to reflect current subscription status.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000214 *
Benny Prijono834aee32006-02-19 01:38:06 +0000215 * @param sub Server subscription object.
216 * @param p_tdata Pointer to receive request.
217 *
218 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000219 */
Benny Prijono834aee32006-02-19 01:38:06 +0000220PJ_DECL(pj_status_t) pjsip_pres_current_notify( pjsip_evsub *sub,
221 pjsip_tx_data **p_tdata );
222
223
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000224
225/**
Benny Prijono26ff9062006-02-21 23:47:00 +0000226 * Send request message that was previously created with initiate(), notify(),
227 * or current_notify(). Application may also send request created with other
228 * functions, e.g. authentication. But the request MUST be either request
229 * that creates/refresh subscription or NOTIFY request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000230 *
Benny Prijono834aee32006-02-19 01:38:06 +0000231 * @param sub The subscription object.
232 * @param tdata Request message to be sent.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000233 *
Benny Prijono834aee32006-02-19 01:38:06 +0000234 * @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_send_request( pjsip_evsub *sub,
237 pjsip_tx_data *tdata );
238
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000239
240/**
Benny Prijono834aee32006-02-19 01:38:06 +0000241 * Get the presence status. Client normally would call this function
242 * after receiving NOTIFY request from server.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000243 *
Benny Prijono834aee32006-02-19 01:38:06 +0000244 * @param sub The client or server subscription.
245 * @param status The structure to receive presence status.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000246 *
Benny Prijono834aee32006-02-19 01:38:06 +0000247 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000248 */
Benny Prijono834aee32006-02-19 01:38:06 +0000249PJ_DECL(pj_status_t) pjsip_pres_get_status( pjsip_evsub *sub,
250 pjsip_pres_status *status );
251
252
253/**
254 * Set the presence status. This operation is only valid for server
255 * subscription. After calling this function, application would need to
256 * send NOTIFY request to client.
257 *
258 * @param sub The server subscription.
259 * @param status Status to be set.
260 *
261 * @return PJ_SUCCESS on success.
262 */
263PJ_DECL(pj_status_t) pjsip_pres_set_status( pjsip_evsub *sub,
264 const pjsip_pres_status *status );
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000265
266
267/**
268 * @}
269 */
270
271PJ_END_DECL
272
273
274#endif /* __PJSIP_SIMPLE_PRESENCE_H__ */