| 1 | /* |
| 2 | * Copyright (C) 2009-2011 Teluu Inc. (http://www.teluu.com) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | */ |
| 18 | #ifndef __PJSIP_TIMER_H__ |
| 19 | #define __PJSIP_TIMER_H__ |
| 20 | |
| 21 | |
| 22 | /** |
| 23 | * @file sip_timer.h |
| 24 | * @brief SIP Session Timers support (RFC 4028 - Session Timer in SIP) |
| 25 | */ |
| 26 | |
| 27 | #include <pjsip-ua/sip_inv.h> |
| 28 | #include <pjsip/sip_msg.h> |
| 29 | |
| 30 | /** |
| 31 | * @defgroup PJSIP_TIMER SIP Session Timers support (RFC 4028 - Session Timers in SIP) |
| 32 | * @ingroup PJSIP_HIGH_UA |
| 33 | * @brief SIP Session Timers support (RFC 4028 - Session Timers in SIP) |
| 34 | * @{ |
| 35 | * |
| 36 | * \section PJSIP_TIMER_REFERENCE References |
| 37 | * |
| 38 | * References: |
| 39 | * - <A HREF="http://www.ietf.org/rfc/rfc4028.txt">RFC 4028: Session Timers |
| 40 | * in the Session Initiation Protocol (SIP)</A> |
| 41 | */ |
| 42 | |
| 43 | PJ_BEGIN_DECL |
| 44 | |
| 45 | /** |
| 46 | * Opaque declaration of Session Timers. |
| 47 | */ |
| 48 | typedef struct pjsip_timer pjsip_timer; |
| 49 | |
| 50 | |
| 51 | /** |
| 52 | * This structure describes Session Timers settings in an invite session. |
| 53 | */ |
| 54 | typedef struct pjsip_timer_setting |
| 55 | { |
| 56 | /** |
| 57 | * Specify minimum session expiration period, in seconds. Must not be |
| 58 | * lower than 90. Default is 90. |
| 59 | */ |
| 60 | unsigned min_se; |
| 61 | |
| 62 | /** |
| 63 | * Specify session expiration period, in seconds. Must not be lower than |
| 64 | * #min_se. Default is 1800. |
| 65 | */ |
| 66 | unsigned sess_expires; |
| 67 | |
| 68 | } pjsip_timer_setting; |
| 69 | |
| 70 | |
| 71 | /** |
| 72 | * SIP Session-Expires header (RFC 4028). |
| 73 | */ |
| 74 | typedef struct pjsip_sess_expires_hdr |
| 75 | { |
| 76 | /** Standard header field. */ |
| 77 | PJSIP_DECL_HDR_MEMBER(struct pjsip_sess_expires_hdr); |
| 78 | |
| 79 | /** Session expiration period */ |
| 80 | unsigned sess_expires; |
| 81 | |
| 82 | /** Refresher */ |
| 83 | pj_str_t refresher; |
| 84 | |
| 85 | /** Other parameters */ |
| 86 | pjsip_param other_param; |
| 87 | |
| 88 | } pjsip_sess_expires_hdr; |
| 89 | |
| 90 | |
| 91 | /** |
| 92 | * SIP Min-SE header (RFC 4028). |
| 93 | */ |
| 94 | typedef struct pjsip_min_se_hdr |
| 95 | { |
| 96 | /** Standard header field. */ |
| 97 | PJSIP_DECL_HDR_MEMBER(struct pjsip_min_se_hdr); |
| 98 | |
| 99 | /** Minimum session expiration period */ |
| 100 | unsigned min_se; |
| 101 | |
| 102 | /** Other parameters */ |
| 103 | pjsip_param other_param; |
| 104 | |
| 105 | } pjsip_min_se_hdr; |
| 106 | |
| 107 | |
| 108 | |
| 109 | /** |
| 110 | * Initialize Session Timers module. This function must be called once during |
| 111 | * application initialization, to register this module to SIP endpoint. |
| 112 | * |
| 113 | * @param endpt The SIP endpoint instance. |
| 114 | * |
| 115 | * @return PJ_SUCCESS if module is successfully initialized. |
| 116 | */ |
| 117 | PJ_DECL(pj_status_t) pjsip_timer_init_module(pjsip_endpoint *endpt); |
| 118 | |
| 119 | |
| 120 | /** |
| 121 | * Initialize Session Timers setting with default values. |
| 122 | * |
| 123 | * @param setting Session Timers setting to be initialized. |
| 124 | * |
| 125 | * @return PJ_SUCCESS on successful. |
| 126 | */ |
| 127 | PJ_DECL(pj_status_t) pjsip_timer_setting_default(pjsip_timer_setting *setting); |
| 128 | |
| 129 | |
| 130 | /** |
| 131 | * Initialize Session Timers for an invite session. This function should be |
| 132 | * called by application to apply Session Timers setting, otherwise invite |
| 133 | * session will apply default setting to the Session Timers. |
| 134 | * |
| 135 | * @param inv The invite session. |
| 136 | * @param setting Session Timers setting, see pjsip_timer_setting. |
| 137 | * If setting is NULL, default setting will be applied. |
| 138 | * |
| 139 | * @return PJ_SUCCESS on successful. |
| 140 | */ |
| 141 | PJ_DECL(pj_status_t) pjsip_timer_init_session( |
| 142 | pjsip_inv_session *inv, |
| 143 | const pjsip_timer_setting *setting); |
| 144 | |
| 145 | |
| 146 | /** |
| 147 | * Create Session-Expires header. |
| 148 | * |
| 149 | * @param pool Pool to allocate the header instance from. |
| 150 | * |
| 151 | * @return An empty Session-Expires header instance. |
| 152 | */ |
| 153 | PJ_DECL(pjsip_sess_expires_hdr*) pjsip_sess_expires_hdr_create( |
| 154 | pj_pool_t *pool); |
| 155 | |
| 156 | |
| 157 | /** |
| 158 | * Create Min-SE header. |
| 159 | * |
| 160 | * @param pool Pool to allocate the header instance from. |
| 161 | * |
| 162 | * @return An empty Min-SE header instance. |
| 163 | */ |
| 164 | PJ_DECL(pjsip_min_se_hdr*) pjsip_min_se_hdr_create(pj_pool_t *pool); |
| 165 | |
| 166 | |
| 167 | /** |
| 168 | * Update outgoing request to insert Session Timers headers and also |
| 169 | * signal Session Timers capability in Supported and/or Require headers. |
| 170 | * |
| 171 | * This function will be called internally by the invite session if it |
| 172 | * detects that the session needs Session Timers support. |
| 173 | * |
| 174 | * @param inv The invite session. |
| 175 | * @param tdata Outgoing INVITE or UPDATE request. |
| 176 | * |
| 177 | * @return PJ_SUCCESS on successful. |
| 178 | */ |
| 179 | PJ_DECL(pj_status_t) pjsip_timer_update_req(pjsip_inv_session *inv, |
| 180 | pjsip_tx_data *tdata); |
| 181 | |
| 182 | |
| 183 | /** |
| 184 | * Process Session Timers headers in incoming response, this function |
| 185 | * will only process incoming response with status code 422 (Session |
| 186 | * Interval Too Small) or 2xx (final response). |
| 187 | * |
| 188 | * This function will be called internally by the invite session if it |
| 189 | * detects that the session needs Session Timers support. |
| 190 | * |
| 191 | * @param inv The invite session. |
| 192 | * @param rdata Incoming response data. |
| 193 | * @param st_code Output buffer to store corresponding SIP status code |
| 194 | * when function returning non-PJ_SUCCESS. |
| 195 | * |
| 196 | * @return PJ_SUCCESS on successful. |
| 197 | */ |
| 198 | PJ_DECL(pj_status_t) pjsip_timer_process_resp(pjsip_inv_session *inv, |
| 199 | const pjsip_rx_data *rdata, |
| 200 | pjsip_status_code *st_code); |
| 201 | |
| 202 | /** |
| 203 | * Process Session Timers refresh error, this function will process |
| 204 | * error from refresh request. The error will be handle according the |
| 205 | * error code, i.e : BYE will be sent after error 503 (Transport Error). |
| 206 | * |
| 207 | * @param inv The invite session. |
| 208 | * @param event The event that trigger the error. |
| 209 | * |
| 210 | * @return PJ_SUCCESS on successful. |
| 211 | */ |
| 212 | PJ_DECL(pj_status_t) pjsip_timer_handle_refresh_error( |
| 213 | pjsip_inv_session *inv, |
| 214 | pjsip_event *event); |
| 215 | |
| 216 | /** |
| 217 | * Process Session Timers headers in incoming request, this function |
| 218 | * will only process incoming INVITE and UPDATE request. |
| 219 | * |
| 220 | * This function will be called internally by the invite session if it |
| 221 | * detects that the session needs Session Timers support. |
| 222 | * |
| 223 | * @param inv The invite session. |
| 224 | * @param rdata Incoming INVITE or UPDATE request. |
| 225 | * @param st_code Output buffer to store corresponding SIP status code |
| 226 | * when function returning non-PJ_SUCCESS. |
| 227 | * |
| 228 | * @return PJ_SUCCESS on successful. |
| 229 | */ |
| 230 | PJ_DECL(pj_status_t) pjsip_timer_process_req(pjsip_inv_session *inv, |
| 231 | const pjsip_rx_data *rdata, |
| 232 | pjsip_status_code *st_code); |
| 233 | |
| 234 | |
| 235 | /** |
| 236 | * Update outgoing response to insert Session Timers headers and also |
| 237 | * signal Session Timers capability in Supported and/or Require headers. |
| 238 | * This function will only update outgoing response with status code |
| 239 | * 422 (Session Interval Too Small) or 2xx (final response). |
| 240 | * |
| 241 | * This function will be called internally by the invite session if it |
| 242 | * detects that the session needs Session Timers support. |
| 243 | * |
| 244 | * @param inv The invite session. |
| 245 | * @param tdata Outgoing 422/2xx response. |
| 246 | * |
| 247 | * @return PJ_SUCCESS on successful. |
| 248 | */ |
| 249 | PJ_DECL(pj_status_t) pjsip_timer_update_resp(pjsip_inv_session *inv, |
| 250 | pjsip_tx_data *tdata); |
| 251 | |
| 252 | /** |
| 253 | * End Session Timers in an invite session. |
| 254 | * |
| 255 | * This function will be called internally by the invite session if it |
| 256 | * detects that the session needs Session Timers support. |
| 257 | * |
| 258 | * @param inv The invite session. |
| 259 | * |
| 260 | * @return PJ_SUCCESS on successful. |
| 261 | */ |
| 262 | PJ_DECL(pj_status_t) pjsip_timer_end_session(pjsip_inv_session *inv); |
| 263 | |
| 264 | |
| 265 | |
| 266 | PJ_END_DECL |
| 267 | |
| 268 | |
| 269 | /** |
| 270 | * @} |
| 271 | */ |
| 272 | |
| 273 | |
| 274 | #endif /* __PJSIP_TIMER_H__ */ |