aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2017-08-24 10:46:00 +0200
committerMarkus Armbruster <armbru@redhat.com>2017-09-04 13:09:13 +0200
commit8e615e34f9f5dc0ee3a39a468ec96ea537c4afe9 (patch)
treed6a660d2ee9dae8c04e5f9b6a7e75cfca9b0356c
parent00bbf50a50e6d6e1a4542db1c1205291395c4105 (diff)
hmp: Use qapi_enum_parse() in hmp_migrate_set_capability()
The error message on invalid capability name changes from Invalid parameter "NAME" to invalid parameter value: NAME No worse than before. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20170822132255.23945-9-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Rebased, commit message rewritten] Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <1503564371-26090-6-git-send-email-armbru@redhat.com>
-rw-r--r--hmp.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/hmp.c b/hmp.c
index 03c1a783b6..7e0bd3d63b 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1527,23 +1527,20 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
bool state = qdict_get_bool(qdict, "state");
Error *err = NULL;
MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
- int i;
+ int val;
- for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
- if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
- caps->value = g_malloc0(sizeof(*caps->value));
- caps->value->capability = i;
- caps->value->state = state;
- caps->next = NULL;
- qmp_migrate_set_capabilities(caps, &err);
- break;
- }
+ val = qapi_enum_parse(MigrationCapability_lookup, cap, -1, &err);
+ if (val < 0) {
+ goto end;
}
- if (i == MIGRATION_CAPABILITY__MAX) {
- error_setg(&err, QERR_INVALID_PARAMETER, cap);
- }
+ caps->value = g_malloc0(sizeof(*caps->value));
+ caps->value->capability = val;
+ caps->value->state = state;
+ caps->next = NULL;
+ qmp_migrate_set_capabilities(caps, &err);
+end:
qapi_free_MigrationCapabilityStatusList(caps);
if (err) {