sssd_dbus_properties.c revision c43ed56bc5d29e189e529235a3ba4bc17cd1a95f
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter/*
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter Authors:
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter Stef Walter <stefw@redhat.com>
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter Copyright (C) 2014 Red Hat
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter This program is free software; you can redistribute it and/or modify
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter it under the terms of the GNU General Public License as published by
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter the Free Software Foundation; either version 3 of the License, or
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter (at your option) any later version.
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter This program is distributed in the hope that it will be useful,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter but WITHOUT ANY WARRANTY; without even the implied warranty of
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter GNU General Public License for more details.
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter You should have received a copy of the GNU General Public License
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter along with this program. If not, see <http://www.gnu.org/licenses/>.
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter*/
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter#include "util/util.h"
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter#include "sbus/sssd_dbus.h"
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter#include "sbus/sssd_dbus_meta.h"
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter#include "sbus/sssd_dbus_private.h"
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozekstatic char *
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozektype_to_string(char type, char *str)
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek{
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek int l;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek l = snprintf(str, 2, "%c", type);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek if (l != 1) {
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return NULL;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek }
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return str;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek}
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozekint sbus_add_variant_to_dict(DBusMessageIter *iter_dict,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek const char *key,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek int type,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek const void *value)
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek{
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek DBusMessageIter iter_dict_entry;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek DBusMessageIter iter_dict_val;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek dbus_bool_t dbret;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek char strtype[2];
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek type_to_string(type, strtype);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek dbret = dbus_message_iter_open_container(iter_dict,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek DBUS_TYPE_DICT_ENTRY, NULL,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek &iter_dict_entry);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek if (!dbret) {
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return ENOMEM;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek }
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek /* Start by appending the key */
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek dbret = dbus_message_iter_append_basic(&iter_dict_entry,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek DBUS_TYPE_STRING, &key);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek if (!dbret) {
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return ENOMEM;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek }
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek dbret = dbus_message_iter_open_container(&iter_dict_entry,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek DBUS_TYPE_VARIANT,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek strtype,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek &iter_dict_val);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek if (!dbret) {
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return ENOMEM;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek }
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek /* Now add the value */
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek dbret = dbus_message_iter_append_basic(&iter_dict_val, type, value);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek if (!dbret) {
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return ENOMEM;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek }
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek dbret = dbus_message_iter_close_container(&iter_dict_entry,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek &iter_dict_val);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek if (!dbret) {
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return ENOMEM;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek }
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek dbret = dbus_message_iter_close_container(iter_dict,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek &iter_dict_entry);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek if (!dbret) {
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return ENOMEM;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek }
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return EOK;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek}
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walterstatic int
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walterdispatch_properties_set(struct sbus_connection *conn,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter struct sbus_interface *intf,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter DBusMessage *message)
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter{
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter const char *signature;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter const struct sbus_interface_meta *meta;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter const struct sbus_property_meta *property;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter const char *interface_name;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter const char *property_name;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter const char *type;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter struct sbus_request *req;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter sbus_msg_handler_fn handler_fn;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter DBusMessageIter iter;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter DBusMessageIter variant;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter req = sbus_new_request(conn, intf, message);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter if (!req)
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter return ENOMEM;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter meta = intf->vtable->meta;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter signature = dbus_message_get_signature(message);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter if (strcmp (signature, "ssv") != 0) {
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter return sbus_request_fail_and_finish(req,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter sbus_error_new(req,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter DBUS_ERROR_INVALID_ARGS,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter "Invalid argument types passed " \
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter "to Set method"));
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter }
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter dbus_message_iter_init (message, &iter);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter dbus_message_iter_get_basic (&iter, &interface_name);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter dbus_message_iter_next (&iter);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter dbus_message_iter_get_basic (&iter, &property_name);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter dbus_message_iter_next (&iter);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter if (strcmp (interface_name, meta->name) != 0) {
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter return sbus_request_fail_and_finish(req,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter sbus_error_new(req,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter DBUS_ERROR_UNKNOWN_INTERFACE,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter "No such interface"));
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter }
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter property = sbus_meta_find_property (intf->vtable->meta, property_name);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter if (property == NULL) {
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter return sbus_request_fail_and_finish(req,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter sbus_error_new(req,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter DBUS_ERROR_UNKNOWN_PROPERTY,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter "No such property"));
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter }
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter if (!(property->flags & SBUS_PROPERTY_WRITABLE)) {
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter return sbus_request_fail_and_finish(req,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter sbus_error_new(req,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter DBUS_ERROR_PROPERTY_READ_ONLY,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter "Property is not writable"));
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter }
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter dbus_message_iter_recurse(&iter, &variant);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter type = dbus_message_iter_get_signature (&variant);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter if (strcmp (property->type, type) != 0) {
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter return sbus_request_fail_and_finish(req,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter sbus_error_new(req,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter DBUS_ERROR_INVALID_ARGS,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter "Invalid data type for property"));
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter }
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter handler_fn = VTABLE_FUNC(intf->vtable, property->vtable_offset_set);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter if (!handler_fn) {
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter return sbus_request_fail_and_finish(req,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter sbus_error_new(req,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter DBUS_ERROR_NOT_SUPPORTED,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter "Not implemented"));
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter }
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter sbus_request_invoke_or_finish(req, handler_fn,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter intf->instance_data,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter property->invoker_set);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter return EOK;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter}
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic int
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekdispatch_properties_get(struct sbus_connection *conn,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek struct sbus_interface *intf,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusMessage *message)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek struct sbus_request *req;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *signature;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const struct sbus_interface_meta *meta;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusMessageIter iter;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek sbus_msg_handler_fn handler_fn;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const struct sbus_property_meta *property;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *interface_name;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *property_name;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek req = sbus_new_request(conn, intf, message);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek if (req == NULL) {
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek return ENOMEM;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek }
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek meta = intf->vtable->meta;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek signature = dbus_message_get_signature(message);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek /* Interface name, property name */
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek if (strcmp(signature, "ss") != 0) {
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek return sbus_request_fail_and_finish(req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek sbus_error_new(req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_ERROR_INVALID_ARGS,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek "Invalid argument types passed to Get method"));
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek }
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_message_iter_init(message, &iter);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_message_iter_get_basic(&iter, &interface_name);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_message_iter_next(&iter);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_message_iter_get_basic(&iter, &property_name);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek if (strcmp(interface_name, meta->name) != 0) {
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek return sbus_request_fail_and_finish(req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek sbus_error_new(req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_ERROR_UNKNOWN_INTERFACE,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek "No such interface"));
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek }
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek property = sbus_meta_find_property(intf->vtable->meta, property_name);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek if (property == NULL) {
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek return sbus_request_fail_and_finish(req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek sbus_error_new(req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_ERROR_UNKNOWN_PROPERTY,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek "No such property"));
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek }
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek if (!(property->flags & SBUS_PROPERTY_READABLE)) {
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek return sbus_request_fail_and_finish(req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek sbus_error_new(req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_ERROR_ACCESS_DENIED,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek "Property is not readable"));
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek }
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek handler_fn = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek if (!handler_fn) {
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek return sbus_request_fail_and_finish(req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek sbus_error_new(req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_ERROR_NOT_SUPPORTED,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek "Not implemented"));
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek }
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek sbus_request_invoke_or_finish(req, handler_fn,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek intf->instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek property->invoker_get);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek return EOK;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozekstatic int
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozekdispatch_properties_get_all(struct sbus_connection *conn,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek struct sbus_interface *intf,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek DBusMessage *message)
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek{
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek struct sbus_request *req;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek const char *signature;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek const struct sbus_interface_meta *meta;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek const char *interface_name;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek DBusMessageIter iter;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek req = sbus_new_request(conn, intf, message);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek if (req == NULL) {
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return ENOMEM;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek }
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek meta = intf->vtable->meta;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek signature = dbus_message_get_signature(message);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek /* Interface name */
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek if (strcmp(signature, "s") != 0) {
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return sbus_request_fail_and_finish(req,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek sbus_error_new(req,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek DBUS_ERROR_INVALID_ARGS,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek "Invalid argument types passed " \
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek "to Set method"));
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek }
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek dbus_message_iter_init(message, &iter);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek dbus_message_iter_get_basic(&iter, &interface_name);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek if (strcmp(interface_name, meta->name) != 0) {
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return sbus_request_fail_and_finish(req,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek sbus_error_new(req,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek DBUS_ERROR_UNKNOWN_INTERFACE,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek "No such interface"));
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek }
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek sbus_request_invoke_or_finish(req, NULL,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek intf->instance_data,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek meta->invoker_get_all);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return EOK;
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek}
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walterint sbus_properties_dispatch(struct sbus_request *dbus_req)
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter{
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter const char *member;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter member = dbus_message_get_member(dbus_req->message);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter /* Set is handled a lot like a method invocation */
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter if (strcmp(member, "Set") == 0) {
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter return dispatch_properties_set(dbus_req->conn,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter dbus_req->intf,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter dbus_req->message);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek } else if (strcmp (member, "Get") == 0) {
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek return dispatch_properties_get(dbus_req->conn,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_req->intf,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_req->message);
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek } else if (strcmp (member, "GetAll") == 0) {
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek return dispatch_properties_get_all(dbus_req->conn,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek dbus_req->intf,
c43ed56bc5d29e189e529235a3ba4bc17cd1a95fJakub Hrozek dbus_req->message);
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter }
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter return ERR_SBUS_NOSUP;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter}