opensips-mi 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +1 -0
- data/README.md +1 -0
- data/lib/opensips/mi/response.rb +58 -24
- data/lib/opensips/mi/transport/fifo.rb +4 -4
- data/lib/opensips/mi/version.rb +1 -1
- data/test/fifo/.keep +0 -0
- data/test/helper.rb +62 -66
- data/test/test_command.rb +1 -10
- data/test/test_response.rb +2 -2
- metadata +15 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ccf5f5bbbc6e55802390c34cfc14d9786a3a66cae096150d2bf7ae9f58ca3bc6
|
4
|
+
data.tar.gz: 2d2e16891fe1c6d0489c04df6a3ad03eb7971247f388cd19b29b456adb6cc34f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a31f00548de585c638296aa97b8fe4889c6d5d85deb7afe83be364a555941b476836f73d053516e05add7d8999f75fc0027a2008adbcdf1e8b2e57c12ae9fad1
|
7
|
+
data.tar.gz: '028af90298a552a3bfff6054de1543acb519aeb846e78074e28b5c638d539a48734ef38eab3eb0cb2374e3b5f59167b655f7c32fa16b198cffff68c91c7fb689'
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/lib/opensips/mi/response.rb
CHANGED
@@ -10,7 +10,7 @@ module Opensips
|
|
10
10
|
'Invalid parameter' unless data.is_a? Array
|
11
11
|
raise EmptyResponseData,
|
12
12
|
'Empty parameter array' if data.empty?
|
13
|
-
|
13
|
+
|
14
14
|
if /^(?<code>\d+) (?<message>.+)$/ =~ data.shift.to_s
|
15
15
|
@code = code.to_i
|
16
16
|
@message = message
|
@@ -22,26 +22,34 @@ module Opensips
|
|
22
22
|
@success = (200..299).include?(@code)
|
23
23
|
|
24
24
|
# successfull responses have additional new line
|
25
|
-
data.pop if @success
|
26
25
|
@rawdata = data
|
27
26
|
@result = nil
|
28
27
|
end
|
29
|
-
|
28
|
+
|
30
29
|
# Parse user locations records to Hash
|
31
30
|
def ul_dump
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
res = {}
|
32
|
+
aor = nil
|
33
|
+
contact = nil
|
34
|
+
|
35
35
|
@rawdata.each do |r|
|
36
|
-
if
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
if
|
41
|
-
|
36
|
+
next if r.start_with?("Domain")
|
37
|
+
r = r.strip
|
38
|
+
key, val = r.split(":: ")
|
39
|
+
|
40
|
+
if key == "AOR"
|
41
|
+
aor = val
|
42
|
+
res[aor] = []
|
43
|
+
next
|
44
|
+
elsif key == "Contact"
|
45
|
+
contact = {}
|
46
|
+
res[aor] << contact
|
42
47
|
end
|
48
|
+
|
49
|
+
contact[key.gsub(?-, ?_).downcase.to_sym] = val if key
|
43
50
|
end
|
44
|
-
|
51
|
+
|
52
|
+
@result = res
|
45
53
|
self
|
46
54
|
end
|
47
55
|
|
@@ -73,22 +81,29 @@ module Opensips
|
|
73
81
|
@result = OpenStruct.new res
|
74
82
|
self
|
75
83
|
end
|
76
|
-
|
84
|
+
|
77
85
|
# returns Array of registered contacts
|
78
86
|
def ul_show_contact
|
79
|
-
res =
|
87
|
+
res = {}
|
88
|
+
aor = nil
|
89
|
+
contact = nil
|
90
|
+
|
80
91
|
@rawdata.each do |r|
|
81
|
-
|
82
|
-
r.split(
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
92
|
+
r = r.strip
|
93
|
+
key, val = r.split(":: ")
|
94
|
+
|
95
|
+
if key == "AOR"
|
96
|
+
aor = val
|
97
|
+
res[aor] = []
|
98
|
+
next
|
99
|
+
elsif key == "Contact"
|
100
|
+
contact = {}
|
101
|
+
res[aor] << contact if res[aor]
|
89
102
|
end
|
90
|
-
|
103
|
+
|
104
|
+
contact[key.gsub(?-, ?_).downcase.to_sym] = val if key
|
91
105
|
end
|
106
|
+
|
92
107
|
@result = res
|
93
108
|
self
|
94
109
|
end
|
@@ -124,6 +139,25 @@ module Opensips
|
|
124
139
|
self
|
125
140
|
end
|
126
141
|
|
142
|
+
# returns array containing list of opensips processes
|
143
|
+
def ps
|
144
|
+
processes = []
|
145
|
+
@rawdata.each do |l|
|
146
|
+
l.slice! "Process:: "
|
147
|
+
h = {}
|
148
|
+
|
149
|
+
l.split(" ", 3).each do |x|
|
150
|
+
key, val = x.split("=", 2)
|
151
|
+
h[key.downcase.to_sym] = val
|
152
|
+
end
|
153
|
+
|
154
|
+
processes << OpenStruct.new(h)
|
155
|
+
end
|
156
|
+
|
157
|
+
@result = processes
|
158
|
+
self
|
159
|
+
end
|
160
|
+
|
127
161
|
private
|
128
162
|
def dr_gws_hash
|
129
163
|
Hash[
|
@@ -28,7 +28,7 @@ module Opensips
|
|
28
28
|
params[:reply_dir]
|
29
29
|
end
|
30
30
|
raise ArgumentError,
|
31
|
-
"Fifo reply directory does not exists #{@reply_dir}" unless Dir.
|
31
|
+
"Fifo reply directory does not exists #{@reply_dir}" unless Dir.exist? @reply_dir
|
32
32
|
|
33
33
|
# fifo_name is required parameter
|
34
34
|
raise ArgumentError,
|
@@ -36,10 +36,10 @@ module Opensips
|
|
36
36
|
|
37
37
|
@fifo_name = params[:fifo_name]
|
38
38
|
raise ArgumentError,
|
39
|
-
"OpenSIPs fifo_name file does not exist: #{@fifo_name}" unless File.
|
39
|
+
"OpenSIPs fifo_name file does not exist: #{@fifo_name}" unless File.exist? @fifo_name
|
40
40
|
raise ArgumentError,
|
41
41
|
"File #{@fifo_name} is not pipe" unless File.pipe? @fifo_name
|
42
|
-
|
42
|
+
|
43
43
|
# set finalizing method
|
44
44
|
reply_file = File.expand_path(@reply_fifo, @reply_dir)
|
45
45
|
ObjectSpace.define_finalizer(self, proc{self.class.finalize(reply_file)})
|
@@ -81,7 +81,7 @@ module Opensips
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def self.finalize(reply_file)
|
84
|
-
File.unlink(reply_file) if File.
|
84
|
+
File.unlink(reply_file) if File.exist?(reply_file)
|
85
85
|
end
|
86
86
|
|
87
87
|
end
|
data/lib/opensips/mi/version.rb
CHANGED
data/test/fifo/.keep
ADDED
File without changes
|
data/test/helper.rb
CHANGED
@@ -13,77 +13,73 @@ require 'mocha/setup'
|
|
13
13
|
require 'stringio'
|
14
14
|
require 'opensips/mi'
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
:reply_fifo => replayfifo
|
28
|
-
end
|
16
|
+
def init_class_fifo
|
17
|
+
Dir.stubs(:exists?).once.returns(true)
|
18
|
+
File.stubs(:exists?).once.returns(true)
|
19
|
+
File.stubs(:pipe?).once.returns(true)
|
20
|
+
directory = File.expand_path 'test/fifo', Dir.pwd
|
21
|
+
fifo_name = File.expand_path 'test/fifo/opensips_fifo', Dir.pwd
|
22
|
+
replayfifo= 'fifo_reply_file_name'
|
23
|
+
Opensips::MI::Transport::Fifo.new :fifo_name => fifo_name,
|
24
|
+
:reply_dir => directory,
|
25
|
+
:reply_fifo => replayfifo
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
def response_data_cmd_which
|
29
|
+
Array[
|
30
|
+
"200 OK", "get_statistics", "reset_statistics", "uptime", "version",
|
31
|
+
"pwd", "arg", "which", "ps", "kill", "debug", "cache_store",
|
32
|
+
"cache_fetch", "cache_remove", "event_subscribe", "help", "list_blacklists",
|
33
|
+
"t_uac_dlg", "t_uac_cancel", "t_hash", "t_reply", "ul_rm", "ul_rm_contact",
|
34
|
+
"ul_dump", "ul_flush", "ul_add", "ul_show_contact", "ul_sync", ""
|
35
|
+
]
|
36
|
+
end
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
def response_uldump
|
39
|
+
fix = File.expand_path('fixtures/ul_dump',File.dirname(__FILE__))
|
40
|
+
File.readlines(fix).map{|l| l.chomp}
|
41
|
+
end
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
43
|
+
def response_dr_gw_status_cmd
|
44
|
+
Array[
|
45
|
+
"200 OK",
|
46
|
+
""
|
47
|
+
]
|
48
|
+
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
50
|
+
def response_dr_gw_status_single
|
51
|
+
Array[
|
52
|
+
"200 OK",
|
53
|
+
"Enabled:: yes",
|
54
|
+
""
|
55
|
+
]
|
56
|
+
end
|
59
57
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
58
|
+
def response_dr_gw_status_list
|
59
|
+
Array[
|
60
|
+
"200 OK",
|
61
|
+
"ID:: gw1 IP=212.182.133.202:5060 Enabled=no ",
|
62
|
+
"ID:: gw2 IP=213.15.222.97:5060 Enabled=yes",
|
63
|
+
"ID:: gw3 IP=200.182.132.201:5060 Enabled=yes",
|
64
|
+
"ID:: gw4 IP=200.182.135.204:5060 Enabled=yes",
|
65
|
+
"ID:: pstn1 IP=199.18.14.101:5060 Enabled=yes",
|
66
|
+
"ID:: pstn2 IP=199.18.14.102:5060 Enabled=no",
|
67
|
+
"ID:: pstn3 IP=199.18.12.103:5060 Enabled=yes",
|
68
|
+
"ID:: pstn4 IP=199.18.12.104:5060 Enabled=yes",
|
69
|
+
""
|
70
|
+
]
|
71
|
+
end
|
74
72
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
73
|
+
def response_contacts
|
74
|
+
[
|
75
|
+
"200 OK",
|
76
|
+
"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>",
|
77
|
+
"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)>",
|
78
|
+
"",
|
79
|
+
]
|
80
|
+
end
|
83
81
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
|
82
|
+
def response_dlg_list
|
83
|
+
fix = File.expand_path('fixtures/dlg_list',File.dirname(__FILE__))
|
84
|
+
File.readlines(fix).map{|l| l.chomp}
|
89
85
|
end
|
data/test/test_command.rb
CHANGED
@@ -9,20 +9,11 @@ describe Command, "commands for transport classes" do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "missing methods" do
|
12
|
-
it "must raise if parameter is not Array" do
|
13
|
-
mi = init_class_fifo
|
14
|
-
mi.expects(:command).with('which').returns(mock(:rawdata => ['meth1', 'meth2']))
|
15
|
-
proc {
|
16
|
-
mi.unknown_command
|
17
|
-
}.must_raise NoMethodError
|
18
|
-
end
|
19
12
|
|
20
13
|
it "must send command" do
|
21
14
|
mi = init_class_fifo
|
22
|
-
mi.expects(:command).with('which').returns(Opensips::MI::Response.new(response_data_cmd_which))
|
23
15
|
mi.expects(:command).with('ul_sync',[]).returns(Opensips::MI::Response.new(["200 OK",""]))
|
24
16
|
mi.ul_sync.code.must_equal 200
|
25
|
-
|
26
17
|
end
|
27
18
|
|
28
19
|
it "must raise when missing basic mandatory headers" do
|
@@ -43,7 +34,7 @@ describe Command, "commands for transport classes" do
|
|
43
34
|
"sip:alice@wanderland.com",
|
44
35
|
".",
|
45
36
|
".",
|
46
|
-
%Q/"From: <sip:opensips@sipproxy.com>\r\nTo: <sip:alice@wanderland.com>\r\n"/
|
37
|
+
%Q/"From: <sip:opensips@sipproxy.com>\r\nTo: <sip:alice@wanderland.com>\r\n\r\n"/
|
47
38
|
])
|
48
39
|
mi.uac_dlg "NOTIFY",
|
49
40
|
"sip:alice@wanderland.com",
|
data/test/test_response.rb
CHANGED
@@ -53,7 +53,7 @@ describe Response, "response class" do
|
|
53
53
|
res = Response.new(response_uldump)
|
54
54
|
ul = res.ul_dump
|
55
55
|
ul.result["7962"].wont_equal nil
|
56
|
-
ul.result["7962"][
|
56
|
+
ul.result["7962"][:callid].must_equal "5e7a1e47da91c41c"
|
57
57
|
end
|
58
58
|
|
59
59
|
it "process uptime response" do
|
@@ -80,7 +80,7 @@ describe Response, "response class" do
|
|
80
80
|
response = res.cache_fetch
|
81
81
|
response.result.userdid.must_equal "18005552211"
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
it "must return userloc contacts" do
|
85
85
|
response = Response.new response_contacts
|
86
86
|
res = response.ul_show_contact.result
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opensips-mi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stas Kobzar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: Ruby module for interacting with OpenSIPs management interface
|
@@ -59,8 +59,8 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .travis.yml
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
64
|
- Gemfile
|
65
65
|
- LICENSE.txt
|
66
66
|
- README.md
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/opensips/mi/transport/xmlrpc.rb
|
76
76
|
- lib/opensips/mi/version.rb
|
77
77
|
- opensips-mi.gemspec
|
78
|
+
- test/fifo/.keep
|
78
79
|
- test/fixtures/dlg_list
|
79
80
|
- test/fixtures/ul_dump
|
80
81
|
- test/helper.rb
|
@@ -90,21 +91,22 @@ require_paths:
|
|
90
91
|
- lib
|
91
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
92
93
|
requirements:
|
93
|
-
- -
|
94
|
+
- - ">="
|
94
95
|
- !ruby/object:Gem::Version
|
95
96
|
version: '0'
|
96
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
98
|
requirements:
|
98
|
-
- -
|
99
|
+
- - ">="
|
99
100
|
- !ruby/object:Gem::Version
|
100
101
|
version: '0'
|
101
102
|
requirements: []
|
102
103
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.7.8
|
104
105
|
signing_key:
|
105
106
|
specification_version: 4
|
106
107
|
summary: OpenSIPs management interface
|
107
108
|
test_files:
|
109
|
+
- test/fifo/.keep
|
108
110
|
- test/fixtures/dlg_list
|
109
111
|
- test/fixtures/ul_dump
|
110
112
|
- test/helper.rb
|