Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 1 | /* $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 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. |
| 106 | * @param p_evsub Pointer to receive the presence subscription |
| 107 | * session. |
| 108 | * |
| 109 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 110 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 111 | PJ_DECL(pj_status_t) pjsip_pres_create_uac( pjsip_dialog *dlg, |
| 112 | const pjsip_evsub_user *user_cb, |
| 113 | pjsip_evsub **p_evsub ); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 114 | |
| 115 | |
| 116 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 117 | * Create presence server subscription session. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 118 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 119 | * @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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 126 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 127 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 128 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 129 | PJ_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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 134 | |
| 135 | /** |
Benny Prijono | d4e0abd | 2006-03-05 11:53:36 +0000 | [diff] [blame] | 136 | * 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 | */ |
| 147 | PJ_DECL(pj_status_t) pjsip_pres_terminate( pjsip_evsub *sub, |
| 148 | pj_bool_t notify ); |
| 149 | |
| 150 | |
| 151 | |
| 152 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 153 | * Call this function to create request to initiate presence subscription, to |
| 154 | * refresh subcription, or to request subscription termination. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 155 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 156 | * @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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 160 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 161 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 162 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 163 | PJ_DECL(pj_status_t) pjsip_pres_initiate( pjsip_evsub *sub, |
| 164 | pj_int32_t expires, |
| 165 | pjsip_tx_data **p_tdata); |
| 166 | |
| 167 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 168 | |
| 169 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 170 | * Accept the incoming subscription request by sending 2xx response to |
| 171 | * incoming SUBSCRIBE request. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 172 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 173 | * @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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 177 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 178 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 179 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 180 | PJ_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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 187 | |
| 188 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 189 | * 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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 193 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 194 | * @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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 202 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 203 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 204 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 205 | PJ_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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 211 | |
| 212 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 213 | * Create NOTIFY request to reflect current subscription status. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 214 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 215 | * @param sub Server subscription object. |
| 216 | * @param p_tdata Pointer to receive request. |
| 217 | * |
| 218 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 219 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 220 | PJ_DECL(pj_status_t) pjsip_pres_current_notify( pjsip_evsub *sub, |
| 221 | pjsip_tx_data **p_tdata ); |
| 222 | |
| 223 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 224 | |
| 225 | /** |
Benny Prijono | 26ff906 | 2006-02-21 23:47:00 +0000 | [diff] [blame] | 226 | * 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 Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 230 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 231 | * @param sub The subscription object. |
| 232 | * @param tdata Request message to be sent. |
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 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 235 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 236 | PJ_DECL(pj_status_t) pjsip_pres_send_request( pjsip_evsub *sub, |
| 237 | pjsip_tx_data *tdata ); |
| 238 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 239 | |
| 240 | /** |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 241 | * Get the presence status. Client normally would call this function |
| 242 | * after receiving NOTIFY request from server. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 243 | * |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 244 | * @param sub The client or server subscription. |
| 245 | * @param status The structure to receive presence status. |
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 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 248 | */ |
Benny Prijono | 834aee3 | 2006-02-19 01:38:06 +0000 | [diff] [blame] | 249 | PJ_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 | */ |
| 263 | PJ_DECL(pj_status_t) pjsip_pres_set_status( pjsip_evsub *sub, |
| 264 | const pjsip_pres_status *status ); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 265 | |
| 266 | |
| 267 | /** |
| 268 | * @} |
| 269 | */ |
| 270 | |
| 271 | PJ_END_DECL |
| 272 | |
| 273 | |
| 274 | #endif /* __PJSIP_SIMPLE_PRESENCE_H__ */ |