blob: eb8b33c0cd8790388a457932514e0f299653e413 [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). */
97};
98
99/**
100 * @see pjsip_regc_info
101 */
102typedef struct pjsip_regc_info pjsip_regc_info;
103
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000104
105/**
106 * Get the module instance for client registration module.
107 *
108 * @return client registration module.
109 */
110PJ_DECL(pjsip_module*) pjsip_regc_get_module(void);
111
112
113/**
114 * Create client registration structure.
115 *
116 * @param endpt Endpoint, used to allocate pool from.
117 * @param token A data to be associated with the client registration struct.
118 * @param cb Pointer to callback function to receive registration status.
Benny Prijonoccf95622006-02-07 18:48:01 +0000119 * @param p_regc Pointer to receive client registration structure.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000120 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000121 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000122 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000123PJ_DECL(pj_status_t) pjsip_regc_create( pjsip_endpoint *endpt, void *token,
124 pjsip_regc_cb *cb,
125 pjsip_regc **p_regc);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000126
127
128/**
129 * Destroy client registration structure. If a registration transaction is
130 * in progress, then the structure will be deleted only after a final response
131 * has been received, and in this case, the callback won't be called.
132 *
133 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000134 *
135 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000136 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000137PJ_DECL(pj_status_t) pjsip_regc_destroy(pjsip_regc *regc);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000138
139/**
Benny Prijonobcaed6c2006-02-19 15:37:19 +0000140 * Get registration info.
141 *
142 * @param regc The client registration structure.
143 * @param info Client registration info.
144 *
145 * @return PJ_SUCCESS on success.
146 */
147PJ_DECL(pj_status_t) pjsip_regc_get_info( pjsip_regc *regc,
148 pjsip_regc_info *info );
149
150
151/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000152 * Get the memory pool associated with a registration client handle.
153 *
154 * @param regc The client registration structure.
155 * @return pool handle.
156 */
157PJ_DECL(pj_pool_t*) pjsip_regc_get_pool(pjsip_regc *regc);
158
159/**
160 * Initialize client registration structure with various information needed to
161 * perform the registration.
162 *
163 * @param regc The client registration structure.
Benny Prijono312aff92006-06-17 04:08:30 +0000164 * @param srv_url Server URL.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000165 * @param from_url The person performing the registration, must be a SIP URL type.
166 * @param to_url The address of record for which the registration is targetd, must
167 * be a SIP/SIPS URL.
168 * @param ccnt Number of contacts in the array.
Nanang Izzuddin5af37ff2009-08-05 18:41:23 +0000169 * @param contact Array of contacts, each contact item must be formatted
170 * as described in RFC 3261 Section 20.10:
171 * When the header field value contains a display
172 * name, the URI including all URI parameters is
173 * enclosed in "<" and ">". If no "<" and ">" are
174 * present, all parameters after the URI are header
175 * parameters, not URI parameters. The display name
176 * can be tokens, or a quoted string, if a larger
177 * character set is desired.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000178 * @param expires Default expiration interval (in seconds) to be applied for
179 * contact URL that doesn't have expiration settings. If the
180 * value PJSIP_REGC_EXPIRATION_NOT_SPECIFIED is given, then
181 * no default expiration will be applied.
182 * @return zero on success.
183 */
184PJ_DECL(pj_status_t) pjsip_regc_init(pjsip_regc *regc,
185 const pj_str_t *srv_url,
186 const pj_str_t *from_url,
187 const pj_str_t *to_url,
188 int ccnt,
189 const pj_str_t contact[],
190 pj_uint32_t expires);
191
192
193/**
194 * Set authentication credentials to use by this registration.
195 *
Benny Prijono84126ab2006-02-09 09:30:09 +0000196 * @param regc The registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000197 * @param count Number of credentials in the array.
198 * @param cred Array of credentials.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000199 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000200 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000201 */
202PJ_DECL(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc,
203 int count,
204 const pjsip_cred_info cred[] );
205
206/**
Benny Prijono48ab2b72007-11-08 09:24:30 +0000207 * Set authentication preference.
208 *
209 * @param regc The registration structure.
210 * @param pref Authentication preference.
211 *
212 * @return PJ_SUCCESS on success.
213 */
214PJ_DECL(pj_status_t) pjsip_regc_set_prefs( pjsip_regc *regc,
215 const pjsip_auth_clt_pref *pref);
216
217/**
Benny Prijono84126ab2006-02-09 09:30:09 +0000218 * Set route set to be used for outgoing requests.
219 *
220 * @param regc The client registration structure.
221 * @param route_set List containing Route headers.
222 *
223 * @return PJ_SUCCESS on success.
224 */
225PJ_DECL(pj_status_t) pjsip_regc_set_route_set(pjsip_regc *regc,
226 const pjsip_route_hdr*route_set);
227
Benny Prijono720d0a82007-01-12 06:37:35 +0000228
229/**
230 * Lock/bind client registration to a specific transport/listener.
231 * This is optional, as normally transport will be selected automatically
232 * based on the destination of requests upon resolver completion.
233 * When the client registration is explicitly bound to the specific
234 * transport/listener, all UAC transactions originated by the client
235 * registration will use the specified transport/listener when sending
236 * outgoing requests.
237 *
238 * Note that this doesn't affect the Contact header set for this client
239 * registration. Application must manually update the Contact header if
240 * necessary, to adjust the address according to the transport being
241 * selected.
242 *
243 * @param regc The client registration instance.
244 * @param sel Transport selector containing the specification of
245 * transport or listener to be used by this session
246 * to send requests.
247 *
248 * @return PJ_SUCCESS on success, or the appropriate error code.
249 */
250PJ_DECL(pj_status_t) pjsip_regc_set_transport(pjsip_regc *regc,
251 const pjsip_tpselector *sel);
252
253
Benny Prijono84126ab2006-02-09 09:30:09 +0000254/**
Benny Prijono8fc6de02006-11-11 21:25:55 +0000255 * Add headers to be added to outgoing REGISTER requests.
256 *
257 * @param regc The client registration structure.
258 * @param hdr_list List containing SIP headers to be added for all outgoing
259 * REGISTER requests.
260 *
261 * @return PJ_SUCCESS on success.
262 */
263PJ_DECL(pj_status_t) pjsip_regc_add_headers(pjsip_regc *regc,
264 const pjsip_hdr *hdr_list);
265
266
267/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000268 * Create REGISTER request for the specified client registration structure.
269 *
270 * After successfull registration, application can inspect the contacts in
271 * the client registration structure to list what contacts are associaciated
272 * with the address of record being targeted in the registration.
273 *
274 * @param regc The client registration structure.
275 * @param autoreg If non zero, the library will automatically refresh the
276 * next registration until application unregister.
Benny Prijonoccf95622006-02-07 18:48:01 +0000277 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000278 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000279 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000280 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000281PJ_DECL(pj_status_t) pjsip_regc_register(pjsip_regc *regc, pj_bool_t autoreg,
282 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000283
284
285/**
Benny Prijonodfc4c482006-12-02 07:25:29 +0000286 * Create REGISTER request to unregister the contacts that were previously
287 * registered by this client registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000288 *
289 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000290 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000291 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000292 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000293 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000294PJ_DECL(pj_status_t) pjsip_regc_unregister(pjsip_regc *regc,
295 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000296
297/**
Benny Prijonodfc4c482006-12-02 07:25:29 +0000298 * Create REGISTER request to unregister all contacts from server records.
299 * Note that this will unregister all registered contact for the AOR
300 * including contacts registered by other user agents. To only unregister
301 * contact registered by this client registration instance, use
302 * #pjsip_regc_unregister() instead.
303 *
304 * @param regc The client registration structure.
305 * @param p_tdata Pointer to receive the REGISTER request.
306 *
307 * @return PJ_SUCCESS on success.
308 */
309PJ_DECL(pj_status_t) pjsip_regc_unregister_all(pjsip_regc *regc,
310 pjsip_tx_data **p_tdata);
311
312/**
Benny Prijonodd742da2008-05-17 12:45:00 +0000313 * Update Contact details in the client registration structure. For each
Nanang Izzuddin5af37ff2009-08-05 18:41:23 +0000314 * contact, if the contact is not found in existing contact, it will be
315 * added to the Contact list. If it matches existing contact, nothing
Benny Prijonodd742da2008-05-17 12:45:00 +0000316 * will be added. This function will also mark existing contacts which
317 * are not specified in the new contact list as to be removed, by adding
318 * "expires=0" parameter to these contacts.
319 *
320 * Once the contact list has been updated, application must update the
321 * registration by creating a new REGISTER request and send it to the
322 * registrar. This request will contain both old and new contacts; the
323 * old contacts will have it's expires parameter set to zero to instruct
324 * the registrar to remove the bindings.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000325 *
326 * @param regc The client registration structure.
327 * @param ccnt Number of contacts.
Nanang Izzuddin5af37ff2009-08-05 18:41:23 +0000328 * @param contact Array of contacts, each contact item must be formatted
329 * as described in RFC 3261 Section 20.10:
330 * When the header field value contains a display
331 * name, the URI including all URI parameters is
332 * enclosed in "<" and ">". If no "<" and ">" are
333 * present, all parameters after the URI are header
334 * parameters, not URI parameters. The display name
335 * can be tokens, or a quoted string, if a larger
336 * character set is desired.
Benny Prijonodd742da2008-05-17 12:45:00 +0000337 * @return PJ_SUCCESS if sucessfull.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000338 */
339PJ_DECL(pj_status_t) pjsip_regc_update_contact( pjsip_regc *regc,
340 int ccnt,
341 const pj_str_t contact[] );
342
343/**
Benny Prijonodd742da2008-05-17 12:45:00 +0000344 * Update the expires value. The next REGISTER request will contain
345 * new expires value for the registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000346 *
347 * @param regc The client registration structure.
348 * @param expires The new expires value.
349 * @return zero on successfull.
350 */
351PJ_DECL(pj_status_t) pjsip_regc_update_expires( pjsip_regc *regc,
352 pj_uint32_t expires );
353
354/**
355 * Sends outgoing REGISTER request.
356 * The process will complete asynchronously, and application
357 * will be notified via the callback when the process completes.
358 *
359 * @param regc The client registration structure.
360 * @param tdata Transmit data.
Benny Prijonoccf95622006-02-07 18:48:01 +0000361 *
362 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000363 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000364PJ_DECL(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000365
366
367PJ_END_DECL
368
Benny Prijono312aff92006-06-17 04:08:30 +0000369/**
370 * @}
371 */
372
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000373#endif /* __PJSIP_REG_H__ */