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