t_hooks.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #include "stdlib.h"
  28. #include "../../dprint.h"
  29. #include "../../error.h"
  30. #include "t_hooks.h"
  31. static struct tm_callback_s* callback_array[ TMCB_END ] = { 0, 0 } ;
  32. static int callback_id=0;
  33. /* register a callback function 'f' of type 'cbt'; will be called
  34. back whenever the event 'cbt' occurs in transaction module
  35. */
  36. int register_tmcb( tmcb_type cbt, transaction_cb f, void *param )
  37. {
  38. struct tm_callback_s *cbs;
  39. if (cbt<0 || cbt>=TMCB_END ) {
  40. LOG(L_ERR, "ERROR: register_tmcb: invalid callback type: %d\n",
  41. cbt );
  42. return E_BUG;
  43. }
  44. if (!(cbs=malloc( sizeof( struct tm_callback_s)))) {
  45. LOG(L_ERR, "ERROR: register_tmcb: out of mem\n");
  46. return E_OUT_OF_MEM;
  47. }
  48. callback_id++;
  49. cbs->id=callback_id;
  50. cbs->callback=f;
  51. cbs->next=callback_array[ cbt ];
  52. cbs->param=param;
  53. callback_array[ cbt ]=cbs;
  54. return callback_id;
  55. }
  56. void callback_event( tmcb_type cbt , struct cell *trans,
  57. struct sip_msg *msg, int code )
  58. {
  59. struct tm_callback_s *cbs;
  60. for (cbs=callback_array[ cbt ]; cbs; cbs=cbs->next) {
  61. DBG("DBG: callback type %d, id %d entered\n", cbt, cbs->id );
  62. cbs->callback( trans, msg, code, cbs->param );
  63. }
  64. }