diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2017-03-07 17:06:48 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2017-03-07 17:06:48 +0000 |
commit | 87467097f8811258cd91d42c141a7bd8492ed08a (patch) | |
tree | 4c9f130fca163f66038c12af9b3416860bad6338 /qapi/qapi-util.c | |
parent | 43c227f9dd7945bb4a895f841ecdb957bd8a12da (diff) | |
parent | 0b2c1beea4358e40d1049b8ee019408ce96b37ce (diff) | |
download | qemu-87467097f8811258cd91d42c141a7bd8492ed08a.zip qemu-87467097f8811258cd91d42c141a7bd8492ed08a.tar.gz qemu-87467097f8811258cd91d42c141a7bd8492ed08a.tar.bz2 |
Merge remote-tracking branch 'remotes/armbru/tags/pull-block-2017-02-28-v4' into staging
block: Command line option -blockdev
# gpg: Signature made Tue 07 Mar 2017 15:07:59 GMT
# gpg: using RSA key 0x3870B400EB918653
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>"
# gpg: aka "Markus Armbruster <armbru@pond.sub.org>"
# Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653
* remotes/armbru/tags/pull-block-2017-02-28-v4: (24 commits)
keyval: Support lists
docs/qapi-code-gen.txt: Clarify naming rules
qapi: Improve how keyval input visitor reports unexpected dicts
block: Initial implementation of -blockdev
qapi: New qobject_input_visitor_new_str() for convenience
keyval: Restrict key components to valid QAPI names
qapi: New parse_qapi_name()
test-qapi-util: New, covering qapi/qapi-util.c
monitor: Assert qmp_schema_json[] is sane
test-visitor-serialization: Pass &error_abort to qobject_from_json()
check-qjson: Test errors from qobject_from_json()
block: More detailed syntax error reporting for JSON filenames
qobject: Propagate parse errors through qobject_from_json()
test-qobject-input-visitor: Abort earlier on bad test input
qjson: Abort earlier on qobject_from_jsonf() misuse
libqtest: Fix qmp() & friends to abort on JSON parse errors
qobject: Propagate parse errors through qobject_from_jsonv()
qapi: Factor out common qobject_input_get_keyval()
qapi: Factor out common part of qobject input visitor creation
test-keyval: Cover use with qobject input visitor
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'qapi/qapi-util.c')
-rw-r--r-- | qapi/qapi-util.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c index 818730a..e28dbd0 100644 --- a/qapi/qapi-util.c +++ b/qapi/qapi-util.c @@ -33,3 +33,50 @@ int qapi_enum_parse(const char * const lookup[], const char *buf, error_setg(errp, "invalid parameter value: %s", buf); return def; } + +/* + * Parse a valid QAPI name from @str. + * A valid name consists of letters, digits, hyphen and underscore. + * It may be prefixed by __RFQDN_ (downstream extension), where RFQDN + * may contain only letters, digits, hyphen and period. + * The special exception for enumeration names is not implemented. + * See docs/qapi-code-gen.txt for more on QAPI naming rules. + * Keep this consistent with scripts/qapi.py! + * If @complete, the parse fails unless it consumes @str completely. + * Return its length on success, -1 on failure. + */ +int parse_qapi_name(const char *str, bool complete) +{ + const char *p = str; + + if (*p == '_') { /* Downstream __RFQDN_ */ + p++; + if (*p != '_') { + return -1; + } + while (*++p) { + if (!qemu_isalnum(*p) && *p != '-' && *p != '.') { + break; + } + } + + if (*p != '_') { + return -1; + } + p++; + } + + if (!qemu_isalpha(*p)) { + return -1; + } + while (*++p) { + if (!qemu_isalnum(*p) && *p != '-' && *p != '_') { + break; + } + } + + if (complete && *p) { + return -1; + } + return p - str; +} |