mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
conf: secret: Refactor cleanup in secretXMLParseNode
Use VIR_AUTO* for temporary locals and get rid of the 'cleanup' label. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
8d301bd435
commit
47b35f4d0e
@ -131,33 +131,33 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt,
|
|||||||
static virSecretDefPtr
|
static virSecretDefPtr
|
||||||
secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
|
secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
|
||||||
{
|
{
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
|
||||||
virSecretDefPtr def = NULL, ret = NULL;
|
VIR_AUTOPTR(virSecretDef) def = NULL;
|
||||||
char *prop = NULL;
|
VIR_AUTOFREE(char *) prop = NULL;
|
||||||
char *uuidstr = NULL;
|
VIR_AUTOFREE(char *) uuidstr = NULL;
|
||||||
|
|
||||||
if (!virXMLNodeNameEqual(root, "secret")) {
|
if (!virXMLNodeNameEqual(root, "secret")) {
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
_("unexpected root element <%s>, "
|
_("unexpected root element <%s>, "
|
||||||
"expecting <secret>"),
|
"expecting <secret>"),
|
||||||
root->name);
|
root->name);
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
ctxt->node = root;
|
ctxt->node = root;
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0)
|
if (VIR_ALLOC(def) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
prop = virXPathString("string(./@ephemeral)", ctxt);
|
prop = virXPathString("string(./@ephemeral)", ctxt);
|
||||||
if (prop != NULL) {
|
if (prop != NULL) {
|
||||||
if (virStringParseYesNo(prop, &def->isephemeral) < 0) {
|
if (virStringParseYesNo(prop, &def->isephemeral) < 0) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("invalid value of 'ephemeral'"));
|
_("invalid value of 'ephemeral'"));
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
VIR_FREE(prop);
|
VIR_FREE(prop);
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
|
|||||||
if (virStringParseYesNo(prop, &def->isprivate) < 0) {
|
if (virStringParseYesNo(prop, &def->isprivate) < 0) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("invalid value of 'private'"));
|
_("invalid value of 'private'"));
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
VIR_FREE(prop);
|
VIR_FREE(prop);
|
||||||
}
|
}
|
||||||
@ -177,13 +177,13 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
|
|||||||
if (virUUIDGenerate(def->uuid) < 0) {
|
if (virUUIDGenerate(def->uuid) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("Failed to generate UUID"));
|
"%s", _("Failed to generate UUID"));
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (virUUIDParse(uuidstr, def->uuid) < 0) {
|
if (virUUIDParse(uuidstr, def->uuid) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("malformed uuid element"));
|
"%s", _("malformed uuid element"));
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
VIR_FREE(uuidstr);
|
VIR_FREE(uuidstr);
|
||||||
}
|
}
|
||||||
@ -191,15 +191,9 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
|
|||||||
def->description = virXPathString("string(./description)", ctxt);
|
def->description = virXPathString("string(./description)", ctxt);
|
||||||
if (virXPathNode("./usage", ctxt) != NULL
|
if (virXPathNode("./usage", ctxt) != NULL
|
||||||
&& virSecretDefParseUsage(ctxt, def) < 0)
|
&& virSecretDefParseUsage(ctxt, def) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
VIR_STEAL_PTR(ret, def);
|
|
||||||
|
|
||||||
cleanup:
|
VIR_RETURN_PTR(def);
|
||||||
VIR_FREE(prop);
|
|
||||||
VIR_FREE(uuidstr);
|
|
||||||
virSecretDefFree(def);
|
|
||||||
xmlXPathFreeContext(ctxt);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static virSecretDefPtr
|
static virSecretDefPtr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user