The bufferNNN functions in the qemud/buf.c file are identical those already present in the src/xml.c file, except the latter are named virBufferNNN. This patch renames bufferNNN to virBufferNNN so that the two impls can be merged into one. No functional change buf.c | 42 +++++------ buf.h | 30 ++++---- conf.c | 228 +++++++++++++++++++++++++++++++-------------------------------- driver.c | 34 ++++----- 4 files changed, 167 insertions(+), 167 deletions(-) Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
diff -r b8a4e065009d qemud/buf.c --- a/qemud/buf.c Sun Jun 17 22:11:26 2007 -0400 +++ b/qemud/buf.c Sun Jun 17 22:11:32 2007 -0400 @@ -1,7 +1,7 @@ /* - * buf.c: buffers for qemud - * - * Copyright (C) 2005 Red Hat, Inc. + * buf.c: buffers for libvirt + * + * Copyright (C) 2005-2007 Red Hat, Inc. * * See COPYING.LIB for the License of this software * @@ -17,7 +17,7 @@ #include "buf.h" /** - * bufferGrow: + * virBufferGrow: * @buf: the buffer * @len: the minimum free size to allocate on top of existing used space * @@ -26,7 +26,7 @@ * Returns the new available space or -1 in case of error */ static int -bufferGrow(bufferPtr buf, unsigned int len) +virBufferGrow(virBufferPtr buf, unsigned int len) { int size; char *newbuf; @@ -46,7 +46,7 @@ bufferGrow(bufferPtr buf, unsigned int l } /** - * bufferAdd: + * virBufferAdd: * @buf: the buffer to dump * @str: the string * @len: the number of bytes to add @@ -57,7 +57,7 @@ bufferGrow(bufferPtr buf, unsigned int l * Returns 0 successful, -1 in case of internal or API error. */ int -bufferAdd(bufferPtr buf, const char *str, int len) +virBufferAdd(virBufferPtr buf, const char *str, int len) { unsigned int needSize; @@ -72,7 +72,7 @@ bufferAdd(bufferPtr buf, const char *str needSize = buf->use + len + 2; if (needSize > buf->size) { - if (!bufferGrow(buf, needSize - buf->use)) { + if (!virBufferGrow(buf, needSize - buf->use)) { return (-1); } } @@ -83,10 +83,10 @@ bufferAdd(bufferPtr buf, const char *str return (0); } -bufferPtr -bufferNew(unsigned int size) -{ - bufferPtr buf; +virBufferPtr +virBufferNew(unsigned int size) +{ + virBufferPtr buf; if (!(buf = malloc(sizeof(*buf)))) return NULL; if (size && (buf->content = malloc(size))==NULL) { @@ -100,7 +100,7 @@ bufferNew(unsigned int size) } void -bufferFree(bufferPtr buf) +virBufferFree(virBufferPtr buf) { if (buf) { if (buf->content) @@ -110,13 +110,13 @@ bufferFree(bufferPtr buf) } /** - * bufferContentAndFree: + * virBufferContentAndFree: * @buf: Buffer * * Return the content from the buffer and free (only) the buffer structure. */ char * -bufferContentAndFree (bufferPtr buf) +virBufferContentAndFree (virBufferPtr buf) { char *content = buf->content; @@ -125,7 +125,7 @@ bufferContentAndFree (bufferPtr buf) } /** - * bufferVSprintf: + * virBufferVSprintf: * @buf: the buffer to dump * @format: the format * @argptr: the variable list of arguments @@ -135,7 +135,7 @@ bufferContentAndFree (bufferPtr buf) * Returns 0 successful, -1 in case of internal or API error. */ int -bufferVSprintf(bufferPtr buf, const char *format, ...) +virBufferVSprintf(virBufferPtr buf, const char *format, ...) { int size, count; va_list locarg, argptr; @@ -150,7 +150,7 @@ bufferVSprintf(bufferPtr buf, const char locarg)) < 0) || (count >= size - 1)) { buf->content[buf->use] = 0; va_end(locarg); - if (bufferGrow(buf, 1000) < 0) { + if (virBufferGrow(buf, 1000) < 0) { return (-1); } size = buf->size - buf->use - 1; @@ -163,7 +163,7 @@ bufferVSprintf(bufferPtr buf, const char } /** - * bufferStrcat: + * virBufferStrcat: * @buf: the buffer to dump * @argptr: the variable list of strings, the last argument must be NULL * @@ -172,7 +172,7 @@ bufferVSprintf(bufferPtr buf, const char * Returns 0 successful, -1 in case of internal or API error. */ int -bufferStrcat(bufferPtr buf, ...) +virBufferStrcat(virBufferPtr buf, ...) { va_list ap; char *str; @@ -184,7 +184,7 @@ bufferStrcat(bufferPtr buf, ...) unsigned int needSize = buf->use + len + 2; if (needSize > buf->size) { - if (!bufferGrow(buf, needSize - buf->use)) + if (!virBufferGrow(buf, needSize - buf->use)) return -1; } memcpy(&buf->content[buf->use], str, len); diff -r b8a4e065009d qemud/buf.h --- a/qemud/buf.h Sun Jun 17 22:11:26 2007 -0400 +++ b/qemud/buf.h Sun Jun 17 22:11:32 2007 -0400 @@ -1,37 +1,37 @@ /* - * buf.h: buffers for qemud + * buf.h: buffers for libvirt * - * Copyright (C) 2005 Red Hat, Inc. + * Copyright (C) 2005-2007 Red Hat, Inc. * * See COPYING.LIB for the License of this software * * Daniel Veillard <veillard@xxxxxxxxxx> */ -#ifndef __QEMUD_BUF_H__ -#define __QEMUD_BUF_H__ +#ifndef __VIR_BUFFER_H__ +#define __VIR_BUFFER_H__ #include "internal.h" /** - * buffer: + * virBuffer: * * A buffer structure. */ -typedef struct _buffer buffer; -typedef buffer *bufferPtr; -struct _buffer { +typedef struct _virBuffer virBuffer; +typedef virBuffer *virBufferPtr; +struct _virBuffer { char *content; /* The buffer content UTF8 */ unsigned int use; /* The buffer size used */ unsigned int size; /* The buffer size */ }; -bufferPtr bufferNew(unsigned int size); -void bufferFree(bufferPtr buf); -char *bufferContentAndFree(bufferPtr buf); -int bufferAdd(bufferPtr buf, const char *str, int len); -int bufferVSprintf(bufferPtr buf, const char *format, ...) +virBufferPtr virBufferNew(unsigned int size); +void virBufferFree(virBufferPtr buf); +char *virBufferContentAndFree(virBufferPtr buf); +int virBufferAdd(virBufferPtr buf, const char *str, int len); +int virBufferVSprintf(virBufferPtr buf, const char *format, ...) ATTRIBUTE_FORMAT(printf, 2, 3); -int bufferStrcat(bufferPtr buf, ...); +int virBufferStrcat(virBufferPtr buf, ...); -#endif /* __QEMUD_BUF_H__ */ +#endif /* __VIR_BUFFER_H__ */ diff -r b8a4e065009d qemud/conf.c --- a/qemud/conf.c Sun Jun 17 22:11:26 2007 -0400 +++ b/qemud/conf.c Sun Jun 17 22:11:32 2007 -0400 @@ -2453,14 +2453,14 @@ char *qemudGenerateXML(struct qemud_driv struct qemud_vm *vm, struct qemud_vm_def *def, int live) { - bufferPtr buf = 0; + virBufferPtr buf = 0; unsigned char *uuid; struct qemud_vm_disk_def *disk; struct qemud_vm_net_def *net; const char *type = NULL; int n; - buf = bufferNew (QEMUD_MAX_XML_LEN); + buf = virBufferNew (QEMUD_MAX_XML_LEN); if (!buf) goto no_memory; @@ -2481,50 +2481,50 @@ char *qemudGenerateXML(struct qemud_driv } if (qemudIsActiveVM(vm) && live) { - if (bufferVSprintf(buf, "<domain type='%s' id='%d'>\n", type, vm->id) < 0) + if (virBufferVSprintf(buf, "<domain type='%s' id='%d'>\n", type, vm->id) < 0) goto no_memory; } else { - if (bufferVSprintf(buf, "<domain type='%s'>\n", type) < 0) - goto no_memory; - } - - if (bufferVSprintf(buf, " <name>%s</name>\n", def->name) < 0) + if (virBufferVSprintf(buf, "<domain type='%s'>\n", type) < 0) + goto no_memory; + } + + if (virBufferVSprintf(buf, " <name>%s</name>\n", def->name) < 0) goto no_memory; uuid = def->uuid; - if (bufferVSprintf(buf, " <uuid>%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x</uuid>\n", + if (virBufferVSprintf(buf, " <uuid>%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x</uuid>\n", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]) < 0) goto no_memory; - if (bufferVSprintf(buf, " <memory>%d</memory>\n", def->maxmem) < 0) - goto no_memory; - if (bufferVSprintf(buf, " <currentMemory>%d</currentMemory>\n", def->memory) < 0) - goto no_memory; - if (bufferVSprintf(buf, " <vcpu>%d</vcpu>\n", def->vcpus) < 0) - goto no_memory; - - if (bufferAdd(buf, " <os>\n", -1) < 0) + if (virBufferVSprintf(buf, " <memory>%d</memory>\n", def->maxmem) < 0) + goto no_memory; + if (virBufferVSprintf(buf, " <currentMemory>%d</currentMemory>\n", def->memory) < 0) + goto no_memory; + if (virBufferVSprintf(buf, " <vcpu>%d</vcpu>\n", def->vcpus) < 0) + goto no_memory; + + if (virBufferAdd(buf, " <os>\n", -1) < 0) goto no_memory; if (def->virtType == QEMUD_VIRT_QEMU) { - if (bufferVSprintf(buf, " <type arch='%s' machine='%s'>%s</type>\n", + if (virBufferVSprintf(buf, " <type arch='%s' machine='%s'>%s</type>\n", def->os.arch, def->os.machine, def->os.type) < 0) goto no_memory; } else { - if (bufferVSprintf(buf, " <type>%s</type>\n", def->os.type) < 0) + if (virBufferVSprintf(buf, " <type>%s</type>\n", def->os.type) < 0) goto no_memory; } if (def->os.kernel[0]) - if (bufferVSprintf(buf, " <kernel>%s</kernel>\n", def->os.kernel) < 0) + if (virBufferVSprintf(buf, " <kernel>%s</kernel>\n", def->os.kernel) < 0) goto no_memory; if (def->os.initrd[0]) - if (bufferVSprintf(buf, " <initrd>%s</initrd>\n", def->os.initrd) < 0) + if (virBufferVSprintf(buf, " <initrd>%s</initrd>\n", def->os.initrd) < 0) goto no_memory; if (def->os.cmdline[0]) - if (bufferVSprintf(buf, " <cmdline>%s</cmdline>\n", def->os.cmdline) < 0) + if (virBufferVSprintf(buf, " <cmdline>%s</cmdline>\n", def->os.cmdline) < 0) goto no_memory; for (n = 0 ; n < def->os.nBootDevs ; n++) { @@ -2543,38 +2543,38 @@ char *qemudGenerateXML(struct qemud_driv boottype = "net"; break; } - if (bufferVSprintf(buf, " <boot dev='%s'/>\n", boottype) < 0) - goto no_memory; - } - - if (bufferAdd(buf, " </os>\n", -1) < 0) + if (virBufferVSprintf(buf, " <boot dev='%s'/>\n", boottype) < 0) + goto no_memory; + } + + if (virBufferAdd(buf, " </os>\n", -1) < 0) goto no_memory; if (def->features & QEMUD_FEATURE_ACPI) { - if (bufferAdd(buf, " <features>\n", -1) < 0) - goto no_memory; - if (bufferAdd(buf, " <acpi/>\n", -1) < 0) - goto no_memory; - if (bufferAdd(buf, " </features>\n", -1) < 0) - goto no_memory; - } - - if (bufferAdd(buf, " <on_poweroff>destroy</on_poweroff>\n", -1) < 0) + if (virBufferAdd(buf, " <features>\n", -1) < 0) + goto no_memory; + if (virBufferAdd(buf, " <acpi/>\n", -1) < 0) + goto no_memory; + if (virBufferAdd(buf, " </features>\n", -1) < 0) + goto no_memory; + } + + if (virBufferAdd(buf, " <on_poweroff>destroy</on_poweroff>\n", -1) < 0) goto no_memory; if (def->noReboot) { - if (bufferAdd(buf, " <on_reboot>destroy</on_reboot>\n", -1) < 0) + if (virBufferAdd(buf, " <on_reboot>destroy</on_reboot>\n", -1) < 0) goto no_memory; } else { - if (bufferAdd(buf, " <on_reboot>restart</on_reboot>\n", -1) < 0) - goto no_memory; - } - if (bufferAdd(buf, " <on_crash>destroy</on_crash>\n", -1) < 0) - goto no_memory; - - if (bufferAdd(buf, " <devices>\n", -1) < 0) - goto no_memory; - - if (bufferVSprintf(buf, " <emulator>%s</emulator>\n", def->os.binary) < 0) + if (virBufferAdd(buf, " <on_reboot>restart</on_reboot>\n", -1) < 0) + goto no_memory; + } + if (virBufferAdd(buf, " <on_crash>destroy</on_crash>\n", -1) < 0) + goto no_memory; + + if (virBufferAdd(buf, " <devices>\n", -1) < 0) + goto no_memory; + + if (virBufferVSprintf(buf, " <emulator>%s</emulator>\n", def->os.binary) < 0) goto no_memory; disk = def->disks; @@ -2592,21 +2592,21 @@ char *qemudGenerateXML(struct qemud_driv "cdrom", "floppy", }; - if (bufferVSprintf(buf, " <disk type='%s' device='%s'>\n", + if (virBufferVSprintf(buf, " <disk type='%s' device='%s'>\n", types[disk->type], devices[disk->device]) < 0) goto no_memory; - if (bufferVSprintf(buf, " <source %s='%s'/>\n", typeAttrs[disk->type], disk->src) < 0) - goto no_memory; - - if (bufferVSprintf(buf, " <target dev='%s'/>\n", disk->dst) < 0) + if (virBufferVSprintf(buf, " <source %s='%s'/>\n", typeAttrs[disk->type], disk->src) < 0) + goto no_memory; + + if (virBufferVSprintf(buf, " <target dev='%s'/>\n", disk->dst) < 0) goto no_memory; if (disk->readonly) - if (bufferAdd(buf, " <readonly/>\n", -1) < 0) + if (virBufferAdd(buf, " <readonly/>\n", -1) < 0) goto no_memory; - if (bufferVSprintf(buf, " </disk>\n") < 0) + if (virBufferVSprintf(buf, " </disk>\n") < 0) goto no_memory; disk = disk->next; @@ -2623,42 +2623,42 @@ char *qemudGenerateXML(struct qemud_driv "network", "bridge", }; - if (bufferVSprintf(buf, " <interface type='%s'>\n", + if (virBufferVSprintf(buf, " <interface type='%s'>\n", types[net->type]) < 0) goto no_memory; - if (bufferVSprintf(buf, " <mac address='%02x:%02x:%02x:%02x:%02x:%02x'/>\n", + if (virBufferVSprintf(buf, " <mac address='%02x:%02x:%02x:%02x:%02x:%02x'/>\n", net->mac[0], net->mac[1], net->mac[2], net->mac[3], net->mac[4], net->mac[5]) < 0) goto no_memory; switch (net->type) { case QEMUD_NET_NETWORK: - if (bufferVSprintf(buf, " <source network='%s'/>\n", net->dst.network.name) < 0) + if (virBufferVSprintf(buf, " <source network='%s'/>\n", net->dst.network.name) < 0) goto no_memory; if (net->dst.network.ifname[0] != '\0') { - if (bufferVSprintf(buf, " <target dev='%s'/>\n", net->dst.network.ifname) < 0) + if (virBufferVSprintf(buf, " <target dev='%s'/>\n", net->dst.network.ifname) < 0) goto no_memory; } break; case QEMUD_NET_ETHERNET: if (net->dst.ethernet.ifname[0] != '\0') { - if (bufferVSprintf(buf, " <target dev='%s'/>\n", net->dst.ethernet.ifname) < 0) + if (virBufferVSprintf(buf, " <target dev='%s'/>\n", net->dst.ethernet.ifname) < 0) goto no_memory; } if (net->dst.ethernet.script[0] != '\0') { - if (bufferVSprintf(buf, " <script path='%s'/>\n", net->dst.ethernet.script) < 0) + if (virBufferVSprintf(buf, " <script path='%s'/>\n", net->dst.ethernet.script) < 0) goto no_memory; } break; case QEMUD_NET_BRIDGE: - if (bufferVSprintf(buf, " <source bridge='%s'/>\n", net->dst.bridge.brname) < 0) + if (virBufferVSprintf(buf, " <source bridge='%s'/>\n", net->dst.bridge.brname) < 0) goto no_memory; if (net->dst.bridge.ifname[0] != '\0') { - if (bufferVSprintf(buf, " <target dev='%s'/>\n", net->dst.bridge.ifname) < 0) + if (virBufferVSprintf(buf, " <target dev='%s'/>\n", net->dst.bridge.ifname) < 0) goto no_memory; } break; @@ -2667,17 +2667,17 @@ char *qemudGenerateXML(struct qemud_driv case QEMUD_NET_CLIENT: case QEMUD_NET_MCAST: if (net->dst.socket.address[0] != '\0') { - if (bufferVSprintf(buf, " <source address='%s' port='%d'/>\n", + if (virBufferVSprintf(buf, " <source address='%s' port='%d'/>\n", net->dst.socket.address, net->dst.socket.port) < 0) goto no_memory; } else { - if (bufferVSprintf(buf, " <source port='%d'/>\n", + if (virBufferVSprintf(buf, " <source port='%d'/>\n", net->dst.socket.port) < 0) goto no_memory; } } - if (bufferVSprintf(buf, " </interface>\n") < 0) + if (virBufferVSprintf(buf, " </interface>\n") < 0) goto no_memory; net = net->next; @@ -2685,20 +2685,20 @@ char *qemudGenerateXML(struct qemud_driv switch (def->graphicsType) { case QEMUD_GRAPHICS_VNC: - if (bufferAdd(buf, " <graphics type='vnc'", -1) < 0) + if (virBufferAdd(buf, " <graphics type='vnc'", -1) < 0) goto no_memory; if (def->vncPort && - bufferVSprintf(buf, " port='%d'", + virBufferVSprintf(buf, " port='%d'", qemudIsActiveVM(vm) && live ? def->vncActivePort : def->vncPort) < 0) goto no_memory; - if (bufferAdd(buf, "/>\n", -1) < 0) + if (virBufferAdd(buf, "/>\n", -1) < 0) goto no_memory; break; case QEMUD_GRAPHICS_SDL: - if (bufferAdd(buf, " <graphics type='sdl'/>\n", -1) < 0) + if (virBufferAdd(buf, " <graphics type='sdl'/>\n", -1) < 0) goto no_memory; break; @@ -2710,19 +2710,19 @@ char *qemudGenerateXML(struct qemud_driv if (def->graphicsType == QEMUD_GRAPHICS_VNC) { } - if (bufferAdd(buf, " </devices>\n", -1) < 0) - goto no_memory; - - - if (bufferAdd(buf, "</domain>\n", -1) < 0) - goto no_memory; - - return bufferContentAndFree (buf); + if (virBufferAdd(buf, " </devices>\n", -1) < 0) + goto no_memory; + + + if (virBufferAdd(buf, "</domain>\n", -1) < 0) + goto no_memory; + + return virBufferContentAndFree (buf); no_memory: qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml"); cleanup: - if (buf) bufferFree (buf); + if (buf) virBufferFree (buf); return NULL; } @@ -2730,21 +2730,21 @@ char *qemudGenerateNetworkXML(struct qem char *qemudGenerateNetworkXML(struct qemud_driver *driver, struct qemud_network *network, struct qemud_network_def *def) { - bufferPtr buf = 0; + virBufferPtr buf = 0; unsigned char *uuid; - buf = bufferNew (QEMUD_MAX_XML_LEN); + buf = virBufferNew (QEMUD_MAX_XML_LEN); if (!buf) goto no_memory; - if (bufferVSprintf(buf, "<network>\n") < 0) - goto no_memory; - - if (bufferVSprintf(buf, " <name>%s</name>\n", def->name) < 0) + if (virBufferVSprintf(buf, "<network>\n") < 0) + goto no_memory; + + if (virBufferVSprintf(buf, " <name>%s</name>\n", def->name) < 0) goto no_memory; uuid = def->uuid; - if (bufferVSprintf(buf, " <uuid>%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x</uuid>\n", + if (virBufferVSprintf(buf, " <uuid>%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x</uuid>\n", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], @@ -2753,67 +2753,67 @@ char *qemudGenerateNetworkXML(struct qem if (def->forward) { if (def->forwardDev[0]) { - bufferVSprintf(buf, " <forward dev='%s'/>\n", + virBufferVSprintf(buf, " <forward dev='%s'/>\n", def->forwardDev); } else { - bufferAdd(buf, " <forward/>\n", -1); - } - } - - bufferAdd(buf, " <bridge", -1); + virBufferAdd(buf, " <forward/>\n", -1); + } + } + + virBufferAdd(buf, " <bridge", -1); if (qemudIsActiveNetwork(network)) { - if (bufferVSprintf(buf, " name='%s'", network->bridge) < 0) + if (virBufferVSprintf(buf, " name='%s'", network->bridge) < 0) goto no_memory; } else if (def->bridge[0]) { - if (bufferVSprintf(buf, " name='%s'", def->bridge) < 0) - goto no_memory; - } - if (bufferVSprintf(buf, " stp='%s' forwardDelay='%d' />\n", + if (virBufferVSprintf(buf, " name='%s'", def->bridge) < 0) + goto no_memory; + } + if (virBufferVSprintf(buf, " stp='%s' forwardDelay='%d' />\n", def->disableSTP ? "off" : "on", def->forwardDelay) < 0) goto no_memory; if (def->ipAddress[0] || def->netmask[0]) { - if (bufferAdd(buf, " <ip", -1) < 0) + if (virBufferAdd(buf, " <ip", -1) < 0) goto no_memory; if (def->ipAddress[0] && - bufferVSprintf(buf, " address='%s'", def->ipAddress) < 0) + virBufferVSprintf(buf, " address='%s'", def->ipAddress) < 0) goto no_memory; if (def->netmask[0] && - bufferVSprintf(buf, " netmask='%s'", def->netmask) < 0) - goto no_memory; - - if (bufferAdd(buf, ">\n", -1) < 0) + virBufferVSprintf(buf, " netmask='%s'", def->netmask) < 0) + goto no_memory; + + if (virBufferAdd(buf, ">\n", -1) < 0) goto no_memory; if (def->ranges) { struct qemud_dhcp_range_def *range = def->ranges; - if (bufferAdd(buf, " <dhcp>\n", -1) < 0) + if (virBufferAdd(buf, " <dhcp>\n", -1) < 0) goto no_memory; while (range) { - if (bufferVSprintf(buf, " <range start='%s' end='%s' />\n", + if (virBufferVSprintf(buf, " <range start='%s' end='%s' />\n", range->start, range->end) < 0) goto no_memory; range = range->next; } - if (bufferAdd(buf, " </dhcp>\n", -1) < 0) + if (virBufferAdd(buf, " </dhcp>\n", -1) < 0) goto no_memory; } - if (bufferAdd(buf, " </ip>\n", -1) < 0) - goto no_memory; - } - - if (bufferAdd(buf, "</network>\n", -1) < 0) - goto no_memory; - - return bufferContentAndFree (buf); + if (virBufferAdd(buf, " </ip>\n", -1) < 0) + goto no_memory; + } + + if (virBufferAdd(buf, "</network>\n", -1) < 0) + goto no_memory; + + return virBufferContentAndFree (buf); no_memory: qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml"); - if (buf) bufferFree (buf); + if (buf) virBufferFree (buf); return NULL; } diff -r b8a4e065009d qemud/driver.c --- a/qemud/driver.c Sun Jun 17 22:11:26 2007 -0400 +++ b/qemud/driver.c Sun Jun 17 22:11:32 2007 -0400 @@ -1391,7 +1391,7 @@ char *qemudGetCapabilities(struct qemud_ int i, j, r; int have_kqemu = 0; int have_kvm = 0; - bufferPtr xml; + virBufferPtr xml; /* Really, this never fails - look at the man-page. */ uname (&utsname); @@ -1400,13 +1400,13 @@ char *qemudGetCapabilities(struct qemud_ have_kvm = access ("/dev/kvm", F_OK) == 0; /* Construct the XML. */ - xml = bufferNew (1024); + xml = virBufferNew (1024); if (!xml) { qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); return NULL; } - r = bufferVSprintf (xml, + r = virBufferVSprintf (xml, "\ <capabilities>\n\ <host>\n\ @@ -1417,7 +1417,7 @@ char *qemudGetCapabilities(struct qemud_ utsname.machine); if (r == -1) { vir_buffer_failed: - bufferFree (xml); + virBufferFree (xml); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); return NULL; } @@ -1427,7 +1427,7 @@ char *qemudGetCapabilities(struct qemud_ else if (strcmp (utsname.machine, "x86_64") == 0) i = 1; if (i >= 0) { /* For the default (PC-like) guest, qemudArchs[0] or [1]. */ - r = bufferVSprintf (xml, + r = virBufferVSprintf (xml, "\ \n\ <guest>\n\ @@ -1442,7 +1442,7 @@ char *qemudGetCapabilities(struct qemud_ if (r == -1) goto vir_buffer_failed; for (j = 0; qemudArchs[i].machines[j]; ++j) { - r = bufferVSprintf (xml, + r = virBufferVSprintf (xml, "\ <machine>%s</machine>\n", qemudArchs[i].machines[j]); @@ -1450,20 +1450,20 @@ char *qemudGetCapabilities(struct qemud_ } if (have_kqemu) { - r = bufferAdd (xml, + r = virBufferAdd (xml, "\ <domain type=\"kqemu\"/>\n", -1); if (r == -1) goto vir_buffer_failed; } if (have_kvm) { - r = bufferAdd (xml, + r = virBufferAdd (xml, "\ <domain type=\"kvm\">\n\ <emulator>/usr/bin/qemu-kvm</emulator>\n\ </domain>\n", -1); if (r == -1) goto vir_buffer_failed; } - r = bufferAdd (xml, + r = virBufferAdd (xml, "\ </arch>\n\ </guest>\n", -1); @@ -1471,7 +1471,7 @@ char *qemudGetCapabilities(struct qemud_ /* The "other" PC architecture needs emulation. */ i = i ^ 1; - r = bufferVSprintf (xml, + r = virBufferVSprintf (xml, "\ \n\ <guest>\n\ @@ -1485,13 +1485,13 @@ char *qemudGetCapabilities(struct qemud_ qemudArchs[i].binary); if (r == -1) goto vir_buffer_failed; for (j = 0; qemudArchs[i].machines[j]; ++j) { - r = bufferVSprintf (xml, + r = virBufferVSprintf (xml, "\ <machine>%s</machine>\n", qemudArchs[i].machines[j]); if (r == -1) goto vir_buffer_failed; } - r = bufferAdd (xml, + r = virBufferAdd (xml, "\ </arch>\n\ </guest>\n", -1); @@ -1500,7 +1500,7 @@ char *qemudGetCapabilities(struct qemud_ /* The non-PC architectures, qemudArchs[>=2]. */ for (i = 2; qemudArchs[i].arch; ++i) { - r = bufferVSprintf (xml, + r = virBufferVSprintf (xml, "\ \n\ <guest>\n\ @@ -1514,13 +1514,13 @@ char *qemudGetCapabilities(struct qemud_ qemudArchs[i].binary); if (r == -1) goto vir_buffer_failed; for (j = 0; qemudArchs[i].machines[j]; ++j) { - r = bufferVSprintf (xml, + r = virBufferVSprintf (xml, "\ <machine>%s</machine>\n", qemudArchs[i].machines[j]); if (r == -1) goto vir_buffer_failed; } - r = bufferAdd (xml, + r = virBufferAdd (xml, "\ </arch>\n\ </guest>\n", -1); @@ -1528,12 +1528,12 @@ char *qemudGetCapabilities(struct qemud_ } /* Finish off. */ - r = bufferAdd (xml, + r = virBufferAdd (xml, "\ </capabilities>\n", -1); if (r == -1) goto vir_buffer_failed; - return bufferContentAndFree(xml); + return virBufferContentAndFree(xml); }