modules/tm/t_cancel.h
caf80ae6
 /*
  * $Id$
  *
7dd0b342
  *
84d8e165
  * Copyright (C) 2001-2003 FhG Fokus
7dd0b342
  *
  * This file is part of ser, a free SIP server.
  *
  * ser is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
  * For a license to use the ser software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info@iptel.org
  *
  * ser is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
c2ea965c
  *
  * History:
  * ---------
  *  2004-02-11  FIFO/CANCEL + alignments (hash=f(callid,cseq)) (uli+jiri)
65e998d1
  *  2006-10-10  should_cancel_branch() returns true even for branches with
  *               no response or with response <100 (andrei)
3357dbdf
  *  2007-06-04  should_cancel_branch() takes another parameter and it is safe
  *               to be called w/o REPLY_LOCK held (andrei)
caf80ae6
  */
 
7dd0b342
 
caf80ae6
 #ifndef _CANCEL_H
 #define _CANCEL_H
 
c2ea965c
 #include <stdio.h> /* just for FILE* for fifo_uac_cancel */
6cc8e8c1
 #include "../../rpc.h"
3357dbdf
 #include "../../atomic_ops.h"
ff979952
 #include "defs.h"
29daf809
 #include "h_table.h"
ff979952
 
 
caf80ae6
 /* a buffer is empty but cannot be used by anyone else;
    particularly, we use this value in the buffer pointer
    in local_buffer to tell "a process is already scheduled
    to generate a CANCEL, other processes are not supposed to"
    (which might happen if for example in a three-branch forking,
    two 200 would enter separate processes and compete for
84d8e165
    canceling the third branch); note that to really avoid
caf80ae6
    race conditions, the value must be set in REPLY_LOCK
 */
 
 #define BUSY_BUFFER ((char *)-1)
 
65e998d1
 /* flags for cancel_uacs(), cancel_branch() */
 #define F_CANCEL_B_KILL 1  /*  will completely stop the  branch (stops the
 							   timers), use only before a put_on_wait()
 							   or set_final_timer()*/
 #define F_CANCEL_B_FAKE_REPLY 2 /* will send a fake 487 to all branches that
 								 haven't received any response (>=100). It
 								 assumes the REPLY_LOCK is not held (if it is
 								 => deadlock) */
68d3acaf
 #define F_CANCEL_B_FORCE_C 4 /* will send a cancel even if no reply was 
 								received; F_CANCEL_B_FAKE_REPLY will be 
 								ignored */
 #define F_CANCEL_B_FORCE_RETR 8  /* will not stop request retr. on a branch
 									if no provisional response was received;
 									F_CANCEL_B_FORCE_C, F_CANCEL_B_FAKE_REPLY
 									and F_CANCE_B_KILL take precedence */
2b5e5254
 #define F_CANCEL_UNREF 16 /* unref the trans after canceling */
65e998d1
 
 
caf80ae6
 void which_cancel( struct cell *t, branch_bm_t *cancel_bm );
65e998d1
 int cancel_uacs( struct cell *t, branch_bm_t cancel_bm, int flags );
2b5e5254
 int cancel_all_uacs(struct cell *trans, int how);
65e998d1
 int cancel_branch( struct cell *t, int branch, int flags );
 
04436036
 typedef int(*cancel_uacs_f)( struct cell *t, branch_bm_t cancel_bm,
 								int flags );
2b5e5254
 typedef int (*cancel_all_uacs_f)(struct cell *trans, int how);
04436036
 
65e998d1
 
caf80ae6
 
3357dbdf
 /* 
  * Can be called w/o REPLY_LOCK held
65e998d1
  *  between this call and the call to cancel_uacs()/cancel_branch()
3357dbdf
  *  if noreply is set to 1 it will return true even if no reply was received
  *   (it will return false only if a final response or a cancel have already 
  *    been sent on the current branch).
  *  if noreply is set to 0 it will return true only if no cancel has already 
  *   been sent and a provisional (<200) reply >=100 was received.
65e998d1
  *  WARNING: has side effects: marks branches that should be canceled
  *   and a second call won't return them again */
3357dbdf
 inline short static should_cancel_branch( struct cell *t, int b, int noreply )
caf80ae6
 {
 	int last_received;
3357dbdf
 	unsigned long old;
caf80ae6
 
 	last_received=t->uac[b].last_received;
3357dbdf
 	/* if noreply=1 cancel even if no reply received (in this case 
 	 * cancel_branch()  won't actually send the cancel but it will do the 
 	 * cleanup) */
 	if (last_received<200 && (noreply || last_received>=100)){
 		old=atomic_cmpxchg_long((void*)&t->uac[b].local_cancel.buffer, 0,
 									(long)(BUSY_BUFFER));
 		return old==0;
 	}
 	return 0;
caf80ae6
 }
 
6cc8e8c1
 const char* rpc_cancel_doc[2];
 void rpc_cancel(rpc_t* rpc, void* c);
68d3acaf
 int cancel_b_flags_fixup(void* handle, str* name, void** val);
 int cancel_b_flags_get(unsigned int* f, int m);
caf80ae6
 
 #endif