sss_sifp.c revision 91cf6f4c6069d6aff01aab171825e83a1a669e2f
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder/*
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder Authors:
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder Pavel Březina <pbrezina@redhat.com>
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder Copyright (C) 2014 Red Hat
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder This program is free software; you can redistribute it and/or modify
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder it under the terms of the GNU General Public License as published by
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder the Free Software Foundation; either version 3 of the License, or
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder (at your option) any later version.
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder This program is distributed in the hope that it will be useful,
99b26e2ab8ba89bc9a050c1524137eb6269e2753Christian Maeder but WITHOUT ANY WARRANTY; without even the implied warranty of
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maeder GNU General Public License for more details.
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder You should have received a copy of the GNU General Public License
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder along with this program. If not, see <http://www.gnu.org/licenses/>.
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder*/
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder#include <dbus/dbus.h>
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder#include <stdlib.h>
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder#include <string.h>
99b26e2ab8ba89bc9a050c1524137eb6269e2753Christian Maeder
736fe640b202e3fe7288fad8251d5b210c5d8d87Christian Maeder#include "lib/sifp/sss_sifp.h"
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder#include "lib/sifp/sss_sifp_dbus.h"
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder#include "lib/sifp/sss_sifp_private.h"
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder#define DBUS_IFACE_PROP "org.freedesktop.DBus.Properties"
e84c877ad38ce9312eab222a79f44da2015572d2Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maederstatic void * default_alloc(size_t size, void *pvt)
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder{
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder return malloc(size);
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder}
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maederstatic void default_free(void *ptr, void *pvt)
945e82ed7877917f3ab1657f555e71991372546aChristian Maeder{
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder free(ptr);
c208973c890b8f993297720fd0247bc7481d4304Christian Maeder}
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maederstatic DBusMessage * sss_sifp_create_prop_msg(const char *object_path,
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder const char *method)
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder{
d97700a22b2585ece83b05f3fff945fdfd0c44b4Christian Maeder return sss_sifp_create_message(object_path, DBUS_IFACE_PROP, method);
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder}
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maeder
de8eee2014437ec4020be15cd363257f87e79943Christian Maedersss_sifp_error
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maedersss_sifp_init(sss_sifp_ctx **_ctx)
fd94a6f66ccb5cef99aa42069b61e4b8734dbd3fChristian Maeder{
fd94a6f66ccb5cef99aa42069b61e4b8734dbd3fChristian Maeder return sss_sifp_init_ex(NULL, default_alloc, default_free, _ctx);
fd94a6f66ccb5cef99aa42069b61e4b8734dbd3fChristian Maeder}
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maedersss_sifp_error
473f5af6e4803fbeecc814065952396f2501039bChristian Maedersss_sifp_init_ex(void *alloc_pvt,
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder sss_sifp_alloc_func *alloc_func,
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder sss_sifp_free_func *free_func,
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder sss_sifp_ctx **_ctx)
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder{
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder sss_sifp_ctx *ctx = NULL;
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder DBusConnection *conn = NULL;
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder DBusError dbus_error;
844c7d2ec3917393e139e53503757098d568713eSimon Ulbricht sss_sifp_error ret;
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder
04c445e50a1d8b95e667595594e6b551c8b2ff59Simon Ulbricht if (_ctx == NULL || alloc_func == NULL || free_func == NULL) {
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maeder return SSS_SIFP_INVALID_ARGUMENT;
c99b0eb6632087d502dd4269599c5aa68a148eebSimon Ulbricht }
c99b0eb6632087d502dd4269599c5aa68a148eebSimon Ulbricht
b99c9606f2faafeabb3fa8c596992143a561c787Simon Ulbricht dbus_error_init(&dbus_error);
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht
df67ddf64192bfcae6ece65255ad796a17cbe532Christian Maeder ctx = alloc_func(sizeof(sss_sifp_ctx), alloc_pvt);
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder if (ctx == NULL) {
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder ret = SSS_SIFP_OUT_OF_MEMORY;
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder goto done;
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder }
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder
f675b8f0a612e37472640da57b48d795bef4427eChristian Maeder ctx->conn = NULL;
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder ctx->alloc_fn = alloc_func;
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder ctx->free_fn = free_func;
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder ctx->alloc_pvt = alloc_pvt;
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder ctx->io_error = alloc_func(sizeof(DBusError), alloc_pvt);
dae8246f1f55b6a85e946fc1bfb6d32d556395f1Simon Ulbricht if (ctx->io_error == NULL) {
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder ret = SSS_SIFP_OUT_OF_MEMORY;
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder goto done;
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder }
7710f7c3425e45af11af124ff37bec27229d24f7Christian Maeder
2e2559f894aaa661b199e4fa00609f522bc5482aSimon Ulbricht dbus_error_init(ctx->io_error);
df67ddf64192bfcae6ece65255ad796a17cbe532Christian Maeder
be1ce1c2b2819ef32743136c13101f1927375311Christian Maeder conn = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder if (dbus_error_is_set(&dbus_error)) {
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder sss_sifp_set_io_error(ctx, &dbus_error);
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder ret = SSS_SIFP_IO_ERROR;
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder goto done;
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder }
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder ctx->conn = conn;
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder *_ctx = ctx;
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder ret = SSS_SIFP_OK;
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maederdone:
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder if (ret != SSS_SIFP_OK) {
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder sss_sifp_free(&ctx);
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder }
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder dbus_error_free(&dbus_error);
5fb6343a5a2b4bbc67bc83479c84a92d23d30edfChristian Maeder return ret;
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder}
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder
5fb6343a5a2b4bbc67bc83479c84a92d23d30edfChristian Maederconst char *
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maedersss_sifp_get_last_io_error_name(sss_sifp_ctx *ctx)
5fb6343a5a2b4bbc67bc83479c84a92d23d30edfChristian Maeder{
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder if (ctx == NULL) {
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder return "Invalid sss_sifp context";
31a81edf1285dc338211bfe86ba50a1f4128d9d2Christian Maeder }
31a81edf1285dc338211bfe86ba50a1f4128d9d2Christian Maeder
31a81edf1285dc338211bfe86ba50a1f4128d9d2Christian Maeder if (!dbus_error_is_set(ctx->io_error)) {
9d50556254571c0811e94b4d948463754812a5aaChristian Maeder return NULL;
31a81edf1285dc338211bfe86ba50a1f4128d9d2Christian Maeder }
31a81edf1285dc338211bfe86ba50a1f4128d9d2Christian Maeder
9d50556254571c0811e94b4d948463754812a5aaChristian Maeder return ctx->io_error->name;
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder}
5dd895cd3d794ecd2f0035ee3a7b6d6bf2eac5efChristian Maeder
2f0ca8050a33fbc1a23c0bd2dec0d09c17e3c548Christian Maederconst char *
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maedersss_sifp_get_last_io_error_message(sss_sifp_ctx *ctx)
262a0a50e5f72336445bee69630a964660cc8622Christian Maeder{
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder if (ctx == NULL) {
2f0ca8050a33fbc1a23c0bd2dec0d09c17e3c548Christian Maeder return "Invalid sss_sifp context";
2f0ca8050a33fbc1a23c0bd2dec0d09c17e3c548Christian Maeder }
2f0ca8050a33fbc1a23c0bd2dec0d09c17e3c548Christian Maeder
2f0ca8050a33fbc1a23c0bd2dec0d09c17e3c548Christian Maeder if (!dbus_error_is_set(ctx->io_error)) {
2f0ca8050a33fbc1a23c0bd2dec0d09c17e3c548Christian Maeder return NULL;
2f0ca8050a33fbc1a23c0bd2dec0d09c17e3c548Christian Maeder }
2f0ca8050a33fbc1a23c0bd2dec0d09c17e3c548Christian Maeder
232c13ff6847a6f2bac7163392f80ab692cd7774Christian Maeder return ctx->io_error->message;
232c13ff6847a6f2bac7163392f80ab692cd7774Christian Maeder}
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maedersss_sifp_error
2f0ca8050a33fbc1a23c0bd2dec0d09c17e3c548Christian Maedersss_sifp_fetch_attr(sss_sifp_ctx *ctx,
2f0ca8050a33fbc1a23c0bd2dec0d09c17e3c548Christian Maeder const char *object_path,
2f0ca8050a33fbc1a23c0bd2dec0d09c17e3c548Christian Maeder const char *interface,
f50c9f317ed743022255535248028675a5716d2aSimon Ulbricht const char *name,
232c13ff6847a6f2bac7163392f80ab692cd7774Christian Maeder sss_sifp_attr ***_attrs)
232c13ff6847a6f2bac7163392f80ab692cd7774Christian Maeder{
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder DBusMessage *msg = NULL;
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder DBusMessage *reply = NULL;
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder dbus_bool_t bret;
99b26e2ab8ba89bc9a050c1524137eb6269e2753Christian Maeder sss_sifp_error ret;
63ec46a77d00127c46ec526df43da8d701c30c65Christian Maeder
99b26e2ab8ba89bc9a050c1524137eb6269e2753Christian Maeder if (ctx == NULL || object_path == NULL || interface == NULL
99b26e2ab8ba89bc9a050c1524137eb6269e2753Christian Maeder || name == NULL || _attrs == NULL) {
99b26e2ab8ba89bc9a050c1524137eb6269e2753Christian Maeder return SSS_SIFP_INVALID_ARGUMENT;
99b26e2ab8ba89bc9a050c1524137eb6269e2753Christian Maeder }
99b26e2ab8ba89bc9a050c1524137eb6269e2753Christian Maeder
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder /* Message format:
cc9f19b1fe81424205736fe0ae73620395b1bb74Simon Ulbricht * In: string:interface
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht * In: string:attribute
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht * Out: variant(misc:value)
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht */
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht msg = sss_sifp_create_prop_msg(object_path, "Get");
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht if (msg == NULL) {
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht ret = SSS_SIFP_OUT_OF_MEMORY;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht goto done;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht }
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht bret = dbus_message_append_args(msg, DBUS_TYPE_STRING, &interface,
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht DBUS_TYPE_STRING, &name,
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht DBUS_TYPE_INVALID);
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht if (!bret) {
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht ret = SSS_SIFP_OUT_OF_MEMORY;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht goto done;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht }
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht ret = sss_sifp_send_message(ctx, msg, &reply);
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht if (ret != SSS_SIFP_OK) {
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht goto done;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht }
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht ret = sss_sifp_parse_attr(ctx, name, reply, _attrs);
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbrichtdone:
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht if (msg != NULL) {
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht dbus_message_unref(msg);
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht }
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht if (reply != NULL) {
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht dbus_message_unref(reply);
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht }
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht return ret;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht}
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbrichtsss_sifp_error
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbrichtsss_sifp_fetch_all_attrs(sss_sifp_ctx *ctx,
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht const char *object_path,
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht const char *interface,
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht sss_sifp_attr ***_attrs)
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht{
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht DBusMessage *msg = NULL;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht DBusMessage *reply = NULL;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht dbus_bool_t bret;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht sss_sifp_error ret;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht if (ctx == NULL || object_path == NULL || interface == NULL
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht || _attrs == NULL) {
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht return SSS_SIFP_INVALID_ARGUMENT;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht }
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht msg = sss_sifp_create_prop_msg(object_path, "GetAll");
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht if (msg == NULL) {
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht ret = SSS_SIFP_OUT_OF_MEMORY;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht goto done;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht }
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht bret = dbus_message_append_args(msg, DBUS_TYPE_STRING, &interface,
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht DBUS_TYPE_INVALID);
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht if (!bret) {
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht ret = SSS_SIFP_OUT_OF_MEMORY;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht goto done;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht }
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht ret = sss_sifp_send_message(ctx, msg, &reply);
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht if (ret != SSS_SIFP_OK) {
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht goto done;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht }
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht ret = sss_sifp_parse_attr_list(ctx, reply, _attrs);
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbrichtdone:
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht if (msg != NULL) {
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht dbus_message_unref(msg);
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht }
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht if (reply != NULL) {
562e30787355109feb0133ffea2ad86b6c143c26Simon Ulbricht dbus_message_unref(reply);
562e30787355109feb0133ffea2ad86b6c143c26Simon Ulbricht }
562e30787355109feb0133ffea2ad86b6c143c26Simon Ulbricht
562e30787355109feb0133ffea2ad86b6c143c26Simon Ulbricht return ret;
562e30787355109feb0133ffea2ad86b6c143c26Simon Ulbricht}
562e30787355109feb0133ffea2ad86b6c143c26Simon Ulbricht
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbrichtsss_sifp_error
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbrichtsss_sifp_fetch_object(sss_sifp_ctx *ctx,
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht const char *object_path,
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht const char *interface,
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht sss_sifp_object **_object)
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht{
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht sss_sifp_object *object = NULL;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht sss_sifp_attr **attrs = NULL;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht const char *name = NULL;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht sss_sifp_error ret;
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht if (ctx == NULL || object_path == NULL || interface == NULL
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht || _object == NULL) {
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht return SSS_SIFP_INVALID_ARGUMENT;
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht }
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht ret = sss_sifp_fetch_all_attrs(ctx, object_path, interface, &attrs);
7463a1bf64cfa90917e2afb6a5017ec411d2b3dbSimon Ulbricht if (ret != SSS_SIFP_OK) {
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht goto done;
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht }
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht ret = sss_sifp_find_attr_as_string(attrs, "name", &name);
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht if (ret != SSS_SIFP_OK) {
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht goto done;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht }
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht object = _alloc_zero(ctx, sss_sifp_object, 1);
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht if (object == NULL) {
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht ret = SSS_SIFP_OUT_OF_MEMORY;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht goto done;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht }
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht object->attrs = attrs;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht object->name = sss_sifp_strdup(ctx, name);
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht if (object->name == NULL) {
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht ret = SSS_SIFP_OUT_OF_MEMORY;
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht goto done;
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht }
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht object->object_path = sss_sifp_strdup(ctx, object_path);
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht if (object->object_path == NULL) {
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht ret = SSS_SIFP_OUT_OF_MEMORY;
2e2559f894aaa661b199e4fa00609f522bc5482aSimon Ulbricht goto done;
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht }
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht object->interface = sss_sifp_strdup(ctx, interface);
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht if (object->interface == NULL) {
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht ret = SSS_SIFP_OUT_OF_MEMORY;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht goto done;
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht }
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht *_object = object;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht ret = SSS_SIFP_OK;
2e76bbbed1c936bb0aee1753837e1c50416847a2Simon Ulbricht
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbrichtdone:
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht if (ret != SSS_SIFP_OK) {
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht sss_sifp_free_object(ctx, &object);
2e2559f894aaa661b199e4fa00609f522bc5482aSimon Ulbricht }
2e2559f894aaa661b199e4fa00609f522bc5482aSimon Ulbricht
05c714be15ce094d83f1b989cdf5236be78419bfSimon Ulbricht return ret;
05c714be15ce094d83f1b989cdf5236be78419bfSimon Ulbricht}
05c714be15ce094d83f1b989cdf5236be78419bfSimon Ulbricht
05c714be15ce094d83f1b989cdf5236be78419bfSimon Ulbrichtvoid
05c714be15ce094d83f1b989cdf5236be78419bfSimon Ulbrichtsss_sifp_free(sss_sifp_ctx **_ctx)
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht{
05c714be15ce094d83f1b989cdf5236be78419bfSimon Ulbricht sss_sifp_ctx *ctx = NULL;
05c714be15ce094d83f1b989cdf5236be78419bfSimon Ulbricht
05c714be15ce094d83f1b989cdf5236be78419bfSimon Ulbricht if (_ctx == NULL || *_ctx == NULL) {
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht return;
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht }
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht ctx = *_ctx;
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht if (ctx->conn != NULL) {
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht dbus_connection_unref(ctx->conn);
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht }
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht if (ctx->io_error != NULL) {
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht dbus_error_free(ctx->io_error);
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht _free(ctx, ctx->io_error);
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht }
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
562e30787355109feb0133ffea2ad86b6c143c26Simon Ulbricht _free(ctx, ctx);
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht *_ctx = NULL;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht return;
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht}
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbrichtvoid
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbrichtsss_sifp_free_attrs(sss_sifp_ctx *ctx,
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht sss_sifp_attr ***_attrs)
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht{
de8eee2014437ec4020be15cd363257f87e79943Christian Maeder sss_sifp_attr **attrs = NULL;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht unsigned int i, j;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht if (_attrs == NULL || *_attrs == NULL) {
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht return;
f6a562e28240e4f9107c199ba7a8e500ccfbfa55Simon Ulbricht }
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht attrs = *_attrs;
9a5e6e537c43a631facd9d87ce1a6c76f4b0af6dSimon Ulbricht
05c714be15ce094d83f1b989cdf5236be78419bfSimon Ulbricht for (i = 0; attrs[i] != NULL; i++) {
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht switch (attrs[i]->type) {
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht case SSS_SIFP_ATTR_TYPE_BOOL:
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht _free(ctx, attrs[i]->data.boolean);
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder break;
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder case SSS_SIFP_ATTR_TYPE_INT16:
1ab66a7e4234c760be9689b05ab4c34ce99dba23Simon Ulbricht _free(ctx, attrs[i]->data.int16);
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder break;
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder case SSS_SIFP_ATTR_TYPE_UINT16:
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder _free(ctx, attrs[i]->data.uint16);
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder break;
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder case SSS_SIFP_ATTR_TYPE_INT32:
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder _free(ctx, attrs[i]->data.int32);
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder break;
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder case SSS_SIFP_ATTR_TYPE_UINT32:
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder _free(ctx, attrs[i]->data.uint32);
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder break;
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder case SSS_SIFP_ATTR_TYPE_INT64:
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder _free(ctx, attrs[i]->data.int64);
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder break;
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder case SSS_SIFP_ATTR_TYPE_UINT64:
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder _free(ctx, attrs[i]->data.uint64);
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder break;
0bbc28585c7d42913167ff78a862ef25ea59e85eChristian Maeder case SSS_SIFP_ATTR_TYPE_STRING:
4ed68712ee368cbebfeaa327968583cb022e3c72Christian Maeder for (j = 0; j < attrs[i]->num_values; j++) {
4ed68712ee368cbebfeaa327968583cb022e3c72Christian Maeder _free(ctx, attrs[i]->data.str[j]);
4ed68712ee368cbebfeaa327968583cb022e3c72Christian Maeder }
4ed68712ee368cbebfeaa327968583cb022e3c72Christian Maeder _free(ctx, attrs[i]->data.str);
4ed68712ee368cbebfeaa327968583cb022e3c72Christian Maeder break;
4ed68712ee368cbebfeaa327968583cb022e3c72Christian Maeder }
4ed68712ee368cbebfeaa327968583cb022e3c72Christian Maeder _free(ctx, attrs[i]->name);
993e01fc242fa58d3dcf1b3272cd411726817eeeSimon Ulbricht _free(ctx, attrs[i]);
4ed68712ee368cbebfeaa327968583cb022e3c72Christian Maeder }
f3fb0e085030be5bc309d946a6a9c20736dd3e0fSimon Ulbricht
f3fb0e085030be5bc309d946a6a9c20736dd3e0fSimon Ulbricht _free(ctx, attrs);
f3fb0e085030be5bc309d946a6a9c20736dd3e0fSimon Ulbricht
f3fb0e085030be5bc309d946a6a9c20736dd3e0fSimon Ulbricht *_attrs = NULL;
f3fb0e085030be5bc309d946a6a9c20736dd3e0fSimon Ulbricht}
f3fb0e085030be5bc309d946a6a9c20736dd3e0fSimon Ulbricht
116efc752fbf094a464c4f4940d9a450ab41c6c9Simon Ulbrichtvoid
31a81edf1285dc338211bfe86ba50a1f4128d9d2Christian Maedersss_sifp_free_object(sss_sifp_ctx *ctx,
4ed68712ee368cbebfeaa327968583cb022e3c72Christian Maeder sss_sifp_object **_object)
31a81edf1285dc338211bfe86ba50a1f4128d9d2Christian Maeder{
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder sss_sifp_object *object = NULL;
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder if (_object == NULL || *_object == NULL) {
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder return;
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder }
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder object = *_object;
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder sss_sifp_free_attrs(ctx, &object->attrs);
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder _free(ctx, object->object_path);
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder _free(ctx, object->interface);
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder _free(ctx, object->name);
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder _free(ctx, object);
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder *_object = NULL;
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder}
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maedervoid
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maedersss_sifp_free_string(sss_sifp_ctx *ctx,
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder char **_str)
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder{
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder if (_str == NULL || *_str == NULL) {
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder return;
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder }
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder
fd94a6f66ccb5cef99aa42069b61e4b8734dbd3fChristian Maeder _free(ctx, *_str);
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maeder
bd90cf050d470eb42f6e0b79327cc53bd0f80dc9Christian Maeder *_str = NULL;
bd90cf050d470eb42f6e0b79327cc53bd0f80dc9Christian Maeder}
bd90cf050d470eb42f6e0b79327cc53bd0f80dc9Christian Maeder
de8eee2014437ec4020be15cd363257f87e79943Christian Maedervoid
de8eee2014437ec4020be15cd363257f87e79943Christian Maedersss_sifp_free_string_array(sss_sifp_ctx *ctx,
de8eee2014437ec4020be15cd363257f87e79943Christian Maeder char ***_str_array)
bd90cf050d470eb42f6e0b79327cc53bd0f80dc9Christian Maeder{
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maeder char **str_array = NULL;
de8eee2014437ec4020be15cd363257f87e79943Christian Maeder int i;
de8eee2014437ec4020be15cd363257f87e79943Christian Maeder
bd90cf050d470eb42f6e0b79327cc53bd0f80dc9Christian Maeder if (_str_array == NULL || *_str_array == NULL) {
bd90cf050d470eb42f6e0b79327cc53bd0f80dc9Christian Maeder return;
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder }
5a448e9be8c4482a978b174b744237757335140fChristian Maeder
5a448e9be8c4482a978b174b744237757335140fChristian Maeder str_array = *_str_array;
bd90cf050d470eb42f6e0b79327cc53bd0f80dc9Christian Maeder
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder for (i = 0; str_array[i] != NULL; i++) {
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder _free(ctx, str_array[i]);
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder }
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder _free(ctx, str_array);
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder *_str_array = NULL;
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder}
142fd5dd7fcfa170f08b2a0ab232859428f6e3c2Christian Maeder