sexpr.h 1.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * sexpr.h : S-Expression interfaces needed to communicate with the Xen Daemon
 *
 * Copyright (C) 2005
 *
 *      Anthony Liguori <aliguori@us.ibm.com>
 *
 *  This file is subject to the terms and conditions of the GNU Lesser General
 *  Public License. See the file COPYING.LIB in the main directory of this
 *  archive for more details.
 */

#ifndef _LIBVIR_SEXPR_H_
#define _LIBVIR_SEXPR_H_

16 17
#include "internal.h"

18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <sys/types.h>

enum sexpr_type {
    SEXPR_NIL,
    SEXPR_CONS,
    SEXPR_VALUE,
};

struct sexpr {
    enum sexpr_type kind;
    union {
        struct {
            struct sexpr *car;
            struct sexpr *cdr;
32
        } s;
33
        char *value;
34
    } u;
35 36 37
};

/* conversion to/from strings */
38 39
size_t sexpr2string(struct sexpr *sexpr, char *buffer, size_t n_buffer);
struct sexpr *string2sexpr(const char *buffer);
40 41

/* constructors and destructors */
42 43 44 45 46
struct sexpr *sexpr_nil(void);
struct sexpr *sexpr_string(const char *str, ssize_t len);
struct sexpr *sexpr_cons(struct sexpr *car, struct sexpr *cdr);
struct sexpr *sexpr_append(struct sexpr *lst, struct sexpr *item);
void sexpr_free(struct sexpr *sexpr);
47 48

/* lookup in S-Expressions */
49
const char *sexpr_node(struct sexpr *sexpr, const char *node);
50 51
const char *sexpr_fmt_node(struct sexpr *sexpr, const char *fmt, ...)
  ATTRIBUTE_FORMAT(printf,2,3);
52
struct sexpr *sexpr_lookup(struct sexpr *sexpr, const char *node);
D
Daniel P. Berrange 已提交
53
int sexpr_has(struct sexpr *sexpr, const char *node);
54
#endif