summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2014-05-12 18:59:35 +0200
committerJakub Hrozek <jhrozek@redhat.com>2014-05-22 17:35:59 +0200
commite871517a0bfb806cb2fddc76ff2f59360437a73c (patch)
tree24b19ee4d560d5bd6b17d7d1745a920a75818648 /src
parente22d84a534c0b093a31f8473e6c3cbabdb5f5c82 (diff)
downloadsssd-e871517a0bfb806cb2fddc76ff2f59360437a73c.tar.gz
sssd-e871517a0bfb806cb2fddc76ff2f59360437a73c.tar.xz
sssd-e871517a0bfb806cb2fddc76ff2f59360437a73c.zip
SBUS: Utility function sbus_request_return_as_variant
Adds a utility function that returns a single value with a given type in a variant. This utility function will be used by the Get property call. Reviewed-by: Stef Walter <stefw@redhat.com> Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/sbus/sssd_dbus.h4
-rw-r--r--src/sbus/sssd_dbus_request.c64
2 files changed, 68 insertions, 0 deletions
diff --git a/src/sbus/sssd_dbus.h b/src/sbus/sssd_dbus.h
index 15ca52118..efb029681 100644
--- a/src/sbus/sssd_dbus.h
+++ b/src/sbus/sssd_dbus.h
@@ -246,6 +246,10 @@ int sbus_request_return_and_finish(struct sbus_request *dbus_req,
int first_arg_type,
...);
+int sbus_request_return_as_variant(struct sbus_request *dbus_req,
+ int type,
+ const void *value);
+
/*
* Return an error for a DBus method call request. The @error is a normal
* DBusError.
diff --git a/src/sbus/sssd_dbus_request.c b/src/sbus/sssd_dbus_request.c
index 2d23931aa..6c0cb4dac 100644
--- a/src/sbus/sssd_dbus_request.c
+++ b/src/sbus/sssd_dbus_request.c
@@ -125,6 +125,70 @@ int sbus_request_return_and_finish(struct sbus_request *dbus_req,
return ret;
}
+int sbus_request_return_as_variant(struct sbus_request *dbus_req,
+ int type,
+ const void *value)
+{
+ DBusMessage *reply;
+ dbus_bool_t dbret;
+ DBusMessageIter iter;
+ DBusMessageIter valiter;
+ char strtype[2];
+ int ret;
+
+ snprintf(strtype, 2, "%c", type);
+
+ reply = dbus_message_new_method_return(dbus_req->message);
+ if (reply == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory allocating DBus message\n");
+ sbus_request_finish(dbus_req, NULL);
+ return ENOMEM;
+ }
+
+ dbus_message_iter_init_append(reply, &iter);
+ dbret = dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+ strtype, &valiter);
+ if (!dbret) {
+ sbus_request_fail_and_finish(
+ dbus_req,
+ sbus_error_new(dbus_req,
+ DBUS_ERROR_FAILED,
+ "Could not open variant for [%s]\n",
+ strtype));
+ ret = EINVAL;
+ goto done;
+ }
+
+ dbret = dbus_message_iter_append_basic(&valiter, type, value);
+ if (!dbret) {
+ sbus_request_fail_and_finish(
+ dbus_req,
+ sbus_error_new(dbus_req,
+ DBUS_ERROR_FAILED,
+ "Could not append [%s] to variant\n",
+ strtype));
+ ret = EINVAL;
+ goto done;
+ }
+
+ dbret = dbus_message_iter_close_container(&iter, &valiter);
+ if (dbret) {
+ ret = sbus_request_finish(dbus_req, reply);
+ } else {
+ sbus_request_fail_and_finish(
+ dbus_req,
+ sbus_error_new(dbus_req,
+ DBUS_ERROR_FAILED,
+ "Could not close variant\n"));
+ ret = EINVAL;
+ }
+
+done:
+ dbus_message_unref(reply);
+ return ret;
+}
+
+
int sbus_request_fail_and_finish(struct sbus_request *dbus_req,
const DBusError *error)
{