oversip_p 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS +22 -0
  3. data/LICENSE +25 -0
  4. data/README.md +43 -0
  5. data/Rakefile +54 -0
  6. data/bin/oversip +184 -0
  7. data/etc/oversip.conf +274 -0
  8. data/etc/proxies.conf +145 -0
  9. data/etc/server.rb +315 -0
  10. data/etc/tls/ca/cacert.pem +3894 -0
  11. data/etc/tls/demo-tls.oversip.net.crt +17 -0
  12. data/etc/tls/demo-tls.oversip.net.key +15 -0
  13. data/etc/tls/upgrade-cacert.sh +12 -0
  14. data/etc/tls/utils/create-cert.rb +162 -0
  15. data/etc/tls/utils/get-sip-identities.rb +95 -0
  16. data/ext/common/c_util.h +74 -0
  17. data/ext/common/ruby_c_util.h +88 -0
  18. data/ext/sip_parser/common_headers.h +210 -0
  19. data/ext/sip_parser/ext_help.h +18 -0
  20. data/ext/sip_parser/extconf.rb +3 -0
  21. data/ext/sip_parser/sip_message_parser.c +29741 -0
  22. data/ext/sip_parser/sip_parser.h +250 -0
  23. data/ext/sip_parser/sip_parser_ruby.c +1370 -0
  24. data/ext/sip_parser/sip_uri_parser.c +39699 -0
  25. data/ext/stud/extconf.rb +43 -0
  26. data/ext/stun/ext_help.h +16 -0
  27. data/ext/stun/extconf.rb +3 -0
  28. data/ext/stun/stun_ruby.c +394 -0
  29. data/ext/utils/ext_help.h +14 -0
  30. data/ext/utils/extconf.rb +3 -0
  31. data/ext/utils/haproxy_protocol.c +6163 -0
  32. data/ext/utils/haproxy_protocol.h +27 -0
  33. data/ext/utils/ip_utils.c +5952 -0
  34. data/ext/utils/ip_utils.h +64 -0
  35. data/ext/utils/outbound_utils.c +3227 -0
  36. data/ext/utils/outbound_utils.h +27 -0
  37. data/ext/utils/utils_ruby.c +392 -0
  38. data/ext/utils/utils_ruby.h +76 -0
  39. data/ext/websocket_framing_utils/ext_help.h +18 -0
  40. data/ext/websocket_framing_utils/extconf.rb +3 -0
  41. data/ext/websocket_framing_utils/ws_framing_utils.h +47 -0
  42. data/ext/websocket_framing_utils/ws_framing_utils_ruby.c +135 -0
  43. data/ext/websocket_http_parser/ext_help.h +18 -0
  44. data/ext/websocket_http_parser/extconf.rb +3 -0
  45. data/ext/websocket_http_parser/ws_http_parser.c +1635 -0
  46. data/ext/websocket_http_parser/ws_http_parser.h +87 -0
  47. data/ext/websocket_http_parser/ws_http_parser_ruby.c +630 -0
  48. data/lib/oversip/config.rb +597 -0
  49. data/lib/oversip/config_validators.rb +126 -0
  50. data/lib/oversip/default_server.rb +52 -0
  51. data/lib/oversip/errors.rb +10 -0
  52. data/lib/oversip/fiber_pool.rb +56 -0
  53. data/lib/oversip/launcher.rb +635 -0
  54. data/lib/oversip/logger.rb +84 -0
  55. data/lib/oversip/modules/outbound_mangling.rb +56 -0
  56. data/lib/oversip/modules/user_assertion.rb +73 -0
  57. data/lib/oversip/proxies_config.rb +189 -0
  58. data/lib/oversip/ruby_ext/eventmachine.rb +38 -0
  59. data/lib/oversip/sip/client.rb +428 -0
  60. data/lib/oversip/sip/client_transaction.rb +586 -0
  61. data/lib/oversip/sip/constants.rb +88 -0
  62. data/lib/oversip/sip/core.rb +217 -0
  63. data/lib/oversip/sip/launcher.rb +221 -0
  64. data/lib/oversip/sip/listeners/connection.rb +54 -0
  65. data/lib/oversip/sip/listeners/ipv4_tcp_client.rb +21 -0
  66. data/lib/oversip/sip/listeners/ipv4_tcp_server.rb +22 -0
  67. data/lib/oversip/sip/listeners/ipv4_tls_client.rb +21 -0
  68. data/lib/oversip/sip/listeners/ipv4_tls_server.rb +22 -0
  69. data/lib/oversip/sip/listeners/ipv4_tls_tunnel_server.rb +22 -0
  70. data/lib/oversip/sip/listeners/ipv4_udp_server.rb +21 -0
  71. data/lib/oversip/sip/listeners/ipv6_tcp_client.rb +21 -0
  72. data/lib/oversip/sip/listeners/ipv6_tcp_server.rb +22 -0
  73. data/lib/oversip/sip/listeners/ipv6_tls_client.rb +21 -0
  74. data/lib/oversip/sip/listeners/ipv6_tls_server.rb +22 -0
  75. data/lib/oversip/sip/listeners/ipv6_tls_tunnel_server.rb +22 -0
  76. data/lib/oversip/sip/listeners/ipv6_udp_server.rb +21 -0
  77. data/lib/oversip/sip/listeners/tcp_client.rb +97 -0
  78. data/lib/oversip/sip/listeners/tcp_connection.rb +202 -0
  79. data/lib/oversip/sip/listeners/tcp_server.rb +71 -0
  80. data/lib/oversip/sip/listeners/tls_client.rb +125 -0
  81. data/lib/oversip/sip/listeners/tls_server.rb +88 -0
  82. data/lib/oversip/sip/listeners/tls_tunnel_connection.rb +89 -0
  83. data/lib/oversip/sip/listeners/tls_tunnel_server.rb +61 -0
  84. data/lib/oversip/sip/listeners/udp_connection.rb +214 -0
  85. data/lib/oversip/sip/listeners.rb +24 -0
  86. data/lib/oversip/sip/message.rb +177 -0
  87. data/lib/oversip/sip/message_processor.rb +213 -0
  88. data/lib/oversip/sip/name_addr.rb +51 -0
  89. data/lib/oversip/sip/proxy.rb +324 -0
  90. data/lib/oversip/sip/request.rb +179 -0
  91. data/lib/oversip/sip/response.rb +37 -0
  92. data/lib/oversip/sip/rfc3263.rb +643 -0
  93. data/lib/oversip/sip/server_transaction.rb +295 -0
  94. data/lib/oversip/sip/sip.rb +76 -0
  95. data/lib/oversip/sip/tags.rb +39 -0
  96. data/lib/oversip/sip/timers.rb +55 -0
  97. data/lib/oversip/sip/transport_manager.rb +130 -0
  98. data/lib/oversip/sip/uac.rb +89 -0
  99. data/lib/oversip/sip/uac_request.rb +84 -0
  100. data/lib/oversip/sip/uri.rb +208 -0
  101. data/lib/oversip/syslog.rb +68 -0
  102. data/lib/oversip/system_callbacks.rb +45 -0
  103. data/lib/oversip/tls.rb +172 -0
  104. data/lib/oversip/utils.rb +30 -0
  105. data/lib/oversip/version.rb +21 -0
  106. data/lib/oversip/websocket/constants.rb +55 -0
  107. data/lib/oversip/websocket/http_request.rb +59 -0
  108. data/lib/oversip/websocket/launcher.rb +183 -0
  109. data/lib/oversip/websocket/listeners/connection.rb +51 -0
  110. data/lib/oversip/websocket/listeners/ipv4_ws_server.rb +22 -0
  111. data/lib/oversip/websocket/listeners/ipv4_wss_server.rb +22 -0
  112. data/lib/oversip/websocket/listeners/ipv4_wss_tunnel_server.rb +22 -0
  113. data/lib/oversip/websocket/listeners/ipv6_ws_server.rb +22 -0
  114. data/lib/oversip/websocket/listeners/ipv6_wss_server.rb +22 -0
  115. data/lib/oversip/websocket/listeners/ipv6_wss_tunnel_server.rb +22 -0
  116. data/lib/oversip/websocket/listeners/ws_server.rb +331 -0
  117. data/lib/oversip/websocket/listeners/wss_server.rb +88 -0
  118. data/lib/oversip/websocket/listeners/wss_tunnel_server.rb +133 -0
  119. data/lib/oversip/websocket/listeners.rb +13 -0
  120. data/lib/oversip/websocket/websocket.rb +13 -0
  121. data/lib/oversip/websocket/ws_framing.rb +545 -0
  122. data/lib/oversip/websocket/ws_sip_app.rb +120 -0
  123. data/lib/oversip.rb +127 -0
  124. data/test/oversip_test_helper.rb +19 -0
  125. data/test/test_http_parser.rb +73 -0
  126. data/test/test_name_addr.rb +27 -0
  127. data/test/test_name_addr_parser.rb +24 -0
  128. data/test/test_sip_message_parser.rb +168 -0
  129. data/test/test_sip_uri_parser.rb +56 -0
  130. data/test/test_uri.rb +68 -0
  131. data/thirdparty/stud/stud.tar.gz +0 -0
  132. metadata +334 -0
@@ -0,0 +1,217 @@
1
+ module OverSIP::SIP
2
+
3
+ # This module is included by OverSIP::SIP::Request class.
4
+ module Core
5
+
6
+ # Create a server transaction for the incoming request.
7
+ def create_transaction
8
+ return false if @server_transaction
9
+
10
+ case @sip_method
11
+ when :INVITE
12
+ ::OverSIP::SIP::InviteServerTransaction.new self
13
+ return true
14
+ when :ACK
15
+ return nil
16
+ when :CANCEL
17
+ return nil
18
+ else
19
+ ::OverSIP::SIP::NonInviteServerTransaction.new self
20
+ return true
21
+ end
22
+ end
23
+
24
+
25
+ def check_max_forwards max_forwards
26
+ if @max_forwards
27
+ unless @max_forwards.zero?
28
+ @new_max_forwards = ( @max_forwards > max_forwards ? max_forwards : @max_forwards - 1 )
29
+ return true
30
+ else
31
+ log_system_notice "Max-Forwards is 0 => 483"
32
+ reply 483
33
+ return false
34
+ end
35
+ else
36
+ @new_max_forwards = max_forwards
37
+ return true
38
+ end
39
+ end
40
+
41
+
42
+ def loose_route
43
+ num_removes = 0
44
+ has_preloaded_route_with_ob_param = false
45
+
46
+ # Remove all the Route's pointing to the proxy until a Route not pointing to us is found.
47
+ if @routes
48
+ @routes.each do |route|
49
+ if ::OverSIP::SIP::Tags.check_value_for_route_ovid(route.ovid_param)
50
+ num_removes += 1
51
+ else
52
+ if local_uri? route
53
+ has_preloaded_route_with_ob_param = true if route.ob_param?
54
+ num_removes += 1
55
+ else
56
+ break
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ ### Outbound stuf. RFC 5626 section 5.3.
63
+
64
+ # Outgoing initial request asking for Outbound. Just valid when:
65
+ # - It's an initial request.
66
+ # - The request comes via UDP or comes via TCP/TLS/WS/WSS but through a connection
67
+ # opened by the peer (and not by OverSIP).
68
+ # - Single Via (so there is no a proxy in front of us).
69
+ # - It's an INVITE, REGISTER, SUBSCRIBE or REFER request.
70
+ # - Has a preloaded top Route with ;ob param pointing to us, or has Contact with ;ob, or
71
+ # it's a REGISTER with ;+sip.instance..
72
+ #
73
+ if (
74
+ initial? and
75
+ @connection.class.outbound_listener? and (
76
+ @force_outgoing_outbound or (
77
+ @num_vias == 1 and
78
+ outbound_aware? and (
79
+ ( has_preloaded_route_with_ob_param or (@contact and @contact.ob_param?) ) or
80
+ ( @sip_method == :REGISTER and contact_reg_id? )
81
+ )
82
+ )
83
+ )
84
+ )
85
+ @outgoing_outbound_requested = true
86
+ log_system_debug "applying outgoing Outbound support" if $oversip_debug
87
+ else
88
+ @outgoing_outbound_requested = false
89
+ end
90
+
91
+ # Incoming initial request or in-dialog incoming/outgoing request. Must only perform
92
+ # Outbound for the incoming case and just when:
93
+ # - All the Route headers point to us.
94
+ # - There are 1 or 2 Route headers.
95
+ # - The latest Route has a flow token and a valid ;ovid param (so has been generated
96
+ # previously by us).
97
+ # NOTE: But don't check its value so it still would work in case of server reboot.
98
+ # - It's an incoming Outbound request (so flow token in the Route does not match the
99
+ # flow token of the incoming connection).
100
+ if (
101
+ (num_removes == 1 or num_removes == 2) and
102
+ @routes.size == num_removes and
103
+ (outbound_route = @routes.last) and
104
+ outbound_route.ovid_param and
105
+ (@route_outbound_flow_token = outbound_route.user) and
106
+ @route_outbound_flow_token != @connection_outbound_flow_token
107
+ )
108
+ @incoming_outbound_requested = true
109
+ log_system_debug "destination is an incoming Outbound connection" if $oversip_debug
110
+ end
111
+
112
+ # If there are not Route headers return false.
113
+ return false unless @routes
114
+
115
+ # Remove the Route values pointintg to us.
116
+ unless num_removes == 0
117
+ @headers["Route"].shift num_removes
118
+ @routes.shift num_removes
119
+ end
120
+ @routes.empty? and @routes = nil
121
+
122
+ # Return true if it is an in-dialog request and the top Route pointed to us.
123
+ # False otherwise as we shouldn't receive an in-dialog request with a top Route non
124
+ # pointing to us.
125
+ if in_dialog?
126
+ return ( num_removes > 0 ? true : false )
127
+ # Return true if it was an initial request and more Route headers remain after inspection.
128
+ elsif @routes
129
+ return true
130
+ # Return false if it was an initial request and all its Route headers pointed to the proxy.
131
+ else
132
+ return false
133
+ end
134
+ end
135
+
136
+
137
+ # Checks whether the RURI points to a local domain or address.
138
+ # Typically, prior to using this method the user has verified the return value of loose_route()
139
+ # in case it's an initial request (if it's _true_ then the request has pre-loaded Route).
140
+ def destination_myself?
141
+ return true if @destination_myself
142
+ return false if @destination_myself == false
143
+
144
+ if local_uri? @ruri
145
+ return @destination_myself = true
146
+ else
147
+ return @destination_myself = false
148
+ end
149
+ end
150
+
151
+
152
+ def fix_nat
153
+ # Force rport usage for UDP clients.
154
+ @via_rport = @source_port
155
+
156
+ # Force outgoing Outbound.
157
+ if initial? and @num_vias == 1 and outbound_aware?
158
+ @force_outgoing_outbound = true
159
+ end
160
+ end
161
+
162
+
163
+ def outgoing_outbound_requested?
164
+ return true if @outgoing_outbound_requested
165
+ return false if @outgoing_outbound_requested == false
166
+
167
+ # It could be an initial request so we must provide Outbound support if
168
+ # forced via request.fix_nat() or if the request properly indicates it, even
169
+ # when route.loose_route() is not called.
170
+ if (
171
+ initial? and
172
+ @connection.class.outbound_listener? and (
173
+ @force_outgoing_outbound or (
174
+ @num_vias == 1 and
175
+ outbound_aware? and (
176
+ ( @contact and @contact.ob_param? ) or
177
+ ( @sip_method == :REGISTER and contact_reg_id? )
178
+ )
179
+ )
180
+ )
181
+ )
182
+ log_system_debug "applying outgoing Outbound support" if $oversip_debug
183
+ @outgoing_outbound_requested = true
184
+ else
185
+ @outgoing_outbound_requested = false
186
+ end
187
+ end
188
+
189
+ def incoming_outbound_requested? ; @incoming_outbound_requested end
190
+
191
+
192
+ def connection_outbound_flow_token
193
+ @connection_outbound_flow_token ||= if @transport == :udp
194
+ # NOTE: Add "_" so later we can figure that this is for UDP.
195
+ # NOTE: Replace "=" with "-" so it can be added as a SIP URI param (needed i.e.
196
+ # for the OutboundMangling module).
197
+ "_" << ::Base64.strict_encode64("#{@source_ip}_#{@source_port}").gsub(/=/,"-")
198
+ else
199
+ @connection.outbound_flow_token
200
+ end
201
+ end
202
+
203
+
204
+ private
205
+
206
+
207
+ def local_uri? uri
208
+ return false unless uri.scheme == :sip or uri.scheme == :sips
209
+ # NOTE: uri.host has been normalized during parsing in case it's an IPv6 and it's
210
+ # an :ipv6_reference.
211
+ ( uri.port and ::OverSIP::SIP.local_aliases["#{uri.host}:#{uri.port}"] ) or
212
+ ( not uri.port and ::OverSIP::SIP.local_aliases[uri.host] )
213
+ end
214
+
215
+ end # module Core
216
+
217
+ end
@@ -0,0 +1,221 @@
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
+ @log_id = "SIP launcher"
13
+
14
+
15
+ def self.run enabled, ip_type, ip, port, transport, virtual_ip=nil, virtual_port=nil
16
+ uri_ip = case ip_type
17
+ when :ipv4 ; ip
18
+ when :ipv6 ; "[#{ip}]"
19
+ end
20
+
21
+ if virtual_ip
22
+ uri_virtual_ip = case ip_type
23
+ when :ipv4 ; virtual_ip
24
+ when :ipv6 ; "[#{virtual_ip}]"
25
+ end
26
+ end
27
+
28
+ klass = case transport
29
+ when :udp
30
+ case ip_type
31
+ when :ipv4 ; ::OverSIP::SIP::IPv4UdpServer
32
+ when :ipv6 ; ::OverSIP::SIP::IPv6UdpServer
33
+ end
34
+ when :tcp
35
+ case ip_type
36
+ when :ipv4 ; ::OverSIP::SIP::IPv4TcpServer
37
+ when :ipv6 ; ::OverSIP::SIP::IPv6TcpServer
38
+ end
39
+ when :tls
40
+ case ip_type
41
+ when :ipv4 ; ::OverSIP::SIP::IPv4TlsServer
42
+ when :ipv6 ; ::OverSIP::SIP::IPv6TlsServer
43
+ end
44
+ when :tls_tunnel
45
+ case ip_type
46
+ when :ipv4 ; ::OverSIP::SIP::IPv4TlsTunnelServer
47
+ when :ipv6 ; ::OverSIP::SIP::IPv6TlsTunnelServer
48
+ end
49
+ end
50
+
51
+ klass.ip = virtual_ip || ip
52
+ klass.port = virtual_port || port
53
+
54
+ case
55
+
56
+ when klass == ::OverSIP::SIP::IPv4UdpServer
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>"
66
+
67
+ if enabled
68
+ ::EM::open_datagram_socket(ip, port, klass) do |conn|
69
+ klass.connections = conn
70
+ end
71
+ end
72
+
73
+ when klass == ::OverSIP::SIP::IPv6UdpServer
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>"
83
+
84
+ if enabled
85
+ ::EM::open_datagram_socket(ip, port, klass) do |conn|
86
+ klass.connections = conn
87
+ end
88
+ end
89
+
90
+ when klass == ::OverSIP::SIP::IPv4TcpServer
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>"
100
+
101
+ if enabled
102
+ ::EM.start_server(ip, port, klass) do |conn|
103
+ conn.post_connection
104
+ conn.set_comm_inactivity_timeout 7200
105
+ end
106
+ end
107
+
108
+ when klass == ::OverSIP::SIP::IPv6TcpServer
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>"
118
+
119
+ if enabled
120
+ ::EM.start_server(ip, port, klass) do |conn|
121
+ conn.post_connection
122
+ conn.set_comm_inactivity_timeout 7200
123
+ end
124
+ end
125
+
126
+ when klass == ::OverSIP::SIP::IPv4TlsServer
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>"
138
+
139
+ if enabled
140
+ ::EM.start_server(ip, port, klass) do |conn|
141
+ conn.post_connection
142
+ conn.set_comm_inactivity_timeout 7200
143
+ end
144
+ end
145
+
146
+ when klass == ::OverSIP::SIP::IPv6TlsServer
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>"
158
+
159
+ if enabled
160
+ ::EM.start_server(ip, port, klass) do |conn|
161
+ conn.post_connection
162
+ conn.set_comm_inactivity_timeout 7200
163
+ end
164
+ end
165
+
166
+ when klass == ::OverSIP::SIP::IPv4TlsTunnelServer
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
+
179
+ if enabled
180
+ ::EM.start_server(ip, port, klass) do |conn|
181
+ conn.post_connection
182
+ conn.set_comm_inactivity_timeout 7200
183
+ end
184
+ end
185
+
186
+ when klass == ::OverSIP::SIP::IPv6TlsTunnelServer
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
+
199
+ if enabled
200
+ ::EM.start_server(ip, port, klass) do |conn|
201
+ conn.post_connection
202
+ conn.set_comm_inactivity_timeout 7200
203
+ end
204
+ end
205
+
206
+ end # case
207
+
208
+ transport_str = case transport
209
+ when :tls_tunnel ; "TLS-Tunnel"
210
+ else ; transport.to_s.upcase
211
+ end
212
+
213
+ if enabled
214
+ log_system_info "SIP #{transport_str} server listening on #{IP_TYPE[ip_type]} #{uri_ip}:#{port}"
215
+ end
216
+
217
+ end # def self.run
218
+
219
+ end
220
+
221
+ end
@@ -0,0 +1,54 @@
1
+ module OverSIP::SIP
2
+
3
+ class Connection < ::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
+
21
+ def outbound_listener?
22
+ @is_outbound_listener
23
+ end
24
+ end
25
+
26
+
27
+ attr_reader :cvars
28
+
29
+ def initialize
30
+ @parser = ::OverSIP::SIP::MessageParser.new
31
+ @buffer = ::IO::Buffer.new
32
+ @state = :init
33
+ @cvars = {}
34
+
35
+ end
36
+
37
+ def receive_senderror error, data
38
+ log_system_error "Socket sending error: #{error.inspect}, #{data.inspect}"
39
+ end
40
+
41
+ def transport
42
+ self.class.transport
43
+ end
44
+
45
+ def open?
46
+ ! error?
47
+ end
48
+
49
+ # close() method causes @local_closed = true.
50
+ alias close close_connection_after_writing
51
+ end
52
+
53
+ end
54
+
@@ -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,22 @@
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
+ @is_outbound_listener = true
14
+
15
+ LOG_ID = "SIP TCP IPv4 server"
16
+ def log_id
17
+ LOG_ID
18
+ end
19
+
20
+ end
21
+
22
+ 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,22 @@
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
+ @is_outbound_listener = true
14
+
15
+ LOG_ID = "SIP TLS IPv4 server"
16
+ def log_id
17
+ LOG_ID
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
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
+ @is_outbound_listener = true
14
+
15
+ LOG_ID = "SIP TLS-Tunnel IPv4 server"
16
+ def log_id
17
+ LOG_ID
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,21 @@
1
+ module OverSIP::SIP
2
+
3
+ class IPv4UdpServer < UdpConnection
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
+ @is_outbound_listener = true
13
+
14
+ LOG_ID = "SIP UDP 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 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,22 @@
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
+ @is_outbound_listener = true
14
+
15
+ LOG_ID = "SIP TCP IPv6 server"
16
+ def log_id
17
+ LOG_ID
18
+ end
19
+
20
+ end
21
+
22
+ 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