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_SIP_REG_H__ |
| 20 | #define __PJSIP_SIP_REG_H__ |
| 21 | |
| 22 | /** |
| 23 | * @file sip_reg.h |
| 24 | * @brief SIP Registration Client |
| 25 | */ |
| 26 | |
| 27 | #include <pjsip/sip_types.h> |
| 28 | #include <pjsip/sip_auth.h> |
Benny Prijono | 720d0a8 | 2007-01-12 06:37:35 +0000 | [diff] [blame] | 29 | #include <pjsip/sip_transport.h> |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 30 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 31 | |
| 32 | /** |
Benny Prijono | 312aff9 | 2006-06-17 04:08:30 +0000 | [diff] [blame] | 33 | * @defgroup PJSUA_REGC Client Registration |
| 34 | * @ingroup PJSIP_HIGH_UA |
| 35 | * @brief High Layer API for performing client registration. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 36 | * @{ |
Benny Prijono | 312aff9 | 2006-06-17 04:08:30 +0000 | [diff] [blame] | 37 | * |
| 38 | * This provides API for performing client registration. Application must |
| 39 | * link with <b>pjsip-ua</b> static library to use this API. |
| 40 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 41 | */ |
| 42 | |
Benny Prijono | 312aff9 | 2006-06-17 04:08:30 +0000 | [diff] [blame] | 43 | |
| 44 | PJ_BEGIN_DECL |
| 45 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 46 | /** Typedef for client registration data. */ |
| 47 | typedef struct pjsip_regc pjsip_regc; |
| 48 | |
| 49 | /** Maximum contacts in registration. */ |
| 50 | #define PJSIP_REGC_MAX_CONTACT 10 |
| 51 | |
| 52 | /** Expiration not specified. */ |
| 53 | #define PJSIP_REGC_EXPIRATION_NOT_SPECIFIED ((pj_uint32_t)0xFFFFFFFFUL) |
| 54 | |
| 55 | /** Buffer to hold all contacts. */ |
| 56 | #define PJSIP_REGC_CONTACT_BUF_SIZE 512 |
| 57 | |
| 58 | /** Structure to hold parameters when calling application's callback. |
| 59 | * The application's callback is called when the client registration process |
| 60 | * has finished. |
| 61 | */ |
| 62 | struct pjsip_regc_cbparam |
| 63 | { |
Benny Prijono | 312aff9 | 2006-06-17 04:08:30 +0000 | [diff] [blame] | 64 | pjsip_regc *regc; /**< Client registration structure. */ |
| 65 | void *token; /**< Arbitrary token. */ |
| 66 | pj_status_t status; /**< Error status. */ |
| 67 | int code; /**< SIP status code received. */ |
| 68 | pj_str_t reason; /**< SIP reason phrase received. */ |
| 69 | pjsip_rx_data *rdata; /**< The complete received response. */ |
| 70 | int expiration;/**< Next expiration interval. */ |
| 71 | int contact_cnt;/**<Number of contacts in response. */ |
| 72 | pjsip_contact_hdr *contact[PJSIP_REGC_MAX_CONTACT]; /**< Contacts. */ |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | |
| 76 | /** Type declaration for callback to receive registration result. */ |
| 77 | typedef void pjsip_regc_cb(struct pjsip_regc_cbparam *param); |
| 78 | |
Benny Prijono | bcaed6c | 2006-02-19 15:37:19 +0000 | [diff] [blame] | 79 | /** |
| 80 | * Client registration information. |
| 81 | */ |
| 82 | struct pjsip_regc_info |
| 83 | { |
| 84 | pj_str_t server_uri; /**< Server URI, */ |
| 85 | pj_str_t client_uri; /**< Client URI (From header). */ |
| 86 | pj_bool_t is_busy; /**< Have pending transaction? */ |
| 87 | pj_bool_t auto_reg; /**< Will register automatically? */ |
| 88 | int interval; /**< Registration interval (seconds). */ |
| 89 | int next_reg; /**< Time until next registration (seconds). */ |
| 90 | }; |
| 91 | |
| 92 | /** |
| 93 | * @see pjsip_regc_info |
| 94 | */ |
| 95 | typedef struct pjsip_regc_info pjsip_regc_info; |
| 96 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Get the module instance for client registration module. |
| 100 | * |
| 101 | * @return client registration module. |
| 102 | */ |
| 103 | PJ_DECL(pjsip_module*) pjsip_regc_get_module(void); |
| 104 | |
| 105 | |
| 106 | /** |
| 107 | * Create client registration structure. |
| 108 | * |
| 109 | * @param endpt Endpoint, used to allocate pool from. |
| 110 | * @param token A data to be associated with the client registration struct. |
| 111 | * @param cb Pointer to callback function to receive registration status. |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 112 | * @param p_regc Pointer to receive client registration structure. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 113 | * |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 114 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 115 | */ |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 116 | PJ_DECL(pj_status_t) pjsip_regc_create( pjsip_endpoint *endpt, void *token, |
| 117 | pjsip_regc_cb *cb, |
| 118 | pjsip_regc **p_regc); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 119 | |
| 120 | |
| 121 | /** |
| 122 | * Destroy client registration structure. If a registration transaction is |
| 123 | * in progress, then the structure will be deleted only after a final response |
| 124 | * has been received, and in this case, the callback won't be called. |
| 125 | * |
| 126 | * @param regc The client registration structure. |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 127 | * |
| 128 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 129 | */ |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 130 | PJ_DECL(pj_status_t) pjsip_regc_destroy(pjsip_regc *regc); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 131 | |
| 132 | /** |
Benny Prijono | bcaed6c | 2006-02-19 15:37:19 +0000 | [diff] [blame] | 133 | * Get registration info. |
| 134 | * |
| 135 | * @param regc The client registration structure. |
| 136 | * @param info Client registration info. |
| 137 | * |
| 138 | * @return PJ_SUCCESS on success. |
| 139 | */ |
| 140 | PJ_DECL(pj_status_t) pjsip_regc_get_info( pjsip_regc *regc, |
| 141 | pjsip_regc_info *info ); |
| 142 | |
| 143 | |
| 144 | /** |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 145 | * Get the memory pool associated with a registration client handle. |
| 146 | * |
| 147 | * @param regc The client registration structure. |
| 148 | * @return pool handle. |
| 149 | */ |
| 150 | PJ_DECL(pj_pool_t*) pjsip_regc_get_pool(pjsip_regc *regc); |
| 151 | |
| 152 | /** |
| 153 | * Initialize client registration structure with various information needed to |
| 154 | * perform the registration. |
| 155 | * |
| 156 | * @param regc The client registration structure. |
Benny Prijono | 312aff9 | 2006-06-17 04:08:30 +0000 | [diff] [blame] | 157 | * @param srv_url Server URL. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 158 | * @param from_url The person performing the registration, must be a SIP URL type. |
| 159 | * @param to_url The address of record for which the registration is targetd, must |
| 160 | * be a SIP/SIPS URL. |
| 161 | * @param ccnt Number of contacts in the array. |
| 162 | * @param contact Array of contacts. |
| 163 | * @param expires Default expiration interval (in seconds) to be applied for |
| 164 | * contact URL that doesn't have expiration settings. If the |
| 165 | * value PJSIP_REGC_EXPIRATION_NOT_SPECIFIED is given, then |
| 166 | * no default expiration will be applied. |
| 167 | * @return zero on success. |
| 168 | */ |
| 169 | PJ_DECL(pj_status_t) pjsip_regc_init(pjsip_regc *regc, |
| 170 | const pj_str_t *srv_url, |
| 171 | const pj_str_t *from_url, |
| 172 | const pj_str_t *to_url, |
| 173 | int ccnt, |
| 174 | const pj_str_t contact[], |
| 175 | pj_uint32_t expires); |
| 176 | |
| 177 | |
| 178 | /** |
| 179 | * Set authentication credentials to use by this registration. |
| 180 | * |
Benny Prijono | 84126ab | 2006-02-09 09:30:09 +0000 | [diff] [blame] | 181 | * @param regc The registration structure. |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 182 | * @param count Number of credentials in the array. |
| 183 | * @param cred Array of credentials. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 184 | * |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 185 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 186 | */ |
| 187 | PJ_DECL(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc, |
| 188 | int count, |
| 189 | const pjsip_cred_info cred[] ); |
| 190 | |
| 191 | /** |
Benny Prijono | 84126ab | 2006-02-09 09:30:09 +0000 | [diff] [blame] | 192 | * Set route set to be used for outgoing requests. |
| 193 | * |
| 194 | * @param regc The client registration structure. |
| 195 | * @param route_set List containing Route headers. |
| 196 | * |
| 197 | * @return PJ_SUCCESS on success. |
| 198 | */ |
| 199 | PJ_DECL(pj_status_t) pjsip_regc_set_route_set(pjsip_regc *regc, |
| 200 | const pjsip_route_hdr*route_set); |
| 201 | |
Benny Prijono | 720d0a8 | 2007-01-12 06:37:35 +0000 | [diff] [blame] | 202 | |
| 203 | /** |
| 204 | * Lock/bind client registration to a specific transport/listener. |
| 205 | * This is optional, as normally transport will be selected automatically |
| 206 | * based on the destination of requests upon resolver completion. |
| 207 | * When the client registration is explicitly bound to the specific |
| 208 | * transport/listener, all UAC transactions originated by the client |
| 209 | * registration will use the specified transport/listener when sending |
| 210 | * outgoing requests. |
| 211 | * |
| 212 | * Note that this doesn't affect the Contact header set for this client |
| 213 | * registration. Application must manually update the Contact header if |
| 214 | * necessary, to adjust the address according to the transport being |
| 215 | * selected. |
| 216 | * |
| 217 | * @param regc The client registration instance. |
| 218 | * @param sel Transport selector containing the specification of |
| 219 | * transport or listener to be used by this session |
| 220 | * to send requests. |
| 221 | * |
| 222 | * @return PJ_SUCCESS on success, or the appropriate error code. |
| 223 | */ |
| 224 | PJ_DECL(pj_status_t) pjsip_regc_set_transport(pjsip_regc *regc, |
| 225 | const pjsip_tpselector *sel); |
| 226 | |
| 227 | |
Benny Prijono | 84126ab | 2006-02-09 09:30:09 +0000 | [diff] [blame] | 228 | /** |
Benny Prijono | 8fc6de0 | 2006-11-11 21:25:55 +0000 | [diff] [blame] | 229 | * Add headers to be added to outgoing REGISTER requests. |
| 230 | * |
| 231 | * @param regc The client registration structure. |
| 232 | * @param hdr_list List containing SIP headers to be added for all outgoing |
| 233 | * REGISTER requests. |
| 234 | * |
| 235 | * @return PJ_SUCCESS on success. |
| 236 | */ |
| 237 | PJ_DECL(pj_status_t) pjsip_regc_add_headers(pjsip_regc *regc, |
| 238 | const pjsip_hdr *hdr_list); |
| 239 | |
| 240 | |
| 241 | /** |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 242 | * Create REGISTER request for the specified client registration structure. |
| 243 | * |
| 244 | * After successfull registration, application can inspect the contacts in |
| 245 | * the client registration structure to list what contacts are associaciated |
| 246 | * with the address of record being targeted in the registration. |
| 247 | * |
| 248 | * @param regc The client registration structure. |
| 249 | * @param autoreg If non zero, the library will automatically refresh the |
| 250 | * next registration until application unregister. |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 251 | * @param p_tdata Pointer to receive the REGISTER request. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 252 | * |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 253 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 254 | */ |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 255 | PJ_DECL(pj_status_t) pjsip_regc_register(pjsip_regc *regc, pj_bool_t autoreg, |
| 256 | pjsip_tx_data **p_tdata); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 257 | |
| 258 | |
| 259 | /** |
Benny Prijono | dfc4c48 | 2006-12-02 07:25:29 +0000 | [diff] [blame] | 260 | * Create REGISTER request to unregister the contacts that were previously |
| 261 | * registered by this client registration. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 262 | * |
| 263 | * @param regc The client registration structure. |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 264 | * @param p_tdata Pointer to receive the REGISTER request. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 265 | * |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 266 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 267 | */ |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 268 | PJ_DECL(pj_status_t) pjsip_regc_unregister(pjsip_regc *regc, |
| 269 | pjsip_tx_data **p_tdata); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 270 | |
| 271 | /** |
Benny Prijono | dfc4c48 | 2006-12-02 07:25:29 +0000 | [diff] [blame] | 272 | * Create REGISTER request to unregister all contacts from server records. |
| 273 | * Note that this will unregister all registered contact for the AOR |
| 274 | * including contacts registered by other user agents. To only unregister |
| 275 | * contact registered by this client registration instance, use |
| 276 | * #pjsip_regc_unregister() instead. |
| 277 | * |
| 278 | * @param regc The client registration structure. |
| 279 | * @param p_tdata Pointer to receive the REGISTER request. |
| 280 | * |
| 281 | * @return PJ_SUCCESS on success. |
| 282 | */ |
| 283 | PJ_DECL(pj_status_t) pjsip_regc_unregister_all(pjsip_regc *regc, |
| 284 | pjsip_tx_data **p_tdata); |
| 285 | |
| 286 | /** |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 287 | * Update Contact details in the client registration structure. |
| 288 | * |
| 289 | * @param regc The client registration structure. |
| 290 | * @param ccnt Number of contacts. |
| 291 | * @param contact Array of contacts. |
| 292 | * @return zero if sucessfull. |
| 293 | */ |
| 294 | PJ_DECL(pj_status_t) pjsip_regc_update_contact( pjsip_regc *regc, |
| 295 | int ccnt, |
| 296 | const pj_str_t contact[] ); |
| 297 | |
| 298 | /** |
| 299 | * Update the expires value. |
| 300 | * |
| 301 | * @param regc The client registration structure. |
| 302 | * @param expires The new expires value. |
| 303 | * @return zero on successfull. |
| 304 | */ |
| 305 | PJ_DECL(pj_status_t) pjsip_regc_update_expires( pjsip_regc *regc, |
| 306 | pj_uint32_t expires ); |
| 307 | |
| 308 | /** |
| 309 | * Sends outgoing REGISTER request. |
| 310 | * The process will complete asynchronously, and application |
| 311 | * will be notified via the callback when the process completes. |
| 312 | * |
| 313 | * @param regc The client registration structure. |
| 314 | * @param tdata Transmit data. |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 315 | * |
| 316 | * @return PJ_SUCCESS on success. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 317 | */ |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 318 | PJ_DECL(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 319 | |
| 320 | |
| 321 | PJ_END_DECL |
| 322 | |
Benny Prijono | 312aff9 | 2006-06-17 04:08:30 +0000 | [diff] [blame] | 323 | /** |
| 324 | * @} |
| 325 | */ |
| 326 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 327 | #endif /* __PJSIP_REG_H__ */ |