mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-04-01 20:05:19 +00:00
Refactoring virDomainSmartcardDefParseXML() to use XPath
Signed-off-by: Kristina Hanicova <khanicov@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
7fefde1f44
commit
17ae6e8d64
@ -11607,12 +11607,14 @@ virDomainSmartcardDefParseXML(virDomainXMLOption *xmlopt,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned int flags)
|
||||
{
|
||||
xmlNodePtr cur;
|
||||
g_autoptr(virDomainSmartcardDef) def = NULL;
|
||||
size_t i;
|
||||
g_autofree char *mode = NULL;
|
||||
g_autofree char *type = NULL;
|
||||
g_autofree xmlNodePtr *certificates = NULL;
|
||||
int n = 0;
|
||||
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
||||
|
||||
ctxt->node = node;
|
||||
def = g_new0(virDomainSmartcardDef, 1);
|
||||
|
||||
mode = virXMLPropString(node, "mode");
|
||||
@ -11633,42 +11635,32 @@ virDomainSmartcardDefParseXML(virDomainXMLOption *xmlopt,
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_SMARTCARD_TYPE_HOST_CERTIFICATES:
|
||||
i = 0;
|
||||
cur = node->children;
|
||||
while (cur) {
|
||||
if (cur->type == XML_ELEMENT_NODE &&
|
||||
virXMLNodeNameEqual(cur, "certificate")) {
|
||||
if (i == 3) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("host-certificates mode needs "
|
||||
"exactly three certificates"));
|
||||
return NULL;
|
||||
}
|
||||
if (!(def->data.cert.file[i] = virXMLNodeContentString(cur)))
|
||||
return NULL;
|
||||
|
||||
i++;
|
||||
} else if (cur->type == XML_ELEMENT_NODE &&
|
||||
virXMLNodeNameEqual(cur, "database") &&
|
||||
!def->data.cert.database) {
|
||||
if (!(def->data.cert.database = virXMLNodeContentString(cur)))
|
||||
return NULL;
|
||||
|
||||
if (*def->data.cert.database != '/') {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("expecting absolute path: %s"),
|
||||
def->data.cert.database);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
if (i < 3) {
|
||||
n = virXPathNodeSet("./certificate", ctxt, &certificates);
|
||||
if (n != VIR_DOMAIN_SMARTCARD_NUM_CERTIFICATES) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("host-certificates mode needs "
|
||||
"exactly three certificates"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(def->data.cert.file[0] = virXMLNodeContentString(certificates[0])) ||
|
||||
!(def->data.cert.file[1] = virXMLNodeContentString(certificates[1])) ||
|
||||
!(def->data.cert.file[2] = virXMLNodeContentString(certificates[2])))
|
||||
return NULL;
|
||||
|
||||
if (virXPathNode("./database", ctxt) &&
|
||||
!def->data.cert.database) {
|
||||
if (!(def->data.cert.database =
|
||||
virXPathString("string(./database/text())", ctxt)))
|
||||
return NULL;
|
||||
|
||||
if (*def->data.cert.database != '/') {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("expecting absolute path: %s"),
|
||||
def->data.cert.database);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH:
|
||||
@ -11690,7 +11682,6 @@ virDomainSmartcardDefParseXML(virDomainXMLOption *xmlopt,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cur = node->children;
|
||||
if (virDomainChrSourceDefParseXML(def->data.passthru, node, flags,
|
||||
NULL, ctxt) < 0)
|
||||
return NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user