introduce virConfReadString

Rewrite virConfReadMem to take a null-terminated string.
All the callers were calling strlen on it anyway.
This commit is contained in:
Ján Tomko 2017-08-07 17:12:02 +02:00
parent 5d218156a8
commit e9f3222705
11 changed files with 24 additions and 24 deletions

View File

@ -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;

View File

@ -1520,7 +1520,7 @@ virConfGetValueULLong;
virConfLoadConfig;
virConfNew;
virConfReadFile;
virConfReadMem;
virConfReadString;
virConfSetValue;
virConfTypeFromString;
virConfTypeToString;

View File

@ -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,

View File

@ -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()))

View File

@ -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);
}

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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)

View File

@ -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)))

View File

@ -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)))