blob: a003641a07c3a7afb1c7c68955a7e27f2c4acadc [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
Benny Prijono32177c02008-06-20 22:44:47 +00004 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono5dcb38d2005-11-21 01:55:47 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#ifndef __PJSIP_SIP_REG_H__
21#define __PJSIP_SIP_REG_H__
22
23/**
Benny Prijonoa7b376b2008-01-25 16:06:33 +000024 * @file sip_regc.h
Benny Prijono5dcb38d2005-11-21 01:55:47 +000025 * @brief SIP Registration Client
26 */
27
28#include <pjsip/sip_types.h>
29#include <pjsip/sip_auth.h>
Benny Prijono720d0a82007-01-12 06:37:35 +000030#include <pjsip/sip_transport.h>
Benny Prijono5dcb38d2005-11-21 01:55:47 +000031
Benny Prijono5dcb38d2005-11-21 01:55:47 +000032
33/**
Benny Prijono312aff92006-06-17 04:08:30 +000034 * @defgroup PJSUA_REGC Client Registration
35 * @ingroup PJSIP_HIGH_UA
36 * @brief High Layer API for performing client registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +000037 * @{
Benny Prijono312aff92006-06-17 04:08:30 +000038 *
39 * This provides API for performing client registration. Application must
40 * link with <b>pjsip-ua</b> static library to use this API.
41
Benny Prijono5dcb38d2005-11-21 01:55:47 +000042 */
43
Benny Prijono312aff92006-06-17 04:08:30 +000044
45PJ_BEGIN_DECL
46
Benny Prijono5dcb38d2005-11-21 01:55:47 +000047/** Typedef for client registration data. */
48typedef struct pjsip_regc pjsip_regc;
49
50/** Maximum contacts in registration. */
51#define PJSIP_REGC_MAX_CONTACT 10
52
53/** Expiration not specified. */
54#define PJSIP_REGC_EXPIRATION_NOT_SPECIFIED ((pj_uint32_t)0xFFFFFFFFUL)
55
56/** Buffer to hold all contacts. */
57#define PJSIP_REGC_CONTACT_BUF_SIZE 512
58
59/** Structure to hold parameters when calling application's callback.
60 * The application's callback is called when the client registration process
61 * has finished.
62 */
63struct pjsip_regc_cbparam
64{
Benny Prijono312aff92006-06-17 04:08:30 +000065 pjsip_regc *regc; /**< Client registration structure. */
Benny Prijonodd742da2008-05-17 12:45:00 +000066 void *token; /**< Arbitrary token set by application */
67
68 /** Error status. If this value is non-PJ_SUCCESS, some error has occured.
69 * Note that even when this contains PJ_SUCCESS the registration might
70 * have failed; in this case the \a code field will contain non
71 * successful (non-2xx status class) code
72 */
73 pj_status_t status;
Benny Prijono312aff92006-06-17 04:08:30 +000074 int code; /**< SIP status code received. */
75 pj_str_t reason; /**< SIP reason phrase received. */
76 pjsip_rx_data *rdata; /**< The complete received response. */
77 int expiration;/**< Next expiration interval. */
78 int contact_cnt;/**<Number of contacts in response. */
79 pjsip_contact_hdr *contact[PJSIP_REGC_MAX_CONTACT]; /**< Contacts. */
Benny Prijono5dcb38d2005-11-21 01:55:47 +000080};
81
82
83/** Type declaration for callback to receive registration result. */
84typedef void pjsip_regc_cb(struct pjsip_regc_cbparam *param);
85
Benny Prijonobcaed6c2006-02-19 15:37:19 +000086/**
87 * Client registration information.
88 */
89struct pjsip_regc_info
90{
91 pj_str_t server_uri; /**< Server URI, */
92 pj_str_t client_uri; /**< Client URI (From header). */
93 pj_bool_t is_busy; /**< Have pending transaction? */
94 pj_bool_t auto_reg; /**< Will register automatically? */
95 int interval; /**< Registration interval (seconds). */
96 int next_reg; /**< Time until next registration (seconds). */
Nanang Izzuddin36dd5b62010-03-30 11:13:59 +000097 pjsip_transport *transport; /**< Last transport used. */
Benny Prijonobcaed6c2006-02-19 15:37:19 +000098};
99
100/**
101 * @see pjsip_regc_info
102 */
103typedef struct pjsip_regc_info pjsip_regc_info;
104
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000105
106/**
107 * Get the module instance for client registration module.
108 *
109 * @return client registration module.
110 */
111PJ_DECL(pjsip_module*) pjsip_regc_get_module(void);
112
113
114/**
115 * Create client registration structure.
116 *
117 * @param endpt Endpoint, used to allocate pool from.
118 * @param token A data to be associated with the client registration struct.
119 * @param cb Pointer to callback function to receive registration status.
Benny Prijonoccf95622006-02-07 18:48:01 +0000120 * @param p_regc Pointer to receive client registration structure.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000121 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000122 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000123 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000124PJ_DECL(pj_status_t) pjsip_regc_create( pjsip_endpoint *endpt, void *token,
125 pjsip_regc_cb *cb,
126 pjsip_regc **p_regc);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000127
128
129/**
130 * Destroy client registration structure. If a registration transaction is
131 * in progress, then the structure will be deleted only after a final response
132 * has been received, and in this case, the callback won't be called.
133 *
134 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000135 *
136 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000137 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000138PJ_DECL(pj_status_t) pjsip_regc_destroy(pjsip_regc *regc);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000139
140/**
Benny Prijonobcaed6c2006-02-19 15:37:19 +0000141 * Get registration info.
142 *
143 * @param regc The client registration structure.
144 * @param info Client registration info.
145 *
146 * @return PJ_SUCCESS on success.
147 */
148PJ_DECL(pj_status_t) pjsip_regc_get_info( pjsip_regc *regc,
149 pjsip_regc_info *info );
150
151
152/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000153 * Get the memory pool associated with a registration client handle.
154 *
155 * @param regc The client registration structure.
156 * @return pool handle.
157 */
158PJ_DECL(pj_pool_t*) pjsip_regc_get_pool(pjsip_regc *regc);
159
160/**
161 * Initialize client registration structure with various information needed to
162 * perform the registration.
163 *
164 * @param regc The client registration structure.
Benny Prijono312aff92006-06-17 04:08:30 +0000165 * @param srv_url Server URL.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000166 * @param from_url The person performing the registration, must be a SIP URL type.
167 * @param to_url The address of record for which the registration is targetd, must
168 * be a SIP/SIPS URL.
169 * @param ccnt Number of contacts in the array.
Nanang Izzuddin5af37ff2009-08-05 18:41:23 +0000170 * @param contact Array of contacts, each contact item must be formatted
171 * as described in RFC 3261 Section 20.10:
172 * When the header field value contains a display
173 * name, the URI including all URI parameters is
174 * enclosed in "<" and ">". If no "<" and ">" are
175 * present, all parameters after the URI are header
176 * parameters, not URI parameters. The display name
177 * can be tokens, or a quoted string, if a larger
178 * character set is desired.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000179 * @param expires Default expiration interval (in seconds) to be applied for
180 * contact URL that doesn't have expiration settings. If the
181 * value PJSIP_REGC_EXPIRATION_NOT_SPECIFIED is given, then
182 * no default expiration will be applied.
183 * @return zero on success.
184 */
185PJ_DECL(pj_status_t) pjsip_regc_init(pjsip_regc *regc,
186 const pj_str_t *srv_url,
187 const pj_str_t *from_url,
188 const pj_str_t *to_url,
189 int ccnt,
190 const pj_str_t contact[],
191 pj_uint32_t expires);
192
193
194/**
195 * Set authentication credentials to use by this registration.
196 *
Benny Prijono84126ab2006-02-09 09:30:09 +0000197 * @param regc The registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000198 * @param count Number of credentials in the array.
199 * @param cred Array of credentials.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000200 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000201 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000202 */
203PJ_DECL(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc,
204 int count,
205 const pjsip_cred_info cred[] );
206
207/**
Benny Prijono48ab2b72007-11-08 09:24:30 +0000208 * Set authentication preference.
209 *
210 * @param regc The registration structure.
211 * @param pref Authentication preference.
212 *
213 * @return PJ_SUCCESS on success.
214 */
215PJ_DECL(pj_status_t) pjsip_regc_set_prefs( pjsip_regc *regc,
216 const pjsip_auth_clt_pref *pref);
217
218/**
Benny Prijono84126ab2006-02-09 09:30:09 +0000219 * Set route set to be used for outgoing requests.
220 *
221 * @param regc The client registration structure.
222 * @param route_set List containing Route headers.
223 *
224 * @return PJ_SUCCESS on success.
225 */
226PJ_DECL(pj_status_t) pjsip_regc_set_route_set(pjsip_regc *regc,
227 const pjsip_route_hdr*route_set);
228
Benny Prijono720d0a82007-01-12 06:37:35 +0000229
230/**
231 * Lock/bind client registration to a specific transport/listener.
232 * This is optional, as normally transport will be selected automatically
233 * based on the destination of requests upon resolver completion.
234 * When the client registration is explicitly bound to the specific
235 * transport/listener, all UAC transactions originated by the client
236 * registration will use the specified transport/listener when sending
237 * outgoing requests.
238 *
239 * Note that this doesn't affect the Contact header set for this client
240 * registration. Application must manually update the Contact header if
241 * necessary, to adjust the address according to the transport being
242 * selected.
243 *
244 * @param regc The client registration instance.
245 * @param sel Transport selector containing the specification of
246 * transport or listener to be used by this session
247 * to send requests.
248 *
249 * @return PJ_SUCCESS on success, or the appropriate error code.
250 */
251PJ_DECL(pj_status_t) pjsip_regc_set_transport(pjsip_regc *regc,
252 const pjsip_tpselector *sel);
253
254
Benny Prijono84126ab2006-02-09 09:30:09 +0000255/**
Benny Prijono8fc6de02006-11-11 21:25:55 +0000256 * Add headers to be added to outgoing REGISTER requests.
257 *
258 * @param regc The client registration structure.
259 * @param hdr_list List containing SIP headers to be added for all outgoing
260 * REGISTER requests.
261 *
262 * @return PJ_SUCCESS on success.
263 */
264PJ_DECL(pj_status_t) pjsip_regc_add_headers(pjsip_regc *regc,
265 const pjsip_hdr *hdr_list);
266
267
268/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000269 * Create REGISTER request for the specified client registration structure.
270 *
271 * After successfull registration, application can inspect the contacts in
272 * the client registration structure to list what contacts are associaciated
273 * with the address of record being targeted in the registration.
274 *
275 * @param regc The client registration structure.
276 * @param autoreg If non zero, the library will automatically refresh the
277 * next registration until application unregister.
Benny Prijonoccf95622006-02-07 18:48:01 +0000278 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000279 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000280 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000281 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000282PJ_DECL(pj_status_t) pjsip_regc_register(pjsip_regc *regc, pj_bool_t autoreg,
283 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000284
285
286/**
Benny Prijonodfc4c482006-12-02 07:25:29 +0000287 * Create REGISTER request to unregister the contacts that were previously
288 * registered by this client registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000289 *
290 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000291 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000292 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000293 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000294 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000295PJ_DECL(pj_status_t) pjsip_regc_unregister(pjsip_regc *regc,
296 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000297
298/**
Benny Prijonodfc4c482006-12-02 07:25:29 +0000299 * Create REGISTER request to unregister all contacts from server records.
300 * Note that this will unregister all registered contact for the AOR
301 * including contacts registered by other user agents. To only unregister
302 * contact registered by this client registration instance, use
303 * #pjsip_regc_unregister() instead.
304 *
305 * @param regc The client registration structure.
306 * @param p_tdata Pointer to receive the REGISTER request.
307 *
308 * @return PJ_SUCCESS on success.
309 */
310PJ_DECL(pj_status_t) pjsip_regc_unregister_all(pjsip_regc *regc,
311 pjsip_tx_data **p_tdata);
312
313/**
Benny Prijonodd742da2008-05-17 12:45:00 +0000314 * Update Contact details in the client registration structure. For each
Nanang Izzuddin5af37ff2009-08-05 18:41:23 +0000315 * contact, if the contact is not found in existing contact, it will be
316 * added to the Contact list. If it matches existing contact, nothing
Benny Prijonodd742da2008-05-17 12:45:00 +0000317 * will be added. This function will also mark existing contacts which
318 * are not specified in the new contact list as to be removed, by adding
319 * "expires=0" parameter to these contacts.
320 *
321 * Once the contact list has been updated, application must update the
322 * registration by creating a new REGISTER request and send it to the
323 * registrar. This request will contain both old and new contacts; the
324 * old contacts will have it's expires parameter set to zero to instruct
325 * the registrar to remove the bindings.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000326 *
327 * @param regc The client registration structure.
328 * @param ccnt Number of contacts.
Nanang Izzuddin5af37ff2009-08-05 18:41:23 +0000329 * @param contact Array of contacts, each contact item must be formatted
330 * as described in RFC 3261 Section 20.10:
331 * When the header field value contains a display
332 * name, the URI including all URI parameters is
333 * enclosed in "<" and ">". If no "<" and ">" are
334 * present, all parameters after the URI are header
335 * parameters, not URI parameters. The display name
336 * can be tokens, or a quoted string, if a larger
337 * character set is desired.
Benny Prijonodd742da2008-05-17 12:45:00 +0000338 * @return PJ_SUCCESS if sucessfull.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000339 */
340PJ_DECL(pj_status_t) pjsip_regc_update_contact( pjsip_regc *regc,
341 int ccnt,
342 const pj_str_t contact[] );
343
344/**
Benny Prijonodd742da2008-05-17 12:45:00 +0000345 * Update the expires value. The next REGISTER request will contain
346 * new expires value for the registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000347 *
348 * @param regc The client registration structure.
349 * @param expires The new expires value.
350 * @return zero on successfull.
351 */
352PJ_DECL(pj_status_t) pjsip_regc_update_expires( pjsip_regc *regc,
353 pj_uint32_t expires );
354
355/**
356 * Sends outgoing REGISTER request.
357 * The process will complete asynchronously, and application
358 * will be notified via the callback when the process completes.
359 *
360 * @param regc The client registration structure.
361 * @param tdata Transmit data.
Benny Prijonoccf95622006-02-07 18:48:01 +0000362 *
363 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000364 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000365PJ_DECL(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000366
367
368PJ_END_DECL
369
Benny Prijono312aff92006-06-17 04:08:30 +0000370/**
371 * @}
372 */
373
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000374#endif /* __PJSIP_REG_H__ */