blob: 71a553e3ca6232df424bc5b00f7f4ce5ccd744fa [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
Benny Prijonoa771a512007-02-19 01:13:53 +00003 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
Benny Prijono5dcb38d2005-11-21 01:55:47 +00004 *
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/**
Benny Prijonoa7b376b2008-01-25 16:06:33 +000023 * @file sip_regc.h
Benny Prijono5dcb38d2005-11-21 01:55:47 +000024 * @brief SIP Registration Client
25 */
26
27#include <pjsip/sip_types.h>
28#include <pjsip/sip_auth.h>
Benny Prijono720d0a82007-01-12 06:37:35 +000029#include <pjsip/sip_transport.h>
Benny Prijono5dcb38d2005-11-21 01:55:47 +000030
Benny Prijono5dcb38d2005-11-21 01:55:47 +000031
32/**
Benny Prijono312aff92006-06-17 04:08:30 +000033 * @defgroup PJSUA_REGC Client Registration
34 * @ingroup PJSIP_HIGH_UA
35 * @brief High Layer API for performing client registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +000036 * @{
Benny Prijono312aff92006-06-17 04:08:30 +000037 *
38 * This provides API for performing client registration. Application must
39 * link with <b>pjsip-ua</b> static library to use this API.
40
Benny Prijono5dcb38d2005-11-21 01:55:47 +000041 */
42
Benny Prijono312aff92006-06-17 04:08:30 +000043
44PJ_BEGIN_DECL
45
Benny Prijono5dcb38d2005-11-21 01:55:47 +000046/** Typedef for client registration data. */
47typedef struct pjsip_regc pjsip_regc;
48
49/** Maximum contacts in registration. */
50#define PJSIP_REGC_MAX_CONTACT 10
51
52/** Expiration not specified. */
53#define PJSIP_REGC_EXPIRATION_NOT_SPECIFIED ((pj_uint32_t)0xFFFFFFFFUL)
54
55/** Buffer to hold all contacts. */
56#define PJSIP_REGC_CONTACT_BUF_SIZE 512
57
58/** Structure to hold parameters when calling application's callback.
59 * The application's callback is called when the client registration process
60 * has finished.
61 */
62struct pjsip_regc_cbparam
63{
Benny Prijono312aff92006-06-17 04:08:30 +000064 pjsip_regc *regc; /**< Client registration structure. */
Benny Prijonodd742da2008-05-17 12:45:00 +000065 void *token; /**< Arbitrary token set by application */
66
67 /** Error status. If this value is non-PJ_SUCCESS, some error has occured.
68 * Note that even when this contains PJ_SUCCESS the registration might
69 * have failed; in this case the \a code field will contain non
70 * successful (non-2xx status class) code
71 */
72 pj_status_t status;
Benny Prijono312aff92006-06-17 04:08:30 +000073 int code; /**< SIP status code received. */
74 pj_str_t reason; /**< SIP reason phrase received. */
75 pjsip_rx_data *rdata; /**< The complete received response. */
76 int expiration;/**< Next expiration interval. */
77 int contact_cnt;/**<Number of contacts in response. */
78 pjsip_contact_hdr *contact[PJSIP_REGC_MAX_CONTACT]; /**< Contacts. */
Benny Prijono5dcb38d2005-11-21 01:55:47 +000079};
80
81
82/** Type declaration for callback to receive registration result. */
83typedef void pjsip_regc_cb(struct pjsip_regc_cbparam *param);
84
Benny Prijonobcaed6c2006-02-19 15:37:19 +000085/**
86 * Client registration information.
87 */
88struct pjsip_regc_info
89{
90 pj_str_t server_uri; /**< Server URI, */
91 pj_str_t client_uri; /**< Client URI (From header). */
92 pj_bool_t is_busy; /**< Have pending transaction? */
93 pj_bool_t auto_reg; /**< Will register automatically? */
94 int interval; /**< Registration interval (seconds). */
95 int next_reg; /**< Time until next registration (seconds). */
96};
97
98/**
99 * @see pjsip_regc_info
100 */
101typedef struct pjsip_regc_info pjsip_regc_info;
102
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000103
104/**
105 * Get the module instance for client registration module.
106 *
107 * @return client registration module.
108 */
109PJ_DECL(pjsip_module*) pjsip_regc_get_module(void);
110
111
112/**
113 * Create client registration structure.
114 *
115 * @param endpt Endpoint, used to allocate pool from.
116 * @param token A data to be associated with the client registration struct.
117 * @param cb Pointer to callback function to receive registration status.
Benny Prijonoccf95622006-02-07 18:48:01 +0000118 * @param p_regc Pointer to receive client registration structure.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000119 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000120 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000121 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000122PJ_DECL(pj_status_t) pjsip_regc_create( pjsip_endpoint *endpt, void *token,
123 pjsip_regc_cb *cb,
124 pjsip_regc **p_regc);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000125
126
127/**
128 * Destroy client registration structure. If a registration transaction is
129 * in progress, then the structure will be deleted only after a final response
130 * has been received, and in this case, the callback won't be called.
131 *
132 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000133 *
134 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000135 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000136PJ_DECL(pj_status_t) pjsip_regc_destroy(pjsip_regc *regc);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000137
138/**
Benny Prijonobcaed6c2006-02-19 15:37:19 +0000139 * Get registration info.
140 *
141 * @param regc The client registration structure.
142 * @param info Client registration info.
143 *
144 * @return PJ_SUCCESS on success.
145 */
146PJ_DECL(pj_status_t) pjsip_regc_get_info( pjsip_regc *regc,
147 pjsip_regc_info *info );
148
149
150/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000151 * Get the memory pool associated with a registration client handle.
152 *
153 * @param regc The client registration structure.
154 * @return pool handle.
155 */
156PJ_DECL(pj_pool_t*) pjsip_regc_get_pool(pjsip_regc *regc);
157
158/**
159 * Initialize client registration structure with various information needed to
160 * perform the registration.
161 *
162 * @param regc The client registration structure.
Benny Prijono312aff92006-06-17 04:08:30 +0000163 * @param srv_url Server URL.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000164 * @param from_url The person performing the registration, must be a SIP URL type.
165 * @param to_url The address of record for which the registration is targetd, must
166 * be a SIP/SIPS URL.
167 * @param ccnt Number of contacts in the array.
168 * @param contact Array of contacts.
169 * @param expires Default expiration interval (in seconds) to be applied for
170 * contact URL that doesn't have expiration settings. If the
171 * value PJSIP_REGC_EXPIRATION_NOT_SPECIFIED is given, then
172 * no default expiration will be applied.
173 * @return zero on success.
174 */
175PJ_DECL(pj_status_t) pjsip_regc_init(pjsip_regc *regc,
176 const pj_str_t *srv_url,
177 const pj_str_t *from_url,
178 const pj_str_t *to_url,
179 int ccnt,
180 const pj_str_t contact[],
181 pj_uint32_t expires);
182
183
184/**
185 * Set authentication credentials to use by this registration.
186 *
Benny Prijono84126ab2006-02-09 09:30:09 +0000187 * @param regc The registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000188 * @param count Number of credentials in the array.
189 * @param cred Array of credentials.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000190 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000191 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000192 */
193PJ_DECL(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc,
194 int count,
195 const pjsip_cred_info cred[] );
196
197/**
Benny Prijono48ab2b72007-11-08 09:24:30 +0000198 * Set authentication preference.
199 *
200 * @param regc The registration structure.
201 * @param pref Authentication preference.
202 *
203 * @return PJ_SUCCESS on success.
204 */
205PJ_DECL(pj_status_t) pjsip_regc_set_prefs( pjsip_regc *regc,
206 const pjsip_auth_clt_pref *pref);
207
208/**
Benny Prijono84126ab2006-02-09 09:30:09 +0000209 * Set route set to be used for outgoing requests.
210 *
211 * @param regc The client registration structure.
212 * @param route_set List containing Route headers.
213 *
214 * @return PJ_SUCCESS on success.
215 */
216PJ_DECL(pj_status_t) pjsip_regc_set_route_set(pjsip_regc *regc,
217 const pjsip_route_hdr*route_set);
218
Benny Prijono720d0a82007-01-12 06:37:35 +0000219
220/**
221 * Lock/bind client registration to a specific transport/listener.
222 * This is optional, as normally transport will be selected automatically
223 * based on the destination of requests upon resolver completion.
224 * When the client registration is explicitly bound to the specific
225 * transport/listener, all UAC transactions originated by the client
226 * registration will use the specified transport/listener when sending
227 * outgoing requests.
228 *
229 * Note that this doesn't affect the Contact header set for this client
230 * registration. Application must manually update the Contact header if
231 * necessary, to adjust the address according to the transport being
232 * selected.
233 *
234 * @param regc The client registration instance.
235 * @param sel Transport selector containing the specification of
236 * transport or listener to be used by this session
237 * to send requests.
238 *
239 * @return PJ_SUCCESS on success, or the appropriate error code.
240 */
241PJ_DECL(pj_status_t) pjsip_regc_set_transport(pjsip_regc *regc,
242 const pjsip_tpselector *sel);
243
244
Benny Prijono84126ab2006-02-09 09:30:09 +0000245/**
Benny Prijono8fc6de02006-11-11 21:25:55 +0000246 * Add headers to be added to outgoing REGISTER requests.
247 *
248 * @param regc The client registration structure.
249 * @param hdr_list List containing SIP headers to be added for all outgoing
250 * REGISTER requests.
251 *
252 * @return PJ_SUCCESS on success.
253 */
254PJ_DECL(pj_status_t) pjsip_regc_add_headers(pjsip_regc *regc,
255 const pjsip_hdr *hdr_list);
256
257
258/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000259 * Create REGISTER request for the specified client registration structure.
260 *
261 * After successfull registration, application can inspect the contacts in
262 * the client registration structure to list what contacts are associaciated
263 * with the address of record being targeted in the registration.
264 *
265 * @param regc The client registration structure.
266 * @param autoreg If non zero, the library will automatically refresh the
267 * next registration until application unregister.
Benny Prijonoccf95622006-02-07 18:48:01 +0000268 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000269 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000270 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000271 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000272PJ_DECL(pj_status_t) pjsip_regc_register(pjsip_regc *regc, pj_bool_t autoreg,
273 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000274
275
276/**
Benny Prijonodfc4c482006-12-02 07:25:29 +0000277 * Create REGISTER request to unregister the contacts that were previously
278 * registered by this client registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000279 *
280 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000281 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000282 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000283 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000284 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000285PJ_DECL(pj_status_t) pjsip_regc_unregister(pjsip_regc *regc,
286 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000287
288/**
Benny Prijonodfc4c482006-12-02 07:25:29 +0000289 * Create REGISTER request to unregister all contacts from server records.
290 * Note that this will unregister all registered contact for the AOR
291 * including contacts registered by other user agents. To only unregister
292 * contact registered by this client registration instance, use
293 * #pjsip_regc_unregister() instead.
294 *
295 * @param regc The client registration structure.
296 * @param p_tdata Pointer to receive the REGISTER request.
297 *
298 * @return PJ_SUCCESS on success.
299 */
300PJ_DECL(pj_status_t) pjsip_regc_unregister_all(pjsip_regc *regc,
301 pjsip_tx_data **p_tdata);
302
303/**
Benny Prijonodd742da2008-05-17 12:45:00 +0000304 * Update Contact details in the client registration structure. For each
305 * contact URI, if the uri is not found in existing contact, it will be
306 * added to the Contact list. If the URI matches existing contact, nothing
307 * will be added. This function will also mark existing contacts which
308 * are not specified in the new contact list as to be removed, by adding
309 * "expires=0" parameter to these contacts.
310 *
311 * Once the contact list has been updated, application must update the
312 * registration by creating a new REGISTER request and send it to the
313 * registrar. This request will contain both old and new contacts; the
314 * old contacts will have it's expires parameter set to zero to instruct
315 * the registrar to remove the bindings.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000316 *
317 * @param regc The client registration structure.
318 * @param ccnt Number of contacts.
Benny Prijonodd742da2008-05-17 12:45:00 +0000319 * @param contact Array of contact URIs.
320 * @return PJ_SUCCESS if sucessfull.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000321 */
322PJ_DECL(pj_status_t) pjsip_regc_update_contact( pjsip_regc *regc,
323 int ccnt,
324 const pj_str_t contact[] );
325
326/**
Benny Prijonodd742da2008-05-17 12:45:00 +0000327 * Update the expires value. The next REGISTER request will contain
328 * new expires value for the registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000329 *
330 * @param regc The client registration structure.
331 * @param expires The new expires value.
332 * @return zero on successfull.
333 */
334PJ_DECL(pj_status_t) pjsip_regc_update_expires( pjsip_regc *regc,
335 pj_uint32_t expires );
336
337/**
338 * Sends outgoing REGISTER request.
339 * The process will complete asynchronously, and application
340 * will be notified via the callback when the process completes.
341 *
342 * @param regc The client registration structure.
343 * @param tdata Transmit data.
Benny Prijonoccf95622006-02-07 18:48:01 +0000344 *
345 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000346 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000347PJ_DECL(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000348
349
350PJ_END_DECL
351
Benny Prijono312aff92006-06-17 04:08:30 +0000352/**
353 * @}
354 */
355
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000356#endif /* __PJSIP_REG_H__ */