oversip_p 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/AUTHORS +22 -0
- data/LICENSE +25 -0
- data/README.md +43 -0
- data/Rakefile +54 -0
- data/bin/oversip +184 -0
- data/etc/oversip.conf +274 -0
- data/etc/proxies.conf +145 -0
- data/etc/server.rb +315 -0
- data/etc/tls/ca/cacert.pem +3894 -0
- data/etc/tls/demo-tls.oversip.net.crt +17 -0
- data/etc/tls/demo-tls.oversip.net.key +15 -0
- data/etc/tls/upgrade-cacert.sh +12 -0
- data/etc/tls/utils/create-cert.rb +162 -0
- data/etc/tls/utils/get-sip-identities.rb +95 -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 +210 -0
- data/ext/sip_parser/ext_help.h +18 -0
- data/ext/sip_parser/extconf.rb +3 -0
- data/ext/sip_parser/sip_message_parser.c +29741 -0
- data/ext/sip_parser/sip_parser.h +250 -0
- data/ext/sip_parser/sip_parser_ruby.c +1370 -0
- data/ext/sip_parser/sip_uri_parser.c +39699 -0
- data/ext/stud/extconf.rb +43 -0
- data/ext/stun/ext_help.h +16 -0
- data/ext/stun/extconf.rb +3 -0
- data/ext/stun/stun_ruby.c +394 -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 +64 -0
- data/ext/utils/outbound_utils.c +3227 -0
- data/ext/utils/outbound_utils.h +27 -0
- data/ext/utils/utils_ruby.c +392 -0
- data/ext/utils/utils_ruby.h +76 -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 +47 -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 +1635 -0
- data/ext/websocket_http_parser/ws_http_parser.h +87 -0
- data/ext/websocket_http_parser/ws_http_parser_ruby.c +630 -0
- data/lib/oversip/config.rb +597 -0
- data/lib/oversip/config_validators.rb +126 -0
- data/lib/oversip/default_server.rb +52 -0
- data/lib/oversip/errors.rb +10 -0
- data/lib/oversip/fiber_pool.rb +56 -0
- data/lib/oversip/launcher.rb +635 -0
- data/lib/oversip/logger.rb +84 -0
- data/lib/oversip/modules/outbound_mangling.rb +56 -0
- data/lib/oversip/modules/user_assertion.rb +73 -0
- data/lib/oversip/proxies_config.rb +189 -0
- data/lib/oversip/ruby_ext/eventmachine.rb +38 -0
- data/lib/oversip/sip/client.rb +428 -0
- data/lib/oversip/sip/client_transaction.rb +586 -0
- data/lib/oversip/sip/constants.rb +88 -0
- data/lib/oversip/sip/core.rb +217 -0
- data/lib/oversip/sip/launcher.rb +221 -0
- data/lib/oversip/sip/listeners/connection.rb +54 -0
- data/lib/oversip/sip/listeners/ipv4_tcp_client.rb +21 -0
- data/lib/oversip/sip/listeners/ipv4_tcp_server.rb +22 -0
- data/lib/oversip/sip/listeners/ipv4_tls_client.rb +21 -0
- data/lib/oversip/sip/listeners/ipv4_tls_server.rb +22 -0
- data/lib/oversip/sip/listeners/ipv4_tls_tunnel_server.rb +22 -0
- data/lib/oversip/sip/listeners/ipv4_udp_server.rb +21 -0
- data/lib/oversip/sip/listeners/ipv6_tcp_client.rb +21 -0
- data/lib/oversip/sip/listeners/ipv6_tcp_server.rb +22 -0
- data/lib/oversip/sip/listeners/ipv6_tls_client.rb +21 -0
- data/lib/oversip/sip/listeners/ipv6_tls_server.rb +22 -0
- data/lib/oversip/sip/listeners/ipv6_tls_tunnel_server.rb +22 -0
- data/lib/oversip/sip/listeners/ipv6_udp_server.rb +21 -0
- data/lib/oversip/sip/listeners/tcp_client.rb +97 -0
- data/lib/oversip/sip/listeners/tcp_connection.rb +202 -0
- data/lib/oversip/sip/listeners/tcp_server.rb +71 -0
- data/lib/oversip/sip/listeners/tls_client.rb +125 -0
- data/lib/oversip/sip/listeners/tls_server.rb +88 -0
- data/lib/oversip/sip/listeners/tls_tunnel_connection.rb +89 -0
- data/lib/oversip/sip/listeners/tls_tunnel_server.rb +61 -0
- data/lib/oversip/sip/listeners/udp_connection.rb +214 -0
- data/lib/oversip/sip/listeners.rb +24 -0
- data/lib/oversip/sip/message.rb +177 -0
- data/lib/oversip/sip/message_processor.rb +213 -0
- data/lib/oversip/sip/name_addr.rb +51 -0
- data/lib/oversip/sip/proxy.rb +324 -0
- data/lib/oversip/sip/request.rb +179 -0
- data/lib/oversip/sip/response.rb +37 -0
- data/lib/oversip/sip/rfc3263.rb +643 -0
- data/lib/oversip/sip/server_transaction.rb +295 -0
- data/lib/oversip/sip/sip.rb +76 -0
- data/lib/oversip/sip/tags.rb +39 -0
- data/lib/oversip/sip/timers.rb +55 -0
- data/lib/oversip/sip/transport_manager.rb +130 -0
- data/lib/oversip/sip/uac.rb +89 -0
- data/lib/oversip/sip/uac_request.rb +84 -0
- data/lib/oversip/sip/uri.rb +208 -0
- data/lib/oversip/syslog.rb +68 -0
- data/lib/oversip/system_callbacks.rb +45 -0
- data/lib/oversip/tls.rb +172 -0
- data/lib/oversip/utils.rb +30 -0
- data/lib/oversip/version.rb +21 -0
- data/lib/oversip/websocket/constants.rb +55 -0
- data/lib/oversip/websocket/http_request.rb +59 -0
- data/lib/oversip/websocket/launcher.rb +183 -0
- data/lib/oversip/websocket/listeners/connection.rb +51 -0
- data/lib/oversip/websocket/listeners/ipv4_ws_server.rb +22 -0
- data/lib/oversip/websocket/listeners/ipv4_wss_server.rb +22 -0
- data/lib/oversip/websocket/listeners/ipv4_wss_tunnel_server.rb +22 -0
- data/lib/oversip/websocket/listeners/ipv6_ws_server.rb +22 -0
- data/lib/oversip/websocket/listeners/ipv6_wss_server.rb +22 -0
- data/lib/oversip/websocket/listeners/ipv6_wss_tunnel_server.rb +22 -0
- data/lib/oversip/websocket/listeners/ws_server.rb +331 -0
- data/lib/oversip/websocket/listeners/wss_server.rb +88 -0
- data/lib/oversip/websocket/listeners/wss_tunnel_server.rb +133 -0
- data/lib/oversip/websocket/listeners.rb +13 -0
- data/lib/oversip/websocket/websocket.rb +13 -0
- data/lib/oversip/websocket/ws_framing.rb +545 -0
- data/lib/oversip/websocket/ws_sip_app.rb +120 -0
- data/lib/oversip.rb +127 -0
- data/test/oversip_test_helper.rb +19 -0
- data/test/test_http_parser.rb +73 -0
- data/test/test_name_addr.rb +27 -0
- data/test/test_name_addr_parser.rb +24 -0
- data/test/test_sip_message_parser.rb +168 -0
- data/test/test_sip_uri_parser.rb +56 -0
- data/test/test_uri.rb +68 -0
- data/thirdparty/stud/stud.tar.gz +0 -0
- metadata +334 -0
@@ -0,0 +1,179 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class Request < Message
|
4
|
+
|
5
|
+
include ::OverSIP::SIP::Core
|
6
|
+
|
7
|
+
SECURE_TRANSPORTS = { :tls=>true, :wss=>true }
|
8
|
+
|
9
|
+
attr_accessor :server_transaction
|
10
|
+
attr_reader :ruri
|
11
|
+
attr_reader :new_max_forwards
|
12
|
+
attr_accessor :antiloop_id
|
13
|
+
attr_accessor :route_outbound_flow_token
|
14
|
+
attr_writer :outgoing_outbound_requested, :incoming_outbound_requested
|
15
|
+
attr_accessor :proxied # If true it means that this request has been already proxied.
|
16
|
+
attr_reader :from_was_modified, :to_was_modified # Set to true if the From / To has been modified prior to routing the request.
|
17
|
+
|
18
|
+
# Used for internal purposes when doing proxy and adding the first Record-Route
|
19
|
+
# or Path.
|
20
|
+
attr_accessor :in_rr
|
21
|
+
|
22
|
+
attr_accessor :cvars # Connection variables (a hash).
|
23
|
+
|
24
|
+
|
25
|
+
def log_id
|
26
|
+
@log_id ||= "SIP Request #{@via_branch_id}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def request? ; true end
|
30
|
+
def response? ; false end
|
31
|
+
|
32
|
+
def initial? ; ! @to_tag end
|
33
|
+
def in_dialog? ; @to_tag end
|
34
|
+
|
35
|
+
def secure?
|
36
|
+
SECURE_TRANSPORTS[@transport] || false
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def reply status_code, reason_phrase=nil, extra_headers=[], body=nil
|
41
|
+
if @sip_method == :ACK
|
42
|
+
log_system_error "attemtp to reply to an ACK aborted"
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
return false unless @server_transaction.receive_response(status_code) if @server_transaction
|
46
|
+
|
47
|
+
reason_phrase ||= REASON_PHRASE[status_code] || REASON_PHRASE_NOT_SET
|
48
|
+
|
49
|
+
if status_code > 100
|
50
|
+
@internal_to_tag ||= @to_tag || ( @server_transaction ? ::SecureRandom.hex(6) : ::OverSIP::SIP::Tags.totag_for_sl_reply )
|
51
|
+
end
|
52
|
+
|
53
|
+
response = "SIP/2.0 #{status_code} #{reason_phrase}\r\n"
|
54
|
+
|
55
|
+
@hdr_via.each do |hdr|
|
56
|
+
response << "Via: " << hdr << CRLF
|
57
|
+
end
|
58
|
+
|
59
|
+
response << "From: " << @hdr_from << CRLF
|
60
|
+
|
61
|
+
response << "To: " << @hdr_to
|
62
|
+
response << ";tag=#{@internal_to_tag}" if @internal_to_tag
|
63
|
+
response << CRLF
|
64
|
+
|
65
|
+
response << "Call-ID: " << @call_id << CRLF
|
66
|
+
response << "CSeq: " << @cseq.to_s << " " << @sip_method.to_s << CRLF
|
67
|
+
response << "Content-Length: #{body ? body.bytesize : "0"}\r\n"
|
68
|
+
|
69
|
+
extra_headers.each do |header|
|
70
|
+
response << header.to_s << CRLF
|
71
|
+
end if extra_headers
|
72
|
+
|
73
|
+
response << HDR_SERVER << CRLF
|
74
|
+
response << CRLF
|
75
|
+
|
76
|
+
response << body if body
|
77
|
+
|
78
|
+
@server_transaction.last_response = response if @server_transaction
|
79
|
+
|
80
|
+
log_system_debug "replying #{status_code} \"#{reason_phrase}\"" if $oversip_debug
|
81
|
+
|
82
|
+
send_response(response)
|
83
|
+
true
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def reply_full response
|
88
|
+
return false unless @server_transaction.receive_response(response.status_code) if @server_transaction
|
89
|
+
|
90
|
+
# Ensure the response has Content-Length. Add it otherwise.
|
91
|
+
if response.body
|
92
|
+
response.headers["Content-Length"] = [ response.body.bytesize.to_s ]
|
93
|
+
else
|
94
|
+
response.headers["Content-Length"] = HDR_ARRAY_CONTENT_LENGTH_0
|
95
|
+
end
|
96
|
+
|
97
|
+
response_leg_a = response.to_s
|
98
|
+
@server_transaction.last_response = response_leg_a if @server_transaction
|
99
|
+
|
100
|
+
log_system_debug "forwarding response #{response.status_code} \"#{response.reason_phrase}\"" if $oversip_debug
|
101
|
+
|
102
|
+
send_response(response_leg_a)
|
103
|
+
true
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
# RFC 6228 (199 response).
|
108
|
+
def reply_199 response
|
109
|
+
# Store the previous internal To-tag (if set).
|
110
|
+
internal_to_tag = @internal_to_tag
|
111
|
+
|
112
|
+
# Set it with the To-tag of the response for which a 199 must eb generated.
|
113
|
+
@internal_to_tag = response.to_tag
|
114
|
+
|
115
|
+
# Send the 199 response.
|
116
|
+
reply 199, "Early Dialog Terminated", [ "Reason: SIP ;cause=#{response.status_code} ;text=\"#{response.reason_phrase}\"" ]
|
117
|
+
|
118
|
+
# Restore the previous internal To-tag.
|
119
|
+
@internal_to_tag = internal_to_tag
|
120
|
+
true
|
121
|
+
end
|
122
|
+
private :reply_199
|
123
|
+
|
124
|
+
|
125
|
+
def ruri= ruri
|
126
|
+
case ruri
|
127
|
+
when ::OverSIP::SIP::Uri, ::OverSIP::SIP::NameAddr
|
128
|
+
@ruri = ruri
|
129
|
+
when ::String
|
130
|
+
@ruri = OverSIP::SIP::Uri.parse ruri
|
131
|
+
else
|
132
|
+
raise ::OverSIP::RuntimeError, "invalid URI #{ruri.inspect}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
def send_response(response)
|
138
|
+
unless (case @transport
|
139
|
+
when :udp
|
140
|
+
@connection.send_sip_msg response, @source_ip, @via_rport || @via_sent_by_port || 5060
|
141
|
+
else
|
142
|
+
@connection.send_sip_msg response
|
143
|
+
end
|
144
|
+
)
|
145
|
+
log_system_notice "error sending the SIP response"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
def to_s
|
151
|
+
msg = "#{@sip_method.to_s} #{@ruri.uri} SIP/2.0\r\n"
|
152
|
+
|
153
|
+
# Update From/To/Contact headers if modified.
|
154
|
+
if @from.modified?
|
155
|
+
@headers["From"] = [ @from.to_s << (@from_tag ? ";tag=#{@from_tag}" : "") ]
|
156
|
+
@from_was_modified = true
|
157
|
+
end
|
158
|
+
if @to.modified?
|
159
|
+
@headers["To"] = [ @to.to_s << (@to_tag ? ";tag=#{@to_tag}" : "") ]
|
160
|
+
@to_was_modified = true
|
161
|
+
end
|
162
|
+
if @contact and @contact.modified?
|
163
|
+
@headers["Contact"] = [ @contact.to_s << (@contact_params ? @contact_params : "") ]
|
164
|
+
end
|
165
|
+
|
166
|
+
@headers.each do |name, values|
|
167
|
+
values.each do |value|
|
168
|
+
msg << name << ": #{value}\r\n"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
msg << CRLF
|
173
|
+
msg << @body if @body
|
174
|
+
msg
|
175
|
+
end
|
176
|
+
|
177
|
+
end # class Request
|
178
|
+
|
179
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module OverSIP::SIP
|
2
|
+
|
3
|
+
class Response < Message
|
4
|
+
|
5
|
+
attr_accessor :status_code
|
6
|
+
attr_accessor :reason_phrase
|
7
|
+
attr_accessor :request # The associated request.
|
8
|
+
|
9
|
+
|
10
|
+
def request? ; false end
|
11
|
+
def response? ; true end
|
12
|
+
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
msg = "SIP/2.0 #{@status_code} #{@reason_phrase}\r\n"
|
16
|
+
|
17
|
+
# Revert changes to From/To headers if modified during the request processing.
|
18
|
+
@headers["From"] = [ request.hdr_from ] if request.from_was_modified
|
19
|
+
if request.to_was_modified
|
20
|
+
hdr_to = @to_tag ? "#{request.hdr_to};tag=#{@to_tag}" : request.hdr_to
|
21
|
+
@headers["To"] = [ hdr_to ]
|
22
|
+
end
|
23
|
+
|
24
|
+
@headers.each do |name, values|
|
25
|
+
values.each do |value|
|
26
|
+
msg << name << ": #{value}\r\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
msg << CRLF
|
31
|
+
msg << @body if @body
|
32
|
+
msg
|
33
|
+
end
|
34
|
+
|
35
|
+
end # class Response
|
36
|
+
|
37
|
+
end
|