Coverage report for src/xml.c.gcov

        -:    0:Source:xml.c
        -:    0:Graph:./libvirt_la-xml.gcno
        -:    0:Data:./libvirt_la-xml.gcda
        -:    0:Runs:2
        -:    0:Programs:2
        -:    1:/*
        -:    2: * xml.c: XML based interfaces for the libvir library
        -:    3: *
        -:    4: * Copyright (C) 2005 Red Hat, Inc.
        -:    5: *
        -:    6: * See COPYING.LIB for the License of this software
        -:    7: *
        -:    8: * Daniel Veillard <veillard@redhat.com>
        -:    9: */
        -:   10:
        -:   11:#include "libvirt/libvirt.h"
        -:   12:
        -:   13:#include <stdio.h>
        -:   14:#include <stdlib.h>
        -:   15:#include <string.h>
        -:   16:#include <stdarg.h>
        -:   17:#include <xs.h>
        -:   18:#include <libxml/parser.h>
        -:   19:#include <libxml/tree.h>
        -:   20:#include <libxml/xpath.h>
        -:   21:#include <math.h> /* for isnan() */
        -:   22:#include "internal.h"
        -:   23:#include "hash.h"
        -:   24:#include "sexpr.h"
        -:   25:#include "xml.h"
        -:   26:
        -:   27:static void
        -:   28:virXMLError(virErrorNumber error, const char *info, int value)
function virXMLError called 0 returned 0% blocks executed 0%
    #####:   29:{
        -:   30:    const char *errmsg;
        -:   31:
    #####:   32:    if (error == VIR_ERR_OK)
branch  0 never executed
branch  1 never executed
    #####:   33:        return;
        -:   34:
    #####:   35:    errmsg = __virErrorMsg(error, info);
call    0 never executed
    #####:   36:    __virRaiseError(NULL, NULL, VIR_FROM_XML, error, VIR_ERR_ERROR,
call    0 never executed
        -:   37:                    errmsg, info, NULL, value, 0, errmsg, info, value);
        -:   38:}
        -:   39:
        -:   40:/**
        -:   41: * virBufferGrow:
        -:   42: * @buf:  the buffer
        -:   43: * @len:  the minimum free size to allocate
        -:   44: *
        -:   45: * Grow the available space of an XML buffer.
        -:   46: *
        -:   47: * Returns the new available space or -1 in case of error
        -:   48: */
        -:   49:static int
        -:   50:virBufferGrow(virBufferPtr buf, unsigned int len)
function virBufferGrow called 0 returned 0% blocks executed 0%
    #####:   51:{
        -:   52:    int size;
        -:   53:    char *newbuf;
        -:   54:
    #####:   55:    if (buf == NULL)
branch  0 never executed
branch  1 never executed
    #####:   56:        return (-1);
    #####:   57:    if (len + buf->use < buf->size)
branch  0 never executed
branch  1 never executed
    #####:   58:        return (0);
        -:   59:
    #####:   60:    size = buf->use + len + 1000;
        -:   61:
    #####:   62:    newbuf = (char *) realloc(buf->content, size);
call    0 never executed
    #####:   63:    if (newbuf == NULL) {
branch  0 never executed
branch  1 never executed
    #####:   64:        virXMLError(VIR_ERR_NO_MEMORY, "growing buffer", size);
call    0 never executed
    #####:   65:        return (-1);
        -:   66:    }
    #####:   67:    buf->content = newbuf;
    #####:   68:    buf->size = size;
    #####:   69:    return (buf->size - buf->use);
        -:   70:}
        -:   71:
        -:   72:/**
        -:   73: * virBufferAdd:
        -:   74: * @buf:  the buffer to dump
        -:   75: * @str:  the string
        -:   76: * @len:  the number of bytes to add
        -:   77: *
        -:   78: * Add a string range to an XML buffer. if len == -1, the length of
        -:   79: * str is recomputed to the full string.
        -:   80: *
        -:   81: * Returns 0 successful, -1 in case of internal or API error.
        -:   82: */
        -:   83:int
        -:   84:virBufferAdd(virBufferPtr buf, const char *str, int len)
function virBufferAdd called 44 returned 100% blocks executed 50%
       44:   85:{
        -:   86:    unsigned int needSize;
        -:   87:
       44:   88:    if ((str == NULL) || (buf == NULL)) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:   89:        return -1;
        -:   90:    }
       44:   91:    if (len == 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:   92:        return 0;
        -:   93:
       44:   94:    if (len < 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:   95:        len = strlen(str);
call    0 never executed
        -:   96:
       44:   97:    needSize = buf->use + len + 2;
       44:   98:    if (needSize > buf->size) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:   99:        if (!virBufferGrow(buf, needSize)) {
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####:  100:            return (-1);
        -:  101:        }
        -:  102:    }
        -:  103:    /* XXX: memmove() is 2x slower than memcpy(), do we really need it? */
       44:  104:    memmove(&buf->content[buf->use], str, len);
call    0 returned 100%
       44:  105:    buf->use += len;
       44:  106:    buf->content[buf->use] = 0;
       44:  107:    return (0);
        -:  108:}
        -:  109:
        -:  110:virBufferPtr
        -:  111:virBufferNew(unsigned int size)
function virBufferNew called 0 returned 0% blocks executed 0%
    #####:  112:{
        -:  113:    virBufferPtr buf;
        -:  114:
    #####:  115:    if (!(buf = malloc(sizeof(*buf)))) {
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####:  116:        virXMLError(VIR_ERR_NO_MEMORY, "allocate new buffer", sizeof(*buf));
call    0 never executed
    #####:  117:        return NULL;
        -:  118:    }
    #####:  119:    if (size && (buf->content = malloc(size))==NULL) {
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
    #####:  120:        virXMLError(VIR_ERR_NO_MEMORY, "allocate buffer content", size);
call    0 never executed
    #####:  121:        free(buf);
call    0 never executed
    #####:  122:        return NULL;
        -:  123:    }
    #####:  124:    buf->size = size;
    #####:  125:    buf->use = 0;
        -:  126:
    #####:  127:    return buf;
        -:  128:}
        -:  129:	
        -:  130:void
        -:  131:virBufferFree(virBufferPtr buf)
function virBufferFree called 0 returned 0% blocks executed 0%
    #####:  132:{
    #####:  133:    if (buf) {
branch  0 never executed
branch  1 never executed
    #####:  134:        if (buf->content)
branch  0 never executed
branch  1 never executed
    #####:  135:	   free(buf->content);
call    0 never executed
    #####:  136:       	free(buf);
call    0 never executed
        -:  137:    }
    #####:  138:}
        -:  139:
        -:  140:/**
        -:  141: * virBufferVSprintf:
        -:  142: * @buf:  the buffer to dump
        -:  143: * @format:  the format
        -:  144: * @argptr:  the variable list of arguments
        -:  145: *
        -:  146: * Do a formatted print to an XML buffer.
        -:  147: *
        -:  148: * Returns 0 successful, -1 in case of internal or API error.
        -:  149: */
        -:  150:int
        -:  151:virBufferVSprintf(virBufferPtr buf, const char *format, ...)
function virBufferVSprintf called 65 returned 100% blocks executed 63%
       65:  152:{
        -:  153:    int size, count;
        -:  154:    va_list locarg, argptr;
        -:  155:
       65:  156:    if ((format == NULL) || (buf == NULL)) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  157:        return (-1);
        -:  158:    }
       65:  159:    size = buf->size - buf->use - 1;
       65:  160:    va_start(argptr, format);
call    0 returned 100%
       65:  161:    va_copy(locarg, argptr);
call    0 returned 100%
      130:  162:    while (((count = vsnprintf(&buf->content[buf->use], size, format,
call    0 returned 100%
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
        -:  163:                               locarg)) < 0) || (count >= size - 1)) {
    #####:  164:        buf->content[buf->use] = 0;
    #####:  165:        va_end(locarg);
call    0 never executed
    #####:  166:        if (virBufferGrow(buf, 1000) < 0) {
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####:  167:            return (-1);
        -:  168:        }
    #####:  169:        size = buf->size - buf->use - 1;
    #####:  170:        va_copy(locarg, argptr);
call    0 never executed
        -:  171:    }
       65:  172:    va_end(locarg);
call    0 returned 100%
       65:  173:    buf->use += count;
       65:  174:    buf->content[buf->use] = 0;
       65:  175:    return (0);
        -:  176:}
        -:  177:
        -:  178:/**
        -:  179: * virBufferStrcat:
        -:  180: * @buf:  the buffer to dump
        -:  181: * @argptr:  the variable list of strings, the last argument must be NULL
        -:  182: *
        -:  183: * Concatenate strings to an XML buffer.
        -:  184: *
        -:  185: * Returns 0 successful, -1 in case of internal or API error.
        -:  186: */
        -:  187:int
        -:  188:virBufferStrcat(virBufferPtr buf, ...)
function virBufferStrcat called 0 returned 0% blocks executed 0%
    #####:  189:{
        -:  190:    va_list ap;
        -:  191:    char *str;
        -:  192:    
    #####:  193:    va_start(ap, buf);
call    0 never executed
        -:  194:    
    #####:  195:    while ((str = va_arg(ap, char *)) != NULL) {
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
    #####:  196:        unsigned int len = strlen(str);
call    0 never executed
    #####:  197:        unsigned int needSize = buf->use + len + 2;
        -:  198:
    #####:  199:        if (needSize > buf->size) {
branch  0 never executed
branch  1 never executed
    #####:  200:           if (!virBufferGrow(buf, needSize))
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####:  201:              return -1;
        -:  202:	}
    #####:  203:        memcpy(&buf->content[buf->use], str, len);
call    0 never executed
    #####:  204:        buf->use += len;
    #####:  205:        buf->content[buf->use] = 0;
        -:  206:    }
    #####:  207:    va_end(ap);
call    0 never executed
    #####:  208:    return 0;
        -:  209:}
        -:  210:
        -:  211:#if 0
        -:  212:
        -:  213:/*
        -:  214: * This block of function are now implemented by a xend poll in
        -:  215: * xend_internal.c instead of querying the Xen store, code is kept
        -:  216: * for reference of in case Xend may not be available in the future ...
        -:  217: */
        -:  218:
        -:  219:/**
        -:  220: * virDomainGetXMLDevice:
        -:  221: * @domain: a domain object
        -:  222: * @sub: the xenstore subsection 'vbd', 'vif', ...
        -:  223: * @dev: the xenstrore internal device number
        -:  224: * @name: the value's name
        -:  225: *
        -:  226: * Extract one information the device used by the domain from xensttore
        -:  227: *
        -:  228: * Returns the new string or NULL in case of error
        -:  229: */
        -:  230:static char *
        -:  231:virDomainGetXMLDeviceInfo(virDomainPtr domain, const char *sub,
        -:  232:                          long dev, const char *name)
        -:  233:{
        -:  234:    char s[256];
        -:  235:    unsigned int len = 0;
        -:  236:
        -:  237:    snprintf(s, 255, "/local/domain/0/backend/%s/%d/%ld/%s",
        -:  238:             sub, domain->handle, dev, name);
        -:  239:    s[255] = 0;
        -:  240:
        -:  241:    return xs_read(domain->conn->xshandle, 0, &s[0], &len);
        -:  242:}
        -:  243:
        -:  244:/**
        -:  245: * virDomainGetXMLDevice:
        -:  246: * @domain: a domain object
        -:  247: * @buf: the output buffer object
        -:  248: * @dev: the xenstrore internal device number
        -:  249: *
        -:  250: * Extract and dump in the buffer information on the device used by the domain
        -:  251: *
        -:  252: * Returns 0 in case of success, -1 in case of failure
        -:  253: */
        -:  254:static int
        -:  255:virDomainGetXMLDevice(virDomainPtr domain, virBufferPtr buf, long dev)
        -:  256:{
        -:  257:    char *type, *val;
        -:  258:
        -:  259:    type = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "type");
        -:  260:    if (type == NULL)
        -:  261:        return (-1);
        -:  262:    if (!strcmp(type, "file")) {
        -:  263:        virBufferVSprintf(buf, "    <disk type='file'>\n");
        -:  264:        val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "params");
        -:  265:        if (val != NULL) {
        -:  266:            virBufferVSprintf(buf, "      <source file='%s'/>\n", val);
        -:  267:            free(val);
        -:  268:        }
        -:  269:        val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "dev");
        -:  270:        if (val != NULL) {
        -:  271:            char *tmp = val;
        -:  272:            if (!strncmp(tmp, "ioemu:", 6))
        -:  273:                tmp += 6;
        -:  274:            virBufferVSprintf(buf, "      <target dev='%s'/>\n", tmp);
        -:  275:            free(val);
        -:  276:        }
        -:  277:        val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "read-only");
        -:  278:        if (val != NULL) {
        -:  279:            virBufferVSprintf(buf, "      <readonly/>\n", val);
        -:  280:            free(val);
        -:  281:        }
        -:  282:        virBufferAdd(buf, "    </disk>\n", 12);
        -:  283:    } else if (!strcmp(type, "phy")) {
        -:  284:        virBufferVSprintf(buf, "    <disk type='device'>\n");
        -:  285:        val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "params");
        -:  286:        if (val != NULL) {
        -:  287:            virBufferVSprintf(buf, "      <source device='%s'/>\n", val);
        -:  288:            free(val);
        -:  289:        }
        -:  290:        val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "dev");
        -:  291:        if (val != NULL) {
        -:  292:            char *tmp = val;
        -:  293:            if (!strncmp(tmp, "ioemu:", 6))
        -:  294:                tmp += 6;
        -:  295:            virBufferVSprintf(buf, "      <target dev='%s'/>\n", tmp);
        -:  296:            free(val);
        -:  297:        }
        -:  298:        val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "read-only");
        -:  299:        if (val != NULL) {
        -:  300:            virBufferVSprintf(buf, "      <readonly/>\n", val);
        -:  301:            free(val);
        -:  302:        }
        -:  303:        virBufferAdd(buf, "    </disk>\n", 12);
        -:  304:    } else {
        -:  305:        TODO fprintf(stderr, "Don't know how to handle device type %s\n",
        -:  306:                     type);
        -:  307:    }
        -:  308:    free(type);
        -:  309:
        -:  310:    return (0);
        -:  311:}
        -:  312:
        -:  313:/**
        -:  314: * virDomainGetXMLDevices:
        -:  315: * @domain: a domain object
        -:  316: * @buf: the output buffer object
        -:  317: *
        -:  318: * Extract the devices used by the domain and dumps then in the buffer
        -:  319: *
        -:  320: * Returns 0 in case of success, -1 in case of failure
        -:  321: */
        -:  322:static int
        -:  323:virDomainGetXMLDevices(virDomainPtr domain, virBufferPtr buf)
        -:  324:{
        -:  325:    int ret = -1;
        -:  326:    unsigned int num, i;
        -:  327:    long id;
        -:  328:    char **list = NULL, *endptr;
        -:  329:    char backend[200];
        -:  330:    virConnectPtr conn;
        -:  331:
        -:  332:    if (!VIR_IS_CONNECTED_DOMAIN(domain))
        -:  333:        return (-1);
        -:  334:
        -:  335:    conn = domain->conn;
        -:  336:
        -:  337:    snprintf(backend, 199, "/local/domain/0/backend/vbd/%d",
        -:  338:             virDomainGetID(domain));
        -:  339:    backend[199] = 0;
        -:  340:    list = xs_directory(conn->xshandle, 0, backend, &num);
        -:  341:    ret = 0;
        -:  342:    if (list == NULL)
        -:  343:        goto done;
        -:  344:
        -:  345:    for (i = 0; i < num; i++) {
        -:  346:        id = strtol(list[i], &endptr, 10);
        -:  347:        if ((endptr == list[i]) || (*endptr != 0)) {
        -:  348:            ret = -1;
        -:  349:            goto done;
        -:  350:        }
        -:  351:        virDomainGetXMLDevice(domain, buf, id);
        -:  352:    }
        -:  353:
        -:  354:  done:
        -:  355:    if (list != NULL)
        -:  356:        free(list);
        -:  357:
        -:  358:    return (ret);
        -:  359:}
        -:  360:
        -:  361:/**
        -:  362: * virDomainGetXMLInterface:
        -:  363: * @domain: a domain object
        -:  364: * @buf: the output buffer object
        -:  365: * @dev: the xenstrore internal device number
        -:  366: *
        -:  367: * Extract and dump in the buffer information on the interface used by
        -:  368: * the domain
        -:  369: *
        -:  370: * Returns 0 in case of success, -1 in case of failure
        -:  371: */
        -:  372:static int
        -:  373:virDomainGetXMLInterface(virDomainPtr domain, virBufferPtr buf, long dev)
        -:  374:{
        -:  375:    char *type, *val;
        -:  376:
        -:  377:    type = virDomainGetXMLDeviceInfo(domain, "vif", dev, "bridge");
        -:  378:    if (type == NULL) {
        -:  379:        virBufferVSprintf(buf, "    <interface type='default'>\n");
        -:  380:        val = virDomainGetXMLDeviceInfo(domain, "vif", dev, "mac");
        -:  381:        if (val != NULL) {
        -:  382:            virBufferVSprintf(buf, "      <mac address='%s'/>\n", val);
        -:  383:            free(val);
        -:  384:        }
        -:  385:        val = virDomainGetXMLDeviceInfo(domain, "vif", dev, "script");
        -:  386:        if (val != NULL) {
        -:  387:            virBufferVSprintf(buf, "      <script path='%s'/>\n", val);
        -:  388:            free(val);
        -:  389:        }
        -:  390:        virBufferAdd(buf, "    </interface>\n", 17);
        -:  391:    } else {
        -:  392:        virBufferVSprintf(buf, "    <interface type='bridge'>\n");
        -:  393:        virBufferVSprintf(buf, "      <source bridge='%s'/>\n", type);
        -:  394:        val = virDomainGetXMLDeviceInfo(domain, "vif", dev, "mac");
        -:  395:        if (val != NULL) {
        -:  396:            virBufferVSprintf(buf, "      <mac address='%s'/>\n", val);
        -:  397:            free(val);
        -:  398:        }
        -:  399:        val = virDomainGetXMLDeviceInfo(domain, "vif", dev, "script");
        -:  400:        if (val != NULL) {
        -:  401:            virBufferVSprintf(buf, "      <script path='%s'/>\n", val);
        -:  402:            free(val);
        -:  403:        }
        -:  404:        virBufferAdd(buf, "    </interface>\n", 17);
        -:  405:    }
        -:  406:    free(type);
        -:  407:
        -:  408:    return (0);
        -:  409:}
        -:  410:
        -:  411:/**
        -:  412: * virDomainGetXMLInterfaces:
        -:  413: * @domain: a domain object
        -:  414: * @buf: the output buffer object
        -:  415: *
        -:  416: * Extract the interfaces used by the domain and dumps then in the buffer
        -:  417: *
        -:  418: * Returns 0 in case of success, -1 in case of failure
        -:  419: */
        -:  420:static int
        -:  421:virDomainGetXMLInterfaces(virDomainPtr domain, virBufferPtr buf)
        -:  422:{
        -:  423:    int ret = -1;
        -:  424:    unsigned int num, i;
        -:  425:    long id;
        -:  426:    char **list = NULL, *endptr;
        -:  427:    char backend[200];
        -:  428:    virConnectPtr conn;
        -:  429:
        -:  430:    if (!VIR_IS_CONNECTED_DOMAIN(domain))
        -:  431:        return (-1);
        -:  432:
        -:  433:    conn = domain->conn;
        -:  434:
        -:  435:    snprintf(backend, 199, "/local/domain/0/backend/vif/%d",
        -:  436:             virDomainGetID(domain));
        -:  437:    backend[199] = 0;
        -:  438:    list = xs_directory(conn->xshandle, 0, backend, &num);
        -:  439:    ret = 0;
        -:  440:    if (list == NULL)
        -:  441:        goto done;
        -:  442:
        -:  443:    for (i = 0; i < num; i++) {
        -:  444:        id = strtol(list[i], &endptr, 10);
        -:  445:        if ((endptr == list[i]) || (*endptr != 0)) {
        -:  446:            ret = -1;
        -:  447:            goto done;
        -:  448:        }
        -:  449:        virDomainGetXMLInterface(domain, buf, id);
        -:  450:    }
        -:  451:
        -:  452:  done:
        -:  453:    if (list != NULL)
        -:  454:        free(list);
        -:  455:
        -:  456:    return (ret);
        -:  457:}
        -:  458:
        -:  459:
        -:  460:
        -:  461:
        -:  462:/**
        -:  463: * virDomainGetXMLBoot:
        -:  464: * @domain: a domain object
        -:  465: * @buf: the output buffer object
        -:  466: *
        -:  467: * Extract the boot information used to start that domain
        -:  468: *
        -:  469: * Returns 0 in case of success, -1 in case of failure
        -:  470: */
        -:  471:static int
        -:  472:virDomainGetXMLBoot(virDomainPtr domain, virBufferPtr buf)
        -:  473:{
        -:  474:    char *vm, *str;
        -:  475:
        -:  476:    if (!VIR_IS_DOMAIN(domain))
        -:  477:        return (-1);
        -:  478:
        -:  479:    vm = virDomainGetVM(domain);
        -:  480:    if (vm == NULL)
        -:  481:        return (-1);
        -:  482:
        -:  483:    virBufferAdd(buf, "  <os>\n", 7);
        -:  484:    str = virDomainGetVMInfo(domain, vm, "image/ostype");
        -:  485:    if (str != NULL) {
        -:  486:        virBufferVSprintf(buf, "    <type>%s</type>\n", str);
        -:  487:        free(str);
        -:  488:    }
        -:  489:    str = virDomainGetVMInfo(domain, vm, "image/kernel");
        -:  490:    if (str != NULL) {
        -:  491:        virBufferVSprintf(buf, "    <kernel>%s</kernel>\n", str);
        -:  492:        free(str);
        -:  493:    }
        -:  494:    str = virDomainGetVMInfo(domain, vm, "image/ramdisk");
        -:  495:    if (str != NULL) {
        -:  496:        if (str[0] != 0)
        -:  497:            virBufferVSprintf(buf, "    <initrd>%s</initrd>\n", str);
        -:  498:        free(str);
        -:  499:    }
        -:  500:    str = virDomainGetVMInfo(domain, vm, "image/cmdline");
        -:  501:    if (str != NULL) {
        -:  502:        if (str[0] != 0)
        -:  503:            virBufferVSprintf(buf, "    <cmdline>%s</cmdline>\n", str);
        -:  504:        free(str);
        -:  505:    }
        -:  506:    virBufferAdd(buf, "  </os>\n", 8);
        -:  507:
        -:  508:    free(vm);
        -:  509:    return (0);
        -:  510:}
        -:  511:
        -:  512:/**
        -:  513: * virDomainGetXMLDesc:
        -:  514: * @domain: a domain object
        -:  515: * @flags: and OR'ed set of extraction flags, not used yet
        -:  516: *
        -:  517: * Provide an XML description of the domain. NOTE: this API is subject
        -:  518: * to changes.
        -:  519: *
        -:  520: * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
        -:  521: *         the caller must free() the returned value.
        -:  522: */
        -:  523:char *
        -:  524:virDomainGetXMLDesc(virDomainPtr domain, int flags)
        -:  525:{
        -:  526:    char *ret = NULL;
        -:  527:    unsigned char uuid[16];
        -:  528:    virBuffer buf;
        -:  529:    virDomainInfo info;
        -:  530:
        -:  531:    if (!VIR_IS_DOMAIN(domain))
        -:  532:        return (NULL);
        -:  533:    if (flags != 0)
        -:  534:        return (NULL);
        -:  535:    if (virDomainGetInfo(domain, &info) < 0)
        -:  536:        return (NULL);
        -:  537:
        -:  538:    ret = malloc(1000);
        -:  539:    if (ret == NULL)
        -:  540:        return (NULL);
        -:  541:    buf.content = ret;
        -:  542:    buf.size = 1000;
        -:  543:    buf.use = 0;
        -:  544:
        -:  545:    virBufferVSprintf(&buf, "<domain type='xen' id='%d'>\n",
        -:  546:                      virDomainGetID(domain));
        -:  547:    virBufferVSprintf(&buf, "  <name>%s</name>\n",
        -:  548:                      virDomainGetName(domain));
        -:  549:    if (virDomainGetUUID(domain, &uuid[0]) == 0) {
        -:  550:    virBufferVSprintf(&buf,
        -:  551:"  <uuid>%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x</uuid>\n",
        -:  552:                      uuid[0], uuid[1], uuid[2], uuid[3],
        -:  553:                      uuid[4], uuid[5], uuid[6], uuid[7],
        -:  554:                      uuid[8], uuid[9], uuid[10], uuid[11],
        -:  555:                      uuid[12], uuid[13], uuid[14], uuid[15]);
        -:  556:    }
        -:  557:    virDomainGetXMLBoot(domain, &buf);
        -:  558:    virBufferVSprintf(&buf, "  <memory>%lu</memory>\n", info.maxMem);
        -:  559:    virBufferVSprintf(&buf, "  <vcpu>%d</vcpu>\n", (int) info.nrVirtCpu);
        -:  560:    virBufferAdd(&buf, "  <devices>\n", 12);
        -:  561:    virDomainGetXMLDevices(domain, &buf);
        -:  562:    virDomainGetXMLInterfaces(domain, &buf);
        -:  563:    virBufferAdd(&buf, "  </devices>\n", 13);
        -:  564:    virBufferAdd(&buf, "</domain>\n", 10);
        -:  565:
        -:  566:    buf.content[buf.use] = 0;
        -:  567:    return (ret);
        -:  568:}
        -:  569:
        -:  570:#endif /* 0 - UNUSED */
        -:  571:
        -:  572:#ifndef PROXY
        -:  573:/**
        -:  574: * virDomainParseXMLOSDescHVM:
        -:  575: * @node: node containing HVM OS description
        -:  576: * @buf: a buffer for the result S-Expr
        -:  577: * @ctxt: a path context representing the XML description
        -:  578: *
        -:  579: * Parse the OS part of the XML description for an HVM domain and add it to
        -:  580: * the S-Expr in buf. This is a temporary interface as the S-Expr interface
        -:  581: * will be replaced by XML-RPC in the future. However the XML format should
        -:  582: * stay valid over time.
        -:  583: *
        -:  584: * Returns 0 in case of success, -1 in case of error.
        -:  585: */
        -:  586:static int
        -:  587:virDomainParseXMLOSDescHVM(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr ctxt)
function virDomainParseXMLOSDescHVM called 1 returned 100% blocks executed 77%
        1:  588:{
        1:  589:    xmlXPathObjectPtr obj = NULL;
        -:  590:    xmlNodePtr cur, txt;
        1:  591:    const xmlChar *type = NULL;
        1:  592:    const xmlChar *loader = NULL;
        1:  593:    const xmlChar *boot_dev = NULL;
        1:  594:    xmlChar *graphics_type = NULL;
        -:  595:
        1:  596:    cur = node->children;
        9:  597:    while (cur != NULL) {
branch  0 taken 88%
branch  1 taken 13% (fallthrough)
        7:  598:        if (cur->type == XML_ELEMENT_NODE) {
branch  0 taken 43% (fallthrough)
branch  1 taken 57%
        3:  599:            if ((type == NULL)
branch  0 taken 33% (fallthrough)
branch  1 taken 67%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -:  600:                && (xmlStrEqual(cur->name, BAD_CAST "type"))) {
        1:  601:                txt = cur->children;
        1:  602:                if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
        -:  603:		    (txt->next == NULL))
        1:  604:                    type = txt->content;
        2:  605:            } else if ((loader == NULL) &&
branch  0 taken 50% (fallthrough)
branch  1 taken 50%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -:  606:                       (xmlStrEqual(cur->name, BAD_CAST "loader"))) {
        1:  607:                txt = cur->children;
        1:  608:                if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
        -:  609:		    (txt->next == NULL))
        1:  610:                    loader = txt->content;
        1:  611:            } else if ((boot_dev == NULL) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -:  612:                       (xmlStrEqual(cur->name, BAD_CAST "boot"))) {
        1:  613:                boot_dev = xmlGetProp(cur, BAD_CAST "dev");
call    0 returned 100%
        -:  614:            }
        -:  615:        }
        7:  616:        cur = cur->next;
        -:  617:    }
        1:  618:    if ((type == NULL) || (!xmlStrEqual(type, BAD_CAST "hvm"))) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
branch  3 taken 0% (fallthrough)
branch  4 taken 100%
        -:  619:        /* VIR_ERR_OS_TYPE */
    #####:  620:        virXMLError(VIR_ERR_OS_TYPE, (const char *) type, 0);
call    0 never executed
    #####:  621:        return (-1);
        -:  622:    }
        1:  623:    virBufferAdd(buf, "(image (hvm ", 12);
call    0 returned 100%
        1:  624:    if (loader == NULL) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  625:       virXMLError(VIR_ERR_NO_KERNEL, NULL, 0);
call    0 never executed
    #####:  626:       goto error;
        -:  627:    } else {
        1:  628:       virBufferVSprintf(buf, "(kernel '%s')", (const char *) loader);
call    0 returned 100%
        -:  629:    }
        -:  630:
        -:  631:    /* get the device emulation model */
        1:  632:    obj = xmlXPathEval(BAD_CAST "string(/domain/devices/emulator[1])", ctxt);
call    0 returned 100%
        1:  633:    if ((obj == NULL) || (obj->type != XPATH_STRING) ||
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 0% (fallthrough)
branch  7 taken 100%
        -:  634:        (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
    #####:  635:        virXMLError(VIR_ERR_NO_KERNEL, NULL, 0); /* TODO: error */
call    0 never executed
    #####:  636:        goto error;
        -:  637:    }
        1:  638:    virBufferVSprintf(buf, "(device_model '%s')",
call    0 returned 100%
        -:  639:                      (const char *) obj->stringval);
        1:  640:    xmlXPathFreeObject(obj);
call    0 returned 100%
        1:  641:    obj = NULL;
        -:  642:
        1:  643:    if (boot_dev) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1:  644:       if (xmlStrEqual(boot_dev, BAD_CAST "fd")) {
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  645:          virBufferVSprintf(buf, "(boot a)", (const char *) boot_dev);
call    0 never executed
        1:  646:       } else if (xmlStrEqual(boot_dev, BAD_CAST "cdrom")) {
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  647:          virBufferVSprintf(buf, "(boot d)", (const char *) boot_dev);
call    0 never executed
        1:  648:       } else if (xmlStrEqual(boot_dev, BAD_CAST "hd")) {
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
        1:  649:          virBufferVSprintf(buf, "(boot c)", (const char *) boot_dev);
call    0 returned 100%
        -:  650:       } else {
        -:  651:         /* Any other type of boot dev is unsupported right now */
    #####:  652:         virXMLError(VIR_ERR_XML_ERROR, NULL, 0);
call    0 never executed
        -:  653:       }
        -:  654:
        -:  655:       /* get the 1st floppy device file */
        1:  656:       obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='floppy' and target/@dev='fda']/source", ctxt);
call    0 returned 100%
        1:  657:       if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 0% (fallthrough)
branch  5 taken 100%
branch  6 never executed
branch  7 never executed
        -:  658:           (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
    #####:  659:         cur = obj->nodesetval->nodeTab[0];
    #####:  660:         virBufferVSprintf(buf, "(fda '%s')",
call    0 never executed
call    1 never executed
        -:  661:                           (const char *) xmlGetProp(cur, BAD_CAST "file"));
    #####:  662:         cur = NULL;
        -:  663:       }
        1:  664:       if (obj) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1:  665:         xmlXPathFreeObject(obj);
call    0 returned 100%
        1:  666:         obj = NULL;
        -:  667:    }
        -:  668:
        -:  669:       /* get the 2nd floppy device file */
        1:  670:       obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='floppy' and target/@dev='fdb']/source", ctxt);
call    0 returned 100%
        1:  671:       if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 0% (fallthrough)
branch  5 taken 100%
branch  6 never executed
branch  7 never executed
        -:  672:           (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
    #####:  673:         cur = obj->nodesetval->nodeTab[0];
    #####:  674:         virBufferVSprintf(buf, "(fdb '%s')",
call    0 never executed
call    1 never executed
        -:  675:                           (const char *) xmlGetProp(cur, BAD_CAST "file"));
    #####:  676:         cur = NULL;
        -:  677:       }
        1:  678:       if (obj) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1:  679:         xmlXPathFreeObject(obj);
call    0 returned 100%
        1:  680:         obj = NULL;
        -:  681:       }
        -:  682:
        -:  683:
        -:  684:       /* get the cdrom device file */
        -:  685:       /* XXX new (3.0.3) Xend puts cdrom devs in usual (devices) block */
        1:  686:       obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='cdrom' and target/@dev='hdc']/source", ctxt);
call    0 returned 100%
        1:  687:       if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 100% (fallthrough)
branch  7 taken 0%
        -:  688:           (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
        1:  689:         cur = obj->nodesetval->nodeTab[0];
        1:  690:         virBufferVSprintf(buf, "(cdrom '%s')",
call    0 returned 100%
call    1 returned 100%
        -:  691:                           (const char *) xmlGetProp(cur, BAD_CAST "file"));
        1:  692:         cur = NULL;
        -:  693:       }
        1:  694:       if (obj) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1:  695:         xmlXPathFreeObject(obj);
call    0 returned 100%
        1:  696:         obj = NULL;
        -:  697:       }
        -:  698:
        1:  699:       obj = xmlXPathEval(BAD_CAST "/domain/features/acpi", ctxt);
call    0 returned 100%
        1:  700:       if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 100% (fallthrough)
branch  7 taken 0%
        -:  701:	   (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
        1:  702:           virBufferAdd(buf, "(acpi 1)", 8);
call    0 returned 100%
        1:  703:	   xmlXPathFreeObject(obj);
call    0 returned 100%
        1:  704:	   obj = NULL;
        -:  705:       }
        1:  706:       obj = xmlXPathEval(BAD_CAST "/domain/features/apic", ctxt);
call    0 returned 100%
        1:  707:       if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 0% (fallthrough)
branch  7 taken 100%
        -:  708:	   (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
    #####:  709:           virBufferAdd(buf, "(apic 1)", 8);
call    0 never executed
    #####:  710:	   xmlXPathFreeObject(obj);
call    0 never executed
    #####:  711:	   obj = NULL;
        -:  712:       }
        1:  713:       obj = xmlXPathEval(BAD_CAST "/domain/features/pae", ctxt);
call    0 returned 100%
        1:  714:       if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 0% (fallthrough)
branch  7 taken 100%
        -:  715:	   (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
    #####:  716:           virBufferAdd(buf, "(pae 1)", 7);
call    0 never executed
    #####:  717:	   xmlXPathFreeObject(obj);
call    0 never executed
    #####:  718:	   obj = NULL;
        -:  719:       }
        -:  720:    }
        -:  721:
        1:  722:    obj = xmlXPathEval(BAD_CAST "count(domain/devices/console) > 0", ctxt);
call    0 returned 100%
        1:  723:    if ((obj == NULL) || (obj->type != XPATH_BOOLEAN)) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
    #####:  724:      virXMLError(VIR_ERR_XML_ERROR, NULL, 0);
call    0 never executed
    #####:  725:      goto error;
        -:  726:    }
        1:  727:    if (obj->boolval) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  728:      virBufferAdd(buf, "(serial pty)", 12);
call    0 never executed
        -:  729:    }
        1:  730:    xmlXPathFreeObject(obj);
call    0 returned 100%
        1:  731:    obj = NULL;
        -:  732:    
        -:  733:    /* Is a graphics device specified? */
        1:  734:    obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics[1]", ctxt);
call    0 returned 100%
        1:  735:    if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 0% (fallthrough)
branch  7 taken 100%
        -:  736:        (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr = 0)) {
    #####:  737:        virXMLError(VIR_ERR_NO_OS, "", 0); /* TODO: error */
call    0 never executed
    #####:  738:        goto error;
        -:  739:    }
        -:  740:
        1:  741:    graphics_type = xmlGetProp(obj->nodesetval->nodeTab[0], BAD_CAST "type");
call    0 returned 100%
        1:  742:    if (graphics_type != NULL) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1:  743:        if (xmlStrEqual(graphics_type, BAD_CAST "sdl")) {
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  744:            virBufferAdd(buf, "(sdl 1)", 7);
call    0 never executed
        -:  745:            // TODO:
        -:  746:            // Need to understand sdl options
        -:  747:            //
        -:  748:            //virBufferAdd(buf, "(display localhost:10.0)", 24);
        -:  749:            //virBufferAdd(buf, "(xauthority /root/.Xauthority)", 30);
        -:  750:        }
        1:  751:        else if (xmlStrEqual(graphics_type, BAD_CAST "vnc"))
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
        1:  752:            virBufferAdd(buf, "(vnc 1)", 7);
call    0 returned 100%
        1:  753:        xmlFree(graphics_type);
call    0 returned 100%
        -:  754:    }
        1:  755:    xmlXPathFreeObject(obj);
call    0 returned 100%
        -:  756:
        1:  757:    virBufferAdd(buf, "))", 2);
call    0 returned 100%
        -:  758:
        1:  759:    return (0);
    #####:  760:error:
    #####:  761:    if (obj != NULL)
branch  0 never executed
branch  1 never executed
    #####:  762:        xmlXPathFreeObject(obj);
call    0 never executed
    #####:  763:    return(-1);
        -:  764:}
        -:  765:
        -:  766:/**
        -:  767: * virDomainParseXMLOSDescPV:
        -:  768: * @node: node containing PV OS description
        -:  769: * @buf: a buffer for the result S-Expr
        -:  770: *
        -:  771: * Parse the OS part of the XML description for a paravirtualized domain
        -:  772: * and add it to the S-Expr in buf.  This is a temporary interface as the
        -:  773: * S-Expr interface will be replaced by XML-RPC in the future. However
        -:  774: * the XML format should stay valid over time.
        -:  775: *
        -:  776: * Returns 0 in case of success, -1 in case of error.
        -:  777: */
        -:  778:static int
        -:  779:virDomainParseXMLOSDescPV(xmlNodePtr node, virBufferPtr buf)
function virDomainParseXMLOSDescPV called 1 returned 100% blocks executed 84%
        1:  780:{
        -:  781:    xmlNodePtr cur, txt;
        1:  782:    const xmlChar *type = NULL;
        1:  783:    const xmlChar *root = NULL;
        1:  784:    const xmlChar *kernel = NULL;
        1:  785:    const xmlChar *initrd = NULL;
        1:  786:    const xmlChar *cmdline = NULL;
        -:  787:
        1:  788:    cur = node->children;
       11:  789:    while (cur != NULL) {
branch  0 taken 90%
branch  1 taken 10% (fallthrough)
        9:  790:        if (cur->type == XML_ELEMENT_NODE) {
branch  0 taken 44% (fallthrough)
branch  1 taken 56%
        4:  791:            if ((type == NULL)
branch  0 taken 25% (fallthrough)
branch  1 taken 75%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -:  792:                && (xmlStrEqual(cur->name, BAD_CAST "type"))) {
        1:  793:                txt = cur->children;
        1:  794:                if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
        -:  795:		    (txt->next == NULL))
        1:  796:                    type = txt->content;
        3:  797:            } else if ((kernel == NULL) &&
branch  0 taken 33% (fallthrough)
branch  1 taken 67%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -:  798:                       (xmlStrEqual(cur->name, BAD_CAST "kernel"))) {
        1:  799:                txt = cur->children;
        1:  800:                if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
        -:  801:		    (txt->next == NULL))
        1:  802:                    kernel = txt->content;
        2:  803:            } else if ((root == NULL) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
branch  3 taken 0% (fallthrough)
branch  4 taken 100%
        -:  804:                       (xmlStrEqual(cur->name, BAD_CAST "root"))) {
    #####:  805:                txt = cur->children;
    #####:  806:                if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
branch  4 never executed
branch  5 never executed
        -:  807:		    (txt->next == NULL))
    #####:  808:                    root = txt->content;
        2:  809:            } else if ((initrd == NULL) &&
branch  0 taken 50% (fallthrough)
branch  1 taken 50%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -:  810:                       (xmlStrEqual(cur->name, BAD_CAST "initrd"))) {
        1:  811:                txt = cur->children;
        1:  812:                if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
        -:  813:		    (txt->next == NULL))
        1:  814:                    initrd = txt->content;
        1:  815:            } else if ((cmdline == NULL) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -:  816:                       (xmlStrEqual(cur->name, BAD_CAST "cmdline"))) {
        1:  817:                txt = cur->children;
        1:  818:                if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
        -:  819:		    (txt->next == NULL))
        1:  820:                    cmdline = txt->content;
        -:  821:            }
        -:  822:        }
        9:  823:        cur = cur->next;
        -:  824:    }
        1:  825:    if ((type != NULL) && (!xmlStrEqual(type, BAD_CAST "linux"))) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
branch  3 taken 0% (fallthrough)
branch  4 taken 100%
        -:  826:        /* VIR_ERR_OS_TYPE */
    #####:  827:        virXMLError(VIR_ERR_OS_TYPE, (const char *) type, 0);
call    0 never executed
    #####:  828:        return (-1);
        -:  829:    }
        1:  830:    virBufferAdd(buf, "(image (linux ", 14);
call    0 returned 100%
        1:  831:    if (kernel == NULL) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  832:      	virXMLError(VIR_ERR_NO_KERNEL, NULL, 0);
call    0 never executed
    #####:  833:	return (-1);
        -:  834:    } else {
        1:  835:	virBufferVSprintf(buf, "(kernel '%s')", (const char *) kernel);
call    0 returned 100%
        -:  836:    }
        1:  837:    if (initrd != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1:  838:        virBufferVSprintf(buf, "(ramdisk '%s')", (const char *) initrd);
call    0 returned 100%
        1:  839:    if (root != NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  840:        virBufferVSprintf(buf, "(root '%s')", (const char *) root);
call    0 never executed
        1:  841:    if (cmdline != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1:  842:        virBufferVSprintf(buf, "(args '%s')", (const char *) cmdline);
call    0 returned 100%
        1:  843:    virBufferAdd(buf, "))", 2);
call    0 returned 100%
        1:  844:    return (0);
        -:  845:}
        -:  846:
        -:  847:/**
        -:  848: * virDomainParseXMLDiskDesc:
        -:  849: * @node: node containing disk description
        -:  850: * @buf: a buffer for the result S-Expr
        -:  851: *
        -:  852: * Parse the one disk in the XML description and add it to the S-Expr in buf
        -:  853: * This is a temporary interface as the S-Expr interface
        -:  854: * will be replaced by XML-RPC in the future. However the XML format should
        -:  855: * stay valid over time.
        -:  856: *
        -:  857: * Returns 0 in case of success, -1 in case of error.
        -:  858: */
        -:  859:static int
        -:  860:virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
function virDomainParseXMLDiskDesc called 3 returned 100% blocks executed 65%
        3:  861:{
        -:  862:    xmlNodePtr cur;
        3:  863:    xmlChar *type = NULL;
        3:  864:    xmlChar *device = NULL;
        3:  865:    xmlChar *source = NULL;
        3:  866:    xmlChar *target = NULL;
        3:  867:    int ro = 0;
        3:  868:    int typ = 0;
        -:  869:
        3:  870:    type = xmlGetProp(node, BAD_CAST "type");
call    0 returned 100%
        3:  871:    if (type != NULL) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        3:  872:        if (xmlStrEqual(type, BAD_CAST "file"))
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
        3:  873:            typ = 0;
    #####:  874:        else if (xmlStrEqual(type, BAD_CAST "block"))
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####:  875:            typ = 1;
        3:  876:        xmlFree(type);
call    0 returned 100%
        -:  877:    }
        3:  878:    device = xmlGetProp(node, BAD_CAST "device");
call    0 returned 100%
        -:  879:    
        3:  880:    cur = node->children;
       23:  881:    while (cur != NULL) {
branch  0 taken 85%
branch  1 taken 15% (fallthrough)
       17:  882:        if (cur->type == XML_ELEMENT_NODE) {
branch  0 taken 41% (fallthrough)
branch  1 taken 59%
        7:  883:            if ((source == NULL) &&
branch  0 taken 43% (fallthrough)
branch  1 taken 57%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -:  884:                (xmlStrEqual(cur->name, BAD_CAST "source"))) {
        -:  885:
        3:  886:                if (typ == 0)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        3:  887:                    source = xmlGetProp(cur, BAD_CAST "file");
call    0 returned 100%
        -:  888:                else
    #####:  889:                    source = xmlGetProp(cur, BAD_CAST "dev");
call    0 never executed
        7:  890:            } else if ((target == NULL) &&
branch  0 taken 75% (fallthrough)
branch  1 taken 25%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -:  891:                       (xmlStrEqual(cur->name, BAD_CAST "target"))) {
        3:  892:                target = xmlGetProp(cur, BAD_CAST "dev");
call    0 returned 100%
        1:  893:            } else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) {
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
        1:  894:                ro = 1;
        -:  895:            }
        -:  896:        }
       17:  897:        cur = cur->next;
        -:  898:    }
        -:  899:
        3:  900:    if (source == NULL) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  901:        virXMLError(VIR_ERR_NO_SOURCE, (const char *) target, 0);
call    0 never executed
        -:  902:
    #####:  903:        if (target != NULL)
branch  0 never executed
branch  1 never executed
    #####:  904:            xmlFree(target);
call    0 never executed
    #####:  905:        return (-1);
        -:  906:    }
        3:  907:    if (target == NULL) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  908:        virXMLError(VIR_ERR_NO_TARGET, (const char *) source, 0);
call    0 never executed
    #####:  909:        if (source != NULL)
branch  0 never executed
branch  1 never executed
    #####:  910:            xmlFree(source);
call    0 never executed
    #####:  911:        return (-1);
        -:  912:    }
        -:  913:
        -:  914:    /* Skip floppy/cdrom disk used as the boot device
        -:  915:     * since that's incorporated into the HVM kernel
        -:  916:     * (image (hvm..)) part of the sexpr, rather than
        -:  917:     * the (devices...) bit. Odd Xend HVM config :-(
        -:  918:     * XXX This will have to change in Xen 3.0.3
        -:  919:     */
        5:  920:    if (hvm && device &&
branch  0 taken 33% (fallthrough)
branch  1 taken 67%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
        1:  921:        (!strcmp((const char *)device, "floppy") ||
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
branch  2 never executed
branch  3 never executed
branch  4 never executed
branch  5 never executed
branch  6 never executed
branch  7 never executed
call    8 returned 100%
        1:  922:         !strcmp((const char *)device, "cdrom"))) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
branch  2 never executed
branch  3 never executed
branch  4 never executed
branch  5 never executed
branch  6 never executed
branch  7 never executed
call    8 returned 100%
        1:  923:      return 0;
        -:  924:    }
        -:  925:
        -:  926:
        2:  927:    virBufferAdd(buf, "(device ", 8);
call    0 returned 100%
        2:  928:    virBufferAdd(buf, "(vbd ", 5);
call    0 returned 100%
        -:  929:    /* XXX ioemu prefix is going away in Xen 3.0.3 */
        2:  930:    if (hvm) {
branch  0 taken 50% (fallthrough)
branch  1 taken 50%
        1:  931:        char *tmp = (char *)target;
        1:  932:        if (!strncmp((const char *) tmp, "ioemu:", 6))
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
        1:  933:            tmp += 6;
        1:  934:        virBufferVSprintf(buf, "(dev 'ioemu:%s')", (const char *) tmp);
call    0 returned 100%
        -:  935:    } else
        1:  936:    virBufferVSprintf(buf, "(dev '%s')", (const char *) target);
call    0 returned 100%
        2:  937:    if (typ == 0)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        2:  938:        virBufferVSprintf(buf, "(uname 'file:%s')", source);
call    0 returned 100%
    #####:  939:    else if (typ == 1) {
branch  0 never executed
branch  1 never executed
    #####:  940:        if (source[0] == '/')
branch  0 never executed
branch  1 never executed
    #####:  941:            virBufferVSprintf(buf, "(uname 'phy:%s')", source);
call    0 never executed
        -:  942:        else
    #####:  943:            virBufferVSprintf(buf, "(uname 'phy:/dev/%s')", source);
call    0 never executed
        -:  944:    }
        2:  945:    if (ro == 0)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        2:  946:        virBufferVSprintf(buf, "(mode 'w')");
call    0 returned 100%
    #####:  947:    else if (ro == 1)
branch  0 never executed
branch  1 never executed
    #####:  948:        virBufferVSprintf(buf, "(mode 'r')");
call    0 never executed
        -:  949:
        2:  950:    virBufferAdd(buf, ")", 1);
call    0 returned 100%
        2:  951:    virBufferAdd(buf, ")", 1);
call    0 returned 100%
        2:  952:    xmlFree(target);
call    0 returned 100%
        2:  953:    xmlFree(source);
call    0 returned 100%
        2:  954:    return (0);
        -:  955:}
        -:  956:
        -:  957:/**
        -:  958: * virDomainParseXMLIfDesc:
        -:  959: * @node: node containing the interface description
        -:  960: * @buf: a buffer for the result S-Expr
        -:  961: *
        -:  962: * Parse the one interface the XML description and add it to the S-Expr in buf
        -:  963: * This is a temporary interface as the S-Expr interface
        -:  964: * will be replaced by XML-RPC in the future. However the XML format should
        -:  965: * stay valid over time.
        -:  966: *
        -:  967: * Returns 0 in case of success, -1 in case of error.
        -:  968: */
        -:  969:static int
        -:  970:virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
function virDomainParseXMLIfDesc called 1 returned 100% blocks executed 88%
        1:  971:{
        -:  972:    xmlNodePtr cur;
        1:  973:    xmlChar *type = NULL;
        1:  974:    xmlChar *source = NULL;
        1:  975:    xmlChar *mac = NULL;
        1:  976:    xmlChar *script = NULL;
        1:  977:    int typ = 0;
        -:  978:
        1:  979:    type = xmlGetProp(node, BAD_CAST "type");
call    0 returned 100%
        1:  980:    if (type != NULL) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1:  981:        if (xmlStrEqual(type, BAD_CAST "bridge"))
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
        1:  982:            typ = 0;
    #####:  983:        else if (xmlStrEqual(type, BAD_CAST "ethernet"))
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####:  984:            typ = 1;
        1:  985:        xmlFree(type);
call    0 returned 100%
        -:  986:    }
        1:  987:    cur = node->children;
        9:  988:    while (cur != NULL) {
branch  0 taken 88%
branch  1 taken 13% (fallthrough)
        7:  989:        if (cur->type == XML_ELEMENT_NODE) {
branch  0 taken 43% (fallthrough)
branch  1 taken 57%
        3:  990:            if ((source == NULL) &&
branch  0 taken 33% (fallthrough)
branch  1 taken 67%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -:  991:                (xmlStrEqual(cur->name, BAD_CAST "source"))) {
        -:  992:
        1:  993:                if (typ == 0)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1:  994:                    source = xmlGetProp(cur, BAD_CAST "bridge");
call    0 returned 100%
        -:  995:                else
    #####:  996:                    source = xmlGetProp(cur, BAD_CAST "dev");
call    0 never executed
        3:  997:            } else if ((mac == NULL) &&
branch  0 taken 50% (fallthrough)
branch  1 taken 50%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -:  998:                       (xmlStrEqual(cur->name, BAD_CAST "mac"))) {
        1:  999:                mac = xmlGetProp(cur, BAD_CAST "address");
call    0 returned 100%
        1: 1000:            } else if ((script == NULL) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -: 1001:                       (xmlStrEqual(cur->name, BAD_CAST "script"))) {
        1: 1002:                script = xmlGetProp(cur, BAD_CAST "path");
call    0 returned 100%
        -: 1003:            }
        -: 1004:        }
        7: 1005:        cur = cur->next;
        -: 1006:    }
        -: 1007:
        1: 1008:    virBufferAdd(buf, "(vif ", 5);
call    0 returned 100%
        1: 1009:    if (mac != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1: 1010:        virBufferVSprintf(buf, "(mac '%s')", (const char *) mac);
call    0 returned 100%
        1: 1011:    if (source != NULL) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1: 1012:        if (typ == 0)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1: 1013:            virBufferVSprintf(buf, "(bridge '%s')", (const char *) source);
call    0 returned 100%
        -: 1014:        else                    /* TODO does that work like that ? */
    #####: 1015:            virBufferVSprintf(buf, "(dev '%s')", (const char *) source);
call    0 never executed
        -: 1016:    }
        1: 1017:    if (script != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1: 1018:        virBufferVSprintf(buf, "(script '%s')", script);
call    0 returned 100%
        1: 1019:    if (hvm)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1: 1020:        virBufferAdd(buf, "(type ioemu)", 12);
call    0 returned 100%
        -: 1021:
        1: 1022:    virBufferAdd(buf, ")", 1);
call    0 returned 100%
        1: 1023:    if (mac != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1: 1024:        xmlFree(mac);
call    0 returned 100%
        1: 1025:    if (source != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1: 1026:        xmlFree(source);
call    0 returned 100%
        1: 1027:    if (script != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        1: 1028:        xmlFree(script);
call    0 returned 100%
        1: 1029:    return (0);
        -: 1030:}
        -: 1031:
        -: 1032:/**
        -: 1033: * virDomainParseXMLDesc:
        -: 1034: * @xmldesc: string with the XML description
        -: 1035: *
        -: 1036: * Parse the XML description and turn it into the xend sexp needed to
        -: 1037: * create the comain. This is a temporary interface as the S-Expr interface
        -: 1038: * will be replaced by XML-RPC in the future. However the XML format should
        -: 1039: * stay valid over time.
        -: 1040: *
        -: 1041: * Returns the 0 terminatedi S-Expr string or NULL in case of error.
        -: 1042: *         the caller must free() the returned value.
        -: 1043: */
        -: 1044:char *
        -: 1045:virDomainParseXMLDesc(const char *xmldesc, char **name)
function virDomainParseXMLDesc called 2 returned 100% blocks executed 77%
        2: 1046:{
        2: 1047:    xmlDocPtr xml = NULL;
        -: 1048:    xmlNodePtr node;
        2: 1049:    char *ret = NULL, *nam = NULL;
        -: 1050:    virBuffer buf;
        -: 1051:    xmlChar *prop;
        2: 1052:    xmlXPathObjectPtr obj = NULL;
        2: 1053:    xmlXPathObjectPtr tmpobj = NULL;
        2: 1054:    xmlXPathContextPtr ctxt = NULL;
        -: 1055:    int i, res;
        2: 1056:    int bootloader = 0;
        2: 1057:    int hvm = 0;
        -: 1058:
        2: 1059:    if (name != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        2: 1060:        *name = NULL;
        2: 1061:    ret = malloc(1000);
call    0 returned 100%
        2: 1062:    if (ret == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 1063:        return (NULL);
        2: 1064:    buf.content = ret;
        2: 1065:    buf.size = 1000;
        2: 1066:    buf.use = 0;
        -: 1067:
        2: 1068:    xml = xmlReadDoc((const xmlChar *) xmldesc, "domain.xml", NULL,
call    0 returned 100%
        -: 1069:                     XML_PARSE_NOENT | XML_PARSE_NONET |
        -: 1070:                     XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
        2: 1071:    if (xml == NULL) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
    #####: 1072:        goto error;
        -: 1073:    }
        2: 1074:    node = xmlDocGetRootElement(xml);
call    0 returned 100%
        2: 1075:    if ((node == NULL) || (!xmlStrEqual(node->name, BAD_CAST "domain")))
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -: 1076:        goto error;
        -: 1077:
        2: 1078:    prop = xmlGetProp(node, BAD_CAST "type");
call    0 returned 100%
        2: 1079:    if (prop != NULL) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        2: 1080:        if (!xmlStrEqual(prop, BAD_CAST "xen")) {
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####: 1081:            xmlFree(prop);
call    0 never executed
    #####: 1082:            goto error;
        -: 1083:        }
        2: 1084:        xmlFree(prop);
call    0 returned 100%
        -: 1085:    }
        2: 1086:    virBufferAdd(&buf, "(vm ", 4);
call    0 returned 100%
        2: 1087:    ctxt = xmlXPathNewContext(xml);
call    0 returned 100%
        2: 1088:    if (ctxt == NULL) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 1089:        goto error;
        -: 1090:    }
        -: 1091:    /*
        -: 1092:     * extract some of the basics, name, memory, cpus ...
        -: 1093:     */
        2: 1094:    obj = xmlXPathEval(BAD_CAST "string(/domain/name[1])", ctxt);
call    0 returned 100%
        2: 1095:    if ((obj == NULL) || (obj->type != XPATH_STRING) ||
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 0% (fallthrough)
branch  7 taken 100%
        -: 1096:        (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
    #####: 1097:        virXMLError(VIR_ERR_NO_NAME, xmldesc, 0);
call    0 never executed
    #####: 1098:        goto error;
        -: 1099:    }
        2: 1100:    virBufferVSprintf(&buf, "(name '%s')", obj->stringval);
call    0 returned 100%
        2: 1101:    nam = strdup((const char *) obj->stringval);
call    0 returned 100%
        2: 1102:    if (nam == NULL) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 1103:        virXMLError(VIR_ERR_NO_MEMORY, "copying name", 0);
call    0 never executed
    #####: 1104:        goto error;
        -: 1105:    }
        2: 1106:    xmlXPathFreeObject(obj);
call    0 returned 100%
        -: 1107:
        2: 1108:    obj = xmlXPathEval(BAD_CAST "number(/domain/memory[1])", ctxt);
call    0 returned 100%
        2: 1109:    if ((obj == NULL) || (obj->type != XPATH_NUMBER) ||
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 0% (fallthrough)
branch  7 taken 100%
        -: 1110:        (isnan(obj->floatval)) || (obj->floatval < 64000)) {
    #####: 1111:        virBufferVSprintf(&buf, "(memory 128)(maxmem 128)");
call    0 never executed
        -: 1112:    } else {
        2: 1113:        unsigned long mem = (obj->floatval / 1024);
        -: 1114:
        2: 1115:        virBufferVSprintf(&buf, "(memory %lu)(maxmem %lu)", mem, mem);
call    0 returned 100%
        -: 1116:    }
        2: 1117:    xmlXPathFreeObject(obj);
call    0 returned 100%
        -: 1118:
        2: 1119:    obj = xmlXPathEval(BAD_CAST "number(/domain/vcpu[1])", ctxt);
call    0 returned 100%
        2: 1120:    if ((obj == NULL) || (obj->type != XPATH_NUMBER) ||
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 0% (fallthrough)
branch  7 taken 100%
        -: 1121:        (isnan(obj->floatval)) || (obj->floatval <= 0)) {
    #####: 1122:        virBufferVSprintf(&buf, "(vcpus 1)");
call    0 never executed
        -: 1123:    } else {
        2: 1124:        unsigned int cpu = (unsigned int) obj->floatval;
        -: 1125:
        2: 1126:        virBufferVSprintf(&buf, "(vcpus %u)", cpu);
call    0 returned 100%
        -: 1127:    }
        2: 1128:    xmlXPathFreeObject(obj);
call    0 returned 100%
        -: 1129:
        2: 1130:    obj = xmlXPathEval(BAD_CAST "string(/domain/uuid[1])", ctxt);
call    0 returned 100%
        2: 1131:    if ((obj == NULL) || ((obj->type == XPATH_STRING) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 100% (fallthrough)
branch  7 taken 0%
        -: 1132:        (obj->stringval != NULL) && (obj->stringval[0] != 0))) {
        2: 1133:        virBufferVSprintf(&buf, "(uuid '%s')", obj->stringval);
call    0 returned 100%
        -: 1134:    }
        2: 1135:    xmlXPathFreeObject(obj);
call    0 returned 100%
        -: 1136:
        2: 1137:    obj = xmlXPathEval(BAD_CAST "string(/domain/bootloader[1])", ctxt);
call    0 returned 100%
        2: 1138:    if ((obj != NULL) && (obj->type == XPATH_STRING) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 0% (fallthrough)
branch  7 taken 100%
        -: 1139:        (obj->stringval != NULL) && (obj->stringval[0] != 0)) {
    #####: 1140:	virBufferVSprintf(&buf, "(bootloader '%s')", obj->stringval);
call    0 never executed
    #####: 1141:	bootloader = 1;
        -: 1142:    }
        2: 1143:    xmlXPathFreeObject(obj);
call    0 returned 100%
        -: 1144:
        2: 1145:    obj = xmlXPathEval(BAD_CAST "string(/domain/on_poweroff[1])", ctxt);
call    0 returned 100%
        2: 1146:    if ((obj != NULL) && (obj->type == XPATH_STRING) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 100% (fallthrough)
branch  7 taken 0%
        -: 1147:        (obj->stringval != NULL) && (obj->stringval[0] != 0)) {
        2: 1148:	virBufferVSprintf(&buf, "(on_poweroff '%s')", obj->stringval);
call    0 returned 100%
        -: 1149:    }
        2: 1150:    xmlXPathFreeObject(obj);
call    0 returned 100%
        -: 1151:
        2: 1152:    obj = xmlXPathEval(BAD_CAST "string(/domain/on_reboot[1])", ctxt);
call    0 returned 100%
        2: 1153:    if ((obj != NULL) && (obj->type == XPATH_STRING) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 100% (fallthrough)
branch  7 taken 0%
        -: 1154:        (obj->stringval != NULL) && (obj->stringval[0] != 0)) {
        2: 1155:	virBufferVSprintf(&buf, "(on_reboot '%s')", obj->stringval);
call    0 returned 100%
        -: 1156:    }
        2: 1157:    xmlXPathFreeObject(obj);
call    0 returned 100%
        -: 1158:
        2: 1159:    obj = xmlXPathEval(BAD_CAST "string(/domain/on_crash[1])", ctxt);
call    0 returned 100%
        2: 1160:    if ((obj != NULL) && (obj->type == XPATH_STRING) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 100% (fallthrough)
branch  7 taken 0%
        -: 1161:        (obj->stringval != NULL) && (obj->stringval[0] != 0)) {
        2: 1162:	virBufferVSprintf(&buf, "(on_crash '%s')", obj->stringval);
call    0 returned 100%
        -: 1163:    }
        2: 1164:    xmlXPathFreeObject(obj);
call    0 returned 100%
        -: 1165:
        2: 1166:    obj = xmlXPathEval(BAD_CAST "/domain/os[1]", ctxt);
call    0 returned 100%
        2: 1167:    if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 100% (fallthrough)
branch  7 taken 0%
        -: 1168:        (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
        -: 1169:	/* Analyze of the os description, based on HVM or PV. */
        2: 1170:	tmpobj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1])", ctxt);
call    0 returned 100%
        2: 1171:	if ((tmpobj != NULL) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 0% (fallthrough)
branch  7 taken 100%
        -: 1172:	    ((tmpobj->type != XPATH_STRING) || (tmpobj->stringval == NULL) ||
        -: 1173:	     (tmpobj->stringval[0] == 0))) {
    #####: 1174:	    xmlXPathFreeObject(tmpobj);
call    0 never executed
    #####: 1175:	    virXMLError(VIR_ERR_OS_TYPE, nam, 0);
call    0 never executed
    #####: 1176:	    goto error;
        -: 1177:	}
        -: 1178:
        3: 1179:	if ((tmpobj == NULL) || !xmlStrEqual(tmpobj->stringval, BAD_CAST "hvm")) {
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
branch  3 taken 50% (fallthrough)
branch  4 taken 50%
        1: 1180:	    res = virDomainParseXMLOSDescPV(obj->nodesetval->nodeTab[0], &buf);
call    0 returned 100%
        -: 1181:	} else {
        1: 1182:	    hvm = 1;
        1: 1183:	    res = virDomainParseXMLOSDescHVM(obj->nodesetval->nodeTab[0], &buf, ctxt);
call    0 returned 100%
        -: 1184:	}
        -: 1185:
        2: 1186:	xmlXPathFreeObject(tmpobj);
call    0 returned 100%
        -: 1187:
        2: 1188:	if (res != 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 1189:	    goto error;
    #####: 1190:    } else if (bootloader == 0) {
branch  0 never executed
branch  1 never executed
    #####: 1191:	virXMLError(VIR_ERR_NO_OS, nam, 0);
call    0 never executed
    #####: 1192:	goto error;
        -: 1193:    }
        2: 1194:    xmlXPathFreeObject(obj);
call    0 returned 100%
        -: 1195:
        -: 1196:    /* analyze of the devices */
        2: 1197:    obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt);
call    0 returned 100%
        2: 1198:    if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 100% (fallthrough)
branch  7 taken 0%
        -: 1199:        (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
        5: 1200:	for (i = 0; i < obj->nodesetval->nodeNr; i++) {
branch  0 taken 60%
branch  1 taken 40% (fallthrough)
        3: 1201:            res = virDomainParseXMLDiskDesc(obj->nodesetval->nodeTab[i], &buf, hvm);
call    0 returned 100%
        3: 1202:	    if (res != 0) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 1203:		goto error;
        -: 1204:	    }
        -: 1205:	}
        -: 1206:    }
        2: 1207:    xmlXPathFreeObject(obj);
call    0 returned 100%
        -: 1208:
        2: 1209:    obj = xmlXPathEval(BAD_CAST "/domain/devices/interface", ctxt);
call    0 returned 100%
        2: 1210:    if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 100% (fallthrough)
branch  7 taken 0%
        -: 1211:        (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
        3: 1212:        for (i = 0; i < obj->nodesetval->nodeNr; i++) {
branch  0 taken 33%
branch  1 taken 67% (fallthrough)
        1: 1213:            virBufferAdd(&buf, "(device ", 8);
call    0 returned 100%
        1: 1214:            res = virDomainParseXMLIfDesc(obj->nodesetval->nodeTab[i], &buf, hvm);
call    0 returned 100%
        1: 1215:            if (res != 0) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 1216:                goto error;
        -: 1217:            }
        1: 1218:            virBufferAdd(&buf, ")", 1);
call    0 returned 100%
        -: 1219:        }
        -: 1220:    }
        2: 1221:    xmlXPathFreeObject(obj);
call    0 returned 100%
        -: 1222:
        -: 1223:
        2: 1224:    virBufferAdd(&buf, ")", 1); /* closes (vm */
call    0 returned 100%
        2: 1225:    buf.content[buf.use] = 0;
        -: 1226:
        2: 1227:    xmlXPathFreeContext(ctxt);
call    0 returned 100%
        2: 1228:    xmlFreeDoc(xml);
call    0 returned 100%
        -: 1229:
        2: 1230:    if (name != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        2: 1231:        *name = nam;
        -: 1232:
        2: 1233:    return (ret);
        -: 1234:
    #####: 1235:  error:
    #####: 1236:    if (nam != NULL)
branch  0 never executed
branch  1 never executed
    #####: 1237:        free(nam);
call    0 never executed
    #####: 1238:    if (name != NULL)
branch  0 never executed
branch  1 never executed
    #####: 1239:        *name = NULL;
    #####: 1240:    if (obj != NULL)
branch  0 never executed
branch  1 never executed
    #####: 1241:        xmlXPathFreeObject(obj);
call    0 never executed
    #####: 1242:    if (ctxt != NULL)
branch  0 never executed
branch  1 never executed
    #####: 1243:        xmlXPathFreeContext(ctxt);
call    0 never executed
    #####: 1244:    if (xml != NULL)
branch  0 never executed
branch  1 never executed
    #####: 1245:        xmlFreeDoc(xml);
call    0 never executed
    #####: 1246:    if (ret != NULL)
branch  0 never executed
branch  1 never executed
    #####: 1247:        free(ret);
call    0 never executed
    #####: 1248:    return (NULL);
        -: 1249:}
        -: 1250:
        -: 1251:#endif /* !PROXY */
        -: 1252:
        -: 1253:
        -: 1254:
function virParseUUID called 0 returned 0% blocks executed 0%
    #####: 1255:unsigned char *virParseUUID(char **ptr, const char *uuid) {
        -: 1256:    int rawuuid[16];
        -: 1257:    const char *cur;
    #####: 1258:    unsigned char *dst_uuid = NULL;
        -: 1259:    int i;
        -: 1260:
    #####: 1261:    if (uuid == NULL)
branch  0 never executed
branch  1 never executed
    #####: 1262:        goto error;
        -: 1263:
        -: 1264:    /*
        -: 1265:     * do a liberal scan allowing '-' and ' ' anywhere between character
        -: 1266:     * pairs as long as there is 32 of them in the end.
        -: 1267:     */
    #####: 1268:    cur = uuid;
    #####: 1269:    for (i = 0;i < 16;) {
branch  0 never executed
branch  1 never executed
    #####: 1270:        rawuuid[i] = 0;
    #####: 1271:        if (*cur == 0)
branch  0 never executed
branch  1 never executed
    #####: 1272:	    goto error;
    #####: 1273:	if ((*cur == '-') || (*cur == ' ')) {
branch  0 never executed
branch  1 never executed
    #####: 1274:	    cur++;
    #####: 1275:	    continue;
        -: 1276:	}
    #####: 1277:	if ((*cur >= '0') && (*cur <= '9'))
branch  0 never executed
branch  1 never executed
    #####: 1278:	    rawuuid[i] = *cur - '0';
    #####: 1279:	else if ((*cur >= 'a') && (*cur <= 'f'))
branch  0 never executed
branch  1 never executed
    #####: 1280:	    rawuuid[i] = *cur - 'a' + 10;
    #####: 1281:	else if ((*cur >= 'A') && (*cur <= 'F'))
branch  0 never executed
branch  1 never executed
    #####: 1282:	    rawuuid[i] = *cur - 'A' + 10;
        -: 1283:	else
    #####: 1284:	    goto error;
    #####: 1285:	rawuuid[i] *= 16;
    #####: 1286:	cur++;
    #####: 1287:        if (*cur == 0)
branch  0 never executed
branch  1 never executed
    #####: 1288:	    goto error;
    #####: 1289:	if ((*cur >= '0') && (*cur <= '9'))
branch  0 never executed
branch  1 never executed
    #####: 1290:	    rawuuid[i] += *cur - '0';
    #####: 1291:	else if ((*cur >= 'a') && (*cur <= 'f'))
branch  0 never executed
branch  1 never executed
    #####: 1292:	    rawuuid[i] += *cur - 'a' + 10;
    #####: 1293:	else if ((*cur >= 'A') && (*cur <= 'F'))
branch  0 never executed
branch  1 never executed
    #####: 1294:	    rawuuid[i] += *cur - 'A' + 10;
        -: 1295:	else
    #####: 1296:	    goto error;
    #####: 1297:        i++;
    #####: 1298:	cur++;
        -: 1299:    }
        -: 1300:
    #####: 1301:    dst_uuid = (unsigned char *) *ptr;
    #####: 1302:    *ptr += 16;
        -: 1303:
    #####: 1304:    for (i = 0; i < 16; i++)
branch  0 never executed
branch  1 never executed
    #####: 1305:        dst_uuid[i] = rawuuid[i] & 0xFF;
        -: 1306:
    #####: 1307:error:
    #####: 1308:    return(dst_uuid);
        -: 1309:}