qapi: Generalize struct member policy checking
The generated visitor functions call visit_deprecated_accept() and
visit_deprecated() when visiting a struct member with special feature
flag 'deprecated'. This makes the feature flag visible to the actual
visitors. I want to make feature flag 'unstable' visible there as
well, so I can add policy for it.
To let me make it visible, replace these functions by
visit_policy_reject() and visit_policy_skip(), which take the member's
special features as an argument. Note that the new functions have the
opposite sense, i.e. the return value flips.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20211028102520.747396-6-armbru@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
[Unbreak forward visitor]
diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
index 71b24a4..c120dbd 100644
--- a/qapi/qobject-input-visitor.c
+++ b/qapi/qobject-input-visitor.c
@@ -662,16 +662,21 @@
*present = true;
}
-static bool qobject_input_deprecated_accept(Visitor *v, const char *name,
- Error **errp)
+static bool qobject_input_policy_reject(Visitor *v, const char *name,
+ unsigned special_features,
+ Error **errp)
{
+ if (!(special_features & 1u << QAPI_DEPRECATED)) {
+ return false;
+ }
+
switch (v->compat_policy.deprecated_input) {
case COMPAT_POLICY_INPUT_ACCEPT:
- return true;
+ return false;
case COMPAT_POLICY_INPUT_REJECT:
error_setg(errp, "Deprecated parameter '%s' disabled by policy",
name);
- return false;
+ return true;
case COMPAT_POLICY_INPUT_CRASH:
default:
abort();
@@ -712,7 +717,7 @@
v->visitor.end_list = qobject_input_end_list;
v->visitor.start_alternate = qobject_input_start_alternate;
v->visitor.optional = qobject_input_optional;
- v->visitor.deprecated_accept = qobject_input_deprecated_accept;
+ v->visitor.policy_reject = qobject_input_policy_reject;
v->visitor.free = qobject_input_free;
v->root = qobject_ref(obj);