oversip 1.1.0.beta5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/etc/oversip.conf +16 -4
  2. data/etc/proxies.conf +8 -9
  3. data/etc/server.rb +59 -0
  4. data/ext/sip_parser/sip_parser.c +12066 -11975
  5. data/ext/sip_parser/sip_parser.h +1 -0
  6. data/ext/sip_parser/sip_parser_ruby.c +15 -4
  7. data/ext/utils/haproxy_protocol.c +4 -1
  8. data/ext/websocket_framing_utils/ws_framing_utils_ruby.c +2 -2
  9. data/lib/oversip/config.rb +50 -38
  10. data/lib/oversip/default_server.rb +12 -0
  11. data/lib/oversip/launcher.rb +10 -35
  12. data/lib/oversip/master_process.rb +2 -2
  13. data/lib/oversip/proxies_config.rb +2 -2
  14. data/lib/oversip/sip/client_transaction.rb +1 -7
  15. data/lib/oversip/sip/grammar/uri.rb +23 -1
  16. data/lib/oversip/sip/listeners/{reactor.rb → connection.rb} +16 -2
  17. data/lib/oversip/sip/listeners/ipv4_udp_server.rb +1 -1
  18. data/lib/oversip/sip/listeners/ipv6_udp_server.rb +1 -1
  19. data/lib/oversip/sip/listeners/tcp_client.rb +2 -3
  20. data/lib/oversip/sip/listeners/{tcp_reactor.rb → tcp_connection.rb} +14 -2
  21. data/lib/oversip/sip/listeners/tcp_server.rb +2 -5
  22. data/lib/oversip/sip/listeners/tls_client.rb +15 -12
  23. data/lib/oversip/sip/listeners/tls_server.rb +11 -11
  24. data/lib/oversip/sip/listeners/{tls_tunnel_reactor.rb → tls_tunnel_connection.rb} +20 -20
  25. data/lib/oversip/sip/listeners/tls_tunnel_server.rb +2 -5
  26. data/lib/oversip/sip/listeners/{udp_reactor.rb → udp_connection.rb} +4 -4
  27. data/lib/oversip/sip/listeners.rb +6 -10
  28. data/lib/oversip/sip/message.rb +4 -3
  29. data/lib/oversip/sip/message_processor.rb +17 -17
  30. data/lib/oversip/sip/modules/core.rb +18 -13
  31. data/lib/oversip/sip/modules/user_assertion.rb +7 -53
  32. data/lib/oversip/sip/proxy.rb +3 -3
  33. data/lib/oversip/sip/request.rb +2 -0
  34. data/lib/oversip/sip/rfc3263.rb +3 -3
  35. data/lib/oversip/sip/sip.rb +6 -0
  36. data/lib/oversip/sip/transport_manager.rb +8 -8
  37. data/lib/oversip/tls.rb +18 -22
  38. data/lib/oversip/version.rb +1 -1
  39. data/lib/oversip/websocket/constants.rb +0 -1
  40. data/lib/oversip/websocket/http_request.rb +4 -8
  41. data/lib/oversip/websocket/launcher.rb +83 -139
  42. data/lib/oversip/websocket/listeners/connection.rb +47 -0
  43. data/lib/oversip/websocket/{ws_apps/ipv4_ws_sip_app.rb → listeners/ipv4_ws_server.rb} +3 -3
  44. data/lib/oversip/websocket/{ws_apps/ipv4_wss_sip_app.rb → listeners/ipv4_wss_server.rb} +2 -2
  45. data/lib/oversip/websocket/listeners/ipv4_wss_tunnel_server.rb +21 -0
  46. data/lib/oversip/websocket/{ws_apps/ipv6_ws_sip_app.rb → listeners/ipv6_ws_server.rb} +3 -3
  47. data/lib/oversip/websocket/{ws_apps/ipv6_wss_sip_app.rb → listeners/ipv6_wss_server.rb} +2 -3
  48. data/lib/oversip/websocket/listeners/ipv6_wss_tunnel_server.rb +21 -0
  49. data/lib/oversip/websocket/listeners/{tcp_server.rb → ws_server.rb} +63 -43
  50. data/lib/oversip/websocket/listeners/{tls_server.rb → wss_server.rb} +14 -13
  51. data/lib/oversip/websocket/listeners/{tls_tunnel_server.rb → wss_tunnel_server.rb} +36 -10
  52. data/lib/oversip/websocket/listeners.rb +10 -9
  53. data/lib/oversip/websocket/websocket.rb +13 -0
  54. data/lib/oversip/websocket/ws_framing.rb +35 -97
  55. data/lib/oversip/websocket/ws_sip_app.rb +120 -0
  56. data/lib/oversip.rb +1 -1
  57. data/test/oversip_test_helper.rb +2 -2
  58. data/test/test_http_parser.rb +2 -2
  59. data/test/test_sip_parser.rb +18 -3
  60. data/test/test_uri.rb +44 -0
  61. metadata +39 -42
  62. data/lib/oversip/websocket/listeners/ipv4_tcp_server.rb +0 -15
  63. data/lib/oversip/websocket/listeners/ipv4_tls_server.rb +0 -15
  64. data/lib/oversip/websocket/listeners/ipv4_tls_tunnel_server.rb +0 -15
  65. data/lib/oversip/websocket/listeners/ipv6_tcp_server.rb +0 -15
  66. data/lib/oversip/websocket/listeners/ipv6_tls_server.rb +0 -15
  67. data/lib/oversip/websocket/listeners/ipv6_tls_tunnel_server.rb +0 -15
  68. data/lib/oversip/websocket/ws_app.rb +0 -77
  69. data/lib/oversip/websocket/ws_apps/ws_autobahn_app.rb +0 -23
  70. data/lib/oversip/websocket/ws_apps/ws_sip_app.rb +0 -156
  71. data/lib/oversip/websocket/ws_apps.rb +0 -9
@@ -1,156 +0,0 @@
1
- module OverSIP::WebSocket
2
-
3
- class WsSipApp < WsApp
4
-
5
- include ::OverSIP::SIP::MessageProcessor
6
-
7
- class << self
8
- attr_accessor :ip_type, :ip, :port, :transport,
9
- :via_core,
10
- :record_route,
11
- :outbound_record_route_fragment, :outbound_path_fragment,
12
- :connections,
13
- :invite_server_transactions, :non_invite_server_transactions,
14
- :invite_client_transactions, :non_invite_client_transactions
15
-
16
- def reliable_transport_listener?
17
- @is_reliable_transport_listener
18
- end
19
- end
20
-
21
-
22
- attr_reader :outbound_flow_token
23
-
24
-
25
- def initialize connection, ws_framing
26
- super
27
- # WebSocket is message boundary so we just need a SIP parser instance.
28
- @@parser ||= ::OverSIP::SIP::MessageParser.new
29
- @parser = @@parser
30
-
31
- # If the request comes from the TLS proxy then take it into account.
32
- if @connection.class == ::OverSIP::WebSocket::IPv4TlsTunnelServer
33
- @connection_id = ::OverSIP::SIP::TransportManager.add_connection self, ::OverSIP::WebSocket::IPv4WssSipApp, :ipv4,
34
- @connection.remote_ip, @connection.remote_port
35
- elsif @connection.class == ::OverSIP::WebSocket::IPv6TlsTunnelServer
36
- @connection_id = ::OverSIP::SIP::TransportManager.add_connection self, ::OverSIP::WebSocket::IPv6WssSipApp, :ipv6,
37
- @connection.remote_ip, @connection.remote_port
38
- else
39
- @connection_id = ::OverSIP::SIP::TransportManager.add_connection self, self.class, self.class.ip_type,
40
- @connection.remote_ip, @connection.remote_port
41
- end
42
-
43
- # Create an Outbound (RFC 5626) flow token for this connection.
44
- @outbound_flow_token = ::OverSIP::SIP::TransportManager.add_outbound_connection self
45
- end
46
-
47
-
48
- def process_text_message ws_message
49
- process_sip_message ws_message
50
- end
51
-
52
-
53
- def process_binary_message ws_message
54
- process_sip_message ws_message
55
- end
56
-
57
-
58
- def process_sip_message ws_message
59
- # Just a single SIP message allowed per WS message.
60
- @parser.reset
61
-
62
- # Better to encode it as BINARY (to later extract the body).
63
- ws_message.force_encoding ::Encoding::BINARY
64
-
65
- unless parser_nbytes = @parser.execute(ws_message, 0)
66
- if wrong_message = @parser.parsed
67
- log_system_warn "SIP parsing error for #{MSG_TYPE[wrong_message.class]}: \"#{@parser.error}\""
68
- else
69
- log_system_warn "SIP parsing error: \"#{@parser.error}\""
70
- end
71
- close_connection 4000, "SIP message parsing error"
72
- return
73
- end
74
-
75
- unless @parser.finished?
76
- log_system_warn "SIP parsing error: message not completed"
77
-
78
- close_connection 4001, "SIP message incomplete"
79
- return
80
- end
81
-
82
- # At this point we've got a SIP::Request, SIP::Response or :outbound_keepalive symbol.
83
- @msg = @parser.parsed
84
-
85
- # Received data is a SIP Outbound keealive (double CRLF). Reply with single CRLF.
86
- if @msg == :outbound_keepalive
87
- log_system_debug "Outbound keepalive received, replying single CRLF" if $oversip_debug
88
- @ws_framing.send_text_frame(CRLF)
89
- return
90
- end
91
-
92
- @parser.post_parsing
93
-
94
- @msg.connection = self
95
- @msg.transport = self.class.transport
96
- @msg.source_ip = @connection.remote_ip
97
- @msg.source_port = @connection.remote_port
98
- @msg.source_ip_type = @connection.remote_ip_type
99
-
100
- return unless valid_message?
101
- add_via_received_rport if @msg.request?
102
- return unless check_via_branch
103
-
104
- # Get the body.
105
- if parser_nbytes != ws_message.bytesize
106
- @msg.body = ws_message[parser_nbytes..-1]
107
-
108
- if @msg.content_length and @msg.content_length != @msg.body.bytesize
109
- log_system_warn "SIP message body size (#{@msg.body.bytesize}) does not match Content-Length (#{@msg.content_length.inspect}), ignoring message"
110
- close_connection 4002, "SIP message body size does not match Content-Length"
111
- return
112
- end
113
- end
114
-
115
- if @msg.request?
116
- process_request
117
- else
118
- process_response
119
- end
120
-
121
- end
122
-
123
-
124
- def tcp_closed
125
- # Remove the connection.
126
- self.class.connections.delete @connection_id
127
-
128
- # Remove the Outbound token flow.
129
- ::OverSIP::SIP::TransportManager.delete_outbound_connection @outbound_flow_token
130
- end
131
-
132
-
133
- # Parameters ip and port are just included because they are needed in UDP, so the API remains equal.
134
- def send_sip_msg msg, ip=nil, port=nil
135
- # If the SIP message is fully valid UTF-8 send a WS text frame.
136
- if msg.force_encoding(::Encoding::UTF_8).valid_encoding?
137
- unless @ws_framing.send_text_frame(msg)
138
- log_system_notice "SIP message could not be sent, WebSocket connection is closed"
139
- return false
140
- end
141
-
142
- # If not, send a WS binary frame.
143
- else
144
- unless @ws_framing.send_binary_frame(msg)
145
- log_system_notice "SIP message could not be sent, WebSocket connection is closed"
146
- return false
147
- end
148
- end
149
-
150
- true
151
- end
152
-
153
-
154
- end # WsSipApp
155
-
156
- end
@@ -1,9 +0,0 @@
1
- # OverSIP files
2
-
3
- require "oversip/websocket/ws_apps/ws_sip_app"
4
- require "oversip/websocket/ws_apps/ipv4_ws_sip_app"
5
- require "oversip/websocket/ws_apps/ipv4_wss_sip_app"
6
- require "oversip/websocket/ws_apps/ipv6_ws_sip_app"
7
- require "oversip/websocket/ws_apps/ipv6_wss_sip_app"
8
- # WebSocket AutoBahn test.
9
- require "oversip/websocket/ws_apps/ws_autobahn_app"