Example #1
0
int pv_get_tm_reply_ruid(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	struct cell *t;
	int branch;

	if(msg==NULL || res==NULL)
		return -1;

	/* first get the transaction */
	if (_tmx_tmb.t_check( msg , 0 )==-1) return -1;
	if ( (t=_tmx_tmb.t_gett())==0) {
		/* no T */
		res->rs = _empty_str;
	} else {
		switch (get_route_type()) {
			case FAILURE_ROUTE:
			case BRANCH_FAILURE_ROUTE:
				/* use the reason of the winning reply */
				if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) {
					LM_CRIT("no picked branch (%d) for a final response"
							" in MODE_ONFAILURE\n", branch);
					return -1;
				}
				res->rs = t->uac[branch].ruid;
				break;
			default:
				LM_ERR("unsupported route_type %d\n", get_route_type());
				return -1;
		}
	}
	LM_DBG("reply ruid is [%.*s]\n", res->rs.len, res->rs.s);
	res->flags = PV_VAL_STR;
	return 0;
}
Example #2
0
int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	struct cell *t;
	int code;
	int branch;

	if(msg==NULL || res==NULL)
		return -1;

	/* first get the transaction */
	if (_tmx_tmb.t_check( msg , 0 )==-1) return -1;
	if ( (t=_tmx_tmb.t_gett())==0) {
		/* no T */
		code = 0;
	} else {
		switch (get_route_type()) {
			case REQUEST_ROUTE:
			case BRANCH_ROUTE:
				/* use the status of the last sent reply */
				code = t->uas.status;
				break;
			case CORE_ONREPLY_ROUTE:
				/*  t_check() above has the side effect of setting T and
					REFerencing T => we must unref and unset it for the 
					main/core onreply_route. */
				_tmx_tmb.t_unref(msg);
				/* no break */
			case TM_ONREPLY_ROUTE:
				/* use the status of the current reply */
				code = msg->first_line.u.reply.statuscode;
				break;
			case FAILURE_ROUTE:
			case BRANCH_FAILURE_ROUTE:
				/* use the status of the winning reply */
				if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) {
					LM_CRIT("no picked branch (%d) for a final response"
							" in MODE_ONFAILURE\n", branch);
					code = 0;
				} else {
					code = t->uac[branch].last_received;
				}
				break;
			default:
				LM_ERR("unsupported route_type %d\n", get_route_type());
				code = 0;
		}
	}

	LM_DBG("reply code is <%d>\n",code);

	res->rs.s = int2str( code, &res->rs.len);

	res->ri = code;
	res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
	return 0;
}
Example #3
0
int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	struct cell *t;
	int code;
	int branch;

	if(msg==NULL || res==NULL)
		return -1;

	switch (get_route_type()) {
		case CORE_ONREPLY_ROUTE:
		case TM_ONREPLY_ROUTE:
			/* use the status of the current reply */
			code = msg->first_line.u.reply.statuscode;
			goto done;
	}

	/* first get the transaction */
	if (_tmx_tmb.t_check( msg , 0 )==-1) return -1;
	if ( (t=_tmx_tmb.t_gett())==0) {
		/* no T */
		code = 0;
	} else {
		switch (get_route_type()) {
			case REQUEST_ROUTE:
			case BRANCH_ROUTE:
				/* use the status of the last sent reply */
				code = t->uas.status;
				break;
			case FAILURE_ROUTE:
			case BRANCH_FAILURE_ROUTE:
				/* use the status of the winning reply */
				if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) {
					LM_CRIT("no picked branch (%d) for a final response"
							" in MODE_ONFAILURE\n", branch);
					code = 0;
				} else {
					code = t->uac[branch].last_received;
				}
				break;
			default:
				LM_INFO("unsupported route_type %d - code set to 0\n",
						get_route_type());
				code = 0;
		}
	}

done:
	LM_DBG("reply code is <%d>\n", code);
	return pv_get_sintval(msg, param, res, code);

	return 0;
}
Example #4
0
int pv_get_t_branch(struct sip_msg *msg,  pv_param_t *param,
		pv_value_t *res)
{
	tm_ctx_t *tcx = 0;
	tm_cell_t *t;
	int branch;

	if ((msg == NULL) || (param == NULL)) return -1;

	t = _tmx_tmb.t_gett();
	if ((t == NULL) || (t == T_UNDEFINED)) {
		/* no T */
		return pv_get_null(msg, param, res);
	}

	switch(param->pvn.u.isname.name.n) {
		case 5: /* $T_branch(flags) */
			switch (get_route_type()) {
				case FAILURE_ROUTE:
				case BRANCH_FAILURE_ROUTE:
					/* use the reason of the winning reply */
					if ((branch=_tmx_tmb.t_get_picked_branch()) < 0) {
						LM_CRIT("no picked branch (%d) for a final response"
								" in MODE_ONFAILURE\n", branch);
						return pv_get_null(msg, param, res);
					}
					res->ri = t->uac[branch].branch_flags;
					res->flags = PV_VAL_INT;
					LM_DBG("branch flags is [%u]\n", res->ri);
					break;
				default:
					LM_ERR("unsupported route_type %d\n", get_route_type());
					return pv_get_null(msg, param, res);
			}
			break;
		case 6: /* $T_branch(uri) */
			if (get_route_type() != TM_ONREPLY_ROUTE) {
				LM_ERR("$T_branch(uri) - unsupported route_type %d\n",
						get_route_type());
				return pv_get_null(msg, param, res);
			}
			tcx = _tmx_tmb.tm_ctx_get();
			if(tcx == NULL) {
				return pv_get_null(msg, param, res);
			}
			branch = tcx->branch_index;
			if(branch<0 || branch>=t->nr_of_outgoings) {
				return pv_get_null(msg, param, res);
			}
			return pv_get_strval(msg, param, res, &t->uac[branch].uri);
	}
	return 0;
}
Example #5
0
int pv_get_tm_reply_reason(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	struct cell *t;
	struct sip_msg *reply;
	int branch;

	if(msg==NULL || res==NULL)
		return -1;

	/* first get the transaction */
	if (_tmx_tmb.t_check( msg , 0 )==-1) return -1;
	if ( (t=_tmx_tmb.t_gett())==0) {
		/* no T */
		return pv_get_strempty(msg, param, res);
	} else {
		switch (get_route_type()) {
			case CORE_ONREPLY_ROUTE:
				/*  t_check() above has the side effect of setting T and
					REFerencing T => we must unref and unset it for the
					main/core onreply_route. */
				_tmx_tmb.t_unref(msg);
				/* no break */
			case TM_ONREPLY_ROUTE:
				/* use the reason of the current reply */
				res->rs.s = msg->first_line.u.reply.reason.s;
				res->rs.len = msg->first_line.u.reply.reason.len;
				break;
			case FAILURE_ROUTE:
				/* use the reason of the winning reply */
				if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) {
					LM_CRIT("no picked branch (%d) for a final response"
							" in MODE_ONFAILURE\n", branch);
					return -1;
				}
				reply = t->uac[branch].reply;
				if (reply == FAKED_REPLY) {
					res->rs.s = error_text(t->uac[branch].last_received);
					res->rs.len = strlen(res->rs.s);
				} else {
					res->rs.s = reply->first_line.u.reply.reason.s;
					res->rs.len = reply->first_line.u.reply.reason.len;
				}
				break;
			default:
				LM_ERR("unsupported route_type %d\n", get_route_type());
				return -1;
		}
	}
	LM_DBG("reply reason is [%.*s]\n", res->rs.len, res->rs.s);
	res->flags = PV_VAL_STR;
	return 0;
}
Example #6
0
static void tcpops_tcp_closed_run_route(struct tcp_connection *con)
{
	int rt, backup_rt;
	struct run_act_ctx ctx;
	sip_msg_t *fmsg;
	LM_DBG("tcp_closed_run_route event_route[tcp:closed]\n");

	rt = route_get(&event_rt, "tcp:closed");
	if (rt < 0 || event_rt.rlist[rt] == NULL)
	{
		LM_DBG("route does not exist");
		return;
	}

	if (faked_msg_init() < 0)
	{
		LM_ERR("faked_msg_init() failed\n");
		return;
	}
	fmsg = faked_msg_next();
	fmsg->rcv = con->rcv;

	backup_rt = get_route_type();
	set_route_type(EVENT_ROUTE);
	init_run_actions_ctx(&ctx);
	run_top_route(event_rt.rlist[rt], fmsg, 0);
	set_route_type(backup_rt);
}
Example #7
0
int evapi_run_cfg_route(evapi_env_t *evenv, int rt)
{
	int backup_rt;
	struct run_act_ctx ctx;
	sip_msg_t *fmsg;
	sip_msg_t tmsg;

	if(evenv==0 || evenv->eset==0) {
		LM_ERR("evapi env not set\n");
		return -1;
	}

	if(rt<0)
		return 0;

	fmsg = faked_msg_next();
	memcpy(&tmsg, fmsg, sizeof(sip_msg_t));
	fmsg = &tmsg;
	evapi_set_msg_env(fmsg, evenv);
	backup_rt = get_route_type();
	set_route_type(EVENT_ROUTE);
	init_run_actions_ctx(&ctx);
	run_top_route(event_rt.rlist[rt], fmsg, 0);
	set_route_type(backup_rt);
	evapi_set_msg_env(fmsg, NULL);
	return 0;
}
Example #8
0
int nsq_consumer_fire_event(char *routename)
{
	struct sip_msg *fmsg;
	struct run_act_ctx ctx;
	int rtb, rt;

	LM_DBG("searching event_route[%s]\n", routename);
	rt = route_get(&event_rt, routename);
	if (rt < 0 || event_rt.rlist[rt] == NULL) {
		LM_DBG("route %s does not exist\n", routename);
		return -2;
	}
	LM_DBG("executing event_route[%s] (%d)\n", routename, rt);
	if (faked_msg_init()<0) {
		return -2;
	}
	fmsg = faked_msg_next();
	rtb = get_route_type();
	set_route_type(REQUEST_ROUTE);
	init_run_actions_ctx(&ctx);
	run_top_route(event_rt.rlist[rt], fmsg, 0);
	set_route_type(rtb);

	return 0;
}
Example #9
0
void ht_expired_run_event_route(char *route)
{
	int rt, backup_rt;
	sip_msg_t *fmsg;

	if (route == NULL)
	{
		LM_ERR("bad route\n");
	}

	LM_DBG("ht_expired_run_event_route event_route[%s]\n", route);

	rt = route_get(&event_rt, route);

	if (rt < 0 || event_rt.rlist[rt] == NULL)
	{
		LM_DBG("route does not exist");
		return;
	}

	if (faked_msg_init() < 0)
	{
		LM_ERR("faked_msg_init() failed\n");
		return;
	}
	fmsg = faked_msg_next();
	fmsg->parsed_orig_ruri_ok = 0;

	backup_rt = get_route_type();

	set_route_type(EVENT_ROUTE);
	run_top_route(event_rt.rlist[rt], fmsg, 0);

	set_route_type(backup_rt);
}
Example #10
0
void uac_req_run_event_route(sip_msg_t *msg, uac_send_info_t *tp, int rcode)
{
	char *evrtname = "uac:reply";
	int rt, backup_rt;
	struct run_act_ctx ctx;
	sip_msg_t *fmsg;

	rt = route_get(&event_rt, evrtname);
	if (rt < 0 || event_rt.rlist[rt] == NULL)
	{
		LM_DBG("event_route[uac:reply] does not exist\n");
		return;
	}

	uac_send_info_copy(tp, &_uac_req);
	_uac_req.evcode = rcode;
	if(msg==NULL)
	{
		_uac_req.evtype = 2;
		fmsg = faked_msg_get_next();
	} else {
		_uac_req.evtype = 1;
		fmsg = msg;
	}

	backup_rt = get_route_type();
	set_route_type(REQUEST_ROUTE);
	init_run_actions_ctx(&ctx);
	run_top_route(event_rt.rlist[rt], fmsg, 0);
	set_route_type(backup_rt);
}
Example #11
0
static void wsconn_run_route(ws_connection_t *wsc)
{
	int rt, backup_rt;
	struct run_act_ctx ctx;
	sip_msg_t *fmsg;

	LM_DBG("wsconn_run_route event_route[websocket:closed]\n");

	rt = route_get(&event_rt, "websocket:closed");
	if (rt < 0 || event_rt.rlist[rt] == NULL)
	{
		LM_DBG("route does not exist");
		return;
	}

	if (faked_msg_init() < 0)
	{
		LM_ERR("faked_msg_init() failed\n");
		return;
	}
	
	fmsg = faked_msg_next();
	wsc->rcv.proto_reserved1 = wsc->id;
	fmsg->rcv = wsc->rcv;

	backup_rt = get_route_type();
	set_route_type(REQUEST_ROUTE);
	init_run_actions_ctx(&ctx);
	run_top_route(event_rt.rlist[rt], fmsg, 0);
	set_route_type(backup_rt);
}
Example #12
0
/*!
 * \brief Cleanup a profile
 * \param msg SIP message
 * \param flags unused
 * \param param unused
 * \return 1
 */
int profile_cleanup( struct sip_msg *msg, unsigned int flags, void *param )
{
	dlg_cell_t *dlg;

	if(get_route_type()==LOCAL_ROUTE) {
		return 1;
	}

	current_dlg_msg_id = 0;
	current_dlg_msg_pid = 0;
	dlg = dlg_get_ctx_dialog();
	if (dlg!=NULL) {
		if(dlg->dflags & DLG_FLAG_TM) {
			dlg_unref(dlg, 1);
		} else {
			/* dialog didn't make it to tm */
			dlg_unref(dlg, 2);
		}
	}
	if (current_pending_linkers) {
		destroy_linkers(current_pending_linkers);
		current_pending_linkers = NULL;
	}

	/* need to return non-zero - 0 will break the exec of the request */
	return 1;
}
Example #13
0
void ht_expired_run_event_route(int routeid)
{
	int backup_rt;
	sip_msg_t *fmsg;

	if (routeid < 0 || event_rt.rlist[routeid] == NULL)
	{
		LM_DBG("route does not exist\n");
		return;
	}

	if (faked_msg_init() < 0)
	{
		LM_ERR("faked_msg_init() failed\n");
		return;
	}
	fmsg = faked_msg_next();
	fmsg->parsed_orig_ruri_ok = 0;

	backup_rt = get_route_type();

	set_route_type(EVENT_ROUTE);
	run_top_route(event_rt.rlist[routeid], fmsg, 0);

	set_route_type(backup_rt);
}
Example #14
0
static int fire_init_event(int rank)
{
	struct sip_msg *fmsg;
	struct run_act_ctx ctx;
	int rtb, rt;

	LM_DBG("rank is (%d)\n", rank);
	if (rank!=PROC_INIT)
		return 0;

	rt = route_get(&event_rt, "kazoo:mod-init");
	if(rt>=0 && event_rt.rlist[rt]!=NULL) {
		LM_DBG("executing event_route[kazoo:mod-init] (%d)\n", rt);
		if(faked_msg_init()<0)
			return -1;
		fmsg = faked_msg_next();
		rtb = get_route_type();
		set_route_type(REQUEST_ROUTE);
		init_run_actions_ctx(&ctx);
		run_top_route(event_rt.rlist[rt], fmsg, &ctx);
		if(ctx.run_flags&DROP_R_F)
		{
			LM_ERR("exit due to 'drop' in event route\n");
			return -1;
		}
		set_route_type(rtb);
	}

	return 0;
}
Example #15
0
void rpc_evr_run(rpc_t *rpc, void *c)
{
	str evr_name = STR_NULL;
	str evr_data = STR_NULL;
	int ret = 0;
	int evr_id = -1;
	sr_kemi_eng_t *keng = NULL;
	sip_msg_t *fmsg = NULL;
	int rtbk = 0;
	char evr_buf[2];

	ret = rpc->scan(c, "s*s", &evr_name.s, &evr_data.s);
	if(ret<1) {
		LM_ERR("failed getting the parameters");
		rpc->fault(c, 500, "Invalid parameters");
		return;
	}
	evr_name.len = strlen(evr_name.s);
	if(ret<2) {
		evr_buf[0] = '\0';
		evr_data.s = evr_buf;
		evr_data.len = 0;
	} else {
		evr_data.len = strlen(evr_data.s);
	}

	pv_evr_data = &evr_data;
	keng = sr_kemi_eng_get();
	if(keng==NULL) {
		evr_id = route_lookup(&event_rt, evr_name.s);
		if(evr_id == -1) {
			pv_evr_data = NULL;
			LM_ERR("event route not found: %.*s\n", evr_name.len, evr_name.s);
			rpc->fault(c, 500, "Event route not found");
			return;
		}
	} else {
		evr_id = -1;
	}

	fmsg = faked_msg_next();
	rtbk = get_route_type();
	set_route_type(LOCAL_ROUTE);

	if(evr_id>=0) {
		if(event_rt.rlist[evr_id]!=NULL) {
			run_top_route(event_rt.rlist[evr_id], fmsg, 0);
		} else {
			LM_WARN("empty event route block [%.*s]\n",
					evr_name.len, evr_name.s);
		}
	} else {
		if(sr_kemi_route(keng, fmsg, EVENT_ROUTE, &evr_name, &evr_data)<0) {
			LM_ERR("error running event route kemi callback\n");
		}
	}
	set_route_type(rtbk);
	pv_evr_data = NULL;
}
Example #16
0
int pv_get_tm_reply_ruid(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	struct cell *t;
	tm_ctx_t *tcx = 0;
	int branch;

	if(msg==NULL || res==NULL)
		return -1;

	/* first get the transaction */
	if (_tmx_tmb.t_check( msg , 0 )==-1) return -1;
	if ( (t=_tmx_tmb.t_gett())==0) {
		/* no T */
		return pv_get_strempty(msg, param, res);
	} else {
		switch (get_route_type()) {
			case FAILURE_ROUTE:
			case BRANCH_FAILURE_ROUTE:
				/* use the reason of the winning reply */
				if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) {
					LM_CRIT("no picked branch (%d) for a final response"
							" in MODE_ONFAILURE\n", branch);
					return pv_get_strempty(msg, param, res);
				}
				LM_DBG("reply ruid is [%.*s]\n", t->uac[branch].ruid.len, t->uac[branch].ruid.s);
				return pv_get_strval(msg, param, res, &t->uac[branch].ruid);
				break;
			case TM_ONREPLY_ROUTE:
				tcx = _tmx_tmb.tm_ctx_get();
				if(tcx == NULL) {
					return pv_get_strempty(msg, param, res);
				}
				branch = tcx->branch_index;
				if(branch<0 || branch>=t->nr_of_outgoings) {
					return pv_get_strempty(msg, param, res);
				}
				LM_DBG("reply ruid is [%.*s]\n", t->uac[branch].ruid.len, t->uac[branch].ruid.s);
				return pv_get_strval(msg, param, res, &t->uac[branch].ruid);
			default:
				LM_ERR("unsupported route_type %d\n", get_route_type());
				return pv_get_strempty(msg, param, res);
		}
	}
}
Example #17
0
int pv_get_tm_reply_last_received(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	struct cell *t;
	tm_ctx_t *tcx = 0;
	int code;

	if(msg==NULL || res==NULL)
		return -1;

	/* Only for TM reply route */
	if (get_route_type() != TM_ONREPLY_ROUTE) {
		LM_ERR("unsupported route_type %d\n", get_route_type());
		return -1;
	}

	/* first get the transaction */
	if (_tmx_tmb.t_check( msg , 0 )==-1) return -1;
	if ( (t=_tmx_tmb.t_gett())==0) {
		/* no T */
		LM_ERR("could not get transaction\n");
		return -1;
	}

	/* get the current branch index */
	tcx = _tmx_tmb.tm_ctx_get();
	if(tcx == NULL) {
		LM_ERR("could not get tm context\n");
		return -1;
	}

	/* get the last received reply code */
	code = t->uac[tcx->branch_index].last_received;

	LM_DBG("reply code is <%d>\n",code);

	res->rs.s = int2str( code, &res->rs.len);

	res->ri = code;
	res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
	return 0;
}
Example #18
0
int pv_get_t(struct sip_msg *msg,  pv_param_t *param,
		pv_value_t *res)
{
	tm_cell_t *t;

	if(msg==NULL || param==NULL)
		return -1;

	/* aliases to old TM pvs */
	switch(param->pvn.u.isname.name.n)
	{
		case 2:
			return pv_get_tm_reply_code(msg, param, res);
		case 4:
			return pv_get_tm_branch_idx(msg, param, res);
	}

	t = _tmx_tmb.t_gett();
	if(t==NULL || t==T_UNDEFINED) {
		/* no T */
		if(param->pvn.u.isname.name.n==8 || param->pvn.u.isname.name.n==9) {
			/* id_label_n or id_index_n - attempt to create transaction */
			if(_tmx_tmb.t_newtran(msg)<0) {
				LM_ERR("cannot create the transaction\n");
				return pv_get_null(msg, param, res);
			}
			t = _tmx_tmb.t_gett();
			if (t==NULL || t==T_UNDEFINED) {
				return pv_get_null(msg, param, res);
			}
		} else {
			return pv_get_null(msg, param, res);
		}
	}
	switch(param->pvn.u.isname.name.n)
	{
		case 1:
			return pv_get_uintval(msg, param, res, t->hash_index);
		case 3:
			if(get_route_type()==FAILURE_ROUTE) {
				if(_tmx_tmb.t_get_picked_branch()<0 )
					return pv_get_uintval(msg, param, res, 0);
				if(t->uac[_tmx_tmb.t_get_picked_branch()].reply==FAKED_REPLY)
					return pv_get_uintval(msg, param, res, 1);
			}
			return pv_get_uintval(msg, param, res, 0);
		case 8:
			return pv_get_uintval(msg, param, res, t->label);
		case 9:
			return pv_get_uintval(msg, param, res, t->hash_index);
		default:
			return pv_get_uintval(msg, param, res, t->label);
	}
}
Example #19
0
/**
 * Creates new "main" branch by making copy of branch-failure branch.
 * Currently the following branch attributes are included:
 * request-uri, ruid, path, instance, and branch flags.
 */
static int w_t_reuse_branch(sip_msg_t* msg, char *p1, char *p2)
{
	tm_cell_t *t;
	int branch;

	if (msg == NULL) return -1;

	/* first get the transaction */
	if (_tmx_tmb.t_check(msg, 0) == -1) return -1;
	if ((t = _tmx_tmb.t_gett()) == 0) {
		LM_ERR("no transaction\n");
		return -1;
	}
	switch (get_route_type()) {
		case BRANCH_FAILURE_ROUTE:
			/* use the reason of the winning reply */
			if ((branch = _tmx_tmb.t_get_picked_branch()) < 0) {
				LM_CRIT("no picked branch (%d) for a final response"
						" in MODE_ONFAILURE\n", branch);
				return -1;
			}
			if(rewrite_uri(msg, &(t->uac[branch].uri))<0) {
				LM_WARN("failed to rewrite the r-uri\n");
			}
			set_ruid(msg, &(t->uac[branch].ruid));
			if (t->uac[branch].path.len) {
				if(set_path_vector(msg, &(t->uac[branch].path))<0) {
					LM_WARN("failed to set the path vector\n");
				}
			} else {
				reset_path_vector(msg);
			}
			setbflagsval(0, t->uac[branch].branch_flags);
			set_instance(msg, &(t->uac[branch].instance));
			return 1;
		default:
			LM_ERR("unsupported route_type %d\n", get_route_type());
			return -1;
	}
}
Example #20
0
void ht_handle_expired_record(ht_t *ht, ht_cell_t *cell)
{
	int backup_rt;
	sip_msg_t *fmsg;
	sr_kemi_eng_t *keng = NULL;

	if(ht_event_callback.s==NULL || ht_event_callback.len<=0) {
		if (ht->evex_index < 0 || event_rt.rlist[ht->evex_index] == NULL) {
			LM_DBG("route does not exist\n");
			return;
		}
	} else {
		keng = sr_kemi_eng_get();
		if(keng==NULL) {
			LM_DBG("event callback (%s) set, but no cfg engine\n",
					ht_event_callback.s);
			return;
		}
	}

	LM_DBG("running event_route[htable:expired:%.*s]\n",
			ht->name.len, ht->name.s);

	if (faked_msg_init() < 0) {
		LM_ERR("faked_msg_init() failed\n");
		return;
	}

	ht_expired_cell = cell;

	fmsg = faked_msg_next();
	fmsg->parsed_orig_ruri_ok = 0;

	backup_rt = get_route_type();

	set_route_type(EVENT_ROUTE);
	if(ht->evex_index >= 0) {
		run_top_route(event_rt.rlist[ht->evex_index], fmsg, 0);
	} else {
		if(keng!=NULL) {
			if(keng->froute(fmsg, EVENT_ROUTE,
						&ht_event_callback, &ht->evex_name)<0) {
				LM_ERR("error running event route kemi callback\n");
			}
		}
	}

	set_route_type(backup_rt);

	ht_expired_cell = NULL;
}
Example #21
0
static void wsconn_run_route(ws_connection_t *wsc)
{
	int rt, backup_rt;
	struct run_act_ctx ctx;
	sip_msg_t *fmsg;
	sr_kemi_eng_t *keng = NULL;
	str evrtname = str_init("websocket:closed");

	LM_DBG("wsconn_run_route event_route[websocket:closed]\n");

	rt = route_lookup(&event_rt, evrtname.s);
	if (rt < 0 || event_rt.rlist[rt] == NULL)
	{
		if(ws_event_callback.len<=0 || ws_event_callback.s==NULL) {
			LM_DBG("event route does not exist");
			return;
		}
		keng = sr_kemi_eng_get();
		if(keng==NULL) {
			LM_DBG("event route callback engine does not exist");
			return;
		} else {
			rt = -1;
		}
	}

	if (faked_msg_init() < 0)
	{
		LM_ERR("faked_msg_init() failed\n");
		return;
	}

	fmsg = faked_msg_next();
	wsc->rcv.proto_reserved1 = wsc->id;
	fmsg->rcv = wsc->rcv;

	backup_rt = get_route_type();
	set_route_type(EVENT_ROUTE);
	init_run_actions_ctx(&ctx);
	if(rt<0) {
		/* kemi script event route callback */
		if(keng && keng->froute(fmsg, EVENT_ROUTE,
					&ws_event_callback, &evrtname)<0) {
			LM_ERR("error running event route kemi callback\n");
		}
	} else {
		/* native cfg event route */
		run_top_route(event_rt.rlist[rt], fmsg, 0);
	}
	set_route_type(backup_rt);
}
Example #22
0
static int msrp_frame_received(void *data)
{
	tcp_event_info_t *tev;
	static msrp_frame_t mf;
	sip_msg_t *fmsg;
	struct run_act_ctx ctx;
	int rtb, rt;


	tev = (tcp_event_info_t*)data;

	if(tev==NULL || tev->buf==NULL || tev->len<=0)
	{
		LM_DBG("invalid parameters\n");
		return -1;
	}

	memset(&mf, 0, sizeof(msrp_frame_t));
	mf.buf.s = tev->buf;
	mf.buf.len = tev->len;
	mf.tcpinfo = tev;
	if(msrp_parse_frame(&mf)<0)
	{
		LM_ERR("error parsing msrp frame\n");
		return -1;
	}
	msrp_reset_env();
	msrp_set_current_frame(&mf);
	rt = route_get(&event_rt, "msrp:frame-in");
	if(rt>=0 && event_rt.rlist[rt]!=NULL) {
		LM_DBG("executing event_route[msrp:frame-in] (%d)\n", rt);
		fmsg = msrp_fake_sipmsg(&mf);
		if(fmsg!=NULL)
			fmsg->rcv = *tev->rcv;
		rtb = get_route_type();
		set_route_type(REQUEST_ROUTE);
		init_run_actions_ctx(&ctx);
		run_top_route(event_rt.rlist[rt], fmsg, &ctx);
		if(ctx.run_flags&DROP_R_F)
		{
			LM_DBG("exit due to 'drop' in event route\n");
		}
		set_route_type(rtb);
		if(fmsg!=NULL)
			free_sip_msg(fmsg);
	}
	msrp_reset_env();
	msrp_destroy_frame(&mf);
	return 0;
}
Example #23
0
int pv_get_t_branch(struct sip_msg *msg,  pv_param_t *param,
		    pv_value_t *res)
{
    tm_cell_t *t;
    int branch;

    if ((msg == NULL) || (param == NULL)) return -1;

    t = _tmx_tmb.t_gett();
    if ((t == NULL) || (t == T_UNDEFINED)) {
	/* no T */
	return pv_get_null(msg, param, res);
    }

    switch(param->pvn.u.isname.name.n) {
    case 5:
	switch (get_route_type()) {
	case FAILURE_ROUTE:
	case BRANCH_FAILURE_ROUTE:
	    /* use the reason of the winning reply */
	    if ((branch=_tmx_tmb.t_get_picked_branch()) < 0) {
		LM_CRIT("no picked branch (%d) for a final response"
			" in MODE_ONFAILURE\n", branch);
		return -1;
	    }
	    res->ri = t->uac[branch].branch_flags;
	    res->flags = PV_VAL_INT;
	    LM_INFO("branch flags is [%u]\n", res->ri);
	    break;
	default:
	    LM_ERR("unsupported route_type %d\n", get_route_type());
	    return -1;
	}
    }
    return 0;
}
Example #24
0
/*! Run a request route block if it exists
 */
static int w_route_exists(struct sip_msg *msg, char *route)
{
	struct run_act_ctx ctx;
	int newroute, backup_rt, ret;

	newroute = route_lookup(&main_rt, route);
	if (newroute<0) {
		return -1;
	}
	backup_rt = get_route_type();
	set_route_type(REQUEST_ROUTE);
	init_run_actions_ctx(&ctx);
	ret = run_top_route(main_rt.rlist[newroute], msg, &ctx);
	set_route_type(backup_rt);
	return ret;
}
Example #25
0
static int child_init(int rank)
{
	struct sip_msg *fmsg;
	struct run_act_ctx ctx;
	int rtb, rt;
	int i;

	LM_DBG("rank is (%d)\n", rank);

	if(rank==PROC_MAIN) {
		if(ht_timer_procs>0) {
			for(i=0; i<ht_timer_procs; i++) {
				if(fork_sync_timer(PROC_TIMER, "HTable Timer", 1 /*socks flag*/,
						ht_timer, (void*)(long)i, ht_timer_interval)<0) {
					LM_ERR("failed to start timer routine as process\n");
					return -1; /* error */
				}
			}
		}
	}

	if (rank!=PROC_INIT)
		return 0;

	rt = route_get(&event_rt, "htable:mod-init");
	if(rt>=0 && event_rt.rlist[rt]!=NULL) {
		LM_DBG("executing event_route[htable:mod-init] (%d)\n", rt);
		if(faked_msg_init()<0)
			return -1;
		fmsg = faked_msg_next();
		rtb = get_route_type();
		set_route_type(REQUEST_ROUTE);
		init_run_actions_ctx(&ctx);
		run_top_route(event_rt.rlist[rt], fmsg, &ctx);
		if(ctx.run_flags&DROP_R_F)
		{
			LM_ERR("exit due to 'drop' in event route\n");
			return -1;
		}
		set_route_type(rtb);
	}

	return 0;
}
Example #26
0
/*!
 * \brief Execute event routes based on new state
 *
 */
void dlg_run_event_route(dlg_cell_t *dlg, sip_msg_t *msg, int ostate, int nstate)
{
	sip_msg_t *fmsg;
	int rt;
	int bkroute;

	if(dlg==NULL)
		return;
	if(ostate==nstate)
		return;

	rt = -1;
	if(nstate==DLG_STATE_CONFIRMED_NA) {
		rt = dlg_event_rt[DLG_EVENTRT_START];
	} else if(nstate==DLG_STATE_DELETED) {
		if(ostate==DLG_STATE_CONFIRMED || ostate==DLG_STATE_CONFIRMED_NA)
			rt = dlg_event_rt[DLG_EVENTRT_END];
		else if(ostate==DLG_STATE_UNCONFIRMED || ostate==DLG_STATE_EARLY)
			rt = dlg_event_rt[DLG_EVENTRT_FAILED];
	}

	if(rt==-1 || event_rt.rlist[rt]==NULL)
		return;

	if(msg==NULL)
		fmsg = faked_msg_next();
	else
		fmsg = msg;

	if (exec_pre_script_cb(fmsg, LOCAL_CB_TYPE)>0)
	{
		dlg_ref(dlg, 1);
		dlg_set_ctx_iuid(dlg);
		LM_DBG("executing event_route %d on state %d\n", rt, nstate);
		bkroute = get_route_type();
		set_route_type(LOCAL_ROUTE);
		run_top_route(event_rt.rlist[rt], fmsg, 0);
		dlg_reset_ctx_iuid();
		exec_post_script_cb(fmsg, LOCAL_CB_TYPE);
		dlg_unref(dlg, 1);
		set_route_type(bkroute);
	}
}
Example #27
0
int tls_run_event_routes(struct tcp_connection *c)
{
	int backup_rt;
	struct run_act_ctx ctx;
	sip_msg_t tmsg;

	if(_tls_evrt_connection_out<0)
		return 0;
	if(p_onsend==0 || p_onsend->msg==0)
		return 0;

	backup_rt = get_route_type();
	set_route_type(LOCAL_ROUTE);
	init_run_actions_ctx(&ctx);
	tls_set_pv_con(c);
	run_top_route(event_rt.rlist[_tls_evrt_connection_out], &tmsg, 0);
	tls_set_pv_con(0);
	set_route_type(backup_rt);
	return 0;
}
Example #28
0
/**
 * wrapper for record_route(msg, params)
 */
static int w_record_route(struct sip_msg *msg, char *key, char *bar)
{
	str s;

	if (msg->msg_flags & FL_RR_ADDED) {
		LM_ERR("Double attempt to record-route\n");
		return -1;
	}

	if (key && pv_printf_s(msg, (pv_elem_t*)key, &s)<0) {
		LM_ERR("failed to print the format\n");
		return -1;
	}
	if ( record_route( msg, key?&s:0 )<0 )
		return -1;

	if(get_route_type()!=BRANCH_ROUTE)
		msg->msg_flags |= FL_RR_ADDED;
	return 1;
}
Example #29
0
int pv_get_t(struct sip_msg *msg,  pv_param_t *param,
		pv_value_t *res)
{
	tm_cell_t *t;

	if(msg==NULL || param==NULL)
		return -1;

	/* aliases to old TM pvs */
	switch(param->pvn.u.isname.name.n)
	{
		case 2:
			return pv_get_tm_reply_code(msg, param, res);
		case 4:
			return pv_get_tm_branch_idx(msg, param, res);
	}

	t = _tmx_tmb.t_gett();
	if(t==NULL || t==T_UNDEFINED) {
		/* no T */
		return pv_get_null(msg, param, res);
	}
	switch(param->pvn.u.isname.name.n)
	{
		case 1:
			return pv_get_uintval(msg, param, res, t->hash_index);
		case 3:
			if(get_route_type()==FAILURE_ROUTE) {
				if(_tmx_tmb.t_get_picked_branch()<0 )
					return pv_get_uintval(msg, param, res, 0);
				if(t->uac[_tmx_tmb.t_get_picked_branch()].reply==FAKED_REPLY)
					return pv_get_uintval(msg, param, res, 1);
			}
			return pv_get_uintval(msg, param, res, 0);
		default:
			return pv_get_uintval(msg, param, res, t->label);
	}
}
Example #30
0
static void tcpops_tcp_closed_run_route(tcp_closed_event_info_t *tev)
{
	int rt, backup_rt;
	struct run_act_ctx ctx;
	sip_msg_t *fmsg;

	rt = tcp_closed_routes[tev->reason];
	if (rt == -1) return;

	if (faked_msg_init() < 0)
	{
		LM_ERR("faked_msg_init() failed\n");
		return;
	}
	fmsg = faked_msg_next();
	fmsg->rcv = tev->con->rcv;

	backup_rt = get_route_type();
	set_route_type(EVENT_ROUTE);
	init_run_actions_ctx(&ctx);
	run_top_route(event_rt.rlist[rt], fmsg, 0);
	set_route_type(backup_rt);
}