mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 20:45:18 +00:00
snapshot: simplify indentation of nwfilter
Fixing this involved some refactoring of common code out of domain_conf and nwfilter_conf into nwfilter_params. * src/conf/nwfilter_params.h (virNWFilterFormatParamAttributes): Adjust signature. * src/conf/nwfilter_params.c (_formatParameterAttrs) (virNWFilterFormatParamAttributes): Adjust indentation handling, and handle filterref here. (formatterParam): Delete unused struct. * src/conf/domain_conf.c (virDomainNetDefFormat): Adjust caller. * src/conf/nwfilter_conf.c (virNWFilterIncludeDefFormat): Likewise.
This commit is contained in:
parent
c04beb5d3a
commit
46e1a426f9
@ -9554,7 +9554,6 @@ virDomainNetDefFormat(virBufferPtr buf,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
const char *type = virDomainNetTypeToString(def->type);
|
const char *type = virDomainNetTypeToString(def->type);
|
||||||
char *attrs;
|
|
||||||
|
|
||||||
if (!type) {
|
if (!type) {
|
||||||
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
|
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -9675,15 +9674,11 @@ virDomainNetDefFormat(virBufferPtr buf,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (def->filter) {
|
if (def->filter) {
|
||||||
virBufferEscapeString(buf, " <filterref filter='%s'",
|
virBufferAdjustIndent(buf, 6);
|
||||||
def->filter);
|
if (virNWFilterFormatParamAttributes(buf, def->filterparams,
|
||||||
attrs = virNWFilterFormatParamAttributes(def->filterparams,
|
def->filter) < 0)
|
||||||
" ");
|
return -1;
|
||||||
if (!attrs || strlen(attrs) <= 1)
|
virBufferAdjustIndent(buf, -6);
|
||||||
virBufferAddLit(buf, "/>\n");
|
|
||||||
else
|
|
||||||
virBufferAsprintf(buf, ">\n%s </filterref>\n", attrs);
|
|
||||||
VIR_FREE(attrs);
|
|
||||||
}
|
}
|
||||||
if (def->bootIndex)
|
if (def->bootIndex)
|
||||||
virBufferAsprintf(buf, " <boot order='%d'/>\n", def->bootIndex);
|
virBufferAsprintf(buf, " <boot order='%d'/>\n", def->bootIndex);
|
||||||
|
@ -2853,19 +2853,15 @@ no_memory:
|
|||||||
static char *
|
static char *
|
||||||
virNWFilterIncludeDefFormat(virNWFilterIncludeDefPtr inc)
|
virNWFilterIncludeDefFormat(virNWFilterIncludeDefPtr inc)
|
||||||
{
|
{
|
||||||
char *attrs;
|
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
virBufferAsprintf(&buf," <filterref filter='%s'",
|
virBufferAdjustIndent(&buf, 2);
|
||||||
inc->filterref);
|
if (virNWFilterFormatParamAttributes(&buf, inc->params,
|
||||||
|
inc->filterref) < 0) {
|
||||||
attrs = virNWFilterFormatParamAttributes(inc->params, " ");
|
virBufferFreeAndReset(&buf);
|
||||||
|
return NULL;
|
||||||
if (!attrs || strlen(attrs) <= 1)
|
}
|
||||||
virBufferAddLit(&buf, "/>\n");
|
virBufferAdjustIndent(&buf, -2);
|
||||||
else
|
|
||||||
virBufferAsprintf(&buf, ">\n%s </filterref>\n", attrs);
|
|
||||||
|
|
||||||
if (virBufferError(&buf)) {
|
if (virBufferError(&buf)) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
virBufferFreeAndReset(&buf);
|
virBufferFreeAndReset(&buf);
|
||||||
|
@ -258,41 +258,36 @@ skip_entry:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct formatterParam {
|
|
||||||
virBufferPtr buf;
|
|
||||||
const char *indent;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_formatParameterAttrs(void *payload, const void *name, void *data)
|
_formatParameterAttrs(void *payload, const void *name, void *data)
|
||||||
{
|
{
|
||||||
struct formatterParam *fp = (struct formatterParam *)data;
|
virBufferPtr buf = data;
|
||||||
|
|
||||||
virBufferAsprintf(fp->buf, "%s<parameter name='%s' value='%s'/>\n",
|
virBufferAsprintf(buf, " <parameter name='%s' value='%s'/>\n",
|
||||||
fp->indent,
|
|
||||||
(const char *)name,
|
(const char *)name,
|
||||||
(char *)payload);
|
(char *)payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *
|
int
|
||||||
virNWFilterFormatParamAttributes(virNWFilterHashTablePtr table,
|
virNWFilterFormatParamAttributes(virBufferPtr buf,
|
||||||
const char *indent)
|
virNWFilterHashTablePtr table,
|
||||||
|
const char *filterref)
|
||||||
{
|
{
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
int count = virHashSize(table->hashTable);
|
||||||
struct formatterParam fp = {
|
|
||||||
.buf = &buf,
|
|
||||||
.indent = indent,
|
|
||||||
};
|
|
||||||
|
|
||||||
virHashForEach(table->hashTable, _formatParameterAttrs, &fp);
|
if (count < 0) {
|
||||||
|
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
if (virBufferError(&buf)) {
|
_("missing filter parameter table"));
|
||||||
virReportOOMError();
|
return -1;
|
||||||
virBufferFreeAndReset(&buf);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
virBufferAsprintf(buf, "<filterref filter='%s'", filterref);
|
||||||
return virBufferContentAndReset(&buf);
|
if (count) {
|
||||||
|
virBufferAddLit(buf, ">\n");
|
||||||
|
virHashForEach(table->hashTable, _formatParameterAttrs, buf);
|
||||||
|
virBufferAddLit(buf, "</filterref>\n");
|
||||||
|
} else {
|
||||||
|
virBufferAddLit(buf, "/>\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* nwfilter_params.h: parsing and data maintenance of filter parameters
|
* nwfilter_params.h: parsing and data maintenance of filter parameters
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2011 Red Hat, Inc.
|
||||||
* Copyright (C) 2010 IBM Corporation
|
* Copyright (C) 2010 IBM Corporation
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
@ -23,6 +24,7 @@
|
|||||||
# define NWFILTER_PARAMS_H
|
# define NWFILTER_PARAMS_H
|
||||||
|
|
||||||
# include "hash.h"
|
# include "hash.h"
|
||||||
|
# include "buf.h"
|
||||||
|
|
||||||
typedef struct _virNWFilterHashTable virNWFilterHashTable;
|
typedef struct _virNWFilterHashTable virNWFilterHashTable;
|
||||||
typedef virNWFilterHashTable *virNWFilterHashTablePtr;
|
typedef virNWFilterHashTable *virNWFilterHashTablePtr;
|
||||||
@ -35,8 +37,9 @@ struct _virNWFilterHashTable {
|
|||||||
|
|
||||||
|
|
||||||
virNWFilterHashTablePtr virNWFilterParseParamAttributes(xmlNodePtr cur);
|
virNWFilterHashTablePtr virNWFilterParseParamAttributes(xmlNodePtr cur);
|
||||||
char * virNWFilterFormatParamAttributes(virNWFilterHashTablePtr table,
|
int virNWFilterFormatParamAttributes(virBufferPtr buf,
|
||||||
const char *indent);
|
virNWFilterHashTablePtr table,
|
||||||
|
const char *filterref);
|
||||||
|
|
||||||
virNWFilterHashTablePtr virNWFilterHashTableCreate(int n);
|
virNWFilterHashTablePtr virNWFilterHashTableCreate(int n);
|
||||||
void virNWFilterHashTableFree(virNWFilterHashTablePtr table);
|
void virNWFilterHashTableFree(virNWFilterHashTablePtr table);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user