oversip 1.3.8 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/etc/oversip.conf +28 -0
- data/ext/sip_parser/{sip_parser.c → sip_message_parser.c} +119 -119
- data/ext/sip_parser/sip_parser.h +24 -2
- data/ext/sip_parser/sip_parser_ruby.c +84 -27
- data/ext/sip_parser/sip_uri_parser.c +39699 -0
- data/lib/oversip/config.rb +14 -0
- data/lib/oversip/errors.rb +3 -0
- data/lib/oversip/modules/outbound_mangling.rb +20 -24
- data/lib/oversip/sip/client.rb +135 -11
- data/lib/oversip/sip/launcher.rb +82 -38
- data/lib/oversip/sip/name_addr.rb +8 -0
- data/lib/oversip/sip/proxy.rb +22 -13
- data/lib/oversip/sip/request.rb +31 -1
- data/lib/oversip/sip/uac.rb +9 -13
- data/lib/oversip/sip/uac_request.rb +11 -10
- data/lib/oversip/sip/uri.rb +24 -0
- data/lib/oversip/version.rb +3 -3
- data/lib/oversip/websocket/launcher.rb +64 -30
- data/lib/oversip.rb +6 -0
- data/test/test_name_addr_parser.rb +24 -0
- data/test/{test_sip_parser.rb → test_sip_message_parser.rb} +15 -1
- data/test/test_sip_uri_parser.rb +56 -0
- data/test/test_uri.rb +11 -0
- data/thirdparty/stud/stud.tar.gz +0 -0
- metadata +10 -5
data/lib/oversip/config.rb
CHANGED
@@ -32,8 +32,10 @@ module OverSIP
|
|
32
32
|
:sip_tls => false,
|
33
33
|
:enable_ipv4 => true,
|
34
34
|
:listen_ipv4 => nil,
|
35
|
+
:advertised_ipv4 => nil,
|
35
36
|
:enable_ipv6 => true,
|
36
37
|
:listen_ipv6 => nil,
|
38
|
+
:advertised_ipv6 => nil,
|
37
39
|
:listen_port => 5060,
|
38
40
|
:listen_port_tls => 5061,
|
39
41
|
:use_tls_tunnel => false,
|
@@ -49,8 +51,10 @@ module OverSIP
|
|
49
51
|
:sip_wss => false,
|
50
52
|
:enable_ipv4 => true,
|
51
53
|
:listen_ipv4 => nil,
|
54
|
+
:advertised_ipv4 => nil,
|
52
55
|
:enable_ipv6 => true,
|
53
56
|
:listen_ipv6 => nil,
|
57
|
+
:advertised_ipv6 => nil,
|
54
58
|
:listen_port => 10080,
|
55
59
|
:listen_port_tls => 10443,
|
56
60
|
:use_tls_tunnel => false,
|
@@ -85,8 +89,10 @@ module OverSIP
|
|
85
89
|
:sip_tls => :boolean,
|
86
90
|
:enable_ipv4 => :boolean,
|
87
91
|
:listen_ipv4 => :ipv4,
|
92
|
+
:advertised_ipv4 => :ipv4,
|
88
93
|
:enable_ipv6 => :boolean,
|
89
94
|
:listen_ipv6 => :ipv6,
|
95
|
+
:advertised_ipv6 => :ipv6,
|
90
96
|
:listen_port => :port,
|
91
97
|
:listen_port_tls => :port,
|
92
98
|
:use_tls_tunnel => :boolean,
|
@@ -102,8 +108,10 @@ module OverSIP
|
|
102
108
|
:sip_wss => :boolean,
|
103
109
|
:enable_ipv4 => :boolean,
|
104
110
|
:listen_ipv4 => :ipv4,
|
111
|
+
:advertised_ipv4 => :ipv4,
|
105
112
|
:enable_ipv6 => :boolean,
|
106
113
|
:listen_ipv6 => :ipv6,
|
114
|
+
:advertised_ipv6 => :ipv6,
|
107
115
|
:listen_port => :port,
|
108
116
|
:listen_port_tls => :port,
|
109
117
|
:use_tls_tunnel => :boolean,
|
@@ -280,10 +288,14 @@ module OverSIP
|
|
280
288
|
|
281
289
|
unless @configuration[:sip][:enable_ipv4]
|
282
290
|
@configuration[:sip][:listen_ipv4] = nil
|
291
|
+
@configuration[:sip][:advertised_ipv4] = nil
|
292
|
+
@configuration[:sip][:record_route_hostname_tls_ipv4] = nil
|
283
293
|
end
|
284
294
|
|
285
295
|
unless @configuration[:sip][:enable_ipv6]
|
286
296
|
@configuration[:sip][:listen_ipv6] = nil
|
297
|
+
@configuration[:sip][:advertised_ipv6] = nil
|
298
|
+
@configuration[:sip][:record_route_hostname_tls_ipv6] = nil
|
287
299
|
end
|
288
300
|
|
289
301
|
if @configuration[:websocket][:sip_ws]
|
@@ -307,10 +319,12 @@ module OverSIP
|
|
307
319
|
|
308
320
|
unless @configuration[:websocket][:enable_ipv4]
|
309
321
|
@configuration[:websocket][:listen_ipv4] = nil
|
322
|
+
@configuration[:websocket][:advertised_ipv4] = nil
|
310
323
|
end
|
311
324
|
|
312
325
|
unless @configuration[:websocket][:enable_ipv6]
|
313
326
|
@configuration[:websocket][:listen_ipv6] = nil
|
327
|
+
@configuration[:websocket][:advertised_ipv6] = nil
|
314
328
|
end
|
315
329
|
|
316
330
|
if ( @use_sip_udp_or_tcp or @use_sip_tls ) and @configuration[:sip][:listen_ipv4] == nil and @configuration[:sip][:enable_ipv4]
|
data/lib/oversip/errors.rb
CHANGED
@@ -6,15 +6,27 @@ module OverSIP::Modules
|
|
6
6
|
|
7
7
|
@log_id = "OutboundMangling module"
|
8
8
|
|
9
|
-
def self.add_outbound_to_contact
|
10
|
-
|
11
|
-
|
9
|
+
def self.add_outbound_to_contact proxy
|
10
|
+
unless proxy.is_a? ::OverSIP::SIP::Proxy
|
11
|
+
raise ::OverSIP::RuntimeError, "proxy must be a OverSIP::SIP::Proxy instance"
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
request
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
proxy.on_target do |target|
|
15
|
+
request = proxy.request
|
16
|
+
# Just act in case the request has a single Contact, its connection uses Outbound
|
17
|
+
# and no ;ov-ob param exists in Contact URI.
|
18
|
+
if request.contact and request.connection_outbound_flow_token and not request.contact.has_param? "ov-ob"
|
19
|
+
log_system_debug "performing Contact mangling (adding ;ov-ob Outbound param) for #{request.log_id}" if $oversip_debug
|
20
|
+
|
21
|
+
request.contact.set_param "ov-ob", request.connection_outbound_flow_token
|
22
|
+
|
23
|
+
proxy.on_success_response do |response|
|
24
|
+
if (contacts = response.headers["Contact"])
|
25
|
+
log_system_debug "reverting original Contact value (removing ;ov-ob Outbound param) from response" if $oversip_debug
|
26
|
+
contacts.each { |contact| contact.gsub! /;ov-ob=[_\-0-9A-Za-z]+/, "" }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
18
30
|
end
|
19
31
|
end
|
20
32
|
|
@@ -39,22 +51,6 @@ module OverSIP::Modules
|
|
39
51
|
end
|
40
52
|
end
|
41
53
|
|
42
|
-
def self.remove_outbound_from_contact message
|
43
|
-
unless message.is_a? ::OverSIP::SIP::Message
|
44
|
-
raise ::OverSIP::RuntimeError, "message must be a OverSIP::SIP::Request or OverSIP::SIP::Response"
|
45
|
-
end
|
46
|
-
|
47
|
-
if (contacts = message.headers["Contact"])
|
48
|
-
log_system_debug "reverting original Contact value (removing ;ov-ob Outbound param) for response" if $oversip_debug
|
49
|
-
contacts.each do |contact|
|
50
|
-
contact.gsub! /;ov-ob=[_\-0-9A-Za-z]+/, ""
|
51
|
-
end
|
52
|
-
return true
|
53
|
-
else
|
54
|
-
return false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
54
|
end # module OutboundMangling
|
59
55
|
|
60
56
|
end
|
data/lib/oversip/sip/client.rb
CHANGED
@@ -4,40 +4,86 @@ module OverSIP::SIP
|
|
4
4
|
|
5
5
|
include ::OverSIP::Logger
|
6
6
|
|
7
|
-
attr_reader :current_target
|
7
|
+
attr_reader :request, :current_target
|
8
8
|
|
9
9
|
def initialize proxy_profile=:default_proxy
|
10
10
|
unless (@conf = ::OverSIP.proxies[proxy_profile.to_sym])
|
11
11
|
raise ::OverSIP::RuntimeError, "proxy profile '#{proxy_profile}' is not defined"
|
12
12
|
end
|
13
|
+
|
14
|
+
@on_provisional_response_cbs = []
|
15
|
+
@on_success_response_cbs = []
|
16
|
+
@on_failure_response_cbs = []
|
17
|
+
@on_canceled_cbs = []
|
18
|
+
@on_invite_timeout_cbs = []
|
19
|
+
@on_error_cbs = []
|
20
|
+
@on_target_cbs = []
|
13
21
|
end
|
14
22
|
|
15
23
|
def on_provisional_response &block
|
16
|
-
@
|
24
|
+
@on_provisional_response_cbs << block
|
17
25
|
end
|
18
26
|
|
19
27
|
def on_success_response &block
|
20
|
-
@
|
28
|
+
@on_success_response_cbs << block
|
21
29
|
end
|
22
30
|
|
23
31
|
def on_failure_response &block
|
24
|
-
@
|
32
|
+
@on_failure_response_cbs << block
|
25
33
|
end
|
26
34
|
|
27
35
|
def on_canceled &block
|
28
|
-
@
|
36
|
+
@on_canceled_cbs << block
|
29
37
|
end
|
30
38
|
|
31
39
|
def on_invite_timeout &block
|
32
|
-
@
|
40
|
+
@on_invite_timeout_cbs << block
|
33
41
|
end
|
34
42
|
|
35
43
|
def on_error &block
|
36
|
-
@
|
44
|
+
@on_error_cbs << block
|
37
45
|
end
|
38
46
|
|
39
47
|
def on_target &block
|
40
|
-
@
|
48
|
+
@on_target_cbs << block
|
49
|
+
end
|
50
|
+
|
51
|
+
def clear_on_provisional_response
|
52
|
+
@on_provisional_response_cbs.clear
|
53
|
+
end
|
54
|
+
|
55
|
+
def clear_on_success_response
|
56
|
+
@on_success_response_cbs.clear
|
57
|
+
end
|
58
|
+
|
59
|
+
def clear_on_failure_response
|
60
|
+
@on_failure_response_cbs.clear
|
61
|
+
end
|
62
|
+
|
63
|
+
def clear_on_canceled
|
64
|
+
@on_canceled_cbs.clear
|
65
|
+
end
|
66
|
+
|
67
|
+
def clear_on_invite_timeout
|
68
|
+
@on_invite_timeout_cbs.clear
|
69
|
+
end
|
70
|
+
|
71
|
+
def clear_on_error
|
72
|
+
@on_error_cbs.clear
|
73
|
+
end
|
74
|
+
|
75
|
+
def clear_on_target
|
76
|
+
@on_target_cbs.clear
|
77
|
+
end
|
78
|
+
|
79
|
+
def clear_callbacks
|
80
|
+
@on_provisional_response_cbs.clear
|
81
|
+
@on_success_response_cbs.clear
|
82
|
+
@on_failure_response_cbs.clear
|
83
|
+
@on_canceled_cbs.clear
|
84
|
+
@on_invite_timeout_cbs.clear
|
85
|
+
@on_error_cbs.clear
|
86
|
+
@on_target_cbs.clear
|
41
87
|
end
|
42
88
|
|
43
89
|
# By calling this method the request routing is aborted, no more DNS targets are tryed,
|
@@ -104,7 +150,7 @@ module OverSIP::SIP
|
|
104
150
|
|
105
151
|
# Timer C for INVITE.
|
106
152
|
def invite_timeout
|
107
|
-
|
153
|
+
run_on_invite_timeout_cbs
|
108
154
|
end
|
109
155
|
|
110
156
|
|
@@ -112,6 +158,84 @@ module OverSIP::SIP
|
|
112
158
|
private
|
113
159
|
|
114
160
|
|
161
|
+
def run_on_provisional_response_cbs response
|
162
|
+
@on_provisional_response_cbs.each do |cb|
|
163
|
+
begin
|
164
|
+
cb.call response
|
165
|
+
rescue => e
|
166
|
+
log_system_error "error executing on_provisional_response callback:"
|
167
|
+
log_system_error e
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def run_on_success_response_cbs response
|
173
|
+
@on_success_response_cbs.each do |cb|
|
174
|
+
begin
|
175
|
+
cb.call response
|
176
|
+
rescue => e
|
177
|
+
log_system_error "error executing on_success_response callback:"
|
178
|
+
log_system_error e
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def run_on_failure_response_cbs response
|
184
|
+
@on_failure_response_cbs.each do |cb|
|
185
|
+
begin
|
186
|
+
cb.call response
|
187
|
+
rescue => e
|
188
|
+
log_system_error "error executing on_failure_response callback:"
|
189
|
+
log_system_error e
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def run_on_canceled_cbs
|
195
|
+
@on_canceled_cbs.each do |cb|
|
196
|
+
begin
|
197
|
+
cb.call
|
198
|
+
rescue => e
|
199
|
+
log_system_error "error executing on_canceled callback:"
|
200
|
+
log_system_error e
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def run_on_invite_timeout_cbs
|
206
|
+
@on_invite_timeout_cbs.each do |cb|
|
207
|
+
begin
|
208
|
+
cb.call
|
209
|
+
rescue => e
|
210
|
+
log_system_error "error executing on_invite_timeout callback:"
|
211
|
+
log_system_error e
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def run_on_error_cbs status, reason, code
|
217
|
+
@on_error_cbs.each do |cb|
|
218
|
+
begin
|
219
|
+
cb.call status, reason, code
|
220
|
+
rescue => e
|
221
|
+
log_system_error "error executing on_error callback:"
|
222
|
+
log_system_error e
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def run_on_target_cbs target
|
228
|
+
@on_target_cbs.each do |cb|
|
229
|
+
begin
|
230
|
+
cb.call target
|
231
|
+
rescue => e
|
232
|
+
log_system_error "error executing on_target callback:"
|
233
|
+
log_system_error e
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
|
115
239
|
def add_routing_headers
|
116
240
|
end
|
117
241
|
|
@@ -236,7 +360,7 @@ module OverSIP::SIP
|
|
236
360
|
end
|
237
361
|
|
238
362
|
# Call the on_target() callback if set by the user.
|
239
|
-
|
363
|
+
run_on_target_cbs target
|
240
364
|
|
241
365
|
# If the user has called to proxy.abort_routing() then stop next targets
|
242
366
|
# and call to on_error() callback.
|
@@ -296,7 +420,7 @@ module OverSIP::SIP
|
|
296
420
|
|
297
421
|
|
298
422
|
def do_dns_fail status, reason, code
|
299
|
-
|
423
|
+
run_on_error_cbs status, reason, code
|
300
424
|
end
|
301
425
|
|
302
426
|
end # class Client
|
data/lib/oversip/sip/launcher.rb
CHANGED
@@ -54,10 +54,15 @@ module OverSIP::SIP
|
|
54
54
|
case
|
55
55
|
|
56
56
|
when klass == ::OverSIP::SIP::IPv4UdpServer
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
if ::OverSIP.configuration[:sip][:advertised_ipv4]
|
58
|
+
used_uri_host = ::OverSIP.configuration[:sip][:advertised_ipv4]
|
59
|
+
else
|
60
|
+
used_uri_host = uri_ip
|
61
|
+
end
|
62
|
+
klass.via_core = "SIP/2.0/UDP #{used_uri_host}:#{port}"
|
63
|
+
klass.record_route = "<sip:#{used_uri_host}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
64
|
+
klass.outbound_record_route_fragment = "@#{used_uri_host}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
65
|
+
klass.outbound_path_fragment = "@#{used_uri_host}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
61
66
|
|
62
67
|
if enabled
|
63
68
|
::EM::open_datagram_socket(ip, port, klass) do |conn|
|
@@ -66,10 +71,15 @@ module OverSIP::SIP
|
|
66
71
|
end
|
67
72
|
|
68
73
|
when klass == ::OverSIP::SIP::IPv6UdpServer
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
74
|
+
if ::OverSIP.configuration[:sip][:advertised_ipv6]
|
75
|
+
used_uri_host = "[#{::OverSIP.configuration[:sip][:advertised_ipv6]}]"
|
76
|
+
else
|
77
|
+
used_uri_host = uri_ip
|
78
|
+
end
|
79
|
+
klass.via_core = "SIP/2.0/UDP #{used_uri_host}:#{port}"
|
80
|
+
klass.record_route = "<sip:#{used_uri_host}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
81
|
+
klass.outbound_record_route_fragment = "@#{used_uri_host}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
82
|
+
klass.outbound_path_fragment = "@#{used_uri_host}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
73
83
|
|
74
84
|
if enabled
|
75
85
|
::EM::open_datagram_socket(ip, port, klass) do |conn|
|
@@ -78,10 +88,15 @@ module OverSIP::SIP
|
|
78
88
|
end
|
79
89
|
|
80
90
|
when klass == ::OverSIP::SIP::IPv4TcpServer
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
91
|
+
if ::OverSIP.configuration[:sip][:advertised_ipv4]
|
92
|
+
used_uri_host = ::OverSIP.configuration[:sip][:advertised_ipv4]
|
93
|
+
else
|
94
|
+
used_uri_host = uri_ip
|
95
|
+
end
|
96
|
+
klass.via_core = "SIP/2.0/TCP #{used_uri_host}:#{port}"
|
97
|
+
klass.record_route = "<sip:#{used_uri_host}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
98
|
+
klass.outbound_record_route_fragment = "@#{used_uri_host}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
99
|
+
klass.outbound_path_fragment = "@#{used_uri_host}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
85
100
|
|
86
101
|
if enabled
|
87
102
|
::EM.start_server(ip, port, klass) do |conn|
|
@@ -91,10 +106,15 @@ module OverSIP::SIP
|
|
91
106
|
end
|
92
107
|
|
93
108
|
when klass == ::OverSIP::SIP::IPv6TcpServer
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
109
|
+
if ::OverSIP.configuration[:sip][:advertised_ipv6]
|
110
|
+
used_uri_host = "[#{::OverSIP.configuration[:sip][:advertised_ipv6]}]"
|
111
|
+
else
|
112
|
+
used_uri_host = uri_ip
|
113
|
+
end
|
114
|
+
klass.via_core = "SIP/2.0/TCP #{used_uri_host}:#{port}"
|
115
|
+
klass.record_route = "<sip:#{used_uri_host}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
116
|
+
klass.outbound_record_route_fragment = "@#{used_uri_host}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
117
|
+
klass.outbound_path_fragment = "@#{used_uri_host}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
98
118
|
|
99
119
|
if enabled
|
100
120
|
::EM.start_server(ip, port, klass) do |conn|
|
@@ -104,11 +124,17 @@ module OverSIP::SIP
|
|
104
124
|
end
|
105
125
|
|
106
126
|
when klass == ::OverSIP::SIP::IPv4TlsServer
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
127
|
+
if ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv4]
|
128
|
+
used_uri_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv4]
|
129
|
+
elsif ::OverSIP.configuration[:sip][:advertised_ipv4]
|
130
|
+
used_uri_host = ::OverSIP.configuration[:sip][:advertised_ipv4]
|
131
|
+
else
|
132
|
+
used_uri_host = uri_ip
|
133
|
+
end
|
134
|
+
klass.via_core = "SIP/2.0/TLS #{used_uri_host}:#{port}"
|
135
|
+
klass.record_route = "<sip:#{used_uri_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
136
|
+
klass.outbound_record_route_fragment = "@#{used_uri_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
137
|
+
klass.outbound_path_fragment = "@#{used_uri_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
112
138
|
|
113
139
|
if enabled
|
114
140
|
::EM.start_server(ip, port, klass) do |conn|
|
@@ -118,11 +144,17 @@ module OverSIP::SIP
|
|
118
144
|
end
|
119
145
|
|
120
146
|
when klass == ::OverSIP::SIP::IPv6TlsServer
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
147
|
+
if ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv6]
|
148
|
+
used_uri_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv6]
|
149
|
+
elsif ::OverSIP.configuration[:sip][:advertised_ipv6]
|
150
|
+
used_uri_host = "[#{::OverSIP.configuration[:sip][:advertised_ipv6]}]"
|
151
|
+
else
|
152
|
+
used_uri_host = uri_ip
|
153
|
+
end
|
154
|
+
klass.via_core = "SIP/2.0/TLS #{used_uri_host}:#{port}"
|
155
|
+
klass.record_route = "<sip:#{used_uri_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
156
|
+
klass.outbound_record_route_fragment = "@#{used_uri_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
157
|
+
klass.outbound_path_fragment = "@#{used_uri_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
126
158
|
|
127
159
|
if enabled
|
128
160
|
::EM.start_server(ip, port, klass) do |conn|
|
@@ -132,12 +164,18 @@ module OverSIP::SIP
|
|
132
164
|
end
|
133
165
|
|
134
166
|
when klass == ::OverSIP::SIP::IPv4TlsTunnelServer
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
167
|
+
if ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv4]
|
168
|
+
used_uri_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv4]
|
169
|
+
elsif ::OverSIP.configuration[:sip][:advertised_ipv4]
|
170
|
+
used_uri_host = ::OverSIP.configuration[:sip][:advertised_ipv4]
|
171
|
+
else
|
172
|
+
used_uri_host = uri_virtual_ip
|
173
|
+
end
|
174
|
+
klass.via_core = "SIP/2.0/TLS #{used_uri_host}:#{virtual_port}"
|
175
|
+
klass.record_route = "<sip:#{used_uri_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
176
|
+
klass.outbound_record_route_fragment = "@#{used_uri_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
177
|
+
klass.outbound_path_fragment = "@#{used_uri_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
178
|
+
|
141
179
|
if enabled
|
142
180
|
::EM.start_server(ip, port, klass) do |conn|
|
143
181
|
conn.post_connection
|
@@ -146,12 +184,18 @@ module OverSIP::SIP
|
|
146
184
|
end
|
147
185
|
|
148
186
|
when klass == ::OverSIP::SIP::IPv6TlsTunnelServer
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
187
|
+
if ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv6]
|
188
|
+
used_uri_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv6]
|
189
|
+
elsif ::OverSIP.configuration[:sip][:advertised_ipv6]
|
190
|
+
used_uri_host = "[#{::OverSIP.configuration[:sip][:advertised_ipv6]}]"
|
191
|
+
else
|
192
|
+
used_uri_host = uri_virtual_ip
|
193
|
+
end
|
194
|
+
klass.via_core = "SIP/2.0/TLS #{used_uri_host}:#{virtual_port}"
|
195
|
+
klass.record_route = "<sip:#{used_uri_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
196
|
+
klass.outbound_record_route_fragment = "@#{used_uri_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
197
|
+
klass.outbound_path_fragment = "@#{used_uri_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
198
|
+
|
155
199
|
if enabled
|
156
200
|
::EM.start_server(ip, port, klass) do |conn|
|
157
201
|
conn.post_connection
|
@@ -4,6 +4,14 @@ module OverSIP::SIP
|
|
4
4
|
|
5
5
|
attr_reader :display_name
|
6
6
|
|
7
|
+
|
8
|
+
def self.parse value
|
9
|
+
name_addr = ::OverSIP::SIP::MessageParser.parse_uri value, true
|
10
|
+
raise ::OverSIP::ParsingError, "invalid NameAddr #{value.inspect}" unless name_addr.is_a? (::OverSIP::SIP::NameAddr)
|
11
|
+
name_addr
|
12
|
+
end
|
13
|
+
|
14
|
+
|
7
15
|
def initialize display_name=nil, scheme=:sip, user=nil, host=nil, port=nil
|
8
16
|
@display_name = display_name
|
9
17
|
@scheme = scheme.to_sym
|
data/lib/oversip/sip/proxy.rb
CHANGED
@@ -2,9 +2,18 @@ module OverSIP::SIP
|
|
2
2
|
|
3
3
|
class Proxy < Client
|
4
4
|
|
5
|
-
# If
|
6
|
-
def drop_response
|
5
|
+
# If a SIP response is given then this method may offer other features such as replying 199.
|
6
|
+
def drop_response response=nil
|
7
7
|
@drop_response = true
|
8
|
+
|
9
|
+
# RFC 6228 (199 response).
|
10
|
+
# http://tools.ietf.org/html/rfc6228#section-6
|
11
|
+
if response and response.status_code >= 300 and
|
12
|
+
@request.sip_method == :INVITE and
|
13
|
+
@request.supported and @request.supported.include?("199")
|
14
|
+
|
15
|
+
@request.send :reply_199, response
|
16
|
+
end
|
8
17
|
end
|
9
18
|
|
10
19
|
|
@@ -45,7 +54,7 @@ module OverSIP::SIP
|
|
45
54
|
unless @request.sip_method == :ACK
|
46
55
|
log_system_debug "flow failed" if $oversip_debug
|
47
56
|
|
48
|
-
|
57
|
+
run_on_error_cbs 430, "Flow Failed", :flow_failed
|
49
58
|
unless @drop_response
|
50
59
|
@request.reply 430, "Flow Failed"
|
51
60
|
else
|
@@ -116,9 +125,9 @@ module OverSIP::SIP
|
|
116
125
|
|
117
126
|
if @request.server_transaction.valid_response? response.status_code
|
118
127
|
if response.status_code < 200 && ! @canceled
|
119
|
-
|
128
|
+
run_on_provisional_response_cbs response
|
120
129
|
elsif response.status_code >= 200 && response.status_code <= 299
|
121
|
-
|
130
|
+
run_on_success_response_cbs response
|
122
131
|
elsif response.status_code >= 300 && ! @canceled
|
123
132
|
if response.status_code == 503
|
124
133
|
if @conf[:dns_failover_on_503]
|
@@ -127,10 +136,10 @@ module OverSIP::SIP
|
|
127
136
|
else
|
128
137
|
# If the response is 503 convert it into 500 (RFC 3261 16.7).
|
129
138
|
response.status_code = 500
|
130
|
-
|
139
|
+
run_on_failure_response_cbs response
|
131
140
|
end
|
132
141
|
else
|
133
|
-
|
142
|
+
run_on_failure_response_cbs response
|
134
143
|
end
|
135
144
|
end
|
136
145
|
end
|
@@ -148,7 +157,7 @@ module OverSIP::SIP
|
|
148
157
|
log_system_debug "server transaction canceled, cancelling pending client transaction" if $oversip_debug
|
149
158
|
|
150
159
|
@canceled = true
|
151
|
-
|
160
|
+
run_on_canceled_cbs
|
152
161
|
|
153
162
|
@client_transaction.do_cancel cancel
|
154
163
|
end
|
@@ -156,7 +165,7 @@ module OverSIP::SIP
|
|
156
165
|
|
157
166
|
# Timer C for INVITE (method called by the client transaction).
|
158
167
|
def invite_timeout
|
159
|
-
|
168
|
+
run_on_invite_timeout_cbs
|
160
169
|
|
161
170
|
unless @drop_response
|
162
171
|
@request.reply 408, "INVITE Timeout"
|
@@ -275,9 +284,9 @@ module OverSIP::SIP
|
|
275
284
|
|
276
285
|
|
277
286
|
def no_more_targets status, reason, full_response, code
|
278
|
-
# If we have received a [3456]XX response from downstream then run @
|
287
|
+
# If we have received a [3456]XX response from downstream then run @on_failure_response_cbs.
|
279
288
|
if full_response
|
280
|
-
|
289
|
+
run_on_failure_response_cbs full_response
|
281
290
|
unless @drop_response
|
282
291
|
# If the response is 503 convert it into 500 (RFC 3261 16.7).
|
283
292
|
full_response.status_code = 500 if full_response.status_code == 503
|
@@ -288,7 +297,7 @@ module OverSIP::SIP
|
|
288
297
|
|
289
298
|
# If not, generate the response according to the given status and reason.
|
290
299
|
else
|
291
|
-
|
300
|
+
run_on_error_cbs status, reason, code
|
292
301
|
unless @drop_response
|
293
302
|
@request.reply status, reason
|
294
303
|
else
|
@@ -300,7 +309,7 @@ module OverSIP::SIP
|
|
300
309
|
|
301
310
|
|
302
311
|
def do_dns_fail status, reason, code
|
303
|
-
|
312
|
+
run_on_error_cbs status, reason, code
|
304
313
|
|
305
314
|
unless @drop_response
|
306
315
|
@request.reply status, reason unless @request.sip_method == :ACK
|