1
/* $Id: sip_endpoint.h 3988 2012-03-28 07:32:42Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
20
#ifndef __PJSIP_SIP_ENDPOINT_H__
21
#define __PJSIP_SIP_ENDPOINT_H__
24
* @file sip_endpoint.h
25
* @brief SIP Endpoint.
28
#include <pjsip/sip_transport.h>
29
#include <pjsip/sip_resolve.h>
32
* @defgroup PJSIP_CORE_CORE At the Very Core
34
* @brief The very core of PJSIP.
40
* @defgroup PJSIP_ENDPT Endpoint
41
* @ingroup PJSIP_CORE_CORE
42
* @brief The master, owner of all objects
44
* SIP Endpoint instance (pjsip_endpoint) can be viewed as the master/owner of
45
* all SIP objects in an application. It performs the following roles:
46
* - it manages the allocation/deallocation of memory pools for all objects.
47
* - it manages listeners and transports, and how they are used by
49
* - it receives incoming messages from transport layer and automatically
50
* dispatches them to the correct transaction (or create a new one).
51
* - it has a single instance of timer management (timer heap).
52
* - it manages modules, which is the primary means of extending the library.
53
* - it provides single polling function for all objects and distributes
55
* - it automatically handles incoming requests which can not be handled by
56
* existing modules (such as when incoming request has unsupported method).
59
* Application should only instantiate one SIP endpoint instance for every
67
* Type of callback to register to pjsip_endpt_atexit().
69
typedef void (*pjsip_endpt_exit_callback)(pjsip_endpoint *endpt);
73
* Create an instance of SIP endpoint from the specified pool factory.
74
* The pool factory reference then will be kept by the endpoint, so that
75
* future memory allocations by SIP components will be taken from the same
78
* @param pf Pool factory that will be used for the lifetime of
80
* @param name Optional name to be specified for the endpoint.
81
* If this parameter is NULL, then the name will use
83
* @param endpt Pointer to receive endpoint instance.
85
* @return PJ_SUCCESS on success.
87
PJ_DECL(pj_status_t) pjsip_endpt_create(pj_pool_factory *pf,
89
pjsip_endpoint **endpt);
92
* Destroy endpoint instance. Application must make sure that all pending
93
* transactions have been terminated properly, because this function does not
94
* check for the presence of pending transactions.
96
* @param endpt The SIP endpoint to be destroyed.
98
PJ_DECL(void) pjsip_endpt_destroy(pjsip_endpoint *endpt);
103
* @param endpt The SIP endpoint instance.
105
* @return Endpoint name, as was registered during endpoint
106
* creation. The string is NULL terminated.
108
PJ_DECL(const pj_str_t*) pjsip_endpt_name(const pjsip_endpoint *endpt);
111
* Poll for events. Application must call this function periodically to ensure
112
* that all events from both transports and timer heap are handled in timely
113
* manner. This function, like all other endpoint functions, is thread safe,
114
* and application may have more than one thread concurrently calling this function.
116
* @param endpt The endpoint.
117
* @param max_timeout Maximum time to wait for events, or NULL to wait forever
118
* until event is received.
120
* @return PJ_SUCCESS on success.
122
PJ_DECL(pj_status_t) pjsip_endpt_handle_events( pjsip_endpoint *endpt,
123
const pj_time_val *max_timeout);
127
* Handle events with additional info about number of events that
130
* @param endpt The endpoint.
131
* @param max_timeout Maximum time to wait for events, or NULL to wait forever
132
* until event is received.
133
* @param count Optional argument to receive the number of events that
134
* have been handled by the function.
136
* @return PJ_SUCCESS on success.
138
PJ_DECL(pj_status_t) pjsip_endpt_handle_events2(pjsip_endpoint *endpt,
139
const pj_time_val *max_timeout,
142
* Schedule timer to endpoint's timer heap. Application must poll the endpoint
143
* periodically (by calling #pjsip_endpt_handle_events) to ensure that the
144
* timer events are handled in timely manner. When the timeout for the timer
145
* has elapsed, the callback specified in the entry argument will be called.
146
* This function, like all other endpoint functions, is thread safe.
148
* @param endpt The endpoint.
149
* @param entry The timer entry.
150
* @param delay The relative delay of the timer.
151
* @return PJ_OK (zero) if successfull.
153
PJ_DECL(pj_status_t) pjsip_endpt_schedule_timer( pjsip_endpoint *endpt,
154
pj_timer_entry *entry,
155
const pj_time_val *delay );
158
* Cancel the previously registered timer.
159
* This function, like all other endpoint functions, is thread safe.
161
* @param endpt The endpoint.
162
* @param entry The timer entry previously registered.
164
PJ_DECL(void) pjsip_endpt_cancel_timer( pjsip_endpoint *endpt,
165
pj_timer_entry *entry );
168
* Get the timer heap instance of the SIP endpoint.
170
* @param endpt The endpoint.
172
* @return The timer heap instance.
174
PJ_DECL(pj_timer_heap_t*) pjsip_endpt_get_timer_heap(pjsip_endpoint *endpt);
178
* Register new module to the endpoint.
179
* The endpoint will then call the load and start function in the module to
180
* properly initialize the module, and assign a unique module ID for the
183
* @param endpt The endpoint.
184
* @param module The module to be registered.
186
* @return PJ_SUCCESS on success.
188
PJ_DECL(pj_status_t) pjsip_endpt_register_module( pjsip_endpoint *endpt,
189
pjsip_module *module );
192
* Unregister a module from the endpoint.
193
* The endpoint will then call the stop and unload function in the module to
194
* properly shutdown the module.
196
* @param endpt The endpoint.
197
* @param module The module to be registered.
199
* @return PJ_SUCCESS on success.
201
PJ_DECL(pj_status_t) pjsip_endpt_unregister_module( pjsip_endpoint *endpt,
202
pjsip_module *module );
206
* Create pool from the endpoint. All SIP components should allocate their
207
* memory pool by calling this function, to make sure that the pools are
208
* allocated from the same pool factory. This function, like all other endpoint
209
* functions, is thread safe.
211
* @param endpt The SIP endpoint.
212
* @param pool_name Name to be assigned to the pool.
213
* @param initial The initial size of the pool.
214
* @param increment The resize size.
215
* @return Memory pool, or NULL on failure.
217
* @see pj_pool_create
219
PJ_DECL(pj_pool_t*) pjsip_endpt_create_pool( pjsip_endpoint *endpt,
220
const char *pool_name,
222
pj_size_t increment );
225
* Return back pool to endpoint to be released back to the pool factory.
226
* This function, like all other endpoint functions, is thread safe.
228
* @param endpt The endpoint.
229
* @param pool The pool to be destroyed.
231
PJ_DECL(void) pjsip_endpt_release_pool( pjsip_endpoint *endpt,
235
* Find transaction in endpoint's transaction table by the transaction's key.
236
* This function normally is only used by modules. The key for a transaction
237
* can be created by calling #pjsip_tsx_create_key.
239
* @param endpt The endpoint instance.
240
* @param key Transaction key, as created with #pjsip_tsx_create_key.
242
* @return The transaction, or NULL if it's not found.
244
PJ_DECL(pjsip_transaction*) pjsip_endpt_find_tsx( pjsip_endpoint *endpt,
245
const pj_str_t *key );
248
* Register the transaction to the endpoint's transaction table.
249
* This function should only be used internally by the stack.
251
* @param endpt The SIP endpoint.
252
* @param tsx The transaction.
254
PJ_DECL(void) pjsip_endpt_register_tsx( pjsip_endpoint *endpt,
255
pjsip_transaction *tsx);
258
* Forcefull destroy the transaction. This function should only be used
259
* internally by the stack.
261
* @param endpt The endpoint.
262
* @param tsx The transaction to destroy.
264
PJ_DECL(void) pjsip_endpt_destroy_tsx( pjsip_endpoint *endpt,
265
pjsip_transaction *tsx);
268
* Create a new transmit data buffer.
269
* This function, like all other endpoint functions, is thread safe.
271
* @param endpt The endpoint.
272
* @param p_tdata Pointer to receive transmit data buffer.
274
* @return PJ_SUCCESS or the appropriate error code.
276
PJ_DECL(pj_status_t) pjsip_endpt_create_tdata( pjsip_endpoint *endpt,
277
pjsip_tx_data **p_tdata);
280
* Create the DNS resolver instance. Application creates the DNS
281
* resolver instance, set the nameserver to be used by the DNS
282
* resolver, then set the DNS resolver to be used by the endpoint
283
* by calling #pjsip_endpt_set_resolver().
285
* @param endpt The SIP endpoint instance.
286
* @param p_resv Pointer to receive the DNS resolver instance.
288
* @return PJ_SUCCESS on success, or the appropriate error
291
PJ_DECL(pj_status_t) pjsip_endpt_create_resolver(pjsip_endpoint *endpt,
292
pj_dns_resolver **p_resv);
295
* Set DNS resolver to be used by the SIP resolver. Application can set
296
* the resolver instance to NULL to disable DNS resolution (perhaps
297
* temporarily). When DNS resolver is disabled, the endpoint will resolve
298
* hostnames with the normal pj_gethostbyname() function.
300
* @param endpt The SIP endpoint instance.
301
* @param resv The resolver instance to be used by the SIP
304
* @return PJ_SUCCESS on success, or the appropriate error
307
PJ_DECL(pj_status_t) pjsip_endpt_set_resolver(pjsip_endpoint *endpt,
308
pj_dns_resolver *resv);
311
* Get the DNS resolver being used by the SIP resolver.
313
* @param endpt The SIP endpoint instance.
315
* @return The DNS resolver instance currently being used
316
* by the SIP endpoint.
318
PJ_DECL(pj_dns_resolver*) pjsip_endpt_get_resolver(pjsip_endpoint *endpt);
321
* Asynchronously resolve a SIP target host or domain according to rule
322
* specified in RFC 3263 (Locating SIP Servers). When the resolving operation
323
* has completed, the callback will be called.
325
* @param endpt The endpoint instance.
326
* @param pool The pool to allocate resolver job.
327
* @param target The target specification to be resolved.
328
* @param token A user defined token to be passed back to callback function.
329
* @param cb The callback function.
331
PJ_DECL(void) pjsip_endpt_resolve( pjsip_endpoint *endpt,
333
pjsip_host_info *target,
335
pjsip_resolver_callback *cb);
338
* Get transport manager instance.
340
* @param endpt The endpoint.
342
* @return Transport manager instance.
344
PJ_DECL(pjsip_tpmgr*) pjsip_endpt_get_tpmgr(pjsip_endpoint *endpt);
347
* Get ioqueue instance.
349
* @param endpt The endpoint.
351
* @return The ioqueue.
353
PJ_DECL(pj_ioqueue_t*) pjsip_endpt_get_ioqueue(pjsip_endpoint *endpt);
356
* Find a SIP transport suitable for sending SIP message to the specified
357
* address. If transport selector ("sel") is set, then the function will
358
* check if the transport selected is suitable to send requests to the
361
* @see pjsip_tpmgr_acquire_transport
363
* @param endpt The SIP endpoint instance.
364
* @param type The type of transport to be acquired.
365
* @param remote The remote address to send message to.
366
* @param addr_len Length of the remote address.
367
* @param sel Optional pointer to transport selector instance which is
368
* used to find explicit transport, if required.
369
* @param p_tp Pointer to receive the transport instance, if one is found.
371
* @return PJ_SUCCESS on success, or the appropriate error code.
374
pjsip_endpt_acquire_transport( pjsip_endpoint *endpt,
375
pjsip_transport_type_e type,
376
const pj_sockaddr_t *remote,
378
const pjsip_tpselector *sel,
379
pjsip_transport **p_tp);
383
* Find a SIP transport suitable for sending SIP message to the specified
384
* address by also considering the outgoing SIP message data. If transport
385
* selector ("sel") is set, then the function will check if the transport
386
* selected is suitable to send requests to the specified address.
388
* @see pjsip_tpmgr_acquire_transport
390
* @param endpt The SIP endpoint instance.
391
* @param type The type of transport to be acquired.
392
* @param remote The remote address to send message to.
393
* @param addr_len Length of the remote address.
394
* @param sel Optional pointer to transport selector instance which is
395
* used to find explicit transport, if required.
396
* @param tdata Optional pointer to SIP message data to be sent.
397
* @param p_tp Pointer to receive the transport instance, if one is found.
399
* @return PJ_SUCCESS on success, or the appropriate error code.
402
pjsip_endpt_acquire_transport2(pjsip_endpoint *endpt,
403
pjsip_transport_type_e type,
404
const pj_sockaddr_t *remote,
406
const pjsip_tpselector *sel,
407
pjsip_tx_data *tdata,
408
pjsip_transport **p_tp);
411
/*****************************************************************************
413
* Capabilities Management
415
* Modules may implement new capabilities to the stack. These capabilities
416
* are indicated by the appropriate SIP header fields, such as Accept,
417
* Accept-Encoding, Accept-Language, Allow, Supported, etc.
419
* When a module provides new capabilities to the stack, it registers these
420
* capabilities to the endpoint by supplying new tags (strings) to the
421
* appropriate header fields. Application (or other modules) can then query
422
* these header fields to get the list of supported capabilities, and may
423
* include these headers in the outgoing message.
424
*****************************************************************************
428
* Get the value of the specified capability header field.
430
* @param endpt The endpoint.
431
* @param htype The header type to be retrieved, which value may be:
434
* - PJSIP_H_SUPPORTED
435
* @param hname If htype specifies PJSIP_H_OTHER, then the header name
436
* must be supplied in this argument. Otherwise the value
437
* must be set to NULL.
439
* @return The appropriate header, or NULL if the header is not
442
PJ_DECL(const pjsip_hdr*) pjsip_endpt_get_capability( pjsip_endpoint *endpt,
444
const pj_str_t *hname);
448
* Check if we have the specified capability.
450
* @param endpt The endpoint.
451
* @param htype The header type to be retrieved, which value may be:
454
* - PJSIP_H_SUPPORTED
455
* @param hname If htype specifies PJSIP_H_OTHER, then the header name
456
* must be supplied in this argument. Otherwise the value
457
* must be set to NULL.
458
* @param token The capability token to check. For example, if \a htype
459
* is PJSIP_H_ALLOW, then \a token specifies the method
460
* names; if \a htype is PJSIP_H_SUPPORTED, then \a token
461
* specifies the extension names such as "100rel".
463
* @return PJ_TRUE if the specified capability is supported,
464
* otherwise PJ_FALSE..
466
PJ_DECL(pj_bool_t) pjsip_endpt_has_capability( pjsip_endpoint *endpt,
468
const pj_str_t *hname,
469
const pj_str_t *token);
473
* Add or register new capabilities as indicated by the tags to the
474
* appropriate header fields in the endpoint.
476
* @param endpt The endpoint.
477
* @param mod The module which registers the capability.
478
* @param htype The header type to be set, which value may be:
481
* - PJSIP_H_SUPPORTED
482
* @param hname If htype specifies PJSIP_H_OTHER, then the header name
483
* must be supplied in this argument. Otherwise the value
484
* must be set to NULL.
485
* @param count The number of tags in the array.
486
* @param tags Array of tags describing the capabilities or extensions
487
* to be added to the appropriate header.
489
* @return PJ_SUCCESS on success.
491
PJ_DECL(pj_status_t) pjsip_endpt_add_capability( pjsip_endpoint *endpt,
494
const pj_str_t *hname,
496
const pj_str_t tags[]);
499
* Get list of additional headers to be put in outgoing request message.
500
* Currently only Max-Forwards are defined.
502
* @param e The endpoint.
504
* @return List of headers.
506
PJ_DECL(const pjsip_hdr*) pjsip_endpt_get_request_headers(pjsip_endpoint *e);
510
* Dump endpoint status to the log. This will print the status to the log
513
* @param endpt The endpoint.
514
* @param detail If non zero, then it will dump a detailed output.
515
* BEWARE that this option may crash the system because
516
* it tries to access all memory pools.
518
PJ_DECL(void) pjsip_endpt_dump( pjsip_endpoint *endpt, pj_bool_t detail );
522
* Register cleanup function to be called by SIP endpoint when
523
* #pjsip_endpt_destroy() is called. Note that application should not
524
* use or access any endpoint resource (such as pool, ioqueue, timer heap)
525
* from within the callback as such resource may have been released when
526
* the callback function is invoked.
528
* @param endpt The SIP endpoint.
529
* @param func The function to be registered.
531
* @return PJ_SUCCESS on success.
533
PJ_DECL(pj_status_t) pjsip_endpt_atexit(pjsip_endpoint *endpt,
534
pjsip_endpt_exit_callback func);
545
PJ_DECL(void) pjsip_endpt_log_error( pjsip_endpoint *endpt,
547
pj_status_t error_code,
551
#define PJSIP_ENDPT_LOG_ERROR(expr) \
552
pjsip_endpt_log_error expr
554
#define PJSIP_ENDPT_TRACE(tracing,expr) \
561
* Internal functions.
564
* Receive transaction events from transactions and put in the event queue
565
* to be processed later.
567
void pjsip_endpt_send_tsx_event( pjsip_endpoint *endpt, pjsip_event *evt );
571
#endif /* __PJSIP_SIP_ENDPOINT_H__ */