Commit Graph

79 Commits

Author SHA1 Message Date
Szymon Janc 97abe1751d gdbus: Fix crash in g_dbus_create_error_valist
Passing NULL format parameter to vsnprintf results in invalid argument
error on glibc. But with some other libc libraries (musl and uClibc)
this results in dereferencing NULL pointer and crash due to
segmentation fault.
2015-04-09 16:59:08 +02:00
Szymon Janc 2f75b13ecd gdbus: Use g_dbus_create_error_valist internally
There is no need to duplicate code in g_dbus_send_error_valist.
2015-04-09 16:59:08 +02:00
Michael Janssen 73e517bcca gdbus: Add g_dbus_get_flags function
The g_dbus_get_flags function enables detection of when the
G_DBUS_FLAG_ENABLE_EXPERIMENTAL is set.
2015-04-07 19:00:45 +02:00
Luiz Augusto von Dentz 1b1b1861ab Revert "gdbus: Don't include just added interfaces in GetManagedObjects"
This actually creates a problem since the code now does flush any pending
message on the queue any signal will be send right away before the
actual reply to GetManagedObjects which will not contain those interfaces.
2014-09-08 05:48:48 +02:00
Anderson Lizardo 90abd44ead gdbus: Fix memory leak
data->conn and data->path must be destroyed before freeing "data".
2014-02-18 23:13:53 -08:00
Bastien Nocera 7a6da06f27 gdbus: Fix trying to remove already removed sources
When we return FALSE from idle handlers, the source is removed.
This will be causing warnings in glib 2.40.

See https://bugzilla.gnome.org/show_bug.cgi?id=710724
2013-11-11 01:06:19 -08:00
Szymon Janc df8cf542d8 gdbus: Check for NULL DBusPendingCall in g_dbus_send_message_with_reply
"Warning: if the connection is disconnected or you try to send Unix file
descriptors on a connection that does not support them, the
DBusPendingCall will be set to NULL, so be careful with this."

Check this in g_dbus_send_message_with_reply so that callers don't need
to double check for NULL if g_dbus_send_message_with_reply returned
TRUE.

This also fix crash if passing FD over D-Bus is blocked e.g. by SELinux
policy.

bluetoothd[1894]: profiles/audio/avdtp.c:session_cb()
bluetoothd[1894]: profiles/audio/avdtp.c:avdtp_parse_cmd() Received
    SET_CONFIGURATION_CMD
bluetoothd[1894]: profiles/audio/a2dp.c:endpoint_setconf_ind() Source
    0x6c5000: Set_Configuration_Ind
bluetoothd[1894]: profiles/audio/avdtp.c:avdtp_ref() 0x6df360: ref=1
bluetoothd[1894]: profiles/audio/a2dp.c:setup_ref() 0x6d32b0: ref=1
process 1894: arguments to dbus_pending_call_set_notify() were incorrect,
     assertion "pending != NULL" failed in file dbus-pending-call.c line
     636.
This is normally a bug in some application using the D-Bus library.
2013-10-14 06:06:31 -07:00
Luiz Augusto von Dentz 778b60a94f gdbus: Fix emitting PropertiesChanged twice
This fixes double emission of PropertiesChanged introduced by flushing
changes, the flushing can happen during the pending processing so the
pending_prop flag needs to be updated in the beginning and the list of
properties can be freed before g_dbus_send_message as it is not required
anymore.
2013-09-10 19:07:28 -07:00
Luiz Augusto von Dentz 1ad938a5fd gdbus: Avoid calling dbus_connection_send*
dbus_connection_send* should not be called directly except by
g_dbus_send_message.
2013-09-10 19:07:28 -07:00
Luiz Augusto von Dentz 6a9a09a02a gdbus: Add g_dbus_send_message_with_reply
g_dbus_send_message_with_reply flushes pending signals before calling
dbus_connection_send_with_reply so it does not alter the message order
2013-09-10 19:07:28 -07:00
Luiz Augusto von Dentz f462a549f5 gdbus: Fix sending ObjectManager/Properties signals out of order
In some cases the order of the messages is altered when a message is
sent without processing the pending signals first, currently this affect
client_check_order unit test:

/gdbus/client_check_order: **
ERROR:unit/test-gdbus-client.c:795:property_check_order: assertion failed: (g_strcmp0(string, "value1") == 0)

As can be observed the value of the property is not yet updated because the
signal it is still pending, once this fix is applied the test pass:

/gdbus/client_check_order: OK

Note that the flushing only works when g_dbus_send_message is used so
places where dbus_connection_send and other variants are called directly
may still change the order.
2013-09-10 19:07:28 -07:00
Tomasz Bursztyka 7b0b28bb41 gdbus: Always unreference the message in g_dbus_send_message()
A quick fix on g_dbus_send_message(), if check_signal() fails it returns
FALSE without unreferencing the message as it should. This patch fixes
it.
2013-02-23 11:50:16 +01:00
Vinicius Costa Gomes f93a6a2d06 gdbus: Fix missing PropertiesChanged signal
If D-Bus ObjectManager is not supported, InterfacesAdded signal
checking needs to be ignored otherwise PropertiesChanged signal
will never be sent.
2013-02-14 15:17:39 +01:00
Johan Hedberg 0b1694f4ba gdbus: Fix unpublished interface signal emission
If we haven't published an interface yet (i.e. it's in the data->added
list), we should just ignore any property changed indications as the
values for the properties will anyway be part of the InterfacesAdded
signal.
2013-02-01 22:06:14 +01:00
Marcel Holtmann abb54f4aa5 gdbus: Check for valid path before handling properties 2013-01-20 18:45:56 -08:00
Anderson Lizardo 45bc35e534 gdbus: Fix memory leak on properties_set()
The pointer returned by dbus_message_iter_get_signature() must be freed
with dbus_free().

Fixes this memory leak:

==1857== 16 bytes in 1 blocks are definitely lost in loss record 104 of
251
==1857==    at 0x402BF52: realloc (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1857==    by 0x415E286: dbus_realloc (in
/lib/i386-linux-gnu/libdbus-1.so.3.5.8)
==1857==    by 0x415E70B: ??? (in
/lib/i386-linux-gnu/libdbus-1.so.3.5.8)
==1857==    by 0x415F17B: ??? (in
/lib/i386-linux-gnu/libdbus-1.so.3.5.8)
==1857==    by 0x414CB33: dbus_message_iter_get_signature (in
/lib/i386-linux-gnu/libdbus-1.so.3.5.8)
==1857==    by 0x8053239: properties_set (object.c:899)
==1857==    by 0x5FFFFF: ???
==1857==
2013-01-06 14:49:03 -08:00
Marcel Holtmann 3143ea126e gdbus: Check signature of property value before calling setter 2013-01-05 00:45:35 -08:00
Lucas De Marchi a39520e1be gdbus: Don't include just added interfaces in GetManagedObjects
If we received a call to ObjectManager.GetManagedObject we should not
include in the response the interfaces in data->added. This is because
it's not guaranteed that those interfaces will trigger an
InterfacesAdded signal, which is the case if the interface is removed in
the same mainloop iteration.
2013-01-03 21:34:18 -08:00
Lucas De Marchi 7482480294 gdbus: Simplify generated introspection
The generated introspection is not supposed to be read as is by human,
so there's no point in printing the indentation or writing more code to
use auto-close tags.

If it's desired to read the raw xml file, user can always use other
tools to transform the output such as "xmllint --format".

This also fixes a missing </property> when property is deprecated.
2013-01-03 21:34:18 -08:00
Luiz Augusto von Dentz a559a4993b gdbus: Call check_signals when sending signals with g_dbus_send_message
If message passed to g_dbus_send_message is a signal verify if it is a
valid and there really exists an interface with respective signal name.
2012-12-30 10:49:27 -08:00
Luiz Augusto von Dentz 9ed7b17ca3 gdbus: Check if the interface being registered is valid
This prevent registering interfaces that are empty or have all members
marked as experiemental.
2012-12-30 10:49:27 -08:00
Luiz Augusto von Dentz 5f8485bcc1 gdbus: Introduce G_DBUS_PROPERTY_FLAG_EXPERIMENTAL
This flag can be used to mark properties as experimental, marked
properties are disabled by default and can be enabled by setting
G_DBUS_FLAG_ENABLE_EXPERIMENTAL using g_dbus_set_flags.
2012-12-30 10:49:27 -08:00
Luiz Augusto von Dentz 4b14fcc9a1 gdbus: Introduce G_DBUS_SIGNAL_FLAG_EXPERIMENTAL
This flag can be used to mark signals as experimental, marked
signals are disabled by default and can be enabled by setting
G_DBUS_FLAG_ENABLE_EXPERIMENTAL using g_dbus_set_flags.
2012-12-30 10:49:27 -08:00
Luiz Augusto von Dentz 4b50c0bd05 gdbus: Introduce G_DBUS_METHOD_FLAG_EXPERIMENTAL
This flag can be used to mark methods as experimental, marked
methods are disable by default and can be enabled by setting
G_DBUS_FLAG_ENABLE_EXPERIMENTAL using g_dbus_set_flags.
2012-12-30 10:49:27 -08:00
Marcel Holtmann 37a54d0433 gdbus: Include changed properties only once per signal 2012-12-30 00:58:59 -08:00
Marcel Holtmann e7ca33f908 gdbus: Add helper for sending async error replies 2012-12-19 03:50:42 +01:00
Lucas De Marchi 2e9bea7af6 gdbus: Don't automatically attach ObjectManager
Let each project attach the object manager interface instead of
registering it automatically.
2012-11-29 17:38:55 +01:00
Lucas De Marchi 959d23833f gdbus: Don't register DBus.Properties with no properties
Delay registering DBus.Properties interface until the moment there are
properties on that path. This is needed for objects that currently don't
expose any property to not export the interface.
2012-11-29 17:38:55 +01:00
Syam Sidhardhan 682bf79a83 gdbus: Replace leading spaces with tabs
Trivial formatting fix.
2012-11-26 12:59:30 +01:00
Syam Sidhardhan 0581ec199c gdbus: Fix compilation error due to missing #defines
Since these are simple #define strings, we are defining it here
instead of upgrading to D-Bus 1.5 or later.

Log:
  CC     gdbus/object.o
gdbus/object.c: In function ‘properties_set’:
gdbus/object.c:876:7: error: ‘DBUS_ERROR_UNKNOWN_PROPERTY’ undeclared
 (first use in this function)
gdbus/object.c:876:7: note: each undeclared identifier is reported
 only once for each function it appears in
gdbus/object.c:881:6: error: ‘DBUS_ERROR_PROPERTY_READ_ONLY’
 undeclared (first use in this function)
make[1]: *** [gdbus/object.o] Error 1
make: *** [all] Error 2
2012-11-26 12:59:16 +01:00
Lucas De Marchi 2e6824dbb0 gdbus: Remove connection from pending_property functions
The reply to a DBus.Properties.Set() method call should go through the
same D-Bus connection. Thus remove the DBusConnection parameter from the
following functions:

    - g_dbus_pending_property_success()
    - g_dbus_pending_property_error_valist()
    - g_dbus_pending_property_error()
2012-11-26 12:58:54 +01:00
Johan Hedberg 8aaa110370 gdbus: Fix invalid memory access during interface removal
If an interface is removed from the root path during the same mainloop
iteration that it was added we need to check for data->added before
doing the check for data->parent == NULL in the remove_interface()
function. Otherwise the added interface doesn't get removed from the
data->added list and will result in accessing freed memory:

==337== Invalid read of size 8
==337==    at 0x4F65AFA: dbus_message_iter_append_basic (in /usr/lib64/libdbus-1.so.3.7.1)
==337==    by 0x1247B5: append_interface (object.c:556)
==337==    by 0x4C8DC5C: g_slist_foreach (gslist.c:840)
==337==    by 0x1261F7: process_changes (object.c:594)
==337==    by 0x126372: generic_unregister (object.c:997)
==337==    by 0x4F69669: ??? (in /usr/lib64/libdbus-1.so.3.7.1)
==337==    by 0x4F5CE51: dbus_connection_unregister_object_path (in /usr/lib64/libdbus-1.so.3.7.1)
==337==    by 0x125E81: object_path_unref (object.c:1236)
==337==    by 0x126136: g_dbus_unregister_interface (object.c:1361)
==337==    by 0x14CDF0: service_exit (service.c:581)
==337==    by 0x177556: plugin_cleanup (plugin.c:242)
==337==    by 0x12221F: main (main.c:559)
==337==  Address 0x5bc1550 is 0 bytes inside a block of size 56 free'd
==337==    at 0x4A079AE: free (vg_replace_malloc.c:427)
==337==    by 0x4C7850E: g_free (gmem.c:252)
==337==    by 0x125DB0: remove_interface (object.c:671)
==337==    by 0x125E3B: object_path_unref (object.c:1230)
==337==    by 0x126136: g_dbus_unregister_interface (object.c:1361)
==337==    by 0x14CDF0: service_exit (service.c:581)
==337==    by 0x177556: plugin_cleanup (plugin.c:242)
==337==    by 0x12221F: main (main.c:559)
2012-11-26 12:58:38 +01:00
Johan Hedberg f9f49f5d42 gdbus: Add g_dbus_get_properties function
This function can be used to construct custom D-Bus messages containing
the properties for a specific interface on a given path.
2012-11-26 12:58:00 +01:00
Johan Hedberg 031189ffea gdbus: Add support for invalidated properties
If there's a pending property but its exists() callback returns false
the property should be considered invalidated and included in the
relevant list of the PropertiesChanged signal.
2012-11-26 12:57:43 +01:00
Johan Hedberg c4ec194ede gdbus: Fix processing pending properties in remove_interface() 2012-11-26 12:57:26 +01:00
Lucas De Marchi d1d2f6dbe1 gdbus: Fix up Properties.Set() code path
Minor fixes to make setter actually work:

	- Add propdata in pending_property_set
	- Break loop when we are removing propdata from list and we
	  found it
	- in_args and out_args were swapped
	- interface and method name arguments were swapped
2012-11-26 12:56:53 +01:00
Lucas De Marchi 7071d8a28e gdbus: Fix invalid memory access while unregistering
If an interface is added and removed on the same mailoop iteration,
ObjectManager would try to send InterfacesAdded signal while running the
idler because the interface was added to data->added list.

This is easily reproduced by forcing an error path in a plugin
registration, like on sap_server_register(), resulting in the following
error:

==11795== Invalid read of size 4
==11795==    at 0x496F592: dbus_message_iter_append_basic (dbus-message.c:2598)
==11795==    by 0x117B39: append_interface (object.c:554)
==11795==    by 0x48955E7: g_slist_foreach (gslist.c:840)
==11795==    by 0x11923B: process_changes (object.c:592)
==11795==    by 0x11956D: generic_unregister (object.c:980)
==11795==    by 0x4973BAC: _dbus_object_tree_unregister_and_unlock (dbus-object-tree.c:516)
==11795==    by 0x4965240: dbus_connection_unregister_object_path (dbus-connection.c:5776)
==11795==    by 0x1178A5: object_path_unref (object.c:1219)
==11795==    by 0x118517: g_dbus_unregister_interface (object.c:1344)
==11795==    by 0x19AF5B: sap_exit (sap.c:385)
==11795==    by 0x13E9E2: sap_server_register (server.c:1428)
==11795==    by 0x13C092: sap_server_probe (manager.c:44)

With this patch we don't send the InterfacesAdded signal, removing it
from data->added while unregistering.
2012-11-26 12:56:40 +01:00
Lucas De Marchi a8e02420b4 gdbus: Implement PropertiesChanged signal 2012-11-26 12:56:11 +01:00
Luiz Augusto von Dentz fd33855e53 gdbus: Simplify code for appending properties
This reuse append_properties for GetAll and GetManagedObjects
2012-11-26 12:55:45 +01:00
Luiz Augusto von Dentz 11ba5b9aa2 gdbus: Integrates ObjectManager with Properties interface
This appends the properties and its values when using ObjectManager.
2012-11-26 12:55:25 +01:00
Luiz Augusto von Dentz cf296a9da9 gdbus: Only export ObjectManager interface on root path
ObjectManager should be exported only in the root path and list all
the children paths.
2012-11-26 12:55:07 +01:00
Luiz Augusto von Dentz f28e6ae984 gdbus: Group interface changes to reduce the amount of signals emitted
InterfacesAdded and InterfacesRemoved can group all the interfaces
changes together in one message.
2012-11-26 12:54:45 +01:00
Luiz Augusto von Dentz 7db2a0bfcc gdbus: Add support for org.freedesktop.DBus.ObjectManager interface
This implements initial support for ObjectManager, it automatically adds
objects to its parents so no action is needed by daemons to get their
objects managed by this interface.

ObjectManager is part of D-Bus spec since revision 0.17:
http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager
2012-11-26 12:54:27 +01:00
Lucas De Marchi 8c634044ed gdbus: Add properties into Introspectable interface 2012-11-26 12:54:05 +01:00
Lucas De Marchi d87dcb6c5b gdbus: Implement DBus.Properties.Set method
Contrary to Get() and GetAll(), Set() is asynchronous so we pass an id
to the setter so later it can declare the Set() as successful or
otherwise.
2012-11-26 12:53:40 +01:00
Lucas De Marchi 1b7afd7b1e gdbus: Implement DBus.Properties.GetAll method 2012-11-26 12:53:23 +01:00
Lucas De Marchi 337e908edd gdbus: Implement DBus.Properties.Get method 2012-11-26 12:52:56 +01:00
Lucas De Marchi 1315c48085 gdbus: Add skeleton of DBus.Properties interface
This interface is responsible for handling properties of all objects in
a given path. Right now it only registers itself, doing nothing useful.
A conversion to this new layout will be done by subsequent patches.

org.freedesktop.org.DBus.Properties spec can be found at
http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties
2012-11-26 12:52:23 +01:00
Lucas De Marchi cb44357b67 gdbus: Use macros to add annotations
Besides being more readable this way it avoids going over 80 chars.
2012-11-26 12:51:53 +01:00
Jaganath Kanakkassery c1cea66a5e gdbus: Fix compilation error if macro "error" is defined
The variable "signature" used in error is not defined and "args" is now
a struct instead of a string.
2012-08-27 17:28:42 -07:00