From 9c3d566e95c9080f6040c64531b0ccae22bd5d74 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sat, 15 Jan 2005 07:15:38 +0000 Subject: 2005-01-15 Havoc Pennington * Land the new message args API and type system. This patch is huge, but the public API change is not really large. The set of D-BUS types has changed somewhat, and the arg "getters" are more geared toward language bindings; they don't make a copy, etc. There are also some known issues. See these emails for details on this huge patch: http://lists.freedesktop.org/archives/dbus/2004-December/001836.html http://lists.freedesktop.org/archives/dbus/2005-January/001922.html * dbus/dbus-marshal-*: all the new stuff * dbus/dbus-message.c: basically rewritten * dbus/dbus-memory.c (check_guards): with "guards" enabled, init freed blocks to be all non-nul bytes so using freed memory is less likely to work right * dbus/dbus-internals.c (_dbus_test_oom_handling): add DBUS_FAIL_MALLOC=N environment variable, so you can do DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or DBUS_FAIL_MALLOC=10 to make it really, really, really slow and thorough. * qt/message.cpp: port to the new message args API (operator<<): use str.utf8() rather than str.unicode() (pretty sure this is right from the Qt docs?) * glib/dbus-gvalue.c: port to the new message args API * bus/dispatch.c, bus/driver.c: port to the new message args API * dbus/dbus-string.c (_dbus_string_init_const_len): initialize the "locked" flag to TRUE and align_offset to 0; I guess we never looked at these anyhow, but seems cleaner. * dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING): move allocation padding macro to this header; use it to implement (_DBUS_STRING_STATIC): ability to declare a static string. * dbus/dbus-message.c (_dbus_message_has_type_interface_member): change to return TRUE if the interface is not set. * dbus/dbus-string.[hc]: move the D-BUS specific validation stuff to dbus-marshal-validate.[hc] * dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from dbus-internals.c * dbus/Makefile.am: cut over from dbus-marshal.[hc] to dbus-marshal-*.[hc] * dbus/dbus-object-tree.c (_dbus_decompose_path): move this function here from dbus-marshal.c --- bus/driver.c | 97 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 40 deletions(-) (limited to 'bus/driver.c') diff --git a/bus/driver.c b/bus/driver.c index dc640396..99e66752 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -47,10 +47,11 @@ bus_driver_send_service_owner_changed (const char *service_name, { DBusMessage *message; dbus_bool_t retval; - const char null_service[] = { '\000' }; + const char *null_service; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - + + null_service = ""; _dbus_verbose ("sending service owner changed: %s [%s -> %s]\n", service_name, old_owner ? old_owner : null_service, @@ -70,9 +71,9 @@ bus_driver_send_service_owner_changed (const char *service_name, goto oom; if (!dbus_message_append_args (message, - DBUS_TYPE_STRING, service_name, - DBUS_TYPE_STRING, old_owner ? old_owner : null_service, - DBUS_TYPE_STRING, new_owner ? new_owner : null_service, + DBUS_TYPE_STRING, &service_name, + DBUS_TYPE_STRING, old_owner ? &old_owner : &null_service, + DBUS_TYPE_STRING, new_owner ? &new_owner : &null_service, DBUS_TYPE_INVALID)) goto oom; @@ -111,7 +112,7 @@ bus_driver_send_service_lost (DBusConnection *connection, if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) || !dbus_message_append_args (message, - DBUS_TYPE_STRING, service_name, + DBUS_TYPE_STRING, &service_name, DBUS_TYPE_INVALID)) { dbus_message_unref (message); @@ -154,7 +155,7 @@ bus_driver_send_service_acquired (DBusConnection *connection, if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) || !dbus_message_append_args (message, - DBUS_TYPE_STRING, service_name, + DBUS_TYPE_STRING, &service_name, DBUS_TYPE_INVALID)) { dbus_message_unref (message); @@ -341,7 +342,7 @@ bus_driver_send_welcome_message (DBusConnection *connection, } if (!dbus_message_append_args (welcome, - DBUS_TYPE_STRING, name, + DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) { dbus_message_unref (welcome); @@ -374,6 +375,9 @@ bus_driver_handle_list_services (DBusConnection *connection, int len; char **services; BusRegistry *registry; + int i; + DBusMessageIter iter; + DBusMessageIter sub; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -392,10 +396,12 @@ bus_driver_handle_list_services (DBusConnection *connection, BUS_SET_OOM (error); return FALSE; } + + dbus_message_append_iter_init (reply, &iter); - if (!dbus_message_append_args (reply, - DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, services, len, - DBUS_TYPE_INVALID)) + if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, + &sub)) { dbus_free_string_array (services); dbus_message_unref (reply); @@ -403,6 +409,28 @@ bus_driver_handle_list_services (DBusConnection *connection, return FALSE; } + i = 0; + while (i < len) + { + if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING, + &services[i])) + { + dbus_free_string_array (services); + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + ++i; + } + + if (!dbus_message_iter_close_container (&iter, &sub)) + { + dbus_free_string_array (services); + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + dbus_free_string_array (services); if (!bus_transaction_send_from_driver (transaction, connection, reply)) @@ -426,7 +454,7 @@ bus_driver_handle_acquire_service (DBusConnection *connection, { DBusMessage *reply; DBusString service_name; - char *name; + const char *name; int service_reply; dbus_uint32_t flags; dbus_bool_t retval; @@ -462,7 +490,7 @@ bus_driver_handle_acquire_service (DBusConnection *connection, goto out; } - if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, service_reply, DBUS_TYPE_INVALID)) + if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, &service_reply, DBUS_TYPE_INVALID)) { BUS_SET_OOM (error); goto out; @@ -477,7 +505,6 @@ bus_driver_handle_acquire_service (DBusConnection *connection, retval = TRUE; out: - dbus_free (name); if (reply) dbus_message_unref (reply); return retval; @@ -492,8 +519,8 @@ bus_driver_handle_service_exists (DBusConnection *connection, DBusMessage *reply; DBusString service_name; BusService *service; - dbus_bool_t service_exists; - char *name; + unsigned char service_exists; + const char *name; dbus_bool_t retval; BusRegistry *registry; @@ -527,7 +554,7 @@ bus_driver_handle_service_exists (DBusConnection *connection, } if (!dbus_message_append_args (reply, - DBUS_TYPE_BOOLEAN, service_exists, + DBUS_TYPE_BOOLEAN, &service_exists, 0)) { BUS_SET_OOM (error); @@ -545,7 +572,6 @@ bus_driver_handle_service_exists (DBusConnection *connection, out: if (reply) dbus_message_unref (reply); - dbus_free (name); return retval; } @@ -557,7 +583,7 @@ bus_driver_handle_activate_service (DBusConnection *connection, DBusError *error) { dbus_uint32_t flags; - char *name; + const char *name; dbus_bool_t retval; BusActivation *activation; @@ -588,7 +614,6 @@ bus_driver_handle_activate_service (DBusConnection *connection, retval = TRUE; out: - dbus_free (name); return retval; } @@ -626,7 +651,7 @@ bus_driver_handle_add_match (DBusConnection *connection, DBusError *error) { BusMatchRule *rule; - char *text; + const char *text; DBusString str; BusMatchmaker *matchmaker; @@ -677,7 +702,6 @@ bus_driver_handle_add_match (DBusConnection *connection, } bus_match_rule_unref (rule); - dbus_free (text); return TRUE; @@ -685,8 +709,6 @@ bus_driver_handle_add_match (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); if (rule) bus_match_rule_unref (rule); - if (text) - dbus_free (text); return FALSE; } @@ -697,7 +719,7 @@ bus_driver_handle_remove_match (DBusConnection *connection, DBusError *error) { BusMatchRule *rule; - char *text; + const char *text; DBusString str; BusMatchmaker *matchmaker; @@ -733,7 +755,6 @@ bus_driver_handle_remove_match (DBusConnection *connection, goto failed; bus_match_rule_unref (rule); - dbus_free (text); return TRUE; @@ -741,8 +762,6 @@ bus_driver_handle_remove_match (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); if (rule) bus_match_rule_unref (rule); - if (text) - dbus_free (text); return FALSE; } @@ -752,7 +771,7 @@ bus_driver_handle_get_service_owner (DBusConnection *connection, DBusMessage *message, DBusError *error) { - char *text; + const char *text; const char *base_name; DBusString str; BusRegistry *registry; @@ -796,7 +815,7 @@ bus_driver_handle_get_service_owner (DBusConnection *connection, goto oom; if (! dbus_message_append_args (reply, - DBUS_TYPE_STRING, base_name, + DBUS_TYPE_STRING, &base_name, DBUS_TYPE_INVALID)) goto oom; @@ -804,7 +823,6 @@ bus_driver_handle_get_service_owner (DBusConnection *connection, goto oom; dbus_message_unref (reply); - dbus_free (text); return TRUE; @@ -815,7 +833,6 @@ bus_driver_handle_get_service_owner (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); if (reply) dbus_message_unref (reply); - dbus_free (text); return FALSE; } @@ -825,13 +842,14 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection, DBusMessage *message, DBusError *error) { - char *service; + const char *service; DBusString str; BusRegistry *registry; BusService *serv; DBusConnection *conn; DBusMessage *reply; unsigned long uid; + dbus_uint32_t uid32; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -871,8 +889,9 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection, goto failed; } + uid32 = uid; if (! dbus_message_append_args (reply, - DBUS_TYPE_UINT32, (dbus_uint32_t) uid, + DBUS_TYPE_UINT32, &uid32, DBUS_TYPE_INVALID)) goto oom; @@ -880,7 +899,6 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection, goto oom; dbus_message_unref (reply); - dbus_free (service); return TRUE; @@ -891,7 +909,6 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); if (reply) dbus_message_unref (reply); - dbus_free (service); return FALSE; } @@ -901,13 +918,14 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection, DBusMessage *message, DBusError *error) { - char *service; + const char *service; DBusString str; BusRegistry *registry; BusService *serv; DBusConnection *conn; DBusMessage *reply; unsigned long pid; + dbus_uint32_t pid32; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -947,8 +965,9 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection, goto failed; } + pid32 = pid; if (! dbus_message_append_args (reply, - DBUS_TYPE_UINT32, (dbus_uint32_t) pid, + DBUS_TYPE_UINT32, &pid32, DBUS_TYPE_INVALID)) goto oom; @@ -956,7 +975,6 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection, goto oom; dbus_message_unref (reply); - dbus_free (service); return TRUE; @@ -967,7 +985,6 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); if (reply) dbus_message_unref (reply); - dbus_free (service); return FALSE; } -- cgit