oversip 1.2.1 → 1.3.0.dev1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +28 -4
- data/bin/oversip +1 -1
- data/etc/proxies.conf +10 -0
- data/etc/server.rb +13 -9
- data/ext/utils/haproxy_protocol.c +0 -3
- data/ext/utils/outbound_utils.c +1 -1
- data/ext/utils/utils_ruby.c +0 -1
- data/ext/websocket_http_parser/ws_http_parser.c +940 -1903
- data/ext/websocket_http_parser/ws_http_parser.h +1 -0
- data/lib/oversip/config_validators.rb +2 -2
- data/lib/oversip/launcher.rb +275 -240
- data/lib/oversip/master_process.rb +7 -2
- data/lib/oversip/proxies_config.rb +8 -1
- data/lib/oversip/sip/client.rb +304 -0
- data/lib/oversip/sip/client_transaction.rb +31 -36
- data/lib/oversip/sip/core.rb +7 -4
- data/lib/oversip/sip/launcher.rb +30 -30
- data/lib/oversip/sip/listeners/connection.rb +4 -0
- data/lib/oversip/sip/listeners/ipv4_tcp_server.rb +1 -0
- data/lib/oversip/sip/listeners/ipv4_tls_server.rb +1 -0
- data/lib/oversip/sip/listeners/ipv4_tls_tunnel_server.rb +1 -0
- data/lib/oversip/sip/listeners/ipv4_udp_server.rb +1 -0
- data/lib/oversip/sip/listeners/ipv6_tcp_server.rb +1 -0
- data/lib/oversip/sip/listeners/ipv6_tls_server.rb +1 -0
- data/lib/oversip/sip/listeners/ipv6_tls_tunnel_server.rb +1 -0
- data/lib/oversip/sip/listeners/ipv6_udp_server.rb +1 -0
- data/lib/oversip/sip/listeners/tcp_client.rb +26 -0
- data/lib/oversip/sip/listeners/tcp_connection.rb +7 -1
- data/lib/oversip/sip/listeners/tcp_server.rb +1 -1
- data/lib/oversip/sip/listeners/tls_client.rb +28 -24
- data/lib/oversip/sip/listeners/tls_server.rb +25 -8
- data/lib/oversip/sip/listeners/tls_tunnel_connection.rb +1 -24
- data/lib/oversip/sip/message.rb +2 -2
- data/lib/oversip/sip/message_processor.rb +23 -13
- data/lib/oversip/sip/{grammar/name_addr.rb → name_addr.rb} +11 -0
- data/lib/oversip/sip/proxy.rb +53 -227
- data/lib/oversip/sip/request.rb +15 -11
- data/lib/oversip/sip/response.rb +3 -3
- data/lib/oversip/sip/rfc3263.rb +2 -3
- data/lib/oversip/sip/tags.rb +1 -1
- data/lib/oversip/sip/transport_manager.rb +6 -5
- data/lib/oversip/sip/uac.rb +93 -0
- data/lib/oversip/sip/uac_request.rb +82 -0
- data/lib/oversip/sip/{grammar/uri.rb → uri.rb} +22 -0
- data/lib/oversip/version.rb +3 -3
- data/lib/oversip/websocket/launcher.rb +25 -25
- data/lib/oversip/websocket/listeners/connection.rb +4 -0
- data/lib/oversip/websocket/listeners/ipv4_ws_server.rb +1 -0
- data/lib/oversip/websocket/listeners/ipv4_wss_server.rb +1 -0
- data/lib/oversip/websocket/listeners/ipv4_wss_tunnel_server.rb +1 -0
- data/lib/oversip/websocket/listeners/ipv6_ws_server.rb +1 -0
- data/lib/oversip/websocket/listeners/ipv6_wss_server.rb +1 -0
- data/lib/oversip/websocket/listeners/ipv6_wss_tunnel_server.rb +1 -0
- data/lib/oversip/websocket/listeners/ws_server.rb +55 -26
- data/lib/oversip/websocket/listeners/wss_server.rb +26 -9
- data/lib/oversip/websocket/listeners/wss_tunnel_server.rb +14 -11
- data/lib/oversip/websocket/ws_framing.rb +6 -2
- data/lib/oversip.rb +3 -1
- data/test/test_http_parser.rb +3 -3
- data/test/test_uri.rb +18 -12
- metadata +91 -77
data/lib/oversip/sip/launcher.rb
CHANGED
@@ -28,23 +28,23 @@ module OverSIP::SIP
|
|
28
28
|
klass = case transport
|
29
29
|
when :udp
|
30
30
|
case ip_type
|
31
|
-
when :ipv4 ; OverSIP::SIP::IPv4UdpServer
|
32
|
-
when :ipv6 ; OverSIP::SIP::IPv6UdpServer
|
31
|
+
when :ipv4 ; ::OverSIP::SIP::IPv4UdpServer
|
32
|
+
when :ipv6 ; ::OverSIP::SIP::IPv6UdpServer
|
33
33
|
end
|
34
34
|
when :tcp
|
35
35
|
case ip_type
|
36
|
-
when :ipv4 ; OverSIP::SIP::IPv4TcpServer
|
37
|
-
when :ipv6 ; OverSIP::SIP::IPv6TcpServer
|
36
|
+
when :ipv4 ; ::OverSIP::SIP::IPv4TcpServer
|
37
|
+
when :ipv6 ; ::OverSIP::SIP::IPv6TcpServer
|
38
38
|
end
|
39
39
|
when :tls
|
40
40
|
case ip_type
|
41
|
-
when :ipv4 ; OverSIP::SIP::IPv4TlsServer
|
42
|
-
when :ipv6 ; OverSIP::SIP::IPv6TlsServer
|
41
|
+
when :ipv4 ; ::OverSIP::SIP::IPv4TlsServer
|
42
|
+
when :ipv6 ; ::OverSIP::SIP::IPv6TlsServer
|
43
43
|
end
|
44
44
|
when :tls_tunnel
|
45
45
|
case ip_type
|
46
|
-
when :ipv4 ; OverSIP::SIP::IPv4TlsTunnelServer
|
47
|
-
when :ipv6 ; OverSIP::SIP::IPv6TlsTunnelServer
|
46
|
+
when :ipv4 ; ::OverSIP::SIP::IPv4TlsTunnelServer
|
47
|
+
when :ipv6 ; ::OverSIP::SIP::IPv6TlsTunnelServer
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -53,57 +53,57 @@ module OverSIP::SIP
|
|
53
53
|
|
54
54
|
case
|
55
55
|
|
56
|
-
when klass == OverSIP::SIP::IPv4UdpServer
|
56
|
+
when klass == ::OverSIP::SIP::IPv4UdpServer
|
57
57
|
klass.via_core = "SIP/2.0/UDP #{uri_ip}:#{port}"
|
58
58
|
klass.record_route = "<sip:#{uri_ip}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
59
59
|
klass.outbound_record_route_fragment = "@#{uri_ip}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
60
60
|
klass.outbound_path_fragment = "@#{uri_ip}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
61
61
|
|
62
62
|
if enabled
|
63
|
-
EM::open_datagram_socket(ip, port, klass) do |conn|
|
63
|
+
::EM::open_datagram_socket(ip, port, klass) do |conn|
|
64
64
|
klass.connections = conn
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
when klass == OverSIP::SIP::IPv6UdpServer
|
68
|
+
when klass == ::OverSIP::SIP::IPv6UdpServer
|
69
69
|
klass.via_core = "SIP/2.0/UDP #{uri_ip}:#{port}"
|
70
70
|
klass.record_route = "<sip:#{uri_ip}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
71
71
|
klass.outbound_record_route_fragment = "@#{uri_ip}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
72
72
|
klass.outbound_path_fragment = "@#{uri_ip}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
73
73
|
|
74
74
|
if enabled
|
75
|
-
EM::open_datagram_socket(ip, port, klass) do |conn|
|
75
|
+
::EM::open_datagram_socket(ip, port, klass) do |conn|
|
76
76
|
klass.connections = conn
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
when klass == OverSIP::SIP::IPv4TcpServer
|
80
|
+
when klass == ::OverSIP::SIP::IPv4TcpServer
|
81
81
|
klass.via_core = "SIP/2.0/TCP #{uri_ip}:#{port}"
|
82
82
|
klass.record_route = "<sip:#{uri_ip}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
83
83
|
klass.outbound_record_route_fragment = "@#{uri_ip}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
84
84
|
klass.outbound_path_fragment = "@#{uri_ip}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
85
85
|
|
86
86
|
if enabled
|
87
|
-
EM.start_server(ip, port, klass) do |conn|
|
87
|
+
::EM.start_server(ip, port, klass) do |conn|
|
88
88
|
conn.post_connection
|
89
|
-
conn.set_comm_inactivity_timeout
|
89
|
+
conn.set_comm_inactivity_timeout 300
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
when klass == OverSIP::SIP::IPv6TcpServer
|
93
|
+
when klass == ::OverSIP::SIP::IPv6TcpServer
|
94
94
|
klass.via_core = "SIP/2.0/TCP #{uri_ip}:#{port}"
|
95
95
|
klass.record_route = "<sip:#{uri_ip}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
96
96
|
klass.outbound_record_route_fragment = "@#{uri_ip}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
97
97
|
klass.outbound_path_fragment = "@#{uri_ip}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
98
98
|
|
99
99
|
if enabled
|
100
|
-
EM.start_server(ip, port, klass) do |conn|
|
100
|
+
::EM.start_server(ip, port, klass) do |conn|
|
101
101
|
conn.post_connection
|
102
|
-
conn.set_comm_inactivity_timeout
|
102
|
+
conn.set_comm_inactivity_timeout 300
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
when klass == OverSIP::SIP::IPv4TlsServer
|
106
|
+
when klass == ::OverSIP::SIP::IPv4TlsServer
|
107
107
|
klass.via_core = "SIP/2.0/TLS #{uri_ip}:#{port}"
|
108
108
|
rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv4] || uri_ip
|
109
109
|
klass.record_route = "<sip:#{rr_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
@@ -111,13 +111,13 @@ module OverSIP::SIP
|
|
111
111
|
klass.outbound_path_fragment = "@#{rr_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
112
112
|
|
113
113
|
if enabled
|
114
|
-
EM.start_server(ip, port, klass) do |conn|
|
114
|
+
::EM.start_server(ip, port, klass) do |conn|
|
115
115
|
conn.post_connection
|
116
|
-
conn.set_comm_inactivity_timeout
|
116
|
+
conn.set_comm_inactivity_timeout 300
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
when klass == OverSIP::SIP::IPv6TlsServer
|
120
|
+
when klass == ::OverSIP::SIP::IPv6TlsServer
|
121
121
|
klass.via_core = "SIP/2.0/TLS #{uri_ip}:#{port}"
|
122
122
|
rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv6] || uri_ip
|
123
123
|
klass.record_route = "<sip:#{rr_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
@@ -125,13 +125,13 @@ module OverSIP::SIP
|
|
125
125
|
klass.outbound_path_fragment = "@#{rr_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
126
126
|
|
127
127
|
if enabled
|
128
|
-
EM.start_server(ip, port, klass) do |conn|
|
128
|
+
::EM.start_server(ip, port, klass) do |conn|
|
129
129
|
conn.post_connection
|
130
|
-
conn.set_comm_inactivity_timeout
|
130
|
+
conn.set_comm_inactivity_timeout 300
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
when klass == OverSIP::SIP::IPv4TlsTunnelServer
|
134
|
+
when klass == ::OverSIP::SIP::IPv4TlsTunnelServer
|
135
135
|
klass.via_core = "SIP/2.0/TLS #{uri_virtual_ip}:#{virtual_port}"
|
136
136
|
rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv4] || uri_virtual_ip
|
137
137
|
klass.record_route = "<sip:#{rr_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
@@ -139,13 +139,13 @@ module OverSIP::SIP
|
|
139
139
|
klass.outbound_path_fragment = "@#{rr_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
140
140
|
|
141
141
|
if enabled
|
142
|
-
EM.start_server(ip, port, klass) do |conn|
|
142
|
+
::EM.start_server(ip, port, klass) do |conn|
|
143
143
|
conn.post_connection
|
144
|
-
conn.set_comm_inactivity_timeout
|
144
|
+
conn.set_comm_inactivity_timeout 300
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
when klass == OverSIP::SIP::IPv6TlsTunnelServer
|
148
|
+
when klass == ::OverSIP::SIP::IPv6TlsTunnelServer
|
149
149
|
klass.via_core = "SIP/2.0/TLS #{uri_virtual_ip}:#{virtual_port}"
|
150
150
|
rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv6] || uri_virtual_ip
|
151
151
|
klass.record_route = "<sip:#{rr_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
@@ -153,9 +153,9 @@ module OverSIP::SIP
|
|
153
153
|
klass.outbound_path_fragment = "@#{rr_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
154
154
|
|
155
155
|
if enabled
|
156
|
-
EM.start_server(ip, port, klass) do |conn|
|
156
|
+
::EM.start_server(ip, port, klass) do |conn|
|
157
157
|
conn.post_connection
|
158
|
-
conn.set_comm_inactivity_timeout
|
158
|
+
conn.set_comm_inactivity_timeout 300
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
@@ -2,6 +2,10 @@ module OverSIP::SIP
|
|
2
2
|
|
3
3
|
class TcpClient < TcpConnection
|
4
4
|
|
5
|
+
class << self
|
6
|
+
attr_reader :server_class
|
7
|
+
end
|
8
|
+
|
5
9
|
attr_reader :connected
|
6
10
|
attr_reader :pending_client_transactions
|
7
11
|
|
@@ -66,6 +70,28 @@ module OverSIP::SIP
|
|
66
70
|
@connected = false
|
67
71
|
end
|
68
72
|
|
73
|
+
|
74
|
+
# For the case in which OverSIP receives a SIP request from a connection open by OverSIP.
|
75
|
+
def record_route
|
76
|
+
@record_route and return @record_route
|
77
|
+
|
78
|
+
server_class = self.class.server_class
|
79
|
+
local_port, local_ip = ::Socket.unpack_sockaddr_in(get_sockname)
|
80
|
+
|
81
|
+
case
|
82
|
+
when server_class == ::OverSIP::SIP::IPv4TcpServer
|
83
|
+
uri_ip = local_ip
|
84
|
+
when server_class == ::OverSIP::SIP::IPv6TcpServer
|
85
|
+
uri_ip = "[#{local_ip}]"
|
86
|
+
when server_class == ::OverSIP::SIP::IPv4TlsServer
|
87
|
+
uri_ip = local_ip
|
88
|
+
when server_class == ::OverSIP::SIP::IPv6TlsServer
|
89
|
+
uri_ip = "[#{local_ip}]"
|
90
|
+
end
|
91
|
+
|
92
|
+
@record_route = "<sip:#{uri_ip}:#{local_port};transport=#{server_class.transport.to_s};lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
93
|
+
end
|
94
|
+
|
69
95
|
end
|
70
96
|
|
71
97
|
end
|
@@ -21,6 +21,13 @@ module OverSIP::SIP
|
|
21
21
|
def receive_data data
|
22
22
|
@state == :ignore and return
|
23
23
|
@buffer << data
|
24
|
+
@state == :waiting_for_on_client_tls_handshake and return
|
25
|
+
|
26
|
+
process_received_data
|
27
|
+
end
|
28
|
+
|
29
|
+
def process_received_data
|
30
|
+
@state == :ignore and return
|
24
31
|
|
25
32
|
while (case @state
|
26
33
|
when :init
|
@@ -52,7 +59,6 @@ module OverSIP::SIP
|
|
52
59
|
false
|
53
60
|
end)
|
54
61
|
end # while
|
55
|
-
|
56
62
|
end
|
57
63
|
|
58
64
|
def parse_headers
|
@@ -28,7 +28,7 @@ module OverSIP::SIP
|
|
28
28
|
set_sock_opt Socket::SOL_TCP, Socket::TCP_KEEPINTVL, ::OverSIP::SIP.tcp_keepalive_interval # Interval between TCP pings.
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
log_system_debug("connection opened from " << remote_desc) if $oversip_debug
|
32
32
|
end
|
33
33
|
|
34
34
|
def remote_desc force=nil
|
@@ -55,40 +55,44 @@ module OverSIP::SIP
|
|
55
55
|
|
56
56
|
# This is called after all the calls to ssl_verify_peer().
|
57
57
|
def ssl_handshake_completed
|
58
|
-
|
58
|
+
log_system_debug("TLS connection established to " << remote_desc) if $oversip_debug
|
59
59
|
|
60
60
|
# @connected in TlsClient means "TLS connection" rather than
|
61
61
|
# just "TCP connection".
|
62
62
|
@connected = true
|
63
63
|
@timer_tls_handshake.cancel if @timer_tls_handshake
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
65
|
+
# Run OverSIP::SipEvents.on_server_tls_handshake.
|
66
|
+
::Fiber.new do
|
67
|
+
if @callback_on_server_tls_handshake
|
68
|
+
log_system_debug "running OverSIP::SipEvents.on_server_tls_handshake()..." if $oversip_debug
|
69
|
+
begin
|
70
|
+
::OverSIP::SipEvents.on_server_tls_handshake self, @server_pems
|
71
|
+
rescue ::Exception => e
|
72
|
+
log_system_error "error calling OverSIP::SipEvents.on_server_tls_handshake():"
|
73
|
+
log_system_error e
|
74
|
+
close_connection
|
75
|
+
end
|
73
76
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
client_transaction
|
77
|
+
# If the user or peer has closed the connection in the on_server_tls_handshake() callback
|
78
|
+
# then notify pending transactions.
|
79
|
+
if @local_closed or error?
|
80
|
+
log_system_debug "connection closed, aborting" if $oversip_debug
|
81
|
+
@pending_client_transactions.each do |client_transaction|
|
82
|
+
client_transaction.tls_validation_failed
|
83
|
+
end
|
84
|
+
@pending_client_transactions.clear
|
85
|
+
@pending_messages.clear
|
86
|
+
@state = :ignore
|
79
87
|
end
|
80
|
-
@pending_client_transactions.clear
|
81
|
-
@pending_messages.clear
|
82
|
-
@state = :ignore
|
83
|
-
return
|
84
88
|
end
|
85
|
-
end
|
86
89
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
@pending_client_transactions.clear
|
91
|
+
@pending_messages.each do |msg|
|
92
|
+
send_data msg
|
93
|
+
end
|
94
|
+
@pending_messages.clear
|
95
|
+
end.resume
|
92
96
|
end
|
93
97
|
|
94
98
|
def unbind cause=nil
|
@@ -51,20 +51,37 @@ module OverSIP::SIP
|
|
51
51
|
@timer_tls_handshake.cancel if @timer_tls_handshake
|
52
52
|
|
53
53
|
if ::OverSIP::SIP.callback_on_client_tls_handshake
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
# Set the state to :waiting_for_on_client_tls_handshake so data received after TLS handshake but before
|
55
|
+
# user callback validation is just stored.
|
56
|
+
@state = :waiting_for_on_client_tls_handshake
|
57
|
+
|
58
|
+
# Run OverSIP::SipEvents.on_client_tls_handshake.
|
59
|
+
::Fiber.new do
|
60
|
+
begin
|
61
|
+
log_system_debug "running OverSIP::SipEvents.on_client_tls_handshake()..." if $oversip_debug
|
62
|
+
::OverSIP::SipEvents.on_client_tls_handshake self, @client_pems
|
63
|
+
# If the user of the peer has not closed the connection then continue.
|
64
|
+
unless @local_closed or error?
|
65
|
+
@state = :init
|
66
|
+
# Call process_received_data() to process possible data received in the meanwhile.
|
67
|
+
process_received_data
|
68
|
+
else
|
69
|
+
log_system_debug "connection closed, aborting" if $oversip_debug
|
70
|
+
end
|
71
|
+
|
72
|
+
rescue ::Exception => e
|
73
|
+
log_system_error "error calling OverSIP::SipEvents.on_client_tls_handshake():"
|
74
|
+
log_system_error e
|
75
|
+
close_connection
|
76
|
+
end
|
77
|
+
end.resume
|
61
78
|
end
|
62
79
|
end
|
63
80
|
|
64
81
|
|
65
82
|
def unbind cause=nil
|
66
|
-
super
|
67
83
|
@timer_tls_handshake.cancel if @timer_tls_handshake
|
84
|
+
super
|
68
85
|
end
|
69
86
|
|
70
87
|
end
|
@@ -6,9 +6,8 @@ module OverSIP::SIP
|
|
6
6
|
# (avoid DoS attacks).
|
7
7
|
HEADERS_MAX_SIZE = 16384
|
8
8
|
|
9
|
-
def
|
9
|
+
def process_received_data
|
10
10
|
@state == :ignore and return
|
11
|
-
@buffer << data
|
12
11
|
|
13
12
|
while (case @state
|
14
13
|
when :init
|
@@ -25,9 +24,6 @@ module OverSIP::SIP
|
|
25
24
|
when :haproxy_protocol
|
26
25
|
parse_haproxy_protocol
|
27
26
|
|
28
|
-
#when :client_pems
|
29
|
-
# parse_client_pems
|
30
|
-
|
31
27
|
when :headers
|
32
28
|
parse_headers
|
33
29
|
|
@@ -87,25 +83,6 @@ module OverSIP::SIP
|
|
87
83
|
end
|
88
84
|
end
|
89
85
|
|
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
|
108
|
-
|
109
86
|
end
|
110
87
|
|
111
88
|
end
|
data/lib/oversip/sip/message.rb
CHANGED
@@ -110,7 +110,7 @@ module OverSIP::SIP
|
|
110
110
|
def set_header name, value
|
111
111
|
@headers[MessageParser.headerize(name)] =
|
112
112
|
case value
|
113
|
-
when Array
|
113
|
+
when ::Array
|
114
114
|
value
|
115
115
|
else
|
116
116
|
[ value.to_s ]
|
@@ -135,7 +135,7 @@ module OverSIP::SIP
|
|
135
135
|
# _value_ must be a string.
|
136
136
|
def insert_header name, value
|
137
137
|
if hdr = @headers[k=MessageParser.headerize(name)]
|
138
|
-
hdr.
|
138
|
+
hdr.unshift value.to_s
|
139
139
|
else
|
140
140
|
#@headers[k] = [ value.to_s ]
|
141
141
|
# NOTE: If the header name doesn't already exist in the mesage, insert
|
@@ -76,6 +76,17 @@ 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
|
+
# Check OverSIP status.
|
80
|
+
unless ::OverSIP.status == :running
|
81
|
+
case ::OverSIP.status
|
82
|
+
when :loading
|
83
|
+
@msg.reply 500, "Server Still Loading", [ "Retry-After: 5" ]
|
84
|
+
when :terminating
|
85
|
+
@msg.reply 500, "Server is Being Stopped"
|
86
|
+
end
|
87
|
+
return
|
88
|
+
end
|
89
|
+
|
79
90
|
# Create the antiloop identifier for this request.
|
80
91
|
@msg.antiloop_id = ::OverSIP::SIP::Tags.create_antiloop_id(@msg)
|
81
92
|
|
@@ -89,14 +100,16 @@ module OverSIP::SIP
|
|
89
100
|
@msg.tvars = {}
|
90
101
|
@msg.cvars = @msg.connection.cvars
|
91
102
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
103
|
+
# Run OverSIP::SipEvents.on_request within a fiber.
|
104
|
+
::Fiber.new do
|
105
|
+
begin
|
106
|
+
::OverSIP::SipEvents.on_request @msg
|
107
|
+
rescue ::Exception => e
|
108
|
+
log_system_error "error calling OverSIP::SipEvents.on_request() => 500:"
|
109
|
+
log_system_error e
|
110
|
+
@msg.reply 500, "Internal Error", ["Content-Type: text/plain"], "#{e.class}: #{e.message}"
|
111
|
+
end
|
112
|
+
end.resume
|
100
113
|
end
|
101
114
|
end
|
102
115
|
private :process_request
|
@@ -106,9 +119,6 @@ module OverSIP::SIP
|
|
106
119
|
def process_response
|
107
120
|
case @msg.sip_method
|
108
121
|
when :INVITE
|
109
|
-
### TODO: Esto va a petar cuando tenga una clase que hereda de, p.ej, IPv4TcpServer que se llame xxxClient,
|
110
|
-
# ya que en ella no existirá @invite_client_transactions. Tengo que hacer que su @invite_client_transactions
|
111
|
-
# se rellene al de la clase padre al hacer el load de las clases.
|
112
122
|
if client_transaction = @msg.connection.class.invite_client_transactions[@msg.via_branch_id]
|
113
123
|
client_transaction.receive_response(@msg)
|
114
124
|
return
|
@@ -136,7 +146,7 @@ module OverSIP::SIP
|
|
136
146
|
|
137
147
|
when :INVITE
|
138
148
|
if server_transaction = @msg.connection.class.invite_server_transactions[@msg.via_branch_id]
|
139
|
-
# If the retranmission arrives via a different connection (for TCP/TLS) then use
|
149
|
+
# If the retranmission arrives via a different connection (for TCP/TLS/WS/WSS) then use
|
140
150
|
# the new one.
|
141
151
|
if @msg.connection == server_transaction.request.connection
|
142
152
|
log_system_debug "INVITE retransmission received" if $oversip_debug
|
@@ -155,7 +165,7 @@ module OverSIP::SIP
|
|
155
165
|
server_transaction.receive_ack
|
156
166
|
return true
|
157
167
|
# Absorb ACK for statelessly generated final responses by us.
|
158
|
-
elsif OverSIP::SIP::Tags.check_totag_for_sl_reply(@msg.to_tag)
|
168
|
+
elsif ::OverSIP::SIP::Tags.check_totag_for_sl_reply(@msg.to_tag)
|
159
169
|
log_system_debug "absorving ACK for a stateless final response" if $oversip_debug
|
160
170
|
return true
|
161
171
|
else
|
@@ -4,6 +4,17 @@ module OverSIP::SIP
|
|
4
4
|
|
5
5
|
attr_reader :display_name
|
6
6
|
|
7
|
+
def initialize display_name=nil, scheme=:sip, user=nil, host=nil, port=nil
|
8
|
+
@display_name = display_name
|
9
|
+
@scheme = scheme.to_sym
|
10
|
+
@user = user
|
11
|
+
@host = host
|
12
|
+
@host_type = ::OverSIP::Utils.ip_type(host) || :domain if host
|
13
|
+
@port = port
|
14
|
+
|
15
|
+
@name_addr_modified = true
|
16
|
+
end
|
17
|
+
|
7
18
|
def display_name= value
|
8
19
|
@display_name = value
|
9
20
|
@name_addr_modified = true
|