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
data/lib/oversip.rb ADDED
@@ -0,0 +1,127 @@
1
+ #
2
+ # OverSIP
3
+ # Copyright (c) 2012-2014 Iñaki Baz Castillo <ibc@aliax.net>
4
+ # MIT License
5
+ #
6
+
7
+ # Ruby built-in libraries.
8
+
9
+ require "rbconfig"
10
+ require "etc"
11
+ require "fileutils"
12
+ require "socket"
13
+ require "timeout"
14
+ require "yaml"
15
+ require "tempfile"
16
+ require "base64"
17
+ require "digest/md5"
18
+ require "digest/sha1"
19
+ require "securerandom"
20
+ require "fiber"
21
+ require "openssl"
22
+
23
+
24
+ # Ruby external gems.
25
+
26
+ require "syslog"
27
+ gem "eventmachine", "~> 1.2.0"
28
+ require "eventmachine"
29
+ gem "iobuffer", "= 1.1.2"
30
+ require "iobuffer"
31
+ gem "em-udns", "= 0.3.6"
32
+ require "em-udns"
33
+ gem "escape_utils", "= 1.0.1"
34
+ require "escape_utils"
35
+ gem "term-ansicolor", "= 1.3.2"
36
+ require "term/ansicolor"
37
+ gem "posix-spawn", "= 0.3.9"
38
+ require "posix-spawn"
39
+ gem "em-synchrony", "= 1.0.3"
40
+ require "em-synchrony"
41
+
42
+
43
+ # OverSIP files.
44
+
45
+ require "oversip/version.rb"
46
+ require "oversip/syslog.rb"
47
+ require "oversip/logger.rb"
48
+ require "oversip/config.rb"
49
+ require "oversip/config_validators.rb"
50
+ require "oversip/proxies_config.rb"
51
+ require "oversip/errors.rb"
52
+ require "oversip/launcher.rb"
53
+ require "oversip/utils.#{RbConfig::CONFIG["DLEXT"]}"
54
+ require "oversip/utils.rb"
55
+ require "oversip/default_server.rb"
56
+ require "oversip/system_callbacks.rb"
57
+
58
+ require "oversip/sip/sip.rb"
59
+ require "oversip/sip/sip_parser.#{RbConfig::CONFIG["DLEXT"]}"
60
+ require "oversip/sip/constants.rb"
61
+ require "oversip/sip/core.rb"
62
+ require "oversip/sip/message.rb"
63
+ require "oversip/sip/request.rb"
64
+ require "oversip/sip/response.rb"
65
+ require "oversip/sip/uri.rb"
66
+ require "oversip/sip/name_addr.rb"
67
+ require "oversip/sip/message_processor.rb"
68
+ require "oversip/sip/listeners.rb"
69
+ require "oversip/sip/launcher.rb"
70
+ require "oversip/sip/server_transaction.rb"
71
+ require "oversip/sip/client_transaction.rb"
72
+ require "oversip/sip/transport_manager.rb"
73
+ require "oversip/sip/timers.rb"
74
+ require "oversip/sip/tags.rb"
75
+ require "oversip/sip/rfc3263.rb"
76
+ require "oversip/sip/client.rb"
77
+ require "oversip/sip/proxy.rb"
78
+ require "oversip/sip/uac.rb"
79
+ require "oversip/sip/uac_request.rb"
80
+
81
+ require "oversip/websocket/websocket.rb"
82
+ require "oversip/websocket/ws_http_parser.#{RbConfig::CONFIG["DLEXT"]}"
83
+ require "oversip/websocket/constants.rb"
84
+ require "oversip/websocket/http_request.rb"
85
+ require "oversip/websocket/listeners.rb"
86
+ require "oversip/websocket/launcher.rb"
87
+ require "oversip/websocket/ws_framing_utils.#{RbConfig::CONFIG["DLEXT"]}"
88
+ require "oversip/websocket/ws_framing.rb"
89
+ require "oversip/websocket/ws_sip_app.rb"
90
+
91
+ require "oversip/fiber_pool.rb"
92
+ require "oversip/tls.rb"
93
+ require "oversip/stun.#{RbConfig::CONFIG["DLEXT"]}"
94
+
95
+ require "oversip/modules/user_assertion.rb"
96
+ require "oversip/modules/outbound_mangling.rb"
97
+
98
+ require "oversip/ruby_ext/eventmachine.rb"
99
+
100
+
101
+ module OverSIP
102
+
103
+ class << self
104
+ attr_accessor :pid_file, :master_name, :pid, :daemonized,
105
+ :configuration,
106
+ :proxies,
107
+ :tls_public_cert, :tls_private_cert,
108
+ :stud_pids,
109
+ :is_ready, # true, false
110
+ :status, # :loading, :running, :terminating
111
+ :root_fiber
112
+
113
+ def daemonized?
114
+ @daemonized
115
+ end
116
+
117
+ end
118
+
119
+ # Pre-declare internal modules.
120
+ module SIP ; end
121
+ module WebSocket ; end
122
+ module Modules ; end
123
+
124
+ # Allow OverSIP::M::MODULE_NAME usage.
125
+ M = Modules
126
+
127
+ end
@@ -0,0 +1,19 @@
1
+ require "test/unit"
2
+ require "oversip"
3
+
4
+
5
+ class OverSIPTest < Test::Unit::TestCase
6
+
7
+ def assert_true(object, message="")
8
+ assert_equal(true, object, message)
9
+ end
10
+
11
+ def assert_false(object, message="")
12
+ assert_equal(false, object, message)
13
+ end
14
+
15
+ def assert_equal_options(options, element)
16
+ assert options.include?(element)
17
+ end
18
+
19
+ end
@@ -0,0 +1,73 @@
1
+ # coding: utf-8
2
+
3
+ require "oversip_test_helper"
4
+
5
+
6
+ class TestHttpParser < OverSIPTest
7
+
8
+ def parse data
9
+ parser = OverSIP::WebSocket::HttpRequestParser.new
10
+ buffer = IO::Buffer.new
11
+ request = OverSIP::WebSocket::HttpRequest.new
12
+
13
+ buffer << data
14
+
15
+ unless bytes_parsed = parser.execute(request, buffer.to_str, 0)
16
+ raise "ERROR: parsing error: \"#{parser.error}\""
17
+ end
18
+
19
+ if parser.finished?
20
+ buffer.read bytes_parsed
21
+ if request.content_length and ! request.content_length.zero?
22
+ request.body = buffer.read request.content_length
23
+ end
24
+ if buffer.size != 0
25
+ raise "ERROR: buffer is not empty after parsing"
26
+ end
27
+ else
28
+ raise "ERROR: parsed NOT finished!"
29
+ end
30
+
31
+ [parser, request]
32
+ end
33
+ private :parse
34
+
35
+ def test_parse_http_get
36
+ parser, request = parse <<-END
37
+ GET /chat?qwe=QWE&asd=#fragment HTTP/1.1\r
38
+ Host: server.example.Com.\r
39
+ Upgrade: WebSocket\r
40
+ Connection: keep-Alive , Upgrade\r
41
+ Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r
42
+ Sec-WebSocket-protocol: foo , chat.lalala.com\r
43
+ Sec-WebSocket-protocol: xmpp.nonaino.org\r
44
+ Origin: http://example.Com\r
45
+ Sec-WebSocket-Version: 13\r
46
+ noNaino-lALA : qwe\r
47
+ NOnaino-lala: asd\r
48
+ \r
49
+ END
50
+
51
+ assert_equal request.http_method, :GET
52
+ assert_equal request.http_version, "HTTP/1.1"
53
+
54
+ assert_equal "/chat?qwe=QWE&asd=#fragment", request.uri
55
+ assert_equal "/chat", request.uri_path
56
+ assert_equal "qwe=QWE&asd=", request.uri_query
57
+ assert_equal "fragment", request.uri_fragment
58
+ assert_equal request.uri_scheme, nil
59
+ assert_equal "server.example.com", request.host
60
+ assert_nil request.port
61
+
62
+ assert_nil request.content_length
63
+ assert request.hdr_connection.include?("upgrade")
64
+ assert_equal "websocket", request.hdr_upgrade
65
+ assert_equal 13, request.hdr_sec_websocket_version
66
+ assert_equal "dGhlIHNhbXBsZSBub25jZQ==", request.hdr_sec_websocket_key
67
+ assert_equal "http://example.com", request.hdr_origin
68
+ assert_equal ["foo", "chat.lalala.com", "xmpp.nonaino.org"], request.hdr_sec_websocket_protocol
69
+
70
+ assert_equal ["qwe", "asd"], request["Nonaino-Lala"]
71
+ end
72
+
73
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+
3
+ require "oversip_test_helper"
4
+
5
+
6
+ class TestNameAddr < OverSIPTest
7
+
8
+ def test_name_addr
9
+ full_name_addr = '"Iñaki Baz Castillo" <sips:i%C3%B1aki@aliax.net:5060;transport=tcp;foo=123;baz?X-Header-1=qwe&X-Header-2=asd>'
10
+ aor = "sip:i%C3%B1aki@aliax.net"
11
+
12
+ name_addr = ::OverSIP::SIP::NameAddr.new "Iñaki Baz Castillo", :sips, "iñaki", "aliax.net", 5060
13
+ name_addr.transport_param = :tcp
14
+ name_addr.set_param "FOO", "123"
15
+ name_addr.set_param "baz", nil
16
+ name_addr.headers = "?X-Header-1=qwe&X-Header-2=asd"
17
+
18
+ assert_true name_addr.sip?
19
+ assert_false name_addr.tel?
20
+ assert_false name_addr.unknown_scheme?
21
+ assert_equal "iñaki", name_addr.user
22
+ assert_equal "123", name_addr.get_param("Foo")
23
+ assert_equal aor, name_addr.aor
24
+ assert_equal full_name_addr, name_addr.to_s
25
+ end
26
+
27
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+
3
+ require "oversip_test_helper"
4
+
5
+
6
+ class TestNameAddrParser < OverSIPTest
7
+
8
+ def test_parse_name_addr
9
+ name_addr_str = '"Iñaki" <sips:i%C3%B1aki@aliax.net:5060;transport=tcp;foo=123;baz?X-Header-1=qwe&X-Header-2=asd>'
10
+ aor = "sip:i%C3%B1aki@aliax.net"
11
+
12
+ name_addr = ::OverSIP::SIP::NameAddr.parse name_addr_str
13
+
14
+ assert_equal ::OverSIP::SIP::NameAddr, name_addr.class
15
+ assert_equal "Iñaki", name_addr.display_name
16
+ assert_true name_addr.sip?
17
+ assert_false name_addr.unknown_scheme?
18
+ assert_equal "iñaki", name_addr.user
19
+ assert_equal "123", name_addr.get_param("Foo")
20
+ assert_equal aor, name_addr.aor
21
+ assert_equal name_addr_str, name_addr.to_s
22
+ end
23
+
24
+ end
@@ -0,0 +1,168 @@
1
+ # coding: utf-8
2
+
3
+ require "oversip_test_helper"
4
+
5
+
6
+ class TestSipMessageParser < OverSIPTest
7
+
8
+ def parse data
9
+ parser = OverSIP::SIP::MessageParser.new
10
+ buffer = IO::Buffer.new
11
+
12
+ buffer << data
13
+
14
+ unless bytes_parsed = parser.execute(buffer.to_str, 0)
15
+ raise "ERROR: parsing error for class #{parser.parsed.class}: \"#{parser.error}\""
16
+ end
17
+
18
+ msg = parser.parsed
19
+
20
+ if parser.finished?
21
+ buffer.read bytes_parsed
22
+ if msg.content_length and ! msg.content_length.zero?
23
+ msg.body = buffer.read msg.content_length
24
+ end
25
+ if buffer.size != 0
26
+ raise "ERROR: buffer is not empty after parsing"
27
+ end
28
+ else
29
+ raise "ERROR: parsed NOT finished! (msg.class = #{msg.class})"
30
+ end
31
+
32
+ parser.post_parsing
33
+
34
+ [parser, msg]
35
+ end
36
+ private :parse
37
+
38
+ def test_parse_sip_invite
39
+ parser, msg = parse <<-END
40
+ INVITE sip:sips%3Auser%40example.com@example.NET.;transport=tcp;FOO=baz?Subject=lalala SIP/2.0\r
41
+ via: SIP/2.0/UDP host5.example.net;branch=z9hG4bKkdjuw ; Rport\r
42
+ v: SIP/2.0/TCP 1.2.3.4;branch=z9hG4bKkdjuw\r
43
+ To: <tel:+(34)-94-499-44-22;lalala=lololo>\r
44
+ from: <sips:I%20have%20spaces@[2001:123:Ab:0:0::123]:9999> ;\r
45
+ tag=938\r
46
+ Route: <sip:qweqwe/.+asdasd@1.2.3.4:7777;LR;ob>,\r
47
+ "Server Ñ€áéíóú" <SIP:[01::000:A0f]:6666;lr>\r
48
+ Max-Forwards: 87\r
49
+ _i: esc01.239409asdfakjkn23onasd0-3234\r
50
+ CSeq: 234234 INVITE\r
51
+ C: application/sdp\r
52
+ Require: AAA, Bbb\r
53
+ Require: ccc\r
54
+ Proxy-Require: AAA, Bbb\r
55
+ Proxy-Require: ccc\r
56
+ Supported: AAA, Bbb\r
57
+ k: ccc\r
58
+ Contact:\r
59
+ <sip:cal%6Cer@host5.example.net;%6C%72;n%61me=v%61lue%25%34%31;ob>;p1=foo;P2=BAR;+sip-instance=qweqwe;reg-id=1\r
60
+ Content-Length: 150\r
61
+ \r
62
+ v=0\r
63
+ o=mhandley 29739 7272939 IN IP4 192.0.2.1\r
64
+ s=-\r
65
+ c=IN IP4 192.0.2.1\r
66
+ t=0 0\r
67
+ m=audio 49217 RTP/AVP 0 12\r
68
+ m=video 3227 RTP/AVP 31\r
69
+ a=rtpmap:31 LPC\r
70
+ END
71
+
72
+ assert_equal msg.class, OverSIP::SIP::Request
73
+ assert_equal msg.sip_method, :INVITE
74
+ assert_equal msg.sip_version, "SIP/2.0"
75
+ assert_true msg.initial?
76
+
77
+ assert_false parser.duplicated_core_header?
78
+ assert_equal parser.missing_core_header?, "Call-ID"
79
+
80
+ assert_equal msg.num_vias, 2
81
+ assert_equal msg.via_sent_by_host, "host5.example.net"
82
+ assert_nil msg.via_sent_by_port
83
+ assert_nil msg.via_received
84
+ assert_true msg.via_rport?
85
+ assert_equal msg.via_core_value, "SIP/2.0/UDP host5.example.net"
86
+ assert_nil msg.via_params
87
+ assert_equal ["SIP/2.0/UDP host5.example.net;branch=z9hG4bKkdjuw ; Rport", "SIP/2.0/TCP 1.2.3.4;branch=z9hG4bKkdjuw"], msg.hdr_via
88
+
89
+ assert_equal msg.cseq, 234234
90
+ assert_equal msg.max_forwards, 87
91
+ assert_equal msg.content_length, 150
92
+ assert_equal msg.body.bytesize, 150
93
+
94
+ assert_equal "sip:sips%3auser%40example.com@example.net.;transport=tcp;foo=baz?subject=lalala", msg.ruri.uri.downcase
95
+ assert_equal :sip, msg.ruri.scheme
96
+ assert_equal "sips:user@example.com", msg.ruri.user
97
+ assert_equal "example.net", msg.ruri.host
98
+ assert_equal :domain, msg.ruri.host_type
99
+ assert_nil msg.ruri.port
100
+ assert_equal({"transport" => "tcp", "foo" => "baz"}, msg.ruri.params)
101
+ assert_equal "?Subject=lalala", msg.ruri.headers
102
+ assert_equal :tcp, msg.ruri.transport_param
103
+ assert_nil msg.ruri.phone_context_param
104
+
105
+ assert_equal :sips, msg.from.scheme
106
+ assert_equal "I have spaces", msg.from.user
107
+ assert OverSIP::Utils.compare_ips("[2001:123:ab::123]", msg.from.host)
108
+ assert_equal :ipv6_reference, msg.from.host_type
109
+ assert_equal 9999, msg.from.port
110
+ assert_equal({}, msg.from.params)
111
+ assert_equal "938", msg.from_tag
112
+
113
+ assert_equal :tel, msg.to.scheme
114
+ assert_equal "+34944994422", msg.to.user
115
+ assert_nil msg.to.host
116
+ assert_nil msg.to.port
117
+ assert_equal({"lalala" => "lololo"}, msg.to.params)
118
+ assert_nil msg.to_tag
119
+
120
+ assert_equal :sip, msg.contact.scheme
121
+ assert_equal "caller", msg.contact.user
122
+ assert_equal "host5.example.net", msg.contact.host
123
+ assert_equal :domain, msg.contact.host_type
124
+ assert_nil msg.contact.port
125
+ assert_true msg.contact.ob_param?
126
+ assert_equal({"%6c%72" => nil, "n%61me" => "v%61lue%25%34%31", "ob" => nil}, msg.contact.params)
127
+ assert_equal ";p1=foo;P2=BAR;+sip-instance=qweqwe;reg-id=1", msg.contact_params
128
+ assert_true msg.contact_reg_id?
129
+
130
+ assert_equal 2, msg.routes.size
131
+
132
+ assert_nil msg.routes.first.display_name
133
+ assert_equal :sip, msg.routes.first.scheme
134
+ assert_equal "qweqwe/.+asdasd", msg.routes.first.user
135
+ assert OverSIP::Utils.compare_ips("1.2.3.4", msg.routes.first.host)
136
+ assert_equal "1.2.3.4", msg.routes.first.host
137
+ assert_equal :ipv4, msg.routes.first.host_type
138
+ assert_equal 7777, msg.routes.first.port
139
+ assert_true msg.routes.first.lr_param?
140
+
141
+ assert_equal "Server Ñ€áéíóú", msg.routes[1].display_name
142
+ assert_equal :sip, msg.routes[1].scheme
143
+ assert_nil msg.routes[1].user
144
+ assert OverSIP::Utils.compare_ips("[1::a0f]", msg.routes[1].host)
145
+ assert_equal :ipv6_reference, msg.routes[1].host_type
146
+ assert_equal 6666, msg.routes[1].port
147
+ assert_true msg.routes[1].lr_param?
148
+
149
+ assert_equal ["aaa", "bbb", "ccc"], msg.require
150
+ assert_equal ["aaa", "bbb", "ccc"], msg.proxy_require
151
+ assert_equal ["aaa", "bbb", "ccc"], msg.supported
152
+
153
+ # Change the full RURI and test again.
154
+ msg.ruri = ::OverSIP::SIP::Uri.new :sips, "iñaki", "aliax.net", 7070
155
+
156
+ assert_equal :sips, msg.ruri.scheme
157
+ assert_equal "iñaki", msg.ruri.user
158
+ assert_equal "aliax.net", msg.ruri.host
159
+ assert_equal :domain, msg.ruri.host_type
160
+ assert_equal 7070, msg.ruri.port
161
+ assert_equal({}, msg.ruri.params)
162
+ assert_nil msg.ruri.headers
163
+ assert_nil msg.ruri.transport_param
164
+ assert_nil msg.ruri.phone_context_param
165
+ assert_equal "sips:i%C3%B1aki@aliax.net:7070", msg.ruri.to_s
166
+ end
167
+
168
+ end
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+
3
+ require "oversip_test_helper"
4
+
5
+
6
+ class TestSipUriParser < OverSIPTest
7
+
8
+ def test_parse_sip_uri
9
+ uri_str = "sips:i%C3%B1aki@aliax.net:5060;transport=tcp;foo=123;baz?X-Header-1=qwe&X-Header-2=asd"
10
+ aor = "sip:i%C3%B1aki@aliax.net"
11
+
12
+ uri = ::OverSIP::SIP::Uri.parse uri_str
13
+
14
+ assert_equal ::OverSIP::SIP::Uri, uri.class
15
+ assert_true uri.sip?
16
+ assert_false uri.unknown_scheme?
17
+ assert_equal "iñaki", uri.user
18
+ assert_true uri.has_param? "FOO"
19
+ assert_false uri.has_param? "LALALA"
20
+ assert_equal "123", uri.get_param("Foo")
21
+ assert_equal aor, uri.aor
22
+ assert_equal uri_str, uri.to_s
23
+ end
24
+
25
+ def test_parse_tel_uri
26
+ uri_str = "tel:944991212;foo=bar;phone-context=+34"
27
+ aor = "tel:944991212"
28
+
29
+ uri = ::OverSIP::SIP::Uri.parse uri_str
30
+
31
+ assert_equal ::OverSIP::SIP::Uri, uri.class
32
+ assert_true uri.tel?
33
+ assert_false uri.unknown_scheme?
34
+ assert_equal "944991212", uri.number
35
+ assert_true uri.has_param? "FOO"
36
+ assert_false uri.has_param? "LALALA"
37
+ assert_equal "bar", uri.get_param("Foo")
38
+ assert_equal aor, uri.aor
39
+ assert_equal uri_str, uri.to_s
40
+ end
41
+
42
+ def test_parse_http_uri
43
+ uri_str = "http://oversip.net/authors/"
44
+ aor = nil
45
+
46
+ uri = ::OverSIP::SIP::Uri.parse uri_str
47
+
48
+ assert_equal ::OverSIP::SIP::Uri, uri.class
49
+ assert_false uri.sip?
50
+ assert_false uri.tel?
51
+ assert_true uri.unknown_scheme?
52
+ assert_nil uri.has_param? "FOO"
53
+ assert_nil uri.aor
54
+ assert_equal uri_str, uri.to_s
55
+ end
56
+ end
data/test/test_uri.rb ADDED
@@ -0,0 +1,68 @@
1
+ # coding: utf-8
2
+
3
+ require "oversip_test_helper"
4
+
5
+
6
+ class TestUri < OverSIPTest
7
+
8
+ def test_sip_uri
9
+ full_uri = "sips:i%C3%B1aki@aliax.net:5060;transport=tcp;foo=123;baz?X-Header-1=qwe&X-Header-2=asd"
10
+ aor = "sip:i%C3%B1aki@aliax.net"
11
+
12
+ uri = ::OverSIP::SIP::Uri.new :sips, "iñaki", "aliax.net", 5060
13
+ uri.transport_param = :tcp
14
+ uri.set_param "FOO", "123"
15
+ uri.set_param "baz", nil
16
+ uri.headers = "?X-Header-1=qwe&X-Header-2=asd"
17
+
18
+ assert_true uri.sip?
19
+ assert_false uri.tel?
20
+ assert_false uri.unknown_scheme?
21
+ assert_equal "iñaki", uri.user
22
+ assert_equal "123", uri.get_param("Foo")
23
+ assert_equal aor, uri.aor
24
+ assert_equal full_uri, uri.to_s
25
+
26
+ uri.clear_params
27
+
28
+ assert_equal({}, uri.params)
29
+ assert_equal "sips:i%C3%B1aki@aliax.net:5060?X-Header-1=qwe&X-Header-2=asd", uri.to_s
30
+ end
31
+
32
+ def test_tel_uri
33
+ full_uri = "tel:944991212;foo=bar;phone-context=+34"
34
+ aor = "tel:944991212"
35
+
36
+ uri = ::OverSIP::SIP::Uri.new :tel, "944991212"
37
+ uri.set_param "FOO", "bar"
38
+ uri.phone_context_param = "+34"
39
+
40
+ assert_false uri.sip?
41
+ assert_true uri.tel?
42
+ assert_false uri.unknown_scheme?
43
+ assert_equal "944991212", uri.number
44
+ assert_equal "bar", uri.get_param("Foo")
45
+ assert_equal aor, uri.aor
46
+ assert_equal full_uri, uri.to_s
47
+
48
+ uri.clear_params
49
+
50
+ assert_equal({}, uri.params)
51
+ assert_equal aor, uri.to_s
52
+ end
53
+
54
+ def test_http_uri
55
+ full_uri = "http://oversip.net/authors/"
56
+ aor = nil
57
+
58
+ uri = ::OverSIP::SIP::Uri.allocate
59
+ uri.instance_variable_set :@uri, full_uri
60
+
61
+ assert_false uri.sip?
62
+ assert_false uri.tel?
63
+ assert_true uri.unknown_scheme?
64
+ assert_nil uri.aor
65
+ assert_equal full_uri, uri.to_s
66
+ assert_nil uri.clear_params
67
+ end
68
+ end
Binary file