The qemuMonitorEscape() method, and the VIR_ENUM for migration
status will be needed by the JSON monitor too, so move that code
into the shared qemu_monitor.c file instead of qemu_monitor_text.c

* src/qemu/qemu_monitor.h: Declare qemuMonitorMigrationStatus enum
  and qemuMonitorEscapeArg and qemuMonitorEscapeShell methods
* src/qemu/qemu_monitor.c: Implement qemuMonitorMigrationStatus enum
  and qemuMonitorEscapeArg and qemuMonitorEscapeShell methods
* src/qemu/qemu_monitor_text.c: Remove above methods/enum
---
 src/qemu/qemu_monitor.c      |   87 ++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor.h      |    5 ++
 src/qemu/qemu_monitor_text.c |   87 ------------------------------------------
 3 files changed, 92 insertions(+), 87 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 3829e7a..21f8c4b 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -77,6 +77,93 @@ struct _qemuMonitor {
 };
 
 
+VIR_ENUM_IMPL(qemuMonitorMigrationStatus,
+              QEMU_MONITOR_MIGRATION_STATUS_LAST,
+              "inactive", "active", "completed", "failed", "cancelled")
+
+static char *qemuMonitorEscape(const char *in, int shell)
+{
+    int len = 0;
+    int i, j;
+    char *out;
+
+    /* To pass through the QEMU monitor, we need to use escape
+       sequences: \r, \n, \", \\
+
+       To pass through both QEMU + the shell, we need to escape
+       the single character ' as the five characters '\\''
+    */
+
+    for (i = 0; in[i] != '\0'; i++) {
+        switch(in[i]) {
+        case '\r':
+        case '\n':
+        case '"':
+        case '\\':
+            len += 2;
+            break;
+        case '\'':
+            if (shell)
+                len += 5;
+            else
+                len += 1;
+            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;
+        case '\'':
+            if (shell) {
+                out[j++] = '\'';
+                out[j++] = '\\';
+                out[j++] = '\\';
+                out[j++] = '\'';
+                out[j++] = '\'';
+            } else {
+                out[j++] = in[i];
+            }
+            break;
+        default:
+            out[j++] = in[i];
+            break;
+        }
+    }
+    out[j] = '\0';
+
+    return out;
+}
+
+char *qemuMonitorEscapeArg(const char *in)
+{
+    return qemuMonitorEscape(in, 0);
+}
+
+char *qemuMonitorEscapeShell(const char *in)
+{
+    return qemuMonitorEscape(in, 1);
+}
+
+
 void qemuMonitorLock(qemuMonitorPtr mon)
 {
     virMutexLock(&mon->lock);
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 27b43b7..88d3dd7 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -75,6 +75,9 @@ typedef int (*qemuMonitorDiskSecretLookup)(qemuMonitorPtr mon,
                                            char **secret,
                                            size_t *secretLen);
 
+char *qemuMonitorEscapeArg(const char *in);
+char *qemuMonitorEscapeShell(const char *in);
+
 qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
                                qemuMonitorEOFNotify eofCB);
 
@@ -158,6 +161,8 @@ enum {
     QEMU_MONITOR_MIGRATION_STATUS_LAST
 };
 
+VIR_ENUM_DECL(qemuMonitorMigrationStatus)
+
 int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
                                   int *status,
                                   unsigned long long *transferred,
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index d39a417..2a8b3bd 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -51,88 +51,6 @@ typedef int qemuMonitorExtraPromptHandler(qemuMonitorPtr mon,
                                           void *data);
 
 
-static char *qemuMonitorEscape(const char *in, int shell)
-{
-    int len = 0;
-    int i, j;
-    char *out;
-
-    /* To pass through the QEMU monitor, we need to use escape
-       sequences: \r, \n, \", \\
-
-       To pass through both QEMU + the shell, we need to escape
-       the single character ' as the five characters '\\''
-    */
-
-    for (i = 0; in[i] != '\0'; i++) {
-        switch(in[i]) {
-        case '\r':
-        case '\n':
-        case '"':
-        case '\\':
-            len += 2;
-            break;
-        case '\'':
-            if (shell)
-                len += 5;
-            else
-                len += 1;
-            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;
-        case '\'':
-            if (shell) {
-                out[j++] = '\'';
-                out[j++] = '\\';
-                out[j++] = '\\';
-                out[j++] = '\'';
-                out[j++] = '\'';
-            } else {
-                out[j++] = in[i];
-            }
-            break;
-        default:
-            out[j++] = in[i];
-            break;
-        }
-    }
-    out[j] = '\0';
-
-    return out;
-}
-
-static char *qemuMonitorEscapeArg(const char *in)
-{
-    return qemuMonitorEscape(in, 0);
-}
-
-static char *qemuMonitorEscapeShell(const char *in)
-{
-    return qemuMonitorEscape(in, 1);
-}
-
 /* When connecting to a monitor, QEMU will print a greeting like
  *
  * QEMU 0.11.0 monitor - type 'help' for more information
@@ -904,11 +822,6 @@ cleanup:
 #define MIGRATION_REMAINING_PREFIX "remaining ram: "
 #define MIGRATION_TOTAL_PREFIX "total ram: "
 
-VIR_ENUM_DECL(qemuMonitorMigrationStatus)
-VIR_ENUM_IMPL(qemuMonitorMigrationStatus,
-              QEMU_MONITOR_MIGRATION_STATUS_LAST,
-              "inactive", "active", "completed", "failed", "cancelled")
-
 int qemuMonitorTextGetMigrationStatus(qemuMonitorPtr mon,
                                       int *status,
                                       unsigned long long *transferred,
-- 
1.6.5.2

--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to