[PATCH] introduce virConfReadString

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rewrite virConfReadMem to take a null-terminated string.
All the callers were calling strlen on it anyway.
---
 daemon/libvirtd-config.c |  2 +-
 src/libvirt_private.syms |  2 +-
 src/libxl/libxl_driver.c |  4 ++--
 src/lxc/lxc_native.c     |  2 +-
 src/util/virconf.c       | 16 ++++++++--------
 src/util/virconf.h       |  4 ++--
 src/vmx/vmx.c            |  4 ++--
 src/xen/xen_driver.c     |  2 +-
 tests/virconftest.c      |  8 ++++----
 tests/xlconfigtest.c     |  2 +-
 tests/xmconfigtest.c     |  2 +-
 11 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c
index 6c0f00ed8..db283a41f 100644
--- a/daemon/libvirtd-config.c
+++ b/daemon/libvirtd-config.c
@@ -433,7 +433,7 @@ int daemonConfigLoadData(struct daemonConfig *data,
     virConfPtr conf;
     int ret;
 
-    conf = virConfReadMem(filedata, strlen(filedata), 0);
+    conf = virConfReadString(filedata, 0);
     if (!conf)
         return -1;
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 32ac0835e..183a9194d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1520,7 +1520,7 @@ virConfGetValueULLong;
 virConfLoadConfig;
 virConfNew;
 virConfReadFile;
-virConfReadMem;
+virConfReadString;
 virConfSetValue;
 virConfTypeFromString;
 virConfTypeToString;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 907f1776f..c261e2155 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2605,14 +2605,14 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn,
         goto cleanup;
 
     if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) {
-        if (!(conf = virConfReadMem(nativeConfig, strlen(nativeConfig), 0)))
+        if (!(conf = virConfReadString(nativeConfig, 0)))
             goto cleanup;
         if (!(def = xenParseXL(conf,
                                cfg->caps,
                                driver->xmlopt)))
             goto cleanup;
     } else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) {
-        if (!(conf = virConfReadMem(nativeConfig, strlen(nativeConfig), 0)))
+        if (!(conf = virConfReadString(nativeConfig, 0)))
             goto cleanup;
 
         if (!(def = xenParseXM(conf,
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 7bcdf1fb0..5fc6e7cda 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -1000,7 +1000,7 @@ lxcParseConfigString(const char *config,
     virConfPtr properties = NULL;
     virConfValuePtr value;
 
-    if (!(properties = virConfReadMem(config, 0, VIR_CONF_FLAG_LXC_FORMAT)))
+    if (!(properties = virConfReadString(config, VIR_CONF_FLAG_LXC_FORMAT)))
         return NULL;
 
     if (!(vmdef = virDomainDefNew()))
diff --git a/src/util/virconf.c b/src/util/virconf.c
index c1f41b7e1..e505848f1 100644
--- a/src/util/virconf.c
+++ b/src/util/virconf.c
@@ -807,27 +807,27 @@ virConfReadFile(const char *filename, unsigned int flags)
 }
 
 /**
- * virConfReadMem:
+ * virConfReadString:
  * @memory: pointer to the content of the configuration file
- * @len: length in byte
  * @flags: combination of virConfFlag(s)
  *
- * Reads a configuration file loaded in memory. The string can be
- * zero terminated in which case @len can be 0
+ * Reads a configuration file loaded in memory. The string must be
+ * zero terminated.
  *
  * Returns a handle to lookup settings or NULL if it failed to
  *         parse the content, use virConfFree() to free the data.
  */
 virConfPtr
-virConfReadMem(const char *memory, int len, unsigned int flags)
+virConfReadString(const char *memory, unsigned int flags)
 {
-    if ((memory == NULL) || (len < 0)) {
+    size_t len;
+
+    if (memory == NULL) {
         virConfError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
         return NULL;
     }
-    if (len == 0)
-        len = strlen(memory);
 
+    len = strlen(memory);
     return virConfParse("memory conf", memory, len, flags);
 }
 
diff --git a/src/util/virconf.h b/src/util/virconf.h
index 23fea4900..f7d9a369c 100644
--- a/src/util/virconf.h
+++ b/src/util/virconf.h
@@ -79,8 +79,8 @@ typedef int (*virConfWalkCallback)(const char* name,
 
 virConfPtr virConfNew(void);
 virConfPtr virConfReadFile(const char *filename, unsigned int flags);
-virConfPtr virConfReadMem(const char *memory,
-                          int len, unsigned int flags);
+virConfPtr virConfReadString(const char *memory,
+                             unsigned int flags);
 int virConfFree(virConfPtr conf);
 void virConfFreeValue(virConfValuePtr val);
 virConfValuePtr virConfGetValue(virConfPtr conf,
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 96507f10f..3e2f4c3e1 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1312,7 +1312,7 @@ virVMXParseConfig(virVMXContext *ctx,
         return NULL;
     }
 
-    conf = virConfReadMem(vmx, strlen(vmx), VIR_CONF_FLAG_VMX_FORMAT);
+    conf = virConfReadString(vmx, VIR_CONF_FLAG_VMX_FORMAT);
 
     if (conf == NULL)
         return NULL;
@@ -1332,7 +1332,7 @@ virVMXParseConfig(virVMXContext *ctx,
         if (utf8 == NULL)
             goto cleanup;
 
-        conf = virConfReadMem(utf8, strlen(utf8), VIR_CONF_FLAG_VMX_FORMAT);
+        conf = virConfReadString(utf8, VIR_CONF_FLAG_VMX_FORMAT);
 
         VIR_FREE(utf8);
 
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index b5cd47e02..dae0f4f28 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1553,7 +1553,7 @@ xenUnifiedConnectDomainXMLFromNative(virConnectPtr conn,
     }
 
     if (STREQ(format, XEN_CONFIG_FORMAT_XM)) {
-        conf = virConfReadMem(config, strlen(config), 0);
+        conf = virConfReadString(config, 0);
         if (!conf)
             goto cleanup;
 
diff --git a/tests/virconftest.c b/tests/virconftest.c
index 1f4b561bb..9d43465a7 100644
--- a/tests/virconftest.c
+++ b/tests/virconftest.c
@@ -89,7 +89,7 @@ static int testConfParseInt(const void *opaque ATTRIBUTE_UNUSED)
         "string = \"foo\"\n";
 
     int ret = -1;
-    virConfPtr conf = virConfReadMem(srcdata, strlen(srcdata), 0);
+    virConfPtr conf = virConfReadString(srcdata, 0);
     int iv;
     unsigned int ui;
     size_t s;
@@ -238,7 +238,7 @@ static int testConfParseBool(const void *opaque ATTRIBUTE_UNUSED)
         "string = \"foo\"\n";
 
     int ret = -1;
-    virConfPtr conf = virConfReadMem(srcdata, strlen(srcdata), 0);
+    virConfPtr conf = virConfReadString(srcdata, 0);
     bool f = true;
     bool t = false;
 
@@ -302,7 +302,7 @@ static int testConfParseString(const void *opaque ATTRIBUTE_UNUSED)
         "string = \"foo\"\n";
 
     int ret = -1;
-    virConfPtr conf = virConfReadMem(srcdata, strlen(srcdata), 0);
+    virConfPtr conf = virConfReadString(srcdata, 0);
     char *str = NULL;
 
     if (!conf)
@@ -342,7 +342,7 @@ static int testConfParseStringList(const void *opaque ATTRIBUTE_UNUSED)
         "string = \"foo\"\n";
 
     int ret = -1;
-    virConfPtr conf = virConfReadMem(srcdata, strlen(srcdata), 0);
+    virConfPtr conf = virConfReadString(srcdata, 0);
     char **str = NULL;
 
     if (!conf)
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index 3fe42988d..30468c905 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -146,7 +146,7 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
     if (virTestLoadFile(xlcfg, &xlcfgData) < 0)
         goto fail;
 
-    if (!(conf = virConfReadMem(xlcfgData, strlen(xlcfgData), 0)))
+    if (!(conf = virConfReadString(xlcfgData, 0)))
         goto fail;
 
     if (!(def = xenParseXL(conf, caps, xmlopt)))
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index 345223ffe..d8455da66 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -115,7 +115,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml)
     priv.caps = caps;
     conn->privateData = &priv;
 
-    if (!(conf = virConfReadMem(xmcfgData, strlen(xmcfgData), 0)))
+    if (!(conf = virConfReadString(xmcfgData, 0)))
         goto fail;
 
     if (!(def = xenParseXM(conf, caps, xmlopt)))
-- 
2.13.0

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux