]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
busctl: Add introspect support for methods with same name but different signature 15833/head
authorSebastian Scheibner <asamk@gmx.de>
Sun, 17 May 2020 12:52:10 +0000 (14:52 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 6 Sep 2022 16:00:36 +0000 (18:00 +0200)
D-Bus interfaces can have multiple methods with the same name, as long
as they have different arguments (signature). Currently busctl can call
those methods but when introspecting the interface it just displays
"Duplicate method"

This PR fixes the behavior, by also adding the signature to the hash for
the members set.

Before this patch:

$ busctl introspect org.asamk.Signal /org/asamk/Signal
Invalid introspection data: duplicate method 'sendMessage' on interface 'org.asamk.Signal'.

After this patch:

$ busctl introspect org.asamk.Signal /org/asamk/Signal
NAME                                TYPE      SIGNATURE RESULT/VALUE FLAGS
org.asamk.Signal                    interface -         -            -
.sendMessage                        method    as        x            -
.sendMessage                        method    s         x            -

Calling the methods already works as expected, as the user must specify
the signature explicitely:
busctl --user call org.asamk.Signal /org/asamk/Signal org.asamk.Signal sendMessage "as" 2 foo bar
busctl --user call org.asamk.Signal /org/asamk/Signal org.asamk.Signal sendMessage "s" foo

$ busctl --xml introspect org.asamk.Signal /org/asamk/Signal
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/asamk/Signal">
 <interface name="org.asamk.Signal">
  <method name="sendMessage" >
   <arg type="as" direction="in"/>
   <arg type="x" direction="out"/>
  </method>
  <method name="sendMessage" >
   <arg type="s" direction="in"/>
   <arg type="x" direction="out"/>
  </method>
 <interface name="org.freedesktop.DBus.Introspectable">
  <method name="Introspect">
   <arg type="s" direction="out"/>
  </method>
 </interface>
 <interface name="org.freedesktop.DBus.Peer">
  <method name="Ping">
  </method>
 </interface>
</node>

src/busctl/busctl.c

index c637d084e7925577da5cdc2c7d55df4323132aac..a6dbf0ddb5423aed54aa41f5caf0bd32517aa7ac 100644 (file)
@@ -742,6 +742,9 @@ static void member_hash_func(const Member *m, struct siphash *state) {
         if (m->name)
                 string_hash_func(m->name, state);
 
+        if (m->signature)
+                string_hash_func(m->signature, state);
+
         if (m->interface)
                 string_hash_func(m->interface, state);
 }
@@ -762,7 +765,11 @@ static int member_compare_func(const Member *x, const Member *y) {
         if (d != 0)
                 return d;
 
-        return strcmp_ptr(x->name, y->name);
+        d = strcmp_ptr(x->name, y->name);
+        if (d != 0)
+                return d;
+
+        return strcmp_ptr(x->signature, y->signature);
 }
 
 static int member_compare_funcp(Member * const *a, Member * const *b) {