Class: OverSIP::SIP::Client
- Inherits:
-
Object
- Object
- OverSIP::SIP::Client
show all
- Includes:
- Logger
- Defined in:
- lib/oversip/sip/client.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logger
close, fg_system_msg2str, init_logger_mq, load_methods, #log_id, syslog_system_msg2str, syslog_user_msg2str
Constructor Details
#initialize(proxy_profile = :default_proxy) ⇒ Client
Returns a new instance of Client.
9
10
11
12
13
|
# File 'lib/oversip/sip/client.rb', line 9
def initialize proxy_profile=:default_proxy
unless (@conf = ::OverSIP.proxies[proxy_profile.to_sym])
raise ::OverSIP::RuntimeError, "proxy profile '#{proxy_profile}' is not defined"
end
end
|
Instance Attribute Details
#current_target ⇒ Object
Returns the value of attribute current_target.
7
8
9
|
# File 'lib/oversip/sip/client.rb', line 7
def current_target
@current_target
end
|
Instance Method Details
#abort_routing ⇒ Object
By calling this method the request routing is aborted, no more DNS targets are tryed, a local 403 response is generated and on_error() callback is called with status 403.
45
46
47
|
# File 'lib/oversip/sip/client.rb', line 45
def abort_routing
@aborted = true
end
|
#add_target_to_blacklist(timeout = nil, status_code = 403, reason_phrase = "Destination Blacklisted") ⇒ Object
Manually insert the last target into the blacklist. Optionally a timeout value can be given (otherwise the proxy blacklist_time is used). The timeout must be between 2 and 600 seconds. Also the SIP code and reason can be passed.
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/oversip/sip/client.rb', line 52
def add_target_to_blacklist timeout=nil, status_code=403, reason_phrase="Destination Blacklisted"
return false unless @current_target
if timeout
timeout = timeout.to_i
if timeout < 2 or timeout > 600
raise ::OverSIP::RuntimeError, "timeout must be between a and 600 seconds"
end
else
timeout = @conf[:blacklist_time]
end
blacklist_entry = @current_target.to_s
@conf[:blacklist][blacklist_entry] = [status_code, reason_phrase, nil, :destination_blacklisted]
::EM.add_timer(timeout) { @conf[:blacklist].delete blacklist_entry }
end
|
#client_timeout ⇒ Object
Methods called by the client transaction.
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/oversip/sip/client.rb', line 72
def client_timeout
if @conf[:use_blacklist]
blacklist_entry = @current_target.to_s
@conf[:blacklist][blacklist_entry] = [408, "Client Timeout", nil, :client_timeout]
::EM.add_timer(@conf[:blacklist_time]) { @conf[:blacklist].delete blacklist_entry }
end
try_next_target 408, "Client Timeout", nil, :client_timeout
end
|
#connection_failed ⇒ Object
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/oversip/sip/client.rb', line 83
def connection_failed
if @conf[:use_blacklist]
blacklist_entry = @current_target.to_s
@conf[:blacklist][blacklist_entry] = [500, "Connection Error", nil, :connection_error]
::EM.add_timer(@conf[:blacklist_time]) { @conf[:blacklist].delete blacklist_entry }
end
try_next_target 500, "Connection Error", nil, :connection_error
end
|
#invite_timeout ⇒ Object
106
107
108
|
# File 'lib/oversip/sip/client.rb', line 106
def invite_timeout
@on_invite_timeout_block && @on_invite_timeout_block.call
end
|
#on_canceled(&block) ⇒ Object
27
28
29
|
# File 'lib/oversip/sip/client.rb', line 27
def on_canceled &block
@on_canceled_block = block
end
|
#on_error(&block) ⇒ Object
35
36
37
|
# File 'lib/oversip/sip/client.rb', line 35
def on_error &block
@on_error_block = block
end
|
#on_failure_response(&block) ⇒ Object
23
24
25
|
# File 'lib/oversip/sip/client.rb', line 23
def on_failure_response &block
@on_failure_response_block = block
end
|
#on_invite_timeout(&block) ⇒ Object
31
32
33
|
# File 'lib/oversip/sip/client.rb', line 31
def on_invite_timeout &block
@on_invite_timeout_block = block
end
|
#on_provisional_response(&block) ⇒ Object
15
16
17
|
# File 'lib/oversip/sip/client.rb', line 15
def on_provisional_response &block
@on_provisional_response_block = block
end
|
#on_success_response(&block) ⇒ Object
19
20
21
|
# File 'lib/oversip/sip/client.rb', line 19
def on_success_response &block
@on_success_response_block = block
end
|
#on_target(&block) ⇒ Object
39
40
41
|
# File 'lib/oversip/sip/client.rb', line 39
def on_target &block
@on_target_block = block
end
|
#tls_validation_failed ⇒ Object
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/oversip/sip/client.rb', line 94
def tls_validation_failed
if @conf[:use_blacklist]
blacklist_entry = @current_target.to_s
@conf[:blacklist][blacklist_entry] = [500, "TLS Validation Failed", nil, :tls_validation_failed]
::EM.add_timer(@conf[:blacklist_time]) { @conf[:blacklist].delete blacklist_entry }
end
try_next_target 500, "TLS Validation Failed", nil, :tls_validation_failed
end
|