Move to virsecret.c and rename to virSecretParseSecret. Also convert to
usage xmlNodePtr and virXMLPropString rather than virXPathString.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
po/POTFILES.in | 1 +
src/libvirt_private.syms | 1 +
src/util/virsecret.c | 44 +++++++++++++++++++++++++++++
src/util/virsecret.h | 5 +++-
src/util/virstoragefile.c | 71 ++++++++++++-----------------------------------
5 files changed, 67 insertions(+), 55 deletions(-)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 822cfbc..67838f5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -233,6 +233,7 @@ src/util/virqemu.c
src/util/virrandom.c
src/util/virrotatingfile.c
src/util/virscsi.c
+src/util/virsecret.c
src/util/virsexpr.c
src/util/virsocketaddr.c
src/util/virstats.c
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 32d5179..ca65885 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2211,6 +2211,7 @@ virSecurityLabelDefNew;
# util/virsecret.h
virSecretLookupDefClear;
virSecretLookupDefCopy;
+virSecretParseSecret;
# util/virsexpr.h
diff --git a/src/util/virsecret.c b/src/util/virsecret.c
index e7a03b7..da5f7af 100644
--- a/src/util/virsecret.c
+++ b/src/util/virsecret.c
@@ -26,6 +26,7 @@
#include "virlog.h"
#include "virsecret.h"
#include "virstring.h"
+#include "viruuid.h"
#define VIR_FROM_THIS VIR_FROM_NONE
@@ -55,3 +56,46 @@ virSecretLookupDefCopy(virSecretLookupTypeDefPtr dst,
}
return 0;
}
+
+
+int
+virSecretParseSecret(xmlNodePtr secretnode,
+ virSecretLookupTypeDefPtr secdef)
+{
+ char *uuid;
+ char *usage;
+ int ret = -1;
+
+ uuid = virXMLPropString(secretnode, "uuid");
+ usage = virXMLPropString(secretnode, "usage");
+ if (uuid == NULL && usage == NULL) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("missing secret uuid or usage attribute"));
+ goto cleanup;
+ }
+
+ if (uuid && usage) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("either secret uuid or usage expected"));
+ goto cleanup;
+ }
+
+ if (uuid) {
+ if (virUUIDParse(uuid, secdef->u.uuid) < 0) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("invalid secret uuid '%s'"), uuid);
+ goto cleanup;
+ }
+ secdef->type = VIR_SECRET_LOOKUP_TYPE_UUID;
+ } else {
+ secdef->u.usage = usage;
+ usage = NULL;
+ secdef->type = VIR_SECRET_LOOKUP_TYPE_USAGE;
+ }
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(uuid);
+ VIR_FREE(usage);
+ return ret;
+}
diff --git a/src/util/virsecret.h b/src/util/virsecret.h
index f2a0b63..d97c17d 100644
--- a/src/util/virsecret.h
+++ b/src/util/virsecret.h
@@ -24,6 +24,8 @@
# include "internal.h"
+# include "virxml.h"
+
typedef enum {
VIR_SECRET_LOOKUP_TYPE_NONE,
VIR_SECRET_LOOKUP_TYPE_UUID,
@@ -46,5 +48,6 @@ struct _virSecretLookupTypeDef {
void virSecretLookupDefClear(virSecretLookupTypeDefPtr secdef);
int virSecretLookupDefCopy(virSecretLookupTypeDefPtr dst,
const virSecretLookupTypeDef *src);
-
+int virSecretParseSecret(xmlNodePtr secretnode,
+ virSecretLookupTypeDefPtr secdef);
#endif /* __VIR_SECRET_H__ */
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 7ed52ab..3a2fd75 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1537,62 +1537,11 @@ virStorageAuthDefCopy(const virStorageAuthDef *src)
}
-static int
-virStorageAuthDefParseSecret(xmlXPathContextPtr ctxt,
- virStorageAuthDefPtr authdef)
-{
- char *uuid;
- char *usage;
- int ret = -1;
-
- /* Used by the domain disk xml parsing in order to ensure the
- * <secret type='%s' value matches the expected secret type for
- * the style of disk (iscsi is chap, nbd is ceph). For some reason
- * the virSecretUsageType{From|To}String() cannot be linked here
- * and because only the domain parsing code cares - just keep
- * it as a string.
- */
- authdef->secrettype = virXPathString("string(./secret/@type)", ctxt);
-
- uuid = virXPathString("string(./secret/@uuid)", ctxt);
- usage = virXPathString("string(./secret/@usage)", ctxt);
- if (uuid == NULL && usage == NULL) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("missing auth secret uuid or usage attribute"));
- goto cleanup;
- }
-
- if (uuid && usage) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("either auth secret uuid or usage expected"));
- goto cleanup;
- }
-
- if (uuid) {
- if (virUUIDParse(uuid, authdef->secdef.u.uuid) < 0) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("invalid auth secret uuid"));
- goto cleanup;
- }
- authdef->secdef.type = VIR_SECRET_LOOKUP_TYPE_UUID;
- } else {
- authdef->secdef.u.usage = usage;
- usage = NULL;
- authdef->secdef.type = VIR_SECRET_LOOKUP_TYPE_USAGE;
- }
- ret = 0;
-
- cleanup:
- VIR_FREE(uuid);
- VIR_FREE(usage);
- return ret;
-}
-
-
static virStorageAuthDefPtr
virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
{
virStorageAuthDefPtr authdef = NULL;
+ xmlNodePtr secretnode = NULL;
char *username = NULL;
char *authtype = NULL;
@@ -1621,8 +1570,22 @@ virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
VIR_FREE(authtype);
}
- authdef->secdef.type = VIR_SECRET_LOOKUP_TYPE_NONE;
- if (virStorageAuthDefParseSecret(ctxt, authdef) < 0)
+ if (!(secretnode = virXPathNode("./secret ", ctxt))) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("Missing <secret> element in auth"));
+ goto error;
+ }
+
+ /* Used by the domain disk xml parsing in order to ensure the
+ * <secret type='%s' value matches the expected secret type for
+ * the style of disk (iscsi is chap, nbd is ceph). For some reason
+ * the virSecretUsageType{From|To}String() cannot be linked here
+ * and because only the domain parsing code cares - just keep
+ * it as a string.
+ */
+ authdef->secrettype = virXMLPropString(secretnode, "type");
+
+ if (virSecretParseSecret(secretnode, &authdef->secdef) < 0)
goto error;
return authdef;
--
2.5.5