mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
qemu: monitor: Remove HMP command (un)escaping infrastructure
We don't need to escape the commands any more since we use QMP passthrough, which means we can delete the functions. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
d6fc3b937b
commit
534daeef82
@ -197,99 +197,6 @@ VIR_ENUM_IMPL(qemuMonitorDumpStatus,
|
|||||||
"none", "active", "completed", "failed",
|
"none", "active", "completed", "failed",
|
||||||
);
|
);
|
||||||
|
|
||||||
char *
|
|
||||||
qemuMonitorEscapeArg(const char *in)
|
|
||||||
{
|
|
||||||
int len = 0;
|
|
||||||
size_t i, j;
|
|
||||||
char *out;
|
|
||||||
|
|
||||||
/* To pass through the QEMU monitor, we need to use escape
|
|
||||||
sequences: \r, \n, \", \\
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (i = 0; in[i] != '\0'; i++) {
|
|
||||||
switch (in[i]) {
|
|
||||||
case '\r':
|
|
||||||
case '\n':
|
|
||||||
case '"':
|
|
||||||
case '\\':
|
|
||||||
len += 2;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
len += 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_ALLOC_N(out, len + 1) < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
for (i = j = 0; in[i] != '\0'; i++) {
|
|
||||||
switch (in[i]) {
|
|
||||||
case '\r':
|
|
||||||
out[j++] = '\\';
|
|
||||||
out[j++] = 'r';
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
out[j++] = '\\';
|
|
||||||
out[j++] = 'n';
|
|
||||||
break;
|
|
||||||
case '"':
|
|
||||||
case '\\':
|
|
||||||
out[j++] = '\\';
|
|
||||||
out[j++] = in[i];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
out[j++] = in[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out[j] = '\0';
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char *
|
|
||||||
qemuMonitorUnescapeArg(const char *in)
|
|
||||||
{
|
|
||||||
size_t i, j;
|
|
||||||
char *out;
|
|
||||||
int len = strlen(in);
|
|
||||||
char next;
|
|
||||||
|
|
||||||
if (VIR_ALLOC_N(out, len + 1) < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
for (i = j = 0; i < len; ++i) {
|
|
||||||
next = in[i];
|
|
||||||
if (in[i] == '\\') {
|
|
||||||
++i;
|
|
||||||
switch (in[i]) {
|
|
||||||
case 'r':
|
|
||||||
next = '\r';
|
|
||||||
break;
|
|
||||||
case 'n':
|
|
||||||
next = '\n';
|
|
||||||
break;
|
|
||||||
case '"':
|
|
||||||
case '\\':
|
|
||||||
next = in[i];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* invalid input (including trailing '\' at end of in) */
|
|
||||||
VIR_FREE(out);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out[j++] = next;
|
|
||||||
}
|
|
||||||
out[j] = '\0';
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#if DEBUG_RAW_IO
|
#if DEBUG_RAW_IO
|
||||||
# include <c-ctype.h>
|
# include <c-ctype.h>
|
||||||
|
@ -382,9 +382,6 @@ struct _qemuMonitorCallbacks {
|
|||||||
qemuMonitorDomainRdmaGidStatusChangedCallback domainRdmaGidStatusChanged;
|
qemuMonitorDomainRdmaGidStatusChangedCallback domainRdmaGidStatusChanged;
|
||||||
};
|
};
|
||||||
|
|
||||||
char *qemuMonitorEscapeArg(const char *in);
|
|
||||||
char *qemuMonitorUnescapeArg(const char *in);
|
|
||||||
|
|
||||||
qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
|
qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
|
||||||
virDomainChrSourceDefPtr config,
|
virDomainChrSourceDefPtr config,
|
||||||
bool retry,
|
bool retry,
|
||||||
|
@ -187,7 +187,6 @@ int ATTRIBUTE_FMT_PRINTF(2, 3)
|
|||||||
qemuMonitorReportError(qemuMonitorTestPtr test, const char *errmsg, ...)
|
qemuMonitorReportError(qemuMonitorTestPtr test, const char *errmsg, ...)
|
||||||
{
|
{
|
||||||
va_list msgargs;
|
va_list msgargs;
|
||||||
VIR_AUTOFREE(char *) tmp = NULL;
|
|
||||||
VIR_AUTOFREE(char *) msg = NULL;
|
VIR_AUTOFREE(char *) msg = NULL;
|
||||||
VIR_AUTOFREE(char *) jsonmsg = NULL;
|
VIR_AUTOFREE(char *) jsonmsg = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -197,13 +196,10 @@ qemuMonitorReportError(qemuMonitorTestPtr test, const char *errmsg, ...)
|
|||||||
if (virVasprintf(&msg, errmsg, msgargs) < 0)
|
if (virVasprintf(&msg, errmsg, msgargs) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(tmp = qemuMonitorEscapeArg(msg)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virAsprintf(&jsonmsg, "{ \"error\": "
|
if (virAsprintf(&jsonmsg, "{ \"error\": "
|
||||||
" { \"desc\": \"%s\", "
|
" { \"desc\": \"%s\", "
|
||||||
" \"class\": \"UnexpectedCommand\" } }",
|
" \"class\": \"UnexpectedCommand\" } }",
|
||||||
tmp) < 0)
|
msg) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = qemuMonitorTestAddResponse(test, jsonmsg);
|
ret = qemuMonitorTestAddResponse(test, jsonmsg);
|
||||||
|
Loading…
Reference in New Issue
Block a user