提交 144276aa 编写于 作者: D Daniel Veillard

extend the configuration parser for VMX syntax

* qemud/qemud.c src/conf.c src/conf.h src/qemu_conf.c src/xen_unified.c
  src/xm_internal.c tests/conftest.c tests/xmconfigtest.c: extend
  the configuration parser for VMX syntax, patch by Matthias Bolte
Daniel
上级 2be4d867
Fri Jun 19 14:32:41 CEST 2009 Daniel Veillard <veillard@redhat.com>
* qemud/qemud.c src/conf.c src/conf.h src/qemu_conf.c src/xen_unified.c
src/xm_internal.c tests/conftest.c tests/xmconfigtest.c: extend
the configuration parser for VMX syntax, patch by Matthias Bolte
Thu Jun 18 14:56:24 BST 2009 Daniel P. Berrange <berrange@redhat.com>
* src/remote_internal.c: Fix socket path for remote SSH
......
此差异已折叠。
......@@ -2542,7 +2542,7 @@ remoteReadConfigFile (struct qemud_server *server, const char *filename)
auth_unix_ro = REMOTE_AUTH_NONE;
#endif
conf = virConfReadFile (filename);
conf = virConfReadFile (filename, 0);
if (!conf) return -1;
/*
......
......@@ -76,6 +76,7 @@ struct _virConfEntry {
struct _virConf {
const char* filename;
unsigned int flags;
virConfEntryPtr entries;
};
......@@ -167,6 +168,7 @@ virConfNew(void)
return(NULL);
}
ret->filename = NULL;
ret->flags = 0;
return(ret);
}
......@@ -174,17 +176,20 @@ virConfNew(void)
/**
* virConfCreate:
* @filename: the name to report errors
* @flags: combination of virConfFlag(s)
*
* Create a configuration internal structure
*
* Returns a pointer or NULL in case of error.
*/
static virConfPtr
virConfCreate(const char *filename)
virConfCreate(const char *filename, unsigned int flags)
{
virConfPtr ret = virConfNew();
if (ret)
if (ret) {
ret->filename = filename;
ret->flags = flags;
}
return(ret);
}
......@@ -523,7 +528,10 @@ virConfParseName(virConfParserCtxtPtr ctxt)
virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a name"));
return(NULL);
}
while ((ctxt->cur < ctxt->end) && (c_isalnum(CUR) || (CUR == '_')))
while ((ctxt->cur < ctxt->end) &&
(c_isalnum(CUR) || (CUR == '_') ||
((ctxt->conf->flags & VIR_CONF_FLAG_ALLOW_VMX_NAMES) &&
((CUR == ':') || (CUR == '.')))))
NEXT;
ret = strndup(base, ctxt->cur - base);
if (ret == NULL) {
......@@ -649,6 +657,7 @@ virConfParseStatement(virConfParserCtxtPtr ctxt)
* @filename: the name to report errors
* @content: the configuration content in memory
* @len: the length in bytes
* @flags: combination of virConfFlag(s)
*
* Parse the subset of the Python language needed to handle simple
* Xen configuration files.
......@@ -657,7 +666,8 @@ virConfParseStatement(virConfParserCtxtPtr ctxt)
* read or parse the file, use virConfFree() to free the data.
*/
static virConfPtr
virConfParse(const char *filename, const char *content, int len) {
virConfParse(const char *filename, const char *content, int len,
unsigned int flags) {
virConfParserCtxt ctxt;
ctxt.filename = filename;
......@@ -665,7 +675,7 @@ virConfParse(const char *filename, const char *content, int len) {
ctxt.end = content + len - 1;
ctxt.line = 1;
ctxt.conf = virConfCreate(filename);
ctxt.conf = virConfCreate(filename, flags);
if (ctxt.conf == NULL)
return(NULL);
......@@ -695,6 +705,7 @@ error:
/**
* virConfReadFile:
* @filename: the path to the configuration file.
* @flags: combination of virConfFlag(s)
*
* Reads a configuration file.
*
......@@ -702,7 +713,7 @@ error:
* read or parse the file, use virConfFree() to free the data.
*/
virConfPtr
virConfReadFile(const char *filename)
virConfReadFile(const char *filename, unsigned int flags)
{
char *content;
int len;
......@@ -717,7 +728,7 @@ virConfReadFile(const char *filename)
return NULL;
}
conf = virConfParse(filename, content, len);
conf = virConfParse(filename, content, len, flags);
VIR_FREE(content);
......@@ -728,6 +739,7 @@ virConfReadFile(const char *filename)
* virConfReadMem:
* @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
......@@ -736,7 +748,7 @@ virConfReadFile(const char *filename)
* parse the content, use virConfFree() to free the data.
*/
virConfPtr
virConfReadMem(const char *memory, int len)
virConfReadMem(const char *memory, int len, unsigned int flags)
{
if ((memory == NULL) || (len < 0)) {
virConfError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
......@@ -745,7 +757,7 @@ virConfReadMem(const char *memory, int len)
if (len == 0)
len = strlen(memory);
return(virConfParse("memory conf", memory, len));
return(virConfParse("memory conf", memory, len, flags));
}
/**
......
......@@ -24,6 +24,11 @@ typedef enum {
VIR_CONF_LIST = 3 /* a list */
} virConfType;
typedef enum {
VIR_CONF_FLAG_ALLOW_VMX_NAMES = 1, /* allow : and . in names for compatibility
with VMware VMX configuration file */
} virConfFlags;
static inline const char *
virConfTypeName (virConfType t)
{
......@@ -62,9 +67,9 @@ typedef struct _virConf virConf;
typedef virConf *virConfPtr;
virConfPtr virConfNew (void);
virConfPtr virConfReadFile (const char *filename);
virConfPtr virConfReadFile (const char *filename, unsigned int flags);
virConfPtr virConfReadMem (const char *memory,
int len);
int len, unsigned int flags);
int virConfFree (virConfPtr conf);
void virConfFreeValue (virConfValuePtr val);
......
......@@ -99,7 +99,7 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
*/
if (access (filename, R_OK) == -1) return 0;
conf = virConfReadFile (filename);
conf = virConfReadFile (filename, 0);
if (!conf) return 0;
......
......@@ -1084,7 +1084,7 @@ xenUnifiedDomainXMLFromNative(virConnectPtr conn,
}
if (STREQ(format, XEN_CONFIG_FORMAT_XM)) {
conf = virConfReadMem(config, strlen(config));
conf = virConfReadMem(config, strlen(config), 0);
if (!conf)
goto cleanup;
......
......@@ -324,7 +324,7 @@ xenXMConfigReadFile(virConnectPtr conn, const char *filename) {
virConfPtr conf;
virDomainDefPtr def;
if (!(conf = virConfReadFile(filename)))
if (!(conf = virConfReadFile(filename, 0)))
return NULL;
def = xenXMDomainConfigParse(conn, conf);
......
......@@ -18,7 +18,7 @@ int main(int argc, char **argv) {
exit(1);
}
conf = virConfReadFile(argv[1]);
conf = virConfReadFile(argv[1], 0);
if (conf == NULL) {
fprintf(stderr, "Failed to process %s\n", argv[1]);
exit(2);
......
......@@ -124,7 +124,7 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml,
priv.caps = caps;
conn->privateData = &priv;
if (!(conf = virConfReadMem(xmcfgPtr, strlen(xmcfgPtr))))
if (!(conf = virConfReadMem(xmcfgPtr, strlen(xmcfgPtr), 0)))
goto fail;
if (!(def = xenXMDomainConfigParse(conn, conf)))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册