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
fg_system_msg2str, load_methods, #log_id
Constructor Details
#initialize(proxy_profile = :default_proxy) ⇒ Client
Returns a new instance of Client.
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# 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
@on_provisional_response_cbs = []
@on_success_response_cbs = []
@on_failure_response_cbs = []
@on_canceled_cbs = []
@on_invite_timeout_cbs = []
@on_error_cbs = []
@on_target_cbs = []
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
|
#request ⇒ Object
Returns the value of attribute request.
7
8
9
|
# File 'lib/oversip/sip/client.rb', line 7
def request
@request
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.
91
92
93
|
# File 'lib/oversip/sip/client.rb', line 91
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.
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/oversip/sip/client.rb', line 98
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
|
#clear_callbacks ⇒ Object
79
80
81
82
83
84
85
86
87
|
# File 'lib/oversip/sip/client.rb', line 79
def clear_callbacks
@on_provisional_response_cbs.clear
@on_success_response_cbs.clear
@on_failure_response_cbs.clear
@on_canceled_cbs.clear
@on_invite_timeout_cbs.clear
@on_error_cbs.clear
@on_target_cbs.clear
end
|
#clear_on_canceled ⇒ Object
63
64
65
|
# File 'lib/oversip/sip/client.rb', line 63
def clear_on_canceled
@on_canceled_cbs.clear
end
|
#clear_on_error ⇒ Object
71
72
73
|
# File 'lib/oversip/sip/client.rb', line 71
def clear_on_error
@on_error_cbs.clear
end
|
#clear_on_failure_response ⇒ Object
59
60
61
|
# File 'lib/oversip/sip/client.rb', line 59
def clear_on_failure_response
@on_failure_response_cbs.clear
end
|
#clear_on_invite_timeout ⇒ Object
67
68
69
|
# File 'lib/oversip/sip/client.rb', line 67
def clear_on_invite_timeout
@on_invite_timeout_cbs.clear
end
|
#clear_on_provisional_response ⇒ Object
51
52
53
|
# File 'lib/oversip/sip/client.rb', line 51
def clear_on_provisional_response
@on_provisional_response_cbs.clear
end
|
#clear_on_success_response ⇒ Object
55
56
57
|
# File 'lib/oversip/sip/client.rb', line 55
def clear_on_success_response
@on_success_response_cbs.clear
end
|
#clear_on_target ⇒ Object
75
76
77
|
# File 'lib/oversip/sip/client.rb', line 75
def clear_on_target
@on_target_cbs.clear
end
|
#client_timeout ⇒ Object
Methods called by the client transaction.
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/oversip/sip/client.rb', line 118
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
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/oversip/sip/client.rb', line 129
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
152
153
154
|
# File 'lib/oversip/sip/client.rb', line 152
def invite_timeout
run_on_invite_timeout_cbs
end
|
#on_canceled(&block) ⇒ Object
35
36
37
|
# File 'lib/oversip/sip/client.rb', line 35
def on_canceled &block
@on_canceled_cbs << block
end
|
#on_error(&block) ⇒ Object
43
44
45
|
# File 'lib/oversip/sip/client.rb', line 43
def on_error &block
@on_error_cbs << block
end
|
#on_failure_response(&block) ⇒ Object
31
32
33
|
# File 'lib/oversip/sip/client.rb', line 31
def on_failure_response &block
@on_failure_response_cbs << block
end
|
#on_invite_timeout(&block) ⇒ Object
39
40
41
|
# File 'lib/oversip/sip/client.rb', line 39
def on_invite_timeout &block
@on_invite_timeout_cbs << block
end
|
#on_provisional_response(&block) ⇒ Object
23
24
25
|
# File 'lib/oversip/sip/client.rb', line 23
def on_provisional_response &block
@on_provisional_response_cbs << block
end
|
#on_success_response(&block) ⇒ Object
27
28
29
|
# File 'lib/oversip/sip/client.rb', line 27
def on_success_response &block
@on_success_response_cbs << block
end
|
#on_target(&block) ⇒ Object
47
48
49
|
# File 'lib/oversip/sip/client.rb', line 47
def on_target &block
@on_target_cbs << block
end
|
#tls_validation_failed ⇒ Object
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/oversip/sip/client.rb', line 140
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
|