2007-03-15 17:30:04 +00:00
|
|
|
/*
|
2012-12-04 12:04:07 +00:00
|
|
|
* virbuffer.h: buffers for libvirt
|
2007-03-15 17:30:04 +00:00
|
|
|
*
|
2014-08-23 19:57:44 +00:00
|
|
|
* Copyright (C) 2005-2008, 2011-2014 Red Hat, Inc.
|
2007-03-15 17:30:04 +00:00
|
|
|
*
|
2012-07-27 09:39:53 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-27 09:39:53 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2007-03-15 17:30:04 +00:00
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2007-06-26 22:21:22 +00:00
|
|
|
#ifndef __VIR_BUFFER_H__
|
2010-03-09 18:22:22 +00:00
|
|
|
# define __VIR_BUFFER_H__
|
2007-03-15 17:30:04 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# include "internal.h"
|
2007-03-15 17:30:04 +00:00
|
|
|
|
2011-04-30 16:44:42 +00:00
|
|
|
# include <stdarg.h>
|
|
|
|
|
2007-03-15 17:30:04 +00:00
|
|
|
/**
|
2007-06-26 22:21:22 +00:00
|
|
|
* virBuffer:
|
2007-03-15 17:30:04 +00:00
|
|
|
*
|
|
|
|
* A buffer structure.
|
|
|
|
*/
|
2007-06-26 22:21:22 +00:00
|
|
|
typedef struct _virBuffer virBuffer;
|
|
|
|
typedef virBuffer *virBufferPtr;
|
2008-04-28 15:14:59 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# ifndef __VIR_BUFFER_C__
|
2011-10-20 21:48:47 +00:00
|
|
|
# define VIR_BUFFER_INITIALIZER { 0, 0, 0, 0, NULL }
|
2008-04-28 15:14:59 +00:00
|
|
|
|
2011-10-20 21:48:47 +00:00
|
|
|
/* This struct must be kept in sync with the real struct
|
2008-04-28 15:14:59 +00:00
|
|
|
in the buf.c impl file */
|
2007-06-26 22:21:22 +00:00
|
|
|
struct _virBuffer {
|
2008-04-28 15:14:59 +00:00
|
|
|
unsigned int a;
|
|
|
|
unsigned int b;
|
|
|
|
unsigned int c;
|
2011-10-20 21:48:47 +00:00
|
|
|
int d;
|
|
|
|
char *e;
|
2007-03-15 17:30:04 +00:00
|
|
|
};
|
2010-03-09 18:22:22 +00:00
|
|
|
# endif
|
2007-03-15 17:30:04 +00:00
|
|
|
|
2012-06-08 19:50:23 +00:00
|
|
|
const char *virBufferCurrentContent(virBufferPtr buf);
|
2011-09-27 19:50:03 +00:00
|
|
|
char *virBufferContentAndReset(virBufferPtr buf);
|
|
|
|
void virBufferFreeAndReset(virBufferPtr buf);
|
maint: avoid 'const fooPtr' in several util files
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up offenders in src/util outside of the virnet namespace.
Also, make a few virSocketAddr functions const-correct, for easier
conversions in future patches.
* src/util/virbuffer.h (virBufferError, virBufferUse)
(virBufferGetIndent): Use intended type.
* src/util/virmacaddr.h (virMacAddrCmp, virMacAddrCmpRaw)
(virMacAddrSet, virMcAddrFormat, virMacAddrIsUnicast)
(virMacAddrIsMulticast): Likewise.
* src/util/virebtables.h (ebtablesAddForwardAllowIn)
(ebtablesRemoveForwardAllowIn): Likewise.
* src/util/virsocketaddr.h (virSocketAddrSetIPv4Addr): Drop
incorrect const.
(virMacAddrGetRaw, virSocketAddrFormat, virSocketAddrFormatFull):
Make const-correct.
(virSocketAddrMask, virSocketAddrMaskByPrefix)
(virSocketAddrBroadcast, virSocketAddrBroadcastByPrefix)
(virSocketAddrGetNumNetmaskBits, virSocketAddrGetIpPrefix)
(virSocketAddrEqual, virSocketAddrIsPrivate)
(virSocketAddrIsWildcard): Use intended type.
* src/util/virbuffer.c (virBufferError, virBufferUse)
(virBufferGetIndent): Fix fallout.
* src/util/virmacaddr.c (virMacAddrCmp, virMacAddrCmpRaw)
(virMacAddrSet, virMcAddrFormat, virMacAddrIsUnicast)
(virMacAddrIsMulticast): Likewise.
* src/util/virebtables.c (ebtablesAddForwardAllowIn)
(ebtablesRemoveForwardAllowIn): Likewise.
* src/util/virsocketaddr.c (virSocketAddrMask, virMacAddrGetRaw)
(virSocketAddrMaskByPrefix, virSocketAddrBroadcast)
(virSocketAddrBroadcastByPrefix, virSocketAddrGetNumNetmaskBits)
(virSocketAddrGetIpPrefix, virSocketAddrEqual)
(virSocketAddrIsPrivate, virSocketAddrIsWildcard)
(virSocketAddrGetIPv4Addr, virSocketAddrGetIPv6Addr)
(virSocketAddrFormat, virSocketAddrFormatFull): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-05 15:51:55 +00:00
|
|
|
int virBufferError(const virBuffer *buf);
|
2014-06-27 07:23:13 +00:00
|
|
|
int virBufferCheckErrorInternal(const virBuffer *buf,
|
|
|
|
int domcode,
|
|
|
|
const char *filename,
|
|
|
|
const char *funcname,
|
|
|
|
size_t linenr)
|
2017-08-16 09:09:47 +00:00
|
|
|
ATTRIBUTE_NONNULL(1);
|
2014-06-27 07:23:13 +00:00
|
|
|
/**
|
|
|
|
* virBufferCheckError
|
|
|
|
*
|
|
|
|
* Checks if the buffer is in error state and reports an error.
|
|
|
|
*
|
2014-08-23 19:57:44 +00:00
|
|
|
* Returns 0 if no error has occurred, otherwise an error is reported
|
2014-06-27 07:23:13 +00:00
|
|
|
* and -1 is returned.
|
|
|
|
*/
|
|
|
|
# define virBufferCheckError(buf) \
|
|
|
|
virBufferCheckErrorInternal(buf, VIR_FROM_THIS, __FILE__, __FUNCTION__, \
|
|
|
|
__LINE__)
|
maint: avoid 'const fooPtr' in several util files
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up offenders in src/util outside of the virnet namespace.
Also, make a few virSocketAddr functions const-correct, for easier
conversions in future patches.
* src/util/virbuffer.h (virBufferError, virBufferUse)
(virBufferGetIndent): Use intended type.
* src/util/virmacaddr.h (virMacAddrCmp, virMacAddrCmpRaw)
(virMacAddrSet, virMcAddrFormat, virMacAddrIsUnicast)
(virMacAddrIsMulticast): Likewise.
* src/util/virebtables.h (ebtablesAddForwardAllowIn)
(ebtablesRemoveForwardAllowIn): Likewise.
* src/util/virsocketaddr.h (virSocketAddrSetIPv4Addr): Drop
incorrect const.
(virMacAddrGetRaw, virSocketAddrFormat, virSocketAddrFormatFull):
Make const-correct.
(virSocketAddrMask, virSocketAddrMaskByPrefix)
(virSocketAddrBroadcast, virSocketAddrBroadcastByPrefix)
(virSocketAddrGetNumNetmaskBits, virSocketAddrGetIpPrefix)
(virSocketAddrEqual, virSocketAddrIsPrivate)
(virSocketAddrIsWildcard): Use intended type.
* src/util/virbuffer.c (virBufferError, virBufferUse)
(virBufferGetIndent): Fix fallout.
* src/util/virmacaddr.c (virMacAddrCmp, virMacAddrCmpRaw)
(virMacAddrSet, virMcAddrFormat, virMacAddrIsUnicast)
(virMacAddrIsMulticast): Likewise.
* src/util/virebtables.c (ebtablesAddForwardAllowIn)
(ebtablesRemoveForwardAllowIn): Likewise.
* src/util/virsocketaddr.c (virSocketAddrMask, virMacAddrGetRaw)
(virSocketAddrMaskByPrefix, virSocketAddrBroadcast)
(virSocketAddrBroadcastByPrefix, virSocketAddrGetNumNetmaskBits)
(virSocketAddrGetIpPrefix, virSocketAddrEqual)
(virSocketAddrIsPrivate, virSocketAddrIsWildcard)
(virSocketAddrGetIPv4Addr, virSocketAddrGetIPv6Addr)
(virSocketAddrFormat, virSocketAddrFormatFull): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-05 15:51:55 +00:00
|
|
|
unsigned int virBufferUse(const virBuffer *buf);
|
2011-09-27 19:50:03 +00:00
|
|
|
void virBufferAdd(virBufferPtr buf, const char *str, int len);
|
2015-02-19 09:56:58 +00:00
|
|
|
void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd);
|
2011-09-27 19:50:03 +00:00
|
|
|
void virBufferAddChar(virBufferPtr buf, char c);
|
|
|
|
void virBufferAsprintf(virBufferPtr buf, const char *format, ...)
|
Fix misc Win32 compile warnings
GCC >= 4.4 assumes the 'printf' attribute refers to the native
runtime libraries format specifiers. Thanks to gnulib, libvirt
has GNU format specifiers everywhere. This means we need to
use 'gnu_printf' with GCC >= 4.4 to get correct compiler
checking of printf format specifiers.
* HACKING: Document new rules for ATTRIBUTE_FMT_PRINTF
* autobuild.sh, mingw32-libvirt.spec.in: Disable OpenNebula
driver on mingw32 builds
* qemud/dispatch.h, qemud/qemu.h, src/buf.h src/internal.h,
src/logging.h, src/security.h, src/sexpr.h, src/util.h,
src/virterror_internal.h, src/xend_internal.c: Change
over to ATTRIBUTE_FMT_PRINTF.
* src/virsh.c: Disable 'cd' and 'pwd' commands on Win32
since they don't compile
* src/threads-win32.c: Add missing return value check
2009-07-23 15:07:32 +00:00
|
|
|
ATTRIBUTE_FMT_PRINTF(2, 3);
|
2011-09-27 19:50:03 +00:00
|
|
|
void virBufferVasprintf(virBufferPtr buf, const char *format, va_list ap)
|
2011-04-30 16:44:42 +00:00
|
|
|
ATTRIBUTE_FMT_PRINTF(2, 0);
|
2011-09-27 19:50:03 +00:00
|
|
|
void virBufferStrcat(virBufferPtr buf, ...)
|
2009-11-06 09:39:13 +00:00
|
|
|
ATTRIBUTE_SENTINEL;
|
2017-07-24 16:54:15 +00:00
|
|
|
void virBufferStrcatVArgs(virBufferPtr buf, va_list ap);
|
|
|
|
|
2012-03-09 19:13:30 +00:00
|
|
|
void virBufferEscape(virBufferPtr buf, char escape, const char *toescape,
|
2011-09-27 19:50:03 +00:00
|
|
|
const char *format, const char *str);
|
2017-02-23 12:43:32 +00:00
|
|
|
void virBufferEscapeN(virBufferPtr buf, const char *format,
|
|
|
|
const char *str, ...);
|
2011-09-27 19:50:03 +00:00
|
|
|
void virBufferEscapeString(virBufferPtr buf, const char *format,
|
|
|
|
const char *str);
|
|
|
|
void virBufferEscapeSexpr(virBufferPtr buf, const char *format,
|
|
|
|
const char *str);
|
2017-05-12 12:26:09 +00:00
|
|
|
void virBufferEscapeRegex(virBufferPtr buf,
|
|
|
|
const char *format,
|
|
|
|
const char *str);
|
2017-10-06 06:47:34 +00:00
|
|
|
void virBufferEscapeSQL(virBufferPtr buf,
|
|
|
|
const char *format,
|
|
|
|
const char *str);
|
2011-07-28 13:25:00 +00:00
|
|
|
void virBufferEscapeShell(virBufferPtr buf, const char *str);
|
2011-09-27 19:50:03 +00:00
|
|
|
void virBufferURIEncodeString(virBufferPtr buf, const char *str);
|
2007-03-15 17:30:04 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# define virBufferAddLit(buf_, literal_string_) \
|
2012-03-29 09:52:04 +00:00
|
|
|
virBufferAdd(buf_, "" literal_string_ "", sizeof(literal_string_) - 1)
|
2008-04-28 15:14:59 +00:00
|
|
|
|
2011-10-20 21:48:47 +00:00
|
|
|
void virBufferAdjustIndent(virBufferPtr buf, int indent);
|
2017-03-09 16:02:19 +00:00
|
|
|
void virBufferSetIndent(virBufferPtr, int indent);
|
|
|
|
|
2017-08-24 12:54:56 +00:00
|
|
|
/**
|
|
|
|
* virBufferSetChildIndent
|
|
|
|
*
|
|
|
|
* Gets the parent indentation, increments it by 2 and sets it to
|
|
|
|
* child buffer.
|
|
|
|
*/
|
|
|
|
# define virBufferSetChildIndent(childBuf_, parentBuf_) \
|
2018-05-11 12:05:53 +00:00
|
|
|
virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_, false) + 2)
|
2017-08-24 12:54:56 +00:00
|
|
|
|
maint: avoid 'const fooPtr' in several util files
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up offenders in src/util outside of the virnet namespace.
Also, make a few virSocketAddr functions const-correct, for easier
conversions in future patches.
* src/util/virbuffer.h (virBufferError, virBufferUse)
(virBufferGetIndent): Use intended type.
* src/util/virmacaddr.h (virMacAddrCmp, virMacAddrCmpRaw)
(virMacAddrSet, virMcAddrFormat, virMacAddrIsUnicast)
(virMacAddrIsMulticast): Likewise.
* src/util/virebtables.h (ebtablesAddForwardAllowIn)
(ebtablesRemoveForwardAllowIn): Likewise.
* src/util/virsocketaddr.h (virSocketAddrSetIPv4Addr): Drop
incorrect const.
(virMacAddrGetRaw, virSocketAddrFormat, virSocketAddrFormatFull):
Make const-correct.
(virSocketAddrMask, virSocketAddrMaskByPrefix)
(virSocketAddrBroadcast, virSocketAddrBroadcastByPrefix)
(virSocketAddrGetNumNetmaskBits, virSocketAddrGetIpPrefix)
(virSocketAddrEqual, virSocketAddrIsPrivate)
(virSocketAddrIsWildcard): Use intended type.
* src/util/virbuffer.c (virBufferError, virBufferUse)
(virBufferGetIndent): Fix fallout.
* src/util/virmacaddr.c (virMacAddrCmp, virMacAddrCmpRaw)
(virMacAddrSet, virMcAddrFormat, virMacAddrIsUnicast)
(virMacAddrIsMulticast): Likewise.
* src/util/virebtables.c (ebtablesAddForwardAllowIn)
(ebtablesRemoveForwardAllowIn): Likewise.
* src/util/virsocketaddr.c (virSocketAddrMask, virMacAddrGetRaw)
(virSocketAddrMaskByPrefix, virSocketAddrBroadcast)
(virSocketAddrBroadcastByPrefix, virSocketAddrGetNumNetmaskBits)
(virSocketAddrGetIpPrefix, virSocketAddrEqual)
(virSocketAddrIsPrivate, virSocketAddrIsWildcard)
(virSocketAddrGetIPv4Addr, virSocketAddrGetIPv6Addr)
(virSocketAddrFormat, virSocketAddrFormatFull): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-05 15:51:55 +00:00
|
|
|
int virBufferGetIndent(const virBuffer *buf, bool dynamic);
|
2011-10-20 21:48:47 +00:00
|
|
|
|
2013-06-18 15:52:00 +00:00
|
|
|
void virBufferTrim(virBufferPtr buf, const char *trim, int len);
|
2015-03-24 09:53:29 +00:00
|
|
|
void virBufferAddStr(virBufferPtr buf, const char *str);
|
virBuffer: add way to trim back extra text
I'm tired of writing:
bool sep = false;
while (...) {
if (sep)
virBufferAddChar(buf, ',');
sep = true;
virBufferAdd(buf, str);
}
This makes it easier, allowing one to write:
while (...)
virBufferAsprintf(buf, "%s,", str);
virBufferTrim(buf, ",", -1);
to trim any remaining comma.
* src/util/buf.h (virBufferTrim): Declare.
* src/util/buf.c (virBufferTrim): New function.
* tests/virbuftest.c (testBufTrim): Test it.
2012-05-18 22:36:59 +00:00
|
|
|
|
2007-06-26 22:21:22 +00:00
|
|
|
#endif /* __VIR_BUFFER_H__ */
|