예제 #1
0
/* !!! COPIED FROM MODULES/TM  !!
 * Calculate dialog hooks
 *
 * This is copied from modules/tm/dlg.c
 *
 * Maybe a reference to the original function in TM
 * could be reached via handlers or whatever...
 */
static inline int calculate_hooks(dlg_t* _d)
{
   str* uri;
   struct sip_uri puri;

   if (_d->route_set) {
      uri = &_d->route_set->nameaddr.uri;
      if (parse_uri(uri->s, uri->len, &puri) < 0) {
         LM_ERR( "Error while parsing URI\n");
         return -1;
      }

      if (puri.lr.s) {
         if (_d->rem_target.s) _d->hooks.request_uri = &_d->rem_target;
         else _d->hooks.request_uri = &_d->rem_uri;
	 _d->hooks.next_hop = &_d->route_set->nameaddr.uri;
	 _d->hooks.first_route = _d->route_set;
      } else {
         _d->hooks.request_uri = &_d->route_set->nameaddr.uri;
         _d->hooks.next_hop = _d->hooks.request_uri;
         _d->hooks.first_route = _d->route_set->next;
         _d->hooks.last_route = &_d->rem_target;
      }
   } else {
      if (_d->rem_target.s) _d->hooks.request_uri = &_d->rem_target;
      else _d->hooks.request_uri = &_d->rem_uri;
      _d->hooks.next_hop = _d->hooks.request_uri;
   }

   if ((_d->hooks.request_uri) && (_d->hooks.request_uri->s) && (_d->hooks.request_uri->len)) {
      _d->hooks.ru.s = _d->hooks.request_uri->s;
      _d->hooks.ru.len = _d->hooks.request_uri->len;
      _d->hooks.request_uri = &_d->hooks.ru;
      get_raw_uri(_d->hooks.request_uri);
   }
   if ((_d->hooks.next_hop) && (_d->hooks.next_hop->s) && (_d->hooks.next_hop->len)) {
      _d->hooks.nh.s = _d->hooks.next_hop->s;
      _d->hooks.nh.len = _d->hooks.next_hop->len;
      _d->hooks.next_hop = &_d->hooks.nh;
      get_raw_uri(_d->hooks.next_hop);
   }

   return 0;
}
예제 #2
0
파일: dlg.c 프로젝트: AndreyRybkin/kamailio
/*
 * Calculate dialog hooks
 * @return:
 *  negative : error
 *  0 : no routes present
 *  F_RB_NH_LOOSE : routes present, next hop is loose router
 *  F_RB_NH_STRICT: next hop is strict.
 */
static inline int calculate_hooks(dlg_t* _d)
{
	str* uri;
	struct sip_uri puri;
	int nhop;

	/* we might re-calc. some existing hooks =>
	 * reset all the hooks to 0 */
	memset(&_d->hooks, 0, sizeof(_d->hooks));
	if (_d->route_set) {
		uri = &_d->route_set->nameaddr.uri;
		if (parse_uri(uri->s, uri->len, &puri) < 0) {
			LOG(L_ERR, "calculate_hooks(): Error while parsing URI\n");
			return -1;
		}
		
		if (puri.lr.s) {
			if (_d->rem_target.s) _d->hooks.request_uri = &_d->rem_target;
			else _d->hooks.request_uri = &_d->rem_uri;
			_d->hooks.next_hop = &_d->route_set->nameaddr.uri;
			_d->hooks.first_route = _d->route_set;
			nhop = F_RB_NH_LOOSE;
		} else {
			_d->hooks.request_uri = &_d->route_set->nameaddr.uri;
			_d->hooks.next_hop = _d->hooks.request_uri;
			_d->hooks.first_route = _d->route_set->next;
			if (_d->rem_target.len > 0) 
				_d->hooks.last_route = &_d->rem_target;
			else 
				_d->hooks.last_route = NULL; /* ? */
			nhop = F_RB_NH_STRICT;
		}
	} else {
		if (_d->rem_target.s) _d->hooks.request_uri = &_d->rem_target;
		else _d->hooks.request_uri = &_d->rem_uri;
		
		if (_d->dst_uri.s) _d->hooks.next_hop = &_d->dst_uri;
		else _d->hooks.next_hop = _d->hooks.request_uri;

		nhop = 0;
		/*
		 * the routes in the hooks need to be reset because if the route_set 
		 * was dropped somewhere else then these will remain set without the
		 * actual routes existing any more
		 */
		_d->hooks.first_route = 0;
		_d->hooks.last_route = 0;
	}

	if ((_d->hooks.request_uri) && (_d->hooks.request_uri->s) && (_d->hooks.request_uri->len)) {
		_d->hooks.ru.s = _d->hooks.request_uri->s;
		_d->hooks.ru.len = _d->hooks.request_uri->len;
		_d->hooks.request_uri = &_d->hooks.ru;
		get_raw_uri(_d->hooks.request_uri);
	}
	if ((_d->hooks.next_hop) && (_d->hooks.next_hop->s) && (_d->hooks.next_hop->len)) {
		_d->hooks.nh.s = _d->hooks.next_hop->s;
		_d->hooks.nh.len = _d->hooks.next_hop->len;
		_d->hooks.next_hop = &_d->hooks.nh;
		get_raw_uri(_d->hooks.next_hop);
	}

	return nhop;
}
예제 #3
0
/*
 * Calculate dialog hooks
 */
static inline int calculate_hooks(dlg_t* _d)
{
	str* uri;
	struct sip_uri puri;
	param_hooks_t hooks;
	param_t* params;

	if (_d->route_set) {
		uri = &_d->route_set->nameaddr.uri;
		if (parse_uri(uri->s, uri->len, &puri) < 0) {
			LOG(L_ERR, "calculate_hooks(): Error while parsing URI\n");
			return -1;
		}

		if (parse_params(&puri.params, CLASS_URI, &hooks, &params) < 0) {
			LOG(L_ERR, "calculate_hooks(): Error while parsing parameters\n");
			return -2;
		}
		free_params(params);
		
		if (hooks.uri.lr) {
			if (_d->rem_target.s) _d->hooks.request_uri = &_d->rem_target;
			else _d->hooks.request_uri = &_d->rem_uri;
			_d->hooks.next_hop = &_d->route_set->nameaddr.uri;
			_d->hooks.first_route = _d->route_set;
		} else {
			_d->hooks.request_uri = &_d->route_set->nameaddr.uri;
			_d->hooks.next_hop = _d->hooks.request_uri;
			_d->hooks.first_route = _d->route_set->next;
			if (_d->rem_target.len > 0) 
				_d->hooks.last_route = &_d->rem_target;
			else 
				_d->hooks.last_route = NULL; /* ? */
		}
	} else {
		if (_d->rem_target.s) _d->hooks.request_uri = &_d->rem_target;
		else _d->hooks.request_uri = &_d->rem_uri;
		
		if (_d->dst_uri.s) _d->hooks.next_hop = &_d->dst_uri;
		else _d->hooks.next_hop = _d->hooks.request_uri;
		/* 
		 * the routes need to be reset because if the route_set was dropped by somebody else 
		 * then this will remain set without the actual routes 
		 */
		_d->hooks.first_route = 0;
		_d->hooks.last_route = 0;
	}

	if ((_d->hooks.request_uri) && (_d->hooks.request_uri->s) && (_d->hooks.request_uri->len)) {
		_d->hooks.ru.s = _d->hooks.request_uri->s;
		_d->hooks.ru.len = _d->hooks.request_uri->len;
		_d->hooks.request_uri = &_d->hooks.ru;
		get_raw_uri(_d->hooks.request_uri);
	}
	if ((_d->hooks.next_hop) && (_d->hooks.next_hop->s) && (_d->hooks.next_hop->len)) {
		_d->hooks.nh.s = _d->hooks.next_hop->s;
		_d->hooks.nh.len = _d->hooks.next_hop->len;
		_d->hooks.next_hop = &_d->hooks.nh;
		get_raw_uri(_d->hooks.next_hop);
	}

	return 0;
}