]> xenbits.xensource.com Git - libvirt.git/commitdiff
Rename conf.{c,h} to virconf.{c,h}
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 12 Dec 2012 16:35:35 +0000 (16:35 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 21 Dec 2012 11:17:13 +0000 (11:17 +0000)
29 files changed:
daemon/libvirtd-config.c
daemon/libvirtd.c
po/POTFILES.in
src/Makefile.am
src/libvirt.c
src/libxl/libxl_driver.c
src/locking/lock_daemon.c
src/locking/lock_daemon_config.c
src/locking/lock_driver_lockd.c
src/locking/lock_driver_sanlock.c
src/locking/sanlock_helper.c
src/lxc/lxc_conf.c
src/qemu/qemu_conf.c
src/security/security_selinux.c
src/uml/uml_conf.c
src/util/conf.c [deleted file]
src/util/conf.h [deleted file]
src/util/virconf.c [new file with mode: 0644]
src/util/virconf.h [new file with mode: 0644]
src/vmx/vmx.c
src/vmx/vmx.h
src/xen/xen_inotify.c
src/xen/xm_internal.h
src/xenxs/xen_sxpr.c
src/xenxs/xen_sxpr.h
src/xenxs/xen_xm.c
src/xenxs/xen_xm.h
tests/conftest.c
tests/libvirtdconftest.c

index 78380441fd09be740a357b0be285d57c71596a50..0ca185c069c4c879e7a60cc4ed5ea2e8dd948b7c 100644 (file)
@@ -24,7 +24,7 @@
 #include <config.h>
 
 #include "libvirtd-config.h"
-#include "conf.h"
+#include "virconf.h"
 #include "memory.h"
 #include "virterror_internal.h"
 #include "logging.h"
index f88be9bedda1c02c9303a3f4a4d130146584c69e..9b0e45a24b76405f3852c9c44bac49d8234abfc3 100644 (file)
@@ -47,7 +47,7 @@
 #include "uuid.h"
 #include "remote_driver.h"
 #include "memory.h"
-#include "conf.h"
+#include "virconf.h"
 #include "virnetlink.h"
 #include "virnetserver.h"
 #include "threads.h"
index 7b4567bff9b144947cfdcc0a4ce677a1c95b79f5..6dcda84b29a8b8c222f69491953c0b77ac03faa4 100644 (file)
@@ -138,7 +138,6 @@ src/storage/storage_driver.c
 src/test/test_driver.c
 src/uml/uml_conf.c
 src/uml/uml_driver.c
-src/util/conf.c
 src/util/dnsmasq.c
 src/util/event_poll.c
 src/util/hooks.c
@@ -158,6 +157,7 @@ src/util/virauth.c
 src/util/virauthconfig.c
 src/util/vircgroup.c
 src/util/vircommand.c
+src/util/virconf.c
 src/util/virdbus.c
 src/util/virfile.c
 src/util/virhash.c
index 53d1bd405225bce98be5787bac149ace66b5e51a..c27388301fa82b9aa35db43726daa51b512648fb 100644 (file)
@@ -53,7 +53,6 @@ augeastest_DATA =
 # These files are not related to driver APIs. Simply generic
 # helper APIs for various purposes
 UTIL_SOURCES =                                                 \
-               util/conf.c util/conf.h                         \
                util/event.c util/event.h                       \
                util/event_poll.c util/event_poll.h             \
                util/hooks.c util/hooks.h                       \
@@ -84,6 +83,7 @@ UTIL_SOURCES =                                                        \
                util/virbitmap.c util/virbitmap.h               \
                util/virbuffer.c util/virbuffer.h               \
                util/vircommand.c util/vircommand.h             \
+               util/virconf.c util/virconf.h                   \
                util/virfile.c util/virfile.h                   \
                util/virnodesuspend.c util/virnodesuspend.h     \
                util/virobject.c util/virobject.h               \
index e28ed0546ffcfcd57a4db699ffede60627f11b3f..8f7a86953817985bae9412d707f79d60dcf1bd08 100644 (file)
@@ -54,7 +54,7 @@
 #include "memory.h"
 #include "configmake.h"
 #include "intprops.h"
-#include "conf.h"
+#include "virconf.h"
 #include "rpc/virnettlscontext.h"
 #include "vircommand.h"
 #include "virrandom.h"
index f03008f20ea0de87a08ad73c69bf36314a20d5a5..77457c8c02614d35ff033710252ffc1dcd3a6c93 100644 (file)
@@ -33,7 +33,7 @@
 #include "internal.h"
 #include "logging.h"
 #include "virterror_internal.h"
-#include "conf.h"
+#include "virconf.h"
 #include "datatypes.h"
 #include "virfile.h"
 #include "memory.h"
index d7906c5726913dc58e0cabb258c1e3b675351f68..08caa1644ae93c283d475514ecf3983e61c5d405 100644 (file)
@@ -40,7 +40,7 @@
 #include "virterror_internal.h"
 #include "logging.h"
 #include "memory.h"
-#include "conf.h"
+#include "virconf.h"
 #include "rpc/virnetserver.h"
 #include "virrandom.h"
 #include "virhash.h"
index c64de6793ef49a04ef382cd4184f3b6e1d383057..c2d9a76129db60e126bd77221d0934ae250e4cc1 100644 (file)
@@ -24,7 +24,7 @@
 #include <config.h>
 
 #include "lock_daemon_config.h"
-#include "conf.h"
+#include "virconf.h"
 #include "memory.h"
 #include "virterror_internal.h"
 #include "logging.h"
index 3902edee9f8bc6fcbb58ddf0db4ccb465baf284f..c88c5af9aa4c2d17184a71db11d5f7f93dea9908 100644 (file)
@@ -22,7 +22,7 @@
 #include <config.h>
 
 #include "lock_driver.h"
-#include "conf.h"
+#include "virconf.h"
 #include "memory.h"
 #include "logging.h"
 #include "uuid.h"
index a0723439a73acf26a11f3a368e7d50933e5d1793..2eadc07f72c1f02286935b5b1c9ecb1e5da15a97 100644 (file)
@@ -43,7 +43,7 @@
 #include "util.h"
 #include "virfile.h"
 #include "md5.h"
-#include "conf.h"
+#include "virconf.h"
 
 #include "configmake.h"
 
index a73b49ca41820c25b479c9ffc1fc8125add8c24e..ad69312c2f2daa9947f48e4dd9d66f8d977113f0 100644 (file)
@@ -5,7 +5,7 @@
 
 #include "configmake.h"
 #include "internal.h"
-#include "conf.h"
+#include "virconf.h"
 #include "memory.h"
 #include "domain_conf.h"
 
index 9b89ceb2dd79073b11b4153f9162df8f257e0522..905734b5fb7943cc5945aa9054b359da67bb8372 100644 (file)
@@ -29,7 +29,7 @@
 #include "lxc_conf.h"
 #include "nodeinfo.h"
 #include "virterror_internal.h"
-#include "conf.h"
+#include "virconf.h"
 #include "memory.h"
 #include "logging.h"
 #include "uuid.h"
index a796aa9cbd1ea5aa56bcabac3598eac162bfcb2a..91af49bf29413c5d87758f11ec2edb4d8b7a6b80 100644 (file)
@@ -41,7 +41,7 @@
 #include "qemu_bridge_filter.h"
 #include "uuid.h"
 #include "virbuffer.h"
-#include "conf.h"
+#include "virconf.h"
 #include "util.h"
 #include "memory.h"
 #include "datatypes.h"
index 1f73fd2390118418590b795c9780721b935a1236..4456a20c2c3cb94a3340d97f35a006ab63937f5f 100644 (file)
@@ -44,7 +44,7 @@
 #include "virhash.h"
 #include "virrandom.h"
 #include "util.h"
-#include "conf.h"
+#include "virconf.h"
 
 #define VIR_FROM_THIS VIR_FROM_SECURITY
 
index 8f72658662f7cd49c8bf9665e396c09f97c3a640..b669b5a292a55e7c9a0a7642e50a716f42c2f5c2 100644 (file)
@@ -37,7 +37,7 @@
 #include "uml_conf.h"
 #include "uuid.h"
 #include "virbuffer.h"
-#include "conf.h"
+#include "virconf.h"
 #include "util.h"
 #include "memory.h"
 #include "nodeinfo.h"
diff --git a/src/util/conf.c b/src/util/conf.c
deleted file mode 100644 (file)
index 3b97545..0000000
+++ /dev/null
@@ -1,1032 +0,0 @@
-/**
- * conf.c: parser for a subset of the Python encoded Xen configuration files
- *
- * Copyright (C) 2006-2012 Red Hat, Inc.
- *
- * 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/>.
- *
- * Daniel Veillard <veillard@redhat.com>
- */
-
-#include <config.h>
-
-#include <string.h>
-
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include "virterror_internal.h"
-#include "virbuffer.h"
-#include "conf.h"
-#include "util.h"
-#include "c-ctype.h"
-#include "logging.h"
-#include "memory.h"
-#include "virfile.h"
-
-#define VIR_FROM_THIS VIR_FROM_CONF
-
-/************************************************************************
- *                                                                     *
- *     Structures and macros used by the mini parser                   *
- *                                                                     *
- ************************************************************************/
-
-typedef struct _virConfParserCtxt virConfParserCtxt;
-typedef virConfParserCtxt *virConfParserCtxtPtr;
-
-struct _virConfParserCtxt {
-    const char* filename;
-    const char* base;
-    const char* cur;
-    const char *end;
-    int line;
-
-    virConfPtr conf;
-};
-
-#define CUR (*ctxt->cur)
-#define NEXT if (ctxt->cur < ctxt->end) ctxt->cur++;
-#define IS_EOL(c) (((c) == '\n') || ((c) == '\r'))
-
-#define SKIP_BLANKS_AND_EOL                                             \
-  do { while ((ctxt->cur < ctxt->end) && (c_isblank(CUR) || IS_EOL(CUR))) { \
-         if (CUR == '\n') ctxt->line++;                                        \
-         ctxt->cur++;}} while (0)
-#define SKIP_BLANKS                                                     \
-  do { while ((ctxt->cur < ctxt->end) && (c_isblank(CUR)))              \
-          ctxt->cur++; } while (0)
-
-/************************************************************************
- *                                                                     *
- *             Structures used by configuration data                   *
- *                                                                     *
- ************************************************************************/
-
-typedef struct _virConfEntry virConfEntry;
-typedef virConfEntry *virConfEntryPtr;
-
-struct _virConfEntry {
-    virConfEntryPtr next;
-    char* name;
-    char* comment;
-    virConfValuePtr value;
-};
-
-struct _virConf {
-    const char* filename;
-    unsigned int flags;
-    virConfEntryPtr entries;
-};
-
-/**
- * virConfError:
- * @ctxt: the parser context if available or NULL
- * @error: the error number
- * @info: extra information string
- *
- * Handle an error at the xend daemon interface
- */
-#define virConfError(ctxt, error, info) \
-    virConfErrorHelper(__FILE__, __FUNCTION__, __LINE__, ctxt, error, info)
-static void
-virConfErrorHelper(const char *file, const char *func, size_t line,
-                   virConfParserCtxtPtr ctxt,
-                   virErrorNumber error, const char *info)
-{
-    if (error == VIR_ERR_OK)
-        return;
-
-    /* Construct the string 'filename:line: info' if we have that. */
-    if (ctxt && ctxt->filename) {
-        virReportErrorHelper(VIR_FROM_CONF, error, file, func, line,
-                             _("%s:%d: %s"), ctxt->filename, ctxt->line, info);
-    } else {
-        virReportErrorHelper(VIR_FROM_CONF, error, file, func, line,
-                             "%s", info);
-    }
-}
-
-
-/************************************************************************
- *                                                                     *
- *             Structures allocations and deallocations                *
- *                                                                     *
- ************************************************************************/
-
-/**
- * virConfFreeList:
- * @list: the list to free
- *
- * Free a list
- */
-static void
-virConfFreeList(virConfValuePtr list)
-{
-    virConfValuePtr next;
-
-    while (list != NULL) {
-        next = list->next;
-        list->next = NULL;
-        virConfFreeValue(list);
-        list = next;
-    }
-}
-
-/**
- * virConfFreeValue:
- * @val: the value to free
- *
- * Free a value
- */
-void
-virConfFreeValue(virConfValuePtr val)
-{
-    if (val == NULL)
-        return;
-    if (val->type == VIR_CONF_STRING &&
-        val->str != NULL)
-        VIR_FREE(val->str);
-    if (val->type == VIR_CONF_LIST &&
-        val->list != NULL)
-        virConfFreeList(val->list);
-    VIR_FREE(val);
-}
-
-virConfPtr
-virConfNew(void)
-{
-    virConfPtr ret;
-
-    if (VIR_ALLOC(ret) < 0) {
-        virReportOOMError();
-        return NULL;
-    }
-    ret->filename = NULL;
-    ret->flags = 0;
-
-    return ret;
-}
-
-/**
- * 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, unsigned int flags)
-{
-    virConfPtr ret = virConfNew();
-    if (ret) {
-        ret->filename = filename;
-        ret->flags = flags;
-    }
-    return ret;
-}
-
-/**
- * virConfAddEntry:
- * @conf: the conf structure
- * @name: name of the entry or NULL for comment
- * @value: the value if any
- * @comm: extra comment for that entry if any
- *
- * add one entry to the conf, the parameters are included in the conf
- * if successful and freed on virConfFree()
- *
- * Returns a pointer to the entry or NULL in case of failure
- */
-static virConfEntryPtr
-virConfAddEntry(virConfPtr conf, char *name, virConfValuePtr value, char *comm)
-{
-    virConfEntryPtr ret, prev;
-
-    if (conf == NULL)
-        return NULL;
-    if ((comm == NULL) && (name == NULL))
-        return NULL;
-
-    if (VIR_ALLOC(ret) < 0) {
-        virReportOOMError();
-        return NULL;
-    }
-
-    ret->name = name;
-    ret->value = value;
-    ret->comment = comm;
-
-    if (conf->entries == NULL) {
-        conf->entries = ret;
-    } else {
-        prev = conf->entries;
-        while (prev->next != NULL)
-            prev = prev->next;
-        prev->next = ret;
-    }
-    return ret;
-}
-
-/************************************************************************
- *                                                                     *
- *                     Serialization                                   *
- *                                                                     *
- ************************************************************************/
-
-/**
- * virConfSaveValue:
- * @buf: output buffer
- * @val: a value
- *
- * Serialize the value to the buffer
- *
- * Returns 0 in case of success, -1 in case of error.
- */
-static int
-virConfSaveValue(virBufferPtr buf, virConfValuePtr val)
-{
-    if (val == NULL)
-        return -1;
-    switch (val->type) {
-        case VIR_CONF_NONE:
-            return -1;
-        case VIR_CONF_LONG:
-            virBufferAsprintf(buf, "%ld", val->l);
-            break;
-        case VIR_CONF_STRING:
-            if (strchr(val->str, '\n') != NULL) {
-                virBufferAsprintf(buf, "\"\"\"%s\"\"\"", val->str);
-            } else if (strchr(val->str, '"') == NULL) {
-                virBufferAsprintf(buf, "\"%s\"", val->str);
-            } else if (strchr(val->str, '\'') == NULL) {
-                virBufferAsprintf(buf, "'%s'", val->str);
-            } else {
-                virBufferAsprintf(buf, "\"\"\"%s\"\"\"", val->str);
-            }
-            break;
-        case VIR_CONF_LIST: {
-            virConfValuePtr cur;
-
-            cur = val->list;
-            virBufferAddLit(buf, "[ ");
-            if (cur != NULL) {
-                virConfSaveValue(buf, cur);
-                cur = cur->next;
-                while (cur != NULL) {
-                    virBufferAddLit(buf, ", ");
-                    virConfSaveValue(buf, cur);
-                    cur = cur->next;
-                }
-            }
-            virBufferAddLit(buf, " ]");
-            break;
-        }
-        default:
-            return -1;
-    }
-    return 0;
-}
-
-/**
- * virConfSaveEntry:
- * @buf: output buffer
- * @cur: a conf entry
- *
- * Serialize the entry to the buffer
- *
- * Returns 0 in case of success, -1 in case of error.
- */
-static int
-virConfSaveEntry(virBufferPtr buf, virConfEntryPtr cur)
-{
-    if (cur->name != NULL) {
-        virBufferAdd(buf, cur->name, -1);
-        virBufferAddLit(buf, " = ");
-        virConfSaveValue(buf, cur->value);
-        if (cur->comment != NULL) {
-            virBufferAddLit(buf, " #");
-            virBufferAdd(buf, cur->comment, -1);
-        }
-    } else if (cur->comment != NULL) {
-        virBufferAddLit(buf, "#");
-        virBufferAdd(buf, cur->comment, -1);
-    }
-    virBufferAddLit(buf, "\n");
-    return 0;
-}
-
-/************************************************************************
- *                                                                     *
- *                     The parser core                                 *
- *                                                                     *
- ************************************************************************/
-
-/**
- * virConfParseLong:
- * @ctxt: the parsing context
- * @val: the result
- *
- * Parse one long int value
- *
- * Returns 0 in case of success and -1 in case of error
- */
-static int
-virConfParseLong(virConfParserCtxtPtr ctxt, long *val)
-{
-    long l = 0;
-    int neg = 0;
-
-    if (CUR == '-') {
-        neg = 1;
-        NEXT;
-    } else if (CUR == '+') {
-        NEXT;
-    }
-    if ((ctxt->cur >= ctxt->end) || (!c_isdigit(CUR))) {
-        virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated number"));
-        return -1;
-    }
-    while ((ctxt->cur < ctxt->end) && (c_isdigit(CUR))) {
-        l = l * 10 + (CUR - '0');
-        NEXT;
-    }
-    if (neg)
-        l = -l;
-    *val = l;
-    return 0;
-}
-
-/**
- * virConfParseString:
- * @ctxt: the parsing context
- *
- * Parse one string
- *
- * Returns a pointer to the string or NULL in case of error
- */
-static char *
-virConfParseString(virConfParserCtxtPtr ctxt)
-{
-    const char *base;
-    char *ret = NULL;
-
-    if (CUR == '\'') {
-        NEXT;
-        base = ctxt->cur;
-        while ((ctxt->cur < ctxt->end) && (CUR != '\'') && (!IS_EOL(CUR)))
-            NEXT;
-        if (CUR != '\'') {
-            virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
-            return NULL;
-        }
-        ret = strndup(base, ctxt->cur - base);
-        if (ret == NULL) {
-            virReportOOMError();
-            return NULL;
-        }
-        NEXT;
-    } else if ((ctxt->cur + 6 < ctxt->end) &&
-               (STRPREFIX(ctxt->cur, "\"\"\""))) {
-        /* String starts with python-style triple quotes """ */
-        ctxt->cur += 3;
-        base = ctxt->cur;
-
-        /* Find the ending triple quotes */
-        while ((ctxt->cur + 2 < ctxt->end) &&
-               !(STRPREFIX(ctxt->cur, "\"\"\""))) {
-            if (CUR == '\n')
-                ctxt->line++;
-            NEXT;
-        }
-
-        if (!STRPREFIX(ctxt->cur, "\"\"\"")) {
-            virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
-            return NULL;
-        }
-        ret = strndup(base, ctxt->cur - base);
-        if (ret == NULL) {
-            virReportOOMError();
-            return NULL;
-        }
-        ctxt->cur += 3;
-    } else if (CUR == '"') {
-        NEXT;
-        base = ctxt->cur;
-        while ((ctxt->cur < ctxt->end) && (CUR != '"') && (!IS_EOL(CUR)))
-            NEXT;
-        if (CUR != '"') {
-            virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
-            return NULL;
-        }
-        ret = strndup(base, ctxt->cur - base);
-        if (ret == NULL) {
-            virReportOOMError();
-            return NULL;
-        }
-        NEXT;
-    }
-    return ret;
-}
-
-/**
- * virConfParseValue:
- * @ctxt: the parsing context
- *
- * Parse one value
- *
- * Returns a pointer to the value or NULL in case of error
- */
-static virConfValuePtr
-virConfParseValue(virConfParserCtxtPtr ctxt)
-{
-    virConfValuePtr ret, lst = NULL, tmp, prev;
-    virConfType type = VIR_CONF_NONE;
-    char *str = NULL;
-    long  l = 0;
-
-    SKIP_BLANKS;
-    if (ctxt->cur >= ctxt->end) {
-        virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a value"));
-        return NULL;
-    }
-    if ((CUR == '"') || (CUR == '\'')) {
-        type = VIR_CONF_STRING;
-        str = virConfParseString(ctxt);
-        if (str == NULL)
-            return NULL;
-    } else if (CUR == '[') {
-        if (ctxt->conf->flags & VIR_CONF_FLAG_VMX_FORMAT) {
-            virConfError(ctxt, VIR_ERR_CONF_SYNTAX,
-                         _("lists not allowed in VMX format"));
-            return NULL;
-        }
-        type = VIR_CONF_LIST;
-        NEXT;
-        SKIP_BLANKS_AND_EOL;
-        if ((ctxt->cur < ctxt->end) && (CUR != ']')) {
-            if ((lst = virConfParseValue(ctxt)) == NULL)
-                return NULL;
-            SKIP_BLANKS_AND_EOL;
-        }
-        while ((ctxt->cur < ctxt->end) && (CUR != ']')) {
-
-            /* Tell Clang that when execution reaches this point
-               "lst" is guaranteed to be non-NULL.  This stops it
-               from issuing an invalid NULL-dereference warning about
-               "prev = lst; while (prev->next..." below.  */
-            sa_assert(lst);
-
-            if (CUR != ',') {
-                virConfError(ctxt, VIR_ERR_CONF_SYNTAX,
-                             _("expecting a separator in list"));
-                virConfFreeList(lst);
-                return NULL;
-            }
-            NEXT;
-            SKIP_BLANKS_AND_EOL;
-            if (CUR == ']') {
-                break;
-            }
-            tmp = virConfParseValue(ctxt);
-            if (tmp == NULL) {
-                virConfFreeList(lst);
-                return NULL;
-            }
-            prev = lst;
-            while (prev->next != NULL) prev = prev->next;
-            prev->next = tmp;
-            SKIP_BLANKS_AND_EOL;
-        }
-        if (CUR == ']') {
-            NEXT;
-        } else {
-            virConfError(ctxt, VIR_ERR_CONF_SYNTAX,
-                         _("list is not closed with ]"));
-            virConfFreeList(lst);
-            return NULL;
-        }
-    } else if (c_isdigit(CUR) || (CUR == '-') || (CUR == '+')) {
-        if (ctxt->conf->flags & VIR_CONF_FLAG_VMX_FORMAT) {
-            virConfError(ctxt, VIR_ERR_CONF_SYNTAX,
-                         _("numbers not allowed in VMX format"));
-            return NULL;
-        }
-        if (virConfParseLong(ctxt, &l) < 0) {
-            return NULL;
-        }
-        type = VIR_CONF_LONG;
-    } else {
-        virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a value"));
-        return NULL;
-    }
-    if (VIR_ALLOC(ret) < 0) {
-        virReportOOMError();
-        virConfFreeList(lst);
-        VIR_FREE(str);
-        return NULL;
-    }
-    ret->type = type;
-    ret->l = l;
-    ret->str = str;
-    ret->list = lst;
-    return ret;
-}
-
-/**
- * virConfParseName:
- * @ctxt: the parsing context
- *
- * Parse one name
- *
- * Returns a copy of the new string, NULL in case of error
- */
-static char *
-virConfParseName(virConfParserCtxtPtr ctxt)
-{
-    const char *base;
-    char *ret;
-
-    SKIP_BLANKS;
-    base = ctxt->cur;
-    /* TODO: probably need encoding support and UTF-8 parsing ! */
-    if (!c_isalpha(CUR) &&
-        !((ctxt->conf->flags & VIR_CONF_FLAG_VMX_FORMAT) && (CUR == '.'))) {
-        virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a name"));
-        return NULL;
-    }
-    while ((ctxt->cur < ctxt->end) &&
-           (c_isalnum(CUR) || (CUR == '_') ||
-            ((ctxt->conf->flags & VIR_CONF_FLAG_VMX_FORMAT) &&
-             ((CUR == ':') || (CUR == '.') || (CUR == '-')))))
-        NEXT;
-    ret = strndup(base, ctxt->cur - base);
-    if (ret == NULL) {
-        virReportOOMError();
-        return NULL;
-    }
-    return ret;
-}
-
-/**
- * virConfParseComment:
- * @ctxt: the parsing context
- *
- * Parse one standalone comment in the configuration file
- *
- * Returns 0 in case of success and -1 in case of error
- */
-static int
-virConfParseComment(virConfParserCtxtPtr ctxt)
-{
-    const char *base;
-    char *comm;
-
-    if (CUR != '#')
-        return -1;
-    NEXT;
-    base = ctxt->cur;
-    while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT;
-    comm = strndup(base, ctxt->cur - base);
-    if (comm == NULL) {
-        virReportOOMError();
-        return -1;
-    }
-    virConfAddEntry(ctxt->conf, NULL, NULL, comm);
-    return 0;
-}
-
-/**
- * virConfParseSeparator:
- * @ctxt: the parsing context
- *
- * Parse one separator between statement if not at the end.
- *
- * Returns 0 in case of success and -1 in case of error
- */
-static int
-virConfParseSeparator(virConfParserCtxtPtr ctxt)
-{
-    SKIP_BLANKS;
-    if (ctxt->cur >= ctxt->end)
-        return 0;
-    if (IS_EOL(CUR)) {
-        SKIP_BLANKS_AND_EOL;
-    } else if (CUR == ';') {
-        NEXT;
-        SKIP_BLANKS_AND_EOL;
-    } else {
-        virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a separator"));
-        return -1;
-    }
-    return 0;
-}
-
-/**
- * virConfParseStatement:
- * @ctxt: the parsing context
- *
- * Parse one statement in the conf file
- *
- * Returns 0 in case of success and -1 in case of error
- */
-static int
-virConfParseStatement(virConfParserCtxtPtr ctxt)
-{
-    const char *base;
-    char *name;
-    virConfValuePtr value;
-    char *comm = NULL;
-
-    SKIP_BLANKS_AND_EOL;
-    if (CUR == '#') {
-        return virConfParseComment(ctxt);
-    }
-    name = virConfParseName(ctxt);
-    if (name == NULL)
-        return -1;
-    SKIP_BLANKS;
-    if (CUR != '=') {
-        virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting an assignment"));
-        VIR_FREE(name);
-        return -1;
-    }
-    NEXT;
-    SKIP_BLANKS;
-    value = virConfParseValue(ctxt);
-    if (value == NULL) {
-        VIR_FREE(name);
-        return -1;
-    }
-    SKIP_BLANKS;
-    if (CUR == '#') {
-        NEXT;
-        base = ctxt->cur;
-        while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT;
-        comm = strndup(base, ctxt->cur - base);
-        if (comm == NULL) {
-            virReportOOMError();
-            VIR_FREE(name);
-            virConfFreeValue(value);
-            return -1;
-        }
-    }
-    if (virConfAddEntry(ctxt->conf, name, value, comm) == NULL) {
-        VIR_FREE(name);
-        virConfFreeValue(value);
-        VIR_FREE(comm);
-        return -1;
-    }
-    return 0;
-}
-
-/**
- * virConfParse:
- * @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.
- *
- * Returns a handle to lookup settings or NULL if it failed to
- *         read or parse the file, use virConfFree() to free the data.
- */
-static virConfPtr
-virConfParse(const char *filename, const char *content, int len,
-             unsigned int flags) {
-    virConfParserCtxt ctxt;
-
-    ctxt.filename = filename;
-    ctxt.base = ctxt.cur = content;
-    ctxt.end = content + len - 1;
-    ctxt.line = 1;
-
-    ctxt.conf = virConfCreate(filename, flags);
-    if (ctxt.conf == NULL)
-        return NULL;
-
-    while (ctxt.cur < ctxt.end) {
-        if (virConfParseStatement(&ctxt) < 0)
-            goto error;
-        if (virConfParseSeparator(&ctxt) < 0)
-            goto error;
-    }
-
-    return ctxt.conf;
-
-error:
-    virConfFree(ctxt.conf);
-    return NULL;
-}
-
-/************************************************************************
- *                                                                     *
- *                     The module entry points                         *
- *                                                                     *
- ************************************************************************/
-
-/* 10 MB limit on config file size as a sanity check */
-#define MAX_CONFIG_FILE_SIZE (1024*1024*10)
-
-/**
- * virConfReadFile:
- * @filename: the path to the configuration file.
- * @flags: combination of virConfFlag(s)
- *
- * Reads a configuration file.
- *
- * Returns a handle to lookup settings or NULL if it failed to
- *         read or parse the file, use virConfFree() to free the data.
- */
-virConfPtr
-virConfReadFile(const char *filename, unsigned int flags)
-{
-    char *content;
-    int len;
-    virConfPtr conf;
-
-    VIR_DEBUG("filename=%s", NULLSTR(filename));
-
-    if (filename == NULL) {
-        virConfError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return NULL;
-    }
-
-    if ((len = virFileReadAll(filename, MAX_CONFIG_FILE_SIZE, &content)) < 0) {
-        return NULL;
-    }
-
-    conf = virConfParse(filename, content, len, flags);
-
-    VIR_FREE(content);
-
-    return conf;
-}
-
-/**
- * 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
- *
- * 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)
-{
-    if ((memory == NULL) || (len < 0)) {
-        virConfError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return NULL;
-    }
-    if (len == 0)
-        len = strlen(memory);
-
-    return virConfParse("memory conf", memory, len, flags);
-}
-
-/**
- * virConfFree:
- * @conf: a configuration file handle
- *
- * Frees all data associated to the handle
- *
- * Returns 0 in case of success, -1 in case of error.
- */
-int
-virConfFree(virConfPtr conf)
-{
-    virConfEntryPtr tmp;
-    if (conf == NULL)
-        return 0;
-
-    tmp = conf->entries;
-    while (tmp) {
-        virConfEntryPtr next;
-        VIR_FREE(tmp->name);
-        virConfFreeValue(tmp->value);
-        VIR_FREE(tmp->comment);
-        next = tmp->next;
-        VIR_FREE(tmp);
-        tmp = next;
-    }
-    VIR_FREE(conf);
-    return 0;
-}
-
-/**
- * virConfGetValue:
- * @conf: a configuration file handle
- * @entry: the name of the entry
- *
- * Lookup the value associated to this entry in the configuration file
- *
- * Returns a pointer to the value or NULL if the lookup failed, the data
- *         associated will be freed when virConfFree() is called
- */
-virConfValuePtr
-virConfGetValue(virConfPtr conf, const char *setting)
-{
-    virConfEntryPtr cur;
-
-    if (conf == NULL)
-        return NULL;
-
-    cur = conf->entries;
-    while (cur != NULL) {
-        if ((cur->name != NULL) &&
-            ((conf->flags & VIR_CONF_FLAG_VMX_FORMAT &&
-              STRCASEEQ(cur->name, setting)) ||
-             STREQ(cur->name, setting)))
-            return cur->value;
-        cur = cur->next;
-    }
-    return NULL;
-}
-
-/**
- * virConfSetValue:
- * @conf: a configuration file handle
- * @entry: the name of the entry
- * @value: the new configuration value
- *
- * Set (or replace) the value associated to this entry in the configuration
- * file. The passed in 'value' will be owned by the conf object upon return
- * of this method, even in case of error. It should not be referenced again
- * by the caller.
- *
- * Returns 0 on success, or -1 on failure.
- */
-int
-virConfSetValue(virConfPtr conf,
-                const char *setting,
-                virConfValuePtr value)
-{
-    virConfEntryPtr cur, prev = NULL;
-
-    if (value && value->type == VIR_CONF_STRING && value->str == NULL)
-        return -1;
-
-    cur = conf->entries;
-    while (cur != NULL) {
-        if ((cur->name != NULL) && (STREQ(cur->name, setting))) {
-            break;
-        }
-        prev = cur;
-        cur = cur->next;
-    }
-
-    if (!cur) {
-        if (VIR_ALLOC(cur) < 0) {
-            virReportOOMError();
-            virConfFreeValue(value);
-            return -1;
-        }
-        cur->comment = NULL;
-        if (!(cur->name = strdup(setting))) {
-            virReportOOMError();
-            virConfFreeValue(value);
-            VIR_FREE(cur);
-            return -1;
-        }
-        cur->value = value;
-        if (prev) {
-            cur->next = prev->next;
-            prev->next = cur;
-        } else {
-            cur->next = conf->entries;
-            conf->entries = cur;
-        }
-    } else {
-        virConfFreeValue(cur->value);
-        cur->value = value;
-    }
-    return 0;
-}
-
-
-/**
- * virConfWriteFile:
- * @filename: the path to the configuration file.
- * @conf: the conf
- *
- * Writes a configuration file back to a file.
- *
- * Returns the number of bytes written or -1 in case of error.
- */
-int
-virConfWriteFile(const char *filename, virConfPtr conf)
-{
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
-    virConfEntryPtr cur;
-    int ret;
-    int fd;
-    char *content;
-    unsigned int use;
-
-    if (conf == NULL)
-        return -1;
-
-    cur = conf->entries;
-    while (cur != NULL) {
-        virConfSaveEntry(&buf, cur);
-        cur = cur->next;
-    }
-
-    if (virBufferError(&buf)) {
-        virBufferFreeAndReset(&buf);
-        virReportOOMError();
-        return -1;
-    }
-
-    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
-    if (fd < 0) {
-        virBufferFreeAndReset(&buf);
-        virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to open file"));
-        return -1;
-    }
-
-    use = virBufferUse(&buf);
-    content = virBufferContentAndReset(&buf);
-    ret = safewrite(fd, content, use);
-    VIR_FREE(content);
-    VIR_FORCE_CLOSE(fd);
-    if (ret != (int)use) {
-        virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to save content"));
-        return -1;
-    }
-
-    return ret;
-}
-
-/**
- * virConfWriteMem:
- * @memory: pointer to the memory to store the config file
- * @len: pointer to the length in bytes of the store, on output the size
- * @conf: the conf
- *
- * Writes a configuration file back to a memory area. @len is an IN/OUT
- * parameter, it indicates the size available in bytes, and on output the
- * size required for the configuration file (even if the call fails due to
- * insufficient space).
- *
- * Returns the number of bytes written or -1 in case of error.
- */
-int
-virConfWriteMem(char *memory, int *len, virConfPtr conf)
-{
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
-    virConfEntryPtr cur;
-    char *content;
-    unsigned int use;
-
-    if ((memory == NULL) || (len == NULL) || (*len <= 0) || (conf == NULL))
-        return -1;
-
-    cur = conf->entries;
-    while (cur != NULL) {
-        virConfSaveEntry(&buf, cur);
-        cur = cur->next;
-    }
-
-    if (virBufferError(&buf)) {
-        virBufferFreeAndReset(&buf);
-        virReportOOMError();
-        return -1;
-    }
-
-    use = virBufferUse(&buf);
-    content = virBufferContentAndReset(&buf);
-
-    if ((int)use >= *len) {
-        *len = (int)use;
-        VIR_FREE(content);
-        return -1;
-    }
-    memcpy(memory, content, use);
-    VIR_FREE(content);
-    *len = use;
-    return use;
-}
diff --git a/src/util/conf.h b/src/util/conf.h
deleted file mode 100644 (file)
index 224592d..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * conf.h: parser for a subset of the Python encoded Xen configuration files
- *
- * Copyright (C) 2006, 2007 Red Hat, Inc.
- *
- * 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/>.
- *
- * Daniel Veillard <veillard@redhat.com>
- */
-
-#ifndef __VIR_CONF_H__
-# define __VIR_CONF_H__
-
-/**
- * virConfType:
- * one of the possible type for a value from the configuration file
- *
- * TODO: we probably need a float too.
- */
-typedef enum {
-    VIR_CONF_NONE = 0,         /* undefined */
-    VIR_CONF_LONG = 1,         /* a long int */
-    VIR_CONF_STRING = 2,       /* a string */
-    VIR_CONF_LIST = 3          /* a list */
-} virConfType;
-
-typedef enum {
-    VIR_CONF_FLAG_VMX_FORMAT = 1,  /* allow ':', '.' and '-' in names for compatibility
-                                      with VMware VMX configuration file, but restrict
-                                      allowed value types to string only */
-} virConfFlags;
-
-static inline const char *
-virConfTypeName (virConfType t)
-{
-    switch (t) {
-    case VIR_CONF_LONG:
-        return "long";
-    case VIR_CONF_STRING:
-        return "string";
-    case VIR_CONF_LIST:
-        return "list";
-    default:
-        return "*unexpected*";
-    }
-}
-
-/**
- * virConfValue:
- * a value from the configuration file
- */
-typedef struct _virConfValue virConfValue;
-typedef virConfValue *virConfValuePtr;
-
-struct _virConfValue {
-    virConfType type;          /* the virConfType */
-    virConfValuePtr next;      /* next element if in a list */
-    long  l;                   /* long integer */
-    char *str;                 /* pointer to 0 terminated string */
-    virConfValuePtr list;      /* list of a list */
-};
-
-/**
- * virConfPtr:
- * a pointer to a parsed configuration file
- */
-typedef struct _virConf virConf;
-typedef virConf *virConfPtr;
-
-virConfPtr      virConfNew             (void);
-virConfPtr     virConfReadFile (const char *filename, unsigned int flags);
-virConfPtr     virConfReadMem          (const char *memory,
-                                         int len, unsigned int flags);
-int            virConfFree             (virConfPtr conf);
-void            virConfFreeValue      (virConfValuePtr val);
-
-virConfValuePtr        virConfGetValue (virConfPtr conf,
-                                         const char *setting);
-int             virConfSetValue        (virConfPtr conf,
-                                         const char *setting,
-                                         virConfValuePtr value);
-int            virConfWriteFile        (const char *filename,
-                                         virConfPtr conf);
-int            virConfWriteMem (char *memory,
-                                         int *len,
-                                         virConfPtr conf);
-
-#endif /* __VIR_CONF_H__ */
diff --git a/src/util/virconf.c b/src/util/virconf.c
new file mode 100644 (file)
index 0000000..695e6d8
--- /dev/null
@@ -0,0 +1,1032 @@
+/*
+ * virconf.c: parser for a subset of the Python encoded Xen configuration files
+ *
+ * Copyright (C) 2006-2012 Red Hat, Inc.
+ *
+ * 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/>.
+ *
+ * Daniel Veillard <veillard@redhat.com>
+ */
+
+#include <config.h>
+
+#include <string.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "virterror_internal.h"
+#include "virbuffer.h"
+#include "virconf.h"
+#include "util.h"
+#include "c-ctype.h"
+#include "logging.h"
+#include "memory.h"
+#include "virfile.h"
+
+#define VIR_FROM_THIS VIR_FROM_CONF
+
+/************************************************************************
+ *                                                                     *
+ *     Structures and macros used by the mini parser                   *
+ *                                                                     *
+ ************************************************************************/
+
+typedef struct _virConfParserCtxt virConfParserCtxt;
+typedef virConfParserCtxt *virConfParserCtxtPtr;
+
+struct _virConfParserCtxt {
+    const char* filename;
+    const char* base;
+    const char* cur;
+    const char *end;
+    int line;
+
+    virConfPtr conf;
+};
+
+#define CUR (*ctxt->cur)
+#define NEXT if (ctxt->cur < ctxt->end) ctxt->cur++;
+#define IS_EOL(c) (((c) == '\n') || ((c) == '\r'))
+
+#define SKIP_BLANKS_AND_EOL                                             \
+  do { while ((ctxt->cur < ctxt->end) && (c_isblank(CUR) || IS_EOL(CUR))) { \
+         if (CUR == '\n') ctxt->line++;                                        \
+         ctxt->cur++;}} while (0)
+#define SKIP_BLANKS                                                     \
+  do { while ((ctxt->cur < ctxt->end) && (c_isblank(CUR)))              \
+          ctxt->cur++; } while (0)
+
+/************************************************************************
+ *                                                                     *
+ *             Structures used by configuration data                   *
+ *                                                                     *
+ ************************************************************************/
+
+typedef struct _virConfEntry virConfEntry;
+typedef virConfEntry *virConfEntryPtr;
+
+struct _virConfEntry {
+    virConfEntryPtr next;
+    char* name;
+    char* comment;
+    virConfValuePtr value;
+};
+
+struct _virConf {
+    const char* filename;
+    unsigned int flags;
+    virConfEntryPtr entries;
+};
+
+/**
+ * virConfError:
+ * @ctxt: the parser context if available or NULL
+ * @error: the error number
+ * @info: extra information string
+ *
+ * Handle an error at the xend daemon interface
+ */
+#define virConfError(ctxt, error, info) \
+    virConfErrorHelper(__FILE__, __FUNCTION__, __LINE__, ctxt, error, info)
+static void
+virConfErrorHelper(const char *file, const char *func, size_t line,
+                   virConfParserCtxtPtr ctxt,
+                   virErrorNumber error, const char *info)
+{
+    if (error == VIR_ERR_OK)
+        return;
+
+    /* Construct the string 'filename:line: info' if we have that. */
+    if (ctxt && ctxt->filename) {
+        virReportErrorHelper(VIR_FROM_CONF, error, file, func, line,
+                             _("%s:%d: %s"), ctxt->filename, ctxt->line, info);
+    } else {
+        virReportErrorHelper(VIR_FROM_CONF, error, file, func, line,
+                             "%s", info);
+    }
+}
+
+
+/************************************************************************
+ *                                                                     *
+ *             Structures allocations and deallocations                *
+ *                                                                     *
+ ************************************************************************/
+
+/**
+ * virConfFreeList:
+ * @list: the list to free
+ *
+ * Free a list
+ */
+static void
+virConfFreeList(virConfValuePtr list)
+{
+    virConfValuePtr next;
+
+    while (list != NULL) {
+        next = list->next;
+        list->next = NULL;
+        virConfFreeValue(list);
+        list = next;
+    }
+}
+
+/**
+ * virConfFreeValue:
+ * @val: the value to free
+ *
+ * Free a value
+ */
+void
+virConfFreeValue(virConfValuePtr val)
+{
+    if (val == NULL)
+        return;
+    if (val->type == VIR_CONF_STRING &&
+        val->str != NULL)
+        VIR_FREE(val->str);
+    if (val->type == VIR_CONF_LIST &&
+        val->list != NULL)
+        virConfFreeList(val->list);
+    VIR_FREE(val);
+}
+
+virConfPtr
+virConfNew(void)
+{
+    virConfPtr ret;
+
+    if (VIR_ALLOC(ret) < 0) {
+        virReportOOMError();
+        return NULL;
+    }
+    ret->filename = NULL;
+    ret->flags = 0;
+
+    return ret;
+}
+
+/**
+ * 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, unsigned int flags)
+{
+    virConfPtr ret = virConfNew();
+    if (ret) {
+        ret->filename = filename;
+        ret->flags = flags;
+    }
+    return ret;
+}
+
+/**
+ * virConfAddEntry:
+ * @conf: the conf structure
+ * @name: name of the entry or NULL for comment
+ * @value: the value if any
+ * @comm: extra comment for that entry if any
+ *
+ * add one entry to the conf, the parameters are included in the conf
+ * if successful and freed on virConfFree()
+ *
+ * Returns a pointer to the entry or NULL in case of failure
+ */
+static virConfEntryPtr
+virConfAddEntry(virConfPtr conf, char *name, virConfValuePtr value, char *comm)
+{
+    virConfEntryPtr ret, prev;
+
+    if (conf == NULL)
+        return NULL;
+    if ((comm == NULL) && (name == NULL))
+        return NULL;
+
+    if (VIR_ALLOC(ret) < 0) {
+        virReportOOMError();
+        return NULL;
+    }
+
+    ret->name = name;
+    ret->value = value;
+    ret->comment = comm;
+
+    if (conf->entries == NULL) {
+        conf->entries = ret;
+    } else {
+        prev = conf->entries;
+        while (prev->next != NULL)
+            prev = prev->next;
+        prev->next = ret;
+    }
+    return ret;
+}
+
+/************************************************************************
+ *                                                                     *
+ *                     Serialization                                   *
+ *                                                                     *
+ ************************************************************************/
+
+/**
+ * virConfSaveValue:
+ * @buf: output buffer
+ * @val: a value
+ *
+ * Serialize the value to the buffer
+ *
+ * Returns 0 in case of success, -1 in case of error.
+ */
+static int
+virConfSaveValue(virBufferPtr buf, virConfValuePtr val)
+{
+    if (val == NULL)
+        return -1;
+    switch (val->type) {
+        case VIR_CONF_NONE:
+            return -1;
+        case VIR_CONF_LONG:
+            virBufferAsprintf(buf, "%ld", val->l);
+            break;
+        case VIR_CONF_STRING:
+            if (strchr(val->str, '\n') != NULL) {
+                virBufferAsprintf(buf, "\"\"\"%s\"\"\"", val->str);
+            } else if (strchr(val->str, '"') == NULL) {
+                virBufferAsprintf(buf, "\"%s\"", val->str);
+            } else if (strchr(val->str, '\'') == NULL) {
+                virBufferAsprintf(buf, "'%s'", val->str);
+            } else {
+                virBufferAsprintf(buf, "\"\"\"%s\"\"\"", val->str);
+            }
+            break;
+        case VIR_CONF_LIST: {
+            virConfValuePtr cur;
+
+            cur = val->list;
+            virBufferAddLit(buf, "[ ");
+            if (cur != NULL) {
+                virConfSaveValue(buf, cur);
+                cur = cur->next;
+                while (cur != NULL) {
+                    virBufferAddLit(buf, ", ");
+                    virConfSaveValue(buf, cur);
+                    cur = cur->next;
+                }
+            }
+            virBufferAddLit(buf, " ]");
+            break;
+        }
+        default:
+            return -1;
+    }
+    return 0;
+}
+
+/**
+ * virConfSaveEntry:
+ * @buf: output buffer
+ * @cur: a conf entry
+ *
+ * Serialize the entry to the buffer
+ *
+ * Returns 0 in case of success, -1 in case of error.
+ */
+static int
+virConfSaveEntry(virBufferPtr buf, virConfEntryPtr cur)
+{
+    if (cur->name != NULL) {
+        virBufferAdd(buf, cur->name, -1);
+        virBufferAddLit(buf, " = ");
+        virConfSaveValue(buf, cur->value);
+        if (cur->comment != NULL) {
+            virBufferAddLit(buf, " #");
+            virBufferAdd(buf, cur->comment, -1);
+        }
+    } else if (cur->comment != NULL) {
+        virBufferAddLit(buf, "#");
+        virBufferAdd(buf, cur->comment, -1);
+    }
+    virBufferAddLit(buf, "\n");
+    return 0;
+}
+
+/************************************************************************
+ *                                                                     *
+ *                     The parser core                                 *
+ *                                                                     *
+ ************************************************************************/
+
+/**
+ * virConfParseLong:
+ * @ctxt: the parsing context
+ * @val: the result
+ *
+ * Parse one long int value
+ *
+ * Returns 0 in case of success and -1 in case of error
+ */
+static int
+virConfParseLong(virConfParserCtxtPtr ctxt, long *val)
+{
+    long l = 0;
+    int neg = 0;
+
+    if (CUR == '-') {
+        neg = 1;
+        NEXT;
+    } else if (CUR == '+') {
+        NEXT;
+    }
+    if ((ctxt->cur >= ctxt->end) || (!c_isdigit(CUR))) {
+        virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated number"));
+        return -1;
+    }
+    while ((ctxt->cur < ctxt->end) && (c_isdigit(CUR))) {
+        l = l * 10 + (CUR - '0');
+        NEXT;
+    }
+    if (neg)
+        l = -l;
+    *val = l;
+    return 0;
+}
+
+/**
+ * virConfParseString:
+ * @ctxt: the parsing context
+ *
+ * Parse one string
+ *
+ * Returns a pointer to the string or NULL in case of error
+ */
+static char *
+virConfParseString(virConfParserCtxtPtr ctxt)
+{
+    const char *base;
+    char *ret = NULL;
+
+    if (CUR == '\'') {
+        NEXT;
+        base = ctxt->cur;
+        while ((ctxt->cur < ctxt->end) && (CUR != '\'') && (!IS_EOL(CUR)))
+            NEXT;
+        if (CUR != '\'') {
+            virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
+            return NULL;
+        }
+        ret = strndup(base, ctxt->cur - base);
+        if (ret == NULL) {
+            virReportOOMError();
+            return NULL;
+        }
+        NEXT;
+    } else if ((ctxt->cur + 6 < ctxt->end) &&
+               (STRPREFIX(ctxt->cur, "\"\"\""))) {
+        /* String starts with python-style triple quotes """ */
+        ctxt->cur += 3;
+        base = ctxt->cur;
+
+        /* Find the ending triple quotes */
+        while ((ctxt->cur + 2 < ctxt->end) &&
+               !(STRPREFIX(ctxt->cur, "\"\"\""))) {
+            if (CUR == '\n')
+                ctxt->line++;
+            NEXT;
+        }
+
+        if (!STRPREFIX(ctxt->cur, "\"\"\"")) {
+            virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
+            return NULL;
+        }
+        ret = strndup(base, ctxt->cur - base);
+        if (ret == NULL) {
+            virReportOOMError();
+            return NULL;
+        }
+        ctxt->cur += 3;
+    } else if (CUR == '"') {
+        NEXT;
+        base = ctxt->cur;
+        while ((ctxt->cur < ctxt->end) && (CUR != '"') && (!IS_EOL(CUR)))
+            NEXT;
+        if (CUR != '"') {
+            virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
+            return NULL;
+        }
+        ret = strndup(base, ctxt->cur - base);
+        if (ret == NULL) {
+            virReportOOMError();
+            return NULL;
+        }
+        NEXT;
+    }
+    return ret;
+}
+
+/**
+ * virConfParseValue:
+ * @ctxt: the parsing context
+ *
+ * Parse one value
+ *
+ * Returns a pointer to the value or NULL in case of error
+ */
+static virConfValuePtr
+virConfParseValue(virConfParserCtxtPtr ctxt)
+{
+    virConfValuePtr ret, lst = NULL, tmp, prev;
+    virConfType type = VIR_CONF_NONE;
+    char *str = NULL;
+    long  l = 0;
+
+    SKIP_BLANKS;
+    if (ctxt->cur >= ctxt->end) {
+        virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a value"));
+        return NULL;
+    }
+    if ((CUR == '"') || (CUR == '\'')) {
+        type = VIR_CONF_STRING;
+        str = virConfParseString(ctxt);
+        if (str == NULL)
+            return NULL;
+    } else if (CUR == '[') {
+        if (ctxt->conf->flags & VIR_CONF_FLAG_VMX_FORMAT) {
+            virConfError(ctxt, VIR_ERR_CONF_SYNTAX,
+                         _("lists not allowed in VMX format"));
+            return NULL;
+        }
+        type = VIR_CONF_LIST;
+        NEXT;
+        SKIP_BLANKS_AND_EOL;
+        if ((ctxt->cur < ctxt->end) && (CUR != ']')) {
+            if ((lst = virConfParseValue(ctxt)) == NULL)
+                return NULL;
+            SKIP_BLANKS_AND_EOL;
+        }
+        while ((ctxt->cur < ctxt->end) && (CUR != ']')) {
+
+            /* Tell Clang that when execution reaches this point
+               "lst" is guaranteed to be non-NULL.  This stops it
+               from issuing an invalid NULL-dereference warning about
+               "prev = lst; while (prev->next..." below.  */
+            sa_assert(lst);
+
+            if (CUR != ',') {
+                virConfError(ctxt, VIR_ERR_CONF_SYNTAX,
+                             _("expecting a separator in list"));
+                virConfFreeList(lst);
+                return NULL;
+            }
+            NEXT;
+            SKIP_BLANKS_AND_EOL;
+            if (CUR == ']') {
+                break;
+            }
+            tmp = virConfParseValue(ctxt);
+            if (tmp == NULL) {
+                virConfFreeList(lst);
+                return NULL;
+            }
+            prev = lst;
+            while (prev->next != NULL) prev = prev->next;
+            prev->next = tmp;
+            SKIP_BLANKS_AND_EOL;
+        }
+        if (CUR == ']') {
+            NEXT;
+        } else {
+            virConfError(ctxt, VIR_ERR_CONF_SYNTAX,
+                         _("list is not closed with ]"));
+            virConfFreeList(lst);
+            return NULL;
+        }
+    } else if (c_isdigit(CUR) || (CUR == '-') || (CUR == '+')) {
+        if (ctxt->conf->flags & VIR_CONF_FLAG_VMX_FORMAT) {
+            virConfError(ctxt, VIR_ERR_CONF_SYNTAX,
+                         _("numbers not allowed in VMX format"));
+            return NULL;
+        }
+        if (virConfParseLong(ctxt, &l) < 0) {
+            return NULL;
+        }
+        type = VIR_CONF_LONG;
+    } else {
+        virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a value"));
+        return NULL;
+    }
+    if (VIR_ALLOC(ret) < 0) {
+        virReportOOMError();
+        virConfFreeList(lst);
+        VIR_FREE(str);
+        return NULL;
+    }
+    ret->type = type;
+    ret->l = l;
+    ret->str = str;
+    ret->list = lst;
+    return ret;
+}
+
+/**
+ * virConfParseName:
+ * @ctxt: the parsing context
+ *
+ * Parse one name
+ *
+ * Returns a copy of the new string, NULL in case of error
+ */
+static char *
+virConfParseName(virConfParserCtxtPtr ctxt)
+{
+    const char *base;
+    char *ret;
+
+    SKIP_BLANKS;
+    base = ctxt->cur;
+    /* TODO: probably need encoding support and UTF-8 parsing ! */
+    if (!c_isalpha(CUR) &&
+        !((ctxt->conf->flags & VIR_CONF_FLAG_VMX_FORMAT) && (CUR == '.'))) {
+        virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a name"));
+        return NULL;
+    }
+    while ((ctxt->cur < ctxt->end) &&
+           (c_isalnum(CUR) || (CUR == '_') ||
+            ((ctxt->conf->flags & VIR_CONF_FLAG_VMX_FORMAT) &&
+             ((CUR == ':') || (CUR == '.') || (CUR == '-')))))
+        NEXT;
+    ret = strndup(base, ctxt->cur - base);
+    if (ret == NULL) {
+        virReportOOMError();
+        return NULL;
+    }
+    return ret;
+}
+
+/**
+ * virConfParseComment:
+ * @ctxt: the parsing context
+ *
+ * Parse one standalone comment in the configuration file
+ *
+ * Returns 0 in case of success and -1 in case of error
+ */
+static int
+virConfParseComment(virConfParserCtxtPtr ctxt)
+{
+    const char *base;
+    char *comm;
+
+    if (CUR != '#')
+        return -1;
+    NEXT;
+    base = ctxt->cur;
+    while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT;
+    comm = strndup(base, ctxt->cur - base);
+    if (comm == NULL) {
+        virReportOOMError();
+        return -1;
+    }
+    virConfAddEntry(ctxt->conf, NULL, NULL, comm);
+    return 0;
+}
+
+/**
+ * virConfParseSeparator:
+ * @ctxt: the parsing context
+ *
+ * Parse one separator between statement if not at the end.
+ *
+ * Returns 0 in case of success and -1 in case of error
+ */
+static int
+virConfParseSeparator(virConfParserCtxtPtr ctxt)
+{
+    SKIP_BLANKS;
+    if (ctxt->cur >= ctxt->end)
+        return 0;
+    if (IS_EOL(CUR)) {
+        SKIP_BLANKS_AND_EOL;
+    } else if (CUR == ';') {
+        NEXT;
+        SKIP_BLANKS_AND_EOL;
+    } else {
+        virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a separator"));
+        return -1;
+    }
+    return 0;
+}
+
+/**
+ * virConfParseStatement:
+ * @ctxt: the parsing context
+ *
+ * Parse one statement in the conf file
+ *
+ * Returns 0 in case of success and -1 in case of error
+ */
+static int
+virConfParseStatement(virConfParserCtxtPtr ctxt)
+{
+    const char *base;
+    char *name;
+    virConfValuePtr value;
+    char *comm = NULL;
+
+    SKIP_BLANKS_AND_EOL;
+    if (CUR == '#') {
+        return virConfParseComment(ctxt);
+    }
+    name = virConfParseName(ctxt);
+    if (name == NULL)
+        return -1;
+    SKIP_BLANKS;
+    if (CUR != '=') {
+        virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting an assignment"));
+        VIR_FREE(name);
+        return -1;
+    }
+    NEXT;
+    SKIP_BLANKS;
+    value = virConfParseValue(ctxt);
+    if (value == NULL) {
+        VIR_FREE(name);
+        return -1;
+    }
+    SKIP_BLANKS;
+    if (CUR == '#') {
+        NEXT;
+        base = ctxt->cur;
+        while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT;
+        comm = strndup(base, ctxt->cur - base);
+        if (comm == NULL) {
+            virReportOOMError();
+            VIR_FREE(name);
+            virConfFreeValue(value);
+            return -1;
+        }
+    }
+    if (virConfAddEntry(ctxt->conf, name, value, comm) == NULL) {
+        VIR_FREE(name);
+        virConfFreeValue(value);
+        VIR_FREE(comm);
+        return -1;
+    }
+    return 0;
+}
+
+/**
+ * virConfParse:
+ * @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.
+ *
+ * Returns a handle to lookup settings or NULL if it failed to
+ *         read or parse the file, use virConfFree() to free the data.
+ */
+static virConfPtr
+virConfParse(const char *filename, const char *content, int len,
+             unsigned int flags) {
+    virConfParserCtxt ctxt;
+
+    ctxt.filename = filename;
+    ctxt.base = ctxt.cur = content;
+    ctxt.end = content + len - 1;
+    ctxt.line = 1;
+
+    ctxt.conf = virConfCreate(filename, flags);
+    if (ctxt.conf == NULL)
+        return NULL;
+
+    while (ctxt.cur < ctxt.end) {
+        if (virConfParseStatement(&ctxt) < 0)
+            goto error;
+        if (virConfParseSeparator(&ctxt) < 0)
+            goto error;
+    }
+
+    return ctxt.conf;
+
+error:
+    virConfFree(ctxt.conf);
+    return NULL;
+}
+
+/************************************************************************
+ *                                                                     *
+ *                     The module entry points                         *
+ *                                                                     *
+ ************************************************************************/
+
+/* 10 MB limit on config file size as a sanity check */
+#define MAX_CONFIG_FILE_SIZE (1024*1024*10)
+
+/**
+ * virConfReadFile:
+ * @filename: the path to the configuration file.
+ * @flags: combination of virConfFlag(s)
+ *
+ * Reads a configuration file.
+ *
+ * Returns a handle to lookup settings or NULL if it failed to
+ *         read or parse the file, use virConfFree() to free the data.
+ */
+virConfPtr
+virConfReadFile(const char *filename, unsigned int flags)
+{
+    char *content;
+    int len;
+    virConfPtr conf;
+
+    VIR_DEBUG("filename=%s", NULLSTR(filename));
+
+    if (filename == NULL) {
+        virConfError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return NULL;
+    }
+
+    if ((len = virFileReadAll(filename, MAX_CONFIG_FILE_SIZE, &content)) < 0) {
+        return NULL;
+    }
+
+    conf = virConfParse(filename, content, len, flags);
+
+    VIR_FREE(content);
+
+    return conf;
+}
+
+/**
+ * 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
+ *
+ * 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)
+{
+    if ((memory == NULL) || (len < 0)) {
+        virConfError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return NULL;
+    }
+    if (len == 0)
+        len = strlen(memory);
+
+    return virConfParse("memory conf", memory, len, flags);
+}
+
+/**
+ * virConfFree:
+ * @conf: a configuration file handle
+ *
+ * Frees all data associated to the handle
+ *
+ * Returns 0 in case of success, -1 in case of error.
+ */
+int
+virConfFree(virConfPtr conf)
+{
+    virConfEntryPtr tmp;
+    if (conf == NULL)
+        return 0;
+
+    tmp = conf->entries;
+    while (tmp) {
+        virConfEntryPtr next;
+        VIR_FREE(tmp->name);
+        virConfFreeValue(tmp->value);
+        VIR_FREE(tmp->comment);
+        next = tmp->next;
+        VIR_FREE(tmp);
+        tmp = next;
+    }
+    VIR_FREE(conf);
+    return 0;
+}
+
+/**
+ * virConfGetValue:
+ * @conf: a configuration file handle
+ * @entry: the name of the entry
+ *
+ * Lookup the value associated to this entry in the configuration file
+ *
+ * Returns a pointer to the value or NULL if the lookup failed, the data
+ *         associated will be freed when virConfFree() is called
+ */
+virConfValuePtr
+virConfGetValue(virConfPtr conf, const char *setting)
+{
+    virConfEntryPtr cur;
+
+    if (conf == NULL)
+        return NULL;
+
+    cur = conf->entries;
+    while (cur != NULL) {
+        if ((cur->name != NULL) &&
+            ((conf->flags & VIR_CONF_FLAG_VMX_FORMAT &&
+              STRCASEEQ(cur->name, setting)) ||
+             STREQ(cur->name, setting)))
+            return cur->value;
+        cur = cur->next;
+    }
+    return NULL;
+}
+
+/**
+ * virConfSetValue:
+ * @conf: a configuration file handle
+ * @entry: the name of the entry
+ * @value: the new configuration value
+ *
+ * Set (or replace) the value associated to this entry in the configuration
+ * file. The passed in 'value' will be owned by the conf object upon return
+ * of this method, even in case of error. It should not be referenced again
+ * by the caller.
+ *
+ * Returns 0 on success, or -1 on failure.
+ */
+int
+virConfSetValue(virConfPtr conf,
+                const char *setting,
+                virConfValuePtr value)
+{
+    virConfEntryPtr cur, prev = NULL;
+
+    if (value && value->type == VIR_CONF_STRING && value->str == NULL)
+        return -1;
+
+    cur = conf->entries;
+    while (cur != NULL) {
+        if ((cur->name != NULL) && (STREQ(cur->name, setting))) {
+            break;
+        }
+        prev = cur;
+        cur = cur->next;
+    }
+
+    if (!cur) {
+        if (VIR_ALLOC(cur) < 0) {
+            virReportOOMError();
+            virConfFreeValue(value);
+            return -1;
+        }
+        cur->comment = NULL;
+        if (!(cur->name = strdup(setting))) {
+            virReportOOMError();
+            virConfFreeValue(value);
+            VIR_FREE(cur);
+            return -1;
+        }
+        cur->value = value;
+        if (prev) {
+            cur->next = prev->next;
+            prev->next = cur;
+        } else {
+            cur->next = conf->entries;
+            conf->entries = cur;
+        }
+    } else {
+        virConfFreeValue(cur->value);
+        cur->value = value;
+    }
+    return 0;
+}
+
+
+/**
+ * virConfWriteFile:
+ * @filename: the path to the configuration file.
+ * @conf: the conf
+ *
+ * Writes a configuration file back to a file.
+ *
+ * Returns the number of bytes written or -1 in case of error.
+ */
+int
+virConfWriteFile(const char *filename, virConfPtr conf)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+    virConfEntryPtr cur;
+    int ret;
+    int fd;
+    char *content;
+    unsigned int use;
+
+    if (conf == NULL)
+        return -1;
+
+    cur = conf->entries;
+    while (cur != NULL) {
+        virConfSaveEntry(&buf, cur);
+        cur = cur->next;
+    }
+
+    if (virBufferError(&buf)) {
+        virBufferFreeAndReset(&buf);
+        virReportOOMError();
+        return -1;
+    }
+
+    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
+    if (fd < 0) {
+        virBufferFreeAndReset(&buf);
+        virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to open file"));
+        return -1;
+    }
+
+    use = virBufferUse(&buf);
+    content = virBufferContentAndReset(&buf);
+    ret = safewrite(fd, content, use);
+    VIR_FREE(content);
+    VIR_FORCE_CLOSE(fd);
+    if (ret != (int)use) {
+        virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to save content"));
+        return -1;
+    }
+
+    return ret;
+}
+
+/**
+ * virConfWriteMem:
+ * @memory: pointer to the memory to store the config file
+ * @len: pointer to the length in bytes of the store, on output the size
+ * @conf: the conf
+ *
+ * Writes a configuration file back to a memory area. @len is an IN/OUT
+ * parameter, it indicates the size available in bytes, and on output the
+ * size required for the configuration file (even if the call fails due to
+ * insufficient space).
+ *
+ * Returns the number of bytes written or -1 in case of error.
+ */
+int
+virConfWriteMem(char *memory, int *len, virConfPtr conf)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+    virConfEntryPtr cur;
+    char *content;
+    unsigned int use;
+
+    if ((memory == NULL) || (len == NULL) || (*len <= 0) || (conf == NULL))
+        return -1;
+
+    cur = conf->entries;
+    while (cur != NULL) {
+        virConfSaveEntry(&buf, cur);
+        cur = cur->next;
+    }
+
+    if (virBufferError(&buf)) {
+        virBufferFreeAndReset(&buf);
+        virReportOOMError();
+        return -1;
+    }
+
+    use = virBufferUse(&buf);
+    content = virBufferContentAndReset(&buf);
+
+    if ((int)use >= *len) {
+        *len = (int)use;
+        VIR_FREE(content);
+        return -1;
+    }
+    memcpy(memory, content, use);
+    VIR_FREE(content);
+    *len = use;
+    return use;
+}
diff --git a/src/util/virconf.h b/src/util/virconf.h
new file mode 100644 (file)
index 0000000..577af8c
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * virconf.h: parser for a subset of the Python encoded Xen configuration files
+ *
+ * Copyright (C) 2006, 2007 Red Hat, Inc.
+ *
+ * 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/>.
+ *
+ * Daniel Veillard <veillard@redhat.com>
+ */
+
+#ifndef __VIR_CONF_H__
+# define __VIR_CONF_H__
+
+/**
+ * virConfType:
+ * one of the possible type for a value from the configuration file
+ *
+ * TODO: we probably need a float too.
+ */
+typedef enum {
+    VIR_CONF_NONE = 0,         /* undefined */
+    VIR_CONF_LONG = 1,         /* a long int */
+    VIR_CONF_STRING = 2,       /* a string */
+    VIR_CONF_LIST = 3          /* a list */
+} virConfType;
+
+typedef enum {
+    VIR_CONF_FLAG_VMX_FORMAT = 1,  /* allow ':', '.' and '-' in names for compatibility
+                                      with VMware VMX configuration file, but restrict
+                                      allowed value types to string only */
+} virConfFlags;
+
+static inline const char *
+virConfTypeName (virConfType t)
+{
+    switch (t) {
+    case VIR_CONF_LONG:
+        return "long";
+    case VIR_CONF_STRING:
+        return "string";
+    case VIR_CONF_LIST:
+        return "list";
+    default:
+        return "*unexpected*";
+    }
+}
+
+/**
+ * virConfValue:
+ * a value from the configuration file
+ */
+typedef struct _virConfValue virConfValue;
+typedef virConfValue *virConfValuePtr;
+
+struct _virConfValue {
+    virConfType type;          /* the virConfType */
+    virConfValuePtr next;      /* next element if in a list */
+    long  l;                   /* long integer */
+    char *str;                 /* pointer to 0 terminated string */
+    virConfValuePtr list;      /* list of a list */
+};
+
+/**
+ * virConfPtr:
+ * a pointer to a parsed configuration file
+ */
+typedef struct _virConf virConf;
+typedef virConf *virConfPtr;
+
+virConfPtr      virConfNew             (void);
+virConfPtr     virConfReadFile (const char *filename, unsigned int flags);
+virConfPtr     virConfReadMem          (const char *memory,
+                                         int len, unsigned int flags);
+int            virConfFree             (virConfPtr conf);
+void            virConfFreeValue      (virConfValuePtr val);
+
+virConfValuePtr        virConfGetValue (virConfPtr conf,
+                                         const char *setting);
+int             virConfSetValue        (virConfPtr conf,
+                                         const char *setting,
+                                         virConfValuePtr value);
+int            virConfWriteFile        (const char *filename,
+                                         virConfPtr conf);
+int            virConfWriteMem (char *memory,
+                                         int *len,
+                                         virConfPtr conf);
+
+#endif /* __VIR_CONF_H__ */
index a4d1f2e99ce04b78f777344de5455efa36a69c9e..4de9f3382092683ca2a596a375ac24107e144bb8 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "internal.h"
 #include "virterror_internal.h"
-#include "conf.h"
+#include "virconf.h"
 #include "memory.h"
 #include "logging.h"
 #include "uuid.h"
index 406c27ee90d4f4f3c1c3587a5d5a6306aec80f5a..f4877b11c405cb65cc45187cb196a766b049c71f 100644 (file)
@@ -24,7 +24,7 @@
 # define __VIR_VMX_H__
 
 # include "internal.h"
-# include "conf.h"
+# include "virconf.h"
 # include "domain_conf.h"
 
 typedef struct _virVMXContext virVMXContext;
index 2e40015bd41dd455bf46611b263f12c1c9db4115..bcafdd089af84f5071df2ecee2a87ae7f7e06db7 100644 (file)
@@ -32,7 +32,7 @@
 #include "driver.h"
 #include "memory.h"
 #include "xen_driver.h"
-#include "conf.h"
+#include "virconf.h"
 #include "domain_conf.h"
 #include "xen_inotify.h"
 #include "xend_internal.h"
index 98b5ad7bdace17ed259000398cede3f81dfa2989..df77ac80cda5790a532568e42657efa0ff09ed8f 100644 (file)
@@ -27,7 +27,7 @@
 
 # include "internal.h"
 # include "driver.h"
-# include "conf.h"
+# include "virconf.h"
 # include "domain_conf.h"
 
 extern struct xenUnifiedDriver xenXMDriver;
index 3e8396b1781040942ce47d548cd46eb3d677ae78..ed0c9e10e68d2be0756b370aae24714edebf7a43 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "internal.h"
 #include "virterror_internal.h"
-#include "conf.h"
+#include "virconf.h"
 #include "memory.h"
 #include "verify.h"
 #include "uuid.h"
index d4502bd0e940f02a9a2b228350e44ce819f8de97..4ff640c40a5da35e468ffce074fcb6f3ce2620be 100644 (file)
@@ -28,7 +28,7 @@
 # define __VIR_XEN_SXPR_H__
 
 # include "internal.h"
-# include "conf.h"
+# include "virconf.h"
 # include "domain_conf.h"
 # include "sexpr.h"
 
index d1197cde0d4a2063b250e3687062284a1509df2f..5e284df7cf1920a61aca94c7059bad57fc92f409 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "internal.h"
 #include "virterror_internal.h"
-#include "conf.h"
+#include "virconf.h"
 #include "memory.h"
 #include "verify.h"
 #include "uuid.h"
index c3d0ad46b1516474e298eee15053689a225abc00..629a4b32632dbe3eee8198b682fc1c95d0241569 100644 (file)
@@ -27,7 +27,7 @@
 # define __VIR_XEN_XM_H__
 
 # include "internal.h"
-# include "conf.h"
+# include "virconf.h"
 # include "domain_conf.h"
 
 virConfPtr xenFormatXM(virConnectPtr conn, virDomainDefPtr def,
index 4342a5253dcc041fa2b6ff9d80085e8fc923394b..aacc5265dd9184aa047812bc974a1f0a9c835d37 100644 (file)
@@ -5,7 +5,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
-#include "conf.h"
+#include "virconf.h"
 #include "memory.h"
 
 int main(int argc, char **argv)
index ee1f8a0c607533035afa0e591fc5f7a5572a588b..c2b02a6e40d3f276b418a2b9dac722df252ae61a 100644 (file)
@@ -28,7 +28,7 @@
 #include "c-ctype.h"
 #include "virterror_internal.h"
 #include "logging.h"
-#include "conf.h"
+#include "virconf.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE