virconf.h 3.5 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 22 23
 *
 * Daniel Veillard <veillard@redhat.com>
 */

#ifndef __VIR_CONF_H__
24
# define __VIR_CONF_H__
D
Daniel Veillard 已提交
25

26 27
# include "virutil.h"

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

42 43
VIR_ENUM_DECL(virConf)

44
typedef enum {
45 46
    VIR_CONF_FLAG_VMX_FORMAT = 1,  /* allow ':', '.' and '-' in names for compatibility
                                      with VMware VMX configuration file, but restrict
47
                                      allowed value types to string only */
48 49 50
    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 */
51 52
} virConfFlags;

D
Daniel Veillard 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
/**
 * 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;

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

D
Daniel P. Berrange 已提交
79
virConfPtr      virConfNew             (void);
80
virConfPtr	virConfReadFile	(const char *filename, unsigned int flags);
D
Daniel P. Berrange 已提交
81
virConfPtr	virConfReadMem		(const char *memory,
82
                                         int len, unsigned int flags);
D
Daniel P. Berrange 已提交
83 84
int		virConfFree		(virConfPtr conf);
void            virConfFreeValue      (virConfValuePtr val);
D
Daniel Veillard 已提交
85

D
Daniel P. Berrange 已提交
86
virConfValuePtr	virConfGetValue	(virConfPtr conf,
87
                                         const char *setting);
D
Daniel P. Berrange 已提交
88
int             virConfSetValue        (virConfPtr conf,
89 90
                                         const char *setting,
                                         virConfValuePtr value);
91 92 93
int virConfWalk(virConfPtr conf,
                virConfWalkCallback callback,
                void *opaque);
D
Daniel P. Berrange 已提交
94
int		virConfWriteFile	(const char *filename,
95
                                         virConfPtr conf);
D
Daniel P. Berrange 已提交
96
int		virConfWriteMem	(char *memory,
97 98
                                         int *len,
                                         virConfPtr conf);
D
Daniel Veillard 已提交
99 100

#endif /* __VIR_CONF_H__ */