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