opensips-mi 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -9
- data/lib/opensips/mi/command.rb +10 -4
- data/lib/opensips/mi/transport/fifo.rb +70 -0
- data/lib/opensips/mi/transport.rb +1 -0
- data/lib/opensips/mi/version.rb +1 -1
- data/lib/opensips/mi.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1831d86726b1bf7da5ceaa0e705cf777dc625a6ceafc471ffb8750f7a2d7a12d
|
4
|
+
data.tar.gz: 2539ab2e197b634e3f5cf8e12c2be1893424cd5352f83dbb24fbbfa9aa58e168
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd6db00fc4a17046d69b00f9e7b175d5e045150a3323c091ab14bae26119a6705d4f0004c0b5bf74e8b3d54ecc07ae238a277a08f230b2e1c225fcf265bdef76
|
7
|
+
data.tar.gz: 6dec5be60acacf7648e30b67ad9c2b2e15786390274588554bb7d192e35281421f7e2e1178f9b19e4ea550299081bfb870fd5b3bd245b8ae2e1317f4e7062991
|
data/README.md
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
[![Ruby Build](https://github.com/staskobzar/opensips-mi/actions/workflows/main.yml/badge.svg)](https://github.com/staskobzar/opensips-mi/actions/workflows/main.yml)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/staskobzar/opensips-mi.png)](https://codeclimate.com/github/staskobzar/opensips-mi)
|
5
|
-
[![Gem Version](https://badge.fury.io/rb/opensips-mi.
|
6
|
-
[![Coverage Status](https://coveralls.io/repos/staskobzar/opensips-mi/badge.
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/opensips-mi.svg)](https://badge.fury.io/rb/opensips-mi)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/github/staskobzar/opensips-mi/badge.svg?branch=master)](https://coveralls.io/github/staskobzar/opensips-mi?branch=master)
|
7
7
|
|
8
8
|
OpenSIPs management interface library.
|
9
9
|
This library supports following management interfaces OpenSIPs modules:
|
10
10
|
|
11
11
|
- mi_datagram
|
12
|
+
- mi_fifo
|
12
13
|
- mi_http
|
13
14
|
- mi_xmlrpc
|
14
15
|
|
@@ -46,17 +47,13 @@ Parameters:
|
|
46
47
|
_INTRFACE_ - interface name. One of the following:
|
47
48
|
|
48
49
|
- :datagram
|
50
|
+
- :fifo
|
49
51
|
- :http
|
50
52
|
- :xmlrpc
|
51
53
|
|
52
54
|
_PARAMS_ - connection parameters. Depends on interface. See below.
|
53
55
|
|
54
56
|
This function will raise exceptions if there are parameters' or environment errors.
|
55
|
-
Function returns instance of one of the following classes:
|
56
|
-
|
57
|
-
- Opensips::MI::Transport::Datagram
|
58
|
-
- Opensips::MI::Transport::HTTP
|
59
|
-
- Opensips::MI::Transport::Xmlrpc
|
60
57
|
|
61
58
|
### Datagram
|
62
59
|
|
@@ -72,7 +69,25 @@ opensips = Opensips::MI.connect :datagram,
|
|
72
69
|
|
73
70
|
- host: Hostname or IP address of OpenSIPs server
|
74
71
|
- port: Datagram port. See mi_datagram module configuration parameter: `modparam("mi_datagram", "socket_name", "udp:192.168.2.133:8080")`
|
75
|
-
- timeout: Timeout in seconds to wait send/recv commands.
|
72
|
+
- timeout: (OPTIONAL) Timeout in seconds to wait send/recv commands. Default 5 seconds.
|
73
|
+
|
74
|
+
### FIFO
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
require 'opensips/mi'
|
78
|
+
opensips = Opensips::MI.connect :fifo,
|
79
|
+
:fifo_name => '/tmp/opensips_fifo',
|
80
|
+
:reply_dir => '/tmp',
|
81
|
+
:timeout => 3
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
**Parameters hash:**
|
86
|
+
|
87
|
+
- fifo_name: OpenSIPs fifo file. See mi_fifo module parameter: `modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")`.
|
88
|
+
- reply_dir: (OPTIONAL) Path to directory of reply fifo file. This directory is defined by opensips module parameter
|
89
|
+
`modparam("mi_fifo", "reply_dir", "/home/opensips/tmp/")`. Default is "/tmp"
|
90
|
+
- timeout: (OPTIONAL) Timeout in seconds read/write file timeout. Default 5 seconds.
|
76
91
|
|
77
92
|
### HTTP
|
78
93
|
|
@@ -87,6 +102,7 @@ opensips = Opensips::MI.connect :http,
|
|
87
102
|
|
88
103
|
- url: HTTP MI url. Check OpenSIPS module mi_http for setting of IP, port and root path.
|
89
104
|
- timeout: Timeout in seconds to wait send/recv commands. Optional. Default 5 seconds.
|
105
|
+
- timeout: (OPTIONAL) Timeout in seconds to wait send/recv commands. Default 5 seconds.
|
90
106
|
|
91
107
|
### XMLRPC
|
92
108
|
|
@@ -100,7 +116,7 @@ opensips = Opensips::MI.connect :xmlrpc,
|
|
100
116
|
**Parameters hash:**
|
101
117
|
|
102
118
|
- url: HTTP MI url. Check OpenSIPS module mi_http for setting of IP, port and root path.
|
103
|
-
- timeout: Timeout in seconds to wait send/recv commands.
|
119
|
+
- timeout: (OPTIONAL) Timeout in seconds to wait send/recv commands. Default 5 seconds.
|
104
120
|
|
105
121
|
### Command function
|
106
122
|
|
data/lib/opensips/mi/command.rb
CHANGED
@@ -86,14 +86,20 @@ module Opensips
|
|
86
86
|
# Ex.: udp:10.130.8.21:5060
|
87
87
|
# body: (optional, may not be present) request body (if present, requires the "Content-Type"
|
88
88
|
# and "Content-length" headers)
|
89
|
-
def uac_dlg(method, ruri, hdrs, next_hop =
|
89
|
+
def uac_dlg(method, ruri, hdrs, next_hop = nil, socket = nil, body = nil)
|
90
90
|
validate_hf(hdrs)
|
91
91
|
|
92
92
|
headers = hdrs.map { |name, val| "#{name}: #{val}" }.join("\r\n")
|
93
93
|
headers << "\r\n\r\n"
|
94
94
|
|
95
|
-
params =
|
96
|
-
|
95
|
+
params = {
|
96
|
+
"method" => method,
|
97
|
+
"ruri" => ruri,
|
98
|
+
"headers" => headers
|
99
|
+
}
|
100
|
+
params["next_hop"] = next_hop if next_hop
|
101
|
+
params["socket"] = socket if socket
|
102
|
+
params["body"] = body if body
|
97
103
|
command "t_uac_dlg", params
|
98
104
|
end
|
99
105
|
|
@@ -150,7 +156,7 @@ module Opensips
|
|
150
156
|
"Content-Type" => "application/simple-message-summary" }
|
151
157
|
|
152
158
|
body = hbody.map { |k, v| "#{k}: #{v}" }.join("\r\n") << "\r\n\r\n"
|
153
|
-
uac_dlg "NOTIFY", uri, hdrs,
|
159
|
+
uac_dlg "NOTIFY", uri, hdrs, nil, nil, body
|
154
160
|
end
|
155
161
|
|
156
162
|
private
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "abstract"
|
4
|
+
require "fcntl"
|
5
|
+
require "pathname"
|
6
|
+
require "tempfile"
|
7
|
+
require "timeout"
|
8
|
+
|
9
|
+
module Opensips
|
10
|
+
module MI
|
11
|
+
module Transport
|
12
|
+
# FIFO transport to communicate with MI
|
13
|
+
class Fifo < Abstract
|
14
|
+
def initialize(args)
|
15
|
+
super()
|
16
|
+
raise_invalid_params unless args.is_a?(Hash)
|
17
|
+
@fifo_name, @reply_dir, @timeout = args.values_at(:fifo_name, :reply_dir, :timeout)
|
18
|
+
raise_invalid_params if @fifo_name.nil?
|
19
|
+
@reply_dir ||= "/tmp"
|
20
|
+
@timeout ||= 5
|
21
|
+
end
|
22
|
+
|
23
|
+
def send(rpc)
|
24
|
+
reply_file = create_reply_file
|
25
|
+
write(reply_file, rpc)
|
26
|
+
read(reply_file)
|
27
|
+
ensure
|
28
|
+
reply_file.unlink if reply_file&.exist?
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def raise_invalid_params
|
34
|
+
raise Opensips::MI::ErrorParams,
|
35
|
+
"invalid params. Expecting a hash with :fifo_name and optional :reply_dir"
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def write(reply_file, rpc)
|
41
|
+
Timeout.timeout(@timeout, Opensips::MI::ErrorSendTimeout) do
|
42
|
+
fifo_wr = IO.open(IO.sysopen(@fifo_name, Fcntl::O_WRONLY))
|
43
|
+
fifo_wr.syswrite(%(:#{reply_file.basename}:#{rpc}\n))
|
44
|
+
fifo_wr.flush
|
45
|
+
ensure
|
46
|
+
fifo_wr&.close
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def read(reply_file)
|
51
|
+
Timeout.timeout(@timeout, Opensips::MI::ErrorSendTimeout) do
|
52
|
+
fifo_rd = IO.open(IO.sysopen(reply_file, Fcntl::O_RDONLY))
|
53
|
+
fifo_rd.read
|
54
|
+
ensure
|
55
|
+
fifo_rd&.close
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_reply_file
|
60
|
+
tmpfile = Tempfile.create("opensips-mi-reply-", @reply_dir)
|
61
|
+
File.unlink(tmpfile)
|
62
|
+
|
63
|
+
File.mkfifo(tmpfile)
|
64
|
+
File.chmod(0o666, tmpfile)
|
65
|
+
Pathname.new(tmpfile)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/opensips/mi/version.rb
CHANGED
data/lib/opensips/mi.rb
CHANGED
@@ -8,14 +8,15 @@ module Opensips
|
|
8
8
|
# OpenSIPS Managemen Interface core module
|
9
9
|
module MI
|
10
10
|
class Error < StandardError; end
|
11
|
+
class ErrorHTTPReq < Error; end
|
11
12
|
class ErrorParams < Error; end
|
12
13
|
class ErrorResolveTimeout < Error; end
|
13
14
|
class ErrorSendTimeout < Error; end
|
14
|
-
class ErrorHTTPReq < Error; end
|
15
15
|
|
16
16
|
def self.connect(transport_proto, params = {})
|
17
17
|
transp = case transport_proto
|
18
18
|
when :datagram then Transport::Datagram.new(params)
|
19
|
+
when :fifo then Transport::Fifo.new(params)
|
19
20
|
when :http then Transport::HTTP.new(params)
|
20
21
|
when :xmlrpc then Transport::Xmlrpc.new(params)
|
21
22
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opensips-mi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stas Kobzar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xmlrpc
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/opensips/mi/transport.rb
|
45
45
|
- lib/opensips/mi/transport/abstract.rb
|
46
46
|
- lib/opensips/mi/transport/datagram.rb
|
47
|
+
- lib/opensips/mi/transport/fifo.rb
|
47
48
|
- lib/opensips/mi/transport/http.rb
|
48
49
|
- lib/opensips/mi/transport/xmlrpc.rb
|
49
50
|
- lib/opensips/mi/version.rb
|