Class: OverSIP::SIP::Uac

Inherits:
Client
  • Object
show all
Defined in:
lib/oversip/sip/uac.rb

Instance Attribute Summary

Attributes inherited from Client

#current_target

Instance Method Summary collapse

Methods inherited from Client

#abort_routing, #add_target_to_blacklist, #client_timeout, #connection_failed, #initialize, #invite_timeout, #on_canceled, #on_error, #on_failure_response, #on_invite_timeout, #on_provisional_response, #on_success_response, #on_target, #tls_validation_failed

Methods included from Logger

close, fg_system_msg2str, init_logger_mq, load_methods, #log_id, syslog_system_msg2str, syslog_user_msg2str

Constructor Details

This class inherits a constructor from OverSIP::SIP::Client

Instance Method Details

#receive_response(response) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/oversip/sip/uac.rb', line 55

def receive_response response
  log_system_debug "received response #{response.status_code}"  if $oversip_debug

  if response.status_code < 200
    @on_provisional_response_block && @on_provisional_response_block.call(response)
  elsif response.status_code >= 200 && response.status_code <= 299
    @on_success_response_block && @on_success_response_block.call(response)
  elsif response.status_code >= 300
    if response.status_code == 503
      if @conf[:dns_failover_on_503]
        try_next_target nil, nil, response
        return
      else
        @on_failure_response_block && @on_failure_response_block.call(response)
      end
    else
      @on_failure_response_block && @on_failure_response_block.call(response)
    end
  end
end

#route(request, dst_host = nil, dst_port = nil, dst_transport = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/oversip/sip/uac.rb', line 6

def route request, dst_host=nil, dst_port=nil, dst_transport=nil
  unless (@request = request).is_a? ::OverSIP::SIP::UacRequest or @request.is_a? ::OverSIP::SIP::Request
    raise ::OverSIP::RuntimeError, "request must be a OverSIP::SIP::UacRequest or OverSIP::SIP::Request instance"
  end

  # The destination of the request is taken from:
  # - dst_xxx fields if given.
  # - The request.ruri if it is an OverSIP::SIP::Uri or OverSIP::SIP::NameAddr.
  # Otherwise raise an exception.
  unless dst_host or request.ruri.is_a?(::OverSIP::SIP::Uri) or request.ruri.is_a?(::OverSIP::SIP::NameAddr)
    raise ::OverSIP::RuntimeError, "if dst_host is not given then request.ruri must be an OverSIP::SIP::Uri or OverSIP::SIP::NameAddr instance"
  end

  @log_id = "UAC (proxy #{@conf[:name]})"

  # Force the destination.
  if dst_host
    dst_scheme = :sip
    dst_host_type = ::OverSIP::Utils.ip_type(dst_host) || :domain

  # Or use the Request URI.
  else
    dst_scheme = request.ruri.scheme
    dst_host = request.ruri.host
    dst_host_type = request.ruri.host_type
    dst_port = request.ruri.port
    dst_transport = request.ruri.transport_param
  end

  # If the destination uri_host is an IPv6 reference, convert it to real IPv6.
  if dst_host_type == :ipv6_reference
    dst_host = ::OverSIP::Utils.normalize_ipv6(dst_host, true)
    dst_host_type = :ipv6
  end

  # Loockup in the DNS cache of this proxy.
  result = check_dns_cache dst_scheme, dst_host, dst_host_type, dst_port, dst_transport

  case result
  when true
    return
  else  # It can be String or nil, so use it as dns_cache_key param.
    # Perform RFC 3263 procedures.
    do_dns result, @request.via_branch_id, dst_scheme, dst_host, dst_host_type, dst_port, dst_transport
  end

end