oversip 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/AUTHORS.txt +11 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +16 -0
  4. data/Rakefile +55 -0
  5. data/bin/oversip +182 -0
  6. data/ext/common/c_util.h +74 -0
  7. data/ext/common/ruby_c_util.h +88 -0
  8. data/ext/sip_parser/common_headers.h +209 -0
  9. data/ext/sip_parser/ext_help.h +18 -0
  10. data/ext/sip_parser/extconf.rb +3 -0
  11. data/ext/sip_parser/sip_parser.c +29649 -0
  12. data/ext/sip_parser/sip_parser.h +227 -0
  13. data/ext/sip_parser/sip_parser_ruby.c +1292 -0
  14. data/ext/stud/extconf.rb +27 -0
  15. data/ext/stud/stud.tar.gz +0 -0
  16. data/ext/stun/ext_help.h +16 -0
  17. data/ext/stun/extconf.rb +3 -0
  18. data/ext/stun/stun_ruby.c +391 -0
  19. data/ext/utils/ext_help.h +14 -0
  20. data/ext/utils/extconf.rb +3 -0
  21. data/ext/utils/haproxy_protocol.c +6163 -0
  22. data/ext/utils/haproxy_protocol.h +27 -0
  23. data/ext/utils/ip_utils.c +5952 -0
  24. data/ext/utils/ip_utils.h +61 -0
  25. data/ext/utils/outbound_utils.c +3227 -0
  26. data/ext/utils/outbound_utils.h +27 -0
  27. data/ext/utils/utils_ruby.c +384 -0
  28. data/ext/utils/utils_ruby.h +75 -0
  29. data/ext/websocket_framing_utils/ext_help.h +18 -0
  30. data/ext/websocket_framing_utils/extconf.rb +3 -0
  31. data/ext/websocket_framing_utils/ws_framing_utils.h +46 -0
  32. data/ext/websocket_framing_utils/ws_framing_utils_ruby.c +135 -0
  33. data/ext/websocket_http_parser/ext_help.h +18 -0
  34. data/ext/websocket_http_parser/extconf.rb +3 -0
  35. data/ext/websocket_http_parser/ws_http_parser.c +2598 -0
  36. data/ext/websocket_http_parser/ws_http_parser.h +86 -0
  37. data/ext/websocket_http_parser/ws_http_parser_ruby.c +630 -0
  38. data/lib/oversip/config.rb +541 -0
  39. data/lib/oversip/config_validators.rb +126 -0
  40. data/lib/oversip/errors.rb +7 -0
  41. data/lib/oversip/fiber_pool.rb +56 -0
  42. data/lib/oversip/launcher.rb +507 -0
  43. data/lib/oversip/logger.rb +170 -0
  44. data/lib/oversip/master_process.rb +67 -0
  45. data/lib/oversip/posix_mq.rb +121 -0
  46. data/lib/oversip/proxies_config.rb +169 -0
  47. data/lib/oversip/ruby_ext/eventmachine.rb +38 -0
  48. data/lib/oversip/sip/client_transaction.rb +587 -0
  49. data/lib/oversip/sip/constants.rb +87 -0
  50. data/lib/oversip/sip/grammar/name_addr.rb +27 -0
  51. data/lib/oversip/sip/grammar/uri.rb +116 -0
  52. data/lib/oversip/sip/launcher.rb +180 -0
  53. data/lib/oversip/sip/listeners/ipv4_tcp_client.rb +21 -0
  54. data/lib/oversip/sip/listeners/ipv4_tcp_server.rb +21 -0
  55. data/lib/oversip/sip/listeners/ipv4_tls_client.rb +21 -0
  56. data/lib/oversip/sip/listeners/ipv4_tls_server.rb +21 -0
  57. data/lib/oversip/sip/listeners/ipv4_tls_tunnel_server.rb +21 -0
  58. data/lib/oversip/sip/listeners/ipv4_udp_server.rb +20 -0
  59. data/lib/oversip/sip/listeners/ipv6_tcp_client.rb +21 -0
  60. data/lib/oversip/sip/listeners/ipv6_tcp_server.rb +21 -0
  61. data/lib/oversip/sip/listeners/ipv6_tls_client.rb +21 -0
  62. data/lib/oversip/sip/listeners/ipv6_tls_server.rb +21 -0
  63. data/lib/oversip/sip/listeners/ipv6_tls_tunnel_server.rb +21 -0
  64. data/lib/oversip/sip/listeners/ipv6_udp_server.rb +20 -0
  65. data/lib/oversip/sip/listeners/reactor.rb +39 -0
  66. data/lib/oversip/sip/listeners/tcp_client.rb +73 -0
  67. data/lib/oversip/sip/listeners/tcp_reactor.rb +185 -0
  68. data/lib/oversip/sip/listeners/tcp_server.rb +71 -0
  69. data/lib/oversip/sip/listeners/tls_client.rb +117 -0
  70. data/lib/oversip/sip/listeners/tls_server.rb +70 -0
  71. data/lib/oversip/sip/listeners/tls_tunnel_reactor.rb +113 -0
  72. data/lib/oversip/sip/listeners/tls_tunnel_server.rb +61 -0
  73. data/lib/oversip/sip/listeners/udp_reactor.rb +213 -0
  74. data/lib/oversip/sip/listeners.rb +28 -0
  75. data/lib/oversip/sip/logic.rb +14 -0
  76. data/lib/oversip/sip/message.rb +168 -0
  77. data/lib/oversip/sip/message_processor.rb +202 -0
  78. data/lib/oversip/sip/modules/core.rb +200 -0
  79. data/lib/oversip/sip/modules/registrar_without_path.rb +75 -0
  80. data/lib/oversip/sip/modules/user_assertion.rb +123 -0
  81. data/lib/oversip/sip/proxy.rb +460 -0
  82. data/lib/oversip/sip/request.rb +128 -0
  83. data/lib/oversip/sip/response.rb +30 -0
  84. data/lib/oversip/sip/rfc3263.rb +646 -0
  85. data/lib/oversip/sip/server_transaction.rb +295 -0
  86. data/lib/oversip/sip/sip.rb +74 -0
  87. data/lib/oversip/sip/tags.rb +39 -0
  88. data/lib/oversip/sip/timers.rb +55 -0
  89. data/lib/oversip/sip/transport_manager.rb +129 -0
  90. data/lib/oversip/syslogger_process.rb +119 -0
  91. data/lib/oversip/tls.rb +179 -0
  92. data/lib/oversip/utils.rb +25 -0
  93. data/lib/oversip/version.rb +23 -0
  94. data/lib/oversip/websocket/constants.rb +56 -0
  95. data/lib/oversip/websocket/default_policy.rb +19 -0
  96. data/lib/oversip/websocket/http_request.rb +63 -0
  97. data/lib/oversip/websocket/launcher.rb +207 -0
  98. data/lib/oversip/websocket/listeners/ipv4_tcp_server.rb +15 -0
  99. data/lib/oversip/websocket/listeners/ipv4_tls_server.rb +15 -0
  100. data/lib/oversip/websocket/listeners/ipv4_tls_tunnel_server.rb +15 -0
  101. data/lib/oversip/websocket/listeners/ipv6_tcp_server.rb +15 -0
  102. data/lib/oversip/websocket/listeners/ipv6_tls_server.rb +15 -0
  103. data/lib/oversip/websocket/listeners/ipv6_tls_tunnel_server.rb +15 -0
  104. data/lib/oversip/websocket/listeners/tcp_server.rb +265 -0
  105. data/lib/oversip/websocket/listeners/tls_server.rb +69 -0
  106. data/lib/oversip/websocket/listeners/tls_tunnel_server.rb +100 -0
  107. data/lib/oversip/websocket/listeners.rb +12 -0
  108. data/lib/oversip/websocket/ws_app.rb +75 -0
  109. data/lib/oversip/websocket/ws_apps/ipv4_ws_sip_app.rb +21 -0
  110. data/lib/oversip/websocket/ws_apps/ipv4_wss_sip_app.rb +21 -0
  111. data/lib/oversip/websocket/ws_apps/ipv6_ws_sip_app.rb +21 -0
  112. data/lib/oversip/websocket/ws_apps/ipv6_wss_sip_app.rb +22 -0
  113. data/lib/oversip/websocket/ws_apps/ws_autobahn_app.rb +23 -0
  114. data/lib/oversip/websocket/ws_apps/ws_sip_app.rb +156 -0
  115. data/lib/oversip/websocket/ws_apps.rb +9 -0
  116. data/lib/oversip/websocket/ws_framing.rb +597 -0
  117. data/lib/oversip.rb +59 -0
  118. data/test/oversip_test_helper.rb +20 -0
  119. data/test/test_http_parser.rb +73 -0
  120. data/test/test_sip_parser.rb +139 -0
  121. metadata +256 -0
@@ -0,0 +1,22 @@
1
+ module OverSIP::WebSocket
2
+
3
+ class IPv6WssSipApp < WsSipApp
4
+
5
+ @ip_type = :ipv6
6
+ @transport = :wss
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 = "WSS IPv6 SIP app"
15
+ def log_id
16
+ LOG_ID
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
@@ -0,0 +1,23 @@
1
+ module OverSIP::WebSocket
2
+
3
+ class WsAutobahnApp < WsApp
4
+
5
+ LOG_ID = "WS IPv4 AutoBahn app"
6
+ def log_id
7
+ LOG_ID
8
+ end
9
+
10
+ def process_text_message ws_message
11
+ #log_system_info "received WS text message: length=#{ws_message.bytesize}, replying the same..."
12
+ @ws_framing.send_text_frame ws_message
13
+ end
14
+
15
+
16
+ def process_binary_message ws_message
17
+ #log_system_info "received WS binary message: length=#{ws_message.bytesize}, replying the same..."
18
+ @ws_framing.send_binary_frame ws_message
19
+ end
20
+
21
+ end # WsAutobahnApp
22
+
23
+ end
@@ -0,0 +1,156 @@
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 *args
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 # WsSipApplication
155
+
156
+ end
@@ -0,0 +1,9 @@
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"