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 */ -#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, "\n", type, vm->id) < 0) + if (virBufferVSprintf(buf, "\n", type, vm->id) < 0) goto no_memory; } else { - if (bufferVSprintf(buf, "\n", type) < 0) - goto no_memory; - } - - if (bufferVSprintf(buf, " %s\n", def->name) < 0) + if (virBufferVSprintf(buf, "\n", type) < 0) + goto no_memory; + } + + if (virBufferVSprintf(buf, " %s\n", def->name) < 0) goto no_memory; uuid = def->uuid; - if (bufferVSprintf(buf, " %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n", + if (virBufferVSprintf(buf, " %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\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, " %d\n", def->maxmem) < 0) - goto no_memory; - if (bufferVSprintf(buf, " %d\n", def->memory) < 0) - goto no_memory; - if (bufferVSprintf(buf, " %d\n", def->vcpus) < 0) - goto no_memory; - - if (bufferAdd(buf, " \n", -1) < 0) + if (virBufferVSprintf(buf, " %d\n", def->maxmem) < 0) + goto no_memory; + if (virBufferVSprintf(buf, " %d\n", def->memory) < 0) + goto no_memory; + if (virBufferVSprintf(buf, " %d\n", def->vcpus) < 0) + goto no_memory; + + if (virBufferAdd(buf, " \n", -1) < 0) goto no_memory; if (def->virtType == QEMUD_VIRT_QEMU) { - if (bufferVSprintf(buf, " %s\n", + if (virBufferVSprintf(buf, " %s\n", def->os.arch, def->os.machine, def->os.type) < 0) goto no_memory; } else { - if (bufferVSprintf(buf, " %s\n", def->os.type) < 0) + if (virBufferVSprintf(buf, " %s\n", def->os.type) < 0) goto no_memory; } if (def->os.kernel[0]) - if (bufferVSprintf(buf, " %s\n", def->os.kernel) < 0) + if (virBufferVSprintf(buf, " %s\n", def->os.kernel) < 0) goto no_memory; if (def->os.initrd[0]) - if (bufferVSprintf(buf, " %s\n", def->os.initrd) < 0) + if (virBufferVSprintf(buf, " %s\n", def->os.initrd) < 0) goto no_memory; if (def->os.cmdline[0]) - if (bufferVSprintf(buf, " %s\n", def->os.cmdline) < 0) + if (virBufferVSprintf(buf, " %s\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, " \n", boottype) < 0) - goto no_memory; - } - - if (bufferAdd(buf, " \n", -1) < 0) + if (virBufferVSprintf(buf, " \n", boottype) < 0) + goto no_memory; + } + + if (virBufferAdd(buf, " \n", -1) < 0) goto no_memory; if (def->features & QEMUD_FEATURE_ACPI) { - if (bufferAdd(buf, " \n", -1) < 0) - goto no_memory; - if (bufferAdd(buf, " \n", -1) < 0) - goto no_memory; - if (bufferAdd(buf, " \n", -1) < 0) - goto no_memory; - } - - if (bufferAdd(buf, " destroy\n", -1) < 0) + if (virBufferAdd(buf, " \n", -1) < 0) + goto no_memory; + if (virBufferAdd(buf, " \n", -1) < 0) + goto no_memory; + if (virBufferAdd(buf, " \n", -1) < 0) + goto no_memory; + } + + if (virBufferAdd(buf, " destroy\n", -1) < 0) goto no_memory; if (def->noReboot) { - if (bufferAdd(buf, " destroy\n", -1) < 0) + if (virBufferAdd(buf, " destroy\n", -1) < 0) goto no_memory; } else { - if (bufferAdd(buf, " restart\n", -1) < 0) - goto no_memory; - } - if (bufferAdd(buf, " destroy\n", -1) < 0) - goto no_memory; - - if (bufferAdd(buf, " \n", -1) < 0) - goto no_memory; - - if (bufferVSprintf(buf, " %s\n", def->os.binary) < 0) + if (virBufferAdd(buf, " restart\n", -1) < 0) + goto no_memory; + } + if (virBufferAdd(buf, " destroy\n", -1) < 0) + goto no_memory; + + if (virBufferAdd(buf, " \n", -1) < 0) + goto no_memory; + + if (virBufferVSprintf(buf, " %s\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, " \n", + if (virBufferVSprintf(buf, " \n", types[disk->type], devices[disk->device]) < 0) goto no_memory; - if (bufferVSprintf(buf, " \n", typeAttrs[disk->type], disk->src) < 0) - goto no_memory; - - if (bufferVSprintf(buf, " \n", disk->dst) < 0) + if (virBufferVSprintf(buf, " \n", typeAttrs[disk->type], disk->src) < 0) + goto no_memory; + + if (virBufferVSprintf(buf, " \n", disk->dst) < 0) goto no_memory; if (disk->readonly) - if (bufferAdd(buf, " \n", -1) < 0) + if (virBufferAdd(buf, " \n", -1) < 0) goto no_memory; - if (bufferVSprintf(buf, " \n") < 0) + if (virBufferVSprintf(buf, " \n") < 0) goto no_memory; disk = disk->next; @@ -2623,42 +2623,42 @@ char *qemudGenerateXML(struct qemud_driv "network", "bridge", }; - if (bufferVSprintf(buf, " \n", + if (virBufferVSprintf(buf, " \n", types[net->type]) < 0) goto no_memory; - if (bufferVSprintf(buf, " \n", + if (virBufferVSprintf(buf, " \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, " \n", net->dst.network.name) < 0) + if (virBufferVSprintf(buf, " \n", net->dst.network.name) < 0) goto no_memory; if (net->dst.network.ifname[0] != '\0') { - if (bufferVSprintf(buf, " \n", net->dst.network.ifname) < 0) + if (virBufferVSprintf(buf, " \n", net->dst.network.ifname) < 0) goto no_memory; } break; case QEMUD_NET_ETHERNET: if (net->dst.ethernet.ifname[0] != '\0') { - if (bufferVSprintf(buf, " \n", net->dst.ethernet.ifname) < 0) + if (virBufferVSprintf(buf, " \n", net->dst.ethernet.ifname) < 0) goto no_memory; } if (net->dst.ethernet.script[0] != '\0') { - if (bufferVSprintf(buf, "