]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Move qemuParseKeywords(Free) to the monitor code
authorPeter Krempa <pkrempa@redhat.com>
Mon, 17 Jun 2019 12:18:51 +0000 (14:18 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 20 Jun 2019 10:15:05 +0000 (12:15 +0200)
The only user is now in qemu_monitor_json.c to re-parse the command line
format into keyvalue pairs for use in QMP command construction.

Move and rename the functions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
po/POTFILES
src/qemu/Makefile.inc.am
src/qemu/qemu_monitor_json.c
src/qemu/qemu_parse_command.c [deleted file]
src/qemu/qemu_parse_command.h [deleted file]

index 9dd4ee7d9995c8bbe7944e469b0a96d8e15fcf7e..ccfc873a89f4bfa9e1e37fd5b9197f3d356e052b 100644 (file)
@@ -140,7 +140,6 @@ src/qemu/qemu_migration_params.c
 src/qemu/qemu_monitor.c
 src/qemu/qemu_monitor_json.c
 src/qemu/qemu_monitor_text.c
-src/qemu/qemu_parse_command.c
 src/qemu/qemu_process.c
 src/qemu/qemu_qapi.c
 src/remote/remote_client_bodies.h
index fd32a90d567714a6edec35dcd1c336822aab2e8f..254ba07dc0766ddbb2ea89916ab1e53fc75b1b54 100644 (file)
@@ -13,8 +13,6 @@ QEMU_DRIVER_SOURCES = \
        qemu/qemu_capabilities.h \
        qemu/qemu_command.c \
        qemu/qemu_command.h \
-       qemu/qemu_parse_command.c \
-       qemu/qemu_parse_command.h \
        qemu/qemu_domain.c \
        qemu/qemu_domain.h \
        qemu/qemu_domain_address.c \
index 96f44bc7604a93f2404651caf2763c35514a8b75..4eca75ecc96ba372c8f57cb1c2f106abf151ea91 100644 (file)
@@ -31,7 +31,6 @@
 #include "qemu_monitor_text.h"
 #include "qemu_monitor_json.h"
 #include "qemu_alias.h"
-#include "qemu_parse_command.h"
 #include "qemu_capabilities.h"
 #include "viralloc.h"
 #include "virlog.h"
@@ -555,6 +554,123 @@ qemuMonitorJSONMakeCommand(const char *cmdname,
 }
 
 
+static void
+qemuMonitorJSONParseKeywordsFree(int nkeywords,
+                                 char **keywords,
+                                 char **values)
+{
+    size_t i;
+    for (i = 0; i < nkeywords; i++) {
+        VIR_FREE(keywords[i]);
+        VIR_FREE(values[i]);
+    }
+    VIR_FREE(keywords);
+    VIR_FREE(values);
+}
+
+
+/*
+ * Takes a string containing a set of key=value,key=value,key...
+ * parameters and splits them up, returning two arrays with
+ * the individual keys and values. If allowEmptyValue is nonzero,
+ * the "=value" part is optional and if a key with no value is found,
+ * NULL is be placed into corresponding place in retvalues.
+ */
+static int
+qemuMonitorJSONParseKeywords(const char *str,
+                             char ***retkeywords,
+                             char ***retvalues,
+                             int *retnkeywords,
+                             int allowEmptyValue)
+{
+    int keywordCount = 0;
+    int keywordAlloc = 0;
+    char **keywords = NULL;
+    char **values = NULL;
+    const char *start = str;
+    const char *end;
+
+    *retkeywords = NULL;
+    *retvalues = NULL;
+    *retnkeywords = 0;
+    end = start + strlen(str);
+
+    while (start) {
+        const char *separator;
+        const char *endmark;
+        char *keyword;
+        char *value = NULL;
+
+        endmark = start;
+        do {
+            /* QEMU accepts ',,' as an escape for a literal comma;
+             * skip past those here while searching for the end of the
+             * value, then strip them down below */
+            endmark = strchr(endmark, ',');
+        } while (endmark && endmark[1] == ',' && (endmark += 2));
+        if (!endmark)
+            endmark = end;
+        if (!(separator = strchr(start, '=')))
+            separator = end;
+
+        if (separator >= endmark) {
+            if (!allowEmptyValue) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("malformed keyword arguments in '%s'"), str);
+                goto error;
+            }
+            separator = endmark;
+        }
+
+        if (VIR_STRNDUP(keyword, start, separator - start) < 0)
+            goto error;
+
+        if (separator < endmark) {
+            separator++;
+            if (VIR_STRNDUP(value, separator, endmark - separator) < 0) {
+                VIR_FREE(keyword);
+                goto error;
+            }
+            if (strchr(value, ',')) {
+                char *p = strchr(value, ',') + 1;
+                char *q = p + 1;
+                while (*q) {
+                    if (*q == ',')
+                        q++;
+                    *p++ = *q++;
+                }
+                *p = '\0';
+            }
+        }
+
+        if (keywordAlloc == keywordCount) {
+            if (VIR_REALLOC_N(keywords, keywordAlloc + 10) < 0 ||
+                VIR_REALLOC_N(values, keywordAlloc + 10) < 0) {
+                VIR_FREE(keyword);
+                VIR_FREE(value);
+                goto error;
+            }
+            keywordAlloc += 10;
+        }
+
+        keywords[keywordCount] = keyword;
+        values[keywordCount] = value;
+        keywordCount++;
+
+        start = endmark < end ? endmark + 1 : NULL;
+    }
+
+    *retkeywords = keywords;
+    *retvalues = values;
+    *retnkeywords = keywordCount;
+    return 0;
+
+ error:
+    qemuMonitorJSONParseKeywordsFree(keywordCount, keywords, values);
+    return -1;
+}
+
+
 static virJSONValuePtr
 qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeyword)
 {
@@ -567,7 +683,7 @@ qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeyword)
     if (!(ret = virJSONValueNewObject()))
         return NULL;
 
-    if (qemuParseKeywords(str, &keywords, &values, &nkeywords, 1) < 0)
+    if (qemuMonitorJSONParseKeywords(str, &keywords, &values, &nkeywords, 1) < 0)
         goto error;
 
     for (i = 0; i < nkeywords; i++) {
@@ -588,11 +704,11 @@ qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeyword)
         }
     }
 
-    qemuParseKeywordsFree(nkeywords, keywords, values);
+    qemuMonitorJSONParseKeywordsFree(nkeywords, keywords, values);
     return ret;
 
  error:
-    qemuParseKeywordsFree(nkeywords, keywords, values);
+    qemuMonitorJSONParseKeywordsFree(nkeywords, keywords, values);
     virJSONValueFree(ret);
     return NULL;
 }
diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c
deleted file mode 100644 (file)
index b49aa92..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * qemu_parse_command.c: QEMU command parser
- *
- * Copyright (C) 2006-2016 Red Hat, Inc.
- * Copyright (C) 2006 Daniel P. Berrange
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library.  If not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#include <config.h>
-
-#include "qemu_parse_command.h"
-#include "viralloc.h"
-#include "virlog.h"
-#include "virstring.h"
-#include "virerror.h"
-
-#define VIR_FROM_THIS VIR_FROM_QEMU
-
-VIR_LOG_INIT("qemu.qemu_parse_command");
-
-
-void
-qemuParseKeywordsFree(int nkeywords,
-                      char **keywords,
-                      char **values)
-{
-    size_t i;
-    for (i = 0; i < nkeywords; i++) {
-        VIR_FREE(keywords[i]);
-        VIR_FREE(values[i]);
-    }
-    VIR_FREE(keywords);
-    VIR_FREE(values);
-}
-
-
-/*
- * Takes a string containing a set of key=value,key=value,key...
- * parameters and splits them up, returning two arrays with
- * the individual keys and values. If allowEmptyValue is nonzero,
- * the "=value" part is optional and if a key with no value is found,
- * NULL is be placed into corresponding place in retvalues.
- */
-int
-qemuParseKeywords(const char *str,
-                  char ***retkeywords,
-                  char ***retvalues,
-                  int *retnkeywords,
-                  int allowEmptyValue)
-{
-    int keywordCount = 0;
-    int keywordAlloc = 0;
-    char **keywords = NULL;
-    char **values = NULL;
-    const char *start = str;
-    const char *end;
-
-    *retkeywords = NULL;
-    *retvalues = NULL;
-    *retnkeywords = 0;
-    end = start + strlen(str);
-
-    while (start) {
-        const char *separator;
-        const char *endmark;
-        char *keyword;
-        char *value = NULL;
-
-        endmark = start;
-        do {
-            /* QEMU accepts ',,' as an escape for a literal comma;
-             * skip past those here while searching for the end of the
-             * value, then strip them down below */
-            endmark = strchr(endmark, ',');
-        } while (endmark && endmark[1] == ',' && (endmark += 2));
-        if (!endmark)
-            endmark = end;
-        if (!(separator = strchr(start, '=')))
-            separator = end;
-
-        if (separator >= endmark) {
-            if (!allowEmptyValue) {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("malformed keyword arguments in '%s'"), str);
-                goto error;
-            }
-            separator = endmark;
-        }
-
-        if (VIR_STRNDUP(keyword, start, separator - start) < 0)
-            goto error;
-
-        if (separator < endmark) {
-            separator++;
-            if (VIR_STRNDUP(value, separator, endmark - separator) < 0) {
-                VIR_FREE(keyword);
-                goto error;
-            }
-            if (strchr(value, ',')) {
-                char *p = strchr(value, ',') + 1;
-                char *q = p + 1;
-                while (*q) {
-                    if (*q == ',')
-                        q++;
-                    *p++ = *q++;
-                }
-                *p = '\0';
-            }
-        }
-
-        if (keywordAlloc == keywordCount) {
-            if (VIR_REALLOC_N(keywords, keywordAlloc + 10) < 0 ||
-                VIR_REALLOC_N(values, keywordAlloc + 10) < 0) {
-                VIR_FREE(keyword);
-                VIR_FREE(value);
-                goto error;
-            }
-            keywordAlloc += 10;
-        }
-
-        keywords[keywordCount] = keyword;
-        values[keywordCount] = value;
-        keywordCount++;
-
-        start = endmark < end ? endmark + 1 : NULL;
-    }
-
-    *retkeywords = keywords;
-    *retvalues = values;
-    *retnkeywords = keywordCount;
-    return 0;
-
- error:
-    qemuParseKeywordsFree(keywordCount, keywords, values);
-    return -1;
-}
diff --git a/src/qemu/qemu_parse_command.h b/src/qemu/qemu_parse_command.h
deleted file mode 100644 (file)
index 269bf88..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * qemu_parse_command.h: QEMU command parser
- *
- * Copyright (C) 2006-2016 Red Hat, Inc.
- * Copyright (C) 2006 Daniel P. Berrange
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library.  If not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-void
-qemuParseKeywordsFree(int nkeywords,
-                     char **keywords,
-                     char **values);
-
-int
-qemuParseKeywords(const char *str,
-                  char ***retkeywords,
-                  char ***retvalues,
-                  int *retnkeywords,
-                  int allowEmptyValue);