--- src/util/virstorageencryption.c | 39 +++++++++++++++++++++++++++++++++++++++ src/util/virstorageencryption.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/src/util/virstorageencryption.c b/src/util/virstorageencryption.c index 1306490..f750642 100644 --- a/src/util/virstorageencryption.c +++ b/src/util/virstorageencryption.c @@ -67,6 +67,45 @@ virStorageEncryptionFree(virStorageEncryptionPtr enc) } static virStorageEncryptionSecretPtr +virStorageEncryptionSecretCopy(const virStorageEncryptionSecret *src) +{ + virStorageEncryptionSecretPtr ret; + + if (VIR_ALLOC(ret) < 0) + return NULL; + + memcpy(ret, src, sizeof(*src)); + + return ret; +} + +virStorageEncryptionPtr +virStorageEncryptionCopy(const virStorageEncryption *src) +{ + virStorageEncryptionPtr ret; + size_t i; + + if (VIR_ALLOC(ret) < 0) + return NULL; + + ret->nsecrets = src->nsecrets; + + if (VIR_ALLOC_N(ret->secrets, ret->nsecrets) < 0) + goto error; + + for (i = 0; i < src->nsecrets; i++) { + if (!(ret->secrets[i] = virStorageEncryptionSecretCopy(src->secrets[i]))) + goto error; + } + + return ret; + + error: + virStorageEncryptionFree(ret); + return NULL; +} + +static virStorageEncryptionSecretPtr virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, xmlNodePtr node) { diff --git a/src/util/virstorageencryption.h b/src/util/virstorageencryption.h index f63c9ee..313d7ac 100644 --- a/src/util/virstorageencryption.h +++ b/src/util/virstorageencryption.h @@ -61,6 +61,8 @@ struct _virStorageEncryption { virStorageEncryptionSecretPtr *secrets; }; +virStorageEncryptionPtr virStorageEncryptionCopy(const virStorageEncryption *src); + void virStorageEncryptionFree(virStorageEncryptionPtr enc); virStorageEncryptionPtr virStorageEncryptionParseNode(xmlDocPtr xml, -- 1.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list