blob: d86c330e8209041666250078b3194a7c554752b0 [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 Prijonoccf95622006-02-07 18:48:01 +000029//#include <pjsip/sip_ua.h>
Benny Prijono5dcb38d2005-11-21 01:55:47 +000030
31PJ_BEGIN_DECL
32
33/**
34 * @defgroup PJSUA_REGC SIP Registration Client
35 * @ingroup PJSUA
36 * @{
37 * \brief
38 * API for performing registration for user agent.
39 */
40
41/** Typedef for client registration data. */
42typedef struct pjsip_regc pjsip_regc;
43
44/** Maximum contacts in registration. */
45#define PJSIP_REGC_MAX_CONTACT 10
46
47/** Expiration not specified. */
48#define PJSIP_REGC_EXPIRATION_NOT_SPECIFIED ((pj_uint32_t)0xFFFFFFFFUL)
49
50/** Buffer to hold all contacts. */
51#define PJSIP_REGC_CONTACT_BUF_SIZE 512
52
53/** Structure to hold parameters when calling application's callback.
54 * The application's callback is called when the client registration process
55 * has finished.
56 */
57struct pjsip_regc_cbparam
58{
59 pjsip_regc *regc;
60 void *token;
61 int code;
Benny Prijonobcaed6c2006-02-19 15:37:19 +000062 pj_status_t status;
Benny Prijono5dcb38d2005-11-21 01:55:47 +000063 pj_str_t reason;
64 pjsip_rx_data *rdata;
65 int contact_cnt;
66 int expiration;
67 pjsip_contact_hdr *contact[PJSIP_REGC_MAX_CONTACT];
68};
69
70
71/** Type declaration for callback to receive registration result. */
72typedef void pjsip_regc_cb(struct pjsip_regc_cbparam *param);
73
Benny Prijonobcaed6c2006-02-19 15:37:19 +000074/**
75 * Client registration information.
76 */
77struct pjsip_regc_info
78{
79 pj_str_t server_uri; /**< Server URI, */
80 pj_str_t client_uri; /**< Client URI (From header). */
81 pj_bool_t is_busy; /**< Have pending transaction? */
82 pj_bool_t auto_reg; /**< Will register automatically? */
83 int interval; /**< Registration interval (seconds). */
84 int next_reg; /**< Time until next registration (seconds). */
85};
86
87/**
88 * @see pjsip_regc_info
89 */
90typedef struct pjsip_regc_info pjsip_regc_info;
91
Benny Prijono5dcb38d2005-11-21 01:55:47 +000092
93/**
94 * Get the module instance for client registration module.
95 *
96 * @return client registration module.
97 */
98PJ_DECL(pjsip_module*) pjsip_regc_get_module(void);
99
100
101/**
102 * Create client registration structure.
103 *
104 * @param endpt Endpoint, used to allocate pool from.
105 * @param token A data to be associated with the client registration struct.
106 * @param cb Pointer to callback function to receive registration status.
Benny Prijonoccf95622006-02-07 18:48:01 +0000107 * @param p_regc Pointer to receive client registration structure.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000108 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000109 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000110 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000111PJ_DECL(pj_status_t) pjsip_regc_create( pjsip_endpoint *endpt, void *token,
112 pjsip_regc_cb *cb,
113 pjsip_regc **p_regc);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000114
115
116/**
117 * Destroy client registration structure. If a registration transaction is
118 * in progress, then the structure will be deleted only after a final response
119 * has been received, and in this case, the callback won't be called.
120 *
121 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000122 *
123 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000124 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000125PJ_DECL(pj_status_t) pjsip_regc_destroy(pjsip_regc *regc);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000126
127/**
Benny Prijonobcaed6c2006-02-19 15:37:19 +0000128 * Get registration info.
129 *
130 * @param regc The client registration structure.
131 * @param info Client registration info.
132 *
133 * @return PJ_SUCCESS on success.
134 */
135PJ_DECL(pj_status_t) pjsip_regc_get_info( pjsip_regc *regc,
136 pjsip_regc_info *info );
137
138
139/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000140 * Get the memory pool associated with a registration client handle.
141 *
142 * @param regc The client registration structure.
143 * @return pool handle.
144 */
145PJ_DECL(pj_pool_t*) pjsip_regc_get_pool(pjsip_regc *regc);
146
147/**
148 * Initialize client registration structure with various information needed to
149 * perform the registration.
150 *
151 * @param regc The client registration structure.
152 * @param from_url The person performing the registration, must be a SIP URL type.
153 * @param to_url The address of record for which the registration is targetd, must
154 * be a SIP/SIPS URL.
155 * @param ccnt Number of contacts in the array.
156 * @param contact Array of contacts.
157 * @param expires Default expiration interval (in seconds) to be applied for
158 * contact URL that doesn't have expiration settings. If the
159 * value PJSIP_REGC_EXPIRATION_NOT_SPECIFIED is given, then
160 * no default expiration will be applied.
161 * @return zero on success.
162 */
163PJ_DECL(pj_status_t) pjsip_regc_init(pjsip_regc *regc,
164 const pj_str_t *srv_url,
165 const pj_str_t *from_url,
166 const pj_str_t *to_url,
167 int ccnt,
168 const pj_str_t contact[],
169 pj_uint32_t expires);
170
171
172/**
173 * Set authentication credentials to use by this registration.
174 *
Benny Prijono84126ab2006-02-09 09:30:09 +0000175 * @param regc The registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000176 * @param count Number of credentials in the array.
177 * @param cred Array of credentials.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000178 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000179 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000180 */
181PJ_DECL(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc,
182 int count,
183 const pjsip_cred_info cred[] );
184
185/**
Benny Prijono84126ab2006-02-09 09:30:09 +0000186 * Set route set to be used for outgoing requests.
187 *
188 * @param regc The client registration structure.
189 * @param route_set List containing Route headers.
190 *
191 * @return PJ_SUCCESS on success.
192 */
193PJ_DECL(pj_status_t) pjsip_regc_set_route_set(pjsip_regc *regc,
194 const pjsip_route_hdr*route_set);
195
196/**
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000197 * Create REGISTER request for the specified client registration structure.
198 *
199 * After successfull registration, application can inspect the contacts in
200 * the client registration structure to list what contacts are associaciated
201 * with the address of record being targeted in the registration.
202 *
203 * @param regc The client registration structure.
204 * @param autoreg If non zero, the library will automatically refresh the
205 * next registration until application unregister.
Benny Prijonoccf95622006-02-07 18:48:01 +0000206 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000207 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000208 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000209 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000210PJ_DECL(pj_status_t) pjsip_regc_register(pjsip_regc *regc, pj_bool_t autoreg,
211 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000212
213
214/**
215 * Create REGISTER request to unregister all contacts from server records.
216 *
217 * @param regc The client registration structure.
Benny Prijonoccf95622006-02-07 18:48:01 +0000218 * @param p_tdata Pointer to receive the REGISTER request.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000219 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000220 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000221 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000222PJ_DECL(pj_status_t) pjsip_regc_unregister(pjsip_regc *regc,
223 pjsip_tx_data **p_tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000224
225/**
226 * Update Contact details in the client registration structure.
227 *
228 * @param regc The client registration structure.
229 * @param ccnt Number of contacts.
230 * @param contact Array of contacts.
231 * @return zero if sucessfull.
232 */
233PJ_DECL(pj_status_t) pjsip_regc_update_contact( pjsip_regc *regc,
234 int ccnt,
235 const pj_str_t contact[] );
236
237/**
238 * Update the expires value.
239 *
240 * @param regc The client registration structure.
241 * @param expires The new expires value.
242 * @return zero on successfull.
243 */
244PJ_DECL(pj_status_t) pjsip_regc_update_expires( pjsip_regc *regc,
245 pj_uint32_t expires );
246
247/**
248 * Sends outgoing REGISTER request.
249 * The process will complete asynchronously, and application
250 * will be notified via the callback when the process completes.
251 *
252 * @param regc The client registration structure.
253 * @param tdata Transmit data.
Benny Prijonoccf95622006-02-07 18:48:01 +0000254 *
255 * @return PJ_SUCCESS on success.
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000256 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000257PJ_DECL(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000258
259
260PJ_END_DECL
261
262#endif /* __PJSIP_REG_H__ */