conf.h 2.7 KB
Newer Older
D
Daniel Veillard 已提交
1 2 3
/**
 * conf.h: parser for a subset of the Python encoded Xen configuration files
 *
4
 * Copyright (C) 2006, 2007 Red Hat, Inc.
D
Daniel Veillard 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * See COPYING.LIB for the License of this software
 *
 * 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;

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
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*";
    }
}

D
Daniel Veillard 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
/**
 * 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;

64 65 66
virConfPtr      __virConfNew             (void);
virConfPtr	__virConfReadFile	(const char *filename);
virConfPtr	__virConfReadMem		(const char *memory,
67
                                         int len);
68
int		__virConfFree		(virConfPtr conf);
69
void            __virConfFreeValue      (virConfValuePtr val);
D
Daniel Veillard 已提交
70

71
virConfValuePtr	__virConfGetValue	(virConfPtr conf,
72
                                         const char *setting);
73
int             __virConfSetValue        (virConfPtr conf,
74 75
                                         const char *setting,
                                         virConfValuePtr value);
76
int		__virConfWriteFile	(const char *filename,
77
                                         virConfPtr conf);
78
int		__virConfWriteMem	(char *memory,
79 80
                                         int *len,
                                         virConfPtr conf);
D
Daniel Veillard 已提交
81

82 83 84 85 86 87 88 89 90
#define virConfNew() __virConfNew()
#define virConfReadFile(f) __virConfReadFile((f))
#define virConfReadMem(m,l) __virConfReadMem((m),(l))
#define virConfFree(c) __virConfFree((c))
#define virConfFreeValue(v) __virConfFreeValue((v))
#define virConfGetValue(c,s) __virConfGetValue((c),(s))
#define virConfSetValue(c,s,v) __virConfSetValue((c),(s),(v))
#define virConfWriteFile(f,c) __virConfWriteFile((f),(c))
#define virConfWriteMem(m,l,c) __virConfWriteMem((m),(l),(c))
91

D
Daniel Veillard 已提交
92
#endif /* __VIR_CONF_H__ */