t_funcs.h

00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of ser, a free SIP server.
00007  *
00008  * ser 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  * For a license to use the ser software under conditions
00014  * other than those described here, or to purchase support for this
00015  * software, please contact iptel.org by e-mail at the following addresses:
00016  *    info@iptel.org
00017  *
00018  * ser is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License 
00024  * along with this program; if not, write to the Free Software 
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  */
00027  /* History:
00028   * --------
00029   *  2003-02-18  updated various function prototypes (andrei)
00030   *  2003-03-10  removed ifdef _OBSO & made redefined all the *UNREF* macros
00031   *               in a non-gcc specific way (andrei)
00032   *  2003-03-13  now send_pr_buffer will be called w/ function/line info
00033   *               only when compiling w/ -DEXTRA_DEBUG (andrei)
00034   *  2003-03-31  200 for INVITE/UAS resent even for UDP (jiri) 
00035   *  2005-11-09  added stop_rb_timers, updated to the new timer interface 
00036   *               (andrei)
00037   */
00038 
00039 
00040 
00041 #ifndef _T_FUNCS_H
00042 #define _T_FUNCS_H
00043 
00044 #include "defs.h"
00045 
00046 
00047 #include <errno.h>
00048 #include <netdb.h>
00049 
00050 #include "../../mem/shm_mem.h"
00051 #include "../../parser/msg_parser.h"
00052 #include "../../globals.h"
00053 #include "../../udp_server.h"
00054 #include "../../msg_translator.h"
00055 #include "../../timer.h"
00056 #include "../../forward.h"
00057 #include "../../mem/mem.h"
00058 #include "../../md5utils.h"
00059 #include "../../ip_addr.h"
00060 #include "../../parser/parse_uri.h"
00061 #include "../../usr_avp.h"
00062 #include "../../atomic_ops.h"
00063 
00064 #include "config.h"
00065 #include "lock.h"
00066 #include "timer.h"
00067 #include "sip_msg.h"
00068 #include "h_table.h"
00069 #include "ut.h"
00070 
00071 struct s_table;
00072 struct timer;
00073 struct entry;
00074 struct cell;
00075 
00076 extern int tm_error; /* delayed tm error */
00077 extern struct msgid_var user_cell_set_flags;
00078 extern struct msgid_var user_cell_reset_flags;
00079 
00080 extern int fr_inv_timer_avp_type;
00081 extern int_str fr_inv_timer_avp;
00082 extern int contacts_avp_type;
00083 extern int_str contacts_avp;
00084 
00085 /* default names for timer's AVPs  */
00086 #define FR_TIMER_AVP      "callee_fr_timer"
00087 #define FR_INV_TIMER_AVP  "callee_fr_inv_timer"
00088 
00089 
00090 /* send a private buffer: utilize a retransmission structure
00091    but take a separate buffer not referred by it; healthy
00092    for reducing time spend in REPLIES locks
00093 */
00094 
00095 
00096 /* send a buffer -- 'PR' means private, i.e., it is assumed noone
00097    else can affect the buffer during sending time
00098 */
00099 #ifdef EXTRA_DEBUG
00100 int send_pr_buffer( struct retr_buf *rb,
00101         void *buf, int len, char* file, const char *function, int line );
00102 #define SEND_PR_BUFFER(_rb,_bf,_le ) \
00103         send_pr_buffer( (_rb), (_bf), (_le), __FILE__,  __FUNCTION__, __LINE__ )
00104 #else
00105 int send_pr_buffer( struct retr_buf *rb, void *buf, int len);
00106 #define SEND_PR_BUFFER(_rb,_bf,_le ) \
00107         send_pr_buffer( (_rb), (_bf), (_le))
00108 #endif
00109 
00110 #define SEND_BUFFER( _rb ) \
00111         SEND_PR_BUFFER( (_rb) , (_rb)->buffer , (_rb)->buffer_len )
00112 
00113 
00114 
00115 #ifdef TM_DEL_UNREF
00116 
00117 #define UNREF_FREE(_T_cell) \
00118         do{\
00119                 if (atomic_dec_and_test(&(_T_cell)->ref_count)){ \
00120                         unlink_timers((_T_cell)); \
00121                         free_cell((_T_cell)); \
00122                 }else \
00123                         t_stats_delayed_free(); \
00124         }while(0)
00125 
00126 #define UNREF_NOSTATS(_T_cell) \
00127         do{\
00128                 if (atomic_dec_and_test(&(_T_cell)->ref_count)){ \
00129                         unlink_timers((_T_cell)); \
00130                         free_cell((_T_cell)); \
00131                 }\
00132         }while(0)
00133 
00134 #define UNREF_UNSAFE(_T_cell) UNREF_NOSTATS(_T_cell)
00135 /* all the version are safe when using atomic ops */
00136 #define UNREF(_T_cell) UNREF_UNSAFE(_T_cell); 
00137 #define REF(_T_cell) (atomic_inc(&(_T_cell)->ref_count))
00138 #define REF_UNSAFE(_T_cell)  REF(_T_cell)
00139 #define INIT_REF(_T_cell, v) atomic_set(&(_T_cell)->ref_count, v)
00140 
00141 #else
00142 
00143 #define UNREF_UNSAFE(_T_cell) ((_T_cell)->ref_count--)
00144 #define UNREF(_T_cell) do{ \
00145         LOCK_HASH( (_T_cell)->hash_index ); \
00146         UNREF_UNSAFE(_T_cell); \
00147         UNLOCK_HASH( (_T_cell)->hash_index ); }while(0)
00148 #define REF_UNSAFE(_T_cell) ((_T_cell)->ref_count++)
00149 #define INIT_REF_UNSAFE(_T_cell) ((_T_cell)->ref_count=1)
00150 #define IS_REFFED_UNSAFE(_T_cell) ((_T_cell)->ref_count!=0)
00151 
00152 #endif
00153 /*
00154  * Parse and fixup the fr_*_timer AVP specs
00155  */
00156 int init_avp_params(char *fr_timer_param, char *fr_inv_timer_param,
00157                                         char *contacts_avp_param);
00158 
00159 
00160 typedef void (*unref_cell_f)(struct cell *t);
00161 void unref_cell(struct cell *t);
00162 /*
00163  * Get the FR_{INV}_TIMER from corresponding AVP
00164  */
00165 int fr_avp2timer(unsigned int* timer);
00166 int fr_inv_avp2timer(unsigned int* timer);
00167 
00168 
00169 #ifdef TIMER_DEBUG
00170 #define start_retr(rb) \
00171         _set_fr_retr((rb), \
00172                                 ((rb)->dst.proto==PROTO_UDP) ? RT_T1_TIMEOUT_MS(rb) : \
00173                                                                                                 (unsigned)(-1), \
00174                                 __FILE__, __FUNCTION__, __LINE__)
00175 
00176 #define force_retr(rb) \
00177         _set_fr_retr((rb), RT_T1_TIMEOUT_MS(rb), __FILE__, __FUNCTION__, __LINE__)
00178 
00179 #else
00180 #define start_retr(rb) \
00181         _set_fr_retr((rb), \
00182                                 ((rb)->dst.proto==PROTO_UDP) ? RT_T1_TIMEOUT_MS(rb) : \
00183                                                                                                 (unsigned)(-1))
00184 
00185 #define force_retr(rb) \
00186         _set_fr_retr((rb), RT_T1_TIMEOUT_MS(rb))
00187 
00188 #endif
00189 
00190 
00191 
00192 
00193 void tm_shutdown(void);
00194 
00195 
00196 /* function returns:
00197  *       1 - a new transaction was created
00198  *      -1 - error, including retransmission
00199  */
00200 int  t_add_transaction( struct sip_msg* p_msg  );
00201 
00202 
00203 /* returns 1 if everything was OK or -1 for error */
00204 int t_release_transaction( struct cell *trans );
00205 
00206 
00207 int get_ip_and_port_from_uri( str* uri , unsigned int *param_ip,
00208         unsigned int *param_port);
00209 
00210 
00211 void put_on_wait(  struct cell  *Trans  );
00212 
00213 
00214 int t_relay_to( struct sip_msg  *p_msg ,
00215         struct proxy_l *proxy, int proto, int replicate ) ;
00216 
00217 int kill_transaction( struct cell *trans, int error );
00218 int kill_transaction_unsafe( struct cell *trans, int error );
00219 #endif
00220