dlg_event.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * Copyright (C) 2024 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2013 Maxim Kondratenko <max.kondr@gmail.com>
  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_SIMPLE_DLG_EVENT_H__
  20. #define __PJSIP_SIMPLE_DLG_EVENT_H__
  21. /**
  22. * @file dlg_event.h
  23. * @brief SIP Extension for INVITE-Initiated Dialog Event (RFC 4235)
  24. */
  25. #include <pjsip-simple/evsub.h>
  26. #include <pjsip-simple/dialog_info.h>
  27. PJ_BEGIN_DECL
  28. /**
  29. * @defgroup PJSIP_SIMPLE_DLG_EVENT SIP Extension for Dialog Event (RFC 4235)
  30. * @ingroup PJSIP_SIMPLE
  31. * @brief Support for SIP Extension for Dialog Event (RFC 4235)
  32. * @{
  33. *
  34. * This module contains the implementation of INVITE-Initiated Dialog Event
  35. * Package as described in RFC 4235. It uses the SIP Event Notification
  36. * framework (evsub.h) and extends the framework by implementing
  37. * "dialog-info+xml" event package. This could be useful for features such as
  38. * Busy Lamp Field (BLF).
  39. */
  40. /**
  41. * Initialize the dialog event module and register it as endpoint module and
  42. * package to the event subscription module.
  43. *
  44. * @param endpt The endpoint instance.
  45. * @param mod_evsub The event subscription module instance.
  46. *
  47. * @return PJ_SUCCESS if the module is successfully
  48. * initialized and registered to both endpoint
  49. * and the event subscription module.
  50. */
  51. PJ_DECL(pj_status_t) pjsip_dlg_event_init_module(pjsip_endpoint *endpt,
  52. pjsip_module *mod_evsub);
  53. /**
  54. * Get the dialog event module instance.
  55. *
  56. * @return The dialog event module instance.
  57. */
  58. PJ_DECL(pjsip_module*) pjsip_bdlg_event_instance(void);
  59. /**
  60. * Maximum dialog event status info items which can handled by application.
  61. *
  62. */
  63. #define PJSIP_DLG_EVENT_STATUS_MAX_INFO 8
  64. /**
  65. * This structure describes dialog event status of an entity.
  66. */
  67. struct pjsip_dlg_event_status
  68. {
  69. unsigned info_cnt; /**< Number of info in the status */
  70. struct {
  71. pj_str_t dialog_info_state; /**< Dialog-Info state */
  72. pj_str_t dialog_info_entity; /**< Dialog-Info entity */
  73. pj_str_t dialog_call_id; /**< Dialog's call_id */
  74. pj_str_t dialog_remote_tag; /**< Dialog's remote-tag */
  75. pj_str_t dialog_local_tag; /**< Dialog's local-tag */
  76. pj_str_t dialog_direction; /**< Dialog's direction */
  77. pj_str_t dialog_id; /**< Dialog's id */
  78. pj_str_t dialog_state; /**< Dialog state */
  79. pj_str_t dialog_duration; /**< Dialog duration */
  80. pj_xml_node *dialog_node; /**< Pointer to tuple XML node of
  81. parsed dialog-info body received
  82. from remote agent. Only valid
  83. for client subscription. If the
  84. last received NOTIFY request
  85. does not contain any dialog-info
  86. body, this will be set to NULL*/
  87. pj_str_t local_identity;
  88. pj_str_t local_identity_display;
  89. pj_str_t local_target_uri;
  90. pj_str_t remote_identity;
  91. pj_str_t remote_identity_display;
  92. pj_str_t remote_target_uri;
  93. } info[PJSIP_DLG_EVENT_STATUS_MAX_INFO]; /**< Array of info. */
  94. };
  95. /**
  96. * @see pjsip_dlg_event_status
  97. */
  98. typedef struct pjsip_dlg_event_status pjsip_dlg_event_status;
  99. /**
  100. * Create dialog event client subscription session.
  101. *
  102. * @param dlg The underlying dialog to use.
  103. * @param user_cb Pointer to callbacks to receive dialog events.
  104. * @param options Option flags. Currently only PJSIP_EVSUB_NO_EVENT_ID
  105. * is recognized.
  106. * @param p_evsub Pointer to receive the dialog event subscription
  107. * session.
  108. *
  109. * @return PJ_SUCCESS on success.
  110. */
  111. PJ_DECL(pj_status_t)
  112. pjsip_dlg_event_create_uac(pjsip_dialog *dlg,
  113. const pjsip_evsub_user *user_cb,
  114. unsigned options,
  115. pjsip_evsub **p_evsub );
  116. /**
  117. * Forcefully destroy the dialog event subscription. This function should only
  118. * be called on special condition, such as when the subscription
  119. * initialization has failed. For other conditions, application MUST terminate
  120. * the subscription by sending the appropriate un(SUBSCRIBE) or NOTIFY.
  121. *
  122. * @param sub The dialog event subscription.
  123. * @param notify Specify whether the state notification callback
  124. * should be called.
  125. *
  126. * @return PJ_SUCCESS if subscription session has been destroyed.
  127. */
  128. PJ_DECL(pj_status_t) pjsip_dlg_event_terminate(pjsip_evsub *sub,
  129. pj_bool_t notify );
  130. /**
  131. * Call this function to create request to initiate dialog event subscription,
  132. * to refresh subcription, or to request subscription termination.
  133. *
  134. * @param sub Client subscription instance.
  135. * @param expires Subscription expiration. If the value is set to zero,
  136. * this will request unsubscription.
  137. * @param p_tdata Pointer to receive the request.
  138. *
  139. * @return PJ_SUCCESS on success.
  140. */
  141. PJ_DECL(pj_status_t) pjsip_dlg_event_initiate(pjsip_evsub *sub,
  142. pj_int32_t expires,
  143. pjsip_tx_data **p_tdata);
  144. /**
  145. * Add a list of headers to the subscription instance. The list of headers
  146. * will be added to outgoing dialog event subscription requests.
  147. *
  148. * @param sub Subscription instance.
  149. * @param hdr_list List of headers to be added.
  150. *
  151. * @return PJ_SUCCESS on success.
  152. */
  153. PJ_DECL(pj_status_t) pjsip_dlg_event_add_header(pjsip_evsub *sub,
  154. const pjsip_hdr *hdr_list);
  155. /**
  156. * Accept the incoming subscription request by sending 2xx response to
  157. * incoming SUBSCRIBE request.
  158. *
  159. * @param sub Server subscription instance.
  160. * @param rdata The incoming subscription request message.
  161. * @param st_code Status code, which MUST be final response.
  162. * @param hdr_list Optional list of headers to be added in the response.
  163. *
  164. * @return PJ_SUCCESS on success.
  165. */
  166. PJ_DECL(pj_status_t) pjsip_dlg_event_accept(pjsip_evsub *sub,
  167. pjsip_rx_data *rdata,
  168. int st_code,
  169. const pjsip_hdr *hdr_list );
  170. /**
  171. * Send request message. Application may also send request created with other
  172. * functions, e.g. authentication. But the request MUST be either request
  173. * that creates/refresh subscription or NOTIFY request.
  174. *
  175. * @param sub The subscription object.
  176. * @param tdata Request message to be sent.
  177. *
  178. * @return PJ_SUCCESS on success.
  179. */
  180. PJ_DECL(pj_status_t) pjsip_dlg_event_send_request(pjsip_evsub *sub,
  181. pjsip_tx_data *tdata);
  182. /**
  183. * Get the dialog event status. Client normally would call this function
  184. * after receiving NOTIFY request from server.
  185. *
  186. * @param sub The client or server subscription.
  187. * @param status The structure to receive dialog event status.
  188. *
  189. * @return PJ_SUCCESS on success.
  190. */
  191. PJ_DECL(pj_status_t)
  192. pjsip_dlg_event_get_status(pjsip_evsub *sub, pjsip_dlg_event_status *status);
  193. /**
  194. * This is a utility function to parse XML body into PJSIP dialog event status.
  195. *
  196. * @param rdata The incoming SIP message containing the XML body.
  197. * @param pool Pool to allocate memory to copy the strings into
  198. * the dialog event status structure.
  199. * @param status The dialog event status to be initialized.
  200. *
  201. * @return PJ_SUCCESS on success.
  202. *
  203. * @see pjsip_dlg_event_parse_dialog_info()
  204. */
  205. PJ_DECL(pj_status_t)
  206. pjsip_dlg_event_parse_dialog_info(pjsip_rx_data *rdata,
  207. pj_pool_t *pool,
  208. pjsip_dlg_event_status *dlg_status);
  209. /**
  210. * This is a utility function to parse XML body into PJSIP dialog event status.
  211. *
  212. * @param body Text body, with one extra space at the end to place
  213. * NULL character temporarily during parsing.
  214. * @param body_len Length of the body, not including the NULL termination
  215. * character.
  216. * @param pool Pool to allocate memory to copy the strings into
  217. * the dialog event status structure.
  218. * @param status The dialog event status to be initialized.
  219. *
  220. * @return PJ_SUCCESS on success.
  221. *
  222. * @see pjsip_dlg_event_parse_dialog_info2()
  223. */
  224. PJ_DECL(pj_status_t)
  225. pjsip_dlg_event_parse_dialog_info2(char *body, unsigned body_len,
  226. pj_pool_t *pool,
  227. pjsip_dlg_event_status *dlg_status);
  228. /**
  229. * @}
  230. */
  231. PJ_END_DECL
  232. #endif /* __PJSIP_SIMPLE_DLG_EVENT_H__ */