ruby-dbus 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 06e7540fb8468a14731fd8d988828dfe349e687a
4
- data.tar.gz: 86dbf9d6e8c1947bb87ef4f1ef1a4aefa337f1f6
2
+ SHA256:
3
+ metadata.gz: c8a530c6d561a17c6179bda15319036a806f1a42b427033e96caccfc738ebf7b
4
+ data.tar.gz: 959143cab388b528354cc569c698a8c99dc79bbca1b21dbdcc064e212b8794a2
5
5
  SHA512:
6
- metadata.gz: 9347931528a1e83c9b4747b232c3f6e9f8da3968efa7f5fe4a473d6333783a0643823973e91efb35f1c7676a6da0ee6a16eade4176842de6fb4e7aa58c6d5304
7
- data.tar.gz: c814265c6472dc3b715a0f99ca5c6ea920d26a08dcde3eff573a889779320dc00292d637f976067ba3f6e5ae86cbccc099e56430adf8109147e910169f59e44a
6
+ metadata.gz: 41d4ff1294958f67efac62ae0d1b326728617976ea944f3c3374f7156bf33632e9e072260f002c11ca44b099113d75e5ecc58f67c3d2c9d34666f6abe92bdbb3
7
+ data.tar.gz: c93e54662d3cf01a9b0ac0a2e5c70d0efc78da1758349cfe6209cba37fa707b7334503518a7e0b4f53d754aff22d5ff53c2d7f8c2d8c32e6df9b097a1bf0f34b
data/NEWS.md CHANGED
@@ -2,10 +2,19 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## Ruby D-Bus 0.16.0 - 2019-10-15
6
+
7
+ API:
8
+ * An invalid service name or an invalid object path will raise
9
+ instead of being sent to the bus. The bus would then drop the connection,
10
+ producing EOFError here ([#80][]).
11
+
12
+ [#80]: https://github.com/mvidner/ruby-dbus/issues/80
13
+
5
14
  ## Ruby D-Bus 0.15.0 - 2018-04-30
6
15
 
7
16
  API:
8
- * Accessing an unknown interface will raise instead of returning nil ([#74]).
17
+ * Accessing an unknown interface will raise instead of returning nil ([#74][]).
9
18
 
10
19
  Bug fixes:
11
20
  * Fixed a conflict with activesupport 5.2 ([#71])
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.15.0
1
+ 0.16.0
@@ -11,14 +11,16 @@
11
11
  require_relative "dbus/api_options"
12
12
  require_relative "dbus/auth"
13
13
  require_relative "dbus/bus"
14
+ require_relative "dbus/bus_name"
14
15
  require_relative "dbus/error"
15
- require_relative "dbus/export"
16
16
  require_relative "dbus/introspect"
17
17
  require_relative "dbus/logger"
18
18
  require_relative "dbus/marshall"
19
19
  require_relative "dbus/matchrule"
20
20
  require_relative "dbus/message"
21
21
  require_relative "dbus/message_queue"
22
+ require_relative "dbus/object"
23
+ require_relative "dbus/object_path"
22
24
  require_relative "dbus/proxy_object"
23
25
  require_relative "dbus/proxy_object_factory"
24
26
  require_relative "dbus/proxy_object_interface"
@@ -17,7 +17,7 @@ require "singleton"
17
17
  # Module containing all the D-Bus modules and classes.
18
18
  module DBus
19
19
  # This represents a remote service. It should not be instantiated directly
20
- # Use Bus::service()
20
+ # Use {Bus#service}
21
21
  class Service
22
22
  # The service name.
23
23
  attr_reader :name
@@ -28,7 +28,7 @@ module DBus
28
28
 
29
29
  # Create a new service with a given _name_ on a given _bus_.
30
30
  def initialize(name, bus)
31
- @name = name
31
+ @name = BusName.new(name)
32
32
  @bus = bus
33
33
  @root = Node.new("/")
34
34
  end
@@ -458,6 +458,9 @@ module DBus
458
458
  retm = wait_for_message
459
459
  process(retm)
460
460
  end
461
+ rescue EOFError
462
+ new_err = DBus::Error.new("Connection dropped after we sent #{m.inspect}")
463
+ raise new_err
461
464
  end
462
465
 
463
466
  # @api private
@@ -0,0 +1,27 @@
1
+ # This file is part of the ruby-dbus project
2
+ # Copyright (C) 2019 Martin Vidner
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License, version 2.1 as published by the Free Software Foundation.
7
+ # See the file "COPYING" for the exact licensing terms.
8
+
9
+ module DBus
10
+ # A {::String} that validates at initialization time
11
+ # @see https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus
12
+ class BusName < String
13
+ # @raise Error if not a valid bus name
14
+ def initialize(s)
15
+ unless self.class.valid?(s)
16
+ raise DBus::Error, "Invalid bus name #{s.inspect}"
17
+ end
18
+ super
19
+ end
20
+
21
+ def self.valid?(s)
22
+ s.size <= 255 &&
23
+ (s =~ /\A:[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)+\z/ ||
24
+ s =~ /\A[A-Za-z_-][A-Za-z0-9_-]*(\.[A-Za-z_-][A-Za-z0-9_-]*)+\z/)
25
+ end
26
+ end
27
+ end
@@ -14,10 +14,6 @@ module DBus
14
14
  # Regular expressions that should match all interface names.
15
15
  INTERFACE_ELEMENT_RE = /^[A-Za-z][A-Za-z0-9_]*$/
16
16
 
17
- # Exception raised when an unknown signal is used.
18
- class UnknownSignal < Exception
19
- end
20
-
21
17
  # Exception raised when an invalid class definition is encountered.
22
18
  class InvalidClassDefinition < Exception
23
19
  end
@@ -11,6 +11,7 @@ require "fcntl"
11
11
  require "socket"
12
12
 
13
13
  module DBus
14
+ # Encapsulates a socket so that we can {#push} and {#pop} {Message}s.
14
15
  class MessageQueue
15
16
  # The socket that is used to connect with the bus.
16
17
  attr_reader :socket
@@ -22,10 +23,10 @@ module DBus
22
23
  connect
23
24
  end
24
25
 
25
- # TODO: failure modes
26
- #
27
- # If _non_block_ is true, return nil instead of waiting
28
- # EOFError may be raised
26
+ # @param non_block [Boolean] if true, return nil instead of waiting
27
+ # @return [Message,nil] one message or nil if unavailable
28
+ # @raise EOFError
29
+ # @todo failure modes
29
30
  def pop(non_block = false)
30
31
  buffer_from_socket_nonblock
31
32
  message = message_from_buffer_nonblock
@@ -124,14 +125,14 @@ module DBus
124
125
 
125
126
  # Initialize the connection to the bus.
126
127
  def init_connection
127
- @client = Client.new(@socket)
128
- @client.authenticate
128
+ client = Client.new(@socket)
129
+ client.authenticate
129
130
  end
130
131
 
131
132
  public # FIXME: fix Main loop instead
132
133
 
133
134
  # Get and remove one message from the buffer.
134
- # Return the message or nil.
135
+ # @return [Message,nil] the message or nil if unavailable
135
136
  def message_from_buffer_nonblock
136
137
  return nil if @buffer.empty?
137
138
  ret = nil
@@ -139,7 +140,7 @@ module DBus
139
140
  ret, size = Message.new.unmarshall_buffer(@buffer)
140
141
  @buffer.slice!(0, size)
141
142
  rescue IncompleteBufferException
142
- # fall through, let ret be null
143
+ # fall through, let ret remain nil
143
144
  end
144
145
  ret
145
146
  end
@@ -149,7 +150,8 @@ module DBus
149
150
 
150
151
  # Fill (append) the buffer from data that might be available on the
151
152
  # socket.
152
- # EOFError may be raised
153
+ # @return [void]
154
+ # @raise EOFError
153
155
  def buffer_from_socket_nonblock
154
156
  @buffer += @socket.read_nonblock(MSG_BUF_SIZE)
155
157
  rescue EOFError
@@ -1,5 +1,3 @@
1
- # dbus/introspection.rb - module containing a low-level D-Bus introspection implementation
2
- #
3
1
  # This file is part of the ruby-dbus project
4
2
  # Copyright (C) 2007 Arnaud Cornet and Paul van Tilburg
5
3
  #
@@ -16,7 +14,7 @@ module DBus
16
14
  # = Exportable D-Bus object class
17
15
  #
18
16
  # Objects that are going to be exported by a D-Bus service
19
- # should inherit from this class. At the client side, use ProxyObject.
17
+ # should inherit from this class. At the client side, use {ProxyObject}.
20
18
  class Object
21
19
  # The path of the object.
22
20
  attr_reader :path
@@ -127,5 +125,5 @@ module DBus
127
125
  def self.make_method_name(intfname, methname)
128
126
  "#{intfname}%%#{methname}"
129
127
  end
130
- end # class Object
131
- end # module DBus
128
+ end
129
+ end
@@ -0,0 +1,24 @@
1
+ # This file is part of the ruby-dbus project
2
+ # Copyright (C) 2019 Martin Vidner
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License, version 2.1 as published by the Free Software Foundation.
7
+ # See the file "COPYING" for the exact licensing terms.
8
+
9
+ module DBus
10
+ # A {::String} that validates at initialization time
11
+ class ObjectPath < String
12
+ # @raise Error if not a valid object path
13
+ def initialize(s)
14
+ unless self.class.valid?(s)
15
+ raise DBus::Error, "Invalid object path #{s.inspect}"
16
+ end
17
+ super
18
+ end
19
+
20
+ def self.valid?(s)
21
+ s == "/" || s =~ %r{\A(/[A-Za-z0-9_]+)+\z}
22
+ end
23
+ end
24
+ end
@@ -36,7 +36,7 @@ module DBus
36
36
  def initialize(bus, dest, path, api: ApiOptions::CURRENT)
37
37
  @bus = bus
38
38
  @destination = dest
39
- @path = path
39
+ @path = ObjectPath.new(path)
40
40
  @introspected = false
41
41
  @interfaces = {}
42
42
  @subnodes = []
@@ -7,7 +7,7 @@ GEMSPEC = Gem::Specification.new do |s|
7
7
  s.summary = "Ruby module for interaction with D-Bus"
8
8
  s.description = "Pure Ruby module for interaction with D-Bus IPC system"
9
9
  s.version = File.read("VERSION").strip
10
- s.license = "LGPL v2.1"
10
+ s.license = "LGPL-2.1"
11
11
  s.author = "Ruby DBus Team"
12
12
  s.email = "martin.github@vidner.net"
13
13
  s.homepage = "https://github.com/mvidner/ruby-dbus"
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env rspec
2
+ require_relative "spec_helper"
3
+ require "dbus"
4
+
5
+ describe DBus::BusName do
6
+ describe ".valid?" do
7
+ it "recognizes valid bus names" do
8
+ expect(described_class.valid?("org.freedesktop.DBus")).to be_truthy
9
+ expect(described_class.valid?(":1.42")).to be_truthy
10
+ expect(described_class.valid?("org._7_zip.Archiver")).to be_truthy
11
+ end
12
+
13
+ it "recognizes invalid bus names" do
14
+ expect(described_class.valid?("")).to be_falsey
15
+ expect(described_class.valid?("Empty..Component")).to be_falsey
16
+ expect(described_class.valid?(".Empty.First.Component")).to be_falsey
17
+ expect(described_class.valid?("Empty.Last.Component.")).to be_falsey
18
+ expect(described_class.valid?("Invalid.Ch@r@cter")).to be_falsey
19
+ expect(described_class.valid?("/Invalid-Character")).to be_falsey
20
+ long_name = "a." + ("long." * 100) + "name"
21
+ expect(described_class.valid?(long_name)).to be_falsey
22
+ expect(described_class.valid?("org.7_zip.Archiver")).to be_falsey
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env rspec
2
+ # Test that a client survives various error cases
3
+ require_relative "spec_helper"
4
+ require "dbus"
5
+
6
+ describe "ClientRobustnessTest" do
7
+ before(:each) do
8
+ @bus = DBus::ASessionBus.new
9
+ @svc = @bus.service("org.ruby.service")
10
+ end
11
+
12
+ context "when the bus name is invalid" do
13
+ it "tells the user the bus name is invalid" do
14
+ # user mistake, should be "org.ruby.service"
15
+ expect { @bus.service(".org.ruby.service") }.to raise_error(DBus::Error)
16
+ end
17
+ end
18
+
19
+ context "when the object path is invalid" do
20
+ it "tells the user the path is invalid" do
21
+ # user mistake, should be "/org/ruby/MyInstance"
22
+ expect { @svc.object("org.ruby.MyInstance") }.to raise_error(DBus::Error)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env rspec
2
+ require_relative "spec_helper"
3
+ require "dbus"
4
+
5
+ describe DBus::ObjectPath do
6
+ describe ".valid?" do
7
+ it "recognizes valid paths" do
8
+ expect(described_class.valid?("/")).to be_truthy
9
+ expect(described_class.valid?("/99Numbers/_And_Underscores/anywhere")).to be_truthy
10
+ long_name = "/A23456789" * 42
11
+ # no 255 character limit for object paths
12
+ expect(described_class.valid?(long_name)).to be_truthy
13
+ end
14
+
15
+ it "recognizes invalid paths" do
16
+ expect(described_class.valid?("")).to be_falsey
17
+ expect(described_class.valid?("/Empty//Component")).to be_falsey
18
+ expect(described_class.valid?("/EmptyLastComponent/")).to be_falsey
19
+ expect(described_class.valid?("/Invalid Character")).to be_falsey
20
+ expect(described_class.valid?("/Invalid-Character")).to be_falsey
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-dbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby DBus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-30 00:00:00.000000000 Z
11
+ date: 2019-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -127,16 +127,18 @@ files:
127
127
  - lib/dbus/api_options.rb
128
128
  - lib/dbus/auth.rb
129
129
  - lib/dbus/bus.rb
130
+ - lib/dbus/bus_name.rb
130
131
  - lib/dbus/core_ext/class/attribute.rb
131
132
  - lib/dbus/core_ext/module/redefine_method.rb
132
133
  - lib/dbus/error.rb
133
- - lib/dbus/export.rb
134
134
  - lib/dbus/introspect.rb
135
135
  - lib/dbus/logger.rb
136
136
  - lib/dbus/marshall.rb
137
137
  - lib/dbus/matchrule.rb
138
138
  - lib/dbus/message.rb
139
139
  - lib/dbus/message_queue.rb
140
+ - lib/dbus/object.rb
141
+ - lib/dbus/object_path.rb
140
142
  - lib/dbus/proxy_object.rb
141
143
  - lib/dbus/proxy_object_factory.rb
142
144
  - lib/dbus/proxy_object_interface.rb
@@ -147,12 +149,15 @@ files:
147
149
  - spec/binding_spec.rb
148
150
  - spec/bus_and_xml_backend_spec.rb
149
151
  - spec/bus_driver_spec.rb
152
+ - spec/bus_name_spec.rb
150
153
  - spec/bus_spec.rb
151
154
  - spec/byte_array_spec.rb
155
+ - spec/client_robustness_spec.rb
152
156
  - spec/err_msg_spec.rb
153
157
  - spec/introspect_xml_parser_spec.rb
154
158
  - spec/introspection_spec.rb
155
159
  - spec/main_loop_spec.rb
160
+ - spec/object_path_spec.rb
156
161
  - spec/property_spec.rb
157
162
  - spec/proxy_object_spec.rb
158
163
  - spec/server_robustness_spec.rb
@@ -172,7 +177,7 @@ files:
172
177
  - spec/variant_spec.rb
173
178
  homepage: https://github.com/mvidner/ruby-dbus
174
179
  licenses:
175
- - LGPL v2.1
180
+ - LGPL-2.1
176
181
  metadata: {}
177
182
  post_install_message:
178
183
  rdoc_options: []
@@ -190,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
195
  version: '0'
191
196
  requirements: []
192
197
  rubyforge_project:
193
- rubygems_version: 2.2.5
198
+ rubygems_version: 2.7.6
194
199
  signing_key:
195
200
  specification_version: 4
196
201
  summary: Ruby module for interaction with D-Bus