t_cancel.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * $Id$
  3. *
  4. *
  5. * Copyright (C) 2001-2003 Fhg Fokus
  6. *
  7. * This file is part of ser, a free SIP server.
  8. *
  9. * ser is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * For a license to use the ser software under conditions
  15. * other than those described here, or to purchase support for this
  16. * software, please contact iptel.org by e-mail at the following addresses:
  17. * [email protected]
  18. *
  19. * ser is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. */
  28. #ifndef _CANCEL_H
  29. #define _CANCEL_H
  30. /* a buffer is empty but cannot be used by anyone else;
  31. particularly, we use this value in the buffer pointer
  32. in local_buffer to tell "a process is already scheduled
  33. to generate a CANCEL, other processes are not supposed to"
  34. (which might happen if for example in a three-branch forking,
  35. two 200 would enter separate processes and compete for
  36. cancelling the third branch); note that to really avoid
  37. race conditions, the value must be set in REPLY_LOCK
  38. */
  39. #define BUSY_BUFFER ((char *)-1)
  40. void which_cancel( struct cell *t, branch_bm_t *cancel_bm );
  41. void cancel_uacs( struct cell *t, branch_bm_t cancel_bm );
  42. void cancel_branch( struct cell *t, int branch );
  43. char *build_cancel(struct cell *Trans,unsigned int branch,
  44. unsigned int *len );
  45. inline short static should_cancel_branch( struct cell *t, int b )
  46. {
  47. int last_received;
  48. short should;
  49. last_received=t->uac[b].last_received;
  50. /* cancel only if provisional received and noone else
  51. attempted to cancel yet */
  52. should=last_received>=100 && last_received<200
  53. && t->uac[b].local_cancel.buffer==0;
  54. /* we'll cancel -- label it so that noone else
  55. (e.g. another 200 branch) will try to do the same */
  56. if (should) t->uac[b].local_cancel.buffer=BUSY_BUFFER;
  57. return should;
  58. }
  59. #endif