59a64520 |
/*
* Copyright (C) 2005 iptelorg GmbH
*
|
2266bb9c |
* This file is part of Kamailio, a free SIP server.
|
59a64520 |
*
|
2266bb9c |
* Kamailio is free software; you can redistribute it and/or modify
|
59a64520 |
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
|
2266bb9c |
* Kamailio is distributed in the hope that it will be useful,
|
59a64520 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
|
c1cb68f6 |
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
|
9e1ff448 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
59a64520 |
*/
|
2266bb9c |
/*!
* \file
* \brief Kamailio core :: IP address handling
* \author andrei
* \ingroup core
* Module: \ref core
|
59a64520 |
*/
#ifndef onsend_h
#define onsend_h
#include "ip_addr.h"
#include "action.h"
#include "route.h"
|
6d3d94ba |
#include "script_cb.h"
|
5d34bdcd |
#include "sr_compat.h"
|
c1cb68f6 |
#include "kemi.h"
|
59a64520 |
struct onsend_info{
|
80f241b0 |
union sockaddr_union* to; /* dest info */
struct socket_info* send_sock; /* local send socket */
char* buf; /* outgoing buffer */
int len; /* outgoing buffer len */
sip_msg_t *msg; /* original sip msg struct */
|
59a64520 |
};
extern struct onsend_info* p_onsend;
#define get_onsend_info() (p_onsend)
/*
* returns: 0 drop the message, >= ok, <0 error (but forward the message)
|
8ed91651 |
* it also migh change dst->send_flags!
|
59a64520 |
* WARNING: buf must be 0 terminated (to allow regex matches on it) */
|
e6a2b12e |
static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
char* buf, int len)
|
59a64520 |
{
|
80f241b0 |
struct onsend_info onsnd_info = {0};
|
59a64520 |
int ret;
|
20fded1f |
struct run_act_ctx ra_ctx;
|
c1cb68f6 |
struct run_act_ctx *bctx;
|
593513f8 |
int backup_route_type;
|
8ed91651 |
snd_flags_t fwd_snd_flags_bak;
snd_flags_t rpl_snd_flags_bak;
|
c1cb68f6 |
sr_kemi_eng_t *keng = NULL;
|
6a690d16 |
ret=1;
if (onsend_rt.rlist[DEFAULT_RT]){
onsnd_info.to=&dst->to;
onsnd_info.send_sock=dst->send_sock;
onsnd_info.buf=buf;
onsnd_info.len=len;
|
80f241b0 |
onsnd_info.msg=orig_msg;
|
6a690d16 |
p_onsend=&onsnd_info;
|
593513f8 |
backup_route_type=get_route_type();
|
6a690d16 |
set_route_type(ONSEND_ROUTE);
if (exec_pre_script_cb(orig_msg, ONSEND_CB_TYPE)>0) {
|
8ed91651 |
/* backup orig_msg send flags */
fwd_snd_flags_bak=orig_msg->fwd_send_flags;
rpl_snd_flags_bak=orig_msg->rpl_send_flags;
orig_msg->fwd_send_flags=dst->send_flags; /* intial value */
|
6d3d94ba |
init_run_actions_ctx(&ra_ctx);
|
c1cb68f6 |
keng = sr_kemi_eng_get();
if(unlikely(keng!=NULL)) {
bctx = sr_kemi_act_ctx_get();
sr_kemi_act_ctx_set(&ra_ctx);
ret=keng->froute(orig_msg, ONSEND_ROUTE, NULL);
sr_kemi_act_ctx_set(bctx);
} else {
ret=run_actions(&ra_ctx, onsend_rt.rlist[DEFAULT_RT], orig_msg);
}
|
8ed91651 |
/* update dst send_flags */
dst->send_flags=orig_msg->fwd_send_flags;
/* restore orig_msg flags */
orig_msg->fwd_send_flags=fwd_snd_flags_bak;
orig_msg->rpl_send_flags=rpl_snd_flags_bak;
|
6a690d16 |
exec_post_script_cb(orig_msg, ONSEND_CB_TYPE);
|
be55b963 |
if((ret==0) && !(ra_ctx.run_flags&DROP_R_F)){
|
5d34bdcd |
ret = 1;
}
|
6a690d16 |
} else {
ret=0; /* drop the message */
|
6d3d94ba |
}
|
593513f8 |
set_route_type(backup_route_type);
|
6a690d16 |
p_onsend=0; /* reset it */
|
59a64520 |
}
return ret;
}
|
214b161e |
#define onsend_route_enabled(rtype) (onsend_rt.rlist[DEFAULT_RT]?((rtype==SIP_REPLY)?onsend_route_reply:1):0)
|
59a64520 |
#endif
|