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
data/lib/oversip/tls.rb CHANGED
@@ -16,20 +16,10 @@ module OverSIP
16
16
  configuration = ::OverSIP.configuration
17
17
  if configuration[:tls][:public_cert] and configuration[:tls][:private_cert]
18
18
  log_system_info "TLS enabled"
19
-
20
- ::OverSIP.tls = true
21
19
  ::OverSIP.tls_public_cert = configuration[:tls][:public_cert]
22
20
  ::OverSIP.tls_private_cert = configuration[:tls][:private_cert]
23
-
24
- if (::OverSIP.tls_proxy_ipv4 = configuration[:tls][:tls_proxy_ipv4])
25
- log_system_info "TLS proxy enabled from IPv4 #{::OverSIP.tls_proxy_ipv4}"
26
- end
27
- if (::OverSIP.tls_proxy_ipv6 = configuration[:tls][:tls_proxy_ipv6])
28
- log_system_info "TLS proxy enabled from IPv6 #{::OverSIP.tls_proxy_ipv6}"
29
- end
30
-
31
21
  else
32
- log_system_info "TLS dissabled"
22
+ log_system_info "TLS disabled"
33
23
  return
34
24
  end
35
25
 
@@ -86,7 +76,7 @@ module OverSIP
86
76
  end
87
77
 
88
78
  if num_certs_added == 0
89
- log_system_notice "zero public certificates found in '#{ca_dir}' directory, dissabling TLS validation"
79
+ log_system_notice "zero public certificates found in '#{ca_dir}' directory, disabling TLS validation"
90
80
  @store = nil
91
81
  end
92
82
  log_system_info "#{num_certs_added} public certificates available for TLS validation"
@@ -96,18 +86,21 @@ module OverSIP
96
86
 
97
87
 
98
88
  # Return an array with the result of the TLS certificate validation as follows:
99
- # validated, cert, tls_error, tls_error_string
89
+ # cert, validated, tls_error, tls_error_string
100
90
  # where:
91
+ # - cert: the ::OpenSSL::X509::Certificate instance of the first PEM provided by
92
+ # the peer, nil otherwise.
101
93
  # - validated: true if the given certificate(s) have been validated, false otherwise
102
94
  # and nil if no certificate is provided by peer or no CA's were configured
103
95
  # for TLS validation.
104
- # - cert: the ::OpenSSL::X509::Certificate instance of the first PEM provided by
105
- # the peer, nil otherwise.
106
96
  # - tls_error: OpenSSL validation error code (Fixnum) in case of validation error.
107
97
  # - tls_error_string: OpenSSL validation error string in case of validation error.
108
- def self.validate pem, intermediate_pems=nil
109
- return nil, nil, nil, "no CAs provided, validation dissabled" unless @store
110
- return nil, nil, nil, "no certificate provided by peer" unless pem
98
+ def self.validate pems
99
+ return nil, nil, nil, "no CAs provided, validation disabled" unless @store
100
+ return nil, false, nil, "no certificate provided by peer" unless pems.any?
101
+
102
+ pem = pems.pop
103
+ intermediate_pems = pems
111
104
 
112
105
  begin
113
106
  cert = ::OpenSSL::X509::Certificate.new pem
@@ -122,19 +115,21 @@ module OverSIP
122
115
  end
123
116
 
124
117
  if @store.verify cert, intermediate_certs
125
- return true, cert
118
+ return cert, true
126
119
  else
127
- return false, cert, @store.error, @store.error_string
120
+ return cert, false, @store.error, @store.error_string
128
121
  end
129
122
 
130
123
  rescue => e
131
124
  log_system_error "exception validating a certificate: #{e.class}: #{e.message}"
132
- return false, nil, e.class, e.message
125
+ return nil, false, e.class, e.message
133
126
  end
134
127
  end # def self.validate
135
128
 
136
129
 
137
130
  def self.get_sip_identities cert
131
+ return [] unless cert
132
+
138
133
  verify_subjectAltName_DNS = true
139
134
  verify_CN = true
140
135
  subjectAltName_URI_sip_entries = []
@@ -171,7 +166,8 @@ module OverSIP
171
166
  end
172
167
  end
173
168
 
174
- return sip_identities
169
+ # Return an array with the SIP identities (domains) in the certificate.
170
+ return sip_identities.keys
175
171
  end
176
172
 
177
173
  end
@@ -6,7 +6,7 @@ module OverSIP
6
6
  MAJOR = 1
7
7
  MINOR = 1
8
8
  TINY = 0
9
- DEVEL = "beta5" # Set to nil for stable releases.
9
+ DEVEL = nil # Set to nil for stable releases.
10
10
  end
11
11
 
12
12
  PROGRAM_NAME = "OverSIP"
@@ -51,6 +51,5 @@ module OverSIP::WebSocket
51
51
  HDR_SERVER = "Server: #{::OverSIP::PROGRAM_NAME}/#{::OverSIP::VERSION}".freeze
52
52
 
53
53
  WS_SIP_PROTOCOL = "sip"
54
- WS_AUTOBAHN_PROTOCOL = "autobahn"
55
54
 
56
55
  end
@@ -4,11 +4,6 @@ module OverSIP::WebSocket
4
4
 
5
5
  include ::OverSIP::Logger
6
6
 
7
- # HTTP related attributes.
8
- attr_accessor :transport
9
- attr_accessor :source_ip
10
- attr_accessor :source_ip_type
11
- attr_accessor :source_port
12
7
  attr_accessor :connection
13
8
 
14
9
  # HTTP request attributes.
@@ -30,8 +25,9 @@ module OverSIP::WebSocket
30
25
  attr_reader :hdr_sec_websocket_protocol
31
26
 
32
27
 
28
+ LOG_ID = "HTTP WS Request"
33
29
  def log_id
34
- @log_id ||= "HTTP Request #{@connection.connection_log_id}"
30
+ LOG_ID
35
31
  end
36
32
 
37
33
  def unknown_method? ; @is_unknown_method end
@@ -50,7 +46,7 @@ module OverSIP::WebSocket
50
46
  log_system_debug "replying #{status_code} \"#{reason_phrase}\"" if $oversip_debug
51
47
 
52
48
  if @connection.error?
53
- log_system_warn "cannot send response, TCP connection is closed"
49
+ log_system_warn "cannot send response, connection is closed"
54
50
  return false
55
51
  end
56
52
 
@@ -58,6 +54,6 @@ module OverSIP::WebSocket
58
54
  return true
59
55
  end
60
56
 
61
- end # class HttpRequest
57
+ end
62
58
 
63
59
  end
@@ -15,7 +15,7 @@ module OverSIP::WebSocket
15
15
  end
16
16
 
17
17
 
18
- def self.run enabled, ip_type, ip, port, transport, ws_protocol, virtual_ip=nil, virtual_port=nil
18
+ def self.run enabled, ip_type, ip, port, transport, virtual_ip=nil, virtual_port=nil
19
19
  uri_ip = case ip_type
20
20
  when :ipv4 ; ip
21
21
  when :ipv6 ; "[#{ip}]"
@@ -29,167 +29,111 @@ module OverSIP::WebSocket
29
29
  end
30
30
 
31
31
  klass = case transport
32
- when :tcp
32
+ when :ws
33
33
  case ip_type
34
- when :ipv4 ; OverSIP::WebSocket::IPv4TcpServer
35
- when :ipv6 ; OverSIP::WebSocket::IPv6TcpServer
34
+ when :ipv4 ; OverSIP::WebSocket::IPv4WsServer
35
+ when :ipv6 ; OverSIP::WebSocket::IPv6WsServer
36
36
  end
37
- when :tls
37
+ when :wss
38
38
  case ip_type
39
- when :ipv4 ; OverSIP::WebSocket::IPv4TlsServer
40
- when :ipv6 ; OverSIP::WebSocket::IPv6TlsServer
39
+ when :ipv4 ; OverSIP::WebSocket::IPv4WssServer
40
+ when :ipv6 ; OverSIP::WebSocket::IPv6WssServer
41
41
  end
42
- when :tls_tunnel
42
+ when :wss_tunnel
43
43
  case ip_type
44
- when :ipv4 ; OverSIP::WebSocket::IPv4TlsTunnelServer
45
- when :ipv6 ; OverSIP::WebSocket::IPv6TlsTunnelServer
44
+ when :ipv4 ; OverSIP::WebSocket::IPv4WssTunnelServer
45
+ when :ipv6 ; OverSIP::WebSocket::IPv6WssTunnelServer
46
46
  end
47
47
  end
48
48
 
49
- case ws_protocol
50
-
51
- when OverSIP::WebSocket::WS_SIP_PROTOCOL
52
-
53
- ws_app_klass = case transport
54
- when :tcp
55
- case ip_type
56
- when :ipv4 ; OverSIP::WebSocket::IPv4WsSipApp
57
- when :ipv6 ; OverSIP::WebSocket::IPv6WsSipApp
58
- end
59
- when :tls, :tls_tunnel
60
- case ip_type
61
- when :ipv4 ; OverSIP::WebSocket::IPv4WssSipApp
62
- when :ipv6 ; OverSIP::WebSocket::IPv6WssSipApp
63
- end
64
- end
65
-
66
- ws_app_klass.ip = virtual_ip || ip
67
- ws_app_klass.port = virtual_port || port
49
+ klass.ip = virtual_ip || ip
50
+ klass.port = virtual_port || port
68
51
 
69
- case
52
+ case
70
53
 
71
- when klass == OverSIP::WebSocket::IPv4TcpServer
72
- ws_app_klass.via_core = "SIP/2.0/WS #{uri_ip}:#{port}"
73
- ws_app_klass.record_route = "<sip:#{uri_ip}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
74
- ws_app_klass.outbound_record_route_fragment = "@#{uri_ip}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
75
- ws_app_klass.outbound_path_fragment = "@#{uri_ip}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
54
+ when klass == OverSIP::WebSocket::IPv4WsServer
55
+ klass.via_core = "SIP/2.0/WS #{uri_ip}:#{port}"
56
+ klass.record_route = "<sip:#{uri_ip}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
57
+ klass.outbound_record_route_fragment = "@#{uri_ip}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
58
+ klass.outbound_path_fragment = "@#{uri_ip}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
76
59
 
77
- if enabled
78
- EM.start_server(ip, port, klass) do |conn|
79
- conn.ws_protocol = ws_protocol
80
- conn.ws_app_klass = ws_app_klass
81
- conn.post_connection
82
- conn.set_comm_inactivity_timeout 3600 # TODO
83
- end
60
+ if enabled
61
+ EM.start_server(ip, port, klass) do |conn|
62
+ conn.post_connection
63
+ conn.set_comm_inactivity_timeout 3600 # TODO
84
64
  end
65
+ end
85
66
 
86
- when klass == OverSIP::WebSocket::IPv6TcpServer
87
- ws_app_klass.via_core = "SIP/2.0/WS #{uri_ip}:#{port}"
88
- ws_app_klass.record_route = "<sip:#{uri_ip}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
89
- ws_app_klass.outbound_record_route_fragment = "@#{uri_ip}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
90
- ws_app_klass.outbound_path_fragment = "@#{uri_ip}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
91
-
92
- if enabled
93
- EM.start_server(ip, port, klass) do |conn|
94
- conn.ws_protocol = ws_protocol
95
- conn.ws_app_klass = ws_app_klass
96
- conn.post_connection
97
- conn.set_comm_inactivity_timeout 3600 # TODO
98
- end
99
- end
67
+ when klass == OverSIP::WebSocket::IPv6WsServer
68
+ klass.via_core = "SIP/2.0/WS #{uri_ip}:#{port}"
69
+ klass.record_route = "<sip:#{uri_ip}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
70
+ klass.outbound_record_route_fragment = "@#{uri_ip}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
71
+ klass.outbound_path_fragment = "@#{uri_ip}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
100
72
 
101
- when klass == OverSIP::WebSocket::IPv4TlsServer
102
- ws_app_klass.via_core = "SIP/2.0/WSS #{uri_ip}:#{port}"
103
- rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv4] || uri_ip
104
- ws_app_klass.record_route = "<sip:#{rr_host}:#{port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
105
- ws_app_klass.outbound_record_route_fragment = "@#{rr_host}:#{port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
106
- ws_app_klass.outbound_path_fragment = "@#{rr_host}:#{port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
107
-
108
- if enabled
109
- EM.start_server(ip, port, klass) do |conn|
110
- conn.ws_protocol = ws_protocol
111
- conn.ws_app_klass = ws_app_klass
112
- conn.post_connection
113
- conn.set_comm_inactivity_timeout 3600 # TODO
114
- end
73
+ if enabled
74
+ EM.start_server(ip, port, klass) do |conn|
75
+ conn.post_connection
76
+ conn.set_comm_inactivity_timeout 3600 # TODO
115
77
  end
78
+ end
116
79
 
117
- when klass == OverSIP::WebSocket::IPv6TlsServer
118
- ws_app_klass.via_core = "SIP/2.0/WSS #{uri_ip}:#{port}"
119
- rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv6] || uri_ip
120
- ws_app_klass.record_route = "<sips:#{rr_host}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
121
- ws_app_klass.outbound_record_route_fragment = "@#{rr_host}:#{port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
122
- ws_app_klass.outbound_path_fragment = "@#{rr_host}:#{port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
123
-
124
- if enabled
125
- EM.start_server(ip, port, klass) do |conn|
126
- conn.ws_protocol = ws_protocol
127
- conn.ws_app_klass = ws_app_klass
128
- conn.post_connection
129
- conn.set_comm_inactivity_timeout 3600 # TODO
130
- end
80
+ when klass == OverSIP::WebSocket::IPv4WssServer
81
+ klass.via_core = "SIP/2.0/WSS #{uri_ip}:#{port}"
82
+ rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv4] || uri_ip
83
+ klass.record_route = "<sip:#{rr_host}:#{port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
84
+ klass.outbound_record_route_fragment = "@#{rr_host}:#{port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
85
+ klass.outbound_path_fragment = "@#{rr_host}:#{port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
86
+
87
+ if enabled
88
+ EM.start_server(ip, port, klass) do |conn|
89
+ conn.post_connection
90
+ conn.set_comm_inactivity_timeout 3600 # TODO
131
91
  end
92
+ end
132
93
 
133
- when klass == OverSIP::WebSocket::IPv4TlsTunnelServer
134
- ws_app_klass.via_core = "SIP/2.0/WSS #{uri_virtual_ip}:#{virtual_port}"
135
- rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv4] || uri_virtual_ip
136
- ws_app_klass.record_route = "<sip:#{rr_host}:#{virtual_port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
137
- ws_app_klass.outbound_record_route_fragment = "@#{rr_host}:#{virtual_port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
138
- ws_app_klass.outbound_path_fragment = "@#{rr_host}:#{virtual_port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
139
-
140
- if enabled
141
- EM.start_server(ip, port, klass) do |conn|
142
- conn.ws_protocol = ws_protocol
143
- conn.ws_app_klass = ws_app_klass
144
- conn.post_connection
145
- conn.set_comm_inactivity_timeout 3600 # TODO
146
- end
94
+ when klass == OverSIP::WebSocket::IPv6WssServer
95
+ klass.via_core = "SIP/2.0/WSS #{uri_ip}:#{port}"
96
+ rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv6] || uri_ip
97
+ klass.record_route = "<sips:#{rr_host}:#{port};transport=ws;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
98
+ klass.outbound_record_route_fragment = "@#{rr_host}:#{port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
99
+ klass.outbound_path_fragment = "@#{rr_host}:#{port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
100
+
101
+ if enabled
102
+ EM.start_server(ip, port, klass) do |conn|
103
+ conn.post_connection
104
+ conn.set_comm_inactivity_timeout 3600 # TODO
147
105
  end
106
+ end
148
107
 
149
- when klass == OverSIP::WebSocket::IPv6TlsTunnelServer
150
- ws_app_klass.via_core = "SIP/2.0/WSS #{uri_virtual_ip}:#{virtual_port}"
151
- rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv6] || uri_virtual_ip
152
- ws_app_klass.record_route = "<sip:#{rr_host}:#{virtual_port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
153
- ws_app_klass.outbound_record_route_fragment = "@#{rr_host}:#{virtual_port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
154
- ws_app_klass.outbound_path_fragment = "@#{rr_host}:#{virtual_port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
155
-
156
- if enabled
157
- EM.start_server(ip, port, klass) do |conn|
158
- conn.ws_protocol = ws_protocol
159
- conn.ws_app_klass = ws_app_klass
160
- conn.post_connection
161
- conn.set_comm_inactivity_timeout 3600 # TODO
162
- end
108
+ when klass == OverSIP::WebSocket::IPv4WssTunnelServer
109
+ klass.via_core = "SIP/2.0/WSS #{uri_virtual_ip}:#{virtual_port}"
110
+ rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv4] || uri_virtual_ip
111
+ klass.record_route = "<sip:#{rr_host}:#{virtual_port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
112
+ klass.outbound_record_route_fragment = "@#{rr_host}:#{virtual_port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
113
+ klass.outbound_path_fragment = "@#{rr_host}:#{virtual_port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
114
+
115
+ if enabled
116
+ EM.start_server(ip, port, klass) do |conn|
117
+ conn.post_connection
118
+ conn.set_comm_inactivity_timeout 3600 # TODO
163
119
  end
164
-
165
- end # case
166
-
167
-
168
- when OverSIP::WebSocket::WS_AUTOBAHN_PROTOCOL
169
-
170
- ws_app_klass = case transport
171
- when :tcp
172
- case ip_type
173
- when :ipv4 ; OverSIP::WebSocket::WsAutobahnApp
174
- end
175
- when :tls
176
- case ip_type
177
- when :ipv4 ; OverSIP::WebSocket::WsAutobahnApp
178
- end
179
120
  end
180
121
 
181
- EM.start_server(ip, port, klass) do |conn|
182
- conn.ws_protocol = ws_protocol
183
- conn.ws_app_klass = ws_app_klass
184
- conn.post_connection
185
- conn.set_comm_inactivity_timeout 60
186
- end
187
-
188
-
189
- else
190
- fatal "unknown WebSocket protocol: #{ws_protocol}"
122
+ when klass == OverSIP::WebSocket::IPv6WssTunnelServer
123
+ klass.via_core = "SIP/2.0/WSS #{uri_virtual_ip}:#{virtual_port}"
124
+ rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv6] || uri_virtual_ip
125
+ klass.record_route = "<sip:#{rr_host}:#{virtual_port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
126
+ klass.outbound_record_route_fragment = "@#{rr_host}:#{virtual_port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
127
+ klass.outbound_path_fragment = "@#{rr_host}:#{virtual_port};transport=wss;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
128
+
129
+ if enabled
130
+ EM.start_server(ip, port, klass) do |conn|
131
+ conn.post_connection
132
+ conn.set_comm_inactivity_timeout 3600 # TODO
133
+ end
134
+ end
191
135
 
192
- end # case
136
+ end # case
193
137
 
194
138
  transport_str = case transport
195
139
  when :tls_tunnel ; "TLS-Tunnel"
@@ -197,7 +141,7 @@ module OverSIP::WebSocket
197
141
  end
198
142
 
199
143
  if enabled
200
- log_system_info "WebSocket #{transport_str} server listening on #{IP_TYPE[ip_type]} #{uri_ip}:#{port} provides '#{ws_protocol}' WS subprotocol"
144
+ log_system_info "WebSocket #{transport_str} server listening on #{IP_TYPE[ip_type]} #{uri_ip}:#{port} provides '#{::OverSIP::WebSocket::WS_SIP_PROTOCOL}' WS subprotocol"
201
145
  end
202
146
 
203
147
  end # def self.run
@@ -0,0 +1,47 @@
1
+ module OverSIP::WebSocket
2
+
3
+ class Connection < ::EM::Connection
4
+
5
+ include ::OverSIP::Logger
6
+ include ::OverSIP::SIP::MessageProcessor
7
+
8
+ class << self
9
+ attr_accessor :ip_type, :ip, :port, :transport,
10
+ :via_core,
11
+ :record_route,
12
+ :outbound_record_route_fragment, :outbound_path_fragment,
13
+ :connections,
14
+ :invite_server_transactions, :non_invite_server_transactions,
15
+ :invite_client_transactions, :non_invite_client_transactions
16
+
17
+ def reliable_transport_listener?
18
+ @is_reliable_transport_listener
19
+ end
20
+ end
21
+
22
+
23
+ attr_reader :cvars
24
+
25
+ def initialize
26
+ @buffer = ::IO::Buffer.new
27
+ @state = :init
28
+ @cvars = {}
29
+ end
30
+
31
+ def open?
32
+ ! error?
33
+ end
34
+
35
+ def close status=nil, reason=nil
36
+ # When in WebSocket protocol send a close control frame before closing
37
+ # the connection.
38
+ if @state == :websocket
39
+ @ws_framing.send_close_frame status, reason
40
+ end
41
+
42
+ close_connection_after_writing
43
+ @state = :ignore
44
+ end
45
+ end
46
+
47
+ end
@@ -1,6 +1,6 @@
1
1
  module OverSIP::WebSocket
2
2
 
3
- class IPv4WsSipApp < WsSipApp
3
+ class IPv4WsServer < WsServer
4
4
 
5
5
  @ip_type = :ipv4
6
6
  @transport = :ws
@@ -11,11 +11,11 @@ module OverSIP::WebSocket
11
11
  @non_invite_client_transactions = {}
12
12
  @is_reliable_transport_listener = true
13
13
 
14
- LOG_ID = "WS IPv4 SIP app"
14
+ LOG_ID = "SIP WS IPv4 server"
15
15
  def log_id
16
16
  LOG_ID
17
17
  end
18
18
 
19
19
  end
20
20
 
21
- end
21
+ end
@@ -1,6 +1,6 @@
1
1
  module OverSIP::WebSocket
2
2
 
3
- class IPv4WssSipApp < WsSipApp
3
+ class IPv4WssServer < WssServer
4
4
 
5
5
  @ip_type = :ipv4
6
6
  @transport = :wss
@@ -11,7 +11,7 @@ module OverSIP::WebSocket
11
11
  @non_invite_client_transactions = {}
12
12
  @is_reliable_transport_listener = true
13
13
 
14
- LOG_ID = "WSS IPv4 SIP app"
14
+ LOG_ID = "SIP WSS IPv4 server"
15
15
  def log_id
16
16
  LOG_ID
17
17
  end
@@ -0,0 +1,21 @@
1
+ module OverSIP::WebSocket
2
+
3
+ class IPv4WssTunnelServer < WssTunnelServer
4
+
5
+ @ip_type = :ipv4
6
+ @transport = :wss
7
+ @connections = {}
8
+ @invite_server_transactions = {}
9
+ @non_invite_server_transactions = {}
10
+ @invite_client_transactions = {}
11
+ @non_invite_client_transactions = {}
12
+ @is_reliable_transport_listener = true
13
+
14
+ LOG_ID = "SIP WSS-Tunnel IPv4 server"
15
+ def log_id
16
+ LOG_ID
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -1,6 +1,6 @@
1
1
  module OverSIP::WebSocket
2
2
 
3
- class IPv6WsSipApp < WsSipApp
3
+ class IPv6WsServer < WsServer
4
4
 
5
5
  @ip_type = :ipv6
6
6
  @transport = :ws
@@ -11,11 +11,11 @@ module OverSIP::WebSocket
11
11
  @non_invite_client_transactions = {}
12
12
  @is_reliable_transport_listener = true
13
13
 
14
- LOG_ID = "WS IPv6 SIP app"
14
+ LOG_ID = "SIP WS IPv6 server"
15
15
  def log_id
16
16
  LOG_ID
17
17
  end
18
18
 
19
19
  end
20
20
 
21
- end
21
+ end
@@ -1,6 +1,6 @@
1
1
  module OverSIP::WebSocket
2
2
 
3
- class IPv6WssSipApp < WsSipApp
3
+ class IPv6WssServer < WssServer
4
4
 
5
5
  @ip_type = :ipv6
6
6
  @transport = :wss
@@ -11,7 +11,7 @@ module OverSIP::WebSocket
11
11
  @non_invite_client_transactions = {}
12
12
  @is_reliable_transport_listener = true
13
13
 
14
- LOG_ID = "WSS IPv6 SIP app"
14
+ LOG_ID = "SIP WSS IPv6 server"
15
15
  def log_id
16
16
  LOG_ID
17
17
  end
@@ -19,4 +19,3 @@ module OverSIP::WebSocket
19
19
  end
20
20
 
21
21
  end
22
-
@@ -0,0 +1,21 @@
1
+ module OverSIP::WebSocket
2
+
3
+ class IPv6WssTunnelServer < WssTunnelServer
4
+
5
+ @ip_type = :ipv6
6
+ @transport = :wss
7
+ @connections = {}
8
+ @invite_server_transactions = {}
9
+ @non_invite_server_transactions = {}
10
+ @invite_client_transactions = {}
11
+ @non_invite_client_transactions = {}
12
+ @is_reliable_transport_listener = true
13
+
14
+ LOG_ID = "SIP WSS-Tunnel IPv6 server"
15
+ def log_id
16
+ LOG_ID
17
+ end
18
+
19
+ end
20
+
21
+ end