summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYifan Hong2017-06-13 16:13:56 -0500
committerYifan Hong2017-06-23 13:41:14 -0500
commitd48579083ce6d35949444801a9c34e20f4eae254 (patch)
treee4f818417c90b119968f9ee17ef94cb937e96f73 /parse_xml.cpp
parentaf23e28b683ec37e6f8eab1a23c43abba7de3b81 (diff)
downloadplatform-system-libvintf-d48579083ce6d35949444801a9c34e20f4eae254.tar.gz
platform-system-libvintf-d48579083ce6d35949444801a9c34e20f4eae254.tar.xz
platform-system-libvintf-d48579083ce6d35949444801a9c34e20f4eae254.zip
Add <xmlfile> to manifest / comp mat.
manifest.xml is allowed to contain <xmlfile> that is similar to: <xmlfile> <name>media_profile</name> <version>1.0</version> <path>/path/to/media_profile_v1_0.xml</path> </xmlfile> For compatibility-matrix.xml <xmlfile format="dtd" optional="false"> <name>media_profile</name> <version>1.0-1</version> <path>/path/to/media_profile_v1_1.dtd</path> </xmlfile> The <path> tag is optional. See test/main.cpp for examples. Test: libvintf_test Test: vintf_object_test Bug: 38359330 Change-Id: I0a921f32d023e1ba9c54ea6e898bb385fc7abd4f
Diffstat (limited to 'parse_xml.cpp')
-rw-r--r--parse_xml.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/parse_xml.cpp b/parse_xml.cpp
index 557da76..f12df00 100644
--- a/parse_xml.cpp
+++ b/parse_xml.cpp
@@ -265,6 +265,13 @@ struct XmlNodeConverter : public XmlConverter<Object> {
265 return true; 265 return true;
266 } 266 }
267 267
268 inline bool parseOptionalTextElement(NodeType* root, const std::string& elementName,
269 std::string&& defaultValue, std::string* s) const {
270 NodeType* child = getChild(root, elementName);
271 *s = child == nullptr ? std::move(defaultValue) : getText(child);
272 return true;
273 }
274
268 inline bool parseTextElements(NodeType *root, const std::string &elementName, 275 inline bool parseTextElements(NodeType *root, const std::string &elementName,
269 std::vector<std::string> *v) const { 276 std::vector<std::string> *v) const {
270 auto nodes = getChildren(root, elementName); 277 auto nodes = getChildren(root, elementName);
@@ -610,17 +617,40 @@ struct HalManifestSepolicyConverter : public XmlNodeConverter<Version> {
610}; 617};
611const HalManifestSepolicyConverter halManifestSepolicyConverter{}; 618const HalManifestSepolicyConverter halManifestSepolicyConverter{};
612 619
620struct ManifestXmlFileConverter : public XmlNodeConverter<ManifestXmlFile> {
621 std::string elementName() const override { return "xmlfile"; }
622 void mutateNode(const ManifestXmlFile& f, NodeType* root, DocType* d) const override {
623 appendTextElement(root, "name", f.name(), d);
624 appendChild(root, versionConverter(f.version(), d));
625 if (!f.overriddenPath().empty()) {
626 appendTextElement(root, "path", f.overriddenPath(), d);
627 }
628 }
629 bool buildObject(ManifestXmlFile* object, NodeType* root) const override {
630 if (!parseTextElement(root, "name", &object->mName) ||
631 !parseChild(root, versionConverter, &object->mVersion) ||
632 !parseOptionalTextElement(root, "path", {}, &object->mOverriddenPath)) {
633 return false;
634 }
635 return true;
636 }
637};
638const ManifestXmlFileConverter manifestXmlFileConverter{};
639
613struct HalManifestConverter : public XmlNodeConverter<HalManifest> { 640struct HalManifestConverter : public XmlNodeConverter<HalManifest> {
614 std::string elementName() const override { return "manifest"; } 641 std::string elementName() const override { return "manifest"; }
615 void mutateNode(const HalManifest &m, NodeType *root, DocType *d) const override { 642 void mutateNode(const HalManifest &m, NodeType *root, DocType *d) const override {
616 appendAttr(root, "version", HalManifest::kVersion); 643 appendAttr(root, "version", HalManifest::kVersion);
617 appendAttr(root, "type", m.mType); 644 appendAttr(root, "type", m.mType);
645
618 appendChildren(root, manifestHalConverter, m.getHals(), d); 646 appendChildren(root, manifestHalConverter, m.getHals(), d);
619 if (m.mType == SchemaType::DEVICE) { 647 if (m.mType == SchemaType::DEVICE) {
620 appendChild(root, halManifestSepolicyConverter(m.device.mSepolicyVersion, d)); 648 appendChild(root, halManifestSepolicyConverter(m.device.mSepolicyVersion, d));
621 } else if (m.mType == SchemaType::FRAMEWORK) { 649 } else if (m.mType == SchemaType::FRAMEWORK) {
622 appendChildren(root, vndkConverter, m.framework.mVndks, d); 650 appendChildren(root, vndkConverter, m.framework.mVndks, d);
623 } 651 }
652
653 appendChildren(root, manifestXmlFileConverter, m.getXmlFiles(), d);
624 } 654 }
625 bool buildObject(HalManifest *object, NodeType *root) const override { 655 bool buildObject(HalManifest *object, NodeType *root) const override {
626 Version version; 656 Version version;
@@ -661,6 +691,20 @@ struct HalManifestConverter : public XmlNodeConverter<HalManifest> {
661 return false; 691 return false;
662 } 692 }
663 } 693 }
694
695 std::vector<ManifestXmlFile> xmlFiles;
696 if (!parseChildren(root, manifestXmlFileConverter, &xmlFiles)) {
697 return false;
698 }
699 for (auto&& xmlFile : xmlFiles) {
700 std::string description{xmlFile.name()};
701 if (!object->addXmlFile(std::move(xmlFile))) {
702 this->mLastError = "Duplicated manifest.xmlfile entry " + description +
703 "; entries cannot have duplicated name and version";
704 return false;
705 }
706 }
707
664 return true; 708 return true;
665 } 709 }
666}; 710};
@@ -679,6 +723,30 @@ struct AvbConverter : public XmlNodeConverter<Version> {
679}; 723};
680const AvbConverter avbConverter{}; 724const AvbConverter avbConverter{};
681 725
726struct MatrixXmlFileConverter : public XmlNodeConverter<MatrixXmlFile> {
727 std::string elementName() const override { return "xmlfile"; }
728 void mutateNode(const MatrixXmlFile& f, NodeType* root, DocType* d) const override {
729 appendTextElement(root, "name", f.name(), d);
730 appendAttr(root, "format", f.format());
731 appendAttr(root, "optional", f.optional());
732 appendChild(root, versionRangeConverter(f.versionRange(), d));
733 if (!f.overriddenPath().empty()) {
734 appendTextElement(root, "path", f.overriddenPath(), d);
735 }
736 }
737 bool buildObject(MatrixXmlFile* object, NodeType* root) const override {
738 if (!parseTextElement(root, "name", &object->mName) ||
739 !parseAttr(root, "format", &object->mFormat) ||
740 !parseOptionalAttr(root, "optional", false, &object->mOptional) ||
741 !parseChild(root, versionRangeConverter, &object->mVersionRange) ||
742 !parseOptionalTextElement(root, "path", {}, &object->mOverriddenPath)) {
743 return false;
744 }
745 return true;
746 }
747};
748const MatrixXmlFileConverter matrixXmlFileConverter{};
749
682struct CompatibilityMatrixConverter : public XmlNodeConverter<CompatibilityMatrix> { 750struct CompatibilityMatrixConverter : public XmlNodeConverter<CompatibilityMatrix> {
683 std::string elementName() const override { return "compatibility-matrix"; } 751 std::string elementName() const override { return "compatibility-matrix"; }
684 void mutateNode(const CompatibilityMatrix &m, NodeType *root, DocType *d) const override { 752 void mutateNode(const CompatibilityMatrix &m, NodeType *root, DocType *d) const override {
@@ -692,6 +760,8 @@ struct CompatibilityMatrixConverter : public XmlNodeConverter<CompatibilityMatri
692 } else if (m.mType == SchemaType::DEVICE) { 760 } else if (m.mType == SchemaType::DEVICE) {
693 appendChild(root, vndkConverter(m.device.mVndk, d)); 761 appendChild(root, vndkConverter(m.device.mVndk, d));
694 } 762 }
763
764 appendChildren(root, matrixXmlFileConverter, m.getXmlFiles(), d);
695 } 765 }
696 bool buildObject(CompatibilityMatrix *object, NodeType *root) const override { 766 bool buildObject(CompatibilityMatrix *object, NodeType *root) const override {
697 Version version; 767 Version version;
@@ -728,6 +798,24 @@ struct CompatibilityMatrixConverter : public XmlNodeConverter<CompatibilityMatri
728 return false; 798 return false;
729 } 799 }
730 } 800 }
801
802 std::vector<MatrixXmlFile> xmlFiles;
803 if (!parseChildren(root, matrixXmlFileConverter, &xmlFiles)) {
804 return false;
805 }
806 for (auto&& xmlFile : xmlFiles) {
807 if (!xmlFile.optional()) {
808 this->mLastError = "compatibility-matrix.xmlfile entry " + xmlFile.name() +
809 " has to be optional for compatibility matrix version 1.0";
810 return false;
811 }
812 std::string description{xmlFile.name()};
813 if (!object->addXmlFile(std::move(xmlFile))) {
814 this->mLastError = "Duplicated compatibility-matrix.xmlfile entry " + description;
815 return false;
816 }
817 }
818
731 return true; 819 return true;
732 } 820 }
733}; 821};