script_cb.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser 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. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. *
  27. * History:
  28. * --------
  29. * 2005-02-13 script callbacks devided into request and reply types (bogdan)
  30. * 2009-06-01 Added pre- and post-script callback support for all types
  31. * of route blocks. (Miklos)
  32. */
  33. #ifndef _SCRIPT_CB_H_
  34. #define _SCRIPT_CB_H_
  35. #include "parser/msg_parser.h"
  36. typedef int (cb_function)(struct sip_msg *msg, unsigned int flags, void *param);
  37. #define PRE_SCRIPT_CB (1<<30)
  38. #define POST_SCRIPT_CB (1<<31)
  39. /* Pre- and post-script callback flags. Use these flags to register
  40. * for the callbacks, and to check the type of the callback from the
  41. * functions.
  42. * (Power of 2 so more callbacks can be registered at once.)
  43. */
  44. enum script_cb_flag { REQUEST_CB=1, FAILURE_CB=2, ONREPLY_CB=4,
  45. BRANCH_CB=8, ONSEND_CB=16, ERROR_CB=32,
  46. LOCAL_CB=64, EVENT_CB=128, BRANCH_FAILURE_CB=256 };
  47. /* Callback types used for executing the callbacks.
  48. * Keep in sync with script_cb_flag!!!
  49. */
  50. enum script_cb_type { REQUEST_CB_TYPE=1, FAILURE_CB_TYPE, ONREPLY_CB_TYPE,
  51. BRANCH_CB_TYPE, ONSEND_CB_TYPE, ERROR_CB_TYPE,
  52. LOCAL_CB_TYPE, EVENT_CB_TYPE, BRANCH_FAILURE_CB_TYPE, MAX_CB_TYPE };
  53. struct script_cb{
  54. cb_function *cbf;
  55. struct script_cb *next;
  56. void *param;
  57. };
  58. /* Register pre- or post-script callbacks.
  59. * Returns -1 on error, 0 on success
  60. */
  61. int register_script_cb( cb_function f, unsigned int flags, void *param );
  62. int init_script_cb(void);
  63. void destroy_script_cb(void);
  64. /* Execute pre-script callbacks of a given type.
  65. * Returns 0 on error, 1 on success
  66. */
  67. int exec_pre_script_cb( struct sip_msg *msg, enum script_cb_type type);
  68. /* Execute post-script callbacks of a given type.
  69. * Always returns 1, success.
  70. */
  71. int exec_post_script_cb( struct sip_msg *msg, enum script_cb_type type);
  72. #endif