mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
util: eliminate duplicate function virDBusMessageRead
When virDBusMessageRead() and virDBusMessageDecode were first added in commit834c9c94
, they were identical except that virDBusMessageRead() would unref the message after decoding it. This difference was eliminated later in commitdc7f3ffc
after it became apparent that unref-ing the message so soon was never the right thing to do. The two identical functions remained though, with the tests and virDBus library itself calling the Decode variant, and all other users calling the Read variant. This patch eliminates the duplication, switching all users to virDBusMessageDecode (and moving the nice API documentation comment from the Read function up to the Decode function). Signed-off-by: Laine Stump <laine@laine.org> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
4683a609f6
commit
687f556750
@ -1750,7 +1750,6 @@ virDBusGetSystemBus;
|
|||||||
virDBusHasSystemBus;
|
virDBusHasSystemBus;
|
||||||
virDBusMessageDecode;
|
virDBusMessageDecode;
|
||||||
virDBusMessageEncode;
|
virDBusMessageEncode;
|
||||||
virDBusMessageRead;
|
|
||||||
virDBusMessageUnref;
|
virDBusMessageUnref;
|
||||||
virDBusSetSharedBus;
|
virDBusSetSharedBus;
|
||||||
|
|
||||||
|
@ -1228,9 +1228,23 @@ int virDBusMessageEncode(DBusMessage* msg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int virDBusMessageDecode(DBusMessage* msg,
|
/**
|
||||||
const char *types,
|
* virDBusMessageDecode:
|
||||||
...)
|
* @msg: the reply to decode
|
||||||
|
* @types: type signature for following return values
|
||||||
|
* @...: pointers in which to store return values
|
||||||
|
*
|
||||||
|
* The @types type signature is the same format as
|
||||||
|
* that used for the virDBusCallMethod. The difference
|
||||||
|
* is that each variadic parameter must be a pointer to
|
||||||
|
* be filled with the values. eg instead of passing an
|
||||||
|
* 'int', pass an 'int *'.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virDBusMessageDecode(DBusMessage* msg,
|
||||||
|
const char *types,
|
||||||
|
...)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -1654,32 +1668,6 @@ int virDBusCallMethod(DBusConnection *conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* virDBusMessageRead:
|
|
||||||
* @msg: the reply to decode
|
|
||||||
* @types: type signature for following return values
|
|
||||||
* @...: pointers in which to store return values
|
|
||||||
*
|
|
||||||
* The @types type signature is the same format as
|
|
||||||
* that used for the virDBusCallMethod. The difference
|
|
||||||
* is that each variadic parameter must be a pointer to
|
|
||||||
* be filled with the values. eg instead of passing an
|
|
||||||
* 'int', pass an 'int *'.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int virDBusMessageRead(DBusMessage *msg,
|
|
||||||
const char *types, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
va_start(args, types);
|
|
||||||
ret = virDBusMessageDecodeArgs(msg, types, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int virDBusIsServiceInList(const char *listMethod, const char *name)
|
static int virDBusIsServiceInList(const char *listMethod, const char *name)
|
||||||
{
|
{
|
||||||
DBusConnection *conn;
|
DBusConnection *conn;
|
||||||
@ -1854,13 +1842,6 @@ int virDBusCallMethod(DBusConnection *conn ATTRIBUTE_UNUSED,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int virDBusMessageRead(DBusMessage *msg ATTRIBUTE_UNUSED,
|
|
||||||
const char *types ATTRIBUTE_UNUSED, ...)
|
|
||||||
{
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"%s", _("DBus support not compiled into this binary"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int virDBusMessageEncode(DBusMessage* msg ATTRIBUTE_UNUSED,
|
int virDBusMessageEncode(DBusMessage* msg ATTRIBUTE_UNUSED,
|
||||||
const char *types ATTRIBUTE_UNUSED,
|
const char *types ATTRIBUTE_UNUSED,
|
||||||
|
@ -67,8 +67,8 @@ int virDBusCallMethod(DBusConnection *conn,
|
|||||||
const char *iface,
|
const char *iface,
|
||||||
const char *member,
|
const char *member,
|
||||||
const char *types, ...);
|
const char *types, ...);
|
||||||
int virDBusMessageRead(DBusMessage *msg,
|
int virDBusMessageDecode(DBusMessage *msg,
|
||||||
const char *types, ...);
|
const char *types, ...);
|
||||||
void virDBusMessageUnref(DBusMessage *msg);
|
void virDBusMessageUnref(DBusMessage *msg);
|
||||||
|
|
||||||
int virDBusIsServiceEnabled(const char *name);
|
int virDBusIsServiceEnabled(const char *name);
|
||||||
|
@ -56,8 +56,4 @@ int virDBusMessageEncode(DBusMessage* msg,
|
|||||||
const char *types,
|
const char *types,
|
||||||
...);
|
...);
|
||||||
|
|
||||||
int virDBusMessageDecode(DBusMessage* msg,
|
|
||||||
const char *types,
|
|
||||||
...);
|
|
||||||
|
|
||||||
#endif /* LIBVIRT_VIRDBUSPRIV_H */
|
#endif /* LIBVIRT_VIRDBUSPRIV_H */
|
||||||
|
@ -102,7 +102,7 @@ virFirewallDGetVersion(unsigned long *version)
|
|||||||
"version") < 0)
|
"version") < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDBusMessageRead(reply, "v", "s", &versionStr) < 0)
|
if (virDBusMessageDecode(reply, "v", "s", &versionStr) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virParseVersionString(versionStr, version, false) < 0) {
|
if (virParseVersionString(versionStr, version, false) < 0) {
|
||||||
@ -163,7 +163,7 @@ virFirewallDGetBackend(void)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virDBusMessageRead(reply, "v", "s", &backendStr) < 0)
|
if (virDBusMessageDecode(reply, "v", "s", &backendStr) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("FirewallD backend: %s", backendStr);
|
VIR_DEBUG("FirewallD backend: %s", backendStr);
|
||||||
@ -216,7 +216,7 @@ virFirewallDGetZones(char ***zones, size_t *nzones)
|
|||||||
NULL) < 0)
|
NULL) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDBusMessageRead(reply, "a&s", nzones, zones) < 0)
|
if (virDBusMessageDecode(reply, "a&s", nzones, zones) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -337,7 +337,7 @@ virFirewallDApplyRule(virFirewallLayer layer,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (virDBusMessageRead(reply, "s", output) < 0)
|
if (virDBusMessageDecode(reply, "s", output) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,12 +97,12 @@ int virPolkitCheckAuth(const char *actionid,
|
|||||||
"" /* cancellation ID */) < 0)
|
"" /* cancellation ID */) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDBusMessageRead(reply,
|
if (virDBusMessageDecode(reply,
|
||||||
"(bba&{ss})",
|
"(bba&{ss})",
|
||||||
&is_authorized,
|
&is_authorized,
|
||||||
&is_challenge,
|
&is_challenge,
|
||||||
&nretdetails,
|
&nretdetails,
|
||||||
&retdetails) < 0)
|
&retdetails) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0; i < (nretdetails / 2); i++) {
|
for (i = 0; i < (nretdetails / 2); i++) {
|
||||||
|
@ -182,7 +182,7 @@ virSystemdGetMachineNameByPID(pid_t pid)
|
|||||||
"u", pid) < 0)
|
"u", pid) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDBusMessageRead(reply, "o", &object) < 0)
|
if (virDBusMessageDecode(reply, "o", &object) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
virDBusMessageUnref(reply);
|
virDBusMessageUnref(reply);
|
||||||
@ -201,7 +201,7 @@ virSystemdGetMachineNameByPID(pid_t pid)
|
|||||||
"Name") < 0)
|
"Name") < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDBusMessageRead(reply, "v", "s", &name) < 0)
|
if (virDBusMessageDecode(reply, "v", "s", &name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Domain with pid %lld has machine name '%s'",
|
VIR_DEBUG("Domain with pid %lld has machine name '%s'",
|
||||||
@ -533,7 +533,7 @@ virSystemdPMSupportTarget(const char *methodName, bool *result)
|
|||||||
NULL) < 0)
|
NULL) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if ((ret = virDBusMessageRead(message, "s", &response)) < 0)
|
if ((ret = virDBusMessageDecode(message, "s", &response)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
*result = STREQ("yes", response) || STREQ("challenge", response);
|
*result = STREQ("yes", response) || STREQ("challenge", response);
|
||||||
|
@ -72,18 +72,18 @@ VIR_MOCK_WRAP_RET_ARGS(dbus_connection_send_with_reply_and_block,
|
|||||||
int is_authorized = 1;
|
int is_authorized = 1;
|
||||||
int is_challenge = 0;
|
int is_challenge = 0;
|
||||||
|
|
||||||
if (virDBusMessageRead(message,
|
if (virDBusMessageDecode(message,
|
||||||
"(sa{sv})sa&{ss}us",
|
"(sa{sv})sa&{ss}us",
|
||||||
&type,
|
&type,
|
||||||
3,
|
3,
|
||||||
&pidkey, "u", &pidval,
|
&pidkey, "u", &pidval,
|
||||||
&timekey, "t", &timeval,
|
&timekey, "t", &timeval,
|
||||||
&uidkey, "i", &uidval,
|
&uidkey, "i", &uidval,
|
||||||
&actionid,
|
&actionid,
|
||||||
&detailslen,
|
&detailslen,
|
||||||
&details,
|
&details,
|
||||||
&allowInteraction,
|
&allowInteraction,
|
||||||
&cancellationId) < 0)
|
&cancellationId) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (STREQ(actionid, "org.libvirt.test.success")) {
|
if (STREQ(actionid, "org.libvirt.test.success")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user