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