Mercurial > emacs
changeset 87156:e0ab56e63db8
* dbusbind.c (Fdbus_get_unique_name, xd_read_message)
(Fdbus_register_signal): Use DBUS_MAXIMUM_NAME_LENGTH and
DBUS_MAXIMUM_MATCH_RULE_LENGTH for string lengths.
(Fdbus_call_method, Fdbus_send_signal, Fdbus_register_signal):
Unify argument lists.
(xd_read_message, Fdbus_register_signal) Reorder and extend event
arguments and hash table keys. Use unique name for service.
(Fdbus_unregister_signal): Remove checks.
(Vdbus_registered_functions_table): Fix doc string.
author | Michael Albinus <michael.albinus@gmx.de> |
---|---|
date | Fri, 07 Dec 2007 04:39:25 +0000 |
parents | 362f7ff753a3 |
children | c6aa4b381248 |
files | src/ChangeLog src/dbusbind.c |
diffstat | 2 files changed, 85 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Fri Dec 07 04:33:41 2007 +0000 +++ b/src/ChangeLog Fri Dec 07 04:39:25 2007 +0000 @@ -1,3 +1,15 @@ +2007-12-06 Michael Albinus <michael.albinus@gmx.de> + + * dbusbind.c (Fdbus_get_unique_name, xd_read_message) + (Fdbus_register_signal): Use DBUS_MAXIMUM_NAME_LENGTH and + DBUS_MAXIMUM_MATCH_RULE_LENGTH for string lengths. + (Fdbus_call_method, Fdbus_send_signal, Fdbus_register_signal): + Unify argument lists. + (xd_read_message, Fdbus_register_signal) Reorder and extend event + arguments and hash table keys. Use unique name for service. + (Fdbus_unregister_signal): Remove checks. + (Vdbus_registered_functions_table): Fix doc string. + 2007-12-05 Magnus Henoch <mange@freemail.hu> * process.c (make_process): Initialize pty_flag to 0.
--- a/src/dbusbind.c Fri Dec 07 04:33:41 2007 +0000 +++ b/src/dbusbind.c Fri Dec 07 04:39:25 2007 +0000 @@ -241,7 +241,7 @@ Lisp_Object bus; { DBusConnection *connection; - char name[1024]; + char name[DBUS_MAXIMUM_NAME_LENGTH]; /* Check parameters. */ CHECK_SYMBOL (bus); @@ -287,8 +287,8 @@ elements of the D-Bus container. Example: \(dbus-call-method - :session "GetKeyField" "org.gnome.seahorse" - "/org/gnome/seahorse/keys/openpgp" "org.gnome.seahorse.Keys" + :session "org.gnome.seahorse" "/org/gnome/seahorse/keys/openpgp" + "org.gnome.seahorse.Keys" "GetKeyField" "openpgp:657984B8C7A966DD" "simple-name") => (t ("Philip R. Zimmermann")) @@ -297,18 +297,18 @@ object is returned instead of a list containing this single Lisp object. \(dbus-call-method - :system "GetPropertyString" "org.freedesktop.Hal" - "/org/freedesktop/Hal/devices/computer" "org.freedesktop.Hal.Device" + :system "org.freedesktop.Hal" "/org/freedesktop/Hal/devices/computer" + "org.freedesktop.Hal.Device" "GetPropertyString" "system.kernel.machine") => "i686" -usage: (dbus-call-method BUS METHOD SERVICE PATH INTERFACE &rest ARGS) */) +usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &rest ARGS) */) (nargs, args) int nargs; register Lisp_Object *args; { - Lisp_Object bus, method, service, path, interface; + Lisp_Object bus, service, path, interface, method; Lisp_Object result; struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; DBusConnection *connection; @@ -322,23 +322,23 @@ /* Check parameters. */ bus = args[0]; - method = args[1]; - service = args[2]; - path = args[3]; - interface = args[4]; + service = args[1]; + path = args[2]; + interface = args[3]; + method = args[4]; CHECK_SYMBOL (bus); - CHECK_STRING (method); CHECK_STRING (service); CHECK_STRING (path); CHECK_STRING (interface); - GCPRO5 (bus, method, service, path, interface); + CHECK_STRING (method); + GCPRO5 (bus, service, path, interface, method); XD_DEBUG_MESSAGE ("%s %s %s %s", - SDATA (method), SDATA (service), SDATA (path), - SDATA (interface)); + SDATA (interface), + SDATA (method)); /* Open a connection to the bus. */ connection = xd_initialize (bus); @@ -447,14 +447,15 @@ Example: \(dbus-send-signal - :session "Started" "org.gnu.emacs" "/org/gnu/emacs" "org.gnu.emacs"))) + :session "org.gnu.Emacs" "/org/gnu/Emacs" + "org.gnu.Emacs.FileManager" "FileModified" "/home/albinus/.emacs") -usage: (dbus-send-signal BUS SIGNAL SERVICE PATH INTERFACE &rest ARGS) */) +usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */) (nargs, args) int nargs; register Lisp_Object *args; { - Lisp_Object bus, signal, service, path, interface; + Lisp_Object bus, service, path, interface, signal; struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; DBusConnection *connection; DBusMessage *dmessage; @@ -464,23 +465,23 @@ /* Check parameters. */ bus = args[0]; - signal = args[1]; - service = args[2]; - path = args[3]; - interface = args[4]; + service = args[1]; + path = args[2]; + interface = args[3]; + signal = args[4]; CHECK_SYMBOL (bus); - CHECK_STRING (signal); CHECK_STRING (service); CHECK_STRING (path); CHECK_STRING (interface); - GCPRO5 (bus, signal, service, path, interface); + CHECK_STRING (signal); + GCPRO5 (bus, service, path, interface, signal); XD_DEBUG_MESSAGE ("%s %s %s %s", - SDATA (signal), SDATA (service), SDATA (path), - SDATA (interface)); + SDATA (interface), + SDATA (signal)); /* Open a connection to the bus. */ connection = xd_initialize (bus); @@ -549,7 +550,10 @@ DBusMessage *dmessage; DBusMessageIter iter; uint dtype; - char service[1024], path[1024], interface[1024], member[1024]; + char service[DBUS_MAXIMUM_NAME_LENGTH]; + char path[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; /* Unlimited in D-Bus spec. */ + char interface[DBUS_MAXIMUM_NAME_LENGTH]; + char member[DBUS_MAXIMUM_NAME_LENGTH]; /* Open a connection to the bus. */ connection = xd_initialize (bus); @@ -590,14 +594,23 @@ /* The arguments are stored in reverse order. Reorder them. */ event.arg = Fnreverse (event.arg); - /* Read service, object path interface and member from the - message. */ + /* Read service, object path, interface and member from the message. + The service is always the unique name of the sending object. */ strcpy (service, dbus_message_get_sender (dmessage)); strcpy (path, dbus_message_get_path (dmessage)); strcpy (interface, dbus_message_get_interface (dmessage)); strcpy (member, dbus_message_get_member (dmessage)); - /* Add them to the event. */ + /* Add the registered function of the message. */ + key = list5 (bus, + (service == NULL ? Qnil : build_string (service)), + (path == NULL ? Qnil : build_string (path)), + (interface == NULL ? Qnil : build_string (interface)), + (member == NULL ? Qnil : build_string (member))); + event.arg = Fcons (Fgethash (key, Vdbus_registered_functions_table, Qnil), + event.arg); + + /* Add service, path, interface and member to the event. */ event.arg = Fcons ((member == NULL ? Qnil : build_string (member)), event.arg); event.arg = Fcons ((interface == NULL ? Qnil : build_string (interface)), @@ -610,13 +623,6 @@ /* Add the bus symbol to the event. */ event.arg = Fcons (bus, event.arg); - /* Add the registered function of the message. */ - key = list3 (bus, - (interface == NULL ? Qnil : build_string (interface)), - (member == NULL ? Qnil : build_string (member))); - event.arg = Fcons (Fgethash (key, Vdbus_registered_functions_table, Qnil), - event.arg); - /* Store it into the input event queue. */ kbd_buffer_store_event (&event); @@ -666,31 +672,41 @@ (message "Device %s added" device)) \(dbus-register-signal - :system "DeviceAdded" - (dbus-get-name-owner :system "org.freedesktop.Hal") - "/org/freedesktop/Hal/Manager" "org.freedesktop.Hal.Manager" - 'my-signal-handler) + :system "org.freedesktop.Hal" "/org/freedesktop/Hal/Manager" + "org.freedesktop.Hal.Manager" "DeviceAdded" 'my-signal-handler) - => (:system "org.freedesktop.Hal.Manager" "DeviceAdded") + => (:system ":1.3" "/org/freedesktop/Hal/Manager" + "org.freedesktop.Hal.Manager" "DeviceAdded") `dbus-register-signal' returns an object, which can be used in `dbus-unregister-signal' for removing the registration. */) - (bus, signal, service, path, interface, handler) - Lisp_Object bus, signal, service, path, interface, handler; + (bus, service, path, interface, signal, handler) + Lisp_Object bus, service, path, interface, signal, handler; { - Lisp_Object key; + Lisp_Object unique_name, key; DBusConnection *connection; - char rule[1024]; + char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; DBusError derror; /* Check parameters. */ CHECK_SYMBOL (bus); - CHECK_STRING (signal); if (!NILP (service)) CHECK_STRING (service); if (!NILP (path)) CHECK_STRING (path); CHECK_STRING (interface); + CHECK_STRING (signal); CHECK_SYMBOL (handler); + /* Retrieve unique name of service. If service is a known name, we + will register for the corresponding unique name, if any. Signals + are sent always with the unique name as sender. Note: the unique + name of "org.freedesktop.DBus" is that string itself. */ + if ((!NILP (service)) && + (strcmp (SDATA (service), DBUS_SERVICE_DBUS) != 0) && + (strncmp (SDATA (service), ":", 1) != 0)) + unique_name = call2 (intern ("dbus-get-name-owner"), bus, service); + else + unique_name = service; + /* Open a connection to the bus. */ connection = xd_initialize (bus); @@ -700,9 +716,9 @@ SDATA (interface), SDATA (signal)); - /* Add service and path to the rule if they are non-nil. */ - if (!NILP (service)) - sprintf (rule, "%s,sender='%s'%", rule, SDATA (service)); + /* Add unique name and path to the rule if they are non-nil. */ + if (!NILP (unique_name)) + sprintf (rule, "%s,sender='%s'%", rule, SDATA (unique_name)); if (!NILP (path)) sprintf (rule, "%s,path='%s'", rule, SDATA (path)); @@ -716,7 +732,7 @@ XD_DEBUG_MESSAGE ("Matching rule \"%s\" created", rule); /* Create a hash table entry. */ - key = list3 (bus, interface, signal); + key = list5 (bus, unique_name, path, interface, signal); Fputhash (key, handler, Vdbus_registered_functions_table); XD_DEBUG_MESSAGE ("\"%s\" registered with handler \"%s\"", SDATA (format2 ("%s", key, Qnil)), @@ -734,13 +750,6 @@ Lisp_Object object; { - /* Check parameters. */ - CHECK_SYMBOL (object); - - XD_DEBUG_MESSAGE ("\"%s\" unregistered with handler \"%s\"", - SDATA (format2 ("%s", object, Qnil)), - SDATA (format2 ("%s", Fsymbol_function (object), Qnil))); - /* Unintern the signal symbol. */ Fremhash (object, Vdbus_registered_functions_table); @@ -788,10 +797,12 @@ DEFVAR_LISP ("dbus-registered-functions-table", &Vdbus_registered_functions_table, doc: /* Hash table of registered functions for D-Bus. -The key in the hash table is the list (BUS INTERFACE MEMBER). BUS is -either the symbol `:system' or the symbol `:session'. INTERFACE is a -string which denotes a D-Bus interface, and MEMBER, also a string, is -either a method or a signal INTERFACE is offering. +The key in the hash table is the list (BUS SERVICE PATH MEMBER INTERFACE). +BUS is either the symbol `:system' or the symbol `:session'. SERVICE +and PATH are the unique name and the object path of the sending object. +INTERFACE is a string which denotes a D-Bus interface, and MEMBER, +also a string, is either a method or a signal INTERFACE is offering. +All arguments but BUS can be nil, which means a wild card then. The value in the hash table a the function to be called when a D-Bus message, which matches the key criteria, arrives. */);