示例#1
0
/*!
 * \brief Do loose routing as per RFC3261
 * \param _m SIP message
 * \return -1 on failure, 1 on success
 */
int loose_route(struct sip_msg* _m)
{
    int ret;

    if (find_first_route(_m) != 0) {
        LM_DBG("There is no Route HF\n");
        return -1;
    }

    if (parse_sip_msg_uri(_m)<0) {
        LM_ERR("failed to parse Request URI\n");
        return -1;
    }

    ret = is_preloaded(_m);
    if (ret < 0) {
        return -1;
    } else if (ret == 1) {
        return after_loose(_m, 1);
    } else {
        if (is_myself(&_m->parsed_uri)) {
            return after_strict(_m);
        } else {
            return after_loose(_m, 0);
        }
    }
}
示例#2
0
文件: loose.c 项目: doome/opensips
/*
 * Do loose routing as defined in RFC3261
 */
int loose_route(struct sip_msg* _m)
{
	int ret;

	ctx_routing_set(0);

	if (find_first_route(_m) != 0) {
		LM_DBG("There is no Route HF\n");
		return -1;
	}

	if (parse_sip_msg_uri(_m)<0) {
		LM_ERR("failed to parse Request URI\n");
		return -1;
	}

	ret = is_preloaded(_m);
	if (ret < 0) {
		return -1;
	} else if (ret == 1) {
		return after_loose(_m, 1);
	} else {
#ifdef ENABLE_USER_CHECK
		if (is_myself(&_m->parsed_uri.user, &_m->parsed_uri.host,
		_m->parsed_uri.port_no) && !(_m->parsed_uri.gr.s && _m->parsed_uri.gr.len)) {
#else
		if (is_myself(&_m->parsed_uri.host, _m->parsed_uri.port_no) && !(_m->parsed_uri.gr.s && _m->parsed_uri.gr.len)) {
#endif
			return after_strict(_m);
		} else {
			return after_loose(_m, 0);
		}
	}
}


int get_route_params(struct sip_msg *msg, str *val)
{
	if(msg==NULL)
		return -1;

	/* check if params are present */
	if ( (val=ctx_rrparam_get())==NULL )
		return -1;

	return 0;
}


int check_route_param(struct sip_msg * msg, regex_t* re)
{
	regmatch_t pmatch;
	char bk;
	str params;
	str *rparams;

	/* check if params are present */
	if ( (rparams=ctx_rrparam_get())==NULL || rparams->len==0)
		return -1;

	/* include also the first ';' */
	for( params=*rparams ; params.s[0]!=';' ; params.s--,params.len++ );

	/* do the well-known trick to convert to null terminted */
	bk = params.s[params.len];
	params.s[params.len] = 0;
	LM_DBG("params are <%s>\n", params.s);
	if (regexec( re, params.s, 1, &pmatch, 0)!=0) {
		params.s[params.len] = bk;
		return -1;
	} else {
		params.s[params.len] = bk;
		return 0;
	}
}
示例#3
0
/*
 * Do loose routing as defined in RFC3261
 */
int loose_route(struct sip_msg* _m, char* _s1, char* _s2)
{
	int ret;

	removed_routes = 0;
	routing_type = 0;

	if (find_first_route(_m) != 0) {
		LM_DBG("There is no Route HF\n");
		return -1;
	}
		
	if (parse_sip_msg_uri(_m)<0) {
		LM_ERR("failed to parse Request URI\n");
		return -1;
	}

	ret = is_preloaded(_m);
	if (ret < 0) {
		return -1;
	} else if (ret == 1) {
		return after_loose(_m, 1);
	} else {
#ifdef ENABLE_USER_CHECK
		if (is_myself(&_m->parsed_uri.user, &_m->parsed_uri.host,
		_m->parsed_uri.port_no)) {
#else
		if (is_myself(&_m->parsed_uri.host, _m->parsed_uri.port_no)) {
#endif
			return after_strict(_m);
		} else {
			return after_loose(_m, 0);
		}
	}
}


int get_route_params(struct sip_msg *msg, str *val)
{
	if(msg==NULL)
		return -1;

	/* check if the hooked params belong to the same message */
	if (routed_msg_id != msg->id)
		return -1;

	val->s = routed_params.s;
	val->len = routed_params.len;

	return 0;
}


int check_route_param(struct sip_msg * msg, regex_t* re)
{
	regmatch_t pmatch;
	char bk;
	str params;

	/* check if the hooked params belong to the same message */
	if (routed_msg_id != msg->id)
		return -1;

	/* check if params are present */
	if ( !routed_params.s || !routed_params.len )
		return -1;

	/* include also the first ';' */
	for( params=routed_params ; params.s[0]!=';' ; params.s--,params.len++ );

	/* do the well-known trick to convert to null terminted */
	bk = params.s[params.len];
	params.s[params.len] = 0;
	LM_DBG("params are <%s>\n", params.s);
	if (regexec( re, params.s, 1, &pmatch, 0)!=0) {
		params.s[params.len] = bk;
		return -1;
	} else {
		params.s[params.len] = bk;
		return 0;
	}
}