>From e2dfcc9d150a8a1dad475ec554dbbf6d49a5967e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Fri, 12 Dec 2014 15:14:09 +0100
Subject: [PATCH 5/9] sbus: add object path to sbus request

Object path is heavily used in implementation of methods from
interfaces that are supported on whole subtrees. Although it
can be obtained from a D-Bus message, it is nice to have it
accessible directly.
---
 src/responder/ifp/ifp_components.c | 18 ++++++------------
 src/responder/ifp/ifp_domains.c    |  4 ++--
 src/sbus/sssd_dbus.h               |  1 +
 src/sbus/sssd_dbus_request.c       |  1 +
 src/tests/sbus_tests.c             |  8 +++-----
 5 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/src/responder/ifp/ifp_components.c b/src/responder/ifp/ifp_components.c
index c8ad7673c290658e0c6c6273bce5e62bf88e8383..2b76a480dcb5f2d7203eda1c193d133da9ff103b 100644
--- a/src/responder/ifp/ifp_components.c
+++ b/src/responder/ifp/ifp_components.c
@@ -691,7 +691,6 @@ int ifp_component_change_debug_level_tmp(struct sbus_request *dbus_req,
 {
     struct ifp_ctx *ctx = NULL;
     DBusError *error = NULL;
-    const char *path = dbus_message_get_path(dbus_req->message);
     char *name = NULL;
     enum component_type type;
     errno_t ret;
@@ -704,7 +703,7 @@ int ifp_component_change_debug_level_tmp(struct sbus_request *dbus_req,
     }
 
     ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
-                                            path, &type, &name);
+                                            dbus_req->path, &type, &name);
     if (ret != EOK) {
         goto done;
     }
@@ -736,7 +735,6 @@ void ifp_component_get_name(struct sbus_request *dbus_req,
                             const char **_out)
 {
     struct ifp_ctx *ctx = NULL;
-    const char *path = dbus_message_get_path(dbus_req->message);
     char *name = NULL;
     errno_t ret;
 
@@ -749,7 +747,7 @@ void ifp_component_get_name(struct sbus_request *dbus_req,
     }
 
     ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
-                                            path, NULL, &name);
+                                            dbus_req->path, NULL, &name);
     if (ret != EOK) {
         DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
                                  ret, strerror(ret));
@@ -764,7 +762,6 @@ void ifp_component_get_debug_level(struct sbus_request *dbus_req,
                                    uint32_t *_out)
 {
     struct ifp_ctx *ctx = NULL;
-    const char *path = dbus_message_get_path(dbus_req->message);
     const char *confdb_path = NULL;
     char *name = NULL;
     enum component_type type;
@@ -780,7 +777,7 @@ void ifp_component_get_debug_level(struct sbus_request *dbus_req,
     }
 
     ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
-                                            path, &type, &name);
+                                            dbus_req->path, &type, &name);
     if (ret != EOK) {
         DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
                                  ret, strerror(ret));
@@ -820,7 +817,6 @@ void ifp_component_get_enabled(struct sbus_request *dbus_req,
                                bool *_out)
 {
     struct ifp_ctx *ctx = NULL;
-    const char *path = dbus_message_get_path(dbus_req->message);
     const char *param = NULL;
     char **values = NULL;
     char *name = NULL;
@@ -837,7 +833,7 @@ void ifp_component_get_enabled(struct sbus_request *dbus_req,
     }
 
     ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
-                                            path, &type, &name);
+                                            dbus_req->path, &type, &name);
     if (ret != EOK) {
         DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
                                  ret, strerror(ret));
@@ -877,7 +873,6 @@ void ifp_component_get_type(struct sbus_request *dbus_req,
                             const char **_out)
 {
     struct ifp_ctx *ctx = NULL;
-    const char *path = dbus_message_get_path(dbus_req->message);
     enum component_type type;
     errno_t ret;
 
@@ -890,7 +885,7 @@ void ifp_component_get_type(struct sbus_request *dbus_req,
     }
 
     ret = check_and_get_component_from_path(dbus_req, ctx->rctx->cdb,
-                                            path, &type, NULL);
+                                            dbus_req->path, &type, NULL);
     if (ret != EOK) {
         DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
                                  ret, strerror(ret));
@@ -917,7 +912,6 @@ void ifp_backend_get_providers(struct sbus_request *dbus_req,
 {
     TALLOC_CTX *tmp_ctx = NULL;
     struct ifp_ctx *ctx = NULL;
-    const char *path = dbus_message_get_path(dbus_req->message);
     const char *confdb_path = NULL;
     char *name = NULL;
     enum component_type type;
@@ -952,7 +946,7 @@ void ifp_backend_get_providers(struct sbus_request *dbus_req,
     }
 
     ret = check_and_get_component_from_path(tmp_ctx, ctx->rctx->cdb,
-                                            path, &type, &name);
+                                            dbus_req->path, &type, &name);
     if (ret != EOK) {
         DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d]: %s\n",
                                  ret, strerror(ret));
diff --git a/src/responder/ifp/ifp_domains.c b/src/responder/ifp/ifp_domains.c
index 0d50dac32471d82e98ba7a958e44e42a30d2cbf5..1841cbe5857ce159718c6d5e44b02e3bcd6e4a39 100644
--- a/src/responder/ifp/ifp_domains.c
+++ b/src/responder/ifp/ifp_domains.c
@@ -254,7 +254,6 @@ get_domain_info_from_req(struct sbus_request *dbus_req, void *data)
     struct ifp_ctx *ctx = NULL;
     struct sss_domain_info *domains = NULL;
     struct sss_domain_info *iter = NULL;
-    const char *path = dbus_message_get_path(dbus_req->message);
     const char *raw_name = NULL;
     char *name = NULL;
 
@@ -264,7 +263,8 @@ get_domain_info_from_req(struct sbus_request *dbus_req, void *data)
         return NULL;
     }
 
-    raw_name = ifp_path_strip_prefix(path, INFOPIPE_DOMAIN_PATH_PFX "/");
+    raw_name = ifp_path_strip_prefix(dbus_req->path,
+                                     INFOPIPE_DOMAIN_PATH_PFX "/");
     if (raw_name == NULL) {
         return NULL;
     }
diff --git a/src/sbus/sssd_dbus.h b/src/sbus/sssd_dbus.h
index c50b4e9b659a3a35b50e38d8295dbccd9e1a062d..0d021f8fd601ebdacfeb786036144bb627a6389f 100644
--- a/src/sbus/sssd_dbus.h
+++ b/src/sbus/sssd_dbus.h
@@ -219,6 +219,7 @@ struct sbus_request {
     DBusMessage *message;
     struct sbus_interface *intf;
     const struct sbus_method_meta *method;
+    const char *path;
 };
 
 /*
diff --git a/src/sbus/sssd_dbus_request.c b/src/sbus/sssd_dbus_request.c
index 2db9513f638baa8ba5e00c8a6890a78b3f97c015..7362f4b7949e9ddc84856e74e352651b0aa90f8b 100644
--- a/src/sbus/sssd_dbus_request.c
+++ b/src/sbus/sssd_dbus_request.c
@@ -49,6 +49,7 @@ sbus_new_request(struct sbus_connection *conn,
     dbus_req->intf = intf;
     dbus_req->conn = conn;
     dbus_req->message = dbus_message_ref(message);
+    dbus_req->path = dbus_message_get_path(message);
     talloc_set_destructor(dbus_req, sbus_request_destructor);
 
     return dbus_req;
diff --git a/src/tests/sbus_tests.c b/src/tests/sbus_tests.c
index 6086a42bfc8b53ae0a7047345b509d515abab38f..288163d617b4dcd644a6f17ca00021964a7d795d 100644
--- a/src/tests/sbus_tests.c
+++ b/src/tests/sbus_tests.c
@@ -108,7 +108,6 @@ const struct sbus_interface_meta pilot_meta = {
 static int blink_handler(struct sbus_request *req, void *data)
 {
     DBusError error = DBUS_ERROR_INIT;
-    const char *path;
     dbus_int32_t duration = 0;
     dbus_bool_t crashed;
 
@@ -116,12 +115,11 @@ static int blink_handler(struct sbus_request *req, void *data)
     ck_assert(data != NULL);
     ck_assert(data == req->intf->instance_data);
 
-    path = dbus_message_get_path(req->message);
-    ck_assert_str_eq(req->intf->path, path);
+    ck_assert_str_eq(req->intf->path, req->path);
 
-    if (strcmp(path, "/test/fry") == 0) {
+    if (strcmp(req->path, "/test/fry") == 0) {
         ck_assert_str_eq(data, "Don't crash");
-    } else if (strcmp(path, "/test/leela") == 0) {
+    } else if (strcmp(req->path, "/test/leela") == 0) {
         ck_assert_str_eq(data, "Crash into the billboard");
     } else {
         ck_abort();
-- 
1.9.3

