Debian Codegraph @

Xpjproject/pjsip/include/pjsip-ua/sip_regc.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
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_regc.h
24 * @brief SIP Registration Client
25 */
26
27 #include <pjsip/sip_types.h>
28 #include <pjsip/sip_auth.h>
29 #include <pjsip/sip_transport.h>
30
31
32 /**
33 * @defgroup PJSUA_REGC Client Registration
34 * @ingroup PJSIP_HIGH_UA
35 * @brief High Layer API for performing client registration.
36 * @{
37 *
38 * This provides API for performing client registration. Application must
39 * link with <b>pjsip-ua</b> static library to use this API.
40
41 */
42
43
44 PJ_BEGIN_DECL
45
46 /** Typedef for client registration data. */
47 typedef 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 PJSIP_EXPIRES_NOT_SPECIFIED
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 */
62 struct pjsip_regc_cbparam
63 {
64 pjsip_regc *regc; /**< Client registration structure. */
65 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;
73 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 unsigned expiration;/**< Next expiration interval,
77 PJSIP_REGC_EXPIRATION_NOT_SPECIFIED
78 if not specified. */
79 int contact_cnt;/**<Number of contacts in response. */
80 pjsip_contact_hdr *contact[PJSIP_REGC_MAX_CONTACT]; /**< Contacts. */
81 pj_bool_t is_unreg; /**< Expire header, if any, set to zero?*/
82 };
83
84
85 /** Type declaration for callback to receive registration result. */
86 typedef void pjsip_regc_cb(struct pjsip_regc_cbparam *param);
87
88 /**
89 * Structure to hold parameters when calling application's callback
90 * specified in #pjsip_regc_set_reg_tsx_cb().
91 * To update contact address, application can set the field contact_cnt
92 * and contact inside the callback.
93 */
94 struct pjsip_regc_tsx_cb_param
95 {
96 /** cbparam */
97 struct pjsip_regc_cbparam cbparam;
98
99 /** Number of Contacts */
100 int contact_cnt;
101
102 /** Array of Contacts */
103 pj_str_t contact[PJSIP_REGC_MAX_CONTACT];
104 };
105
106 /** Type declaration for callback set in #pjsip_regc_set_reg_tsx_cb(). */
107 typedef void pjsip_regc_tsx_cb(struct pjsip_regc_tsx_cb_param *param);
108
109 /**
110 * Client registration information.
111 */
112 struct pjsip_regc_info
113 {
114 pj_str_t server_uri; /**< Server URI, */
115 pj_str_t client_uri; /**< Client URI (From header). */
116 pj_bool_t is_busy; /**< Have pending transaction? */
117 pj_bool_t auto_reg; /**< Will register automatically? */
118 unsigned interval; /**< Registration interval (seconds). */
119 unsigned next_reg; /**< Time until next registration (seconds). */
120 pjsip_transport *transport; /**< Last transport used, for informational
121 purpose only (e.g: comparing pointers),
122 the transport may be invalid already. */
123 };
124
125 /**
126 * @see pjsip_regc_info
127 */
128 typedef struct pjsip_regc_info pjsip_regc_info;
129
130 /**
131 * Create client registration structure.
132 *
133 * @param endpt Endpoint, used to allocate pool from.
134 * @param token A data to be associated with the client registration struct.
135 * @param cb Pointer to callback function to receive registration status.
136 * @param p_regc Pointer to receive client registration structure.
137 *
138 * @return PJ_SUCCESS on success.
139 */
140 PJ_DECL(pj_status_t) pjsip_regc_create( pjsip_endpoint *endpt, void *token,
141 pjsip_regc_cb *cb,
142 pjsip_regc **p_regc);
143
144
145 /**
146 * Destroy client registration structure. If a registration transaction is
147 * in progress, then the structure will be deleted only after a final response
148 * has been received, and in this case, the callback won't be called.
149 *
150 * @param regc The client registration structure.
151 *
152 * @return PJ_SUCCESS on success.
153 */
154 PJ_DECL(pj_status_t) pjsip_regc_destroy(pjsip_regc *regc);
155
156
157 /**
158 * Destroy client registration structure. If a registration transaction is
159 * in progress:
160 * - if force is PJ_TRUE, then the structure will be deleted only after
161 * a final response has been received, and in this case, the callback
162 * won't be called (this behavior is the same as calling
163 * pjsip_regc_destroye()).
164 * - if force is PJ_FALSE, the function will return PJ_EBUSY
165 *
166 * @param regc The client registration structure.
167 * @param force Specify if the function must destroy the structure.
168 *
169 * @return PJ_SUCCESS on success, or PJ_EBUSY.
170 */
171 PJ_DECL(pj_status_t) pjsip_regc_destroy2(pjsip_regc *regc, pj_bool_t force);
172
173
174 /**
175 * Get registration info.
176 *
177 * @param regc The client registration structure.
178 * @param info Client registration info.
179 *
180 * @return PJ_SUCCESS on success.
181 */
182 PJ_DECL(pj_status_t) pjsip_regc_get_info( pjsip_regc *regc,
183 pjsip_regc_info *info );
184
185
186 /**
187 * Get the memory pool associated with a registration client handle.
188 *
189 * @param regc The client registration structure.
190 * @return pool handle.
191 */
192 PJ_DECL(pj_pool_t*) pjsip_regc_get_pool(pjsip_regc *regc);
193
194 /**
195 * Initialize client registration structure with various information needed to
196 * perform the registration.
197 *
198 * @param regc The client registration structure.
199 * @param srv_url Server URL.
200 * @param from_url The person performing the registration, must be a SIP URL type.
201 * @param to_url The address of record for which the registration is targetd, must
202 * be a SIP/SIPS URL.
203 * @param ccnt Number of contacts in the array.
204 * @param contact Array of contacts, each contact item must be formatted
205 * as described in RFC 3261 Section 20.10:
206 * When the header field value contains a display
207 * name, the URI including all URI parameters is
208 * enclosed in "<" and ">". If no "<" and ">" are
209 * present, all parameters after the URI are header
210 * parameters, not URI parameters. The display name
211 * can be tokens, or a quoted string, if a larger
212 * character set is desired.
213 * @param expires Default expiration interval (in seconds) to be applied for
214 * contact URL that doesn't have expiration settings. If the
215 * value PJSIP_REGC_EXPIRATION_NOT_SPECIFIED is given, then
216 * no default expiration will be applied.
217 * @return zero on success.
218 */
219 PJ_DECL(pj_status_t) pjsip_regc_init(pjsip_regc *regc,
220 const pj_str_t *srv_url,
221 const pj_str_t *from_url,
222 const pj_str_t *to_url,
223 int ccnt,
224 const pj_str_t contact[],
225 pj_uint32_t expires);
226
227
228 /**
229 * Increment busy counter temporarily, to prevent client registration
230 * structure from being destroyed.
231 *
232 * @param regc The client registration structure.
233 */
234 PJ_DECL(void) pjsip_regc_add_ref( pjsip_regc *regc );
235
236
237 /**
238 * Decrement temporary busy counter. After this function
239 * is called, client registration structure may have been destroyed
240 * if there's a pending destroy.
241 *
242 * @param regc The client registration structure.
243 *
244 * @return PJ_SUCCESS on success. PJ_EGONE if the registration
245 * structure has been destroyed inside the function.
246 */
247 PJ_DECL(pj_status_t) pjsip_regc_dec_ref( pjsip_regc *regc );
248
249
250 /**
251 * Set callback to be called when the registration received a final response.
252 * This callback is different with the one specified during creation via
253 * #pjsip_regc_create(). This callback will be called for any final response
254 * (including 401/407/423) and before any subsequent requests are sent.
255 * In case of unregistration, this callback will not be called.
256 *
257 * @param regc The client registration structure.
258 * @param tsx_cb Pointer to callback function to receive registration status.
259 *
260 * @return PJ_SUCCESS on success.
261 */
262 PJ_DECL(pj_status_t) pjsip_regc_set_reg_tsx_cb(pjsip_regc *regc,
263 pjsip_regc_tsx_cb *tsx_cb);
264
265 /**
266 * Set the "sent-by" field of the Via header for outgoing requests.
267 *
268 * @param regc The client registration structure.
269 * @param via_addr Set via_addr to use for the Via header or NULL to use
270 * the transport's published name.
271 * @param via_tp via_addr will only be used if we are using via_tp
272 * transport.
273 *
274 * @return PJ_SUCCESS on success.
275 */
276 PJ_DECL(pj_status_t) pjsip_regc_set_via_sent_by(pjsip_regc *regc,
277 pjsip_host_port *via_addr,
278 pjsip_transport *via_tp);
279
280 /**
281 * Set the number of seconds to refresh the client registration before
282 * the registration expires.
283 *
284 * @param regc The registration structure.
285 * @param delay The number of seconds to refresh the client
286 * registration before the registration expires.
287 *
288 * @return PJ_SUCCESS on success.
289 */
290 PJ_DECL(pj_status_t)
291 pjsip_regc_set_delay_before_refresh( pjsip_regc *regc,
292 pj_uint32_t delay );
293
294
295 /**
296 * Set authentication credentials to use by this registration.
297 *
298 * @param regc The registration structure.
299 * @param count Number of credentials in the array.
300 * @param cred Array of credentials.
301 *
302 * @return PJ_SUCCESS on success.
303 */
304 PJ_DECL(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc,
305 int count,
306 const pjsip_cred_info cred[] );
307
308 /**
309 * Set authentication preference.
310 *
311 * @param regc The registration structure.
312 * @param pref Authentication preference.
313 *
314 * @return PJ_SUCCESS on success.
315 */
316 PJ_DECL(pj_status_t) pjsip_regc_set_prefs( pjsip_regc *regc,
317 const pjsip_auth_clt_pref *pref);
318
319 /**
320 * Set route set to be used for outgoing requests.
321 *
322 * @param regc The client registration structure.
323 * @param route_set List containing Route headers.
324 *
325 * @return PJ_SUCCESS on success.
326 */
327 PJ_DECL(pj_status_t) pjsip_regc_set_route_set(pjsip_regc *regc,
328 const pjsip_route_hdr*route_set);
329
330
331 /**
332 * Lock/bind client registration to a specific transport/listener.
333 * This is optional, as normally transport will be selected automatically
334 * based on the destination of requests upon resolver completion.
335 * When the client registration is explicitly bound to the specific
336 * transport/listener, all UAC transactions originated by the client
337 * registration will use the specified transport/listener when sending
338 * outgoing requests.
339 *
340 * Note that this doesn't affect the Contact header set for this client
341 * registration. Application must manually update the Contact header if
342 * necessary, to adjust the address according to the transport being
343 * selected.
344 *
345 * @param regc The client registration instance.
346 * @param sel Transport selector containing the specification of
347 * transport or listener to be used by this session
348 * to send requests.
349 *
350 * @return PJ_SUCCESS on success, or the appropriate error code.
351 */
352 PJ_DECL(pj_status_t) pjsip_regc_set_transport(pjsip_regc *regc,
353 const pjsip_tpselector *sel);
354
355 /**
356 * Release the reference to current transport being used by the regc, if any.
357 * The regc keeps the reference to the last transport being used in order
358 * to prevent it from being destroyed. In some situation however, such as
359 * when the transport is disconnected, it is necessary to instruct the
360 * regc to release this reference so that the transport can be destroyed.
361 * See https://github.com/pjsip/pjproject/issues/1481 for background info.
362 *
363 * @param regc The client registration instance.
364 *
365 * @return PJ_SUCCESS on success, or the appropriate error code.
366 */
367 PJ_DECL(pj_status_t) pjsip_regc_release_transport(pjsip_regc *regc);
368
369 /**
370 * Add headers to be added to outgoing REGISTER requests.
371 *
372 * @param regc The client registration structure.
373 * @param hdr_list List containing SIP headers to be added for all outgoing
374 * REGISTER requests.
375 *
376 * @return PJ_SUCCESS on success.
377 */
378 PJ_DECL(pj_status_t) pjsip_regc_add_headers(pjsip_regc *regc,
379 const pjsip_hdr *hdr_list);
380
381
382 /**
383 * Create REGISTER request for the specified client registration structure.
384 *
385 * After successfull registration, application can inspect the contacts in
386 * the client registration structure to list what contacts are associaciated
387 * with the address of record being targeted in the registration.
388 *
389 * @param regc The client registration structure.
390 * @param autoreg If non zero, the library will automatically refresh the
391 * next registration until application unregister.
392 * @param p_tdata Pointer to receive the REGISTER request.
393 *
394 * @return PJ_SUCCESS on success.
395 */
396 PJ_DECL(pj_status_t) pjsip_regc_register(pjsip_regc *regc, pj_bool_t autoreg,
397 pjsip_tx_data **p_tdata);
398
399
400 /**
401 * Create REGISTER request to unregister the contacts that were previously
402 * registered by this client registration.
403 *
404 * @param regc The client registration structure.
405 * @param p_tdata Pointer to receive the REGISTER request.
406 *
407 * @return PJ_SUCCESS on success.
408 */
409 PJ_DECL(pj_status_t) pjsip_regc_unregister(pjsip_regc *regc,
410 pjsip_tx_data **p_tdata);
411
412 /**
413 * Create REGISTER request to unregister all contacts from server records.
414 * Note that this will unregister all registered contact for the AOR
415 * including contacts registered by other user agents. To only unregister
416 * contact registered by this client registration instance, use
417 * #pjsip_regc_unregister() instead.
418 *
419 * @param regc The client registration structure.
420 * @param p_tdata Pointer to receive the REGISTER request.
421 *
422 * @return PJ_SUCCESS on success.
423 */
424 PJ_DECL(pj_status_t) pjsip_regc_unregister_all(pjsip_regc *regc,
425 pjsip_tx_data **p_tdata);
426
427 /**
428 * Update Contact details in the client registration structure. For each
429 * contact, if the contact is not found in existing contact, it will be
430 * added to the Contact list. If it matches existing contact, nothing
431 * will be added. This function will also mark existing contacts which
432 * are not specified in the new contact list as to be removed, by adding
433 * "expires=0" parameter to these contacts.
434 *
435 * Once the contact list has been updated, application must update the
436 * registration by creating a new REGISTER request and send it to the
437 * registrar. This request will contain both old and new contacts; the
438 * old contacts will have it's expires parameter set to zero to instruct
439 * the registrar to remove the bindings.
440 *
441 * @param regc The client registration structure.
442 * @param ccnt Number of contacts.
443 * @param contact Array of contacts, each contact item must be formatted
444 * as described in RFC 3261 Section 20.10:
445 * When the header field value contains a display
446 * name, the URI including all URI parameters is
447 * enclosed in "<" and ">". If no "<" and ">" are
448 * present, all parameters after the URI are header
449 * parameters, not URI parameters. The display name
450 * can be tokens, or a quoted string, if a larger
451 * character set is desired.
452 * @return PJ_SUCCESS if sucessfull.
453 */
454 PJ_DECL(pj_status_t) pjsip_regc_update_contact( pjsip_regc *regc,
455 int ccnt,
456 const pj_str_t contact[] );
457
458 /**
459 * Update the expires value. The next REGISTER request will contain
460 * new expires value for the registration.
461 *
462 * @param regc The client registration structure.
463 * @param expires The new expires value.
464 * @return zero on successfull.
465 */
466 PJ_DECL(pj_status_t) pjsip_regc_update_expires( pjsip_regc *regc,
467 pj_uint32_t expires );
468
469 /**
470 * Sends outgoing REGISTER request.
471 * The process will complete asynchronously, and application
472 * will be notified via the callback when the process completes.
473 *
474 * @param regc The client registration structure.
475 * @param tdata Transmit data.
476 *
477 * @return PJ_SUCCESS on success.
478 */
479 PJ_DECL(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata);
480
481
482 /**
483 * Set a shared authentication session to be used by this client registration.
484 * This will try to reuse authorization headers from another source
485 * (e.g. subscribe dialog).
486 *
487 * If available, the internal auth session will be ignored.
488 * To reset client registration, pass NULL as session parameter.
489 *
490 * @param regc The client registration structure.
491 * @param session Pointer to the external session.
492 *
493 * @return PJ_SUCCESS on success.
494 */
495 PJ_DECL(pj_status_t) pjsip_regc_set_auth_sess( pjsip_regc *regc,
496 pjsip_auth_clt_sess *session );
497
498
499 /**
500 * Get the authentication session used by this client registration.
501 *
502 * @param regc The client registration structure.
503 *
504 * @return The client authentication session.
505 */
506 PJ_DECL(pjsip_auth_clt_sess*) pjsip_regc_get_auth_sess( pjsip_regc *regc );
507
508
509 PJ_END_DECL
510
511 /**
512 * @}
513 */
514
515 #endif /* __PJSIP_REG_H__ */