2
0

dlg_cb.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2006 Voice Sistem SRLs
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * Kamailio is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * Kamailio is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * History:
  23. * --------
  24. * 2006-04-11 initial version (bogdan)
  25. * 2008-04-04 added direction reporting in dlg callbacks (bogdan)
  26. * 2008-04-14 added new type of callback to be triggered when dialogs are
  27. * loaded from DB (bogdan)
  28. * 2008-04-17 added new type of callback to be triggered right before the
  29. * dialog is destroyed (deleted from memory) (bogdan)
  30. */
  31. #ifndef _DIALOG_DLG_CB_H_
  32. #define _DIALOG_DLG_CB_H_
  33. #include "../../parser/msg_parser.h"
  34. struct dlg_cell;
  35. struct dlg_cb_params {
  36. struct sip_msg* req; /* sip request msg related to the callback event */
  37. struct sip_msg* rpl; /* sip reply msg related to the callback event */
  38. unsigned int direction; /* direction of the sip msg */
  39. void *dlg_data; /* generic paramter, specific to callback */
  40. void **param; /* parameter passed at callback registration*/
  41. };
  42. /* callback function prototype */
  43. typedef void (dialog_cb) (struct dlg_cell* dlg, int type,
  44. struct dlg_cb_params * params);
  45. /* function to free the callback param */
  46. typedef void (param_free_cb) (void *param);
  47. /* register callback function prototype */
  48. typedef int (*register_dlgcb_f)(struct dlg_cell* dlg, int cb_types,
  49. dialog_cb f, void *param, param_free_cb ff);
  50. typedef int (*register_dlgcb_nodlg_f)(str *callid, str *ftag, str *ttag, int cb_types,
  51. dialog_cb f, void *param, param_free_cb ff);
  52. /* method to set a variable within a dialog */
  53. //typedef int (*set_dlg_variable_f)( struct dlg_cell* dlg,
  54. // str* key,
  55. // str* val);
  56. typedef int (*set_dlg_variable_f)( str* callid, str* ftag, str* ttag,
  57. str* key,
  58. str* val);
  59. /* method to get a variable from a dialog */
  60. //typedef str* (*get_dlg_variable_f)( struct dlg_cell* dlg,
  61. // str* key);
  62. typedef str* (*get_dlg_variable_f)( str *callid, str *ftag, str *ttag,
  63. str* key);
  64. typedef struct dlg_cell* (*get_current_dlg_f)( struct sip_msg* msg);
  65. #define DLGCB_LOADED (1<<0)
  66. #define DLGCB_CREATED (1<<1)
  67. #define DLGCB_FAILED (1<<2)
  68. #define DLGCB_CONFIRMED_NA (1<<3)
  69. #define DLGCB_CONFIRMED (1<<4)
  70. #define DLGCB_REQ_WITHIN (1<<5)
  71. #define DLGCB_TERMINATED (1<<6)
  72. #define DLGCB_EXPIRED (1<<7)
  73. #define DLGCB_EARLY (1<<8)
  74. #define DLGCB_RESPONSE_FWDED (1<<9)
  75. #define DLGCB_RESPONSE_WITHIN (1<<10)
  76. #define DLGCB_MI_CONTEXT (1<<11)
  77. #define DLGCB_RPC_CONTEXT (1<<12)
  78. #define DLGCB_DESTROY (1<<13)
  79. #define DLGCB_SPIRALED (1<<14)
  80. #define DLGCB_TERMINATED_CONFIRMED (1<<14)
  81. struct dlg_callback {
  82. int types;
  83. dialog_cb* callback;
  84. void *param;
  85. param_free_cb* callback_param_free;
  86. struct dlg_callback* next;
  87. };
  88. struct dlg_head_cbl {
  89. struct dlg_callback *first;
  90. int types;
  91. };
  92. void destroy_dlg_callbacks(unsigned int type);
  93. void destroy_dlg_callbacks_list(struct dlg_callback *cb);
  94. int register_dlgcb_nodlg(str *callid, str *ftag, str *ttag, int types, dialog_cb f, void *param, param_free_cb ff );
  95. int register_dlgcb( struct dlg_cell* dlg, int types, dialog_cb f, void *param, param_free_cb ff);
  96. void run_create_callbacks(struct dlg_cell *dlg, struct sip_msg *msg);
  97. void run_dlg_callbacks( int type ,
  98. struct dlg_cell *dlg,
  99. struct sip_msg *req,
  100. struct sip_msg *rpl,
  101. unsigned int dir,
  102. void *dlg_data);
  103. void run_load_callbacks( void );
  104. /*!
  105. * \brief Function that returns valid SIP message from given dialog callback parameter struct
  106. * \param cb_params dialog callback parameter struct
  107. * \return pointer to valid SIP message if existent, NULL otherwise
  108. */
  109. static inline struct sip_msg *dlg_get_valid_msg(struct dlg_cb_params *cb_params)
  110. {
  111. struct sip_msg *msg;
  112. if (cb_params == NULL) {
  113. LM_ERR("no dialog parameters given\n");
  114. return NULL;
  115. }
  116. msg = cb_params->req;
  117. if (msg == NULL) {
  118. msg = cb_params->rpl;
  119. if (msg == NULL || msg == FAKED_REPLY) {
  120. return NULL;
  121. }
  122. }
  123. return msg;
  124. };
  125. #endif