everything: shotgun attempt to put PROTO_WS and PROTO_WSS across core and in modules...
[sip-router] / onsend.h
1 /*
2  *  $Id$
3  *
4  * Copyright (C) 2005 iptelorg GmbH
5  *
6  * This file is part of ser, a free SIP server.
7  *
8  * ser is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  * For a license to use the ser software under conditions
14  * other than those described here, or to purchase support for this
15  * software, please contact iptel.org by e-mail at the following addresses:
16  *    info@iptel.org
17  *
18  * ser is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License 
24  * along with this program; if not, write to the Free Software 
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  */
27 /*
28  * History:
29  * -------
30  *  2005-12-11 created by andrei
31  *  2009-06-01 Pre- and post-script callbacks of onsend route are executed (Miklos)
32  */
33
34
35 #ifndef onsend_h
36 #define onsend_h
37
38
39 #include "ip_addr.h"
40 #include "action.h"
41 #include "route.h"
42 #include "script_cb.h"
43 #include "sr_compat.h"
44
45 struct onsend_info{
46         union sockaddr_union* to;
47         struct socket_info* send_sock;
48         char* buf;
49         int len;
50 };
51
52 extern struct onsend_info* p_onsend;
53
54
55 #define get_onsend_info()       (p_onsend)
56
57 /*
58  * returns: 0 drop the message, >= ok, <0 error (but forward the message)
59  * it also migh change dst->send_flags!
60  * WARNING: buf must be 0 terminated (to allow regex matches on it) */
61 static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
62                                                                 char* buf, int len)
63 {
64         struct onsend_info onsnd_info;
65         int ret;
66         struct run_act_ctx ra_ctx;
67         int backup_route_type;
68         snd_flags_t fwd_snd_flags_bak;
69         snd_flags_t rpl_snd_flags_bak;
70         
71         ret=1;
72         if (onsend_rt.rlist[DEFAULT_RT]){
73                 onsnd_info.to=&dst->to;
74                 onsnd_info.send_sock=dst->send_sock;
75                 onsnd_info.buf=buf;
76                 onsnd_info.len=len;
77                 p_onsend=&onsnd_info;
78                 backup_route_type=get_route_type();
79                 set_route_type(ONSEND_ROUTE);
80                 if (exec_pre_script_cb(orig_msg, ONSEND_CB_TYPE)>0) {
81                         /* backup orig_msg send flags */
82                         fwd_snd_flags_bak=orig_msg->fwd_send_flags;
83                         rpl_snd_flags_bak=orig_msg->rpl_send_flags;
84                         orig_msg->fwd_send_flags=dst->send_flags; /* intial value */
85                         init_run_actions_ctx(&ra_ctx);
86                         ret=run_actions(&ra_ctx, onsend_rt.rlist[DEFAULT_RT], orig_msg);
87                         /* update dst send_flags */
88                         dst->send_flags=orig_msg->fwd_send_flags;
89                         /* restore orig_msg flags */
90                         orig_msg->fwd_send_flags=fwd_snd_flags_bak;
91                         orig_msg->rpl_send_flags=rpl_snd_flags_bak;
92                         exec_post_script_cb(orig_msg, ONSEND_CB_TYPE);
93                         if((ret==0) && !(ra_ctx.run_flags&DROP_R_F)){
94                                 ret = 1;
95                         }
96                 } else {
97                         ret=0; /* drop the message */
98                 }
99                 set_route_type(backup_route_type);
100                 p_onsend=0; /* reset it */
101         }
102         return ret;
103 }
104
105
106 #endif