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 13:57:44 -06:00
|
|
|
* Copyright (C) 2005-2008, 2011-2014 Red Hat, Inc.
|
2007-03-15 17:30:04 +00:00
|
|
|
*
|
2012-07-27 17:39:53 +08: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 16:30:55 -06:00
|
|
|
* License along with this library. If not, see
|
2012-07-27 17:39:53 +08:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2007-03-15 17:30:04 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-18 11:13:08 -05:00
|
|
|
#pragma once
|
2007-03-15 17:30:04 +00:00
|
|
|
|
2019-06-18 11:13:08 -05:00
|
|
|
#include <stdarg.h>
|
2018-07-24 21:22:04 +05:30
|
|
|
|
2019-06-18 11:13:08 -05:00
|
|
|
#include "internal.h"
|
2007-03-15 17:30:04 +00:00
|
|
|
|
2011-04-30 10:44:42 -06: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;
|
|
|
|
typedef virBuffer *virBufferPtr;
|
2008-04-28 15:14:59 +00:00
|
|
|
|
2019-10-24 14:09:42 +02:00
|
|
|
#define VIR_BUFFER_INITIALIZER { NULL, 0 }
|
2008-04-28 15:14:59 +00:00
|
|
|
|
2019-10-25 15:22:12 +02:00
|
|
|
/**
|
|
|
|
* VIR_BUFFER_INIT_CHILD:
|
|
|
|
* @parentbuf: parent buffer for XML element formatting
|
|
|
|
*
|
|
|
|
* Intitialize a virBuffer structure and set up the indentation level for
|
|
|
|
* 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 13:02:41 +02:00
|
|
|
GString *str;
|
2019-03-25 16:54:28 +01:00
|
|
|
int indent;
|
2007-03-15 17:30:04 +00:00
|
|
|
};
|
|
|
|
|
2012-06-08 13:50:23 -06:00
|
|
|
const char *virBufferCurrentContent(virBufferPtr buf);
|
2011-09-27 13:50:03 -06:00
|
|
|
char *virBufferContentAndReset(virBufferPtr buf);
|
|
|
|
void virBufferFreeAndReset(virBufferPtr buf);
|
2019-02-21 16:37:50 +01:00
|
|
|
|
2019-10-15 14:47:50 +02:00
|
|
|
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virBuffer, virBufferFreeAndReset);
|
2019-02-21 16:37:50 +01:00
|
|
|
|
2019-03-26 18:02:06 +01:00
|
|
|
size_t virBufferUse(const virBuffer *buf);
|
2011-09-27 13:50:03 -06:00
|
|
|
void virBufferAdd(virBufferPtr buf, const char *str, int len);
|
2015-02-19 10:56:58 +01:00
|
|
|
void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd);
|
2011-09-27 13:50:03 -06:00
|
|
|
void virBufferAddChar(virBufferPtr buf, char c);
|
|
|
|
void virBufferAsprintf(virBufferPtr buf, const char *format, ...)
|
2019-10-15 13:35:07 +02:00
|
|
|
G_GNUC_PRINTF(2, 3);
|
2011-09-27 13:50:03 -06:00
|
|
|
void virBufferVasprintf(virBufferPtr buf, const char *format, va_list ap)
|
2019-10-15 13:35:07 +02:00
|
|
|
G_GNUC_PRINTF(2, 0);
|
2011-09-27 13:50:03 -06:00
|
|
|
void virBufferStrcat(virBufferPtr buf, ...)
|
2019-10-14 14:13:31 +02:00
|
|
|
G_GNUC_NULL_TERMINATED;
|
2017-07-24 18:54:15 +02:00
|
|
|
void virBufferStrcatVArgs(virBufferPtr buf, va_list ap);
|
|
|
|
|
2012-03-09 16:13:30 -03:00
|
|
|
void virBufferEscape(virBufferPtr buf, char escape, const char *toescape,
|
2011-09-27 13:50:03 -06:00
|
|
|
const char *format, const char *str);
|
|
|
|
void virBufferEscapeString(virBufferPtr buf, const char *format,
|
|
|
|
const char *str);
|
|
|
|
void virBufferEscapeSexpr(virBufferPtr buf, const char *format,
|
|
|
|
const char *str);
|
2017-05-12 14:26:09 +02:00
|
|
|
void virBufferEscapeRegex(virBufferPtr buf,
|
|
|
|
const char *format,
|
|
|
|
const char *str);
|
2017-10-06 08:47:34 +02:00
|
|
|
void virBufferEscapeSQL(virBufferPtr buf,
|
|
|
|
const char *format,
|
|
|
|
const char *str);
|
2011-07-28 15:25:00 +02:00
|
|
|
void virBufferEscapeShell(virBufferPtr buf, const char *str);
|
2011-09-27 13:50:03 -06:00
|
|
|
void virBufferURIEncodeString(virBufferPtr buf, const char *str);
|
2007-03-15 17:30:04 +00:00
|
|
|
|
2019-06-18 11:13:08 -05:00
|
|
|
#define virBufferAddLit(buf_, literal_string_) \
|
2012-03-29 10:52:04 +01:00
|
|
|
virBufferAdd(buf_, "" literal_string_ "", sizeof(literal_string_) - 1)
|
2008-04-28 15:14:59 +00:00
|
|
|
|
2011-10-20 15:48:47 -06:00
|
|
|
void virBufferAdjustIndent(virBufferPtr buf, int indent);
|
2017-03-09 17:02:19 +01:00
|
|
|
void virBufferSetIndent(virBufferPtr, int indent);
|
|
|
|
|
2019-10-24 12:51:24 +02:00
|
|
|
size_t virBufferGetIndent(const virBuffer *buf);
|
2019-10-24 12:29:12 +02:00
|
|
|
size_t virBufferGetEffectiveIndent(const virBuffer *buf);
|
2011-10-20 15:48:47 -06:00
|
|
|
|
2020-02-02 20:26:38 +01:00
|
|
|
void virBufferTrim(virBufferPtr buf, const char *trim);
|
2020-01-14 08:04:14 +01:00
|
|
|
void virBufferTrimChars(virBufferPtr buf, const char *trim);
|
2020-02-02 20:16:36 +01:00
|
|
|
void virBufferTrimLen(virBufferPtr buf, int len);
|
2015-03-24 10:53:29 +01:00
|
|
|
void virBufferAddStr(virBufferPtr buf, const char *str);
|