opensips-mi 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 71ef11dfb16e3efdac5669c4afd6ef2b433a74fc
4
- data.tar.gz: dcc82b55bf1030ac0086310e0643e530640da7fa
2
+ SHA256:
3
+ metadata.gz: ccf5f5bbbc6e55802390c34cfc14d9786a3a66cae096150d2bf7ae9f58ca3bc6
4
+ data.tar.gz: 2d2e16891fe1c6d0489c04df6a3ad03eb7971247f388cd19b29b456adb6cc34f
5
5
  SHA512:
6
- metadata.gz: b62cecb80c51d27d2a5c0707056f0a5c6355b872bae13edb301cb923215aa846929320428fdc8e21f15f8f92d36ff1f9a7f13b7b85d6321884d2fdc02e5adf5c
7
- data.tar.gz: 0f6aa840550cf9fb0b3e160b2fa441cfa197f09d2a8c71ed21e480c0c0a354ab5ebfc78a05c051e1ce65705c5f31689927cb42374233a696c5aeb95704c2a722
6
+ metadata.gz: a31f00548de585c638296aa97b8fe4889c6d5d85deb7afe83be364a555941b476836f73d053516e05add7d8999f75fc0027a2008adbcdf1e8b2e57c12ae9fad1
7
+ data.tar.gz: '028af90298a552a3bfff6054de1543acb519aeb846e78074e28b5c638d539a48734ef38eab3eb0cb2374e3b5f59167b655f7c32fa16b198cffff68c91c7fb689'
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  group :test do
4
+ gem 'minitest'
4
5
  gem 'coveralls', require: false
5
6
  gem 'simplecov' #, :require => false
6
7
  gem 'mocha'
data/README.md CHANGED
@@ -141,6 +141,7 @@ There are several helper methods which return conveniently formatted data:
141
141
  * cache_fetch
142
142
  * ul_show_contact
143
143
  * dlg_list
144
+ * ps
144
145
 
145
146
  See example files for details.
146
147
 
@@ -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
- return nil unless /^Domain:: location table=\d+ records=(\d+)$/ =~ @rawdata.shift
33
- records = Hash.new
34
- aor = ''
31
+ res = {}
32
+ aor = nil
33
+ contact = nil
34
+
35
35
  @rawdata.each do |r|
36
- if /\tAOR:: (?<peer>.+)$/ =~ r
37
- aor = peer
38
- records[aor] = Hash.new
39
- end
40
- if /^\t{2,3}(?<key>[^:]+):: (?<val>.*)$/ =~ r
41
- records[aor][key] = val if aor
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
- @result = records
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 = Array.new
87
+ res = {}
88
+ aor = nil
89
+ contact = nil
90
+
80
91
  @rawdata.each do |r|
81
- cont = Hash.new
82
- r.split(?;).each do |rec|
83
- if /^Contact:: (.*)$/ =~ rec
84
- cont[:contact] = $1
85
- else
86
- key,val = rec.split ?=
87
- cont[key.to_sym] = val
88
- end
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
- res << cont
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.exists? @reply_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.exists? @fifo_name
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.exists?(reply_file)
84
+ File.unlink(reply_file) if File.exist?(reply_file)
85
85
  end
86
86
 
87
87
  end
@@ -1,5 +1,5 @@
1
1
  module Opensips
2
2
  module MI
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
File without changes
@@ -13,77 +13,73 @@ require 'mocha/setup'
13
13
  require 'stringio'
14
14
  require 'opensips/mi'
15
15
 
16
- class MiniTest::Unit::TestCase
17
-
18
- def init_class_fifo
19
- Dir.stubs(:exists?).once.returns(true)
20
- File.stubs(:exists?).once.returns(true)
21
- File.stubs(:pipe?).once.returns(true)
22
- directory = '/tmp/opensips/fifo'
23
- fifo_name = '/tmp/opensips_fifo'
24
- replayfifo= 'fifo_reply_file_name'
25
- Opensips::MI::Transport::Fifo.new :fifo_name => fifo_name,
26
- :reply_dir => directory,
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
- def response_data_cmd_which
31
- Array[
32
- "200 OK", "get_statistics", "reset_statistics", "uptime", "version",
33
- "pwd", "arg", "which", "ps", "kill", "debug", "cache_store",
34
- "cache_fetch", "cache_remove", "event_subscribe", "help", "list_blacklists",
35
- "t_uac_dlg", "t_uac_cancel", "t_hash", "t_reply", "ul_rm", "ul_rm_contact",
36
- "ul_dump", "ul_flush", "ul_add", "ul_show_contact", "ul_sync", ""
37
- ]
38
- end
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
- def response_uldump
41
- fix = File.expand_path('fixtures/ul_dump',File.dirname(__FILE__))
42
- File.readlines(fix).map{|l| l.chomp}
43
- end
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
- def response_dr_gw_status_cmd
46
- Array[
47
- "200 OK",
48
- ""
49
- ]
50
- end
43
+ def response_dr_gw_status_cmd
44
+ Array[
45
+ "200 OK",
46
+ ""
47
+ ]
48
+ end
51
49
 
52
- def response_dr_gw_status_single
53
- Array[
54
- "200 OK",
55
- "Enabled:: yes",
56
- ""
57
- ]
58
- end
50
+ def response_dr_gw_status_single
51
+ Array[
52
+ "200 OK",
53
+ "Enabled:: yes",
54
+ ""
55
+ ]
56
+ end
59
57
 
60
- def response_dr_gw_status_list
61
- Array[
62
- "200 OK",
63
- "ID:: gw1 IP=212.182.133.202:5060 Enabled=no ",
64
- "ID:: gw2 IP=213.15.222.97:5060 Enabled=yes",
65
- "ID:: gw3 IP=200.182.132.201:5060 Enabled=yes",
66
- "ID:: gw4 IP=200.182.135.204:5060 Enabled=yes",
67
- "ID:: pstn1 IP=199.18.14.101:5060 Enabled=yes",
68
- "ID:: pstn2 IP=199.18.14.102:5060 Enabled=no",
69
- "ID:: pstn3 IP=199.18.12.103:5060 Enabled=yes",
70
- "ID:: pstn4 IP=199.18.12.104:5060 Enabled=yes",
71
- ""
72
- ]
73
- end
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
- def response_contacts
76
- [
77
- "200 OK",
78
- "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>",
79
- "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)>",
80
- "",
81
- ]
82
- end
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
- def response_dlg_list
85
- fix = File.expand_path('fixtures/dlg_list',File.dirname(__FILE__))
86
- File.readlines(fix).map{|l| l.chomp}
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
@@ -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",
@@ -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"]['Callid'].must_equal "5e7a1e47da91c41c"
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.7
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: 2014-02-18 00:00:00.000000000 Z
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.1.11
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