mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: storage: Simplify error handling in virStorageAuthDefParseXML
Unify the cleanup and error paths and simplify the code flow by removing some unnecessary variables. Signed-off-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
b932ed69f6
commit
74942ff0b6
@ -1813,20 +1813,18 @@ static virStorageAuthDefPtr
|
|||||||
virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
|
virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
|
||||||
{
|
{
|
||||||
virStorageAuthDefPtr authdef = NULL;
|
virStorageAuthDefPtr authdef = NULL;
|
||||||
|
virStorageAuthDefPtr ret = NULL;
|
||||||
xmlNodePtr secretnode = NULL;
|
xmlNodePtr secretnode = NULL;
|
||||||
char *username = NULL;
|
|
||||||
char *authtype = NULL;
|
char *authtype = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(authdef) < 0)
|
if (VIR_ALLOC(authdef) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(username = virXPathString("string(./@username)", ctxt))) {
|
if (!(authdef->username = virXPathString("string(./@username)", ctxt))) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("missing username for auth"));
|
_("missing username for auth"));
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
authdef->username = username;
|
|
||||||
username = NULL;
|
|
||||||
|
|
||||||
authdef->authType = VIR_STORAGE_AUTH_TYPE_NONE;
|
authdef->authType = VIR_STORAGE_AUTH_TYPE_NONE;
|
||||||
authtype = virXPathString("string(./@type)", ctxt);
|
authtype = virXPathString("string(./@type)", ctxt);
|
||||||
@ -1837,15 +1835,14 @@ virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
if ((authdef->authType = virStorageAuthTypeFromString(authtype)) < 0) {
|
if ((authdef->authType = virStorageAuthTypeFromString(authtype)) < 0) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("unknown auth type '%s'"), authtype);
|
_("unknown auth type '%s'"), authtype);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
VIR_FREE(authtype);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(secretnode = virXPathNode("./secret ", ctxt))) {
|
if (!(secretnode = virXPathNode("./secret ", ctxt))) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("Missing <secret> element in auth"));
|
_("Missing <secret> element in auth"));
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Used by the domain disk xml parsing in order to ensure the
|
/* Used by the domain disk xml parsing in order to ensure the
|
||||||
@ -1858,15 +1855,15 @@ virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
authdef->secrettype = virXMLPropString(secretnode, "type");
|
authdef->secrettype = virXMLPropString(secretnode, "type");
|
||||||
|
|
||||||
if (virSecretLookupParseSecret(secretnode, &authdef->seclookupdef) < 0)
|
if (virSecretLookupParseSecret(secretnode, &authdef->seclookupdef) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
return authdef;
|
VIR_STEAL_PTR(ret, authdef);
|
||||||
|
|
||||||
error:
|
cleanup:
|
||||||
VIR_FREE(authtype);
|
VIR_FREE(authtype);
|
||||||
VIR_FREE(username);
|
|
||||||
virStorageAuthDefFree(authdef);
|
virStorageAuthDefFree(authdef);
|
||||||
return NULL;
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user