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
|
|
|
*/
|
|
|
|
|
2019-06-18 16:13:08 +00:00
|
|
|
#pragma once
|
2007-03-15 17:30:04 +00:00
|
|
|
|
2019-06-18 16:13:08 +00:00
|
|
|
#include <stdarg.h>
|
2018-07-24 15:52:04 +00:00
|
|
|
|
2019-06-18 16:13:08 +00:00
|
|
|
#include "internal.h"
|
2007-03-15 17:30:04 +00:00
|
|
|
|
2011-04-30 16:44:42 +00:00
|
|
|
|
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;
|
2008-04-28 15:14:59 +00:00
|
|
|
|
2019-10-24 12:09:42 +00:00
|
|
|
#define VIR_BUFFER_INITIALIZER { NULL, 0 }
|
2008-04-28 15:14:59 +00:00
|
|
|
|
2019-10-25 13:22:12 +00:00
|
|
|
/**
|
|
|
|
* VIR_BUFFER_INIT_CHILD:
|
|
|
|
* @parentbuf: parent buffer for XML element formatting
|
|
|
|
*
|
2020-07-09 04:42:21 +00:00
|
|
|
* Initialize a virBuffer structure and set up the indentation level for
|
2019-10-25 13:22:12 +00:00
|
|
|
* formatting XML subelements of @parentbuf.
|
|
|
|
*/
|
|
|
|
#define VIR_BUFFER_INIT_CHILD(parentbuf) { NULL, (parentbuf)->indent + 2 }
|
|
|
|
|
2007-06-26 22:21:22 +00:00
|
|
|
struct _virBuffer {
|
2019-10-24 11:02:41 +00:00
|
|
|
GString *str;
|
2019-03-25 15:54:28 +00:00
|
|
|
int indent;
|
2007-03-15 17:30:04 +00:00
|
|
|
};
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
const char *virBufferCurrentContent(virBuffer *buf);
|
|
|
|
char *virBufferContentAndReset(virBuffer *buf);
|
|
|
|
void virBufferFreeAndReset(virBuffer *buf);
|
2019-02-21 15:37:50 +00:00
|
|
|
|
2019-10-15 12:47:50 +00:00
|
|
|
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virBuffer, virBufferFreeAndReset);
|
2019-02-21 15:37:50 +00:00
|
|
|
|
2019-03-26 17:02:06 +00:00
|
|
|
size_t virBufferUse(const virBuffer *buf);
|
2021-03-11 07:16:13 +00:00
|
|
|
void virBufferAdd(virBuffer *buf, const char *str, int len);
|
|
|
|
void virBufferAddBuffer(virBuffer *buf, virBuffer *toadd);
|
|
|
|
void virBufferAddChar(virBuffer *buf, char c);
|
|
|
|
void virBufferAsprintf(virBuffer *buf, const char *format, ...)
|
2019-10-15 11:35:07 +00:00
|
|
|
G_GNUC_PRINTF(2, 3);
|
2021-03-11 07:16:13 +00:00
|
|
|
void virBufferVasprintf(virBuffer *buf, const char *format, va_list ap)
|
2019-10-15 11:35:07 +00:00
|
|
|
G_GNUC_PRINTF(2, 0);
|
2021-03-11 07:16:13 +00:00
|
|
|
void virBufferStrcat(virBuffer *buf, ...)
|
2019-10-14 12:13:31 +00:00
|
|
|
G_GNUC_NULL_TERMINATED;
|
2021-03-11 07:16:13 +00:00
|
|
|
void virBufferStrcatVArgs(virBuffer *buf, va_list ap);
|
2017-07-24 16:54:15 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virBufferEscape(virBuffer *buf, char escape, const char *toescape,
|
2011-09-27 19:50:03 +00:00
|
|
|
const char *format, const char *str);
|
2021-03-11 07:16:13 +00:00
|
|
|
void virBufferEscapeString(virBuffer *buf, const char *format,
|
2011-09-27 19:50:03 +00:00
|
|
|
const char *str);
|
2021-03-11 07:16:13 +00:00
|
|
|
void virBufferEscapeSexpr(virBuffer *buf, const char *format,
|
2011-09-27 19:50:03 +00:00
|
|
|
const char *str);
|
2021-03-11 07:16:13 +00:00
|
|
|
void virBufferEscapeRegex(virBuffer *buf,
|
2017-05-12 12:26:09 +00:00
|
|
|
const char *format,
|
|
|
|
const char *str);
|
2021-03-11 07:16:13 +00:00
|
|
|
void virBufferEscapeSQL(virBuffer *buf,
|
2017-10-06 06:47:34 +00:00
|
|
|
const char *format,
|
|
|
|
const char *str);
|
2021-03-11 07:16:13 +00:00
|
|
|
void virBufferEscapeShell(virBuffer *buf, const char *str);
|
|
|
|
void virBufferURIEncodeString(virBuffer *buf, const char *str);
|
2007-03-15 17:30:04 +00:00
|
|
|
|
2019-06-18 16:13:08 +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
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virBufferAdjustIndent(virBuffer *buf, int indent);
|
|
|
|
void virBufferSetIndent(virBuffer *, int indent);
|
2017-03-09 16:02:19 +00:00
|
|
|
|
2019-10-24 10:51:24 +00:00
|
|
|
size_t virBufferGetIndent(const virBuffer *buf);
|
2019-10-24 10:29:12 +00:00
|
|
|
size_t virBufferGetEffectiveIndent(const virBuffer *buf);
|
2011-10-20 21:48:47 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virBufferTrim(virBuffer *buf, const char *trim);
|
|
|
|
void virBufferTrimChars(virBuffer *buf, const char *trim);
|
|
|
|
void virBufferTrimLen(virBuffer *buf, int len);
|
|
|
|
void virBufferAddStr(virBuffer *buf, const char *str);
|