sip_endpoint.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 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_ENDPOINT_H__
  20. #define __PJSIP_SIP_ENDPOINT_H__
  21. /**
  22. * @file sip_endpoint.h
  23. * @brief SIP Endpoint.
  24. */
  25. #include <pjsip/sip_transport.h>
  26. #include <pjsip/sip_resolve.h>
  27. /**
  28. * @defgroup PJSIP_CORE_CORE At the Very Core
  29. * @ingroup PJSIP_CORE
  30. * @brief The very core of PJSIP.
  31. */
  32. PJ_BEGIN_DECL
  33. /**
  34. * @defgroup PJSIP_ENDPT Endpoint
  35. * @ingroup PJSIP_CORE_CORE
  36. * @brief The master, owner of all objects
  37. *
  38. * SIP Endpoint instance (pjsip_endpoint) can be viewed as the master/owner of
  39. * all SIP objects in an application. It performs the following roles:
  40. * - it manages the allocation/deallocation of memory pools for all objects.
  41. * - it manages listeners and transports, and how they are used by
  42. * transactions.
  43. * - it receives incoming messages from transport layer and automatically
  44. * dispatches them to the correct transaction (or create a new one).
  45. * - it has a single instance of timer management (timer heap).
  46. * - it manages modules, which is the primary means of extending the library.
  47. * - it provides single polling function for all objects and distributes
  48. * events.
  49. * - it automatically handles incoming requests which can not be handled by
  50. * existing modules (such as when incoming request has unsupported method).
  51. * - and so on..
  52. *
  53. * Application should only instantiate one SIP endpoint instance for every
  54. * process.
  55. *
  56. * @{
  57. */
  58. /**
  59. * Type of callback to register to pjsip_endpt_atexit().
  60. */
  61. typedef void (*pjsip_endpt_exit_callback)(pjsip_endpoint *endpt);
  62. /**
  63. * Create an instance of SIP endpoint from the specified pool factory.
  64. * The pool factory reference then will be kept by the endpoint, so that
  65. * future memory allocations by SIP components will be taken from the same
  66. * pool factory.
  67. *
  68. * @param pf Pool factory that will be used for the lifetime of
  69. * endpoint.
  70. * @param name Optional name to be specified for the endpoint.
  71. * If this parameter is NULL, then the name will use
  72. * local host name.
  73. * @param endpt Pointer to receive endpoint instance.
  74. *
  75. * @return PJ_SUCCESS on success.
  76. */
  77. PJ_DECL(pj_status_t) pjsip_endpt_create(pj_pool_factory *pf,
  78. const char *name,
  79. pjsip_endpoint **endpt);
  80. /**
  81. * Destroy endpoint instance. Application must make sure that all pending
  82. * transactions have been terminated properly, because this function does not
  83. * check for the presence of pending transactions.
  84. *
  85. * @param endpt The SIP endpoint to be destroyed.
  86. */
  87. PJ_DECL(void) pjsip_endpt_destroy(pjsip_endpoint *endpt);
  88. /**
  89. * Get endpoint name.
  90. *
  91. * @param endpt The SIP endpoint instance.
  92. *
  93. * @return Endpoint name, as was registered during endpoint
  94. * creation. The string is NULL terminated.
  95. */
  96. PJ_DECL(const pj_str_t*) pjsip_endpt_name(const pjsip_endpoint *endpt);
  97. /**
  98. * Poll for events. Application must call this function periodically to ensure
  99. * that all events from both transports and timer heap are handled in timely
  100. * manner. This function, like all other endpoint functions, is thread safe,
  101. * and application may have more than one thread concurrently calling this function.
  102. *
  103. * @param endpt The endpoint.
  104. * @param max_timeout Maximum time to wait for events, or NULL to wait forever
  105. * until event is received.
  106. *
  107. * @return PJ_SUCCESS on success.
  108. */
  109. PJ_DECL(pj_status_t) pjsip_endpt_handle_events( pjsip_endpoint *endpt,
  110. const pj_time_val *max_timeout);
  111. /**
  112. * Handle events with additional info about number of events that
  113. * have been handled.
  114. *
  115. * @param endpt The endpoint.
  116. * @param max_timeout Maximum time to wait for events, or NULL to wait forever
  117. * until event is received.
  118. * @param count Optional argument to receive the number of events that
  119. * have been handled by the function.
  120. *
  121. * @return PJ_SUCCESS on success.
  122. */
  123. PJ_DECL(pj_status_t) pjsip_endpt_handle_events2(pjsip_endpoint *endpt,
  124. const pj_time_val *max_timeout,
  125. unsigned *count);
  126. /**
  127. * Schedule timer to endpoint's timer heap. Application must poll the endpoint
  128. * periodically (by calling #pjsip_endpt_handle_events) to ensure that the
  129. * timer events are handled in timely manner. When the timeout for the timer
  130. * has elapsed, the callback specified in the entry argument will be called.
  131. * This function, like all other endpoint functions, is thread safe.
  132. *
  133. * @param endpt The endpoint.
  134. * @param entry The timer entry.
  135. * @param delay The relative delay of the timer.
  136. * @return PJ_OK (zero) if successfull.
  137. */
  138. #if PJ_TIMER_DEBUG
  139. #define pjsip_endpt_schedule_timer(ept,ent,d) \
  140. pjsip_endpt_schedule_timer_dbg(ept, ent, d, \
  141. __FILE__, __LINE__)
  142. PJ_DECL(pj_status_t) pjsip_endpt_schedule_timer_dbg(pjsip_endpoint *endpt,
  143. pj_timer_entry *entry,
  144. const pj_time_val *delay,
  145. const char *src_file,
  146. int src_line);
  147. #else
  148. PJ_DECL(pj_status_t) pjsip_endpt_schedule_timer( pjsip_endpoint *endpt,
  149. pj_timer_entry *entry,
  150. const pj_time_val *delay );
  151. #endif
  152. /**
  153. * Schedule timer to endpoint's timer heap with group lock. Application must
  154. * poll the endpoint periodically (by calling #pjsip_endpt_handle_events) to
  155. * ensure that the timer events are handled in timely manner. When the
  156. * timeout for the timer has elapsed, the callback specified in the entry
  157. * argument will be called. This function, like all other endpoint functions,
  158. * is thread safe.
  159. *
  160. * @param endpt The endpoint.
  161. * @param entry The timer entry.
  162. * @param delay The relative delay of the timer.
  163. * @param id_val The value to be set to the "id" field of the timer entry
  164. * once the timer is scheduled.
  165. * @param grp_lock The group lock.
  166. * @return PJ_OK (zero) if successfull.
  167. */
  168. #if PJ_TIMER_DEBUG
  169. #define pjsip_endpt_schedule_timer_w_grp_lock(ept,ent,d,id,gl) \
  170. pjsip_endpt_schedule_timer_w_grp_lock_dbg(ept,ent,d,id,gl,\
  171. __FILE__, __LINE__)
  172. PJ_DECL(pj_status_t) pjsip_endpt_schedule_timer_w_grp_lock_dbg(
  173. pjsip_endpoint *endpt,
  174. pj_timer_entry *entry,
  175. const pj_time_val *delay,
  176. int id_val,
  177. pj_grp_lock_t *grp_lock,
  178. const char *src_file,
  179. int src_line);
  180. #else
  181. PJ_DECL(pj_status_t) pjsip_endpt_schedule_timer_w_grp_lock(
  182. pjsip_endpoint *endpt,
  183. pj_timer_entry *entry,
  184. const pj_time_val *delay,
  185. int id_val,
  186. pj_grp_lock_t *grp_lock );
  187. #endif
  188. /**
  189. * Cancel the previously registered timer.
  190. * This function, like all other endpoint functions, is thread safe.
  191. *
  192. * @param endpt The endpoint.
  193. * @param entry The timer entry previously registered.
  194. */
  195. PJ_DECL(void) pjsip_endpt_cancel_timer( pjsip_endpoint *endpt,
  196. pj_timer_entry *entry );
  197. /**
  198. * Get the timer heap instance of the SIP endpoint.
  199. *
  200. * @param endpt The endpoint.
  201. *
  202. * @return The timer heap instance.
  203. */
  204. PJ_DECL(pj_timer_heap_t*) pjsip_endpt_get_timer_heap(pjsip_endpoint *endpt);
  205. /**
  206. * Register new module to the endpoint.
  207. * The endpoint will then call the load and start function in the module to
  208. * properly initialize the module, and assign a unique module ID for the
  209. * module.
  210. *
  211. * @param endpt The endpoint.
  212. * @param module The module to be registered.
  213. *
  214. * @return PJ_SUCCESS on success.
  215. */
  216. PJ_DECL(pj_status_t) pjsip_endpt_register_module( pjsip_endpoint *endpt,
  217. pjsip_module *module );
  218. /**
  219. * Unregister a module from the endpoint.
  220. * The endpoint will then call the stop and unload function in the module to
  221. * properly shutdown the module.
  222. *
  223. * @param endpt The endpoint.
  224. * @param module The module to be registered.
  225. *
  226. * @return PJ_SUCCESS on success.
  227. */
  228. PJ_DECL(pj_status_t) pjsip_endpt_unregister_module( pjsip_endpoint *endpt,
  229. pjsip_module *module );
  230. /**
  231. * This describes additional parameters to pjsip_endpt_process_rx_data()
  232. * function. Application MUST call pjsip_process_rdata_param_default() to
  233. * initialize this structure.
  234. */
  235. typedef struct pjsip_process_rdata_param
  236. {
  237. /**
  238. * Specify the minimum priority number of the modules that are allowed
  239. * to process the message. Default is zero to allow all modules to
  240. * process the message.
  241. */
  242. unsigned start_prio;
  243. /**
  244. * Specify the pointer of the module where processing will start.
  245. * The default is NULL, meaning processing will start from the start
  246. * of the module list.
  247. */
  248. void *start_mod;
  249. /**
  250. * Set to N, then processing will start at Nth module after start
  251. * module (where start module can be an explicit module as specified
  252. * by \a start_mod or the start of module list when \a start_mod is
  253. * NULL). For example, if set to 1, then processing will start from
  254. * the next module after start module. Default is zero.
  255. */
  256. unsigned idx_after_start;
  257. /**
  258. * Print nothing to log. Default is PJ_FALSE.
  259. */
  260. pj_bool_t silent;
  261. } pjsip_process_rdata_param;
  262. /**
  263. * Initialize with default.
  264. *
  265. * @param p The param.
  266. */
  267. PJ_DECL(void) pjsip_process_rdata_param_default(pjsip_process_rdata_param *p);
  268. /**
  269. * Manually distribute the specified pjsip_rx_data to registered modules.
  270. * Normally application does not need to call this function because received
  271. * messages will be given to endpoint automatically by transports.
  272. *
  273. * Application can use this function when it has postponed the processing of
  274. * an incoming message, for example to perform long operations such as
  275. * database operation or to consult other servers to decide what to do with
  276. * the message. In this case, application clones the original rdata, return
  277. * from the callback, and perform the long operation. Upon completing the
  278. * long operation, it resumes pjsip's module processing by calling this
  279. * function, and then free the cloned rdata.
  280. *
  281. * @param endpt The endpoint instance.
  282. * @param rdata The rdata to be distributed.
  283. * @param p Optional pointer to param to specify from which module
  284. * the processing should start.
  285. * @param p_handled Optional pointer to receive last return value of
  286. * module's \a on_rx_request() or \a on_rx_response()
  287. * callback.
  288. *
  289. * @return PJ_SUCCESS on success.
  290. */
  291. PJ_DECL(pj_status_t) pjsip_endpt_process_rx_data(pjsip_endpoint *endpt,
  292. pjsip_rx_data *rdata,
  293. pjsip_process_rdata_param *p,
  294. pj_bool_t *p_handled);
  295. /**
  296. * Create pool from the endpoint. All SIP components should allocate their
  297. * memory pool by calling this function, to make sure that the pools are
  298. * allocated from the same pool factory. This function, like all other endpoint
  299. * functions, is thread safe.
  300. *
  301. * @param endpt The SIP endpoint.
  302. * @param pool_name Name to be assigned to the pool.
  303. * @param initial The initial size of the pool.
  304. * @param increment The resize size.
  305. * @return Memory pool, or NULL on failure.
  306. *
  307. * @see pj_pool_create
  308. */
  309. PJ_DECL(pj_pool_t*) pjsip_endpt_create_pool( pjsip_endpoint *endpt,
  310. const char *pool_name,
  311. pj_size_t initial,
  312. pj_size_t increment );
  313. /**
  314. * Return back pool to endpoint to be released back to the pool factory.
  315. * This function, like all other endpoint functions, is thread safe.
  316. *
  317. * @param endpt The endpoint.
  318. * @param pool The pool to be destroyed.
  319. */
  320. PJ_DECL(void) pjsip_endpt_release_pool( pjsip_endpoint *endpt,
  321. pj_pool_t *pool );
  322. /**
  323. * Find transaction in endpoint's transaction table by the transaction's key.
  324. * This function normally is only used by modules. The key for a transaction
  325. * can be created by calling #pjsip_tsx_create_key.
  326. *
  327. * @param endpt The endpoint instance.
  328. * @param key Transaction key, as created with #pjsip_tsx_create_key.
  329. *
  330. * @return The transaction, or NULL if it's not found.
  331. */
  332. PJ_DECL(pjsip_transaction*) pjsip_endpt_find_tsx( pjsip_endpoint *endpt,
  333. const pj_str_t *key );
  334. /**
  335. * Register the transaction to the endpoint's transaction table.
  336. * This function should only be used internally by the stack.
  337. *
  338. * @param endpt The SIP endpoint.
  339. * @param tsx The transaction.
  340. */
  341. PJ_DECL(void) pjsip_endpt_register_tsx( pjsip_endpoint *endpt,
  342. pjsip_transaction *tsx);
  343. /**
  344. * Forcefull destroy the transaction. This function should only be used
  345. * internally by the stack.
  346. *
  347. * @param endpt The endpoint.
  348. * @param tsx The transaction to destroy.
  349. */
  350. PJ_DECL(void) pjsip_endpt_destroy_tsx( pjsip_endpoint *endpt,
  351. pjsip_transaction *tsx);
  352. /**
  353. * Create a new transmit data buffer.
  354. * This function, like all other endpoint functions, is thread safe.
  355. *
  356. * @param endpt The endpoint.
  357. * @param p_tdata Pointer to receive transmit data buffer.
  358. *
  359. * @return PJ_SUCCESS or the appropriate error code.
  360. */
  361. PJ_DECL(pj_status_t) pjsip_endpt_create_tdata( pjsip_endpoint *endpt,
  362. pjsip_tx_data **p_tdata);
  363. /**
  364. * Create the DNS resolver instance. Application creates the DNS
  365. * resolver instance, set the nameserver to be used by the DNS
  366. * resolver, then set the DNS resolver to be used by the endpoint
  367. * by calling #pjsip_endpt_set_resolver().
  368. *
  369. * @param endpt The SIP endpoint instance.
  370. * @param p_resv Pointer to receive the DNS resolver instance.
  371. *
  372. * @return PJ_SUCCESS on success, or the appropriate error
  373. * code.
  374. */
  375. PJ_DECL(pj_status_t) pjsip_endpt_create_resolver(pjsip_endpoint *endpt,
  376. pj_dns_resolver **p_resv);
  377. /**
  378. * Set DNS resolver to be used by the SIP resolver. Application can set
  379. * the resolver instance to NULL to disable DNS resolution (perhaps
  380. * temporarily). When DNS resolver is disabled, the endpoint will resolve
  381. * hostnames with the normal pj_gethostbyname() function.
  382. *
  383. * @param endpt The SIP endpoint instance.
  384. * @param resv The resolver instance to be used by the SIP
  385. * endpoint.
  386. *
  387. * @return PJ_SUCCESS on success, or the appropriate error
  388. * code.
  389. */
  390. PJ_DECL(pj_status_t) pjsip_endpt_set_resolver(pjsip_endpoint *endpt,
  391. pj_dns_resolver *resv);
  392. /**
  393. * Set the DNS external resolver implementation to use in the SIP resolver.
  394. *
  395. * Note that naturally when implementing its own resolver, application would not
  396. * need the internal resolver, hence this function will also destroy the
  397. * PJLIB-UTIL DNS resolver if any (e.g: set using #pjsip_endpt_set_resolver()).
  398. * Application that needs it, still be able create its own instance.
  399. *
  400. * @param endpt The SIP resolver engine.
  401. * @param ext_res The external resolver implementation callback. This argument
  402. * can be NULL to reset the whole external implementation.
  403. * However, it is prohibited to reset individual callback.
  404. *
  405. * @return PJ_SUCCESS on success, or the appropriate error code.
  406. */
  407. PJ_DECL(pj_status_t) pjsip_endpt_set_ext_resolver(pjsip_endpoint *endpt,
  408. pjsip_ext_resolver *ext_res);
  409. /**
  410. * Get the DNS resolver being used by the SIP resolver.
  411. *
  412. * @param endpt The SIP endpoint instance.
  413. *
  414. * @return The DNS resolver instance currently being used
  415. * by the SIP endpoint.
  416. */
  417. PJ_DECL(pj_dns_resolver*) pjsip_endpt_get_resolver(pjsip_endpoint *endpt);
  418. /**
  419. * Asynchronously resolve a SIP target host or domain according to rule
  420. * specified in RFC 3263 (Locating SIP Servers). When the resolving operation
  421. * has completed, the callback will be called.
  422. *
  423. * @param endpt The endpoint instance.
  424. * @param pool The pool to allocate resolver job.
  425. * @param target The target specification to be resolved.
  426. * @param token A user defined token to be passed back to callback function.
  427. * @param cb The callback function.
  428. */
  429. PJ_DECL(void) pjsip_endpt_resolve( pjsip_endpoint *endpt,
  430. pj_pool_t *pool,
  431. pjsip_host_info *target,
  432. void *token,
  433. pjsip_resolver_callback *cb);
  434. /**
  435. * Get transport manager instance.
  436. *
  437. * @param endpt The endpoint.
  438. *
  439. * @return Transport manager instance.
  440. */
  441. PJ_DECL(pjsip_tpmgr*) pjsip_endpt_get_tpmgr(pjsip_endpoint *endpt);
  442. /**
  443. * Get ioqueue instance.
  444. *
  445. * @param endpt The endpoint.
  446. *
  447. * @return The ioqueue.
  448. */
  449. PJ_DECL(pj_ioqueue_t*) pjsip_endpt_get_ioqueue(pjsip_endpoint *endpt);
  450. /**
  451. * Find a SIP transport suitable for sending SIP message to the specified
  452. * address. If transport selector ("sel") is set, then the function will
  453. * check if the transport selected is suitable to send requests to the
  454. * specified address.
  455. *
  456. * @see pjsip_tpmgr_acquire_transport
  457. *
  458. * @param endpt The SIP endpoint instance.
  459. * @param type The type of transport to be acquired.
  460. * @param remote The remote address to send message to.
  461. * @param addr_len Length of the remote address.
  462. * @param sel Optional pointer to transport selector instance which is
  463. * used to find explicit transport, if required.
  464. * @param p_tp Pointer to receive the transport instance, if one is found.
  465. *
  466. * @return PJ_SUCCESS on success, or the appropriate error code.
  467. */
  468. PJ_DECL(pj_status_t)
  469. pjsip_endpt_acquire_transport( pjsip_endpoint *endpt,
  470. pjsip_transport_type_e type,
  471. const pj_sockaddr_t *remote,
  472. int addr_len,
  473. const pjsip_tpselector *sel,
  474. pjsip_transport **p_tp);
  475. /**
  476. * Find a SIP transport suitable for sending SIP message to the specified
  477. * address by also considering the outgoing SIP message data. If transport
  478. * selector ("sel") is set, then the function will check if the transport
  479. * selected is suitable to send requests to the specified address.
  480. *
  481. * @see pjsip_tpmgr_acquire_transport
  482. *
  483. * @param endpt The SIP endpoint instance.
  484. * @param type The type of transport to be acquired.
  485. * @param remote The remote address to send message to.
  486. * @param addr_len Length of the remote address.
  487. * @param sel Optional pointer to transport selector instance which is
  488. * used to find explicit transport, if required.
  489. * @param tdata Optional pointer to SIP message data to be sent.
  490. * @param p_tp Pointer to receive the transport instance, if one is found.
  491. *
  492. * @return PJ_SUCCESS on success, or the appropriate error code.
  493. */
  494. PJ_DECL(pj_status_t)
  495. pjsip_endpt_acquire_transport2(pjsip_endpoint *endpt,
  496. pjsip_transport_type_e type,
  497. const pj_sockaddr_t *remote,
  498. int addr_len,
  499. const pjsip_tpselector *sel,
  500. pjsip_tx_data *tdata,
  501. pjsip_transport **p_tp);
  502. /*****************************************************************************
  503. *
  504. * Capabilities Management
  505. *
  506. * Modules may implement new capabilities to the stack. These capabilities
  507. * are indicated by the appropriate SIP header fields, such as Accept,
  508. * Accept-Encoding, Accept-Language, Allow, Supported, etc.
  509. *
  510. * When a module provides new capabilities to the stack, it registers these
  511. * capabilities to the endpoint by supplying new tags (strings) to the
  512. * appropriate header fields. Application (or other modules) can then query
  513. * these header fields to get the list of supported capabilities, and may
  514. * include these headers in the outgoing message.
  515. *****************************************************************************
  516. */
  517. /**
  518. * Get the value of the specified capability header field.
  519. *
  520. * @param endpt The endpoint.
  521. * @param htype The header type to be retrieved, which value may be:
  522. * - PJSIP_H_ACCEPT
  523. * - PJSIP_H_ALLOW
  524. * - PJSIP_H_SUPPORTED
  525. * @param hname If htype specifies PJSIP_H_OTHER, then the header name
  526. * must be supplied in this argument. Otherwise the value
  527. * must be set to NULL.
  528. *
  529. * @return The appropriate header, or NULL if the header is not
  530. * available.
  531. */
  532. PJ_DECL(const pjsip_hdr*) pjsip_endpt_get_capability( pjsip_endpoint *endpt,
  533. int htype,
  534. const pj_str_t *hname);
  535. /**
  536. * Check if we have the specified capability.
  537. *
  538. * @param endpt The endpoint.
  539. * @param htype The header type to be retrieved, which value may be:
  540. * - PJSIP_H_ACCEPT
  541. * - PJSIP_H_ALLOW
  542. * - PJSIP_H_SUPPORTED
  543. * @param hname If htype specifies PJSIP_H_OTHER, then the header name
  544. * must be supplied in this argument. Otherwise the value
  545. * must be set to NULL.
  546. * @param token The capability token to check. For example, if \a htype
  547. * is PJSIP_H_ALLOW, then \a token specifies the method
  548. * names; if \a htype is PJSIP_H_SUPPORTED, then \a token
  549. * specifies the extension names such as "100rel".
  550. *
  551. * @return PJ_TRUE if the specified capability is supported,
  552. * otherwise PJ_FALSE..
  553. */
  554. PJ_DECL(pj_bool_t) pjsip_endpt_has_capability( pjsip_endpoint *endpt,
  555. int htype,
  556. const pj_str_t *hname,
  557. const pj_str_t *token);
  558. /**
  559. * Add or register new capabilities as indicated by the tags to the
  560. * appropriate header fields in the endpoint.
  561. *
  562. * @param endpt The endpoint.
  563. * @param mod The module which registers the capability.
  564. * @param htype The header type to be set, which value may be:
  565. * - PJSIP_H_ACCEPT
  566. * - PJSIP_H_ALLOW
  567. * - PJSIP_H_SUPPORTED
  568. * @param hname If htype specifies PJSIP_H_OTHER, then the header name
  569. * must be supplied in this argument. Otherwise the value
  570. * must be set to NULL.
  571. * @param count The number of tags in the array. The value must not
  572. * be greater than PJSIP_GENERIC_ARRAY_MAX_COUNT.
  573. * @param tags Array of tags describing the capabilities or extensions
  574. * to be added to the appropriate header.
  575. *
  576. * @return PJ_SUCCESS on success.
  577. */
  578. PJ_DECL(pj_status_t) pjsip_endpt_add_capability( pjsip_endpoint *endpt,
  579. pjsip_module *mod,
  580. int htype,
  581. const pj_str_t *hname,
  582. unsigned count,
  583. const pj_str_t tags[]);
  584. /**
  585. * Get list of additional headers to be put in outgoing request message.
  586. * Currently only Max-Forwards are defined.
  587. *
  588. * @param e The endpoint.
  589. *
  590. * @return List of headers.
  591. */
  592. PJ_DECL(const pjsip_hdr*) pjsip_endpt_get_request_headers(pjsip_endpoint *e);
  593. /**
  594. * Dump endpoint status to the log. This will print the status to the log
  595. * with log level 3.
  596. *
  597. * @param endpt The endpoint.
  598. * @param detail If non zero, then it will dump a detailed output.
  599. * BEWARE that this option may crash the system because
  600. * it tries to access all memory pools.
  601. */
  602. PJ_DECL(void) pjsip_endpt_dump( pjsip_endpoint *endpt, pj_bool_t detail );
  603. /**
  604. * Register cleanup function to be called by SIP endpoint when
  605. * #pjsip_endpt_destroy() is called. Note that application should not
  606. * use or access any endpoint resource (such as pool, ioqueue, timer heap)
  607. * from within the callback as such resource may have been released when
  608. * the callback function is invoked.
  609. *
  610. * @param endpt The SIP endpoint.
  611. * @param func The function to be registered.
  612. *
  613. * @return PJ_SUCCESS on success.
  614. */
  615. PJ_DECL(pj_status_t) pjsip_endpt_atexit(pjsip_endpoint *endpt,
  616. pjsip_endpt_exit_callback func);
  617. /**
  618. * @}
  619. */
  620. /**
  621. * Log an error.
  622. */
  623. PJ_DECL(void) pjsip_endpt_log_error( pjsip_endpoint *endpt,
  624. const char *sender,
  625. pj_status_t error_code,
  626. const char *format,
  627. ... )
  628. PJ_PRINT_FUNC_DECOR(4);
  629. /** Internal */
  630. #define PJSIP_ENDPT_LOG_ERROR(expr) \
  631. pjsip_endpt_log_error expr
  632. /** Internal */
  633. #define PJSIP_ENDPT_TRACE(tracing,expr) \
  634. do { \
  635. if ((tracing)) \
  636. PJ_LOG(4,expr); \
  637. } while (0)
  638. /*
  639. * Internal functions.
  640. */
  641. /**
  642. * Internal: receive transaction events from transactions and put in the
  643. * event queue to be processed later.
  644. */
  645. void pjsip_endpt_send_tsx_event( pjsip_endpoint *endpt, pjsip_event *evt );
  646. PJ_END_DECL
  647. #endif /* __PJSIP_SIP_ENDPOINT_H__ */