1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-11 09:17:52 +03:00

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; virConfPtr conf;
int ret; int ret;
conf = virConfReadMem(filedata, strlen(filedata), 0); conf = virConfReadString(filedata, 0);
if (!conf) if (!conf)
return -1; return -1;

View File

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

View File

@ -2605,14 +2605,14 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn,
goto cleanup; goto cleanup;
if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) { if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) {
if (!(conf = virConfReadMem(nativeConfig, strlen(nativeConfig), 0))) if (!(conf = virConfReadString(nativeConfig, 0)))
goto cleanup; goto cleanup;
if (!(def = xenParseXL(conf, if (!(def = xenParseXL(conf,
cfg->caps, cfg->caps,
driver->xmlopt))) driver->xmlopt)))
goto cleanup; goto cleanup;
} else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) { } else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) {
if (!(conf = virConfReadMem(nativeConfig, strlen(nativeConfig), 0))) if (!(conf = virConfReadString(nativeConfig, 0)))
goto cleanup; goto cleanup;
if (!(def = xenParseXM(conf, if (!(def = xenParseXM(conf,

View File

@ -1000,7 +1000,7 @@ lxcParseConfigString(const char *config,
virConfPtr properties = NULL; virConfPtr properties = NULL;
virConfValuePtr value; virConfValuePtr value;
if (!(properties = virConfReadMem(config, 0, VIR_CONF_FLAG_LXC_FORMAT))) if (!(properties = virConfReadString(config, VIR_CONF_FLAG_LXC_FORMAT)))
return NULL; return NULL;
if (!(vmdef = virDomainDefNew())) 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 * @memory: pointer to the content of the configuration file
* @len: length in byte
* @flags: combination of virConfFlag(s) * @flags: combination of virConfFlag(s)
* *
* Reads a configuration file loaded in memory. The string can be * Reads a configuration file loaded in memory. The string must be
* zero terminated in which case @len can be 0 * zero terminated.
* *
* Returns a handle to lookup settings or NULL if it failed to * Returns a handle to lookup settings or NULL if it failed to
* parse the content, use virConfFree() to free the data. * parse the content, use virConfFree() to free the data.
*/ */
virConfPtr 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__); virConfError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
return NULL; return NULL;
} }
if (len == 0)
len = strlen(memory);
len = strlen(memory);
return virConfParse("memory conf", memory, len, flags); return virConfParse("memory conf", memory, len, flags);
} }

View File

@ -79,8 +79,8 @@ typedef int (*virConfWalkCallback)(const char* name,
virConfPtr virConfNew(void); virConfPtr virConfNew(void);
virConfPtr virConfReadFile(const char *filename, unsigned int flags); virConfPtr virConfReadFile(const char *filename, unsigned int flags);
virConfPtr virConfReadMem(const char *memory, virConfPtr virConfReadString(const char *memory,
int len, unsigned int flags); unsigned int flags);
int virConfFree(virConfPtr conf); int virConfFree(virConfPtr conf);
void virConfFreeValue(virConfValuePtr val); void virConfFreeValue(virConfValuePtr val);
virConfValuePtr virConfGetValue(virConfPtr conf, virConfValuePtr virConfGetValue(virConfPtr conf,

View File

@ -1312,7 +1312,7 @@ virVMXParseConfig(virVMXContext *ctx,
return NULL; return NULL;
} }
conf = virConfReadMem(vmx, strlen(vmx), VIR_CONF_FLAG_VMX_FORMAT); conf = virConfReadString(vmx, VIR_CONF_FLAG_VMX_FORMAT);
if (conf == NULL) if (conf == NULL)
return NULL; return NULL;
@ -1332,7 +1332,7 @@ virVMXParseConfig(virVMXContext *ctx,
if (utf8 == NULL) if (utf8 == NULL)
goto cleanup; goto cleanup;
conf = virConfReadMem(utf8, strlen(utf8), VIR_CONF_FLAG_VMX_FORMAT); conf = virConfReadString(utf8, VIR_CONF_FLAG_VMX_FORMAT);
VIR_FREE(utf8); VIR_FREE(utf8);

View File

@ -1553,7 +1553,7 @@ xenUnifiedConnectDomainXMLFromNative(virConnectPtr conn,
} }
if (STREQ(format, XEN_CONFIG_FORMAT_XM)) { if (STREQ(format, XEN_CONFIG_FORMAT_XM)) {
conf = virConfReadMem(config, strlen(config), 0); conf = virConfReadString(config, 0);
if (!conf) if (!conf)
goto cleanup; goto cleanup;

View File

@ -89,7 +89,7 @@ static int testConfParseInt(const void *opaque ATTRIBUTE_UNUSED)
"string = \"foo\"\n"; "string = \"foo\"\n";
int ret = -1; int ret = -1;
virConfPtr conf = virConfReadMem(srcdata, strlen(srcdata), 0); virConfPtr conf = virConfReadString(srcdata, 0);
int iv; int iv;
unsigned int ui; unsigned int ui;
size_t s; size_t s;
@ -238,7 +238,7 @@ static int testConfParseBool(const void *opaque ATTRIBUTE_UNUSED)
"string = \"foo\"\n"; "string = \"foo\"\n";
int ret = -1; int ret = -1;
virConfPtr conf = virConfReadMem(srcdata, strlen(srcdata), 0); virConfPtr conf = virConfReadString(srcdata, 0);
bool f = true; bool f = true;
bool t = false; bool t = false;
@ -302,7 +302,7 @@ static int testConfParseString(const void *opaque ATTRIBUTE_UNUSED)
"string = \"foo\"\n"; "string = \"foo\"\n";
int ret = -1; int ret = -1;
virConfPtr conf = virConfReadMem(srcdata, strlen(srcdata), 0); virConfPtr conf = virConfReadString(srcdata, 0);
char *str = NULL; char *str = NULL;
if (!conf) if (!conf)
@ -342,7 +342,7 @@ static int testConfParseStringList(const void *opaque ATTRIBUTE_UNUSED)
"string = \"foo\"\n"; "string = \"foo\"\n";
int ret = -1; int ret = -1;
virConfPtr conf = virConfReadMem(srcdata, strlen(srcdata), 0); virConfPtr conf = virConfReadString(srcdata, 0);
char **str = NULL; char **str = NULL;
if (!conf) if (!conf)

View File

@ -146,7 +146,7 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
if (virTestLoadFile(xlcfg, &xlcfgData) < 0) if (virTestLoadFile(xlcfg, &xlcfgData) < 0)
goto fail; goto fail;
if (!(conf = virConfReadMem(xlcfgData, strlen(xlcfgData), 0))) if (!(conf = virConfReadString(xlcfgData, 0)))
goto fail; goto fail;
if (!(def = xenParseXL(conf, caps, xmlopt))) if (!(def = xenParseXL(conf, caps, xmlopt)))

View File

@ -115,7 +115,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml)
priv.caps = caps; priv.caps = caps;
conn->privateData = &priv; conn->privateData = &priv;
if (!(conf = virConfReadMem(xmcfgData, strlen(xmcfgData), 0))) if (!(conf = virConfReadString(xmcfgData, 0)))
goto fail; goto fail;
if (!(def = xenParseXM(conf, caps, xmlopt))) if (!(def = xenParseXM(conf, caps, xmlopt)))