1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * This file is part of message-port.
6 * Copyright (C) 2013 Intel Corporation.
8 * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 #include "msgport-utils.h"
27 #include "common/dbus-error.h" /* MsgPortError */
28 #include "common/log.h"
31 _bundle_iter_cb (const char *key, const int type, const bundle_keyval_t *kv, void *user_data)
33 GVariantBuilder *builder = (GVariantBuilder *)user_data;
37 /* NOTE: we support only string values as
38 * MessagePort API support key,value strings
40 if (bundle_keyval_get_type ((bundle_keyval_t*)kv) != BUNDLE_TYPE_STR) return;
42 bundle_keyval_get_basic_val ((bundle_keyval_t*)kv, &val, &size);
44 g_variant_builder_add (builder, "{sv}", key, g_variant_new_string ((const gchar *)val));
47 GVariant * bundle_to_variant_map (bundle *b)
49 GVariantBuilder builder;
51 g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
53 bundle_foreach (b, _bundle_iter_cb, &builder);
55 return g_variant_builder_end (&builder);
58 bundle * bundle_from_variant_map (GVariant *v_data)
63 GVariant *value = NULL;
65 if (!v_data) return b;
67 g_variant_iter_init (&iter, v_data);
71 while (g_variant_iter_next (&iter, "{sv}", &key, &value)) {
72 bundle_add (b, key, g_variant_get_string (value, NULL));
74 g_variant_unref (value);
81 msgport_daemon_error_to_error (const GError *error)
83 if (!error) return MESSAGEPORT_ERROR_NONE;
85 switch (error->code) {
86 case MSGPORT_ERROR_OUT_OF_MEMORY:
87 return MESSAGEPORT_ERROR_OUT_OF_MEMORY;
88 case MSGPORT_ERROR_NOT_FOUND:
89 return MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND;
90 case MSGPORT_ERROR_INVALID_PARAMS:
91 return MESSAGEPORT_ERROR_INVALID_PARAMETER;
92 case MSGPORT_ERROR_CERTIFICATE_MISMATCH:
93 return MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH;
94 case MSGPORT_ERROR_UNKNOWN:
95 case MSGPORT_ERROR_IO_ERROR:
96 return MESSAGEPORT_ERROR_IO_ERROR;
99 return MESSAGEPORT_ERROR_IO_ERROR;