+Tue Jun 26 18:30:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
+
+ * qemud/buf.c, qemud/buf.h: Remove obsolete files
+ * src/xml.c: remove virBuffer functions
+ * src/buf.c, src/buf.c, src/Makefile.am: Re-add virBuffer functions
+ * proxy/Makefile.am, qemud/Makefile.am, qemud/conf.c,
+ qemud/driver.c, src/conf.c, src/test.c, src/xen_internal.c,
+ src/xend_internal.c, src/xm_internal.c, src/xmlrpc.h,
+ tests/xmlrpc.test: Adapt to deal with new location of headers
+ for virBuffer functions.
+
Tue Jun 26 18:21:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* qemud/conf.c, qemud/driver.c, qemud/buf.c, qemud/buf.h:
#include "hash.h"
#include "sexpr.h"
#include "xml.h"
+#include "buf.h"
#include "xs_internal.h" /* for xenStoreDomainGetNetworkID */
/**
}
#endif /* !PROXY */
-/**
- * virBufferGrow:
- * @buf: the buffer
- * @len: the minimum free size to allocate on top of existing used space
- *
- * Grow the available space of an XML buffer to at least @len bytes.
- *
- * Returns the new available space or -1 in case of error
- */
-static int
-virBufferGrow(virBufferPtr buf, unsigned int len)
-{
- int size;
- char *newbuf;
-
- if (buf == NULL)
- return (-1);
- if (len + buf->use < buf->size)
- return (0);
-
- size = buf->use + len + 1000;
-
- newbuf = (char *) realloc(buf->content, size);
- if (newbuf == NULL) {
- virXMLError(NULL, VIR_ERR_NO_MEMORY, _("growing buffer"), size);
- return (-1);
- }
- buf->content = newbuf;
- buf->size = size;
- return (buf->size - buf->use);
-}
-
-/**
- * virBufferAdd:
- * @buf: the buffer to dump
- * @str: the string
- * @len: the number of bytes to add
- *
- * Add a string range to an XML buffer. if len == -1, the length of
- * str is recomputed to the full string.
- *
- * Returns 0 successful, -1 in case of internal or API error.
- */
-int
-virBufferAdd(virBufferPtr buf, const char *str, int len)
-{
- unsigned int needSize;
-
- if ((str == NULL) || (buf == NULL)) {
- return -1;
- }
- if (len == 0)
- return 0;
-
- if (len < 0)
- len = strlen(str);
-
- needSize = buf->use + len + 2;
- if (needSize > buf->size) {
- if (!virBufferGrow(buf, needSize - buf->use)) {
- return (-1);
- }
- }
- /* XXX: memmove() is 2x slower than memcpy(), do we really need it? */
- memmove(&buf->content[buf->use], str, len);
- buf->use += len;
- buf->content[buf->use] = 0;
- return (0);
-}
-
-virBufferPtr
-virBufferNew(unsigned int size)
-{
- virBufferPtr buf;
-
- if (!(buf = malloc(sizeof(*buf)))) {
- virXMLError(NULL, VIR_ERR_NO_MEMORY, _("allocate new buffer"), sizeof(*buf));
- return NULL;
- }
- if (size && (buf->content = malloc(size))==NULL) {
- virXMLError(NULL, VIR_ERR_NO_MEMORY, _("allocate buffer content"), size);
- free(buf);
- return NULL;
- }
- buf->size = size;
- buf->use = 0;
-
- return buf;
-}
-
-void
-virBufferFree(virBufferPtr buf)
-{
- if (buf) {
- if (buf->content)
- free(buf->content);
- free(buf);
- }
-}
-
-/**
- * virBufferVSprintf:
- * @buf: the buffer to dump
- * @format: the format
- * @argptr: the variable list of arguments
- *
- * Do a formatted print to an XML buffer.
- *
- * Returns 0 successful, -1 in case of internal or API error.
- */
-int
-virBufferVSprintf(virBufferPtr buf, const char *format, ...)
-{
- int size, count;
- va_list locarg, argptr;
-
- if ((format == NULL) || (buf == NULL)) {
- return (-1);
- }
- size = buf->size - buf->use - 1;
- va_start(argptr, format);
- va_copy(locarg, argptr);
- while (((count = vsnprintf(&buf->content[buf->use], size, format,
- locarg)) < 0) || (count >= size - 1)) {
- buf->content[buf->use] = 0;
- va_end(locarg);
- if (virBufferGrow(buf, 1000) < 0) {
- return (-1);
- }
- size = buf->size - buf->use - 1;
- va_copy(locarg, argptr);
- }
- va_end(locarg);
- buf->use += count;
- buf->content[buf->use] = 0;
- return (0);
-}
-
-/**
- * virBufferStrcat:
- * @buf: the buffer to dump
- * @argptr: the variable list of strings, the last argument must be NULL
- *
- * Concatenate strings to an XML buffer.
- *
- * Returns 0 successful, -1 in case of internal or API error.
- */
-int
-virBufferStrcat(virBufferPtr buf, ...)
-{
- va_list ap;
- char *str;
-
- va_start(ap, buf);
-
- while ((str = va_arg(ap, char *)) != NULL) {
- unsigned int len = strlen(str);
- unsigned int needSize = buf->use + len + 2;
-
- if (needSize > buf->size) {
- if (!virBufferGrow(buf, needSize - buf->use))
- return -1;
- }
- memcpy(&buf->content[buf->use], str, len);
- buf->use += len;
- buf->content[buf->use] = 0;
- }
- va_end(ap);
- return 0;
-}
-
#ifndef PROXY
/**
extern "C" {
#endif
-/**
- * virBuffer:
- *
- * A buffer structure.
- */
-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 */
-};
-
-virBufferPtr virBufferNew(unsigned int size);
-void virBufferFree(virBufferPtr buf);
-int virBufferAdd(virBufferPtr buf, const char *str, int len);
-int virBufferVSprintf(virBufferPtr buf, const char *format, ...)
- ATTRIBUTE_FORMAT(printf, 2, 3);
-int virBufferStrcat(virBufferPtr buf, ...);
-
int virXPathBoolean (const char *xpath,
xmlXPathContextPtr ctxt);
char * virXPathString (const char *xpath,