Class: OverSIP::SIP::ClientTransaction

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/oversip/sip/client_transaction.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

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

Constructor Details

#initialize(core, request, transaction_conf, transport, ip = nil, ip_type = nil, port = nil) ⇒ ClientTransaction

In case transport is a String, it’s an Outbound flow token.



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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/oversip/sip/client_transaction.rb', line 18

def initialize core, request, transaction_conf, transport, ip=nil, ip_type=nil, port=nil
  @core = core
  @request = request
  @transaction_conf = transaction_conf || {}
  @transaction_id = ::SecureRandom.hex(4) << @request.antiloop_id

  # A client transaction for using an existing Outbound connection.
  if transport.is_a? ::String
    @connection, @ip, @port = ::OverSIP::SIP::TransportManager.get_outbound_connection transport
    if @connection
      @server_klass = @connection.class
      @transport = @server_klass.transport
    end

  # A client transaction based on procedures of RFC 3263. The connection could exist (so reuse it)
  # or not (so try to create it).
  else
    @transport = transport
    @ip = ip
    @ip_type = ip_type
    @port = port

    @server_klass = case @transport
      when :udp
        case @ip_type
          when :ipv4 ; ::OverSIP::SIP::IPv4UdpServer
          when :ipv6 ; ::OverSIP::SIP::IPv6UdpServer
        end
      when :tcp
        case @ip_type
          when :ipv4 ; ::OverSIP::SIP::IPv4TcpServer
          when :ipv6 ; ::OverSIP::SIP::IPv6TcpServer
        end
      when :tls
        case @ip_type
          when :ipv4 ; ::OverSIP::SIP::IPv4TlsServer
          when :ipv6 ; ::OverSIP::SIP::IPv6TlsServer
        end
      end

    @connection = ::OverSIP::SIP::TransportManager.get_connection @server_klass, @ip, @port, self, transaction_conf[:callback_on_server_tls_handshake]
  end

  # Ensure the request has Content-Length. Add it otherwise.
  # NOTE: Don't do this for UAcRequest instances!
  if @request.is_a? ::OverSIP::SIP::Request
    if @request.body
      @request.headers["Content-Length"] = [ @request.body.bytesize.to_s ]
    else
      @request.headers["Content-Length"] = HDR_ARRAY_CONTENT_LENGTH_0
    end
  end

end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



15
16
17
# File 'lib/oversip/sip/client_transaction.rb', line 15

def connection
  @connection
end

#coreObject (readonly)

Returns the value of attribute core.



15
16
17
# File 'lib/oversip/sip/client_transaction.rb', line 15

def core
  @core
end

#requestObject (readonly)

Returns the value of attribute request.



15
16
17
# File 'lib/oversip/sip/client_transaction.rb', line 15

def request
  @request
end

#stateObject (readonly)

Returns the value of attribute state.



15
16
17
# File 'lib/oversip/sip/client_transaction.rb', line 15

def state
  @state
end

Class Method Details

.get_class(request) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/oversip/sip/client_transaction.rb', line 7

def self.get_class request
  case request.sip_method
  when :INVITE  ; ::OverSIP::SIP::InviteClientTransaction
  when :ACK     ; ::OverSIP::SIP::Ack2xxForwarder
  else          ; ::OverSIP::SIP::NonInviteClientTransaction
  end
end