This change addresses conditions where an exception is thrown by the library upon receipt of a malformed message from an external
source, and propagated up to the event loop with no chance of
interception by the application. This issue is only experienced by
proxy convenience APIs, as low-level APIs allow the application to
unpack the message.
Strategy:
1. For malformed signals received by proxies: ignore the signal.
2. For malformed async method responses, translate the unpack
exception into an sdbus::Error, and pass it to the caller as expected.
This internally calls sd_bus_open(), which automatically selects the
system or session bus connection based on the presence and
content of a DBUS_STARTER_BUS_TYPE environment variable and
whether the calling process has root privileges.
This option is very helpful when creating services and clients that will use the system bus in production, but connect to a session
for testing.
Additional changes:
* Removed assertions null-checking make_unique() return values.
make_unique() calls new, and new is expected to throw or abort
on failure, making the assertions unhelpful.
* Corrected a typo in the ClosesAndUnrefsBusWhenDestructed
unit test for the system bus (tested the wrong function).
* Add missing nullptr check in Message::peekType().
* According to its specification, sd_bus_message_peek_type() sets a
given contents parameter to NULL if the next element in a message is
not a container. Since assigning a nullptr to a std::string has
undefined behaviour (typically resulting in an invalid memory access),
Message::peekType() must not assign contentsSig unconditionally.
* fix construct/destruct order of mutex/data in AsnycCalls
Destroying a mutex which might still be owned leads to undefined behaviour.
It wasn't the case here but using the right order is more resistant to future bugs.
* proxy AsnycCalls: don't leave map in unspecified state
* fix 133: use thread-safe container for proxy interfaces list
* proxy callback payload uses concrete signalData
* proxy: revert adding the wrapper class InterfaceContainer
It's no longer required and simplifies the locking logic.
* Proxy: avoid additional lambda wrapper around signal callbacks
As proposed in
https://github.com/Kistler-Group/sdbus-cpp/pull/177#issuecomment-834439707
option 3.
Still TODO: Avoid relying on std::map's non-invalidatable by adding just
std::unique_ptr<Proxy::InterfaceData::SignalData> to the container.
* proxy: add missing underscore prefix
* proxy: put InterfaceData::SignalData into a unique_ptr
This ways, we avoid relying on std::map's non-invalidatable references.
* proxy: code style: get raw pointer directly
* style: fix code style
Co-authored-by: Stanislav Angelovic <stanislav.angelovic@siemens.com>
* Add API to get message path
* Add API to get message destination
* Handle NULL message fields interface and member
Functions sd_bus_message_get_interface() and sd_bus_message_get_member()
can return null in case the message does not use those fields or does
not have them set.
This provides access to the proxy's bus connection so code using
the proxy does not need to store an external reference to it.
A matching function is already available in IObject.
* fix: minor documentation and test improvements
* doc: add link to tests in standard interfaces tutorial secion
* Update README.md
Co-authored-by: Urs Ritzmann <urs.ritzmann@kistler.com>
* Update docs/using-sdbus-c++.md
Co-authored-by: Urs Ritzmann <urs.ritzmann@kistler.com>
* Use cmake instead of make in build instructions
Co-authored-by: Stanislav Angelovic <stanislav.angelovic@siemens.com>
Co-authored-by: Urs Ritzmann <urs.ritzmann@kistler.com>
* sdbus-cpp: Add API to get message credentials
Signed-off-by: Alexander Livenets <a.livenets@gmail.com>
* fix: add <sys/types.h> include for gid_t and other types
Co-authored-by: Stanislav Angelovič <angelovic.s@gmail.com>
This patch is required if EXPAT library is installed in non-standard location.
Without 'target_include_directories' cmake will find EXPAT library:
...
-- Found EXPAT: .../lib/libexpat.a (found version "2.2.10")
...
But 'xml.cpp' compilation will fail with error:
...
tools/xml2cpp-codegen/xml.cpp:7:10: fatal error: expat.h: No such file or directory
7 | #include <expat.h>
...
This introduces GitHub CI which runs builds and tests in a matrix configuration. It also changes the systemd repo to stable one. And puts the CI badge (plus a few more badges) to the README page.
Fixes#44