From 06b7bc8ca2e005ed510210d3b8dee16afbabbcc9 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 21 Feb 2014 16:59:48 +0100 Subject: sbus: Add the sbus_request_parse_or_finish() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some DBus types returned from dbus_message_get_args() require memory to be released when done. We automatically attach these to the talloc struct sbus_request memory context in this function. This accepts varargs similar to dbus_message_get_args(), which are rather awkward. However instead of reworking them completely, future generated marshalling code will replace most uses of these varargs. If parsing the dbus message fails, then it responds to the DBus caller with an appropriate error such as o.f.D.Error.InvalidArgs. In these cases (ie: when it returns FALSE) the sbus_request is finished. Migrated some, but not all, uses of dbus_message_get_args() to the new function. Some instances have uncommon semantics such as terminating the connection upon failure to parse a message. Reviewed-by: Jakub Hrozek Reviewed-by: Pavel Březina Reviewed-by: Lukáš Slebodník --- src/providers/proxy/proxy_init.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'src/providers/proxy') diff --git a/src/providers/proxy/proxy_init.c b/src/providers/proxy/proxy_init.c index 0206ec15b..dd1b75826 100644 --- a/src/providers/proxy/proxy_init.c +++ b/src/providers/proxy/proxy_init.c @@ -397,10 +397,8 @@ static int client_registration(struct sbus_request *dbus_req, void *data) dbus_uint16_t version = DATA_PROVIDER_VERSION; struct sbus_connection *conn; struct proxy_client *proxy_cli; - DBusError dbus_error; dbus_uint16_t cli_ver; uint32_t cli_id; - dbus_bool_t dbret; int hret; hash_key_t key; hash_value_t value; @@ -421,19 +419,12 @@ static int client_registration(struct sbus_request *dbus_req, void *data) "Cancel proxy client ID timeout [%p]\n", proxy_cli->timeout); talloc_zfree(proxy_cli->timeout); - dbus_error_init(&dbus_error); - - dbret = dbus_message_get_args(dbus_req->message, &dbus_error, - DBUS_TYPE_UINT16, &cli_ver, - DBUS_TYPE_UINT32, &cli_id, - DBUS_TYPE_INVALID); - if (!dbret) { - DEBUG(SSSDBG_CRIT_FAILURE, - "Failed to parse message, killing connection\n"); - if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error); + if (!sbus_request_parse_or_finish(dbus_req, + DBUS_TYPE_UINT16, &cli_ver, + DBUS_TYPE_UINT32, &cli_id, + DBUS_TYPE_INVALID)) { sbus_disconnect(conn); - /* FIXME: should we just talloc_zfree(conn) ? */ - return EIO; + return EOK; /* handled */ } DEBUG(SSSDBG_FUNC_DATA, "Proxy client [%"PRIu32"] connected\n", cli_id); -- cgit