• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

onsend.h

00001 /*
00002  *  $Id$
00003  *
00004  * Copyright (C) 2005 iptelorg GmbH
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 /*
00028  * History:
00029  * -------
00030  *  2005-12-11 created by andrei
00031  *  2009-06-01 Pre- and post-script callbacks of onsend route are executed (Miklos)
00032  */
00033 
00034 
00035 #ifndef onsend_h
00036 #define onsend_h
00037 
00038 
00039 #include "ip_addr.h"
00040 #include "action.h"
00041 #include "route.h"
00042 #include "script_cb.h"
00043 #include "sr_compat.h"
00044 
00045 struct onsend_info{
00046         union sockaddr_union* to;
00047         struct socket_info* send_sock;
00048         char* buf;
00049         int len;
00050 };
00051 
00052 extern struct onsend_info* p_onsend;
00053 
00054 
00055 #define get_onsend_info()       (p_onsend)
00056 
00057 /*
00058  * returns: 0 drop the message, >= ok, <0 error (but forward the message)
00059  * it also migh change dst->send_flags!
00060  * WARNING: buf must be 0 terminated (to allow regex matches on it) */
00061 static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
00062                                                                 char* buf, int len)
00063 {
00064         struct onsend_info onsnd_info;
00065         int ret;
00066         struct run_act_ctx ra_ctx;
00067         int backup_route_type;
00068         snd_flags_t fwd_snd_flags_bak;
00069         snd_flags_t rpl_snd_flags_bak;
00070         
00071         ret=1;
00072         if (onsend_rt.rlist[DEFAULT_RT]){
00073                 onsnd_info.to=&dst->to;
00074                 onsnd_info.send_sock=dst->send_sock;
00075                 onsnd_info.buf=buf;
00076                 onsnd_info.len=len;
00077                 p_onsend=&onsnd_info;
00078                 backup_route_type=get_route_type();
00079                 set_route_type(ONSEND_ROUTE);
00080                 if (exec_pre_script_cb(orig_msg, ONSEND_CB_TYPE)>0) {
00081                         /* backup orig_msg send flags */
00082                         fwd_snd_flags_bak=orig_msg->fwd_send_flags;
00083                         rpl_snd_flags_bak=orig_msg->rpl_send_flags;
00084                         orig_msg->fwd_send_flags=dst->send_flags; /* intial value */
00085                         init_run_actions_ctx(&ra_ctx);
00086                         ret=run_actions(&ra_ctx, onsend_rt.rlist[DEFAULT_RT], orig_msg);
00087                         /* update dst send_flags */
00088                         dst->send_flags=orig_msg->fwd_send_flags;
00089                         /* restore orig_msg flags */
00090                         orig_msg->fwd_send_flags=fwd_snd_flags_bak;
00091                         orig_msg->rpl_send_flags=rpl_snd_flags_bak;
00092                         exec_post_script_cb(orig_msg, ONSEND_CB_TYPE);
00093                         if((ret==0) && !(ra_ctx.run_flags&DROP_R_F)){
00094                                 ret = 1;
00095                         }
00096                 } else {
00097                         ret=0; /* drop the message */
00098                 }
00099                 set_route_type(backup_route_type);
00100                 p_onsend=0; /* reset it */
00101         }
00102         return ret;
00103 }
00104 
00105 
00106 #endif

Generated on Tue May 22 2012 13:10:12 for SIP Router by  doxygen 1.7.1