blob: 91adaa4f2093c8b57543a05432eec16c2982d23a [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.
169 * @param contact Array of contacts.
170 * @param expires Default expiration interval (in seconds) to be applied for
171 * contact URL that doesn't have expiration settings. If the
172 * value PJSIP_REGC_EXPIRATION_NOT_SPECIFIED is given, then
173 * no default expiration will be applied.
174 * @return zero on success.
175 */
176PJ_DECL(pj_status_t) pjsip_regc_init(pjsip_regc *regc,
177 const pj_str_t *srv_url,
178 const pj_str_t *from_url,
179 const pj_str_t *to_url,
180 int ccnt,
181 const pj_str_t contact[],
182 pj_uint32_t expires);
183
184
185/**
186 * Set authentication credentials to use by this registration.
187 *
Benny Prijono84126ab2006-02-09 09:30:09 +0000188 * @param regc The registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000189 * @param count Number of credentials in the array.
190 * @param cred Array of credentials.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000191 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000192 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000193 */
194PJ_DECL(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc,
195 int count,
196 const pjsip_cred_info cred[] );
197
198/**
Benny Prijono48ab2b72007-11-08 09:24:30 +0000199 * Set authentication preference.
200 *
201 * @param regc The registration structure.
202 * @param pref Authentication preference.
203 *
204 * @return PJ_SUCCESS on success.
205 */
206PJ_DECL(pj_status_t) pjsip_regc_set_prefs( pjsip_regc *regc,
207 const pjsip_auth_clt_pref *pref);
208
209/**
Benny Prijono84126ab2006-02-09 09:30:09 +0000210 * Set route set to be used for outgoing requests.
211 *
212 * @param regc The client registration structure.
213 * @param route_set List containing Route headers.
214 *
215 * @return PJ_SUCCESS on success.
216 */
217PJ_DECL(pj_status_t) pjsip_regc_set_route_set(pjsip_regc *regc,
218 const pjsip_route_hdr*route_set);
219
Benny Prijono720d0a82007-01-12 06:37:35 +0000220
221/**
222 * Lock/bind client registration to a specific transport/listener.
223 * This is optional, as normally transport will be selected automatically
224 * based on the destination of requests upon resolver completion.
225 * When the client registration is explicitly bound to the specific
226 * transport/listener, all UAC transactions originated by the client
227 * registration will use the specified transport/listener when sending
228 * outgoing requests.
229 *
230 * Note that this doesn't affect the Contact header set for this client
231 * registration. Application must manually update the Contact header if
232 * necessary, to adjust the address according to the transport being
233 * selected.
234 *
235 * @param regc The client registration instance.
236 * @param sel Transport selector containing the specification of
237 * transport or listener to be used by this session
238 * to send requests.
239 *
240 * @return PJ_SUCCESS on success, or the appropriate error code.
241 */
242PJ_DECL(pj_status_t) pjsip_regc_set_transport(pjsip_regc *regc,
243 const pjsip_tpselector *sel);
244
245
Benny Prijono84126ab2006-02-09 09:30:09 +0000246/**
Benny Prijono8fc6de02006-11-11 21:25:55 +0000247 * Add headers to be added to outgoing REGISTER requests.
248 *
249 * @param regc The client registration structure.
250 * @param hdr_list List containing SIP headers to be added for all outgoing
251 * REGISTER requests.
252 *
253 * @return PJ_SUCCESS on success.
254 */
255PJ_DECL(pj_status_t) pjsip_regc_add_headers(pjsip_regc *regc,
256 const pjsip_hdr *hdr_list);
257
258
259/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000260 * Create REGISTER request for the specified client registration structure.
261 *
262 * After successfull registration, application can inspect the contacts in
263 * the client registration structure to list what contacts are associaciated
264 * with the address of record being targeted in the registration.
265 *
266 * @param regc The client registration structure.
267 * @param autoreg If non zero, the library will automatically refresh the
268 * next registration until application unregister.
Benny Prijonoccf95622006-02-07 18:48:01 +0000269 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000270 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000271 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000272 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000273PJ_DECL(pj_status_t) pjsip_regc_register(pjsip_regc *regc, pj_bool_t autoreg,
274 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000275
276
277/**
Benny Prijonodfc4c482006-12-02 07:25:29 +0000278 * Create REGISTER request to unregister the contacts that were previously
279 * registered by this client registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000280 *
281 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000282 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000283 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000284 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000285 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000286PJ_DECL(pj_status_t) pjsip_regc_unregister(pjsip_regc *regc,
287 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000288
289/**
Benny Prijonodfc4c482006-12-02 07:25:29 +0000290 * Create REGISTER request to unregister all contacts from server records.
291 * Note that this will unregister all registered contact for the AOR
292 * including contacts registered by other user agents. To only unregister
293 * contact registered by this client registration instance, use
294 * #pjsip_regc_unregister() instead.
295 *
296 * @param regc The client registration structure.
297 * @param p_tdata Pointer to receive the REGISTER request.
298 *
299 * @return PJ_SUCCESS on success.
300 */
301PJ_DECL(pj_status_t) pjsip_regc_unregister_all(pjsip_regc *regc,
302 pjsip_tx_data **p_tdata);
303
304/**
Benny Prijonodd742da2008-05-17 12:45:00 +0000305 * Update Contact details in the client registration structure. For each
306 * contact URI, if the uri is not found in existing contact, it will be
307 * added to the Contact list. If the URI matches existing contact, nothing
308 * will be added. This function will also mark existing contacts which
309 * are not specified in the new contact list as to be removed, by adding
310 * "expires=0" parameter to these contacts.
311 *
312 * Once the contact list has been updated, application must update the
313 * registration by creating a new REGISTER request and send it to the
314 * registrar. This request will contain both old and new contacts; the
315 * old contacts will have it's expires parameter set to zero to instruct
316 * the registrar to remove the bindings.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000317 *
318 * @param regc The client registration structure.
319 * @param ccnt Number of contacts.
Benny Prijonodd742da2008-05-17 12:45:00 +0000320 * @param contact Array of contact URIs.
321 * @return PJ_SUCCESS if sucessfull.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000322 */
323PJ_DECL(pj_status_t) pjsip_regc_update_contact( pjsip_regc *regc,
324 int ccnt,
325 const pj_str_t contact[] );
326
327/**
Benny Prijonodd742da2008-05-17 12:45:00 +0000328 * Update the expires value. The next REGISTER request will contain
329 * new expires value for the registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000330 *
331 * @param regc The client registration structure.
332 * @param expires The new expires value.
333 * @return zero on successfull.
334 */
335PJ_DECL(pj_status_t) pjsip_regc_update_expires( pjsip_regc *regc,
336 pj_uint32_t expires );
337
338/**
339 * Sends outgoing REGISTER request.
340 * The process will complete asynchronously, and application
341 * will be notified via the callback when the process completes.
342 *
343 * @param regc The client registration structure.
344 * @param tdata Transmit data.
Benny Prijonoccf95622006-02-07 18:48:01 +0000345 *
346 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000347 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000348PJ_DECL(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000349
350
351PJ_END_DECL
352
Benny Prijono312aff92006-06-17 04:08:30 +0000353/**
354 * @}
355 */
356
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000357#endif /* __PJSIP_REG_H__ */