1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

drop libdbus from libvirt

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Pavel Hrdina 2020-09-15 14:22:57 +02:00
parent 35069cad0a
commit cf6cc86cd2
15 changed files with 3 additions and 2862 deletions

View File

@ -374,9 +374,6 @@ BuildRequires: util-linux
# For showmount in FS driver (netfs discovery)
BuildRequires: nfs-utils
# Communication with the firewall and polkit daemons use DBus
BuildRequires: dbus-devel
# Fedora build root suckage
BuildRequires: gawk

View File

@ -1019,22 +1019,6 @@ if curl_dep.found()
conf.set('WITH_CURL', 1)
endif
dbus_version = '1.0.0'
dbus_dep = dependency('dbus-1', version: '>=' + dbus_version, required: get_option('dbus'))
if dbus_dep.found()
conf.set('WITH_DBUS', 1)
function = 'dbus_watch_get_unix_fd'
if cc.has_function(function, dependencies: dbus_dep)
conf.set('WITH_@0@'.format(function.to_upper()), 1)
endif
type = 'DBusBasicValue'
if cc.has_type(type, dependencies: dbus_dep, prefix: '#include <dbus/dbus.h>')
conf.set('WITH_@0@'.format(type.to_upper()), 1)
endif
endif
devmapper_version = '1.0.0'
devmapper_dep = dependency('devmapper', version: '>=' + devmapper_version, required: false)
if not devmapper_dep.found()
@ -1536,10 +1520,8 @@ if bash_completion_dep.found()
endif
if host_machine.system() != 'freebsd'
if not get_option('firewalld').disabled() and dbus_dep.found()
if not get_option('firewalld').disabled()
conf.set('WITH_FIREWALLD', 1)
elif get_option('firewalld').enabled()
error('You must have dbus enabled for firewalld support')
endif
endif
@ -1553,10 +1535,8 @@ if conf.has('WITH_MACVTAP') and not conf.has('WITH_LIBNL')
error('libnl3-devel is required for macvtap support')
endif
if (pkcheck_prog.found() or get_option('polkit').enabled()) and dbus_dep.found()
if (pkcheck_prog.found() or get_option('polkit').enabled())
conf.set('WITH_POLKIT', 1)
elif get_option('polkit').enabled()
error('You must install dbus to compile libvirt with polkit-1')
endif
if udev_dep.found() and not pciaccess_dep.found()
@ -2203,7 +2183,7 @@ endif
if not get_option('pm_utils').disabled()
use_pm_utils = true
if dbus_dep.found() and init_script == 'systemd'
if init_script == 'systemd'
use_pm_utils = false
endif
@ -2423,7 +2403,6 @@ libs_summary = {
'blkid': blkid_dep.found(),
'capng': capng_dep.found(),
'curl': curl_dep.found(),
'dbus': dbus_dep.found(),
'dlopen': dlopen_dep.found(),
'firewalld': conf.has('WITH_FIREWALLD'),
'firewalld-zone': conf.has('WITH_FIREWALLD_ZONE'),

View File

@ -18,7 +18,6 @@ option('bash_completion_dir', type: 'string', value: '', description: 'directory
option('blkid', type: 'feature', value: 'auto', description: 'blkid support')
option('capng', type: 'feature', value: 'auto', description: 'cap-ng support')
option('curl', type: 'feature', value: 'auto', description: 'curl support')
option('dbus', type: 'feature', value: 'auto', description: 'dbus-1 support')
option('firewalld', type: 'feature', value: 'auto', description: 'firewalld support')
option('firewalld_zone', type: 'feature', value: 'auto', description: 'whether to install firewalld libvirt zone')
option('fuse', type: 'feature', value: 'auto', description: 'fuse support')

View File

@ -243,7 +243,6 @@
@SRCDIR@src/util/virconf.c
@SRCDIR@src/util/vircrypto.c
@SRCDIR@src/util/virdaemon.c
@SRCDIR@src/util/virdbus.c
@SRCDIR@src/util/virdevmapper.c
@SRCDIR@src/util/virdnsmasq.c
@SRCDIR@src/util/virerror.c

View File

@ -1948,23 +1948,6 @@ virDaemonSetupLogging;
virDaemonUnixSocketPaths;
# util/virdbus.h
virDBusCallMethod;
virDBusCloseSystemBus;
virDBusCreateMethod;
virDBusCreateMethodV;
virDBusCreateReply;
virDBusCreateReplyV;
virDBusErrorIsUnknownMethod;
virDBusGetSessionBus;
virDBusGetSystemBus;
virDBusHasSystemBus;
virDBusMessageDecode;
virDBusMessageEncode;
virDBusMessageUnref;
virDBusSetSharedBus;
# util/virdevmapper.h
virDevMapperGetTargets;
virIsDevMapperDevice;

View File

@ -13,12 +13,6 @@ provider libvirt {
probe event_glib_remove_timeout_idle(int timer, void *ff, void *opaque);
probe event_glib_dispatch_timeout(int timer, void *cb, void *opaque);
# file: src/util/virdbus.c
# prefix: dbus
probe dbus_method_call(const char *interface, const char *member, const char *object, const char *destination);
probe dbus_method_error(const char *interface, const char *member, const char *object, const char *destination, const char *name, const char *message);
probe dbus_method_reply(const char *interface, const char *member, const char *object, const char *destination);
# file: src/util/virobject.c
# prefix: object
probe object_new(void *obj, const char *klassname);

View File

@ -614,7 +614,6 @@ foreach daemon : virt_daemons
dependencies: [
admin_dep,
access_dep,
dbus_dep,
gnutls_dep,
libnl_dep,
rpc_dep,

View File

@ -35,7 +35,6 @@
#include "virnetserver.h"
#include "virfile.h"
#include "virtypedparam.h"
#include "virdbus.h"
#include "virprocess.h"
#include "remote_protocol.h"
#include "qemu_protocol.h"

View File

@ -18,7 +18,6 @@ util_sources = [
'virconf.c',
'vircrypto.c',
'virdaemon.c',
'virdbus.c',
'virdevmapper.c',
'virdnsmasq.c',
'virebtables.c',
@ -185,7 +184,6 @@ virt_util_lib = static_library(
acl_dep,
audit_dep,
capng_dep,
dbus_dep,
devmapper_dep,
gnutls_dep,
intl_dep,

File diff suppressed because it is too large Load Diff

View File

@ -1,76 +0,0 @@
/*
* virdbus.h: helper for using DBus
*
* Copyright (C) 2012-2013 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#ifdef WITH_DBUS
# undef interface /* Work around namespace pollution in mingw's rpc.h */
# include <dbus/dbus.h>
#else
# define DBusConnection void
# define DBusMessage void
#endif
#include "internal.h"
#include <stdarg.h>
void virDBusSetSharedBus(bool shared);
DBusConnection *virDBusGetSystemBus(void);
bool virDBusHasSystemBus(void);
void virDBusCloseSystemBus(void);
DBusConnection *virDBusGetSessionBus(void);
int virDBusCreateMethod(DBusMessage **call,
const char *destination,
const char *path,
const char *iface,
const char *member,
const char *types, ...);
int virDBusCreateMethodV(DBusMessage **call,
const char *destination,
const char *path,
const char *iface,
const char *member,
const char *types,
va_list args);
int virDBusCreateReply(DBusMessage **reply,
const char *types, ...);
int virDBusCreateReplyV(DBusMessage **reply,
const char *types,
va_list args);
int virDBusCallMethod(DBusConnection *conn,
DBusMessage **reply,
virErrorPtr error,
const char *destination,
const char *path,
const char *iface,
const char *member,
const char *types, ...);
int virDBusMessageDecode(DBusMessage *msg,
const char *types, ...);
void virDBusMessageUnref(DBusMessage *msg);
int virDBusIsServiceEnabled(const char *name);
int virDBusIsServiceRegistered(const char *name);
bool virDBusErrorIsUnknownMethod(virErrorPtr err);

View File

@ -1,56 +0,0 @@
/*
* virdbuspriv.h: internal APIs for testing DBus code
*
* Copyright (C) 2012-2014 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#ifndef LIBVIRT_VIRDBUSPRIV_H_ALLOW
# error "virdbuspriv.h may only be included by virdbus.c or test suites"
#endif /* LIBVIRT_VIRDBUSPRIV_H_ALLOW */
#pragma once
#include "virdbus.h"
#if defined(WITH_DBUS) && !WITH_DBUSBASICVALUE
/* Copied (and simplified) from dbus 1.6.12, for use with older dbus headers */
typedef union
{
dbus_int16_t i16; /**< as int16 */
dbus_uint16_t u16; /**< as int16 */
dbus_int32_t i32; /**< as int32 */
dbus_uint32_t u32; /**< as int32 */
dbus_bool_t bool_val; /**< as boolean */
dbus_int64_t i64; /**< as int64 */
dbus_uint64_t u64; /**< as int64 */
double dbl; /**< as double */
unsigned char byt; /**< as byte */
} DBusBasicValue;
#endif
int virDBusMessageEncodeArgs(DBusMessage* msg,
const char *types,
va_list args);
int virDBusMessageDecodeArgs(DBusMessage* msg,
const char *types,
va_list args);
int virDBusMessageEncode(DBusMessage* msg,
const char *types,
...);

View File

@ -86,12 +86,6 @@ if conf.has('WITH_BHYVE')
]
endif
if conf.has('WITH_DBUS')
mock_libs += [
{ 'name': 'virdbusmock', 'deps': [ dbus_dep ] },
]
endif
if conf.has('WITH_LIBXL')
mock_libs += [
{ 'name': 'xlmock', 'sources': [ 'libxlmock.c' ], 'deps': [ libxl_dep ] },
@ -360,13 +354,6 @@ if conf.has('WITH_BHYVE')
]
endif
if conf.has('WITH_DBUS')
tests += [
{ 'name': 'virdbustest', 'deps': [ dbus_dep ] },
]
endif
if conf.has('WITH_ESX')
tests += [
{ 'name': 'esxutilstest', 'include': [ esx_inc_dir ] },

View File

@ -1,62 +0,0 @@
/*
* virdbusmock.c: mocking of dbus message send/reply
*
* Copyright (C) 2013-2014 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#if defined(WITH_DBUS) && !defined(WIN32)
# include "virmock.h"
# include <dbus/dbus.h>
VIR_MOCK_STUB_VOID_ARGS(dbus_connection_set_change_sigpipe,
dbus_bool_t, will_modify_sigpipe)
VIR_MOCK_STUB_RET_ARGS(dbus_bus_get,
DBusConnection *, (DBusConnection *)0x1,
DBusBusType, type,
DBusError *, error)
VIR_MOCK_STUB_VOID_ARGS(dbus_connection_set_exit_on_disconnect,
DBusConnection *, connection,
dbus_bool_t, exit_on_disconnect)
VIR_MOCK_STUB_RET_ARGS(dbus_connection_set_watch_functions,
dbus_bool_t, 1,
DBusConnection *, connection,
DBusAddWatchFunction, add_function,
DBusRemoveWatchFunction, remove_function,
DBusWatchToggledFunction, toggled_function,
void *, data,
DBusFreeFunction, free_data_function)
VIR_MOCK_STUB_RET_ARGS(dbus_message_set_reply_serial,
dbus_bool_t, 1,
DBusMessage *, message,
dbus_uint32_t, serial)
VIR_MOCK_LINK_RET_ARGS(dbus_connection_send_with_reply_and_block,
DBusMessage *,
DBusConnection *, connection,
DBusMessage *, message,
int, timeout_milliseconds,
DBusError *, error)
#endif /* WITH_DBUS && !WIN32 */

View File

@ -1,728 +0,0 @@
/*
* Copyright (C) 2013, 2014 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#define LIBVIRT_VIRDBUSPRIV_H_ALLOW
#include "virdbuspriv.h"
#include "virlog.h"
#include "testutils.h"
VIR_LOG_INIT("tests.dbustest");
#define VERIFY(typname, valorig, valnew, fmt) \
do { \
VIR_DEBUG("Compare " typname " '" fmt "' to '" \
fmt "'", valorig, valnew); \
if (valorig != valnew) { \
fprintf(stderr, "Failed to round-trip " typname " '" \
fmt "' to '" fmt "'\n", valorig, valnew); \
goto cleanup; \
} \
} while (0)
#define VERIFY_STR(typname, valorig, valnew, fmt) \
do { \
VIR_DEBUG("Compare " typname " '" fmt "' to '" \
fmt "'", valorig, valnew); \
if (STRNEQ(valorig, valnew)) { \
fprintf(stderr, "Failed to round-trip " typname " '" \
fmt "' to '" fmt "'\n", valorig, valnew); \
goto cleanup; \
} \
} while (0)
static int testMessageSimple(const void *args G_GNUC_UNUSED)
{
DBusMessage *msg = NULL;
int ret = -1;
unsigned char in_byte = 200, out_byte = 0;
bool in_bool = true, out_bool = false;
short in_int16 = 0xfefe, out_int16 = 0;
unsigned short in_uint16 = 32000, out_uint16 = 0;
int in_int32 = 100000000, out_int32 = 0;
unsigned int in_uint32 = 200000000, out_uint32 = 0;
long long in_int64 = 1000000000000LL, out_int64 = 0;
unsigned long long in_uint64 = 2000000000000LL, out_uint64 = 0;
double in_double = 3.14159265359, out_double = 0;
const char *in_string = "Hello World";
char *out_string = NULL;
const char *in_objectpath = "/org/libvirt/test";
char *out_objectpath = NULL;
const char *in_signature = "ybnqiuxtdsog";
char *out_signature = NULL;
if (!(msg = dbus_message_new_method_call("org.libvirt.test",
"/org/libvirt/test",
"org.libvirt.test.astrochicken",
"cluck"))) {
VIR_DEBUG("Failed to allocate method call");
goto cleanup;
}
if (virDBusMessageEncode(msg,
"ybnqiuxtdsog",
in_byte, in_bool,
in_int16, in_uint16,
in_int32, in_uint32,
in_int64, in_uint64,
in_double, in_string,
in_objectpath, in_signature) < 0) {
VIR_DEBUG("Failed to encode arguments");
goto cleanup;
}
if (virDBusMessageDecode(msg,
"ybnqiuxtdsog",
&out_byte, &out_bool,
&out_int16, &out_uint16,
&out_int32, &out_uint32,
&out_int64, &out_uint64,
&out_double, &out_string,
&out_objectpath, &out_signature) < 0) {
VIR_DEBUG("Failed to decode arguments");
goto cleanup;
}
VERIFY("byte", in_byte, out_byte, "%d");
VERIFY("bool", in_bool, out_bool, "%d");
VERIFY("int16", in_int16, out_int16, "%d");
VERIFY("uint16", in_int16, out_int16, "%d");
VERIFY("int32", in_int32, out_int32, "%d");
VERIFY("uint32", in_int32, out_int32, "%d");
VERIFY("int64", in_int64, out_int64, "%lld");
VERIFY("uint64", in_int64, out_int64, "%lld");
VERIFY("double", in_double, out_double, "%lf");
VERIFY_STR("string", in_string, out_string, "%s");
VERIFY_STR("objectpath", in_objectpath, out_objectpath, "%s");
VERIFY_STR("signature", in_signature, out_signature, "%s");
ret = 0;
cleanup:
VIR_FREE(out_string);
VIR_FREE(out_signature);
VIR_FREE(out_objectpath);
virDBusMessageUnref(msg);
return ret;
}
static int testMessageVariant(const void *args G_GNUC_UNUSED)
{
DBusMessage *msg = NULL;
int ret = -1;
const char *in_str1 = "Hello";
int in_int32 = 100000000, out_int32 = 0;
const char *in_str2 = "World";
char *out_str1 = NULL, *out_str2 = NULL;
if (!(msg = dbus_message_new_method_call("org.libvirt.test",
"/org/libvirt/test",
"org.libvirt.test.astrochicken",
"cluck"))) {
VIR_DEBUG("Failed to allocate method call");
goto cleanup;
}
if (virDBusMessageEncode(msg,
"svs",
in_str1,
"i", in_int32,
in_str2) < 0) {
VIR_DEBUG("Failed to encode arguments");
goto cleanup;
}
if (virDBusMessageDecode(msg,
"svs",
&out_str1,
"i", &out_int32,
&out_str2) < 0) {
VIR_DEBUG("Failed to decode arguments");
goto cleanup;
}
VERIFY_STR("str1", in_str1, out_str1, "%s");
VERIFY("int32", in_int32, out_int32, "%d");
VERIFY_STR("str2", in_str2, out_str2, "%s");
ret = 0;
cleanup:
VIR_FREE(out_str1);
VIR_FREE(out_str2);
virDBusMessageUnref(msg);
return ret;
}
static int testMessageArray(const void *args G_GNUC_UNUSED)
{
DBusMessage *msg = NULL;
int ret = -1;
const char *in_str1 = "Hello";
int in_int32a = 1000000000, out_int32a = 0;
int in_int32b = 2000000000, out_int32b = 0;
int in_int32c = -2000000000, out_int32c = 0;
bool in_bool[] = { true, false, true }, out_bool[] = { false, true, false};
const char *in_str2 = "World";
char *out_str1 = NULL, *out_str2 = NULL;
if (!(msg = dbus_message_new_method_call("org.libvirt.test",
"/org/libvirt/test",
"org.libvirt.test.astrochicken",
"cluck"))) {
VIR_DEBUG("Failed to allocate method call");
goto cleanup;
}
if (virDBusMessageEncode(msg,
"saiabs",
in_str1,
3, in_int32a, in_int32b, in_int32c,
3, in_bool[0], in_bool[1], in_bool[2],
in_str2) < 0) {
VIR_DEBUG("Failed to encode arguments");
goto cleanup;
}
if (virDBusMessageDecode(msg,
"saiabs",
&out_str1,
3, &out_int32a, &out_int32b, &out_int32c,
3, &out_bool[0], &out_bool[1], &out_bool[2],
&out_str2) < 0) {
VIR_DEBUG("Failed to decode arguments");
goto cleanup;
}
VERIFY_STR("str1", in_str1, out_str1, "%s");
VERIFY("int32a", in_int32a, out_int32a, "%d");
VERIFY("int32b", in_int32b, out_int32b, "%d");
VERIFY("int32c", in_int32c, out_int32c, "%d");
VERIFY("bool[0]", in_bool[0], out_bool[0], "%d");
VERIFY("bool[1]", in_bool[1], out_bool[1], "%d");
VERIFY("bool[2]", in_bool[2], out_bool[2], "%d");
VERIFY_STR("str2", in_str2, out_str2, "%s");
ret = 0;
cleanup:
VIR_FREE(out_str1);
VIR_FREE(out_str2);
virDBusMessageUnref(msg);
return ret;
}
static int testMessageEmptyArrayRef(const void *args G_GNUC_UNUSED)
{
DBusMessage *msg = NULL;
int ret = -1;
const char *in_strv1[] = {};
size_t out_nstrv1;
char **out_strv1 = NULL;
if (!(msg = dbus_message_new_method_call("org.libvirt.test",
"/org/libvirt/test",
"org.libvirt.test.astrochicken",
"cluck"))) {
VIR_DEBUG("Failed to allocate method call");
goto cleanup;
}
if (virDBusMessageEncode(msg,
"a&s",
0, in_strv1) < 0) {
VIR_DEBUG("Failed to encode arguments");
goto cleanup;
}
if (virDBusMessageDecode(msg,
"a&s",
&out_nstrv1, &out_strv1) < 0) {
VIR_DEBUG("Failed to decode arguments");
goto cleanup;
}
if (out_nstrv1 != 0) {
fprintf(stderr, "Expected 0 string, but got %zu\n",
out_nstrv1);
goto cleanup;
}
ret = 0;
cleanup:
virDBusMessageUnref(msg);
return ret;
}
static int testMessageSingleArrayRef(const void *args G_GNUC_UNUSED)
{
DBusMessage *msg = NULL;
int ret = -1;
const char *in_strv1[] = {
"Fishfood",
};
char **out_strv1 = NULL;
size_t out_nstrv1 = 0;
if (!(msg = dbus_message_new_method_call("org.libvirt.test",
"/org/libvirt/test",
"org.libvirt.test.astrochicken",
"cluck"))) {
VIR_DEBUG("Failed to allocate method call");
goto cleanup;
}
if (virDBusMessageEncode(msg,
"a&s",
1, in_strv1) < 0) {
VIR_DEBUG("Failed to encode arguments");
goto cleanup;
}
if (virDBusMessageDecode(msg,
"a&s",
&out_nstrv1, &out_strv1) < 0) {
VIR_DEBUG("Failed to decode arguments");
goto cleanup;
}
if (out_nstrv1 != 1) {
fprintf(stderr, "Expected 1 string, but got %zu\n",
out_nstrv1);
goto cleanup;
}
VERIFY_STR("strv1[0]", in_strv1[0], out_strv1[0], "%s");
ret = 0;
cleanup:
if (out_strv1)
VIR_FREE(out_strv1[0]);
VIR_FREE(out_strv1);
virDBusMessageUnref(msg);
return ret;
}
static int testMessageArrayRef(const void *args G_GNUC_UNUSED)
{
DBusMessage *msg = NULL;
int ret = -1;
const char *in_str1 = "Hello";
int in_int32[] = {
100000000, 2000000000, -2000000000
};
bool in_bool[] = { true, false, true };
const char *in_strv1[] = {
"Fishfood",
};
const char *in_strv2[] = {
"Hello", "World",
};
int *out_int32 = NULL;
size_t out_nint32 = 0;
bool *out_bool = NULL;
size_t out_nbool = 0;
char **out_strv1 = NULL;
char **out_strv2 = NULL;
size_t out_nstrv1 = 0;
size_t out_nstrv2 = 0;
const char *in_str2 = "World";
char *out_str1 = NULL, *out_str2 = NULL;
size_t i;
if (!(msg = dbus_message_new_method_call("org.libvirt.test",
"/org/libvirt/test",
"org.libvirt.test.astrochicken",
"cluck"))) {
VIR_DEBUG("Failed to allocate method call");
goto cleanup;
}
if (virDBusMessageEncode(msg,
"sa&sa&ia&ba&ss",
in_str1,
1, in_strv1,
3, in_int32,
3, in_bool,
2, in_strv2,
in_str2) < 0) {
VIR_DEBUG("Failed to encode arguments");
goto cleanup;
}
if (virDBusMessageDecode(msg,
"sa&sa&ia&ba&ss",
&out_str1,
&out_nstrv1, &out_strv1,
&out_nint32, &out_int32,
&out_nbool, &out_bool,
&out_nstrv2, &out_strv2,
&out_str2) < 0) {
VIR_DEBUG("Failed to decode arguments");
goto cleanup;
}
VERIFY_STR("str1", in_str1, out_str1, "%s");
if (out_nstrv1 != 1) {
fprintf(stderr, "Expected 1 string, but got %zu\n",
out_nstrv1);
goto cleanup;
}
VERIFY_STR("strv1[0]", in_strv1[0], out_strv1[0], "%s");
if (out_nint32 != 3) {
fprintf(stderr, "Expected 3 integers, but got %zu\n",
out_nint32);
goto cleanup;
}
VERIFY("int32a", in_int32[0], out_int32[0], "%d");
VERIFY("int32b", in_int32[1], out_int32[1], "%d");
VERIFY("int32c", in_int32[2], out_int32[2], "%d");
if (out_nbool != 3) {
fprintf(stderr, "Expected 3 bools, but got %zu\n",
out_nbool);
goto cleanup;
}
VERIFY("bool[0]", in_bool[0], out_bool[0], "%d");
VERIFY("bool[1]", in_bool[1], out_bool[1], "%d");
VERIFY("bool[2]", in_bool[2], out_bool[2], "%d");
if (out_nstrv2 != 2) {
fprintf(stderr, "Expected 2 strings, but got %zu\n",
out_nstrv2);
goto cleanup;
}
VERIFY_STR("strv2[0]", in_strv2[0], out_strv2[0], "%s");
VERIFY_STR("strv2[1]", in_strv2[1], out_strv2[1], "%s");
VERIFY_STR("str2", in_str2, out_str2, "%s");
ret = 0;
cleanup:
VIR_FREE(out_int32);
VIR_FREE(out_bool);
VIR_FREE(out_str1);
VIR_FREE(out_str2);
for (i = 0; i < out_nstrv1; i++)
VIR_FREE(out_strv1[i]);
VIR_FREE(out_strv1);
for (i = 0; i < out_nstrv2; i++)
VIR_FREE(out_strv2[i]);
VIR_FREE(out_strv2);
virDBusMessageUnref(msg);
return ret;
}
static int testMessageStruct(const void *args G_GNUC_UNUSED)
{
DBusMessage *msg = NULL;
int ret = -1;
unsigned char in_byte = 200, out_byte = 0;
bool in_bool = true, out_bool = false;
short in_int16 = 12000, out_int16 = 0;
unsigned short in_uint16 = 32000, out_uint16 = 0;
int in_int32 = 100000000, out_int32 = 0;
unsigned int in_uint32 = 200000000, out_uint32 = 0;
long long in_int64 = -1000000000000LL, out_int64 = 0;
unsigned long long in_uint64 = 2000000000000LL, out_uint64 = 0;
double in_double = 3.14159265359, out_double = 0;
const char *in_string = "Hello World";
char *out_string = NULL;
const char *in_objectpath = "/org/libvirt/test";
char *out_objectpath = NULL;
const char *in_signature = "ybnqiuxtdsog";
char *out_signature = NULL;
if (!(msg = dbus_message_new_method_call("org.libvirt.test",
"/org/libvirt/test",
"org.libvirt.test.astrochicken",
"cluck"))) {
VIR_DEBUG("Failed to allocate method call");
goto cleanup;
}
if (virDBusMessageEncode(msg,
"ybn(qiuxtds)og",
in_byte, in_bool,
in_int16, in_uint16,
in_int32, in_uint32,
in_int64, in_uint64,
in_double, in_string,
in_objectpath, in_signature) < 0) {
VIR_DEBUG("Failed to encode arguments");
goto cleanup;
}
if (virDBusMessageDecode(msg,
"ybn(qiuxtds)og",
&out_byte, &out_bool,
&out_int16, &out_uint16,
&out_int32, &out_uint32,
&out_int64, &out_uint64,
&out_double, &out_string,
&out_objectpath, &out_signature) < 0) {
VIR_DEBUG("Failed to decode arguments");
goto cleanup;
}
VERIFY("byte", in_byte, out_byte, "%d");
VERIFY("bool", in_bool, out_bool, "%d");
VERIFY("int16", in_int16, out_int16, "%d");
VERIFY("uint16", in_int16, out_int16, "%d");
VERIFY("int32", in_int32, out_int32, "%d");
VERIFY("uint32", in_int32, out_int32, "%d");
VERIFY("int64", in_int64, out_int64, "%lld");
VERIFY("uint64", in_int64, out_int64, "%lld");
VERIFY("double", in_double, out_double, "%lf");
VERIFY_STR("string", in_string, out_string, "%s");
VERIFY_STR("objectpath", in_objectpath, out_objectpath, "%s");
VERIFY_STR("signature", in_signature, out_signature, "%s");
ret = 0;
cleanup:
VIR_FREE(out_string);
VIR_FREE(out_signature);
VIR_FREE(out_objectpath);
virDBusMessageUnref(msg);
return ret;
}
static int testMessageDict(const void *args G_GNUC_UNUSED)
{
DBusMessage *msg = NULL;
int ret = -1;
const char *in_str1 = "Hello";
int in_int32a = 100000000, out_int32a = 0;
const char *in_key1 = "turnover";
int in_int32b = 200000000, out_int32b = 0;
const char *in_key2 = "revenue";
int in_int32c = 300000000, out_int32c = 0;
const char *in_key3 = "debt";
const char *in_str2 = "World";
char *out_str1 = NULL, *out_str2 = NULL;
char *out_key1 = NULL, *out_key2 = NULL, *out_key3 = NULL;
if (!(msg = dbus_message_new_method_call("org.libvirt.test",
"/org/libvirt/test",
"org.libvirt.test.astrochicken",
"cluck"))) {
VIR_DEBUG("Failed to allocate method call");
goto cleanup;
}
if (virDBusMessageEncode(msg,
"(sa{si}s)",
in_str1,
3,
in_key1, in_int32a,
in_key2, in_int32b,
in_key3, in_int32c,
in_str2) < 0) {
VIR_DEBUG("Failed to encode arguments");
goto cleanup;
}
if (virDBusMessageDecode(msg,
"(sa{si}s)",
&out_str1,
3,
&out_key1, &out_int32a,
&out_key2, &out_int32b,
&out_key3, &out_int32c,
&out_str2) < 0) {
VIR_DEBUG("Failed to decode arguments");
goto cleanup;
}
VERIFY_STR("str1", in_str1, out_str1, "%s");
VERIFY("int32a", in_int32a, out_int32a, "%d");
VERIFY("int32b", in_int32b, out_int32b, "%d");
VERIFY("int32c", in_int32c, out_int32c, "%d");
VERIFY_STR("key1", in_key1, out_key1, "%s");
VERIFY_STR("key1", in_key2, out_key2, "%s");
VERIFY_STR("key1", in_key3, out_key3, "%s");
VERIFY_STR("str2", in_str2, out_str2, "%s");
ret = 0;
cleanup:
VIR_FREE(out_str1);
VIR_FREE(out_str2);
VIR_FREE(out_key1);
VIR_FREE(out_key2);
VIR_FREE(out_key3);
virDBusMessageUnref(msg);
return ret;
}
static int testMessageDictRef(const void *args G_GNUC_UNUSED)
{
DBusMessage *msg = NULL;
int ret = -1;
const char *in_str1 = "Hello";
const char *in_strv1[] = {
"Fruit1", "Apple",
"Fruit2", "Orange",
"Fruit3", "Kiwi",
};
const char *in_str2 = "World";
char *out_str1 = NULL;
size_t out_nint32 = 0;
char **out_strv1 = NULL;
char *out_str2 = NULL;
if (!(msg = dbus_message_new_method_call("org.libvirt.test",
"/org/libvirt/test",
"org.libvirt.test.astrochicken",
"cluck"))) {
VIR_DEBUG("Failed to allocate method call");
goto cleanup;
}
if (virDBusMessageEncode(msg,
"(sa&{ss}s)",
in_str1,
3, in_strv1,
in_str2) < 0) {
VIR_DEBUG("Failed to encode arguments");
goto cleanup;
}
if (virDBusMessageDecode(msg,
"(sa&{ss}s)",
&out_str1,
&out_nint32,
&out_strv1,
&out_str2) < 0) {
VIR_DEBUG("Failed to decode arguments: '%s'", virGetLastErrorMessage());
goto cleanup;
}
VERIFY_STR("str1", in_str1, out_str1, "%s");
VERIFY_STR("strv1[0]", in_strv1[0], out_strv1[0], "%s");
VERIFY_STR("strv1[1]", in_strv1[1], out_strv1[1], "%s");
VERIFY_STR("strv1[2]", in_strv1[2], out_strv1[2], "%s");
VERIFY_STR("strv1[3]", in_strv1[3], out_strv1[3], "%s");
VERIFY_STR("strv1[4]", in_strv1[4], out_strv1[4], "%s");
VERIFY_STR("strv1[5]", in_strv1[5], out_strv1[5], "%s");
VERIFY_STR("str2", in_str2, out_str2, "%s");
ret = 0;
cleanup:
VIR_FREE(out_str1);
VIR_FREE(out_str2);
if (out_strv1) {
VIR_FREE(out_strv1[0]);
VIR_FREE(out_strv1[1]);
VIR_FREE(out_strv1[2]);
VIR_FREE(out_strv1[3]);
VIR_FREE(out_strv1[4]);
VIR_FREE(out_strv1[5]);
}
VIR_FREE(out_strv1);
virDBusMessageUnref(msg);
return ret;
}
static int testMessageEmptyDictRef(const void *args G_GNUC_UNUSED)
{
DBusMessage *msg = NULL;
int ret = -1;
const char *in_strv1[] = {};
size_t out_nint32 = 0;
char **out_strv1 = NULL;
if (!(msg = dbus_message_new_method_call("org.libvirt.test",
"/org/libvirt/test",
"org.libvirt.test.astrochicken",
"cluck"))) {
VIR_DEBUG("Failed to allocate method call");
goto cleanup;
}
if (virDBusMessageEncode(msg,
"a&{ss}",
0, in_strv1) < 0) {
VIR_DEBUG("Failed to encode arguments");
goto cleanup;
}
if (virDBusMessageDecode(msg,
"a&{ss}",
&out_nint32,
&out_strv1) < 0) {
VIR_DEBUG("Failed to decode arguments: '%s'", virGetLastErrorMessage());
goto cleanup;
}
if (out_nint32 != 0) {
fprintf(stderr, "Unexpected dict entries\n");
goto cleanup;
}
ret = 0;
cleanup:
virDBusMessageUnref(msg);
return ret;
}
static int
mymain(void)
{
int ret = 0;
if (virTestRun("Test message simple ", testMessageSimple, NULL) < 0)
ret = -1;
if (virTestRun("Test message variant ", testMessageVariant, NULL) < 0)
ret = -1;
if (virTestRun("Test message array ", testMessageArray, NULL) < 0)
ret = -1;
if (virTestRun("Test message array empty ref ", testMessageEmptyArrayRef, NULL) < 0)
ret = -1;
if (virTestRun("Test message array single ref ", testMessageSingleArrayRef, NULL) < 0)
ret = -1;
if (virTestRun("Test message array ref ", testMessageArrayRef, NULL) < 0)
ret = -1;
if (virTestRun("Test message struct ", testMessageStruct, NULL) < 0)
ret = -1;
if (virTestRun("Test message dict ", testMessageDict, NULL) < 0)
ret = -1;
if (virTestRun("Test message dict empty ref ", testMessageEmptyDictRef, NULL) < 0)
ret = -1;
if (virTestRun("Test message dict ref ", testMessageDictRef, NULL) < 0)
ret = -1;
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
VIR_TEST_MAIN(mymain)