char: refactor parsing of socket address information
To prepare for handling more address types, refactor the parsing of socket address information to make it more robust and extensible. Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
1723d6b1cf
commit
9bb4060c99
@ -1012,21 +1012,25 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
|
||||
SocketAddressLegacy *addr;
|
||||
ChardevSocket *sock;
|
||||
|
||||
if ((!!path + !!host) != 1) {
|
||||
error_setg(errp,
|
||||
"Exactly one of 'path' or 'host' required");
|
||||
return;
|
||||
}
|
||||
|
||||
backend->type = CHARDEV_BACKEND_KIND_SOCKET;
|
||||
if (!path) {
|
||||
if (!host) {
|
||||
error_setg(errp, "chardev: socket: no host given");
|
||||
if (path) {
|
||||
if (tls_creds) {
|
||||
error_setg(errp, "TLS can only be used over TCP socket");
|
||||
return;
|
||||
}
|
||||
} else if (host) {
|
||||
if (!port) {
|
||||
error_setg(errp, "chardev: socket: no port given");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (tls_creds) {
|
||||
error_setg(errp, "TLS can only be used over TCP socket");
|
||||
return;
|
||||
}
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
sock = backend->u.socket.data = g_new0(ChardevSocket, 1);
|
||||
@ -1052,7 +1056,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
|
||||
addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
|
||||
q_unix = addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
|
||||
q_unix->path = g_strdup(path);
|
||||
} else {
|
||||
} else if (host) {
|
||||
addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
|
||||
addr->u.inet.data = g_new(InetSocketAddress, 1);
|
||||
*addr->u.inet.data = (InetSocketAddress) {
|
||||
@ -1065,6 +1069,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
|
||||
.has_ipv6 = qemu_opt_get(opts, "ipv6"),
|
||||
.ipv6 = qemu_opt_get_bool(opts, "ipv6", 0),
|
||||
};
|
||||
} else {
|
||||
g_assert_not_reached();
|
||||
}
|
||||
sock->addr = addr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user