opensips-mi 1.0.0 → 1.1.0
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 +4 -4
- data/README.md +23 -7
- 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: e13c9966a4b4c84d25ec9e900d1b640f3650f6d33989c152070ccd67a707cc51
|
4
|
+
data.tar.gz: e22c248064c8ae003c45a84dc871d24c4070f01ac1951ffcf7504e2351792cc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77fefce67ccc8ef925daeca1726e8efb22fc1746889108aa6fbbb571f07857b305b9ccf4de62a2cf229481cf7bbf628a5bfc3e5df8a9a04a03bb281fa0667e29
|
7
|
+
data.tar.gz: 552c0cbfaaf7d5c38bf0a931acd1a05bd6eb5f6649d23175943ca291a19474e62ceaaeb36e74f1d89cb157f2d90aee9d39663e57dcfd40c30d2060e21355f215
|
data/README.md
CHANGED
@@ -9,6 +9,7 @@ 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_fifo => 'opensips_reply' . $$,
|
81
|
+
:reply_dir => '/tmp'
|
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
|
|
@@ -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.0
|
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-08-
|
11
|
+
date: 2023-08-11 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
|