oversip 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS.txt +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +16 -0
- data/Rakefile +55 -0
- data/bin/oversip +182 -0
- data/ext/common/c_util.h +74 -0
- data/ext/common/ruby_c_util.h +88 -0
- data/ext/sip_parser/common_headers.h +209 -0
- data/ext/sip_parser/ext_help.h +18 -0
- data/ext/sip_parser/extconf.rb +3 -0
- data/ext/sip_parser/sip_parser.c +29649 -0
- data/ext/sip_parser/sip_parser.h +227 -0
- data/ext/sip_parser/sip_parser_ruby.c +1292 -0
- data/ext/stud/extconf.rb +27 -0
- data/ext/stud/stud.tar.gz +0 -0
- data/ext/stun/ext_help.h +16 -0
- data/ext/stun/extconf.rb +3 -0
- data/ext/stun/stun_ruby.c +391 -0
- data/ext/utils/ext_help.h +14 -0
- data/ext/utils/extconf.rb +3 -0
- data/ext/utils/haproxy_protocol.c +6163 -0
- data/ext/utils/haproxy_protocol.h +27 -0
- data/ext/utils/ip_utils.c +5952 -0
- data/ext/utils/ip_utils.h +61 -0
- data/ext/utils/outbound_utils.c +3227 -0
- data/ext/utils/outbound_utils.h +27 -0
- data/ext/utils/utils_ruby.c +384 -0
- data/ext/utils/utils_ruby.h +75 -0
- data/ext/websocket_framing_utils/ext_help.h +18 -0
- data/ext/websocket_framing_utils/extconf.rb +3 -0
- data/ext/websocket_framing_utils/ws_framing_utils.h +46 -0
- data/ext/websocket_framing_utils/ws_framing_utils_ruby.c +135 -0
- data/ext/websocket_http_parser/ext_help.h +18 -0
- data/ext/websocket_http_parser/extconf.rb +3 -0
- data/ext/websocket_http_parser/ws_http_parser.c +2598 -0
- data/ext/websocket_http_parser/ws_http_parser.h +86 -0
- data/ext/websocket_http_parser/ws_http_parser_ruby.c +630 -0
- data/lib/oversip/config.rb +541 -0
- data/lib/oversip/config_validators.rb +126 -0
- data/lib/oversip/errors.rb +7 -0
- data/lib/oversip/fiber_pool.rb +56 -0
- data/lib/oversip/launcher.rb +507 -0
- data/lib/oversip/logger.rb +170 -0
- data/lib/oversip/master_process.rb +67 -0
- data/lib/oversip/posix_mq.rb +121 -0
- data/lib/oversip/proxies_config.rb +169 -0
- data/lib/oversip/ruby_ext/eventmachine.rb +38 -0
- data/lib/oversip/sip/client_transaction.rb +587 -0
- data/lib/oversip/sip/constants.rb +87 -0
- data/lib/oversip/sip/grammar/name_addr.rb +27 -0
- data/lib/oversip/sip/grammar/uri.rb +116 -0
- data/lib/oversip/sip/launcher.rb +180 -0
- data/lib/oversip/sip/listeners/ipv4_tcp_client.rb +21 -0
- data/lib/oversip/sip/listeners/ipv4_tcp_server.rb +21 -0
- data/lib/oversip/sip/listeners/ipv4_tls_client.rb +21 -0
- data/lib/oversip/sip/listeners/ipv4_tls_server.rb +21 -0
- data/lib/oversip/sip/listeners/ipv4_tls_tunnel_server.rb +21 -0
- data/lib/oversip/sip/listeners/ipv4_udp_server.rb +20 -0
- data/lib/oversip/sip/listeners/ipv6_tcp_client.rb +21 -0
- data/lib/oversip/sip/listeners/ipv6_tcp_server.rb +21 -0
- data/lib/oversip/sip/listeners/ipv6_tls_client.rb +21 -0
- data/lib/oversip/sip/listeners/ipv6_tls_server.rb +21 -0
- data/lib/oversip/sip/listeners/ipv6_tls_tunnel_server.rb +21 -0
- data/lib/oversip/sip/listeners/ipv6_udp_server.rb +20 -0
- data/lib/oversip/sip/listeners/reactor.rb +39 -0
- data/lib/oversip/sip/listeners/tcp_client.rb +73 -0
- data/lib/oversip/sip/listeners/tcp_reactor.rb +185 -0
- data/lib/oversip/sip/listeners/tcp_server.rb +71 -0
- data/lib/oversip/sip/listeners/tls_client.rb +117 -0
- data/lib/oversip/sip/listeners/tls_server.rb +70 -0
- data/lib/oversip/sip/listeners/tls_tunnel_reactor.rb +113 -0
- data/lib/oversip/sip/listeners/tls_tunnel_server.rb +61 -0
- data/lib/oversip/sip/listeners/udp_reactor.rb +213 -0
- data/lib/oversip/sip/listeners.rb +28 -0
- data/lib/oversip/sip/logic.rb +14 -0
- data/lib/oversip/sip/message.rb +168 -0
- data/lib/oversip/sip/message_processor.rb +202 -0
- data/lib/oversip/sip/modules/core.rb +200 -0
- data/lib/oversip/sip/modules/registrar_without_path.rb +75 -0
- data/lib/oversip/sip/modules/user_assertion.rb +123 -0
- data/lib/oversip/sip/proxy.rb +460 -0
- data/lib/oversip/sip/request.rb +128 -0
- data/lib/oversip/sip/response.rb +30 -0
- data/lib/oversip/sip/rfc3263.rb +646 -0
- data/lib/oversip/sip/server_transaction.rb +295 -0
- data/lib/oversip/sip/sip.rb +74 -0
- data/lib/oversip/sip/tags.rb +39 -0
- data/lib/oversip/sip/timers.rb +55 -0
- data/lib/oversip/sip/transport_manager.rb +129 -0
- data/lib/oversip/syslogger_process.rb +119 -0
- data/lib/oversip/tls.rb +179 -0
- data/lib/oversip/utils.rb +25 -0
- data/lib/oversip/version.rb +23 -0
- data/lib/oversip/websocket/constants.rb +56 -0
- data/lib/oversip/websocket/default_policy.rb +19 -0
- data/lib/oversip/websocket/http_request.rb +63 -0
- data/lib/oversip/websocket/launcher.rb +207 -0
- data/lib/oversip/websocket/listeners/ipv4_tcp_server.rb +15 -0
- data/lib/oversip/websocket/listeners/ipv4_tls_server.rb +15 -0
- data/lib/oversip/websocket/listeners/ipv4_tls_tunnel_server.rb +15 -0
- data/lib/oversip/websocket/listeners/ipv6_tcp_server.rb +15 -0
- data/lib/oversip/websocket/listeners/ipv6_tls_server.rb +15 -0
- data/lib/oversip/websocket/listeners/ipv6_tls_tunnel_server.rb +15 -0
- data/lib/oversip/websocket/listeners/tcp_server.rb +265 -0
- data/lib/oversip/websocket/listeners/tls_server.rb +69 -0
- data/lib/oversip/websocket/listeners/tls_tunnel_server.rb +100 -0
- data/lib/oversip/websocket/listeners.rb +12 -0
- data/lib/oversip/websocket/ws_app.rb +75 -0
- data/lib/oversip/websocket/ws_apps/ipv4_ws_sip_app.rb +21 -0
- data/lib/oversip/websocket/ws_apps/ipv4_wss_sip_app.rb +21 -0
- data/lib/oversip/websocket/ws_apps/ipv6_ws_sip_app.rb +21 -0
- data/lib/oversip/websocket/ws_apps/ipv6_wss_sip_app.rb +22 -0
- data/lib/oversip/websocket/ws_apps/ws_autobahn_app.rb +23 -0
- data/lib/oversip/websocket/ws_apps/ws_sip_app.rb +156 -0
- data/lib/oversip/websocket/ws_apps.rb +9 -0
- data/lib/oversip/websocket/ws_framing.rb +597 -0
- data/lib/oversip.rb +59 -0
- data/test/oversip_test_helper.rb +20 -0
- data/test/test_http_parser.rb +73 -0
- data/test/test_sip_parser.rb +139 -0
- metadata +256 -0
@@ -0,0 +1,116 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class Uri
|
4
|
+
attr_reader :scheme, :user, :host, :host_type, :port, :params, :transport_param, :ovid_param, :phone_context_param, :headers
|
5
|
+
attr_accessor :uri_modified
|
6
|
+
|
7
|
+
def scheme= value
|
8
|
+
return nil if unknown_scheme?
|
9
|
+
@scheme = value
|
10
|
+
@uri_modified = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def unknown_scheme?
|
14
|
+
not @scheme.is_a? Symbol
|
15
|
+
end
|
16
|
+
|
17
|
+
def user= value
|
18
|
+
return nil if unknown_scheme?
|
19
|
+
@user = value
|
20
|
+
@uri_modified = true
|
21
|
+
end
|
22
|
+
alias :number :user
|
23
|
+
alias :number= :user=
|
24
|
+
|
25
|
+
def host= value
|
26
|
+
return nil if unknown_scheme?
|
27
|
+
@host = value
|
28
|
+
@host_type = ::OverSIP::Utils.ip_type(value) || :domain
|
29
|
+
@uri_modified = true
|
30
|
+
end
|
31
|
+
alias :domain :host
|
32
|
+
alias :domain= :host=
|
33
|
+
|
34
|
+
def host_type= value
|
35
|
+
return nil if unknown_scheme?
|
36
|
+
@host_type = value
|
37
|
+
end
|
38
|
+
|
39
|
+
def port= value
|
40
|
+
return nil if unknown_scheme?
|
41
|
+
@port = value
|
42
|
+
@uri_modified = true
|
43
|
+
end
|
44
|
+
|
45
|
+
def params
|
46
|
+
@params ||= {}
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_param k, v
|
50
|
+
return nil if unknown_scheme?
|
51
|
+
@params ||= {}
|
52
|
+
@params[k.downcase] = v
|
53
|
+
@uri_modified = true
|
54
|
+
end
|
55
|
+
|
56
|
+
def del_param k
|
57
|
+
return nil if unknown_scheme?
|
58
|
+
return false unless @params
|
59
|
+
if @params.include?(k=k.downcase)
|
60
|
+
@uri_modified = true
|
61
|
+
return @params.delete(k)
|
62
|
+
end
|
63
|
+
false
|
64
|
+
end
|
65
|
+
|
66
|
+
def lr_param?
|
67
|
+
@lr_param ? true : false
|
68
|
+
end
|
69
|
+
|
70
|
+
def ob_param?
|
71
|
+
@ob_param ? true : false
|
72
|
+
end
|
73
|
+
|
74
|
+
def headers= value
|
75
|
+
return nil if unknown_scheme?
|
76
|
+
@headers = value
|
77
|
+
@uri_modified = true
|
78
|
+
end
|
79
|
+
|
80
|
+
def uri
|
81
|
+
return @uri unless @uri_modified
|
82
|
+
|
83
|
+
case @scheme
|
84
|
+
when :sip, :sips
|
85
|
+
@uri = @scheme.to_s << ":"
|
86
|
+
( @uri << ::EscapeUtils.escape_uri(@user) << "@" ) if @user
|
87
|
+
@uri << @host
|
88
|
+
( @uri << ":" << @port.to_s ) if @port
|
89
|
+
|
90
|
+
@params.each do |k,v|
|
91
|
+
@uri << ";" << k
|
92
|
+
( @uri << "=" << v.to_s ) if v
|
93
|
+
end if @params
|
94
|
+
|
95
|
+
@uri << @headers if @headers
|
96
|
+
|
97
|
+
when :tel
|
98
|
+
@uri = "tel:"
|
99
|
+
@uri << @user
|
100
|
+
|
101
|
+
@params.each do |k,v|
|
102
|
+
@uri << ";" << k
|
103
|
+
( @uri << "=" << v.to_s ) if v
|
104
|
+
end if @params
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
@uri_modified = false
|
109
|
+
@uri
|
110
|
+
end
|
111
|
+
alias :to_s :uri
|
112
|
+
alias :inspect :uri
|
113
|
+
|
114
|
+
end # class Uri
|
115
|
+
|
116
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
module Launcher
|
4
|
+
|
5
|
+
extend ::OverSIP::Logger
|
6
|
+
|
7
|
+
IP_TYPE = {
|
8
|
+
:ipv4 => "IPv4",
|
9
|
+
:ipv6 => "IPv6"
|
10
|
+
}
|
11
|
+
|
12
|
+
|
13
|
+
def self.log_id
|
14
|
+
@log_id ||= "SIP launcher"
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def self.run enabled, ip_type, ip, port, transport, virtual_ip=nil, virtual_port=nil
|
19
|
+
uri_ip = case ip_type
|
20
|
+
when :ipv4 ; ip
|
21
|
+
when :ipv6 ; "[#{ip}]"
|
22
|
+
end
|
23
|
+
|
24
|
+
if virtual_ip
|
25
|
+
uri_virtual_ip = case ip_type
|
26
|
+
when :ipv4 ; virtual_ip
|
27
|
+
when :ipv6 ; "[#{virtual_ip}]"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
klass = case transport
|
32
|
+
when :udp
|
33
|
+
case ip_type
|
34
|
+
when :ipv4 ; OverSIP::SIP::IPv4UdpServer
|
35
|
+
when :ipv6 ; OverSIP::SIP::IPv6UdpServer
|
36
|
+
end
|
37
|
+
when :tcp
|
38
|
+
case ip_type
|
39
|
+
when :ipv4 ; OverSIP::SIP::IPv4TcpServer
|
40
|
+
when :ipv6 ; OverSIP::SIP::IPv6TcpServer
|
41
|
+
end
|
42
|
+
when :tls
|
43
|
+
case ip_type
|
44
|
+
when :ipv4 ; OverSIP::SIP::IPv4TlsServer
|
45
|
+
when :ipv6 ; OverSIP::SIP::IPv6TlsServer
|
46
|
+
end
|
47
|
+
when :tls_tunnel
|
48
|
+
case ip_type
|
49
|
+
when :ipv4 ; OverSIP::SIP::IPv4TlsTunnelServer
|
50
|
+
when :ipv6 ; OverSIP::SIP::IPv6TlsTunnelServer
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
klass.ip = virtual_ip || ip
|
55
|
+
klass.port = virtual_port || port
|
56
|
+
|
57
|
+
case
|
58
|
+
|
59
|
+
when klass == OverSIP::SIP::IPv4UdpServer
|
60
|
+
klass.via_core = "SIP/2.0/UDP #{uri_ip}:#{port}"
|
61
|
+
klass.record_route = "<sip:#{uri_ip}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
62
|
+
klass.outbound_record_route_fragment = "@#{uri_ip}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
63
|
+
klass.outbound_path_fragment = "@#{uri_ip}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
64
|
+
|
65
|
+
if enabled
|
66
|
+
EM::open_datagram_socket(ip, port, klass) do |conn|
|
67
|
+
klass.connections = conn
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
when klass == OverSIP::SIP::IPv6UdpServer
|
72
|
+
klass.via_core = "SIP/2.0/UDP #{uri_ip}:#{port}"
|
73
|
+
klass.record_route = "<sip:#{uri_ip}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
74
|
+
klass.outbound_record_route_fragment = "@#{uri_ip}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
75
|
+
klass.outbound_path_fragment = "@#{uri_ip}:#{port};transport=udp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
76
|
+
|
77
|
+
if enabled
|
78
|
+
EM::open_datagram_socket(ip, port, klass) do |conn|
|
79
|
+
klass.connections = conn
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
when klass == OverSIP::SIP::IPv4TcpServer
|
84
|
+
klass.via_core = "SIP/2.0/TCP #{uri_ip}:#{port}"
|
85
|
+
klass.record_route = "<sip:#{uri_ip}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
86
|
+
klass.outbound_record_route_fragment = "@#{uri_ip}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
87
|
+
klass.outbound_path_fragment = "@#{uri_ip}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
88
|
+
|
89
|
+
if enabled
|
90
|
+
EM.start_server(ip, port, klass) do |conn|
|
91
|
+
conn.post_connection
|
92
|
+
conn.set_comm_inactivity_timeout 3600 # TODO
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
when klass == OverSIP::SIP::IPv6TcpServer
|
97
|
+
klass.via_core = "SIP/2.0/TCP #{uri_ip}:#{port}"
|
98
|
+
klass.record_route = "<sip:#{uri_ip}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
99
|
+
klass.outbound_record_route_fragment = "@#{uri_ip}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
100
|
+
klass.outbound_path_fragment = "@#{uri_ip}:#{port};transport=tcp;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
101
|
+
|
102
|
+
if enabled
|
103
|
+
EM.start_server(ip, port, klass) do |conn|
|
104
|
+
conn.post_connection
|
105
|
+
conn.set_comm_inactivity_timeout 3600 # TODO
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
when klass == OverSIP::SIP::IPv4TlsServer
|
110
|
+
klass.via_core = "SIP/2.0/TLS #{uri_ip}:#{port}"
|
111
|
+
rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv4] || uri_ip
|
112
|
+
klass.record_route = "<sip:#{rr_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
113
|
+
klass.outbound_record_route_fragment = "@#{rr_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
114
|
+
klass.outbound_path_fragment = "@#{rr_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
115
|
+
|
116
|
+
if enabled
|
117
|
+
EM.start_server(ip, port, klass) do |conn|
|
118
|
+
conn.post_connection
|
119
|
+
conn.set_comm_inactivity_timeout 3600 # TODO
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
when klass == OverSIP::SIP::IPv6TlsServer
|
124
|
+
klass.via_core = "SIP/2.0/TLS #{uri_ip}:#{port}"
|
125
|
+
rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv6] || uri_ip
|
126
|
+
klass.record_route = "<sip:#{rr_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
127
|
+
klass.outbound_record_route_fragment = "@#{rr_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
128
|
+
klass.outbound_path_fragment = "@#{rr_host}:#{port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
129
|
+
|
130
|
+
if enabled
|
131
|
+
EM.start_server(ip, port, klass) do |conn|
|
132
|
+
conn.post_connection
|
133
|
+
conn.set_comm_inactivity_timeout 3600 # TODO
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
when klass == OverSIP::SIP::IPv4TlsTunnelServer
|
138
|
+
klass.via_core = "SIP/2.0/TLS #{uri_virtual_ip}:#{virtual_port}"
|
139
|
+
rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv4] || uri_virtual_ip
|
140
|
+
klass.record_route = "<sip:#{rr_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
141
|
+
klass.outbound_record_route_fragment = "@#{rr_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
142
|
+
klass.outbound_path_fragment = "@#{rr_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
143
|
+
|
144
|
+
if enabled
|
145
|
+
EM.start_server(ip, port, klass) do |conn|
|
146
|
+
conn.post_connection
|
147
|
+
conn.set_comm_inactivity_timeout 3600 # TODO
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
when klass == OverSIP::SIP::IPv6TlsTunnelServer
|
152
|
+
klass.via_core = "SIP/2.0/TLS #{uri_virtual_ip}:#{virtual_port}"
|
153
|
+
rr_host = ::OverSIP.configuration[:sip][:record_route_hostname_tls_ipv6] || uri_virtual_ip
|
154
|
+
klass.record_route = "<sip:#{rr_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
155
|
+
klass.outbound_record_route_fragment = "@#{rr_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>"
|
156
|
+
klass.outbound_path_fragment = "@#{rr_host}:#{virtual_port};transport=tls;lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid};ob>"
|
157
|
+
|
158
|
+
if enabled
|
159
|
+
EM.start_server(ip, port, klass) do |conn|
|
160
|
+
conn.post_connection
|
161
|
+
conn.set_comm_inactivity_timeout 3600 # TODO
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
end # case
|
166
|
+
|
167
|
+
transport_str = case transport
|
168
|
+
when :tls_tunnel ; "TLS-Tunnel"
|
169
|
+
else ; transport.to_s.upcase
|
170
|
+
end
|
171
|
+
|
172
|
+
if enabled
|
173
|
+
log_system_info "SIP #{transport_str} server listening on #{IP_TYPE[ip_type]} #{uri_ip}:#{port}"
|
174
|
+
end
|
175
|
+
|
176
|
+
end # def self.run
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class IPv4TcpClient < TcpClient
|
4
|
+
|
5
|
+
@ip_type = :ipv4
|
6
|
+
@transport = :tcp
|
7
|
+
@server_class = ::OverSIP::SIP::IPv4TcpServer
|
8
|
+
@connections = @server_class.connections
|
9
|
+
@invite_server_transactions = @server_class.invite_server_transactions
|
10
|
+
@non_invite_server_transactions = @server_class.non_invite_server_transactions
|
11
|
+
@invite_client_transactions = @server_class.invite_client_transactions
|
12
|
+
@non_invite_client_transactions = @server_class.non_invite_client_transactions
|
13
|
+
|
14
|
+
LOG_ID = "SIP TCP IPv4 client"
|
15
|
+
def log_id
|
16
|
+
LOG_ID
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class IPv4TcpServer < TcpServer
|
4
|
+
|
5
|
+
@ip_type = :ipv4
|
6
|
+
@transport = :tcp
|
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 TCP IPv4 server"
|
15
|
+
def log_id
|
16
|
+
LOG_ID
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class IPv4TlsClient < TlsClient
|
4
|
+
|
5
|
+
@ip_type = :ipv4
|
6
|
+
@transport = :tls
|
7
|
+
@server_class = ::OverSIP::SIP::IPv4TlsServer
|
8
|
+
@connections = @server_class.connections
|
9
|
+
@invite_server_transactions = @server_class.invite_server_transactions
|
10
|
+
@non_invite_server_transactions = @server_class.non_invite_server_transactions
|
11
|
+
@invite_client_transactions = @server_class.invite_client_transactions
|
12
|
+
@non_invite_client_transactions = @server_class.non_invite_client_transactions
|
13
|
+
|
14
|
+
LOG_ID = "SIP TLS IPv4 client"
|
15
|
+
def log_id
|
16
|
+
LOG_ID
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class IPv4TlsServer < TlsServer
|
4
|
+
|
5
|
+
@ip_type = :ipv4
|
6
|
+
@transport = :tls
|
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 TLS IPv4 server"
|
15
|
+
def log_id
|
16
|
+
LOG_ID
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class IPv4TlsTunnelServer < TlsTunnelServer
|
4
|
+
|
5
|
+
@ip_type = :ipv4
|
6
|
+
@transport = :tls
|
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 TLS-Tunnel IPv4 server"
|
15
|
+
def log_id
|
16
|
+
LOG_ID
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class IPv4UdpServer < UdpReactor
|
4
|
+
|
5
|
+
@ip_type = :ipv4
|
6
|
+
@transport = :udp
|
7
|
+
@connections = nil # To be set after creating the unique server instance.
|
8
|
+
@invite_server_transactions = {}
|
9
|
+
@non_invite_server_transactions = {}
|
10
|
+
@invite_client_transactions = {}
|
11
|
+
@non_invite_client_transactions = {}
|
12
|
+
|
13
|
+
LOG_ID = "SIP UDP IPv4 server"
|
14
|
+
def log_id
|
15
|
+
LOG_ID
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class IPv6TcpClient < TcpClient
|
4
|
+
|
5
|
+
@ip_type = :ipv6
|
6
|
+
@transport = :tcp
|
7
|
+
@server_class = ::OverSIP::SIP::IPv6TcpServer
|
8
|
+
@connections = @server_class.connections
|
9
|
+
@invite_server_transactions = @server_class.invite_server_transactions
|
10
|
+
@non_invite_server_transactions = @server_class.non_invite_server_transactions
|
11
|
+
@invite_client_transactions = @server_class.invite_client_transactions
|
12
|
+
@non_invite_client_transactions = @server_class.non_invite_client_transactions
|
13
|
+
|
14
|
+
LOG_ID = "SIP TCP IPv6 client"
|
15
|
+
def log_id
|
16
|
+
LOG_ID
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class IPv6TcpServer < TcpServer
|
4
|
+
|
5
|
+
@ip_type = :ipv6
|
6
|
+
@transport = :tcp
|
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 TCP IPv6 server"
|
15
|
+
def log_id
|
16
|
+
LOG_ID
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class IPv6TlsClient < TlsClient
|
4
|
+
|
5
|
+
@ip_type = :ipv6
|
6
|
+
@transport = :tls
|
7
|
+
@server_class = ::OverSIP::SIP::IPv6TlsServer
|
8
|
+
@connections = @server_class.connections
|
9
|
+
@invite_server_transactions = @server_class.invite_server_transactions
|
10
|
+
@non_invite_server_transactions = @server_class.non_invite_server_transactions
|
11
|
+
@invite_client_transactions = @server_class.invite_client_transactions
|
12
|
+
@non_invite_client_transactions = @server_class.non_invite_client_transactions
|
13
|
+
|
14
|
+
LOG_ID = "SIP TLS IPv6 client"
|
15
|
+
def log_id
|
16
|
+
LOG_ID
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class IPv6TlsServer < TlsServer
|
4
|
+
|
5
|
+
@ip_type = :ipv6
|
6
|
+
@transport = :tls
|
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 TLS IPv6 server"
|
15
|
+
def log_id
|
16
|
+
LOG_ID
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class IPv6TlsTunnelServer < TlsTunnelServer
|
4
|
+
|
5
|
+
@ip_type = :ipv6
|
6
|
+
@transport = :tls
|
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 TLS-Tunnel IPv6 server"
|
15
|
+
def log_id
|
16
|
+
LOG_ID
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class IPv6UdpServer < UdpReactor
|
4
|
+
|
5
|
+
@ip_type = :ipv6
|
6
|
+
@transport = :udp
|
7
|
+
@connections = nil # To be set after creating the unique server instance.
|
8
|
+
@invite_server_transactions = {}
|
9
|
+
@non_invite_server_transactions = {}
|
10
|
+
@invite_client_transactions = {}
|
11
|
+
@non_invite_client_transactions = {}
|
12
|
+
|
13
|
+
LOG_ID = "SIP UDP IPv6 server"
|
14
|
+
def log_id
|
15
|
+
LOG_ID
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class Reactor < ::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
|
+
def initialize
|
23
|
+
@parser = ::OverSIP::SIP::MessageParser.new
|
24
|
+
@buffer = ::IO::Buffer.new
|
25
|
+
@state = :init
|
26
|
+
|
27
|
+
# Set the socket sending error handling to report the error:
|
28
|
+
# :ERRORHANDLING_KILL, :ERRORHANDLING_IGNORE, :ERRORHANDLING_REPORT
|
29
|
+
self.send_error_handling = :ERRORHANDLING_REPORT
|
30
|
+
end
|
31
|
+
|
32
|
+
def receive_senderror error, data
|
33
|
+
log_system_error "Socket sending error: #{error.inspect}, #{data.inspect}"
|
34
|
+
end
|
35
|
+
|
36
|
+
end # class Reactor
|
37
|
+
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class TcpClient < TcpReactor
|
4
|
+
|
5
|
+
attr_accessor :server_class ## TODO: sirve??
|
6
|
+
attr_reader :connected
|
7
|
+
attr_reader :pending_client_transactions
|
8
|
+
|
9
|
+
def initialize ip, port
|
10
|
+
# NOTE: The parent class implementing "initialize" method is Reactor, and allows no arguments.
|
11
|
+
# If we call just "super" from here it will fail since "ip" and "port" will be passed as
|
12
|
+
# arguments. So we must use "super()" and we are done (no arguments are passed to parent).
|
13
|
+
super()
|
14
|
+
|
15
|
+
@remote_ip = ip
|
16
|
+
@remote_port = port
|
17
|
+
@connection_id = ::OverSIP::SIP::TransportManager.add_connection self, self.class, self.class.ip_type, @remote_ip, @remote_port
|
18
|
+
@connected = false
|
19
|
+
@pending_client_transactions = []
|
20
|
+
|
21
|
+
### TODO: make it configurable.
|
22
|
+
set_pending_connect_timeout 2.0
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def connection_completed
|
28
|
+
log_system_info "TCP connection opened to " << remote_desc
|
29
|
+
|
30
|
+
@connected = true
|
31
|
+
@pending_client_transactions.clear
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def remote_desc
|
36
|
+
@remote_desc ||= case self.class.ip_type
|
37
|
+
when :ipv4 ; "#{@remote_ip}:#{@remote_port.to_s}"
|
38
|
+
when :ipv6 ; "[#{@remote_ip}]:#{@remote_port.to_s}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def unbind cause=nil
|
44
|
+
@state = :ignore
|
45
|
+
|
46
|
+
# Remove the connection.
|
47
|
+
self.class.connections.delete @connection_id
|
48
|
+
|
49
|
+
@local_closed = true if cause == ::Errno::ETIMEDOUT
|
50
|
+
|
51
|
+
if @connected
|
52
|
+
log_msg = "connection to #{remote_desc} "
|
53
|
+
log_msg << ( @local_closed ? "locally closed" : "remotely closed" )
|
54
|
+
log_msg << " (cause: #{cause.inspect})" if cause
|
55
|
+
log_system_debug log_msg if $oversip_debug
|
56
|
+
|
57
|
+
# If the TCP client connection has failed (remote server rejected the connection) then
|
58
|
+
# inform to all the pending client transactions.
|
59
|
+
else
|
60
|
+
log_system_notice "connection to #{remote_desc} failed" if $oversip_debug
|
61
|
+
|
62
|
+
@pending_client_transactions.each do |client_transaction|
|
63
|
+
client_transaction.connection_failed
|
64
|
+
end
|
65
|
+
@pending_client_transactions.clear
|
66
|
+
end
|
67
|
+
|
68
|
+
@connected = false
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|