opensips-mi 0.0.10 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +7 -0
- data/Gemfile +9 -4
- data/README.md +134 -118
- data/Rakefile +8 -12
- data/lib/opensips/mi/command.rb +85 -92
- data/lib/opensips/mi/transport/abstract.rb +64 -0
- data/lib/opensips/mi/transport/datagram.rb +41 -28
- data/lib/opensips/mi/transport/http.rb +40 -0
- data/lib/opensips/mi/transport/xmlrpc.rb +36 -22
- data/lib/opensips/mi/transport.rb +4 -1
- data/lib/opensips/mi/version.rb +3 -1
- data/lib/opensips/mi.rb +17 -12
- data/lib/opensips.rb +4 -0
- data/sig/opensips/mi.rbs +6 -0
- metadata +20 -69
- data/.gitignore +0 -30
- data/.rspec +0 -1
- data/.travis.yml +0 -3
- data/lib/opensips/mi/response.rb +0 -176
- data/lib/opensips/mi/transport/fifo.rb +0 -90
- data/opensips-mi.gemspec +0 -25
- data/spec/command_spec.rb +0 -4
- data/spec/fixtures/dlg_list +0 -20
- data/spec/fixtures/ul_dump +0 -168
- data/spec/response_spec.rb +0 -117
- data/spec/spec_helper.rb +0 -112
- data/spec/transport_spec.rb +0 -119
data/spec/response_spec.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
include Opensips::MI
|
2
|
-
|
3
|
-
describe Response do
|
4
|
-
it "must raise if parameter is not Array" do
|
5
|
-
expect {Response.new "foo"}.to raise_error InvalidResponseData
|
6
|
-
end
|
7
|
-
|
8
|
-
it "must raise if response data id empty array" do
|
9
|
-
expect {Response.new Array[]}.to raise_error EmptyResponseData
|
10
|
-
end
|
11
|
-
|
12
|
-
it "must raise if invalid response data" do
|
13
|
-
expect {Response.new(["invalid param","343",222])}.
|
14
|
-
to raise_error InvalidResponseData
|
15
|
-
end
|
16
|
-
|
17
|
-
it "must parse successfull response" do
|
18
|
-
resp = Response.new ["200 it is OK", "data", ""]
|
19
|
-
expect(resp.success).to be_truthy
|
20
|
-
expect(resp.code).to be(200)
|
21
|
-
expect(resp.message).to match("it is OK")
|
22
|
-
end
|
23
|
-
|
24
|
-
it "must parse unsuccessfull response" do
|
25
|
-
resp = Response.new ["500 command 'unknown' not available"]
|
26
|
-
expect(resp.success).to be_falsey
|
27
|
-
expect(resp.code).to be(500)
|
28
|
-
expect(resp.message).to match("command 'unknown' not available")
|
29
|
-
end
|
30
|
-
|
31
|
-
it "parse ul dump response" do
|
32
|
-
res = Response.new(fixture('ul_dump'))
|
33
|
-
ul = res.ul_dump
|
34
|
-
expect(ul.result["7962"]).not_to be_nil
|
35
|
-
expect(ul.result["7962"][0][:callid]).to match("5e7a1e47da91c41c")
|
36
|
-
end
|
37
|
-
|
38
|
-
it "process uptime response" do
|
39
|
-
res = Response.new [
|
40
|
-
"200 OK",
|
41
|
-
"Now:: Fri Apr 12 22:04:27 2013",
|
42
|
-
"Up since:: Thu Apr 11 21:43:01 2013",
|
43
|
-
"Up time:: 87686 [sec]",
|
44
|
-
""
|
45
|
-
]
|
46
|
-
resp = res.uptime
|
47
|
-
expect(resp.result.uptime).to be(87686)
|
48
|
-
expect(resp.result.since.thursday?).to be_truthy
|
49
|
-
expect(resp.result.since.hour).to be(21)
|
50
|
-
expect(resp.result.since.mon).to be(4)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "must fetch cache value" do
|
54
|
-
res = Response.new [
|
55
|
-
"200 OK",
|
56
|
-
"userdid = [18005552211]",
|
57
|
-
""
|
58
|
-
]
|
59
|
-
resp= res.cache_fetch
|
60
|
-
expect(resp.result.userdid).to match("18005552211")
|
61
|
-
end
|
62
|
-
|
63
|
-
it "must return userloc contacts" do
|
64
|
-
contacts = ["200 OK",
|
65
|
-
"Contact:: <sip:7747@10.132.113.198>;q=;expires=100;flags=0x0;cflags=0x0;socket=<udp:10.130.8.21:5060>;methods=0x1F7F;user_agent=<PolycomSoundStationIP-SSIP_6000-UA/3.3.5.0247_0004f2f18103>",
|
66
|
-
"Contact:: <sip:7747@10.130.8.100;line=628f4ffdfa7316e>;q=;expires=3593;flags=0x0;cflags=0x0;socket=<udp:10.130.8.21:5060>;methods=0xFFFFFFFF;user_agent=<Linphone/3.5.2 (eXosip2/3.6.0)>",
|
67
|
-
""]
|
68
|
-
response = Response.new contacts
|
69
|
-
res = response.ul_show_contact
|
70
|
-
expect(res.size).to be(2)
|
71
|
-
expect(res.first[:socket]).to match("<udp:10.130.8.21:5060>")
|
72
|
-
expect(res.last[:expires]).to match("3593")
|
73
|
-
end
|
74
|
-
|
75
|
-
it "must process dialogs list" do
|
76
|
-
response = Response.new fixture('dlg_list')
|
77
|
-
res = response.dlg_list.result
|
78
|
-
expect(res.size).to be(1)
|
79
|
-
expect(res["3212:2099935485"][:callid]).to match("1854719653")
|
80
|
-
end
|
81
|
-
|
82
|
-
it "must process dr_gw_status response in hash" do
|
83
|
-
gw_list = [
|
84
|
-
"200 OK",
|
85
|
-
"ID:: gw1 IP=212.182.133.202:5060 Enabled=no ",
|
86
|
-
"ID:: gw2 IP=213.15.222.97:5060 Enabled=yes",
|
87
|
-
"ID:: gw3 IP=200.182.132.201:5060 Enabled=yes",
|
88
|
-
"ID:: gw4 IP=200.182.135.204:5060 Enabled=yes",
|
89
|
-
"ID:: pstn1 IP=199.18.14.101:5060 Enabled=yes",
|
90
|
-
"ID:: pstn2 IP=199.18.14.102:5060 Enabled=no",
|
91
|
-
"ID:: pstn3 IP=199.18.12.103:5060 Enabled=yes",
|
92
|
-
"ID:: pstn4 IP=199.18.12.104:5060 Enabled=yes",
|
93
|
-
""
|
94
|
-
]
|
95
|
-
response = Response.new gw_list
|
96
|
-
drgws = response.dr_gw_status
|
97
|
-
expect(drgws.result.size).to be(8)
|
98
|
-
expect(drgws.result["pstn4"][:ipaddr]).to match("199.18.12.104")
|
99
|
-
expect(drgws.result["pstn3"][:port]).to match("5060")
|
100
|
-
expect(drgws.result["gw1"][:enabled]).to be_falsey
|
101
|
-
expect(drgws.result["gw4"][:enabled]).to be_truthy
|
102
|
-
end
|
103
|
-
|
104
|
-
it "must return raw data if dr_gw_status is run with arguments" do
|
105
|
-
gw = [ "200 OK", "Enabled:: yes", "" ]
|
106
|
-
response = Response.new gw
|
107
|
-
drgws = response.dr_gw_status
|
108
|
-
expect(drgws.enabled).to be_truthy
|
109
|
-
end
|
110
|
-
|
111
|
-
it "result must be empty if command send to dr_gw_status" do
|
112
|
-
response = Response.new [ "200 OK", "" ]
|
113
|
-
drgws = response.dr_gw_status
|
114
|
-
expect(drgws.result).to be_nil
|
115
|
-
expect(drgws.success).to be_truthy
|
116
|
-
end
|
117
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
-
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
-
# files.
|
6
|
-
#
|
7
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
-
# a separate helper file that requires the additional dependencies and performs
|
12
|
-
# the additional setup, and require it from the spec files that actually need
|
13
|
-
# it.
|
14
|
-
#
|
15
|
-
|
16
|
-
require 'simplecov'
|
17
|
-
SimpleCov.start
|
18
|
-
|
19
|
-
require 'opensips/mi'
|
20
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
21
|
-
RSpec.configure do |config|
|
22
|
-
# rspec-expectations config goes here. You can use an alternate
|
23
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
24
|
-
# assertions if you prefer.
|
25
|
-
config.expect_with :rspec do |expectations|
|
26
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
27
|
-
# and `failure_message` of custom matchers include text for helper methods
|
28
|
-
# defined using `chain`, e.g.:
|
29
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
30
|
-
# # => "be bigger than 2 and smaller than 4"
|
31
|
-
# ...rather than:
|
32
|
-
# # => "be bigger than 2"
|
33
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
34
|
-
end
|
35
|
-
|
36
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
37
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
38
|
-
config.mock_with :rspec do |mocks|
|
39
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
40
|
-
# a real object. This is generally recommended, and will default to
|
41
|
-
# `true` in RSpec 4.
|
42
|
-
mocks.verify_partial_doubles = true
|
43
|
-
end
|
44
|
-
|
45
|
-
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
46
|
-
# have no way to turn it off -- the option exists only for backwards
|
47
|
-
# compatibility in RSpec 3). It causes shared context metadata to be
|
48
|
-
# inherited by the metadata hash of host groups and examples, rather than
|
49
|
-
# triggering implicit auto-inclusion in groups with matching metadata.
|
50
|
-
config.shared_context_metadata_behavior = :apply_to_host_groups
|
51
|
-
|
52
|
-
# The settings below are suggested to provide a good initial experience
|
53
|
-
# with RSpec, but feel free to customize to your heart's content.
|
54
|
-
=begin
|
55
|
-
# This allows you to limit a spec run to individual examples or groups
|
56
|
-
# you care about by tagging them with `:focus` metadata. When nothing
|
57
|
-
# is tagged with `:focus`, all examples get run. RSpec also provides
|
58
|
-
# aliases for `it`, `describe`, and `context` that include `:focus`
|
59
|
-
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
60
|
-
config.filter_run_when_matching :focus
|
61
|
-
|
62
|
-
# Allows RSpec to persist some state between runs in order to support
|
63
|
-
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
64
|
-
# you configure your source control system to ignore this file.
|
65
|
-
config.example_status_persistence_file_path = "spec/examples.txt"
|
66
|
-
|
67
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
68
|
-
# recommended. For more details, see:
|
69
|
-
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
70
|
-
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
71
|
-
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
72
|
-
config.disable_monkey_patching!
|
73
|
-
|
74
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
75
|
-
# be too noisy due to issues in dependencies.
|
76
|
-
config.warnings = true
|
77
|
-
|
78
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
79
|
-
# file, and it's useful to allow more verbose output when running an
|
80
|
-
# individual spec file.
|
81
|
-
if config.files_to_run.one?
|
82
|
-
# Use the documentation formatter for detailed output,
|
83
|
-
# unless a formatter has already been configured
|
84
|
-
# (e.g. via a command-line flag).
|
85
|
-
config.default_formatter = "doc"
|
86
|
-
end
|
87
|
-
|
88
|
-
# Print the 10 slowest examples and example groups at the
|
89
|
-
# end of the spec run, to help surface which specs are running
|
90
|
-
# particularly slow.
|
91
|
-
config.profile_examples = 10
|
92
|
-
|
93
|
-
# Run specs in random order to surface order dependencies. If you find an
|
94
|
-
# order dependency and want to debug it, you can fix the order by providing
|
95
|
-
# the seed, which is printed after each run.
|
96
|
-
# --seed 1234
|
97
|
-
config.order = :random
|
98
|
-
|
99
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
100
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
101
|
-
# test failures related to randomization by passing the same `--seed` value
|
102
|
-
# as the one that triggered the failure.
|
103
|
-
Kernel.srand config.seed
|
104
|
-
=end
|
105
|
-
end
|
106
|
-
|
107
|
-
def fixture(name)
|
108
|
-
path = File.expand_path('fixtures', File.dirname(__FILE__))
|
109
|
-
file = File.expand_path(name, path)
|
110
|
-
File.readlines(file).map{|l| l.chomp}
|
111
|
-
end
|
112
|
-
|
data/spec/transport_spec.rb
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
include Opensips::MI
|
2
|
-
|
3
|
-
describe Transport do
|
4
|
-
context "fifo" do
|
5
|
-
it "must raise when using unknown transport method" do
|
6
|
-
expect {
|
7
|
-
Opensips::MI.connect(:unknown_transport_method,{})
|
8
|
-
}.to raise_error NameError
|
9
|
-
end
|
10
|
-
|
11
|
-
it "must raise when no fifo_nameInstanceOf.new parameter passed" do
|
12
|
-
expect {
|
13
|
-
Opensips::MI.connect :fifo, {}
|
14
|
-
}.to raise_error ArgumentError
|
15
|
-
end
|
16
|
-
|
17
|
-
it "must raise when fifo_name file not exists" do
|
18
|
-
allow(File).to receive(:exists?).and_return(false)
|
19
|
-
expect {
|
20
|
-
Opensips::MI.connect :fifo, :fifo_name => '/file/not/exists'
|
21
|
-
}.to raise_error ArgumentError
|
22
|
-
end
|
23
|
-
|
24
|
-
it "must raise when fifo_name file is not pipe" do
|
25
|
-
allow(File).to receive(:exists?).and_return(true)
|
26
|
-
allow(File).to receive(:pipe?).and_return(false)
|
27
|
-
expect {
|
28
|
-
Opensips::MI.connect :fifo, :fifo_name => '/tmp/opensips_fifo'
|
29
|
-
}.to raise_error ArgumentError
|
30
|
-
end
|
31
|
-
|
32
|
-
it "must raise if fifo reply directory not exists" do
|
33
|
-
allow(Dir).to receive(:exists?).and_return(false)
|
34
|
-
expect {
|
35
|
-
Opensips::MI.connect :fifo, :fifo_name => '/tmp/opensips_fifo',
|
36
|
-
:reply_dir => '/tmp'
|
37
|
-
}.to raise_error ArgumentError
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "datagram" do
|
42
|
-
it "must raise if empty host" do
|
43
|
-
expect {
|
44
|
-
Opensips::MI.connect :datagram, {}
|
45
|
-
}.to raise_error ArgumentError
|
46
|
-
end
|
47
|
-
|
48
|
-
it "must raise if empty port" do
|
49
|
-
expect {
|
50
|
-
Opensips::MI.connect :datagram, {:host => "10.10.10.10"}
|
51
|
-
}.to raise_error ArgumentError
|
52
|
-
end
|
53
|
-
|
54
|
-
it "must raise if invalid host" do
|
55
|
-
host = "256.0.0.300"
|
56
|
-
expect {
|
57
|
-
Opensips::MI.connect :datagram, {:host => host, :port => 8088}
|
58
|
-
}.to raise_error(SocketError, /#{host}/)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "must raise if invalid port" do
|
62
|
-
expect {
|
63
|
-
Opensips::MI.connect :datagram, {:host => "10.0.0.1", :port => (2**16 + 1)}
|
64
|
-
}.to raise_error SocketError
|
65
|
-
|
66
|
-
expect {
|
67
|
-
Opensips::MI.connect :datagram, {:host => "10.0.0.1", :port => 0}
|
68
|
-
}.to raise_error SocketError
|
69
|
-
end
|
70
|
-
|
71
|
-
it "default timeout is 3 sec" do
|
72
|
-
mi=Opensips::MI.connect :datagram, {:host => "10.0.0.1", :port => 8088}
|
73
|
-
expect(mi.tout).to be(3)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "must set timeout from params" do
|
77
|
-
mi=Opensips::MI.connect :datagram, {:host => "10.0.0.1", :port => 8088, :timeout => 15}
|
78
|
-
expect(mi.tout).to be(15)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "must foo" do
|
82
|
-
mi=Opensips::MI.connect :datagram, {:host => "10.0.0.1", :port => 8088, :timeout => 1}
|
83
|
-
expect {
|
84
|
-
mi.uptime
|
85
|
-
}.to raise_error Timeout::Error
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "xmlrpc" do
|
90
|
-
it "must raise if empty host" do
|
91
|
-
expect {
|
92
|
-
Opensips::MI.connect :xmlrpc, {}
|
93
|
-
}.to raise_error ArgumentError
|
94
|
-
end
|
95
|
-
|
96
|
-
it "must raise if empty port" do
|
97
|
-
expect {
|
98
|
-
Opensips::MI.connect :xmlrpc, {:host => "10.10.10.10"}
|
99
|
-
}.to raise_error ArgumentError
|
100
|
-
end
|
101
|
-
|
102
|
-
it "must raise if invalid host" do
|
103
|
-
host = "256.0.0.300"
|
104
|
-
expect {
|
105
|
-
Opensips::MI.connect :xmlrpc, {:host => host, :port => 8088}
|
106
|
-
}.to raise_error(SocketError, /#{host}/)
|
107
|
-
end
|
108
|
-
|
109
|
-
it "must raise if invalid port" do
|
110
|
-
expect {
|
111
|
-
Opensips::MI.connect :xmlrpc, {:host => "10.0.0.1", :port => (2**16 + 1)}
|
112
|
-
}.to raise_error SocketError
|
113
|
-
|
114
|
-
expect {
|
115
|
-
Opensips::MI.connect :xmlrpc, {:host => "10.0.0.1", :port => 0}
|
116
|
-
}.to raise_error SocketError
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|