t_funcs.h

Go to the documentation of this file.
00001 /*
00002  * $Id: t_funcs.h 5101 2008-10-22 08:03:56Z juhe $
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  * History:
00023  * --------
00024  *  2003-02-18  updated various function prototypes (andrei)
00025  *  2003-03-10  removed ifdef _OBSO & made redefined all the *UNREF* macros
00026  *               in a non-gcc specific way (andrei)
00027  *  2003-03-13  now send_pr_buffer will be called w/ function/line info
00028  *               only when compiling w/ -DEXTRA_DEBUG (andrei)
00029  *  2003-03-31  200 for INVITE/UAS resent even for UDP (jiri) 
00030  *  2007-01-25  DNS failover at transaction level added (bogdan) 
00031  */
00032 
00033 /*! \file
00034  * \brief TM :: Transaction maintenance functions
00035  *
00036  * \ingroup tm
00037  * - Module: \ref tm
00038  */
00039 
00040 
00041 #ifndef _T_FUNCS_H
00042 #define _T_FUNCS_H
00043 
00044 #include <errno.h>
00045 #include <netdb.h>
00046 
00047 #include "../../mem/shm_mem.h"
00048 #include "../../parser/msg_parser.h"
00049 #include "../../globals.h"
00050 #include "../../udp_server.h"
00051 #include "../../msg_translator.h"
00052 #include "../../timer.h"
00053 #include "../../forward.h"
00054 #include "../../mem/mem.h"
00055 #include "../../md5utils.h"
00056 #include "../../ip_addr.h"
00057 #include "../../parser/parse_uri.h"
00058 #include "../../usr_avp.h"
00059 
00060 #include "config.h"
00061 #include "lock.h"
00062 #include "timer.h"
00063 #include "sip_msg.h"
00064 #include "h_table.h"
00065 #include "ut.h"
00066 
00067 struct s_table;
00068 struct timer;
00069 struct entry;
00070 struct cell;
00071 
00072 extern int noisy_ctimer;
00073 
00074 
00075 /* t_reply_to flags */
00076 #define TM_T_REPLY_repl_FLAG     (1<<0)
00077 #define TM_T_REPLY_no100_FLAG    (1<<1)
00078 #define TM_T_REPLY_noerr_FLAG    (1<<2)
00079 #define TM_T_REPLY_nodnsfo_FLAG  (1<<3)
00080 
00081 
00082 /* send a private buffer: utilize a retransmission structure
00083    but take a separate buffer not referred by it; healthy
00084    for reducing time spend in REPLIES locks
00085 */
00086 
00087 /* send a buffer -- 'PR' means private, i.e., it is assumed noone
00088    else can affect the buffer during sending time
00089 */
00090 #ifdef EXTRA_DEBUG
00091 int send_pr_buffer( struct retr_buf *rb,
00092    void *buf, int len, char* file, const char *function, int line );
00093 #define SEND_PR_BUFFER(_rb,_bf,_le ) \
00094    send_pr_buffer( (_rb), (_bf), (_le), __FILE__,  __FUNCTION__, __LINE__ )
00095 #else
00096 int send_pr_buffer( struct retr_buf *rb, void *buf, int len);
00097 #define SEND_PR_BUFFER(_rb,_bf,_le ) \
00098    send_pr_buffer( (_rb), (_bf), (_le))
00099 #endif
00100 
00101 #define SEND_BUFFER( _rb ) \
00102    SEND_PR_BUFFER( (_rb) , (_rb)->buffer.s , (_rb)->buffer.len )
00103 
00104 
00105 #define UNREF_UNSAFE(_T_cell) do { \
00106    ((_T_cell)->ref_count--);\
00107    LM_DBG("UNREF_UNSAFE: after is %d\n",(_T_cell)->ref_count);\
00108    }while(0)
00109 #define UNREF(_T_cell) do{ \
00110    LOCK_HASH( (_T_cell)->hash_index ); \
00111    UNREF_UNSAFE(_T_cell); \
00112    UNLOCK_HASH( (_T_cell)->hash_index ); }while(0)
00113 #define REF_UNSAFE(_T_cell) do {\
00114    ((_T_cell)->ref_count++);\
00115    LM_DBG("REF_UNSAFE: after is %d\n",(_T_cell)->ref_count);\
00116    }while(0)
00117 #define INIT_REF_UNSAFE(_T_cell) ((_T_cell)->ref_count=1)
00118 #define IS_REFFED_UNSAFE(_T_cell) ((_T_cell)->ref_count!=0)
00119 
00120 /*! \brief
00121  * Parse and fixup the fr_*_timer AVP specs
00122  */
00123 int init_avp_params(char *fr_timer_param, char *fr_inv_timer_param,
00124           char *contacts_avp_param);
00125 
00126 /*! \brief
00127  * FR_INV_TIMER AVP and SERIAL AVP variables needed by next_branches() function
00128  */
00129 extern int     fr_inv_timer_avp_type;
00130 extern int_str fr_inv_timer_avp;
00131 extern int     contacts_avp_type;
00132 extern int_str contacts_avp;
00133 
00134 /*! \brief
00135  * Get the FR_{INV}_TIMER from corresponding AVP
00136  */
00137 int fr_avp2timer( utime_t* timer);
00138 int fr_inv_avp2timer( utime_t* timer);
00139 
00140 
00141 inline static void _set_fr_retr( struct retr_buf *rb, int retr )
00142 {
00143    utime_t timer;
00144 
00145    if (retr) {
00146       rb->retr_list=RT_T1_TO_1;
00147       set_timer( &rb->retr_timer, RT_T1_TO_1, 0 );
00148    }
00149 
00150    if (!fr_avp2timer(&timer)) {
00151       LM_DBG("FR_TIMER = %llu\n", timer);
00152       set_timer(&rb->fr_timer, FR_TIMER_LIST, &timer);
00153    } else {
00154       set_timer(&rb->fr_timer, FR_TIMER_LIST, 0);
00155    }
00156 }
00157 
00158 
00159 inline static void start_retr(struct retr_buf *rb)
00160 {
00161    _set_fr_retr(rb, rb->dst.proto==PROTO_UDP);
00162 }
00163 
00164 
00165 inline static void force_retr(struct retr_buf *rb)
00166 {
00167    _set_fr_retr(rb, 1);
00168 }
00169 
00170 
00171 void tm_shutdown(void);
00172 
00173 
00174 /* function returns:
00175  *       1 - a new transaction was created
00176  *      -1 - error, including retransmission
00177  */
00178 int  t_add_transaction( struct sip_msg* p_msg  );
00179 
00180 
00181 /* returns 1 if everything was OK or -1 for error */
00182 int t_release_transaction( struct cell *trans );
00183 
00184 
00185 int get_ip_and_port_from_uri( str* uri , unsigned int *param_ip,
00186    unsigned int *param_port);
00187 
00188 
00189 void put_on_wait(  struct cell  *Trans  );
00190 
00191 
00192 void cleanup_localcancel_timers( struct cell *t );
00193 
00194 
00195 int t_relay_to( struct sip_msg  *p_msg, struct proxy_l *proxy, int replicate);
00196 
00197 
00198 #endif
00199 

Generated on Thu May 24 20:00:32 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6