oversip 1.1.0.beta5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/etc/oversip.conf +16 -4
  2. data/etc/proxies.conf +8 -9
  3. data/etc/server.rb +59 -0
  4. data/ext/sip_parser/sip_parser.c +12066 -11975
  5. data/ext/sip_parser/sip_parser.h +1 -0
  6. data/ext/sip_parser/sip_parser_ruby.c +15 -4
  7. data/ext/utils/haproxy_protocol.c +4 -1
  8. data/ext/websocket_framing_utils/ws_framing_utils_ruby.c +2 -2
  9. data/lib/oversip/config.rb +50 -38
  10. data/lib/oversip/default_server.rb +12 -0
  11. data/lib/oversip/launcher.rb +10 -35
  12. data/lib/oversip/master_process.rb +2 -2
  13. data/lib/oversip/proxies_config.rb +2 -2
  14. data/lib/oversip/sip/client_transaction.rb +1 -7
  15. data/lib/oversip/sip/grammar/uri.rb +23 -1
  16. data/lib/oversip/sip/listeners/{reactor.rb → connection.rb} +16 -2
  17. data/lib/oversip/sip/listeners/ipv4_udp_server.rb +1 -1
  18. data/lib/oversip/sip/listeners/ipv6_udp_server.rb +1 -1
  19. data/lib/oversip/sip/listeners/tcp_client.rb +2 -3
  20. data/lib/oversip/sip/listeners/{tcp_reactor.rb → tcp_connection.rb} +14 -2
  21. data/lib/oversip/sip/listeners/tcp_server.rb +2 -5
  22. data/lib/oversip/sip/listeners/tls_client.rb +15 -12
  23. data/lib/oversip/sip/listeners/tls_server.rb +11 -11
  24. data/lib/oversip/sip/listeners/{tls_tunnel_reactor.rb → tls_tunnel_connection.rb} +20 -20
  25. data/lib/oversip/sip/listeners/tls_tunnel_server.rb +2 -5
  26. data/lib/oversip/sip/listeners/{udp_reactor.rb → udp_connection.rb} +4 -4
  27. data/lib/oversip/sip/listeners.rb +6 -10
  28. data/lib/oversip/sip/message.rb +4 -3
  29. data/lib/oversip/sip/message_processor.rb +17 -17
  30. data/lib/oversip/sip/modules/core.rb +18 -13
  31. data/lib/oversip/sip/modules/user_assertion.rb +7 -53
  32. data/lib/oversip/sip/proxy.rb +3 -3
  33. data/lib/oversip/sip/request.rb +2 -0
  34. data/lib/oversip/sip/rfc3263.rb +3 -3
  35. data/lib/oversip/sip/sip.rb +6 -0
  36. data/lib/oversip/sip/transport_manager.rb +8 -8
  37. data/lib/oversip/tls.rb +18 -22
  38. data/lib/oversip/version.rb +1 -1
  39. data/lib/oversip/websocket/constants.rb +0 -1
  40. data/lib/oversip/websocket/http_request.rb +4 -8
  41. data/lib/oversip/websocket/launcher.rb +83 -139
  42. data/lib/oversip/websocket/listeners/connection.rb +47 -0
  43. data/lib/oversip/websocket/{ws_apps/ipv4_ws_sip_app.rb → listeners/ipv4_ws_server.rb} +3 -3
  44. data/lib/oversip/websocket/{ws_apps/ipv4_wss_sip_app.rb → listeners/ipv4_wss_server.rb} +2 -2
  45. data/lib/oversip/websocket/listeners/ipv4_wss_tunnel_server.rb +21 -0
  46. data/lib/oversip/websocket/{ws_apps/ipv6_ws_sip_app.rb → listeners/ipv6_ws_server.rb} +3 -3
  47. data/lib/oversip/websocket/{ws_apps/ipv6_wss_sip_app.rb → listeners/ipv6_wss_server.rb} +2 -3
  48. data/lib/oversip/websocket/listeners/ipv6_wss_tunnel_server.rb +21 -0
  49. data/lib/oversip/websocket/listeners/{tcp_server.rb → ws_server.rb} +63 -43
  50. data/lib/oversip/websocket/listeners/{tls_server.rb → wss_server.rb} +14 -13
  51. data/lib/oversip/websocket/listeners/{tls_tunnel_server.rb → wss_tunnel_server.rb} +36 -10
  52. data/lib/oversip/websocket/listeners.rb +10 -9
  53. data/lib/oversip/websocket/websocket.rb +13 -0
  54. data/lib/oversip/websocket/ws_framing.rb +35 -97
  55. data/lib/oversip/websocket/ws_sip_app.rb +120 -0
  56. data/lib/oversip.rb +1 -1
  57. data/test/oversip_test_helper.rb +2 -2
  58. data/test/test_http_parser.rb +2 -2
  59. data/test/test_sip_parser.rb +18 -3
  60. data/test/test_uri.rb +44 -0
  61. metadata +39 -42
  62. data/lib/oversip/websocket/listeners/ipv4_tcp_server.rb +0 -15
  63. data/lib/oversip/websocket/listeners/ipv4_tls_server.rb +0 -15
  64. data/lib/oversip/websocket/listeners/ipv4_tls_tunnel_server.rb +0 -15
  65. data/lib/oversip/websocket/listeners/ipv6_tcp_server.rb +0 -15
  66. data/lib/oversip/websocket/listeners/ipv6_tls_server.rb +0 -15
  67. data/lib/oversip/websocket/listeners/ipv6_tls_tunnel_server.rb +0 -15
  68. data/lib/oversip/websocket/ws_app.rb +0 -77
  69. data/lib/oversip/websocket/ws_apps/ws_autobahn_app.rb +0 -23
  70. data/lib/oversip/websocket/ws_apps/ws_sip_app.rb +0 -156
  71. data/lib/oversip/websocket/ws_apps.rb +0 -9
@@ -5,7 +5,7 @@ module OverSIP::SIP
5
5
  TLS_HANDSHAKE_MAX_TIME = 4
6
6
 
7
7
 
8
- attr_writer :tls_validation
8
+ attr_writer :callback_on_server_tls_handshake
9
9
 
10
10
 
11
11
  def initialize ip, port
@@ -19,7 +19,7 @@ module OverSIP::SIP
19
19
  @server_last_pem = false
20
20
 
21
21
  start_tls({
22
- :verify_peer => @tls_validation,
22
+ :verify_peer => @callback_on_server_tls_handshake,
23
23
  :cert_chain_file => ::OverSIP.tls_public_cert,
24
24
  :private_key_file => ::OverSIP.tls_private_cert
25
25
  })
@@ -37,7 +37,7 @@ module OverSIP::SIP
37
37
 
38
38
 
39
39
  # Called for every certificate provided by the peer.
40
- # This is just called in case @tls_validation is true.
40
+ # This is just called in case @callback_on_server_tls_handshake is true.
41
41
  def ssl_verify_peer pem
42
42
  # TODO: Dirty workaround for bug https://github.com/eventmachine/eventmachine/issues/194.
43
43
  return true if @server_last_pem == pem
@@ -61,20 +61,23 @@ module OverSIP::SIP
61
61
  @connected = true
62
62
  @timer_tls_handshake.cancel if @timer_tls_handshake
63
63
 
64
- if @tls_validation
65
- validated, cert, tls_error, tls_error_string = ::OverSIP::TLS.validate @server_pems.pop, @server_pems
66
- if validated
67
- log_system_info "server provides a valid TLS certificate"
68
- sip_identities = ::OverSIP::TLS.get_sip_identities(cert)
69
- log_system_debug "SIP identities in peer cert: #{sip_identities.keys}" if $oversip_debug
70
- else
71
- log_system_notice "server's TLS certificate validation failed (TLS error: #{tls_error.inspect}, description: #{tls_error_string.inspect})"
64
+ if @callback_on_server_tls_handshake
65
+ begin
66
+ ::OverSIP::SipEvents.on_server_tls_handshake self, @server_pems
67
+ rescue ::Exception => e
68
+ log_system_error "error calling OverSIP::SipEvents.on_server_tls_handshake():"
69
+ log_system_error e
70
+ close_connection
71
+ end
72
+
73
+ # If the user has closed the connection in the on_server_tls_handshake() callback
74
+ # then @local_closed is true, so notify pending transactions.
75
+ if @local_closed
72
76
  @pending_client_transactions.each do |client_transaction|
73
77
  client_transaction.tls_validation_failed
74
78
  end
75
79
  @pending_client_transactions.clear
76
80
  @pending_messages.clear
77
- close_connection
78
81
  @state = :ignore
79
82
  return
80
83
  end
@@ -2,7 +2,7 @@ module OverSIP::SIP
2
2
 
3
3
  class TlsServer < TcpServer
4
4
 
5
- TLS_HANDSHAKE_MAX_TIME = 8
5
+ TLS_HANDSHAKE_MAX_TIME = 4
6
6
 
7
7
 
8
8
  def post_init
@@ -44,19 +44,20 @@ module OverSIP::SIP
44
44
  def ssl_handshake_completed
45
45
  log_system_info "TLS connection established from " << remote_desc
46
46
 
47
- # TODO: What to do it falidation fails? always do validation?
48
-
49
- validated, cert, tls_error, tls_error_string = ::OverSIP::TLS.validate @client_pems.pop, @client_pems
50
- if validated
51
- log_system_info "client provides a valid TLS certificate"
52
- else
53
- log_system_notice "client's TLS certificate validation failed (TLS error: #{tls_error.inspect}, description: #{tls_error_string.inspect})"
54
- end
55
-
56
47
  # @connected in TlsServer means "TLS connection" rather than
57
48
  # just "TCP connection".
58
49
  @connected = true
59
50
  @timer_tls_handshake.cancel if @timer_tls_handshake
51
+
52
+ if ::OverSIP::SIP.callback_on_client_tls_handshake
53
+ begin
54
+ ::OverSIP::SipEvents.on_client_tls_handshake self, @client_pems
55
+ rescue ::Exception => e
56
+ log_system_error "error calling OverSIP::SipEvents.on_client_tls_handshake():"
57
+ log_system_error e
58
+ close_connection
59
+ end
60
+ end
60
61
  end
61
62
 
62
63
 
@@ -67,4 +68,3 @@ module OverSIP::SIP
67
68
 
68
69
  end
69
70
  end
70
-
@@ -1,6 +1,6 @@
1
1
  module OverSIP::SIP
2
2
 
3
- class TlsTunnelReactor < TcpReactor
3
+ class TlsTunnelConnection < TcpConnection
4
4
 
5
5
  # Max size (bytes) of the buffered data when receiving message headers
6
6
  # (avoid DoS attacks).
@@ -25,8 +25,8 @@ module OverSIP::SIP
25
25
  when :haproxy_protocol
26
26
  parse_haproxy_protocol
27
27
 
28
- when :client_pems
29
- parse_client_pems
28
+ #when :client_pems
29
+ # parse_client_pems
30
30
 
31
31
  when :headers
32
32
  parse_headers
@@ -88,23 +88,23 @@ module OverSIP::SIP
88
88
  end
89
89
 
90
90
  # TODO: Not terminated yet.
91
- def parse_client_pems
92
- # TODO: Wrong, it could occur that here the last PEMs byte arries.
93
- return false if @buffer.size < 3 # 3 bytes = 0\r\n (minimum data).
94
-
95
- @pems_str ||= ""
96
- @pems_str << @buffer.read(2)
97
-
98
- # No PEMS.
99
- if @pems_str == "\r\n"
100
- @state = :headers
101
- return true
102
- end
103
-
104
- #@pem_size_str =
105
-
106
- @state = :headers
107
- end
91
+ # def parse_client_pems
92
+ # # TODO: Wrong, it could occur that here the last PEMs byte arries.
93
+ # return false if @buffer.size < 3 # 3 bytes = 0\r\n (minimum data).
94
+ #
95
+ # @pems_str ||= ""
96
+ # @pems_str << @buffer.read(2)
97
+ #
98
+ # # No PEMS.
99
+ # if @pems_str == "\r\n"
100
+ # @state = :headers
101
+ # return true
102
+ # end
103
+ #
104
+ # #@pem_size_str =
105
+ #
106
+ # @state = :headers
107
+ # end
108
108
 
109
109
  end
110
110
 
@@ -1,6 +1,6 @@
1
1
  module OverSIP::SIP
2
2
 
3
- class TlsTunnelServer < TlsTunnelReactor
3
+ class TlsTunnelServer < TlsTunnelConnection
4
4
 
5
5
  attr_reader :outbound_flow_token
6
6
 
@@ -15,13 +15,10 @@ module OverSIP::SIP
15
15
  return
16
16
  end
17
17
 
18
- log_system_debug ("connection from the TLS tunnel " << remote_desc) if $oversip_debug
19
-
20
18
  # Create an Outbound (RFC 5626) flow token for this connection.
21
19
  @outbound_flow_token = ::OverSIP::SIP::TransportManager.add_outbound_connection self
22
20
 
23
- # Initialize @cvars.
24
- @cvars = {}
21
+ log_system_debug ("connection from the TLS tunnel " << remote_desc) if $oversip_debug
25
22
  end
26
23
 
27
24
  def remote_desc force=nil
@@ -1,6 +1,6 @@
1
1
  module OverSIP::SIP
2
2
 
3
- class UdpReactor < Reactor
3
+ class UdpConnection < Connection
4
4
 
5
5
  def receive_data data
6
6
  @buffer << data
@@ -63,7 +63,7 @@ module OverSIP::SIP
63
63
  @buffer.clear
64
64
  @state = :init
65
65
  return false
66
- end
66
+ end
67
67
 
68
68
  # Parse the currently buffered data. If parsing fails @parser_nbytes gets nil value.
69
69
  unless @parser_nbytes = @parser.execute(buffer_str, @parser_nbytes)
@@ -129,7 +129,7 @@ module OverSIP::SIP
129
129
  @msg.source_port = source_port
130
130
  @msg.source_ip_type = self.class.ip_type
131
131
 
132
- unless valid_message?
132
+ unless valid_message? @parser
133
133
  @buffer.clear
134
134
  @state = :init
135
135
  return false
@@ -208,7 +208,7 @@ module OverSIP::SIP
208
208
  end
209
209
  end
210
210
 
211
- end # class UdpReactor
211
+ end
212
212
 
213
213
  end
214
214
 
@@ -1,14 +1,14 @@
1
1
  # OverSIP files
2
2
 
3
- require "oversip/sip/listeners/reactor"
4
-
5
- require "oversip/sip/listeners/udp_reactor"
6
- require "oversip/sip/listeners/tcp_reactor"
7
- require "oversip/sip/listeners/tls_tunnel_reactor"
8
-
3
+ require "oversip/sip/listeners/connection"
4
+ require "oversip/sip/listeners/udp_connection"
5
+ require "oversip/sip/listeners/tcp_connection"
6
+ require "oversip/sip/listeners/tls_tunnel_connection"
9
7
  require "oversip/sip/listeners/tcp_server"
10
8
  require "oversip/sip/listeners/tls_server"
11
9
  require "oversip/sip/listeners/tls_tunnel_server"
10
+ require "oversip/sip/listeners/tcp_client"
11
+ require "oversip/sip/listeners/tls_client"
12
12
 
13
13
  require "oversip/sip/listeners/ipv4_udp_server"
14
14
  require "oversip/sip/listeners/ipv6_udp_server"
@@ -18,10 +18,6 @@ require "oversip/sip/listeners/ipv4_tls_server"
18
18
  require "oversip/sip/listeners/ipv6_tls_server"
19
19
  require "oversip/sip/listeners/ipv4_tls_tunnel_server"
20
20
  require "oversip/sip/listeners/ipv6_tls_tunnel_server"
21
-
22
- require "oversip/sip/listeners/tcp_client"
23
- require "oversip/sip/listeners/tls_client"
24
-
25
21
  require "oversip/sip/listeners/ipv4_tcp_client"
26
22
  require "oversip/sip/listeners/ipv6_tcp_client"
27
23
  require "oversip/sip/listeners/ipv4_tls_client"
@@ -59,13 +59,12 @@ module OverSIP::SIP
59
59
 
60
60
  # Other attributes.
61
61
  attr_accessor :tvars # Transaction variables (a hash).
62
- attr_accessor :cvars # Connection variables (a hash).
63
62
 
64
63
  def udp? ; @transport == :udp end
65
64
  def tcp? ; @transport == :tcp end
66
65
  def tls? ; @transport == :tls end
67
66
  def ws? ; @transport == :ws end
68
- def tls? ; @transport == :wss end
67
+ def wss? ; @transport == :wss end
69
68
 
70
69
  def websocket? ; @transport == :ws || @transport == :wss end
71
70
 
@@ -75,6 +74,8 @@ module OverSIP::SIP
75
74
 
76
75
  def via_alias? ; @via_has_alias end
77
76
 
77
+ def contact_reg_id? ; @contact_has_reg_id end
78
+
78
79
  def dialog_forming?
79
80
  DIALOG_FORMING_METHODS[@sip_method]
80
81
  end
@@ -167,7 +168,7 @@ module OverSIP::SIP
167
168
  # received.
168
169
  def close_connection
169
170
  return false if @transport == :udp
170
- @connection.close_connection
171
+ @connection.close
171
172
  true
172
173
  end
173
174
 
@@ -10,11 +10,11 @@ module OverSIP::SIP
10
10
  }
11
11
 
12
12
 
13
- def valid_message?
14
- if header = @parser.missing_core_header?
13
+ def valid_message? parser
14
+ if header = parser.missing_core_header?
15
15
  log_system_notice "ignoring #{MSG_TYPE[@msg.class]} missing #{header} header"
16
16
  return false
17
- elsif header = @parser.duplicated_core_header?
17
+ elsif header = parser.duplicated_core_header?
18
18
  log_system_notice "ignoring #{MSG_TYPE[@msg.class]} with duplicated #{header} header"
19
19
  return false
20
20
  end
@@ -76,20 +76,20 @@ module OverSIP::SIP
76
76
  # Run the user provided OverSIP::SipEvents.on_request() callback (unless the request
77
77
  # it's a retransmission, a CANCEL or an ACK for a final non-2XX response).
78
78
  unless check_transaction
79
- begin
80
- # Create the antiloop identifier for this request.
81
- @msg.antiloop_id = ::OverSIP::SIP::Tags.create_antiloop_id(@msg)
79
+ # Create the antiloop identifier for this request.
80
+ @msg.antiloop_id = ::OverSIP::SIP::Tags.create_antiloop_id(@msg)
82
81
 
83
- # Check loops.
84
- if @msg.antiloop_id == @msg.via_branch_id[-32..-1]
85
- @msg.reply 482, "Loop Detected"
86
- return
87
- end
82
+ # Check loops.
83
+ if @msg.antiloop_id == @msg.via_branch_id[-32..-1]
84
+ @msg.reply 482, "Loop Detected"
85
+ return
86
+ end
88
87
 
89
- # Initialize some attributes for the request.
90
- @msg.tvars = {}
91
- @msg.cvars = @cvars
88
+ # Initialize some attributes for the request.
89
+ @msg.tvars = {}
90
+ @msg.cvars = @msg.connection.cvars
92
91
 
92
+ begin
93
93
  # Run the callback.
94
94
  ::OverSIP::SipEvents.on_request @msg
95
95
  rescue ::Exception => e
@@ -109,18 +109,18 @@ module OverSIP::SIP
109
109
  ### TODO: Esto va a petar cuando tenga una clase que hereda de, p.ej, IPv4TcpServer que se llame xxxClient,
110
110
  # ya que en ella no existirá @invite_client_transactions. Tengo que hacer que su @invite_client_transactions
111
111
  # se rellene al de la clase padre al hacer el load de las clases.
112
- if client_transaction = self.class.invite_client_transactions[@msg.via_branch_id]
112
+ if client_transaction = @msg.connection.class.invite_client_transactions[@msg.via_branch_id]
113
113
  client_transaction.receive_response(@msg)
114
114
  return
115
115
  end
116
116
  when :ACK
117
117
  when :CANCEL
118
- if client_transaction = self.class.invite_client_transactions[@msg.via_branch_id]
118
+ if client_transaction = @msg.connection.class.invite_client_transactions[@msg.via_branch_id]
119
119
  client_transaction.receive_response_to_cancel(@msg)
120
120
  return
121
121
  end
122
122
  else
123
- if client_transaction = self.class.non_invite_client_transactions[@msg.via_branch_id]
123
+ if client_transaction = @msg.connection.class.non_invite_client_transactions[@msg.via_branch_id]
124
124
  client_transaction.receive_response(@msg)
125
125
  return
126
126
  end
@@ -5,13 +5,19 @@ module OverSIP::SIP
5
5
 
6
6
  # Create a server transaction for the incoming request.
7
7
  def create_transaction
8
+ return false if @server_transaction
9
+
8
10
  case @sip_method
9
11
  when :INVITE
10
12
  ::OverSIP::SIP::InviteServerTransaction.new self
13
+ return true
11
14
  when :ACK
15
+ return nil
12
16
  when :CANCEL
17
+ return nil
13
18
  else
14
19
  ::OverSIP::SIP::NonInviteServerTransaction.new self
20
+ return true
15
21
  end
16
22
  end
17
23
 
@@ -44,7 +50,6 @@ module OverSIP::SIP
44
50
  num_removes += 1
45
51
  else
46
52
  if local_uri? route
47
- log_system_debug "removing pre-loaded Route pointing to this server" if $oversip_debug
48
53
  has_preloaded_route_with_ob_param = true if route.ob_param?
49
54
  num_removes += 1
50
55
  else
@@ -63,14 +68,15 @@ module OverSIP::SIP
63
68
  # - Has a preloaded top Route with ;ob param pointing to us, or has Contact with ;ob, or
64
69
  # it's a REGISTER with ;+sip.instance.
65
70
  #
66
- # TODO: and (has_preloaded_route_with_ob_param or @request.contact.ob_param?).
67
- # TODO: For REGISTER check also ;+sip.instance Contact param.
68
71
  if (
69
- @force_outgoing_outbound or (
70
- initial? and
71
- @num_vias == 1 and
72
- outbound_aware? and
73
- has_preloaded_route_with_ob_param
72
+ initial? and (
73
+ @force_outgoing_outbound or (
74
+ @num_vias == 1 and
75
+ outbound_aware? and (
76
+ ( has_preloaded_route_with_ob_param or (@contact and @contact.ob_param?) ) or
77
+ ( @sip_method == :REGISTER and contact_reg_id?)
78
+ )
79
+ )
74
80
  )
75
81
  )
76
82
  @outgoing_outbound_requested = true
@@ -107,7 +113,7 @@ module OverSIP::SIP
107
113
  end
108
114
  @routes.empty? and @routes = nil
109
115
 
110
- # Return true if it is an in-dialog request and at least one top Route pointed to us.
116
+ # Return true if it is an in-dialog request and the top Route pointed to us.
111
117
  # False otherwise as we shouldn't receive an in-dialog request with a top Route non
112
118
  # pointing to us.
113
119
  if in_dialog?
@@ -122,8 +128,9 @@ module OverSIP::SIP
122
128
  end
123
129
 
124
130
 
125
- # Mira si el RURI es local. Se supone que antes se ha validado el Route y que el script
126
- # no permite pre-loaded Route a otro destino..
131
+ # Checks whether the RURI points to a local domain or address.
132
+ # Typically, prior to using this method the user has verified the return value of loose_route()
133
+ # in case it's an initial request (if it's _true_ then the request has pre-loaded Route).
127
134
  def destination_myself?
128
135
  return true if @destination_myself
129
136
  return false if @destination_myself == false
@@ -149,8 +156,6 @@ module OverSIP::SIP
149
156
  end
150
157
 
151
158
 
152
- # TODO: It must be true if top Route or Contact has ;ob param, or also if the Contact
153
- # has +sip.instance.
154
159
  def outgoing_outbound_requested? ; @outgoing_outbound_requested end
155
160
 
156
161
  def incoming_outbound_requested? ; @incoming_outbound_requested end
@@ -22,13 +22,13 @@ module OverSIP::SIP
22
22
  # Don't do this stuf for UDP or for outbound connections.
23
23
  return false unless request.connection.class.reliable_transport_listener?
24
24
  # Return if already set.
25
- return request.connection.asserted_user if request.connection.asserted_user
25
+ return request.cvars[:asserted_user] if request.cvars[:asserted_user]
26
26
  # Don't do this stuf in case of P-Preferred-Identity header is present.
27
27
  return false if request.headers["P-Preferred-Identity"]
28
28
 
29
29
  log_system_debug "user #{request.from.uri} asserted to connection" if $oversip_debug
30
30
  # Store the request From URI as "asserted_user" for this connection.
31
- request.connection.asserted_user = request.from.uri
31
+ request.cvars[:asserted_user] = request.from.uri
32
32
  end
33
33
 
34
34
  def self.revoke_assertion message
@@ -41,7 +41,7 @@ module OverSIP::SIP
41
41
  raise ::OverSIP::RuntimeError, "message must be a OverSIP::SIP::Request or OverSIP::SIP::Response"
42
42
  end
43
43
 
44
- request.connection.asserted_user = false
44
+ request.cvars.delete :asserted_user
45
45
  true
46
46
  end
47
47
 
@@ -50,16 +50,17 @@ module OverSIP::SIP
50
50
  # in case it matches request From URI !
51
51
  # NOTE: If the connection is not asserted (it's null) then it will not match this
52
52
  # comparisson, so OK.
53
- if request.connection.asserted_user == request.from.uri
53
+ if request.cvars[:asserted_user] == request.from.uri
54
54
  # Don't add P-Asserted-Identity if the request contains P-Preferred-Identity header.
55
55
  unless request.headers["P-Preferred-Identity"]
56
56
  log_system_debug "user asserted, adding P-Asserted-Identity for #{request.log_id}" if $oversip_debug
57
- request.set_header "P-Asserted-Identity", "<" << request.connection.asserted_user << ">"
57
+ request.set_header "P-Asserted-Identity", "<" << request.cvars[:asserted_user] << ">"
58
58
  return true
59
59
  else
60
60
  # Remove posible P-Asserted-Identity header!
61
61
  log_system_debug "user asserted but P-Preferred-Identity header present, P-Asserted-Identity not added for #{request.log_id}" if $oversip_debug
62
62
  request.headers.delete "P-Asserted-Identity"
63
+ return nil
63
64
  end
64
65
 
65
66
  # Otherwise ensure the request has no spoofed P-Asserted-Identity headers!
@@ -73,51 +74,4 @@ module OverSIP::SIP
73
74
  end # module UserAssertion
74
75
  end # module Modules
75
76
 
76
- end # module OverSIP::SIP
77
-
78
-
79
- module OverSIP::SIP
80
- class Request
81
- def asserted_user?
82
- true if self.connection.asserted_user
83
- end
84
-
85
- def asserted_user
86
- self.connection.asserted_user
87
- end
88
- end
89
-
90
- class Response
91
- def asserted_user?
92
- true if self.request.connection.asserted_user
93
- end
94
-
95
- def asserted_user
96
- self.request.connection.asserted_user
97
- end
98
- end
99
-
100
- class TcpServer
101
- attr_accessor :asserted_user
102
- end
103
-
104
- class TlsServer
105
- attr_accessor :asserted_user
106
- end
107
-
108
- class TlsTunnelServer
109
- attr_accessor :asserted_user
110
- end
111
-
112
- # This is never used since it's not a reliable connection, but it's required not to fail.
113
- class UdpReactor
114
- attr_accessor :asserted_user
115
- end
116
- end # OverSIP::SIP
117
-
118
-
119
- module OverSIP::WebSocket
120
- class WsSipApp
121
- attr_accessor :asserted_user
122
- end
123
- end # OverSIP::WebSocket
77
+ end
@@ -4,9 +4,9 @@ module OverSIP::SIP
4
4
 
5
5
  include ::OverSIP::Logger
6
6
 
7
- def initialize proxy_name=:default_proxy
8
- unless (@proxy_conf = ::OverSIP.proxies[proxy_name.to_sym])
9
- raise ::OverSIP::RuntimeError, "proxy '#{proxy_name}' is not defined in Proxies Configuration file"
7
+ def initialize proxy_profile=:default_proxy
8
+ unless (@proxy_conf = ::OverSIP.proxies[proxy_profile.to_sym])
9
+ raise ::OverSIP::RuntimeError, "proxy '#{proxy_profile}' is not defined in Proxies Configuration file"
10
10
  end
11
11
  end
12
12
 
@@ -17,6 +17,8 @@ module OverSIP::SIP
17
17
  # or Path.
18
18
  attr_accessor :in_rr
19
19
 
20
+ attr_accessor :cvars # Connection variables (a hash).
21
+
20
22
 
21
23
  def log_id
22
24
  @log_id ||= "SIP Request #{@via_branch_id}"
@@ -285,7 +285,7 @@ module OverSIP::SIP
285
285
 
286
286
  # If @use_srv is false then perform A/AAAA queries.
287
287
  else
288
- log_system_debug "SRV is dissabled, performing A/AAAA queries" if $oversip_debug
288
+ log_system_debug "SRV is disabled, performing A/AAAA queries" if $oversip_debug
289
289
 
290
290
  port = 5061 if dns_transport == :tls
291
291
  port ||= case @uri_scheme
@@ -311,12 +311,12 @@ module OverSIP::SIP
311
311
  # If @use_naptr is false then NAPTR must not be performed.
312
312
  if ! @use_naptr
313
313
  if @use_srv
314
- log_system_debug "NAPTR is dissabled, performing SRV queries" if $oversip_debug
314
+ log_system_debug "NAPTR is disabled, performing SRV queries" if $oversip_debug
315
315
  continue_with_SRV
316
316
 
317
317
  # If @use_srv is false then perform A/AAAA queries.
318
318
  else
319
- log_system_debug "NAPTR and SRV are dissabled, performing A/AAAA queries" if $oversip_debug
319
+ log_system_debug "NAPTR and SRV are disabled, performing A/AAAA queries" if $oversip_debug
320
320
  case @uri_scheme
321
321
  when :sip
322
322
  if @has_sip_udp
@@ -49,6 +49,8 @@ module OverSIP::SIP
49
49
  ws_local_ips.each do |ip|
50
50
  @local_aliases[ip] = true if conf[:websocket][:listen_port] == 80 or conf[:websocket][:listen_port_tls] == 443
51
51
  end
52
+
53
+ @callback_on_client_tls_handshake = conf[:sip][:callback_on_client_tls_handshake]
52
54
  end
53
55
 
54
56
  def self.local_aliases
@@ -67,4 +69,8 @@ module OverSIP::SIP
67
69
  @local_ipv6
68
70
  end
69
71
 
72
+ def self.callback_on_client_tls_handshake
73
+ @callback_on_client_tls_handshake
74
+ end
75
+
70
76
  end
@@ -15,7 +15,7 @@ module OverSIP::SIP
15
15
  # the client transaction is stored in the @pending_client_transactions of the client
16
16
  # connection.
17
17
  # This method always returns a connection object, never nil or false.
18
- def self.get_connection klass, ip, port, client_transaction=nil, tls_validation=false
18
+ def self.get_connection klass, ip, port, client_transaction=nil, callback_on_server_tls_handshake=false
19
19
  # A normal connection (so we arrive here after RFC 3263 procedures).
20
20
  case klass.transport
21
21
 
@@ -28,13 +28,13 @@ module OverSIP::SIP
28
28
  when :tcp
29
29
  case klass.ip_type
30
30
  when :ipv4
31
- conn = klass.connections["#{ip}_#{port}"] || ::EM.oversip_connect_tcp_server(::OverSIP::SIP.local_ipv4, ip, port, IPv4TcpClient, ip, port)
31
+ conn = klass.connections["#{ip}_#{port}"] || ::EM.oversip_connect_tcp_server(::OverSIP::SIP.local_ipv4, ip, port, ::OverSIP::SIP::IPv4TcpClient, ip, port)
32
32
 
33
33
  if conn.is_a? ::OverSIP::SIP::IPv4TcpClient and not conn.connected
34
34
  conn.pending_client_transactions << client_transaction
35
35
  end
36
36
  when :ipv6
37
- conn = klass.connections["#{::OverSIP::Utils.normalize_ipv6 ip}_#{port}"] || ::EM.oversip_connect_tcp_server(::OverSIP::SIP.local_ipv6, ip, port, IPv6TcpClient, ip, port)
37
+ conn = klass.connections["#{::OverSIP::Utils.normalize_ipv6 ip}_#{port}"] || ::EM.oversip_connect_tcp_server(::OverSIP::SIP.local_ipv6, ip, port, ::OverSIP::SIP::IPv6TcpClient, ip, port)
38
38
 
39
39
  if conn.is_a? ::OverSIP::SIP::IPv6TcpClient and not conn.connected
40
40
  conn.pending_client_transactions << client_transaction
@@ -44,17 +44,17 @@ module OverSIP::SIP
44
44
  when :tls
45
45
  case klass.ip_type
46
46
  when :ipv4
47
- conn = klass.connections["#{ip}_#{port}"] || ::EM.oversip_connect_tcp_server(::OverSIP::SIP.local_ipv4, ip, port, IPv4TlsClient, ip, port)
47
+ conn = klass.connections["#{ip}_#{port}"] || ::EM.oversip_connect_tcp_server(::OverSIP::SIP.local_ipv4, ip, port, ::OverSIP::SIP::IPv4TlsClient, ip, port)
48
48
 
49
49
  if conn.is_a? ::OverSIP::SIP::IPv4TlsClient and not conn.connected
50
- conn.tls_validation = tls_validation
50
+ conn.callback_on_server_tls_handshake = callback_on_server_tls_handshake
51
51
  conn.pending_client_transactions << client_transaction
52
52
  end
53
53
  when :ipv6
54
- conn = klass.connections["#{::OverSIP::Utils.normalize_ipv6 ip}_#{port}"] || ::EM.oversip_connect_tcp_server(::OverSIP::SIP.local_ipv6, ip, port, IPv6TlsClient, ip, port)
54
+ conn = klass.connections["#{::OverSIP::Utils.normalize_ipv6 ip}_#{port}"] || ::EM.oversip_connect_tcp_server(::OverSIP::SIP.local_ipv6, ip, port, ::OverSIP::SIP::IPv6TlsClient, ip, port)
55
55
 
56
56
  if conn.is_a? ::OverSIP::SIP::IPv6TlsClient and not conn.connected
57
- conn.tls_validation = tls_validation
57
+ conn.callback_on_server_tls_handshake = callback_on_server_tls_handshake
58
58
  conn.pending_client_transactions << client_transaction
59
59
  end
60
60
  end
@@ -105,7 +105,7 @@ module OverSIP::SIP
105
105
  return false
106
106
  end
107
107
 
108
- # It not, the flow token has been generated for a TCP/TLS/WS connection so let's lookup
108
+ # It not, the flow token has been generated for a TCP/TLS/WS/WSS connection so let's lookup
109
109
  # it into the Outbound connection collection and return nil for IP and port.
110
110
  else
111
111
  @outbound_connections[flow_token]