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