blob: bfc5b74671cdff855be1ea04d9871f15d5e7be18 [file] [log] [blame]
Alexandre Lision8af73cb2013-12-10 14:11:20 -05001/* $Id: sip_regc.h 4586 2013-09-04 10:07:45Z ming $ */
Tristan Matthews0a329cc2013-07-17 13:20:14 -04002/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
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/**
24 * @file sip_regc.h
25 * @brief SIP Registration Client
26 */
27
28#include <pjsip/sip_types.h>
29#include <pjsip/sip_auth.h>
30#include <pjsip/sip_transport.h>
31
32
33/**
34 * @defgroup PJSUA_REGC Client Registration
35 * @ingroup PJSIP_HIGH_UA
36 * @brief High Layer API for performing client registration.
37 * @{
38 *
39 * This provides API for performing client registration. Application must
40 * link with <b>pjsip-ua</b> static library to use this API.
41
42 */
43
44
45PJ_BEGIN_DECL
46
47/** 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{
65 pjsip_regc *regc; /**< Client registration structure. */
66 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;
74 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. */
80};
81
82
83/** Type declaration for callback to receive registration result. */
84typedef void pjsip_regc_cb(struct pjsip_regc_cbparam *param);
85
86/**
Alexandre Lision94f06ba2013-12-09 16:28:33 -050087 * Structure to hold parameters when calling application's callback
88 * specified in #pjsip_regc_set_reg_tsx_cb().
89 * To update contact address, application can set the field contact_cnt
90 * and contact inside the callback.
91 */
92struct pjsip_regc_tsx_cb_param
93{
94 struct pjsip_regc_cbparam cbparam;
95 int contact_cnt;
96 pj_str_t contact[PJSIP_REGC_MAX_CONTACT];
97};
98
99/** Type declaration for callback set in #pjsip_regc_set_reg_tsx_cb(). */
100typedef void pjsip_regc_tsx_cb(struct pjsip_regc_tsx_cb_param *param);
101
102/**
Tristan Matthews0a329cc2013-07-17 13:20:14 -0400103 * Client registration information.
104 */
105struct pjsip_regc_info
106{
107 pj_str_t server_uri; /**< Server URI, */
108 pj_str_t client_uri; /**< Client URI (From header). */
109 pj_bool_t is_busy; /**< Have pending transaction? */
110 pj_bool_t auto_reg; /**< Will register automatically? */
111 int interval; /**< Registration interval (seconds). */
112 int next_reg; /**< Time until next registration (seconds). */
113 pjsip_transport *transport; /**< Last transport used. */
114};
115
116/**
117 * @see pjsip_regc_info
118 */
119typedef struct pjsip_regc_info pjsip_regc_info;
120
121
122/**
123 * Get the module instance for client registration module.
124 *
125 * @return client registration module.
126 */
127PJ_DECL(pjsip_module*) pjsip_regc_get_module(void);
128
129
130/**
131 * Create client registration structure.
132 *
133 * @param endpt Endpoint, used to allocate pool from.
134 * @param token A data to be associated with the client registration struct.
135 * @param cb Pointer to callback function to receive registration status.
136 * @param p_regc Pointer to receive client registration structure.
137 *
138 * @return PJ_SUCCESS on success.
139 */
140PJ_DECL(pj_status_t) pjsip_regc_create( pjsip_endpoint *endpt, void *token,
141 pjsip_regc_cb *cb,
142 pjsip_regc **p_regc);
143
144
145/**
146 * Destroy client registration structure. If a registration transaction is
147 * in progress, then the structure will be deleted only after a final response
148 * has been received, and in this case, the callback won't be called.
149 *
150 * @param regc The client registration structure.
151 *
152 * @return PJ_SUCCESS on success.
153 */
154PJ_DECL(pj_status_t) pjsip_regc_destroy(pjsip_regc *regc);
155
156/**
157 * Get registration info.
158 *
159 * @param regc The client registration structure.
160 * @param info Client registration info.
161 *
162 * @return PJ_SUCCESS on success.
163 */
164PJ_DECL(pj_status_t) pjsip_regc_get_info( pjsip_regc *regc,
165 pjsip_regc_info *info );
166
167
168/**
169 * Get the memory pool associated with a registration client handle.
170 *
171 * @param regc The client registration structure.
172 * @return pool handle.
173 */
174PJ_DECL(pj_pool_t*) pjsip_regc_get_pool(pjsip_regc *regc);
175
176/**
177 * Initialize client registration structure with various information needed to
178 * perform the registration.
179 *
180 * @param regc The client registration structure.
181 * @param srv_url Server URL.
182 * @param from_url The person performing the registration, must be a SIP URL type.
183 * @param to_url The address of record for which the registration is targetd, must
184 * be a SIP/SIPS URL.
185 * @param ccnt Number of contacts in the array.
186 * @param contact Array of contacts, each contact item must be formatted
187 * as described in RFC 3261 Section 20.10:
188 * When the header field value contains a display
189 * name, the URI including all URI parameters is
190 * enclosed in "<" and ">". If no "<" and ">" are
191 * present, all parameters after the URI are header
192 * parameters, not URI parameters. The display name
193 * can be tokens, or a quoted string, if a larger
194 * character set is desired.
195 * @param expires Default expiration interval (in seconds) to be applied for
196 * contact URL that doesn't have expiration settings. If the
197 * value PJSIP_REGC_EXPIRATION_NOT_SPECIFIED is given, then
198 * no default expiration will be applied.
199 * @return zero on success.
200 */
201PJ_DECL(pj_status_t) pjsip_regc_init(pjsip_regc *regc,
202 const pj_str_t *srv_url,
203 const pj_str_t *from_url,
204 const pj_str_t *to_url,
205 int ccnt,
206 const pj_str_t contact[],
207 pj_uint32_t expires);
208
209/**
Alexandre Lision94f06ba2013-12-09 16:28:33 -0500210 * Set callback to be called when the registration received a final response.
211 * This callback is different with the one specified during creation via
212 * #pjsip_regc_create(). This callback will be called for any final response
213 * (including 401/407/423) and before any subsequent requests are sent.
214 * In case of unregistration, this callback will not be called.
215 *
216 * @param regc The client registration structure.
217 * @param tsx_cb Pointer to callback function to receive registration status.
218 *
219 * @return PJ_SUCCESS on success.
220 */
221PJ_DECL(pj_status_t) pjsip_regc_set_reg_tsx_cb(pjsip_regc *regc,
222 pjsip_regc_tsx_cb *tsx_cb);
223
224/**
Tristan Matthews0a329cc2013-07-17 13:20:14 -0400225 * Set the "sent-by" field of the Via header for outgoing requests.
226 *
227 * @param regc The client registration structure.
228 * @param via_addr Set via_addr to use for the Via header or NULL to use
229 * the transport's published name.
230 * @param via_tp via_addr will only be used if we are using via_tp
231 * transport.
232 *
233 * @return PJ_SUCCESS on success.
234 */
235PJ_DECL(pj_status_t) pjsip_regc_set_via_sent_by(pjsip_regc *regc,
236 pjsip_host_port *via_addr,
237 pjsip_transport *via_tp);
238
239/**
240 * Set the number of seconds to refresh the client registration before
241 * the registration expires.
242 *
243 * @param regc The registration structure.
244 * @param delay The number of seconds to refresh the client
245 * registration before the registration expires.
246 *
247 * @return PJ_SUCCESS on success.
248 */
249PJ_DECL(pj_status_t)
250pjsip_regc_set_delay_before_refresh( pjsip_regc *regc,
251 pj_uint32_t delay );
252
253
254/**
255 * Set authentication credentials to use by this registration.
256 *
257 * @param regc The registration structure.
258 * @param count Number of credentials in the array.
259 * @param cred Array of credentials.
260 *
261 * @return PJ_SUCCESS on success.
262 */
263PJ_DECL(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc,
264 int count,
265 const pjsip_cred_info cred[] );
266
267/**
268 * Set authentication preference.
269 *
270 * @param regc The registration structure.
271 * @param pref Authentication preference.
272 *
273 * @return PJ_SUCCESS on success.
274 */
275PJ_DECL(pj_status_t) pjsip_regc_set_prefs( pjsip_regc *regc,
276 const pjsip_auth_clt_pref *pref);
277
278/**
279 * Set route set to be used for outgoing requests.
280 *
281 * @param regc The client registration structure.
282 * @param route_set List containing Route headers.
283 *
284 * @return PJ_SUCCESS on success.
285 */
286PJ_DECL(pj_status_t) pjsip_regc_set_route_set(pjsip_regc *regc,
287 const pjsip_route_hdr*route_set);
288
289
290/**
291 * Lock/bind client registration to a specific transport/listener.
292 * This is optional, as normally transport will be selected automatically
293 * based on the destination of requests upon resolver completion.
294 * When the client registration is explicitly bound to the specific
295 * transport/listener, all UAC transactions originated by the client
296 * registration will use the specified transport/listener when sending
297 * outgoing requests.
298 *
299 * Note that this doesn't affect the Contact header set for this client
300 * registration. Application must manually update the Contact header if
301 * necessary, to adjust the address according to the transport being
302 * selected.
303 *
304 * @param regc The client registration instance.
305 * @param sel Transport selector containing the specification of
306 * transport or listener to be used by this session
307 * to send requests.
308 *
309 * @return PJ_SUCCESS on success, or the appropriate error code.
310 */
311PJ_DECL(pj_status_t) pjsip_regc_set_transport(pjsip_regc *regc,
312 const pjsip_tpselector *sel);
313
314/**
315 * Release the reference to current transport being used by the regc, if any.
316 * The regc keeps the reference to the last transport being used in order
317 * to prevent it from being destroyed. In some situation however, such as
318 * when the transport is disconnected, it is necessary to instruct the
319 * regc to release this reference so that the transport can be destroyed.
320 * See https://trac.pjsip.org/repos/ticket/1481 for background info.
321 *
322 * @param regc The client registration instance.
323 *
324 * @return PJ_SUCCESS on success, or the appropriate error code.
325 */
326PJ_DECL(pj_status_t) pjsip_regc_release_transport(pjsip_regc *regc);
327
328/**
329 * Add headers to be added to outgoing REGISTER requests.
330 *
331 * @param regc The client registration structure.
332 * @param hdr_list List containing SIP headers to be added for all outgoing
333 * REGISTER requests.
334 *
335 * @return PJ_SUCCESS on success.
336 */
337PJ_DECL(pj_status_t) pjsip_regc_add_headers(pjsip_regc *regc,
338 const pjsip_hdr *hdr_list);
339
340
341/**
342 * Create REGISTER request for the specified client registration structure.
343 *
344 * After successfull registration, application can inspect the contacts in
345 * the client registration structure to list what contacts are associaciated
346 * with the address of record being targeted in the registration.
347 *
348 * @param regc The client registration structure.
349 * @param autoreg If non zero, the library will automatically refresh the
350 * next registration until application unregister.
351 * @param p_tdata Pointer to receive the REGISTER request.
352 *
353 * @return PJ_SUCCESS on success.
354 */
355PJ_DECL(pj_status_t) pjsip_regc_register(pjsip_regc *regc, pj_bool_t autoreg,
356 pjsip_tx_data **p_tdata);
357
358
359/**
360 * Create REGISTER request to unregister the contacts that were previously
361 * registered by this client registration.
362 *
363 * @param regc The client registration structure.
364 * @param p_tdata Pointer to receive the REGISTER request.
365 *
366 * @return PJ_SUCCESS on success.
367 */
368PJ_DECL(pj_status_t) pjsip_regc_unregister(pjsip_regc *regc,
369 pjsip_tx_data **p_tdata);
370
371/**
372 * Create REGISTER request to unregister all contacts from server records.
373 * Note that this will unregister all registered contact for the AOR
374 * including contacts registered by other user agents. To only unregister
375 * contact registered by this client registration instance, use
376 * #pjsip_regc_unregister() instead.
377 *
378 * @param regc The client registration structure.
379 * @param p_tdata Pointer to receive the REGISTER request.
380 *
381 * @return PJ_SUCCESS on success.
382 */
383PJ_DECL(pj_status_t) pjsip_regc_unregister_all(pjsip_regc *regc,
384 pjsip_tx_data **p_tdata);
385
386/**
387 * Update Contact details in the client registration structure. For each
388 * contact, if the contact is not found in existing contact, it will be
389 * added to the Contact list. If it matches existing contact, nothing
390 * will be added. This function will also mark existing contacts which
391 * are not specified in the new contact list as to be removed, by adding
392 * "expires=0" parameter to these contacts.
393 *
394 * Once the contact list has been updated, application must update the
395 * registration by creating a new REGISTER request and send it to the
396 * registrar. This request will contain both old and new contacts; the
397 * old contacts will have it's expires parameter set to zero to instruct
398 * the registrar to remove the bindings.
399 *
400 * @param regc The client registration structure.
401 * @param ccnt Number of contacts.
402 * @param contact Array of contacts, each contact item must be formatted
403 * as described in RFC 3261 Section 20.10:
404 * When the header field value contains a display
405 * name, the URI including all URI parameters is
406 * enclosed in "<" and ">". If no "<" and ">" are
407 * present, all parameters after the URI are header
408 * parameters, not URI parameters. The display name
409 * can be tokens, or a quoted string, if a larger
410 * character set is desired.
411 * @return PJ_SUCCESS if sucessfull.
412 */
413PJ_DECL(pj_status_t) pjsip_regc_update_contact( pjsip_regc *regc,
414 int ccnt,
415 const pj_str_t contact[] );
416
417/**
418 * Update the expires value. The next REGISTER request will contain
419 * new expires value for the registration.
420 *
421 * @param regc The client registration structure.
422 * @param expires The new expires value.
423 * @return zero on successfull.
424 */
425PJ_DECL(pj_status_t) pjsip_regc_update_expires( pjsip_regc *regc,
426 pj_uint32_t expires );
427
428/**
429 * Sends outgoing REGISTER request.
430 * The process will complete asynchronously, and application
431 * will be notified via the callback when the process completes.
432 *
433 * @param regc The client registration structure.
434 * @param tdata Transmit data.
435 *
436 * @return PJ_SUCCESS on success.
437 */
438PJ_DECL(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata);
439
440
441PJ_END_DECL
442
443/**
444 * @}
445 */
446
447#endif /* __PJSIP_REG_H__ */