[glibmm] DBus: Avoid errors/exceptions in callbacks due to NULL C strings.
- From: José Alburquerque <jaalburqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] DBus: Avoid errors/exceptions in callbacks due to NULL C strings.
- Date: Thu, 13 Jan 2011 22:30:31 +0000 (UTC)
commit 7e694da5eea703de072192f47940bbedd3287650
Author: José Alburquerque <jaalburqu svn gnome org>
Date: Thu Jan 13 17:00:31 2011 -0500
DBus: Avoid errors/exceptions in callbacks due to NULL C strings.
* gio/src/dbusconnection.ccg: Modify the callbacks so that if a C
string parameter might be NULL, it is passed to the slots as an empty
string (""). This avoids possible exceptions from constructing a
Glib::ustring from NULL.
* gio/src/dbusconnection.hg: Typos.
* examples/dbus/peer.cc: Add the usage examples from the C API's
example.
ChangeLog | 13 ++++++++
examples/dbus/peer.cc | 72 ++++++++++++++++++++++++++++++++++++++++++--
gio/src/dbusconnection.ccg | 33 ++++++++------------
gio/src/dbusconnection.hg | 8 ++--
4 files changed, 99 insertions(+), 27 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e2e2943..6eed6ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2011-01-13 José Alburquerque <jaalburqu svn gnome org>
+ DBus: Avoid errors/exceptions in callbacks due to NULL C strings.
+
+ * gio/src/dbusconnection.ccg: Modify the callbacks so that if a C
+ string parameter might be NULL, it is passed to the slots as an empty
+ string (""). This avoids possible exceptions from constructing a
+ Glib::ustring from NULL.
+ * gio/src/dbusconnection.hg: Typos.
+
+ * examples/dbus/peer.cc: Add the usage examples from the C API's
+ example.
+
+2011-01-13 José Alburquerque <jaalburqu svn gnome org>
+
DBusServer: Add docs to the signal_new_connection() signal.
* gio/src/dbusserver.hg: Add the docs from the C API to make sure it
diff --git a/examples/dbus/peer.cc b/examples/dbus/peer.cc
index 6d383c3..6bedafc 100644
--- a/examples/dbus/peer.cc
+++ b/examples/dbus/peer.cc
@@ -15,9 +15,75 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/* For some usage examples see the C API's GDBusServer's example from which
- * this example was adapted.
- */
+/*
+
+Usage examples (modulo addresses / credentials) (copied from the C API's
+GDBusServer's example).
+
+UNIX domain socket transport:
+
+ Server:
+ $ ./peer --server --address unix:abstract=myaddr
+ Server is listening at: unix:abstract=myaddr
+ Client connected.
+ Peer credentials: GCredentials:unix-user=500,unix-group=500,unix-process=13378
+ Negotiated capabilities: unix-fd-passing=1
+ Client said: Hey, it's 1273093080 already!
+
+ Client:
+ $ ./peer --address unix:abstract=myaddr
+ Connected.
+ Negotiated capabilities: unix-fd-passing=1
+ Server said: You said 'Hey, it's 1273093080 already!'. KTHXBYE!
+
+Nonce-secured TCP transport on the same host:
+
+ Server:
+ $ ./peer --server --address nonce-tcp:
+ Server is listening at: nonce-tcp:host=localhost,port=43077,noncefile=/tmp/gdbus-nonce-file-X1ZNCV
+ Client connected.
+ Peer credentials: (no credentials received)
+ Negotiated capabilities: unix-fd-passing=0
+ Client said: Hey, it's 1273093206 already!
+
+ Client:
+ $ ./peer -address nonce-tcp:host=localhost,port=43077,noncefile=/tmp/gdbus-nonce-file-X1ZNCV
+ Connected.
+ Negotiated capabilities: unix-fd-passing=0
+ Server said: You said 'Hey, it's 1273093206 already!'. KTHXBYE!
+
+TCP transport on two different hosts with a shared home directory:
+
+ Server:
+ host1 $ ./peer --server --address tcp:host=0.0.0.0
+ Server is listening at: tcp:host=0.0.0.0,port=46314
+ Client connected.
+ Peer credentials: (no credentials received)
+ Negotiated capabilities: unix-fd-passing=0
+ Client said: Hey, it's 1273093337 already!
+
+ Client:
+ host2 $ ./peer -a tcp:host=host1,port=46314
+ Connected.
+ Negotiated capabilities: unix-fd-passing=0
+ Server said: You said 'Hey, it's 1273093337 already!'. KTHXBYE!
+
+TCP transport on two different hosts without authentication:
+
+ Server:
+ host1 $ ./peer --server --address tcp:host=0.0.0.0 --allow-anonymous
+ Server is listening at: tcp:host=0.0.0.0,port=59556
+ Client connected.
+ Peer credentials: (no credentials received)
+ Negotiated capabilities: unix-fd-passing=0
+ Client said: Hey, it's 1273093652 already!
+
+ Client:
+ host2 $ ./peer -a tcp:host=host1,port=59556
+ Connected.
+ Negotiated capabilities: unix-fd-passing=0
+ Server said: You said 'Hey, it's 1273093652 already!'. KTHXBYE!
+*/
#include <giomm.h>
#include <glibmm.h>
diff --git a/gio/src/dbusconnection.ccg b/gio/src/dbusconnection.ccg
index a3b47ee..1347a56 100644
--- a/gio/src/dbusconnection.ccg
+++ b/gio/src/dbusconnection.ccg
@@ -40,9 +40,9 @@ static void DBusConnection_Signal_giomm_callback(GDBusConnection* connection,
try
{
- (*the_slot)(Glib::wrap(connection, true), Glib::ustring(sender_name),
- Glib::ustring(object_path), Glib::ustring(interface_name),
- Glib::ustring(signal_name), Glib::VariantBase(parameters, true));
+ (*the_slot)(Glib::wrap(connection, true), (sender_name ? sender_name : ""),
+ (object_path ? object_path : ""), (interface_name ? interface_name : ""),
+ (signal_name ? signal_name : ""), Glib::VariantBase(parameters, true));
}
catch(...)
{
@@ -95,11 +95,9 @@ static void DBusInterfaceVTable_MethodCall_giomm_callback(
try
{
- (*the_slot)(Glib::wrap(connection, true),
- (sender ? Glib::ustring(sender) : ""),
- Glib::ustring(object_path), Glib::ustring(interface_name),
- Glib::ustring(method_name), Glib::VariantBase(parameters, true),
- Glib::wrap(invocation, true));
+ (*the_slot)(Glib::wrap(connection, true), (sender ? sender : ""),
+ object_path, interface_name, method_name,
+ Glib::VariantBase(parameters, true), Glib::wrap(invocation, true));
}
catch(...)
{
@@ -122,9 +120,8 @@ static GVariant* DBusInterfaceVTable_GetProperty_giomm_callback(
{
Glib::VariantBase result;
- (*the_slot)(result, Glib::wrap(connection, true),
- Glib::ustring(sender), Glib::ustring(object_path),
- Glib::ustring(interface_name), Glib::ustring(property_name));
+ (*the_slot)(result, Glib::wrap(connection, true), sender, object_path,
+ interface_name, property_name);
return result.gobj_copy();
}
catch(const Glib::Error& ex)
@@ -154,8 +151,7 @@ static gboolean DBusInterfaceVTable_SetProperty_giomm_callback(
try
{
return static_cast<gboolean>((*the_slot)(Glib::wrap(connection, true),
- Glib::ustring(sender), Glib::ustring(object_path),
- Glib::ustring(interface_name), Glib::ustring(property_name),
+ sender, object_path, interface_name, property_name,
Glib::VariantBase(value, true)));
}
catch(const Glib::Error& ex)
@@ -184,8 +180,7 @@ static char** DBusSubtreeVTable_Enumerate_giomm_callback(
try
{
std::vector<Glib::ustring> result =
- (*the_slot)(Glib::wrap(connection, true), Glib::ustring(sender),
- Glib::ustring(object_path));
+ (*the_slot)(Glib::wrap(connection, true), sender, object_path);
// This will be freed by the caller.
char** ret = g_new(char*, result.size());
@@ -218,8 +213,7 @@ static GDBusInterfaceInfo** DBusSubtreeVTable_Introspect_giomm_callback(
try
{
std::vector< Glib::RefPtr<Gio::DBusInterfaceInfo> > result =
- (*the_slot)(Glib::wrap(connection, true), Glib::ustring(sender),
- Glib::ustring(object_path), Glib::ustring(node));
+ (*the_slot)(Glib::wrap(connection, true), sender, object_path, node);
// This will be freed by the caller, along with unreferencing its members.
GDBusInterfaceInfo** info = g_new(GDBusInterfaceInfo*, result.size());
@@ -255,9 +249,8 @@ static const GDBusInterfaceVTable* DBusSubtreeVTable_Dispatch_giomm_callback(
try
{
const Gio::DBusInterfaceVTable* vtable =
- (*the_slot)(Glib::wrap(connection, true), Glib::ustring(sender),
- Glib::ustring(object_path), Glib::ustring(interface_name),
- Glib::ustring(node));
+ (*the_slot)(Glib::wrap(connection, true), sender, object_path,
+ interface_name, (node ? node : ""));
*out_user_data = const_cast<Gio::DBusInterfaceVTable*>(vtable);
diff --git a/gio/src/dbusconnection.hg b/gio/src/dbusconnection.hg
index a79784b..ba41ee2 100644
--- a/gio/src/dbusconnection.hg
+++ b/gio/src/dbusconnection.hg
@@ -157,7 +157,7 @@ public:
/** Signature for slot used in signal_subscribe().
* For example,
* @code
- * void on_signal(const Glib::RefPtr<DBusConnection>&, const
+ * void on_signal(const Glib::RefPtr<DBusConnection>& connection, const
* Glib::ustring& sender_name, const Glib::ustring& object_path, const
* Glib::ustring& object_path, const Glib::ustring& interface_name, const
* Glib::ustring& signal_name, const Glib::VariantBase& parameters);.
@@ -165,14 +165,14 @@ public:
*/
typedef sigc::slot<void, const Glib::RefPtr<DBusConnection>&,
const Glib::ustring&, const Glib::ustring&, const Glib::ustring&,
- const Glib::ustring&, const Glib::VariantBase&> SlotSignal;
+ const Glib::ustring&, const Glib::VariantBase&> SlotSignal;
/** Signature for slot used in add_filter().
* For example,
* @code
* Glib::RefPtr<DBusMessage> on_message_filter(const
- * Glib::RefPtr<DBusConnection>, const Glib::RefPtr<DBusMessage>& bool
- * incoming);.
+ * Glib::RefPtr<DBusConnection> connection, const Glib::RefPtr<DBusMessage>&
+ * message, bool incoming);.
* @endcode
*
* A filter function is passed a DBusMessage and expected to return a
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]