sdague-ruby-dbus 0.2.1
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.
- data/COPYING +504 -0
- data/ChangeLog +782 -0
- data/NEWS +31 -0
- data/README +53 -0
- data/examples/gdbus/gdbus +255 -0
- data/examples/gdbus/gdbus.glade +184 -0
- data/examples/gdbus/launch.sh +4 -0
- data/examples/no-introspect/nm-test.rb +16 -0
- data/examples/no-introspect/tracker-test.rb +16 -0
- data/examples/rhythmbox/playpause.rb +25 -0
- data/examples/service/call_service.rb +25 -0
- data/examples/service/service_newapi.rb +51 -0
- data/examples/simple/call_introspect.rb +34 -0
- data/examples/utils/listnames.rb +11 -0
- data/examples/utils/notify.rb +19 -0
- data/lib/dbus/auth.rb +156 -0
- data/lib/dbus/bus.rb +690 -0
- data/lib/dbus/export.rb +123 -0
- data/lib/dbus/introspect.rb +509 -0
- data/lib/dbus/marshall.rb +391 -0
- data/lib/dbus/matchrule.rb +98 -0
- data/lib/dbus/message.rb +280 -0
- data/lib/dbus/type.rb +206 -0
- data/lib/dbus.rb +82 -0
- metadata +86 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require "dbus"
|
4
|
+
|
5
|
+
session_bus = DBus::SessionBus.instance
|
6
|
+
|
7
|
+
# Get the Rhythmbox service
|
8
|
+
rhythmbox = session_bus.service("org.gnome.Rhythmbox")
|
9
|
+
|
10
|
+
# Get the object from this service
|
11
|
+
player = rhythmbox.object("/org/gnome/Rhythmbox/Player")
|
12
|
+
|
13
|
+
# Introspect it
|
14
|
+
player.introspect
|
15
|
+
if player.has_iface? "org.gnome.Rhythmbox.Player"
|
16
|
+
puts "We have Rhythmbox Player interface"
|
17
|
+
end
|
18
|
+
|
19
|
+
player_with_iface = player["org.gnome.Rhythmbox.Player"]
|
20
|
+
p player_with_iface.getPlayingUri
|
21
|
+
|
22
|
+
# Maybe support default_iface=(iface_str) on an ProxyObject, so
|
23
|
+
# that this is possible?
|
24
|
+
player.default_iface = "org.gnome.Rhythmbox.Player"
|
25
|
+
puts "default_iface test:"
|
26
|
+
p player.getPlayingUri
|
27
|
+
player.on_signal("elapsedChanged") do |u|
|
28
|
+
puts "elapsedChanged: #{u}"
|
29
|
+
end
|
30
|
+
|
31
|
+
main = DBus::Main.new
|
32
|
+
main << session_bus
|
33
|
+
main.run
|
34
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'dbus'
|
4
|
+
|
5
|
+
if ARGV.size < 2
|
6
|
+
puts "Usage:"
|
7
|
+
puts "notify.rb \"title\" \"body\""
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
d = DBus::SessionBus.instance
|
12
|
+
o = d.service("org.freedesktop.Notifications").object("/org/freedesktop/Notifications")
|
13
|
+
o.introspect
|
14
|
+
|
15
|
+
i = o["org.freedesktop.Notifications"]
|
16
|
+
|
17
|
+
i.Notify('notify.rb', 0, 'info', ARGV[0], ARGV[1], [], {}, 2000) do |ret, param|
|
18
|
+
end
|
19
|
+
|
data/lib/dbus/auth.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
# This file is part of the ruby-dbus project
|
2
|
+
# Copyright (C) 2007 Arnaud Cornet and Paul van Tilburg
|
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
|
+
# Exception raised when authentication fails somehow.
|
11
|
+
class AuthenticationFailed < Exception
|
12
|
+
end
|
13
|
+
|
14
|
+
# = General class for authentication.
|
15
|
+
class Authenticator
|
16
|
+
# Returns the name of the authenticator.
|
17
|
+
def name
|
18
|
+
self.class.to_s.upcase.sub(/.*::/, "")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# = External authentication class
|
23
|
+
#
|
24
|
+
# Class for 'external' type authentication.
|
25
|
+
class External < Authenticator
|
26
|
+
# Performs the authentication.
|
27
|
+
def authenticate
|
28
|
+
# Take the user id (eg integer 1000) make a string out of it "1000", take
|
29
|
+
# each character and determin hex value "1" => 0x31, "0" => 0x30. You
|
30
|
+
# obtain for "1000" => 31303030 This is what the server is expecting.
|
31
|
+
# Why? I dunno. How did I come to that conclusion? by looking at rbus
|
32
|
+
# code. I have no idea how he found that out.
|
33
|
+
return Process.uid.to_s.split(//).collect { |a| "%x" % a[0] }.join
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Note: this following stuff is tested with External authenticator only!
|
38
|
+
|
39
|
+
# = Authentication client class.
|
40
|
+
#
|
41
|
+
# Class tha performs the actional authentication.
|
42
|
+
class Client
|
43
|
+
# Create a new authentication client.
|
44
|
+
def initialize(socket)
|
45
|
+
@socket = socket
|
46
|
+
@state = nil
|
47
|
+
@auth_list = [External]
|
48
|
+
end
|
49
|
+
|
50
|
+
# Start the authentication process.
|
51
|
+
def authenticate
|
52
|
+
@socket.write(0.chr)
|
53
|
+
next_authenticator
|
54
|
+
@state = :Starting
|
55
|
+
while @state != :Authenticated
|
56
|
+
r = next_state
|
57
|
+
return r if not r
|
58
|
+
end
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
##########
|
63
|
+
private
|
64
|
+
##########
|
65
|
+
|
66
|
+
# Send an authentication method _meth_ with arguments _args_ to the
|
67
|
+
# server.
|
68
|
+
def send(meth, *args)
|
69
|
+
o = ([meth] + args).join(" ")
|
70
|
+
@socket.write(o + "\r\n")
|
71
|
+
end
|
72
|
+
|
73
|
+
# Try authentication using the next authenticator.
|
74
|
+
def next_authenticator
|
75
|
+
raise AuthenticationFailed if @auth_list.size == 0
|
76
|
+
@authenticator = @auth_list.shift.new
|
77
|
+
send("AUTH", @authenticator.name, @authenticator.authenticate)
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
# Read data (a buffer) from the bus until CR LF is encountered.
|
82
|
+
# Return the buffer without the CR LF characters.
|
83
|
+
def next_msg
|
84
|
+
@socket.readline.chomp.split(" ")
|
85
|
+
end
|
86
|
+
|
87
|
+
# Try to reach the next state based on the current state.
|
88
|
+
def next_state
|
89
|
+
msg = next_msg
|
90
|
+
if @state == :Starting
|
91
|
+
case msg[0]
|
92
|
+
when "CONTINUE"
|
93
|
+
@state = :WaitingForData
|
94
|
+
when "OK"
|
95
|
+
@state = :WaitingForOk
|
96
|
+
end
|
97
|
+
end
|
98
|
+
case @state
|
99
|
+
when :WaitingForData
|
100
|
+
case msg[0]
|
101
|
+
when "DATA"
|
102
|
+
chall = msg[1]
|
103
|
+
resp, chall = @authenticator.data(chall)
|
104
|
+
case resp
|
105
|
+
when :AuthContinue
|
106
|
+
send("DATA", chall)
|
107
|
+
@state = :WaitingForData
|
108
|
+
when :AuthOk
|
109
|
+
send("DATA", chall)
|
110
|
+
@state = :WaitingForOk
|
111
|
+
when :AuthError
|
112
|
+
send("ERROR")
|
113
|
+
@state = :WaitingForData
|
114
|
+
end
|
115
|
+
when "REJECTED"
|
116
|
+
next_authenticator
|
117
|
+
@state = :WaitingForData
|
118
|
+
when "ERROR"
|
119
|
+
send("CANCEL")
|
120
|
+
@state = :WaitingForReject
|
121
|
+
when "OK"
|
122
|
+
send("BEGIN")
|
123
|
+
@state = :Authenticated
|
124
|
+
else
|
125
|
+
send("ERROR")
|
126
|
+
@state = :WaitingForData
|
127
|
+
end
|
128
|
+
when :WaitingForOk
|
129
|
+
case msg[0]
|
130
|
+
when "OK"
|
131
|
+
send("BEGIN")
|
132
|
+
@state = :Authenticated
|
133
|
+
when "REJECT"
|
134
|
+
next_authenticator
|
135
|
+
@state = :WaitingForData
|
136
|
+
when "DATA", "ERROR"
|
137
|
+
send("CANCEL")
|
138
|
+
@state = :WaitingForReject
|
139
|
+
else
|
140
|
+
send("ERROR")
|
141
|
+
@state = :WaitingForOk
|
142
|
+
end
|
143
|
+
when :WaitingForReject
|
144
|
+
case msg[0]
|
145
|
+
when "REJECT"
|
146
|
+
next_authenticator
|
147
|
+
@state = :WaitingForOk
|
148
|
+
else
|
149
|
+
@socket.close
|
150
|
+
return false
|
151
|
+
end
|
152
|
+
end
|
153
|
+
return true
|
154
|
+
end # def next_state
|
155
|
+
end # class Client
|
156
|
+
end # module D-Bus
|