00001 /* 00002 * $Id: t_hooks.h 5748 2009-03-20 15:33:36Z osas $ 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-03-16 : backwards-compatibility callback names introduced (jiri) 00025 * 2003-03-06 : old callbacks renamed, new one introduced (jiri) 00026 * 2003-12-04 : global callbacks moved into transaction callbacks; 00027 * multiple events per callback added; single list per 00028 * transaction for all its callbacks (bogdan) 00029 * 2006-03-29 : added transaction callbacks: TMCB_REQUEST_BUILT and 00030 * TMCB_REQUEST_DELETED (bogdan) 00031 */ 00032 00033 /*! \file 00034 * \brief TM :: Callback hooks 00035 * 00036 * \ingroup tm 00037 * - Module: \ref tm 00038 * - \ref TMcallbacks 00039 */ 00040 00041 #ifndef _HOOKS_H 00042 #define _HOOKS_H 00043 00044 struct sip_msg; 00045 struct cell; 00046 00047 00048 #define TMCB_REQUEST_IN (1<<0) 00049 #define TMCB_RESPONSE_IN (1<<1) 00050 #define TMCB_E2EACK_IN (1<<2) 00051 #define TMCB_REQUEST_FWDED (1<<3) 00052 #define TMCB_RESPONSE_FWDED (1<<4) 00053 #define TMCB_ON_FAILURE_RO (1<<5) 00054 #define TMCB_ON_FAILURE (1<<6) 00055 #define TMCB_RESPONSE_PRE_OUT (1<<7) 00056 #define TMCB_RESPONSE_OUT (1<<8) 00057 #define TMCB_LOCAL_COMPLETED (1<<9) 00058 #define TMCB_LOCAL_RESPONSE_OUT (1<<10) 00059 #define TMCB_REQUEST_BUILT (1<<11) 00060 #define TMCB_TRANS_DELETED (1<<12) 00061 #define TMCB_MAX ((1<<13)-1) 00062 00063 /*! 00064 * \page TMcallbacks TM :: Callback hooks 00065 * 00066 * Caution: most of the callbacks work with shmem-ized messages 00067 * which you can no more change (e.g., lumps are fixed). Most 00068 * reply-processing callbacks are also called from a mutex, 00069 * which may cause deadlock if you are not careful. Also, reply 00070 * callbacks may pass the value of FAKED_REPLY messages, which 00071 * is a non-dereferencable pointer indicating that no message 00072 * was received and a timer hit instead. 00073 * 00074 * All callbacks excepting the TMCB_REQUEST_IN are associates to a 00075 * transaction. It means they will be run only when the event will hint 00076 * the transaction the callbacks were register for. 00077 * TMCB_REQUEST_IN is a global callback - it means it will be run for 00078 * all transactions. 00079 * 00080 * 00081 * \paragraph Callback description: 00082 * -------------------------------- 00083 * 00084 * TMCB_REQUEST_IN -- a brand-new request was received and is 00085 * about to establish transaction; it is not yet cloned and 00086 * lives in pkg mem -- your last chance to mangle it before 00087 * it gets shmem-ized (then, it's read-only); it's called from 00088 * HASH_LOCK, so be careful. It is guaranteed not to be 00089 * a retransmission. The transactional context is mostly 00090 * incomplete -- this callback is called in very early stage 00091 * before the message is shmem-ized (so that you can work 00092 * with it). 00093 * 00094 * TMCB_RESPONSE_IN -- a brand-new reply was received which matches 00095 * an existing transaction. It may or may not be a retransmission. 00096 * 00097 * TMCB_RESPONSE_PRE_OUT -- a final reply is about to be sent out 00098 * (either local or proxied); you cannnot change the reply, but 00099 * it is usefull to update your state before putting the reply on 00100 * the network and to avoid any races (receiving an ACK before 00101 * updating with the status of the reply) 00102 * 00103 * TMCB_RESPONSE_OUT -- a final reply was sent out (either local 00104 * or proxied) -- there is nothing more you can change from 00105 * the callback, it is good for accounting-like uses. 00106 * 00107 * \note: the message passed to callback may also have 00108 * value FAKED_REPLY (like other reply callbacks) which 00109 * indicates a pseudo_reply caused by a timer. Check for 00110 * this value before deferring -- you will cause a segfault 00111 * otherwise. Check for t->uas.request validity too if you 00112 * need it ... locally initiated UAC transactions set it to 0. 00113 * 00114 * TMCB_ON_FAILURE_RO -- called on receipt of a reply or timer; 00115 * it means all branches completed with a failure; the callback 00116 * function MUST not change anything in the transaction (READONLY) 00117 * that's a chance for doing ACC or stuff like this 00118 * 00119 * TMCB_ON_FAILURE -- called on receipt of a reply or timer; 00120 * it means all branches completed with a failure; that's 00121 * a chance for example to add new transaction branches 00122 * 00123 * TMCB_RESPONSE_FWDED -- called when a reply is about to be 00124 * forwarded; it is called after a message is received but before 00125 * a message is sent out: it is called when the decision is 00126 * made to forward a reply; it is parametrized by pkg message 00127 * which caused the transaction to complete (which is not 00128 * necessarily the same which will be forwarded). As forwarding 00129 * has not been executed and may fail, there is no guarantee 00130 * a reply will be successfully sent out at this point of time. 00131 * 00132 * \note: TMCB_REPLY_ON_FAILURE and TMCB_REPLY_FWDED are 00133 * called from reply mutex which is used to deterministically 00134 * process multiple replies received in parallel. A failure 00135 * to set the mutex again or stay too long in the callback 00136 * may result in deadlock. 00137 * 00138 * \note: the reply callbacks will not be evoked if "silent 00139 * C-timer hits". That's a feature to clean transactional 00140 * state from a proxy quickly -- transactions will then 00141 * complete statelessly. If you wish to disable this 00142 * feature, either set the global option "noisy_ctimer" 00143 * to 1, or set t->noisy_ctimer for selected transaction. 00144 * 00145 * TMCB_E2EACK_IN -- called when an ACK belonging to a proxied 00146 * INVITE transaction completed with 200 arrived. Note that 00147 * because it can be only dialog-wise matched, only the first 00148 * transaction occurrence will be matched with spirals. If 00149 * record-routing is not enabled, you will never receive the 00150 * ACK and the callback will never be triggered. 00151 * 00152 * 00153 * TMCB_REQUEST_FWDED -- request is being forwarded out. It is 00154 * called before a message is forwarded and it is your last 00155 * chance to change its shape. 00156 * 00157 * TMCB_LOCAL_COMPLETED -- final reply for localy initiated 00158 * transaction arrived. Message may be FAKED_REPLY. 00159 * 00160 * IMPORTANT NOTES: 00161 * 00162 * 1) that callbacks MUST be installed before forking 00163 * (callback lists do not live in shmem and have no access 00164 * protection), i.e., at best from mod_init functions. 00165 * 00166 * 2) the callback's param MUST be in shared memory and will 00167 * NOT be freed by TM; you must do it yourself from the 00168 * callback function if necessary. 00169 */ 00170 00171 00172 /*! \brief pack structure with all params passed to callback function */ 00173 struct tmcb_params { 00174 struct sip_msg* req; 00175 struct sip_msg* rpl; 00176 int code; 00177 void **param; 00178 void *extra1; 00179 void *extra2; 00180 }; 00181 00182 /*! \brief callback function prototype */ 00183 typedef void (transaction_cb) (struct cell* t, int type, struct tmcb_params*); 00184 /*! \brief function to release the callback param */ 00185 typedef void (release_tmcb_param) (void *param); 00186 /*! \brief register callback function prototype */ 00187 typedef int (*register_tmcb_f)(struct sip_msg* p_msg, struct cell *t, 00188 int cb_types, transaction_cb f, void *param, release_tmcb_param func); 00189 00190 00191 struct tm_callback { 00192 int id; /*!< id of this callback - useless */ 00193 int types; /*!< types of events that trigger the callback*/ 00194 transaction_cb* callback; /*!< callback function */ 00195 void *param; /*!< param to be passed to callback function */ 00196 release_tmcb_param *release; /*!< function to release the callback param when the callback is deleted */ 00197 struct tm_callback* next; 00198 }; 00199 00200 struct tmcb_head_list { 00201 struct tm_callback *first; 00202 int reg_types; 00203 }; 00204 00205 00206 extern struct tmcb_head_list* req_in_tmcb_hl; 00207 00208 extern struct tmcb_head_list tmcb_pending_hl; 00209 extern unsigned int tmcb_pending_id; 00210 00211 #define has_tran_tmcbs(_T_, _types_) \ 00212 ( ((_T_)->tmcb_hl.reg_types)&(_types_) ) 00213 #define has_reqin_tmcbs() \ 00214 ( req_in_tmcb_hl->first!=0 ) 00215 00216 void empty_tmcb_list(struct tmcb_head_list *head); 00217 00218 int init_tmcb_lists(void); 00219 00220 void destroy_tmcb_lists(void); 00221 00222 00223 /*! 00224 * \brief Register a callback function for several types of events 00225 * 00226 * Register a callback function 'f' for 'types' mask of events. This 00227 * will be called back whenever one of the events occurs in transaction module 00228 * (global or per transaction, depending of event type). 00229 * \param p_msg SIP message 00230 * \param t transaction 00231 * \param types 00232 * \param f callback 00233 * \param param callback parameter 00234 * \param release_func release function for callback parameter 00235 * \return negative result on error, the return code from insert_tmcb on success 00236 */ 00237 int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types, transaction_cb f, void *param, release_tmcb_param release_func ); 00238 00239 /*! 00240 * \brief Inserts a callback into the a callback list 00241 * \param cb_list callback list 00242 * \param types callback type 00243 * \param f transaction callback 00244 * \param param callback parameter 00245 * \param release_func release function for callback parameter 00246 */ 00247 int insert_tmcb(struct tmcb_head_list *cb_list, int types, transaction_cb f, void *param, release_tmcb_param release_func ); 00248 00249 /*! 00250 * \brief Set extra parameter for tm callback 00251 */ 00252 void set_extra_tmcb_params(void *extra1, void *extra2); 00253 00254 /*! 00255 * \brief Run all transaction callbacks for an event type 00256 * \param type callback type 00257 * \param trans transaction 00258 * \param req SIP request 00259 * \param rpl SIP reply 00260 * \param code callback code 00261 */ 00262 void run_trans_callbacks( int type , struct cell *trans, struct sip_msg *req, struct sip_msg *rpl, int code ); 00263 00264 /*! \brief run all REQUEST_IN callbacks */ 00265 void run_reqin_callbacks( struct cell *trans, struct sip_msg *req, int code ); 00266 00267 #endif
1.5.6