blob: 683c3d48c778a03ffa1bc703a4bbbf63606ac39d [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
4 *
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/**
23 * @file sip_reg.h
24 * @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. */
65 void *token; /**< Arbitrary token. */
66 pj_status_t status; /**< Error status. */
67 int code; /**< SIP status code received. */
68 pj_str_t reason; /**< SIP reason phrase received. */
69 pjsip_rx_data *rdata; /**< The complete received response. */
70 int expiration;/**< Next expiration interval. */
71 int contact_cnt;/**<Number of contacts in response. */
72 pjsip_contact_hdr *contact[PJSIP_REGC_MAX_CONTACT]; /**< Contacts. */
Benny Prijono5dcb38d2005-11-21 01:55:47 +000073};
74
75
76/** Type declaration for callback to receive registration result. */
77typedef void pjsip_regc_cb(struct pjsip_regc_cbparam *param);
78
Benny Prijonobcaed6c2006-02-19 15:37:19 +000079/**
80 * Client registration information.
81 */
82struct pjsip_regc_info
83{
84 pj_str_t server_uri; /**< Server URI, */
85 pj_str_t client_uri; /**< Client URI (From header). */
86 pj_bool_t is_busy; /**< Have pending transaction? */
87 pj_bool_t auto_reg; /**< Will register automatically? */
88 int interval; /**< Registration interval (seconds). */
89 int next_reg; /**< Time until next registration (seconds). */
90};
91
92/**
93 * @see pjsip_regc_info
94 */
95typedef struct pjsip_regc_info pjsip_regc_info;
96
Benny Prijono5dcb38d2005-11-21 01:55:47 +000097
98/**
99 * Get the module instance for client registration module.
100 *
101 * @return client registration module.
102 */
103PJ_DECL(pjsip_module*) pjsip_regc_get_module(void);
104
105
106/**
107 * Create client registration structure.
108 *
109 * @param endpt Endpoint, used to allocate pool from.
110 * @param token A data to be associated with the client registration struct.
111 * @param cb Pointer to callback function to receive registration status.
Benny Prijonoccf95622006-02-07 18:48:01 +0000112 * @param p_regc Pointer to receive client registration structure.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000113 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000114 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000115 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000116PJ_DECL(pj_status_t) pjsip_regc_create( pjsip_endpoint *endpt, void *token,
117 pjsip_regc_cb *cb,
118 pjsip_regc **p_regc);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000119
120
121/**
122 * Destroy client registration structure. If a registration transaction is
123 * in progress, then the structure will be deleted only after a final response
124 * has been received, and in this case, the callback won't be called.
125 *
126 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000127 *
128 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000129 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000130PJ_DECL(pj_status_t) pjsip_regc_destroy(pjsip_regc *regc);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000131
132/**
Benny Prijonobcaed6c2006-02-19 15:37:19 +0000133 * Get registration info.
134 *
135 * @param regc The client registration structure.
136 * @param info Client registration info.
137 *
138 * @return PJ_SUCCESS on success.
139 */
140PJ_DECL(pj_status_t) pjsip_regc_get_info( pjsip_regc *regc,
141 pjsip_regc_info *info );
142
143
144/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000145 * Get the memory pool associated with a registration client handle.
146 *
147 * @param regc The client registration structure.
148 * @return pool handle.
149 */
150PJ_DECL(pj_pool_t*) pjsip_regc_get_pool(pjsip_regc *regc);
151
152/**
153 * Initialize client registration structure with various information needed to
154 * perform the registration.
155 *
156 * @param regc The client registration structure.
Benny Prijono312aff92006-06-17 04:08:30 +0000157 * @param srv_url Server URL.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000158 * @param from_url The person performing the registration, must be a SIP URL type.
159 * @param to_url The address of record for which the registration is targetd, must
160 * be a SIP/SIPS URL.
161 * @param ccnt Number of contacts in the array.
162 * @param contact Array of contacts.
163 * @param expires Default expiration interval (in seconds) to be applied for
164 * contact URL that doesn't have expiration settings. If the
165 * value PJSIP_REGC_EXPIRATION_NOT_SPECIFIED is given, then
166 * no default expiration will be applied.
167 * @return zero on success.
168 */
169PJ_DECL(pj_status_t) pjsip_regc_init(pjsip_regc *regc,
170 const pj_str_t *srv_url,
171 const pj_str_t *from_url,
172 const pj_str_t *to_url,
173 int ccnt,
174 const pj_str_t contact[],
175 pj_uint32_t expires);
176
177
178/**
179 * Set authentication credentials to use by this registration.
180 *
Benny Prijono84126ab2006-02-09 09:30:09 +0000181 * @param regc The registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000182 * @param count Number of credentials in the array.
183 * @param cred Array of credentials.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000184 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000185 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000186 */
187PJ_DECL(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc,
188 int count,
189 const pjsip_cred_info cred[] );
190
191/**
Benny Prijono84126ab2006-02-09 09:30:09 +0000192 * Set route set to be used for outgoing requests.
193 *
194 * @param regc The client registration structure.
195 * @param route_set List containing Route headers.
196 *
197 * @return PJ_SUCCESS on success.
198 */
199PJ_DECL(pj_status_t) pjsip_regc_set_route_set(pjsip_regc *regc,
200 const pjsip_route_hdr*route_set);
201
Benny Prijono720d0a82007-01-12 06:37:35 +0000202
203/**
204 * Lock/bind client registration to a specific transport/listener.
205 * This is optional, as normally transport will be selected automatically
206 * based on the destination of requests upon resolver completion.
207 * When the client registration is explicitly bound to the specific
208 * transport/listener, all UAC transactions originated by the client
209 * registration will use the specified transport/listener when sending
210 * outgoing requests.
211 *
212 * Note that this doesn't affect the Contact header set for this client
213 * registration. Application must manually update the Contact header if
214 * necessary, to adjust the address according to the transport being
215 * selected.
216 *
217 * @param regc The client registration instance.
218 * @param sel Transport selector containing the specification of
219 * transport or listener to be used by this session
220 * to send requests.
221 *
222 * @return PJ_SUCCESS on success, or the appropriate error code.
223 */
224PJ_DECL(pj_status_t) pjsip_regc_set_transport(pjsip_regc *regc,
225 const pjsip_tpselector *sel);
226
227
Benny Prijono84126ab2006-02-09 09:30:09 +0000228/**
Benny Prijono8fc6de02006-11-11 21:25:55 +0000229 * Add headers to be added to outgoing REGISTER requests.
230 *
231 * @param regc The client registration structure.
232 * @param hdr_list List containing SIP headers to be added for all outgoing
233 * REGISTER requests.
234 *
235 * @return PJ_SUCCESS on success.
236 */
237PJ_DECL(pj_status_t) pjsip_regc_add_headers(pjsip_regc *regc,
238 const pjsip_hdr *hdr_list);
239
240
241/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000242 * Create REGISTER request for the specified client registration structure.
243 *
244 * After successfull registration, application can inspect the contacts in
245 * the client registration structure to list what contacts are associaciated
246 * with the address of record being targeted in the registration.
247 *
248 * @param regc The client registration structure.
249 * @param autoreg If non zero, the library will automatically refresh the
250 * next registration until application unregister.
Benny Prijonoccf95622006-02-07 18:48:01 +0000251 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000252 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000253 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000254 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000255PJ_DECL(pj_status_t) pjsip_regc_register(pjsip_regc *regc, pj_bool_t autoreg,
256 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000257
258
259/**
Benny Prijonodfc4c482006-12-02 07:25:29 +0000260 * Create REGISTER request to unregister the contacts that were previously
261 * registered by this client registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000262 *
263 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000264 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000265 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000266 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000267 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000268PJ_DECL(pj_status_t) pjsip_regc_unregister(pjsip_regc *regc,
269 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000270
271/**
Benny Prijonodfc4c482006-12-02 07:25:29 +0000272 * Create REGISTER request to unregister all contacts from server records.
273 * Note that this will unregister all registered contact for the AOR
274 * including contacts registered by other user agents. To only unregister
275 * contact registered by this client registration instance, use
276 * #pjsip_regc_unregister() instead.
277 *
278 * @param regc The client registration structure.
279 * @param p_tdata Pointer to receive the REGISTER request.
280 *
281 * @return PJ_SUCCESS on success.
282 */
283PJ_DECL(pj_status_t) pjsip_regc_unregister_all(pjsip_regc *regc,
284 pjsip_tx_data **p_tdata);
285
286/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000287 * Update Contact details in the client registration structure.
288 *
289 * @param regc The client registration structure.
290 * @param ccnt Number of contacts.
291 * @param contact Array of contacts.
292 * @return zero if sucessfull.
293 */
294PJ_DECL(pj_status_t) pjsip_regc_update_contact( pjsip_regc *regc,
295 int ccnt,
296 const pj_str_t contact[] );
297
298/**
299 * Update the expires value.
300 *
301 * @param regc The client registration structure.
302 * @param expires The new expires value.
303 * @return zero on successfull.
304 */
305PJ_DECL(pj_status_t) pjsip_regc_update_expires( pjsip_regc *regc,
306 pj_uint32_t expires );
307
308/**
309 * Sends outgoing REGISTER request.
310 * The process will complete asynchronously, and application
311 * will be notified via the callback when the process completes.
312 *
313 * @param regc The client registration structure.
314 * @param tdata Transmit data.
Benny Prijonoccf95622006-02-07 18:48:01 +0000315 *
316 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000317 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000318PJ_DECL(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000319
320
321PJ_END_DECL
322
Benny Prijono312aff92006-06-17 04:08:30 +0000323/**
324 * @}
325 */
326
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000327#endif /* __PJSIP_REG_H__ */