blob: 04f2752d05b55e9c6b758e96e51c800c8de5127d [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 Prijono5dcb38d2005-11-21 01:55:47 +000029
Benny Prijono5dcb38d2005-11-21 01:55:47 +000030
31/**
Benny Prijono312aff92006-06-17 04:08:30 +000032 * @defgroup PJSUA_REGC Client Registration
33 * @ingroup PJSIP_HIGH_UA
34 * @brief High Layer API for performing client registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +000035 * @{
Benny Prijono312aff92006-06-17 04:08:30 +000036 *
37 * This provides API for performing client registration. Application must
38 * link with <b>pjsip-ua</b> static library to use this API.
39
Benny Prijono5dcb38d2005-11-21 01:55:47 +000040 */
41
Benny Prijono312aff92006-06-17 04:08:30 +000042
43PJ_BEGIN_DECL
44
Benny Prijono5dcb38d2005-11-21 01:55:47 +000045/** Typedef for client registration data. */
46typedef struct pjsip_regc pjsip_regc;
47
48/** Maximum contacts in registration. */
49#define PJSIP_REGC_MAX_CONTACT 10
50
51/** Expiration not specified. */
52#define PJSIP_REGC_EXPIRATION_NOT_SPECIFIED ((pj_uint32_t)0xFFFFFFFFUL)
53
54/** Buffer to hold all contacts. */
55#define PJSIP_REGC_CONTACT_BUF_SIZE 512
56
57/** Structure to hold parameters when calling application's callback.
58 * The application's callback is called when the client registration process
59 * has finished.
60 */
61struct pjsip_regc_cbparam
62{
Benny Prijono312aff92006-06-17 04:08:30 +000063 pjsip_regc *regc; /**< Client registration structure. */
64 void *token; /**< Arbitrary token. */
65 pj_status_t status; /**< Error status. */
66 int code; /**< SIP status code received. */
67 pj_str_t reason; /**< SIP reason phrase received. */
68 pjsip_rx_data *rdata; /**< The complete received response. */
69 int expiration;/**< Next expiration interval. */
70 int contact_cnt;/**<Number of contacts in response. */
71 pjsip_contact_hdr *contact[PJSIP_REGC_MAX_CONTACT]; /**< Contacts. */
Benny Prijono5dcb38d2005-11-21 01:55:47 +000072};
73
74
75/** Type declaration for callback to receive registration result. */
76typedef void pjsip_regc_cb(struct pjsip_regc_cbparam *param);
77
Benny Prijonobcaed6c2006-02-19 15:37:19 +000078/**
79 * Client registration information.
80 */
81struct pjsip_regc_info
82{
83 pj_str_t server_uri; /**< Server URI, */
84 pj_str_t client_uri; /**< Client URI (From header). */
85 pj_bool_t is_busy; /**< Have pending transaction? */
86 pj_bool_t auto_reg; /**< Will register automatically? */
87 int interval; /**< Registration interval (seconds). */
88 int next_reg; /**< Time until next registration (seconds). */
89};
90
91/**
92 * @see pjsip_regc_info
93 */
94typedef struct pjsip_regc_info pjsip_regc_info;
95
Benny Prijono5dcb38d2005-11-21 01:55:47 +000096
97/**
98 * Get the module instance for client registration module.
99 *
100 * @return client registration module.
101 */
102PJ_DECL(pjsip_module*) pjsip_regc_get_module(void);
103
104
105/**
106 * Create client registration structure.
107 *
108 * @param endpt Endpoint, used to allocate pool from.
109 * @param token A data to be associated with the client registration struct.
110 * @param cb Pointer to callback function to receive registration status.
Benny Prijonoccf95622006-02-07 18:48:01 +0000111 * @param p_regc Pointer to receive client registration structure.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000112 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000113 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000114 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000115PJ_DECL(pj_status_t) pjsip_regc_create( pjsip_endpoint *endpt, void *token,
116 pjsip_regc_cb *cb,
117 pjsip_regc **p_regc);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000118
119
120/**
121 * Destroy client registration structure. If a registration transaction is
122 * in progress, then the structure will be deleted only after a final response
123 * has been received, and in this case, the callback won't be called.
124 *
125 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000126 *
127 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000128 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000129PJ_DECL(pj_status_t) pjsip_regc_destroy(pjsip_regc *regc);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000130
131/**
Benny Prijonobcaed6c2006-02-19 15:37:19 +0000132 * Get registration info.
133 *
134 * @param regc The client registration structure.
135 * @param info Client registration info.
136 *
137 * @return PJ_SUCCESS on success.
138 */
139PJ_DECL(pj_status_t) pjsip_regc_get_info( pjsip_regc *regc,
140 pjsip_regc_info *info );
141
142
143/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000144 * Get the memory pool associated with a registration client handle.
145 *
146 * @param regc The client registration structure.
147 * @return pool handle.
148 */
149PJ_DECL(pj_pool_t*) pjsip_regc_get_pool(pjsip_regc *regc);
150
151/**
152 * Initialize client registration structure with various information needed to
153 * perform the registration.
154 *
155 * @param regc The client registration structure.
Benny Prijono312aff92006-06-17 04:08:30 +0000156 * @param srv_url Server URL.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000157 * @param from_url The person performing the registration, must be a SIP URL type.
158 * @param to_url The address of record for which the registration is targetd, must
159 * be a SIP/SIPS URL.
160 * @param ccnt Number of contacts in the array.
161 * @param contact Array of contacts.
162 * @param expires Default expiration interval (in seconds) to be applied for
163 * contact URL that doesn't have expiration settings. If the
164 * value PJSIP_REGC_EXPIRATION_NOT_SPECIFIED is given, then
165 * no default expiration will be applied.
166 * @return zero on success.
167 */
168PJ_DECL(pj_status_t) pjsip_regc_init(pjsip_regc *regc,
169 const pj_str_t *srv_url,
170 const pj_str_t *from_url,
171 const pj_str_t *to_url,
172 int ccnt,
173 const pj_str_t contact[],
174 pj_uint32_t expires);
175
176
177/**
178 * Set authentication credentials to use by this registration.
179 *
Benny Prijono84126ab2006-02-09 09:30:09 +0000180 * @param regc The registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000181 * @param count Number of credentials in the array.
182 * @param cred Array of credentials.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000183 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000184 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000185 */
186PJ_DECL(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc,
187 int count,
188 const pjsip_cred_info cred[] );
189
190/**
Benny Prijono84126ab2006-02-09 09:30:09 +0000191 * Set route set to be used for outgoing requests.
192 *
193 * @param regc The client registration structure.
194 * @param route_set List containing Route headers.
195 *
196 * @return PJ_SUCCESS on success.
197 */
198PJ_DECL(pj_status_t) pjsip_regc_set_route_set(pjsip_regc *regc,
199 const pjsip_route_hdr*route_set);
200
201/**
Benny Prijono8fc6de02006-11-11 21:25:55 +0000202 * Add headers to be added to outgoing REGISTER requests.
203 *
204 * @param regc The client registration structure.
205 * @param hdr_list List containing SIP headers to be added for all outgoing
206 * REGISTER requests.
207 *
208 * @return PJ_SUCCESS on success.
209 */
210PJ_DECL(pj_status_t) pjsip_regc_add_headers(pjsip_regc *regc,
211 const pjsip_hdr *hdr_list);
212
213
214/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000215 * Create REGISTER request for the specified client registration structure.
216 *
217 * After successfull registration, application can inspect the contacts in
218 * the client registration structure to list what contacts are associaciated
219 * with the address of record being targeted in the registration.
220 *
221 * @param regc The client registration structure.
222 * @param autoreg If non zero, the library will automatically refresh the
223 * next registration until application unregister.
Benny Prijonoccf95622006-02-07 18:48:01 +0000224 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000225 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000226 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000227 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000228PJ_DECL(pj_status_t) pjsip_regc_register(pjsip_regc *regc, pj_bool_t autoreg,
229 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000230
231
232/**
Benny Prijonodfc4c482006-12-02 07:25:29 +0000233 * Create REGISTER request to unregister the contacts that were previously
234 * registered by this client registration.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000235 *
236 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000237 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000238 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000239 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000240 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000241PJ_DECL(pj_status_t) pjsip_regc_unregister(pjsip_regc *regc,
242 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000243
244/**
Benny Prijonodfc4c482006-12-02 07:25:29 +0000245 * Create REGISTER request to unregister all contacts from server records.
246 * Note that this will unregister all registered contact for the AOR
247 * including contacts registered by other user agents. To only unregister
248 * contact registered by this client registration instance, use
249 * #pjsip_regc_unregister() instead.
250 *
251 * @param regc The client registration structure.
252 * @param p_tdata Pointer to receive the REGISTER request.
253 *
254 * @return PJ_SUCCESS on success.
255 */
256PJ_DECL(pj_status_t) pjsip_regc_unregister_all(pjsip_regc *regc,
257 pjsip_tx_data **p_tdata);
258
259/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000260 * Update Contact details in the client registration structure.
261 *
262 * @param regc The client registration structure.
263 * @param ccnt Number of contacts.
264 * @param contact Array of contacts.
265 * @return zero if sucessfull.
266 */
267PJ_DECL(pj_status_t) pjsip_regc_update_contact( pjsip_regc *regc,
268 int ccnt,
269 const pj_str_t contact[] );
270
271/**
272 * Update the expires value.
273 *
274 * @param regc The client registration structure.
275 * @param expires The new expires value.
276 * @return zero on successfull.
277 */
278PJ_DECL(pj_status_t) pjsip_regc_update_expires( pjsip_regc *regc,
279 pj_uint32_t expires );
280
281/**
282 * Sends outgoing REGISTER request.
283 * The process will complete asynchronously, and application
284 * will be notified via the callback when the process completes.
285 *
286 * @param regc The client registration structure.
287 * @param tdata Transmit data.
Benny Prijonoccf95622006-02-07 18:48:01 +0000288 *
289 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000290 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000291PJ_DECL(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000292
293
294PJ_END_DECL
295
Benny Prijono312aff92006-06-17 04:08:30 +0000296/**
297 * @}
298 */
299
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000300#endif /* __PJSIP_REG_H__ */