virconf.h 4.7 KB
Newer Older
1 2
/*
 * virconf.h: parser for a subset of the Python encoded Xen configuration files
D
Daniel Veillard 已提交
3
 *
4
 * Copyright (C) 2006, 2007 Red Hat, Inc.
D
Daniel Veillard 已提交
5
 *
O
Osier Yang 已提交
6 7 8 9 10 11 12 13 14 15 16
 * 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
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
D
Daniel Veillard 已提交
19 20
 */

21
#pragma once
D
Daniel Veillard 已提交
22

23 24
#include "virutil.h"
#include "virenum.h"
25

D
Daniel Veillard 已提交
26 27 28 29 30 31 32
/**
 * virConfType:
 * one of the possible type for a value from the configuration file
 *
 * TODO: we probably need a float too.
 */
typedef enum {
33
    VIR_CONF_NONE = 0,      /* undefined */
34 35
    VIR_CONF_LLONG,         /* a long long int */
    VIR_CONF_ULLONG,        /* an unsigned long long int */
36 37 38
    VIR_CONF_STRING,        /* a string */
    VIR_CONF_LIST,          /* a list */
    VIR_CONF_LAST,          /* sentinel */
D
Daniel Veillard 已提交
39 40
} virConfType;

41
VIR_ENUM_DECL(virConf);
42

43
typedef enum {
44 45
    VIR_CONF_FLAG_VMX_FORMAT = 1,  /* allow ':', '.' and '-' in names for compatibility
                                      with VMware VMX configuration file, but restrict
46
                                      allowed value types to string only */
47 48 49
    VIR_CONF_FLAG_LXC_FORMAT = 2,  /* allow '.' in names for compatibility with LXC
                                      configuration file, restricts allowed value types
                                      to string only and don't expect quotes for values */
50 51
} virConfFlags;

D
Daniel Veillard 已提交
52 53 54 55 56 57 58 59
/**
 * virConfValue:
 * a value from the configuration file
 */
typedef struct _virConfValue virConfValue;
typedef virConfValue *virConfValuePtr;

struct _virConfValue {
60 61 62 63 64
    virConfType type;           /* the virConfType */
    virConfValuePtr next;       /* next element if in a list */
    long long  l;               /* very long integer */
    char *str;                  /* pointer to 0 terminated string */
    virConfValuePtr list;       /* list of a list */
D
Daniel Veillard 已提交
65 66 67 68 69 70 71 72 73
};

/**
 * virConfPtr:
 * a pointer to a parsed configuration file
 */
typedef struct _virConf virConf;
typedef virConf *virConfPtr;

74 75 76 77
typedef int (*virConfWalkCallback)(const char* name,
                                   virConfValuePtr value,
                                   void *opaque);

C
Cao jin 已提交
78 79
virConfPtr virConfNew(void);
virConfPtr virConfReadFile(const char *filename, unsigned int flags);
J
Ján Tomko 已提交
80 81
virConfPtr virConfReadString(const char *memory,
                             unsigned int flags);
C
Cao jin 已提交
82 83 84 85
int virConfFree(virConfPtr conf);
void virConfFreeValue(virConfValuePtr val);
virConfValuePtr virConfGetValue(virConfPtr conf,
                                const char *setting);
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117

virConfType virConfGetValueType(virConfPtr conf,
                                const char *setting);
int virConfGetValueString(virConfPtr conf,
                          const char *setting,
                          char **value);
int virConfGetValueStringList(virConfPtr conf,
                              const char *setting,
                              bool compatString,
                              char ***values);
int virConfGetValueBool(virConfPtr conf,
                        const char *setting,
                        bool *value);
int virConfGetValueInt(virConfPtr conf,
                       const char *setting,
                       int *value);
int virConfGetValueUInt(virConfPtr conf,
                        const char *setting,
                        unsigned int *value);
int virConfGetValueSizeT(virConfPtr conf,
                         const char *setting,
                         size_t *value);
int virConfGetValueSSizeT(virConfPtr conf,
                          const char *setting,
                          ssize_t *value);
int virConfGetValueLLong(virConfPtr conf,
                        const char *setting,
                        long long *value);
int virConfGetValueULLong(virConfPtr conf,
                          const char *setting,
                          unsigned long long *value);

C
Cao jin 已提交
118 119 120
int virConfSetValue(virConfPtr conf,
                    const char *setting,
                    virConfValuePtr value);
121 122 123
int virConfWalk(virConfPtr conf,
                virConfWalkCallback callback,
                void *opaque);
C
Cao jin 已提交
124 125 126 127 128
int virConfWriteFile(const char *filename,
                     virConfPtr conf);
int virConfWriteMem(char *memory,
                    int *len,
                    virConfPtr conf);
129
int virConfLoadConfig(virConfPtr *conf, const char *name);