Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
Benny Prijono | a771a51 | 2007-02-19 01:13:53 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 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 Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 26 | #include <pjsip-simple/evsub.h> |
| 27 | #include <pjsip-simple/pidf.h> |
| 28 | #include <pjsip-simple/xpidf.h> |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 29 | |
| 30 | |
| 31 | PJ_BEGIN_DECL |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * @defgroup PJSIP_SIMPLE_PRES SIP Extension for Presence (RFC 3856) |
| 36 | * @ingroup PJSIP_SIMPLE |
Benny Prijono | 312aff9 | 2006-06-17 04:08:30 +0000 | [diff] [blame] | 37 | * @brief Support for SIP Extension for Presence (RFC 3856) |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 38 | * @{ |
| 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 Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 42 | * (evsub.h) and extends the framework by implementing "presence" |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 43 | * event package. |
| 44 | */ |
| 45 | |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 46 | |
| 47 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 48 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 49 | * 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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 58 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 59 | PJ_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 | */ |
| 68 | PJ_DECL(pjsip_module*) pjsip_pres_instance(void); |
| 69 | |
| 70 | |
Benny Prijono | 312aff9 | 2006-06-17 04:08:30 +0000 | [diff] [blame] | 71 | /** |
| 72 | * Maximum presence status info. |
| 73 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 74 | #define PJSIP_PRES_STATUS_MAX_INFO 8 |
| 75 | |
| 76 | /** |
| 77 | * This structure describes presence status of a presentity. |
| 78 | */ |
| 79 | struct pjsip_pres_status |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 80 | { |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 81 | unsigned info_cnt; /**< Number of info in the status. */ |
| 82 | struct { |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 83 | |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 84 | 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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 92 | |
| 93 | |
| 94 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 95 | * @see pjsip_pres_status |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 96 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 97 | typedef struct pjsip_pres_status pjsip_pres_status; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 98 | |
| 99 | |
| 100 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 101 | * Create presence client subscription session. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 102 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 103 | * @param dlg The underlying dialog to use. |
| 104 | * @param user_cb Pointer to callbacks to receive presence subscription |
| 105 | * events. |
Benny Prijono | 3a5e1ab | 2006-08-15 20:26:34 +0000 | [diff] [blame] | 106 | * @param options Option flags. Currently only PJSIP_EVSUB_NO_EVENT_ID |
| 107 | * is recognized. |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 108 | * @param p_evsub Pointer to receive the presence subscription |
| 109 | * session. |
| 110 | * |
| 111 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 112 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 113 | PJ_DECL(pj_status_t) pjsip_pres_create_uac( pjsip_dialog *dlg, |
| 114 | const pjsip_evsub_user *user_cb, |
Benny Prijono | 3a5e1ab | 2006-08-15 20:26:34 +0000 | [diff] [blame] | 115 | unsigned options, |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 116 | pjsip_evsub **p_evsub ); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 117 | |
| 118 | |
| 119 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 120 | * Create presence server subscription session. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 121 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 122 | * @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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 129 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 130 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 131 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 132 | PJ_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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 137 | |
| 138 | /** |
Benny Prijono | d4e0abd | 2006-03-05 11:53:36 +0000 | [diff] [blame] | 139 | * 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 | */ |
| 150 | PJ_DECL(pj_status_t) pjsip_pres_terminate( pjsip_evsub *sub, |
| 151 | pj_bool_t notify ); |
| 152 | |
| 153 | |
| 154 | |
| 155 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 156 | * Call this function to create request to initiate presence subscription, to |
| 157 | * refresh subcription, or to request subscription termination. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 158 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 159 | * @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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 163 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 164 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 165 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 166 | PJ_DECL(pj_status_t) pjsip_pres_initiate( pjsip_evsub *sub, |
| 167 | pj_int32_t expires, |
| 168 | pjsip_tx_data **p_tdata); |
| 169 | |
| 170 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 171 | |
| 172 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 173 | * Accept the incoming subscription request by sending 2xx response to |
| 174 | * incoming SUBSCRIBE request. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 175 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 176 | * @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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 180 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 181 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 182 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 183 | PJ_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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 190 | |
| 191 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 192 | * 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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 196 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 197 | * @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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 205 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 206 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 207 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 208 | PJ_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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 214 | |
| 215 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 216 | * Create NOTIFY request to reflect current subscription status. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 217 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 218 | * @param sub Server subscription object. |
| 219 | * @param p_tdata Pointer to receive request. |
| 220 | * |
| 221 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 222 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 223 | PJ_DECL(pj_status_t) pjsip_pres_current_notify( pjsip_evsub *sub, |
| 224 | pjsip_tx_data **p_tdata ); |
| 225 | |
| 226 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 227 | |
| 228 | /** |
Benny Prijono | 26ff906 | 2006-02-21 23:47:00 +0000 | [diff] [blame] | 229 | * 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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 233 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 234 | * @param sub The subscription object. |
| 235 | * @param tdata Request message to be sent. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 236 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 237 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 238 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 239 | PJ_DECL(pj_status_t) pjsip_pres_send_request( pjsip_evsub *sub, |
| 240 | pjsip_tx_data *tdata ); |
| 241 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 242 | |
| 243 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 244 | * Get the presence status. Client normally would call this function |
| 245 | * after receiving NOTIFY request from server. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 246 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 247 | * @param sub The client or server subscription. |
| 248 | * @param status The structure to receive presence status. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 249 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 250 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 251 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 252 | PJ_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 | */ |
| 266 | PJ_DECL(pj_status_t) pjsip_pres_set_status( pjsip_evsub *sub, |
| 267 | const pjsip_pres_status *status ); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 268 | |
| 269 | |
| 270 | /** |
Benny Prijono | 3a5e1ab | 2006-08-15 20:26:34 +0000 | [diff] [blame] | 271 | * 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 | */ |
| 283 | PJ_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 | */ |
| 302 | PJ_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 | */ |
| 319 | PJ_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 | */ |
| 335 | PJ_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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 342 | * @} |
| 343 | */ |
| 344 | |
| 345 | PJ_END_DECL |
| 346 | |
| 347 | |
| 348 | #endif /* __PJSIP_SIMPLE_PRESENCE_H__ */ |