sip_module.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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_MODULE_H__
  20. #define __PJSIP_SIP_MODULE_H__
  21. /**
  22. * @file sip_module.h
  23. * @brief Module helpers
  24. */
  25. #include <pjsip/sip_types.h>
  26. #include <pj/list.h>
  27. PJ_BEGIN_DECL
  28. /**
  29. * @defgroup PJSIP_MOD Modules
  30. * @ingroup PJSIP_CORE_CORE
  31. * @brief Modules are the primary means to extend PJSIP!
  32. * @{
  33. * Modules are the primary means to extend PJSIP. Without modules, PJSIP
  34. * would not know how to handle messages, and will simply discard all
  35. * incoming messages.
  36. *
  37. * Modules are registered by creating and initializing #pjsip_module
  38. * structure, and register the structure to PJSIP with
  39. * #pjsip_endpt_register_module().
  40. *
  41. * The <A HREF="/en/latest/api/pjsip/guide.html">PJSIP Developer's Guide</A>
  42. * has a thorough discussion on this subject, and readers are encouraged
  43. * to read the document for more information.
  44. */
  45. /**
  46. * The declaration for SIP module. This structure would be passed to
  47. * #pjsip_endpt_register_module() to register the module to PJSIP.
  48. */
  49. struct pjsip_module
  50. {
  51. /** To allow chaining of modules in the endpoint. */
  52. PJ_DECL_LIST_MEMBER(struct pjsip_module);
  53. /**
  54. * Module name to identify the module.
  55. *
  56. * This field MUST be initialized before registering the module.
  57. */
  58. pj_str_t name;
  59. /**
  60. * Module ID. Application must initialize this field with -1 before
  61. * registering the module to PJSIP. After the module is registered,
  62. * this field will contain a unique ID to identify the module.
  63. */
  64. int id;
  65. /**
  66. * Integer number to identify module initialization and start order with
  67. * regard to other modules. Higher number will make the module gets
  68. * initialized later.
  69. *
  70. * This field MUST be initialized before registering the module.
  71. */
  72. int priority;
  73. /**
  74. * Optional function to be called to initialize the module. This function
  75. * will be called by endpoint during module registration. If the value
  76. * is NULL, then it's equal to returning PJ_SUCCESS.
  77. *
  78. * @param endpt The endpoint instance.
  79. * @return Module should return PJ_SUCCESS to indicate success.
  80. */
  81. pj_status_t (*load)(pjsip_endpoint *endpt);
  82. /**
  83. * Optional function to be called to start the module. This function
  84. * will be called by endpoint during module registration. If the value
  85. * is NULL, then it's equal to returning PJ_SUCCESS.
  86. *
  87. * @return Module should return zero to indicate success.
  88. */
  89. pj_status_t (*start)(void);
  90. /**
  91. * Optional function to be called to deinitialize the module before
  92. * it is unloaded. This function will be called by endpoint during
  93. * module unregistration. If the value is NULL, then it's equal to
  94. * returning PJ_SUCCESS.
  95. *
  96. * @return Module should return PJ_SUCCESS to indicate success.
  97. */
  98. pj_status_t (*stop)(void);
  99. /**
  100. * Optional function to be called to deinitialize the module before
  101. * it is unloaded. This function will be called by endpoint during
  102. * module unregistration. If the value is NULL, then it's equal to
  103. * returning PJ_SUCCESS.
  104. *
  105. * @param mod The module.
  106. *
  107. * @return Module should return PJ_SUCCESS to indicate success.
  108. */
  109. pj_status_t (*unload)(void);
  110. /**
  111. * Optional function to be called to process incoming request message.
  112. *
  113. * @param rdata The incoming message.
  114. *
  115. * @return Module should return PJ_TRUE if it handles the request,
  116. * or otherwise it should return PJ_FALSE to allow other
  117. * modules to handle the request.
  118. */
  119. pj_bool_t (*on_rx_request)(pjsip_rx_data *rdata);
  120. /**
  121. * Optional function to be called to process incoming response message.
  122. *
  123. * @param rdata The incoming message.
  124. *
  125. * @return Module should return PJ_TRUE if it handles the
  126. * response, or otherwise it should return PJ_FALSE to
  127. * allow other modules to handle the response.
  128. */
  129. pj_bool_t (*on_rx_response)(pjsip_rx_data *rdata);
  130. /**
  131. * Optional function to be called when transport layer is about to
  132. * transmit outgoing request message.
  133. *
  134. * @param tdata The outgoing request message.
  135. *
  136. * @return Module should return PJ_SUCCESS in all cases.
  137. * If non-zero is returned, the message
  138. * will not be sent.
  139. */
  140. pj_status_t (*on_tx_request)(pjsip_tx_data *tdata);
  141. /**
  142. * Optional function to be called when transport layer is about to
  143. * transmit outgoing response message.
  144. *
  145. * @param tdata The outgoing response message.
  146. *
  147. * @return Module should return PJ_SUCCESS in all cases.
  148. * If non-zero is returned, the message
  149. * will not be sent.
  150. */
  151. pj_status_t (*on_tx_response)(pjsip_tx_data *tdata);
  152. /**
  153. * Optional function to be called when this module is acting as
  154. * transaction user for the specified transaction, when the
  155. * transaction's state has changed.
  156. *
  157. * @param tsx The transaction.
  158. * @param event The event which has caused the transaction state
  159. * to change.
  160. */
  161. void (*on_tsx_state)(pjsip_transaction *tsx, pjsip_event *event);
  162. };
  163. /**
  164. * Module priority guidelines.
  165. */
  166. enum pjsip_module_priority
  167. {
  168. /**
  169. * This is the priority used by transport layer.
  170. */
  171. PJSIP_MOD_PRIORITY_TRANSPORT_LAYER = 8,
  172. /**
  173. * This is the priority used by transaction layer.
  174. */
  175. PJSIP_MOD_PRIORITY_TSX_LAYER = 16,
  176. /**
  177. * This is the priority used by the user agent and proxy layer.
  178. */
  179. PJSIP_MOD_PRIORITY_UA_PROXY_LAYER = 32,
  180. /**
  181. * This is the priority used by the dialog usages.
  182. */
  183. PJSIP_MOD_PRIORITY_DIALOG_USAGE = 48,
  184. /**
  185. * This is the recommended priority to be used by applications.
  186. */
  187. PJSIP_MOD_PRIORITY_APPLICATION = 64
  188. };
  189. /**
  190. * @}
  191. */
  192. PJ_END_DECL
  193. #endif /* __PJSIP_SIP_MODULE_H__ */