debuggers.hg

changeset 21040:71af69a9d393

Replace config file parser for "xl"

This provides a replacement config file parser for "xl" based on bison
and flex.

Benefits:
* proper error reporting with line numbers
* parser can understand nearly all "xm" configuration files directly
(doesn't understand Python code but should do everything else)
* parser also understands the ;-infested "xl" style files
* removes the dependency on libconfig
* better checking for certain kinds of mistakes
* eliminates the strange "massage file and try again" code

This is intended to support all config files currently supported by
"xl" and almost all files supported by "xm". (NB that whether a
feature works depends on the implementation of that feature in
xl/libxl of course.)

This patch also introduces a new library "libxlutil" which is mainly
for the benefit of "xl". Users of libxl do not need to use libxlutil,
but they can do so if they want to parse "xl" files without being
"xl".

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Mar 03 17:39:22 2010 +0000 (2010-03-03)
parents 4554b305228a
children 6c338a5830b5
files .hgignore Config.mk README tools/libxl/Makefile tools/libxl/libxlu_cfg.c tools/libxl/libxlu_cfg_i.h tools/libxl/libxlu_cfg_l.l tools/libxl/libxlu_cfg_y.y tools/libxl/libxlu_internal.h tools/libxl/libxlutil.h tools/libxl/xl.c
line diff
     1.1 --- a/.hgignore	Tue Mar 02 14:05:35 2010 +0000
     1.2 +++ b/.hgignore	Wed Mar 03 17:39:22 2010 +0000
     1.3 @@ -180,7 +180,8 @@
     1.4  ^tools/libxen/libxenapi-
     1.5  ^tools/libxen/test/test_bindings$
     1.6  ^tools/libxen/test/test_event_handling$
     1.7 -^tools/libxl/libconfig.*$
     1.8 +^tools/libxl/libxlu_cfg_[yl]\.[ch]$
     1.9 +^tools/libxl/libxlu_cfg_y\.output
    1.10  ^tools/libxl/xl$
    1.11  ^tools/libaio/src/.*\.ol$
    1.12  ^tools/libaio/src/.*\.os$
     2.1 --- a/Config.mk	Tue Mar 02 14:05:35 2010 +0000
     2.2 +++ b/Config.mk	Wed Mar 03 17:39:22 2010 +0000
     2.3 @@ -35,6 +35,9 @@ EXTRA_INCLUDES += $(EXTRA_PREFIX)/includ
     2.4  EXTRA_LIB += $(EXTRA_PREFIX)/$(LIBLEAFDIR)
     2.5  endif
     2.6  
     2.7 +BISON	?= bison
     2.8 +FLEX	?= flex
     2.9 +
    2.10  PYTHON      ?= python
    2.11  PYTHON_PREFIX_ARG ?= --prefix="$(PREFIX)"
    2.12  # The above requires that PREFIX contains *no spaces*. This variable is here
     3.1 --- a/README	Tue Mar 02 14:05:35 2010 +0000
     3.2 +++ b/README	Wed Mar 03 17:39:22 2010 +0000
     3.3 @@ -49,6 +49,7 @@ provided by your Linux distributor:
     3.4      * bridge-utils package (/sbin/brctl)
     3.5      * iproute package (/sbin/ip)
     3.6      * hotplug or udev
     3.7 +    * GNU bison and GNU flex
     3.8  
     3.9  [NB. Unless noted otherwise, all the following steps should be
    3.10  performed with root privileges.]
     4.1 --- a/tools/libxl/Makefile	Tue Mar 02 14:05:35 2010 +0000
     4.2 +++ b/tools/libxl/Makefile	Wed Mar 03 17:39:22 2010 +0000
     4.3 @@ -8,24 +8,40 @@ include $(XEN_ROOT)/tools/Rules.mk
     4.4  MAJOR = 1.0
     4.5  MINOR = 0
     4.6  
     4.7 +XLUMAJOR = 1.0
     4.8 +XLUMINOR = 0
     4.9 +
    4.10  #CFLAGS += -Werror
    4.11  CFLAGS += -I. -fPIC
    4.12  CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore)
    4.13  
    4.14  LIBS = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore)
    4.15  
    4.16 -#LIBCONFIG_URL ?= http://www.hyperrealm.com/libconfig
    4.17 -LIBCONFIG_URL = $(XEN_EXTFILES_URL)
    4.18 -LIBCONFIG_SOURCE = libconfig-1.3.2
    4.19 -LIBCONFIG_OUTPUT = $(LIBCONFIG_SOURCE)/.libs
    4.20 -
    4.21  LIBXL_OBJS-y = osdeps.o
    4.22  LIBXL_OBJS = flexarray.o libxl.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o xenguest.o libxl_utils.o $(LIBXL_OBJS-y)
    4.23  
    4.24 +AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h
    4.25 +AUTOSRCS= libxlu_cfg_y.c libxlu_cfg_l.c
    4.26 +LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o
    4.27 +
    4.28  CLIENTS = xl
    4.29  
    4.30  .PHONY: all
    4.31 -all: $(CLIENTS) libxenlight.so libxenlight.a
    4.32 +all: $(CLIENTS) libxenlight.so libxenlight.a libxlutil.so libxlutil.a \
    4.33 +	$(AUTOSRCS) $(AUTOINCS)
    4.34 +
    4.35 +$(AUTOINCS): $(AUTOSRCS)
    4.36 +
    4.37 +#%_y.h: %_y.c
    4.38 +#%_l.h: %_l.c
    4.39 +
    4.40 +$(LIBXLU_OBJS): $(AUTOINCS)
    4.41 +
    4.42 +%.c: %.y
    4.43 +	$(BISON) --output=$@ $<
    4.44 +
    4.45 +%.c: %.l
    4.46 +	$(FLEX) --header-file=$*.h --outfile=$@ $<
    4.47  
    4.48  libxenlight.so: libxenlight.so.$(MAJOR)
    4.49  	ln -sf $< $@
    4.50 @@ -39,18 +55,23 @@ libxenlight.so.$(MAJOR).$(MINOR): $(LIBX
    4.51  libxenlight.a: $(LIBXL_OBJS)
    4.52  	$(AR) rcs libxenlight.a $^
    4.53  
    4.54 -$(LIBCONFIG_SOURCE).tar.gz:
    4.55 -	$(WGET) $(LIBCONFIG_URL)/$@
    4.56 +libxlutil.so: libxlutil.so.$(XLUMAJOR)
    4.57 +	ln -sf $< $@
    4.58 +
    4.59 +libxlutil.so.$(XLUMAJOR): libxlutil.so.$(XLUMAJOR).$(XLUMINOR)
    4.60 +	ln -sf $< $@
    4.61 +
    4.62 +libxlutil.so.$(XLUMAJOR).$(XLUMINOR): $(LIBXLU_OBJS)
    4.63 +	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxlutil.so.$(XLUMAJOR) $(SHLIB_CFLAGS) -o $@ $^
    4.64  
    4.65 -$(LIBCONFIG_OUTPUT)/libconfig.so: $(LIBCONFIG_SOURCE).tar.gz
    4.66 -	[ ! -d "$(LIBCONFIG_SOURCE)" ] && tar xzf $<
    4.67 -	cd $(LIBCONFIG_SOURCE) && ./configure --prefix=$(PREFIX) --libdir=$(LIBDIR) --disable-cxx && $(MAKE)
    4.68 +libxlutil.a: $(LIBXLU_OBJS)
    4.69 +	$(AR) rcs libxlutil.a $^
    4.70  
    4.71 -xl.o: $(LIBCONFIG_OUTPUT)/libconfig.so xl.c
    4.72 -	$(CC) $(CFLAGS) -I$(LIBCONFIG_SOURCE) -c xl.c
    4.73 +xl.o: xl.c
    4.74 +	$(CC) $(CFLAGS) -c xl.c
    4.75  
    4.76 -$(CLIENTS): xl.o libxenlight.so $(LIBCONFIG_OUTPUT)/libconfig.so
    4.77 -	$(CC) $(LDFLAGS) -o $@ $< $(LIBS) -L . -lxenlight -L$(LIBCONFIG_OUTPUT) -lconfig
    4.78 +$(CLIENTS): xl.o libxlutil.so libxenlight.so
    4.79 +	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
    4.80  
    4.81  .PHONY: install
    4.82  install: all
    4.83 @@ -59,15 +80,17 @@ install: all
    4.84  	ln -sf libxenlight.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libxenlight.so.$(MAJOR)
    4.85  	ln -sf libxenlight.so.$(MAJOR) $(DESTDIR)$(LIBDIR)/libxenlight.so
    4.86  	$(INSTALL_DATA) libxenlight.a $(DESTDIR)$(LIBDIR)
    4.87 +	$(INSTALL_PROG) libxlutil.so.$(XLUMAJOR).$(XLUMINOR) $(DESTDIR)$(LIBDIR)
    4.88 +	ln -sf libxlutil.so.$(XLUMAJOR).$(XLUMINOR) $(DESTDIR)$(LIBDIR)/libxlutil.so.$(XLUMAJOR)
    4.89 +	ln -sf libxlutil.so.$(XLUMAJOR) $(DESTDIR)$(LIBDIR)/libxlutil.so
    4.90 +	$(INSTALL_DATA) libxlutil.a $(DESTDIR)$(LIBDIR)
    4.91  	$(INSTALL_DATA) libxl.h $(DESTDIR)$(INCLUDEDIR)
    4.92 -	cd $(LIBCONFIG_SOURCE) && DESTDIR=$(DESTDIR) $(MAKE) install
    4.93  
    4.94  .PHONY: clean
    4.95  clean:
    4.96  	$(RM) -f *.o *.so* *.a $(CLIENTS) $(DEPS)
    4.97 -	$(RM) -rf $(LIBCONFIG_SOURCE)
    4.98 +	$(RM) -f $(AUTOSRCS) $(AUTOINCS)
    4.99  
   4.100  distclean: clean
   4.101 -	$(RM) -f $(LIBCONFIG_SOURCE).tar.gz
   4.102  
   4.103  -include $(DEPS)
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/libxl/libxlu_cfg.c	Wed Mar 03 17:39:22 2010 +0000
     5.3 @@ -0,0 +1,341 @@
     5.4 +
     5.5 +#include "libxlu_internal.h"
     5.6 +#include "libxlu_cfg_y.h"
     5.7 +#include "libxlu_cfg_l.h"
     5.8 +#include "libxlu_cfg_i.h"
     5.9 +
    5.10 +XLU_Config *xlu_cfg_init(FILE *report, const char *report_filename) {
    5.11 +    XLU_Config *cfg;
    5.12 +
    5.13 +    cfg= malloc(sizeof(*cfg));
    5.14 +    if (!cfg) return 0;
    5.15 +
    5.16 +    cfg->report= report;
    5.17 +    cfg->filename= strdup(report_filename);
    5.18 +    if (!cfg->filename) { free(cfg); return 0; }
    5.19 +
    5.20 +    cfg->settings= 0;
    5.21 +    return cfg;
    5.22 +}
    5.23 +
    5.24 +int xlu_cfg_readfile(XLU_Config *cfg, const char *real_filename) {
    5.25 +    CfgParseContext ctx;
    5.26 +    FILE *f;
    5.27 +    int e, r;
    5.28 +
    5.29 +    ctx.cfg= cfg;
    5.30 +    ctx.err= 0;
    5.31 +    ctx.lexerrlineno= -1;
    5.32 +    
    5.33 +    f= fopen(real_filename, "r");
    5.34 +    if (!f) {
    5.35 +        e= errno;
    5.36 +        fprintf(cfg->report,"%s: unable to open configuration file: %s\n",
    5.37 +                real_filename, strerror(e));
    5.38 +        return e;
    5.39 +    }
    5.40 +
    5.41 +    e= xlu__cfg_yylex_init_extra(&ctx, &ctx.scanner);
    5.42 +    if (e) {
    5.43 +        fprintf(cfg->report,"%s: unable to create scanner: %s\n",
    5.44 +                cfg->filename, strerror(e));
    5.45 +        return e;
    5.46 +    }
    5.47 +
    5.48 +    xlu__cfg_yyrestart(f, ctx.scanner);
    5.49 +
    5.50 +    r= xlu__cfg_yyparse(&ctx);
    5.51 +    if (r) assert(ctx.err);
    5.52 +
    5.53 +    xlu__cfg_yylex_destroy(ctx.scanner);
    5.54 +    fclose(f);
    5.55 +
    5.56 +    return ctx.err;
    5.57 +}
    5.58 +
    5.59 +void xlu__cfg_set_free(XLU_ConfigSetting *set) {
    5.60 +    free(set->name);
    5.61 +    free(set->values);
    5.62 +    free(set);
    5.63 +}
    5.64 +
    5.65 +void xlu_cfg_destroy(XLU_Config *cfg) {
    5.66 +    XLU_ConfigSetting *set, *set_next;
    5.67 +
    5.68 +    for (set= cfg->settings;
    5.69 +         set;
    5.70 +         set= set_next) {
    5.71 +        set_next= set->next;
    5.72 +        xlu__cfg_set_free(set);
    5.73 +    }
    5.74 +    free(cfg->filename);
    5.75 +    free(cfg);
    5.76 +}
    5.77 +
    5.78 +static XLU_ConfigSetting *find(const XLU_Config *cfg, const char *n) {
    5.79 +    XLU_ConfigSetting *set;
    5.80 +
    5.81 +    for (set= cfg->settings;
    5.82 +         set;
    5.83 +         set= set->next)
    5.84 +        if (!strcmp(set->name, n))
    5.85 +            return set;
    5.86 +    return 0;
    5.87 +}
    5.88 +
    5.89 +static int find_atom(const XLU_Config *cfg, const char *n,
    5.90 +                     XLU_ConfigSetting **set_r) {
    5.91 +    XLU_ConfigSetting *set;
    5.92 +
    5.93 +    set= find(cfg,n);
    5.94 +    if (!set) return ESRCH;
    5.95 +
    5.96 +    if (set->avalues!=1) {
    5.97 +        fprintf(cfg->report,
    5.98 +                "%s:%d: warning: parameter `%s' is"
    5.99 +                " a list but should be a single value\n",
   5.100 +                cfg->filename, set->lineno, n);
   5.101 +        return EINVAL;
   5.102 +    }
   5.103 +    *set_r= set;
   5.104 +    return 0;
   5.105 +}
   5.106 +
   5.107 +int xlu_cfg_get_string(const XLU_Config *cfg, const char *n,
   5.108 +                       const char **value_r) {
   5.109 +    XLU_ConfigSetting *set;
   5.110 +    int e;
   5.111 +
   5.112 +    e= find_atom(cfg,n,&set);  if (e) return e;
   5.113 +    *value_r= set->values[0];
   5.114 +    return 0;
   5.115 +}
   5.116 +        
   5.117 +int xlu_cfg_get_long(const XLU_Config *cfg, const char *n,
   5.118 +                     long *value_r) {
   5.119 +    long l;
   5.120 +    XLU_ConfigSetting *set;
   5.121 +    int e;
   5.122 +    char *ep;
   5.123 +
   5.124 +    e= find_atom(cfg,n,&set);  if (e) return e;
   5.125 +    errno= 0; l= strtol(set->values[0], &ep, 0);
   5.126 +    e= errno;
   5.127 +    if (errno) {
   5.128 +        e= errno;
   5.129 +        assert(e==EINVAL || e==ERANGE);
   5.130 +        fprintf(cfg->report,
   5.131 +                "%s:%d: warning: parameter `%s' could not be parsed"
   5.132 +                " as a number: %s\n",
   5.133 +                cfg->filename, set->lineno, n, strerror(e));
   5.134 +        return e;
   5.135 +    }
   5.136 +    if (*ep || ep==set->values[0]) {
   5.137 +        fprintf(cfg->report,
   5.138 +                "%s:%d: warning: parameter `%s' is not a valid number\n",
   5.139 +                cfg->filename, set->lineno, n);
   5.140 +        return EINVAL;
   5.141 +    }
   5.142 +    *value_r= l;
   5.143 +    return 0;
   5.144 +}
   5.145 +        
   5.146 +
   5.147 +int xlu_cfg_get_list(const XLU_Config *cfg, const char *n,
   5.148 +                     XLU_ConfigList **list_r, int *entries_r) {
   5.149 +    XLU_ConfigSetting *set;
   5.150 +    set= find(cfg,n);  if (!set) return ESRCH;
   5.151 +    if (set->avalues==1) {
   5.152 +        fprintf(cfg->report,
   5.153 +                "%s:%d: warning: parameter `%s' is a single value"
   5.154 +                " but should be a list\n",
   5.155 +                cfg->filename, set->lineno, n);
   5.156 +        return EINVAL;
   5.157 +    }
   5.158 +    if (list_r) *list_r= set;
   5.159 +    if (entries_r) *entries_r= set->nvalues;
   5.160 +    return 0;
   5.161 +}
   5.162 +
   5.163 +const char *xlu_cfg_get_listitem(const XLU_ConfigList *set, int entry) {
   5.164 +    if (entry < 0 || entry >= set->nvalues) return 0;
   5.165 +    return set->values[entry];
   5.166 +}
   5.167 +
   5.168 +
   5.169 +XLU_ConfigSetting *xlu__cfg_set_mk(CfgParseContext *ctx,
   5.170 +                                   int alloc, char *atom) {
   5.171 +    XLU_ConfigSetting *set= 0;
   5.172 +
   5.173 +    if (ctx->err) goto x;
   5.174 +    assert(!!alloc == !!atom);
   5.175 +
   5.176 +    set= malloc(sizeof(*set));
   5.177 +    if (!set) goto xe;
   5.178 +
   5.179 +    set->name= 0; /* tbd */
   5.180 +    set->avalues= alloc;
   5.181 +    
   5.182 +    if (!alloc) {
   5.183 +        set->nvalues= 0;
   5.184 +        set->values= 0;
   5.185 +    } else {
   5.186 +        set->values= malloc(sizeof(*set->values) * alloc);
   5.187 +        if (!set->values) goto xe;
   5.188 +
   5.189 +        set->nvalues= 1;
   5.190 +        set->values[0]= atom;
   5.191 +    }
   5.192 +    return set;
   5.193 +
   5.194 + xe:
   5.195 +    ctx->err= errno;
   5.196 + x:
   5.197 +    free(set);
   5.198 +    free(atom);
   5.199 +    return 0;
   5.200 +}
   5.201 +
   5.202 +void xlu__cfg_set_add(CfgParseContext *ctx, XLU_ConfigSetting *set,
   5.203 +                      char *atom) {
   5.204 +    if (ctx->err) return;
   5.205 +
   5.206 +    assert(atom);
   5.207 +    
   5.208 +    if (set->nvalues >= set->avalues) {
   5.209 +        int new_avalues;
   5.210 +        char **new_values;
   5.211 +        
   5.212 +        if (set->avalues > INT_MAX / 100) { ctx->err= ERANGE; return; }
   5.213 +        new_avalues= set->avalues * 4;
   5.214 +        new_values= realloc(set->values,
   5.215 +                            sizeof(*new_values) * new_avalues);
   5.216 +        if (!new_values) { ctx->err= errno; free(atom); return; }
   5.217 +        set->values= new_values;
   5.218 +        set->avalues= new_avalues;
   5.219 +    }
   5.220 +    set->values[set->nvalues++]= atom;
   5.221 +}
   5.222 +
   5.223 +void xlu__cfg_set_store(CfgParseContext *ctx, char *name,
   5.224 +                        XLU_ConfigSetting *set, int lineno) {
   5.225 +    if (ctx->err) return;
   5.226 +
   5.227 +    assert(name);
   5.228 +    set->name= name;
   5.229 +    set->lineno= lineno;
   5.230 +    set->next= ctx->cfg->settings;
   5.231 +    ctx->cfg->settings= set;
   5.232 +}
   5.233 +
   5.234 +char *xlu__cfgl_strdup(CfgParseContext *ctx, const char *src) {
   5.235 +    char *result;
   5.236 +    
   5.237 +    if (ctx->err) return 0;
   5.238 +    result= strdup(src);
   5.239 +    if (!result) ctx->err= errno;
   5.240 +    return result;
   5.241 +}
   5.242 +
   5.243 +char *xlu__cfgl_dequote(CfgParseContext *ctx, const char *src) {
   5.244 +    char *result;
   5.245 +    const char *p;
   5.246 +    char *q;
   5.247 +    int len, c, nc;
   5.248 +
   5.249 +    if (ctx->err) return 0;
   5.250 +
   5.251 +    len= strlen(src);
   5.252 +    assert(len>=2 && src[0]==src[len-1]);
   5.253 +
   5.254 +    result= malloc(len-1);
   5.255 +    if (!result) { ctx->err= errno; return 0; }
   5.256 +
   5.257 +    q= result;
   5.258 +
   5.259 +    for (p= src+1;
   5.260 +         p < src+len-1;
   5.261 +         ) {
   5.262 +        c= *p++;
   5.263 +        if (c=='\\') {
   5.264 +            assert(p < src+len-1);
   5.265 +            nc= *p++;
   5.266 +            if (nc=='"' || nc=='\'' || nc=='\\') {
   5.267 +                *q++= nc;
   5.268 +            } else if (nc=='a') { *q++= '\007';
   5.269 +            } else if (nc=='b') { *q++= '\010';
   5.270 +            } else if (nc=='f') { *q++= '\014';
   5.271 +            } else if (nc=='n') { *q++= '\n';
   5.272 +            } else if (nc=='r') { *q++= '\r';
   5.273 +            } else if (nc=='t') { *q++= '\t';
   5.274 +            } else if (nc=='v') { *q++= '\013';
   5.275 +            } else if (nc=='x') {
   5.276 +
   5.277 +#define NUMERIC_CHAR(minlen,maxlen,base,basetext) do{                        \
   5.278 +                char numbuf[(maxlen)+1], *ep;                                \
   5.279 +                unsigned long val;                                           \
   5.280 +                                                                             \
   5.281 +                strncpy(numbuf,p,(maxlen));                                  \
   5.282 +                numbuf[(maxlen)]= 0;                                         \
   5.283 +                val= strtoul(numbuf, &ep, (base));                           \
   5.284 +                if (ep <= numbuf+(minlen)) {                                 \
   5.285 +                    xlu__cfgl_lexicalerror(ctx,"invalid digit after"         \
   5.286 +                         " backslash " basetext "numerical character escape" \
   5.287 +                         " in quoted string");                               \
   5.288 +                    ctx->err= EINVAL;                                        \
   5.289 +                    goto x;                                                  \
   5.290 +                }                                                            \
   5.291 +                p += (ep - numbuf);                                          \
   5.292 + }while(0) 
   5.293 +
   5.294 +                p++;
   5.295 +                NUMERIC_CHAR(2,2,16,"hex");
   5.296 +            } else if (nc>='0' && nc<='7') {
   5.297 +                NUMERIC_CHAR(1,3,10,"octal");
   5.298 +            }
   5.299 +            assert(p <= src+len-1);
   5.300 +        } else {
   5.301 +            *q++= c;
   5.302 +        }
   5.303 +    }
   5.304 +
   5.305 + x:
   5.306 +    *q++= 0;
   5.307 +    return result;
   5.308 +}
   5.309 +
   5.310 +void xlu__cfgl_lexicalerror(CfgParseContext *ctx, char const *msg) {
   5.311 +    YYLTYPE loc;
   5.312 +    loc.first_line= xlu__cfg_yyget_lineno(ctx->scanner);
   5.313 +    xlu__cfg_yyerror(&loc, ctx, msg);
   5.314 +    ctx->lexerrlineno= loc.first_line;
   5.315 +}
   5.316 +
   5.317 +void xlu__cfg_yyerror(YYLTYPE *loc, CfgParseContext *ctx, char const *msg) {
   5.318 +    const char *text, *newline;
   5.319 +    int len, lineno;
   5.320 +
   5.321 +    lineno= loc->first_line;
   5.322 +    if (lineno <= ctx->lexerrlineno) return;
   5.323 +
   5.324 +    text= xlu__cfg_yyget_text(ctx->scanner);
   5.325 +    len= xlu__cfg_yyget_leng(ctx->scanner);
   5.326 +    newline= "";
   5.327 +    if (len>0 && text[len-1]=='\n') {
   5.328 +        len--;
   5.329 +        lineno--;
   5.330 +        if (!len) {
   5.331 +            newline= "<newline>";
   5.332 +        }
   5.333 +    }
   5.334 +    while (len>0 && (text[len-1]=='\t' || text[len-1]==' ')) {
   5.335 +        len--;
   5.336 +    }
   5.337 +
   5.338 +    fprintf(ctx->cfg->report,
   5.339 +            "%s:%d: config parsing error near %s%.*s%s%s: %s\n",
   5.340 +            ctx->cfg->filename, lineno,
   5.341 +            len?"`":"", len, text, len?"'":"", newline,
   5.342 +            msg);
   5.343 +    if (!ctx->err) ctx->err= EINVAL;
   5.344 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/libxl/libxlu_cfg_i.h	Wed Mar 03 17:39:22 2010 +0000
     6.3 @@ -0,0 +1,25 @@
     6.4 +#ifndef LIBXLU_CFG_I_H
     6.5 +#define LIBXLU_CFG_I_H
     6.6 +
     6.7 +#include "libxlu_internal.h"
     6.8 +#include "libxlu_cfg_y.h"
     6.9 +
    6.10 +void xlu__cfg_set_free(XLU_ConfigSetting *set);
    6.11 +XLU_ConfigSetting *xlu__cfg_set_mk(CfgParseContext*, int alloc, char *atom);
    6.12 +void xlu__cfg_set_add(CfgParseContext*, XLU_ConfigSetting *set, char *atom);
    6.13 +void xlu__cfg_set_store(CfgParseContext*, char *name,
    6.14 +                        XLU_ConfigSetting *set, int lineno);
    6.15 +
    6.16 +char *xlu__cfgl_strdup(CfgParseContext*, const char *src);
    6.17 +char *xlu__cfgl_dequote(CfgParseContext*, const char *src);
    6.18 +
    6.19 +void xlu__cfg_yyerror(YYLTYPE *locp, CfgParseContext*, char const *msg);
    6.20 +void xlu__cfgl_lexicalerror(CfgParseContext*, char const *msg);
    6.21 +
    6.22 +
    6.23 +
    6.24 +/* Why oh why does bison not declare this in its autogenerated .h ? */
    6.25 +int xlu__cfg_yyparse(CfgParseContext *ctx);
    6.26 +
    6.27 +
    6.28 +#endif /*LIBXLU_CFG_I_H*/
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/libxl/libxlu_cfg_l.l	Wed Mar 03 17:39:22 2010 +0000
     7.3 @@ -0,0 +1,74 @@
     7.4 +/* -*- fundamental -*- */
     7.5 +
     7.6 +%{
     7.7 +#include "libxlu_cfg_i.h"
     7.8 +
     7.9 +#define ctx ((CfgParseContext*)yyextra)
    7.10 +#define YY_NO_INPUT
    7.11 +
    7.12 +#define GOT(x) do{                \
    7.13 +    yylloc->first_line= yylineno; \
    7.14 +    return (x);                   \
    7.15 +  }while(0)
    7.16 +
    7.17 +%}
    7.18 +
    7.19 +%option warn
    7.20 +%option nodefault
    7.21 +%option batch
    7.22 +%option 8bit
    7.23 +%option yylineno
    7.24 +%option noyywrap
    7.25 +%option bison-bridge
    7.26 +%option bison-locations
    7.27 +%option reentrant
    7.28 +%option prefix="xlu__cfg_yy"
    7.29 +%option nounput
    7.30 +
    7.31 +%x lexerr
    7.32 +
    7.33 +%%
    7.34 +
    7.35 +[a-z][_0-9a-z]*         {
    7.36 +                          yylval->string= xlu__cfgl_strdup(ctx,yytext);
    7.37 +                          GOT(IDENT);
    7.38 +                        }
    7.39 +[0-9][0-9a-fx]*         {
    7.40 +                          yylval->string= xlu__cfgl_strdup(ctx,yytext);
    7.41 +                          GOT(NUMBER);
    7.42 +                        }
    7.43 +
    7.44 +[ \t]
    7.45 +
    7.46 +,                       { GOT(','); }
    7.47 +\[                      { GOT('['); }
    7.48 +\]                      { GOT(']'); }
    7.49 +\=                      { GOT('='); }
    7.50 +\;                      { GOT(';'); }
    7.51 +
    7.52 +\n|\#.*\n               { yylloc->first_line= yylineno-1; return NEWLINE; }
    7.53 +
    7.54 +\'([^\'\\\n]|\\.)*\'    {
    7.55 +                          yylval->string= xlu__cfgl_dequote(ctx,yytext);
    7.56 +                          GOT(STRING);
    7.57 +                        }
    7.58 +\"([^\"\\\n]|\\.)*\"    {
    7.59 +                          yylval->string= xlu__cfgl_dequote(ctx,yytext);
    7.60 +                          GOT(STRING);
    7.61 +                        }
    7.62 +
    7.63 +.                       {
    7.64 +                          BEGIN(lexerr);
    7.65 +                          yymore();
    7.66 +                        }
    7.67 +
    7.68 +<lexerr>[^ \t\n]*|[ \t] {
    7.69 +                          xlu__cfgl_lexicalerror(ctx,"lexical error");
    7.70 +                          BEGIN(0);
    7.71 +                        }
    7.72 +
    7.73 +<lexerr>\n              {
    7.74 +                          xlu__cfgl_lexicalerror(ctx,"lexical error");
    7.75 +                          BEGIN(0);
    7.76 +                          GOT(NEWLINE);
    7.77 +                        }
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/libxl/libxlu_cfg_y.y	Wed Mar 03 17:39:22 2010 +0000
     8.3 @@ -0,0 +1,57 @@
     8.4 +/* -*- fundamental -*- */
     8.5 +
     8.6 +%{
     8.7 +#define YYLEX_PARAM ctx->scanner
     8.8 +#include "libxlu_cfg_i.h"
     8.9 +#include "libxlu_cfg_l.h"
    8.10 +%}
    8.11 +
    8.12 +%union {
    8.13 +  char *string;
    8.14 +  XLU_ConfigSetting *setting;
    8.15 +}
    8.16 +
    8.17 +%locations
    8.18 +%pure-parser
    8.19 +%defines
    8.20 +%error-verbose
    8.21 +%name-prefix="xlu__cfg_yy"
    8.22 +%parse-param { CfgParseContext *ctx }
    8.23 +%lex-param { void *scanner }
    8.24 +
    8.25 +%token <string>                IDENT STRING NUMBER NEWLINE
    8.26 +%type <string>            atom
    8.27 +%destructor { free($$); } atom IDENT STRING NUMBER
    8.28 +
    8.29 +%type <setting>                         value valuelist values
    8.30 +%destructor { xlu__cfg_set_free($$); }  value valuelist values
    8.31 +
    8.32 +%%
    8.33 +
    8.34 +file: /* empty */
    8.35 + |     file setting           
    8.36 +
    8.37 +setting: IDENT '=' value      { xlu__cfg_set_store(ctx,$1,$3,@3.first_line); }
    8.38 +                     endstmt
    8.39 + |      endstmt
    8.40 + |      error NEWLINE
    8.41 +
    8.42 +endstmt: NEWLINE
    8.43 + |      ';'
    8.44 +
    8.45 +value:  atom                         { $$= xlu__cfg_set_mk(ctx,1,$1); }
    8.46 + |      '[' nlok valuelist ']'       { $$= $3; }
    8.47 +
    8.48 +atom:   STRING                   { $$= $1; }
    8.49 + |      NUMBER                   { $$= $1; }
    8.50 +
    8.51 +valuelist: /* empty */           { $$= xlu__cfg_set_mk(ctx,0,0); }
    8.52 + |      values                  { $$= $1; }
    8.53 + |      values ',' nlok         { $$= $1; }
    8.54 +
    8.55 +values: atom nlok                  { $$= xlu__cfg_set_mk(ctx,2,$1); }
    8.56 + |      values ',' nlok atom nlok  { xlu__cfg_set_add(ctx,$1,$4); $$= $1; }
    8.57 +
    8.58 +nlok:
    8.59 +        /* nothing */
    8.60 + |      nlok NEWLINE
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/libxl/libxlu_internal.h	Wed Mar 03 17:39:22 2010 +0000
     9.3 @@ -0,0 +1,48 @@
     9.4 +/*
     9.5 + * Copyright (C) 2010      Citrix Ltd.
     9.6 + * Author Ian Jackson <ian.jackson@eu.citrix.com>
     9.7 + *
     9.8 + * This program is free software; you can redistribute it and/or modify
     9.9 + * it under the terms of the GNU Lesser General Public License as published
    9.10 + * by the Free Software Foundation; version 2.1 only. with the special
    9.11 + * exception on linking described in file LICENSE.
    9.12 + *
    9.13 + * This program is distributed in the hope that it will be useful,
    9.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.16 + * GNU Lesser General Public License for more details.
    9.17 + */
    9.18 +
    9.19 +#ifndef LIBXLU_INTERNAL_H
    9.20 +#define LIBXLU_INTERNAL_H
    9.21 +
    9.22 +#include <stdio.h>
    9.23 +#include <errno.h>
    9.24 +#include <string.h>
    9.25 +#include <assert.h>
    9.26 +
    9.27 +#define XLU_ConfigList XLU_ConfigSetting
    9.28 +
    9.29 +#include "libxlutil.h"
    9.30 +
    9.31 +struct XLU_ConfigSetting { /* transparent */
    9.32 +    struct XLU_ConfigSetting *next;
    9.33 +    char *name;
    9.34 +    int nvalues, avalues; /* lists have avalues>1 */
    9.35 +    char **values;
    9.36 +    int lineno;
    9.37 +};
    9.38 +
    9.39 +struct XLU_Config {
    9.40 +    XLU_ConfigSetting *settings;
    9.41 +    FILE *report;
    9.42 +    char *filename;
    9.43 +};
    9.44 +
    9.45 +typedef struct {
    9.46 +    XLU_Config *cfg;
    9.47 +    int err, lexerrlineno;
    9.48 +    void *scanner;
    9.49 +} CfgParseContext;
    9.50 +
    9.51 +#endif /*LIBXLU_INTERNAL_H*/
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/libxl/libxlutil.h	Wed Mar 03 17:39:22 2010 +0000
    10.3 @@ -0,0 +1,58 @@
    10.4 +/*
    10.5 + * Copyright (C) 2010      Citrix Ltd.
    10.6 + * Author Ian Jackson <ian.jackson@eu.citrix.com>
    10.7 + *
    10.8 + * This program is free software; you can redistribute it and/or modify
    10.9 + * it under the terms of the GNU Lesser General Public License as published
   10.10 + * by the Free Software Foundation; version 2.1 only. with the special
   10.11 + * exception on linking described in file LICENSE.
   10.12 + *
   10.13 + * This program is distributed in the hope that it will be useful,
   10.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.16 + * GNU Lesser General Public License for more details.
   10.17 + */
   10.18 +
   10.19 +#ifndef LIBXLUTIL_H
   10.20 +#define LIBXLUTIL_H
   10.21 +
   10.22 +#include <stdio.h>
   10.23 +
   10.24 +#include "libxl.h"
   10.25 +
   10.26 +/* Unless otherwise stated, all functions return an errno value. */
   10.27 +typedef struct XLU_Config XLU_Config;
   10.28 +typedef struct XLU_ConfigList XLU_ConfigList;
   10.29 +
   10.30 +XLU_Config *xlu_cfg_init(FILE *report, const char *report_filename);
   10.31 +  /* 0 means we got ENOMEM. */
   10.32 +  /* report_filename is copied; report is saved and must remain valid
   10.33 +   *  until the Config is destroyed. */
   10.34 +
   10.35 +int xlu_cfg_readfile(XLU_Config*, const char *real_filename);
   10.36 +  /* If this fails, then it is undefined behaviour to call xlu_cfg_get_...
   10.37 +   * functions.  You have to just xlu_cfg_destroy. */
   10.38 + 
   10.39 +void xlu_cfg_destroy(XLU_Config*);
   10.40 +
   10.41 +
   10.42 +/* All of the following print warnings to "report" if there is a problem.
   10.43 + * Return values are:
   10.44 + *   0        OK
   10.45 + *   ESRCH    not defined
   10.46 + *   EINVAL   value found but wrong format for request (prints warning)
   10.47 + *   ERANGE   value out of range (from strtol)
   10.48 + */
   10.49 +
   10.50 +int xlu_cfg_get_string(const XLU_Config*, const char *n, const char **value_r);
   10.51 +int xlu_cfg_get_long(const XLU_Config*, const char *n, long *value_r);
   10.52 +
   10.53 +int xlu_cfg_get_list(const XLU_Config*, const char *n,
   10.54 +                     XLU_ConfigList **list_r /* may be 0 */,
   10.55 +                     int *entries_r /* may be 0 */);
   10.56 +  /* there is no need to free *list_r; lifetime is that of the XLU_Config */
   10.57 +const char *xlu_cfg_get_listitem(const XLU_ConfigList*, int entry);
   10.58 +  /* xlu_cfg_get_listitem cannot fail, except that if entry is
   10.59 +   * out of range it returns 0 (not setting errno) */
   10.60 +
   10.61 +#endif /* LIBXLUTIL_H */
    11.1 --- a/tools/libxl/xl.c	Tue Mar 02 14:05:35 2010 +0000
    11.2 +++ b/tools/libxl/xl.c	Wed Mar 03 17:39:22 2010 +0000
    11.3 @@ -19,7 +19,6 @@
    11.4  #include <stdio.h>
    11.5  #include <stdlib.h>
    11.6  #include <string.h>
    11.7 -#include <libconfig.h>
    11.8  #include <unistd.h>
    11.9  #include <sys/time.h> /* for time */
   11.10  #include <getopt.h>
   11.11 @@ -34,6 +33,7 @@
   11.12  
   11.13  #include "libxl.h"
   11.14  #include "libxl_utils.h"
   11.15 +#include "libxlutil.h"
   11.16  
   11.17  #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
   11.18  
   11.19 @@ -320,63 +320,6 @@ static void printf_info(libxl_domain_cre
   11.20      }
   11.21  }
   11.22  
   11.23 -static char* compat_config_file(const char *filename)
   11.24 -{
   11.25 -    char t;
   11.26 -    char *newfile = (char*) malloc(strlen(filename) + 4);
   11.27 -    char *buf = (char *) malloc(2048);
   11.28 -    int size = 2048, i;
   11.29 -    FILE *s;
   11.30 -    FILE *d;
   11.31 -
   11.32 -    sprintf(newfile, "%s.xl", filename);
   11.33 -
   11.34 -    s = fopen(filename, "r");
   11.35 -    if (!s) {
   11.36 -        perror("cannot open file for reading");
   11.37 -        return NULL;
   11.38 -    }
   11.39 -    d = fopen(newfile, "w");
   11.40 -    if (!d) {
   11.41 -        fclose(s);
   11.42 -        perror("cannot open file for writting");
   11.43 -        return NULL;
   11.44 -    }
   11.45 -
   11.46 -    while (!feof(s)) {
   11.47 -        buf[0] = 0;
   11.48 -        fgets(buf, size, s);
   11.49 -        while (buf[strlen(buf) - 1] != '\n' && !feof(s)) {
   11.50 -            size += 1024;
   11.51 -            buf = realloc(buf, size + 1024);
   11.52 -            fgets(buf + (size - 1025), 1025, s);
   11.53 -        }
   11.54 -        for (i = 0; i < strlen(buf); i++)
   11.55 -            if (buf[i] == '\'')
   11.56 -                buf[i] = '\"';
   11.57 -        if (strchr(buf, '=') != NULL) {
   11.58 -            if ((buf[strlen(buf) - 1] == '\n' && buf[strlen(buf) - 2] == ';') ||
   11.59 -                    buf[strlen(buf) - 1] == ';') {
   11.60 -                fputs(buf, d);
   11.61 -            } else {
   11.62 -                t = buf[strlen(buf) - 1];
   11.63 -                buf[strlen(buf) - 1] = ';';
   11.64 -                fputs(buf, d);
   11.65 -                fputc(t, d);
   11.66 -            }
   11.67 -        } else if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\n') {
   11.68 -            fputs(buf, d);
   11.69 -        }
   11.70 -    }
   11.71 -
   11.72 -    fclose(s);
   11.73 -    fclose(d);
   11.74 -
   11.75 -    free(buf);
   11.76 -
   11.77 -    return newfile;
   11.78 -}
   11.79 -
   11.80  static void parse_config_file(const char *filename,
   11.81                                libxl_domain_create_info *c_info,
   11.82                                libxl_domain_build_info *b_info,
   11.83 @@ -394,35 +337,33 @@ static void parse_config_file(const char
   11.84  {
   11.85      const char *buf;
   11.86      long l;
   11.87 -    struct config_t config;
   11.88 -    struct config_setting_t *vbds, *nics, *pcis, *cvfbs;
   11.89 +    XLU_Config *config;
   11.90 +    XLU_ConfigList *vbds, *nics, *pcis, *cvfbs;
   11.91      int pci_power_mgmt = 0;
   11.92      int pci_msitranslate = 1;
   11.93 -    int i;
   11.94 -
   11.95 -    config_init (&config);
   11.96 +    int i, e;
   11.97  
   11.98 -    if (!config_read_file(&config, filename)) {
   11.99 -        char *newfilename;
  11.100 -        config_destroy(&config);
  11.101 -        newfilename = compat_config_file(filename);
  11.102 -        config_init (&config);
  11.103 -        if (!config_read_file(&config, newfilename)) {
  11.104 -            fprintf(stderr, "Failed to parse config file %s on line %d, try removing any embedded python code\n", config_error_text(&config), config_error_line(&config));
  11.105 -            exit(1);
  11.106 -        }
  11.107 -        free(newfilename);
  11.108 +    config= xlu_cfg_init(stderr, filename);
  11.109 +    if (!config) {
  11.110 +        fprintf(stderr, "Failed to allocate for configuration\n");
  11.111 +        exit(1);
  11.112 +    }
  11.113 +
  11.114 +    e= xlu_cfg_readfile (config, filename);
  11.115 +    if (e) {
  11.116 +        fprintf(stderr, "Failed to parse config file: %s\n", strerror(e));
  11.117 +        exit(1);
  11.118      }
  11.119  
  11.120      init_create_info(c_info);
  11.121  
  11.122      c_info->hvm = 0;
  11.123 -    if ((config_lookup_string (&config, "builder", &buf) == CONFIG_TRUE) &&
  11.124 +    if (!xlu_cfg_get_string (config, "builder", &buf) &&
  11.125          !strncmp(buf, "hvm", strlen(buf)))
  11.126          c_info->hvm = 1;
  11.127  
  11.128      /* hap is missing */
  11.129 -    if (config_lookup_string (&config, "name", &buf) == CONFIG_TRUE)
  11.130 +    if (!xlu_cfg_get_string (config, "name", &buf))
  11.131          c_info->name = strdup(buf);
  11.132      else
  11.133          c_info->name = "test";
  11.134 @@ -433,48 +374,48 @@ static void parse_config_file(const char
  11.135      init_build_info(b_info, c_info);
  11.136  
  11.137      /* the following is the actual config parsing with overriding values in the structures */
  11.138 -    if (config_lookup_int (&config, "vcpus", &l) == CONFIG_TRUE)
  11.139 +    if (!xlu_cfg_get_long (config, "vcpus", &l))
  11.140          b_info->max_vcpus = l;
  11.141  
  11.142 -    if (config_lookup_int (&config, "memory", &l) == CONFIG_TRUE) {
  11.143 +    if (!xlu_cfg_get_long (config, "memory", &l)) {
  11.144          b_info->max_memkb = l * 1024;
  11.145          b_info->target_memkb = b_info->max_memkb;
  11.146      }
  11.147  
  11.148 -    if (config_lookup_int (&config, "shadow_memory", &l) == CONFIG_TRUE)
  11.149 +    if (!xlu_cfg_get_long (config, "shadow_memory", &l))
  11.150          b_info->shadow_memkb = l * 1024;
  11.151  
  11.152 -    if (config_lookup_int (&config, "videoram", &l) == CONFIG_TRUE)
  11.153 +    if (!xlu_cfg_get_long (config, "videoram", &l))
  11.154          b_info->video_memkb = l * 1024;
  11.155  
  11.156 -    if (config_lookup_string (&config, "kernel", &buf) == CONFIG_TRUE)
  11.157 +    if (!xlu_cfg_get_string (config, "kernel", &buf))
  11.158          b_info->kernel = strdup(buf);
  11.159  
  11.160      if (c_info->hvm == 1) {
  11.161 -        if (config_lookup_int (&config, "pae", &l) == CONFIG_TRUE)
  11.162 +        if (!xlu_cfg_get_long (config, "pae", &l))
  11.163              b_info->u.hvm.pae = l;
  11.164 -        if (config_lookup_int (&config, "apic", &l) == CONFIG_TRUE)
  11.165 +        if (!xlu_cfg_get_long (config, "apic", &l))
  11.166              b_info->u.hvm.apic = l;
  11.167 -        if (config_lookup_int (&config, "acpi", &l) == CONFIG_TRUE)
  11.168 +        if (!xlu_cfg_get_long (config, "acpi", &l))
  11.169              b_info->u.hvm.acpi = l;
  11.170 -        if (config_lookup_int (&config, "nx", &l) == CONFIG_TRUE)
  11.171 +        if (!xlu_cfg_get_long (config, "nx", &l))
  11.172              b_info->u.hvm.nx = l;
  11.173 -        if (config_lookup_int (&config, "viridian", &l) == CONFIG_TRUE)
  11.174 +        if (!xlu_cfg_get_long (config, "viridian", &l))
  11.175              b_info->u.hvm.viridian = l;
  11.176      } else {
  11.177          char *cmdline;
  11.178 -        if (config_lookup_string (&config, "root", &buf) == CONFIG_TRUE) {
  11.179 +        if (!xlu_cfg_get_string (config, "root", &buf)) {
  11.180              asprintf(&cmdline, "root=%s", buf);
  11.181              b_info->u.pv.cmdline = cmdline;
  11.182          }
  11.183 -        if (config_lookup_string (&config, "ramdisk", &buf) == CONFIG_TRUE)
  11.184 +        if (!xlu_cfg_get_string (config, "ramdisk", &buf))
  11.185              b_info->u.pv.ramdisk = strdup(buf);
  11.186      }
  11.187  
  11.188 -    if ((vbds = config_lookup (&config, "disk")) != NULL) {
  11.189 +    if (!xlu_cfg_get_list (config, "disk", &vbds, 0)) {
  11.190          *num_disks = 0;
  11.191          *disks = NULL;
  11.192 -        while ((buf = config_setting_get_string_elem (vbds, *num_disks)) != NULL) {
  11.193 +        while ((buf = xlu_cfg_get_listitem (vbds, *num_disks)) != NULL) {
  11.194              char *buf2 = strdup(buf);
  11.195              char *p, *p2;
  11.196              *disks = (libxl_device_disk *) realloc(*disks, sizeof (libxl_device_disk) * ((*num_disks) + 1));
  11.197 @@ -530,10 +471,10 @@ static void parse_config_file(const char
  11.198          }
  11.199      }
  11.200  
  11.201 -    if ((nics = config_lookup (&config, "vif")) != NULL) {
  11.202 +    if (!xlu_cfg_get_list (config, "vif", &nics, 0)) {
  11.203          *num_vifs = 0;
  11.204          *vifs = NULL;
  11.205 -        while ((buf = config_setting_get_string_elem (nics, *num_vifs)) != NULL) {
  11.206 +        while ((buf = xlu_cfg_get_listitem (nics, *num_vifs)) != NULL) {
  11.207              char *buf2 = strdup(buf);
  11.208              char *p, *p2;
  11.209              *vifs = (libxl_device_nic *) realloc(*vifs, sizeof (libxl_device_nic) * ((*num_vifs) + 1));
  11.210 @@ -593,12 +534,12 @@ skip:
  11.211          }
  11.212      }
  11.213  
  11.214 -    if ((cvfbs = config_lookup (&config, "vfb")) != NULL) {
  11.215 +    if (!xlu_cfg_get_list (config, "vfb", &cvfbs, 0)) {
  11.216          *num_vfbs = 0;
  11.217          *num_vkbs = 0;
  11.218          *vfbs = NULL;
  11.219          *vkbs = NULL;
  11.220 -        while ((buf = config_setting_get_string_elem (cvfbs, *num_vfbs)) != NULL) {
  11.221 +        while ((buf = xlu_cfg_get_listitem (cvfbs, *num_vfbs)) != NULL) {
  11.222              char *buf2 = strdup(buf);
  11.223              char *p, *p2;
  11.224              *vfbs = (libxl_device_vfb *) realloc(*vfbs, sizeof(libxl_device_vfb) * ((*num_vfbs) + 1));
  11.225 @@ -643,16 +584,16 @@ skip_vfb:
  11.226          }
  11.227      }
  11.228  
  11.229 -    if (config_lookup_int (&config, "pci_msitranslate", &l) == CONFIG_TRUE)
  11.230 +    if (!xlu_cfg_get_long (config, "pci_msitranslate", &l))
  11.231          pci_msitranslate = l;
  11.232  
  11.233 -    if (config_lookup_int (&config, "pci_power_mgmt", &l) == CONFIG_TRUE)
  11.234 +    if (!xlu_cfg_get_long (config, "pci_power_mgmt", &l))
  11.235          pci_power_mgmt = l;
  11.236  
  11.237 -    if ((pcis = config_lookup (&config, "pci")) != NULL) {
  11.238 +    if (xlu_cfg_get_list (config, "pci", &pcis, 0)) {
  11.239          *num_pcidevs = 0;
  11.240          *pcidevs = NULL;
  11.241 -        while ((buf = config_setting_get_string_elem (pcis, *num_pcidevs)) != NULL) {
  11.242 +        while ((buf = xlu_cfg_get_listitem (pcis, *num_pcidevs)) != NULL) {
  11.243              unsigned int domain = 0, bus = 0, dev = 0, func = 0, vdevfn = 0;
  11.244              char *buf2 = strdup(buf);
  11.245              char *p;
  11.246 @@ -690,37 +631,37 @@ skip_pci:
  11.247          init_dm_info(dm_info, c_info, b_info);
  11.248  
  11.249          /* then process config related to dm */
  11.250 -        if (config_lookup_string (&config, "device_model", &buf) == CONFIG_TRUE)
  11.251 +        if (!xlu_cfg_get_string (config, "device_model", &buf))
  11.252              dm_info->device_model = strdup(buf);
  11.253 -        if (config_lookup_int (&config, "stdvga", &l) == CONFIG_TRUE)
  11.254 +        if (!xlu_cfg_get_long (config, "stdvga", &l))
  11.255              dm_info->stdvga = l;
  11.256 -        if (config_lookup_int (&config, "vnc", &l) == CONFIG_TRUE)
  11.257 +        if (!xlu_cfg_get_long (config, "vnc", &l))
  11.258              dm_info->vnc = l;
  11.259 -        if (config_lookup_string (&config, "vnclisten", &buf) == CONFIG_TRUE)
  11.260 +        if (!xlu_cfg_get_string (config, "vnclisten", &buf))
  11.261              dm_info->vnclisten = strdup(buf);
  11.262 -        if (config_lookup_int (&config, "vncdisplay", &l) == CONFIG_TRUE)
  11.263 +        if (!xlu_cfg_get_long (config, "vncdisplay", &l))
  11.264              dm_info->vncdisplay = l;
  11.265 -        if (config_lookup_int (&config, "vncunused", &l) == CONFIG_TRUE)
  11.266 +        if (!xlu_cfg_get_long (config, "vncunused", &l))
  11.267              dm_info->vncunused = l;
  11.268 -        if (config_lookup_string (&config, "keymap", &buf) == CONFIG_TRUE)
  11.269 +        if (!xlu_cfg_get_string (config, "keymap", &buf))
  11.270              dm_info->keymap = strdup(buf);
  11.271 -        if (config_lookup_int (&config, "sdl", &l) == CONFIG_TRUE)
  11.272 +        if (!xlu_cfg_get_long (config, "sdl", &l))
  11.273              dm_info->sdl = l;
  11.274 -        if (config_lookup_int (&config, "opengl", &l) == CONFIG_TRUE)
  11.275 +        if (!xlu_cfg_get_long (config, "opengl", &l))
  11.276              dm_info->opengl = l;
  11.277 -        if (config_lookup_int (&config, "nographic", &l) == CONFIG_TRUE)
  11.278 +        if (!xlu_cfg_get_long (config, "nographic", &l))
  11.279              dm_info->nographic = l;
  11.280 -        if (config_lookup_string (&config, "serial", &buf) == CONFIG_TRUE)
  11.281 +        if (!xlu_cfg_get_string (config, "serial", &buf))
  11.282              dm_info->serial = strdup(buf);
  11.283 -        if (config_lookup_string (&config, "boot", &buf) == CONFIG_TRUE)
  11.284 +        if (!xlu_cfg_get_string (config, "boot", &buf))
  11.285              dm_info->boot = strdup(buf);
  11.286 -        if (config_lookup_int (&config, "usb", &l) == CONFIG_TRUE)
  11.287 +        if (!xlu_cfg_get_long (config, "usb", &l))
  11.288              dm_info->usb = l;
  11.289 -        if (config_lookup_string (&config, "usbdevice", &buf) == CONFIG_TRUE)
  11.290 +        if (!xlu_cfg_get_string (config, "usbdevice", &buf))
  11.291              dm_info->usbdevice = strdup(buf);
  11.292      }
  11.293  
  11.294 -    config_destroy(&config);
  11.295 +    xlu_cfg_destroy(config);
  11.296  }
  11.297  
  11.298  #define MUST( call ) ({                                                 \