Changeset 45227 in vbox for trunk/src/VBox/Main
- Timestamp:
- Mar 28, 2013 12:22:11 PM (12 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/ApplianceImpl.h
r44528 r45227 28 28 #include <iprt/tar.h> 29 29 30 #include "ovfreader.h" 31 30 32 /* VBox forward declarations */ 31 33 class Progress; … … 43 45 class OVFReader; 44 46 struct DiskImage; 47 struct EnvelopeData; 45 48 } 46 49 … … 73 76 DECLARE_EMPTY_CTOR_DTOR (Appliance) 74 77 75 enum OVFFormat 76 { 77 unspecified, 78 OVF_0_9, 79 OVF_1_0, 80 OVF_2_0 81 }; 78 82 79 83 80 // public initializer/uninitializer for internal purposes only … … 200 197 ******************************************************************************/ 201 198 202 HRESULT writeImpl( OVFFormataFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);199 HRESULT writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress); 203 200 204 201 HRESULT writeFS(TaskOVF *pTask); … … 209 206 210 207 struct XMLStack; 211 void buildXML(AutoWriteLockBase& writeLock, xml::Document &doc, XMLStack &stack, const Utf8Str &strPath, OVFFormat enFormat); 208 209 void buildXML(AutoWriteLockBase& writeLock, 210 xml::Document &doc, 211 XMLStack &stack, 212 const Utf8Str &strPath, 213 ovf::OVFVersion_T enFormat); 212 214 void buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock, 213 215 xml::ElementNode &elmToAddVirtualSystemsTo, 214 216 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes, 215 217 ComObjPtr<VirtualSystemDescription> &vsdescThis, 216 OVFFormatenFormat,218 ovf::OVFVersion_T enFormat, 217 219 XMLStack &stack); 218 219 220 220 221 friend class Machine; -
trunk/src/VBox/Main/include/ApplianceImplPrivate.h
r44528 r45227 116 116 locInfo(aLocInfo), 117 117 pProgress(aProgress), 118 enFormat( unspecified),118 enFormat(ovf::OVFVersion_unknown), 119 119 rc(S_OK) 120 120 {} … … 129 129 ComObjPtr<Progress> pProgress; 130 130 131 OVFFormatenFormat;131 ovf::OVFVersion_T enFormat; 132 132 133 133 HRESULT rc; -
trunk/src/VBox/Main/include/ovfreader.h
r44528 r45227 150 150 }; 151 151 152 enum OVFVersion_T 153 { 154 OVFVersion_unknown, 155 OVFVersion_0_9, 156 OVFVersion_1_0, 157 OVFVersion_2_0 158 }; 159 160 //////////////////////////////////////////////////////////////////////////////// 161 // 162 // Envelope data 163 // 164 //////////////////////////////////////////////////////////////////////////////// 165 struct EnvelopeData 166 { 167 RTCString version;//OVF standard version, it is used internally only by VirtualBox 168 RTCString lang;//language 169 170 OVFVersion_T getOVFVersion() const 171 { 172 if(version == "0.9") 173 return OVFVersion_0_9; 174 else if(version == "1.0") 175 return OVFVersion_1_0; 176 else if(version == "2.0") 177 return OVFVersion_2_0; 178 else 179 return OVFVersion_unknown; 180 } 181 }; 152 182 153 183 //////////////////////////////////////////////////////////////////////////////// … … 412 442 413 443 // Data fields 414 RTCString m_strPath; // file name given to constructor 444 EnvelopeData m_envelopeData; //data of root element "Envelope" 445 RTCString m_strPath; // file name given to constructor 415 446 DiskImagesMap m_mapDisks; // map of DiskImage structs, sorted by DiskImage.strDiskId 416 447 std::list<VirtualSystem> m_llVirtualSystems; // list of virtual systems, created by and valid after read() -
trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp
r45068 r45227 553 553 m->fManifest = !!fManifest; 554 554 Utf8Str strFormat(format); 555 OVFFormat ovfF; 555 556 ovf::OVFVersion_T ovfF; 556 557 if (strFormat == "ovf-0.9") 557 ovfF = OVF_0_9; 558 { 559 ovfF = ovf::OVFVersion_0_9; 560 } 558 561 else if (strFormat == "ovf-1.0") 559 ovfF = OVF_1_0; 562 { 563 ovfF = ovf::OVFVersion_1_0; 564 } 560 565 else if (strFormat == "ovf-2.0") 561 ovfF = OVF_2_0; 566 { 567 ovfF = ovf::OVFVersion_2_0; 568 } 562 569 else 563 570 return setError(VBOX_E_FILE_ERROR, … … 565 572 566 573 /* as of OVF 2.0 we have to use SHA256 */ 567 m->fSha256 = ovfF >= OVF_2_0;574 m->fSha256 = ovfF >= ovf::OVFVersion_2_0; 568 575 569 576 ComObjPtr<Progress> progress; … … 615 622 * @return 616 623 */ 617 HRESULT Appliance::writeImpl( OVFFormataFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)624 HRESULT Appliance::writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress) 618 625 { 619 626 HRESULT rc = S_OK; … … 659 666 XMLStack &stack, 660 667 const Utf8Str &strPath, 661 OVFFormatenFormat)668 ovf::OVFVersion_T enFormat) 662 669 { 663 670 xml::ElementNode *pelmRoot = doc.createRootElement("Envelope"); 664 671 665 pelmRoot->setAttribute("ovf:version", enFormat == OVF_2_0 ? "2.0"666 : enFormat == OVF_1_0 ? "1.0"672 pelmRoot->setAttribute("ovf:version", enFormat == ovf::OVFVersion_2_0 ? "2.0" 673 : enFormat == ovf::OVFVersion_1_0 ? "1.0" 667 674 : "0.9"); 668 675 pelmRoot->setAttribute("xml:lang", "en-US"); 669 676 670 Utf8Str strNamespace = (enFormat == OVF_0_9) 671 ? "http://www.vmware.com/schema/ovf/1/envelope" // 0.9 672 : "http://schemas.dmtf.org/ovf/envelope/1"; // 1.0 677 Utf8Str strNamespace; 678 679 if (enFormat == ovf::OVFVersion_0_9) 680 { 681 strNamespace = "http://www.vmware.com/schema/ovf/1/envelope"; 682 } 683 else if (enFormat == ovf::OVFVersion_1_0) 684 { 685 strNamespace = "http://schemas.dmtf.org/ovf/envelope/1"; 686 } 687 else 688 { 689 strNamespace = "http://schemas.dmtf.org/ovf/envelope/2"; 690 } 691 673 692 pelmRoot->setAttribute("xmlns", strNamespace); 674 693 pelmRoot->setAttribute("xmlns:ovf", strNamespace); … … 690 709 </DiskSection> */ 691 710 xml::ElementNode *pelmDiskSection; 692 if (enFormat == OVF_0_9)711 if (enFormat == ovf::OVFVersion_0_9) 693 712 { 694 713 // <Section xsi:type="ovf:DiskSection_Type"> … … 710 729 </NetworkSection> */ 711 730 xml::ElementNode *pelmNetworkSection; 712 if (enFormat == OVF_0_9)731 if (enFormat == ovf::OVFVersion_0_9) 713 732 { 714 733 // <Section xsi:type="ovf:NetworkSection_Type"> … … 730 749 if (m->virtualSystemDescriptions.size() > 1) 731 750 { 732 if (enFormat == OVF_0_9)751 if (enFormat == ovf::OVFVersion_0_9) 733 752 throw setError(VBOX_E_FILE_ERROR, 734 753 tr("Cannot export more than one virtual system with OVF 0.9, use OVF 1.0")); … … 845 864 pelmDisk->setAttribute("ovf:fileRef", strFileRef); 846 865 pelmDisk->setAttribute("ovf:format", 847 (enFormat == OVF_0_9)866 (enFormat == ovf::OVFVersion_0_9) 848 867 ? "http://www.vmware.com/specifications/vmdk.html#sparse" // must be sparse or ovftool chokes 849 868 : "http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized" … … 892 911 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes, 893 912 ComObjPtr<VirtualSystemDescription> &vsdescThis, 894 OVFFormatenFormat,913 ovf::OVFVersion_T enFormat, 895 914 XMLStack &stack) 896 915 { … … 898 917 899 918 xml::ElementNode *pelmVirtualSystem; 900 if (enFormat == OVF_0_9)919 if (enFormat == ovf::OVFVersion_0_9) 901 920 { 902 921 // <Section xsi:type="ovf:NetworkSection_Type"> … … 942 961 </Section> */ 943 962 xml::ElementNode *pelmAnnotationSection; 944 if (enFormat == OVF_0_9)963 if (enFormat == ovf::OVFVersion_0_9) 945 964 { 946 965 // <Section ovf:required="false" xsi:type="ovf:ProductSection_Type"> … … 974 993 </Section> */ 975 994 xml::ElementNode *pelmAnnotationSection; 976 if (enFormat == OVF_0_9)995 if (enFormat == ovf::OVFVersion_0_9) 977 996 { 978 997 // <Section ovf:required="false" xsi:type="ovf:AnnotationSection_Type"> … … 997 1016 </EulaSection> */ 998 1017 xml::ElementNode *pelmEulaSection; 999 if (enFormat == OVF_0_9)1018 if (enFormat == ovf::OVFVersion_0_9) 1000 1019 { 1001 1020 pelmEulaSection = pelmVirtualSystem->createChild("Section"); … … 1020 1039 VirtualSystemDescriptionEntry *pvsdeOS = llOS.front(); 1021 1040 xml::ElementNode *pelmOperatingSystemSection; 1022 if (enFormat == OVF_0_9)1041 if (enFormat == ovf::OVFVersion_0_9) 1023 1042 { 1024 1043 pelmOperatingSystemSection = pelmVirtualSystem->createChild("Section"); … … 1040 1059 // <VirtualHardwareSection ovf:id="hw1" ovf:transport="iso"> 1041 1060 xml::ElementNode *pelmVirtualHardwareSection; 1042 if (enFormat == OVF_0_9)1061 if (enFormat == ovf::OVFVersion_0_9) 1043 1062 { 1044 1063 // <Section xsi:type="ovf:VirtualHardwareSection_Type"> … … 1063 1082 1064 1083 // <vssd:InstanceId>0</vssd:InstanceId> 1065 if (enFormat == OVF_0_9)1084 if (enFormat == ovf::OVFVersion_0_9) 1066 1085 pelmSystem->createChild("vssd:InstanceId")->addContent("0"); 1067 1086 else // capitalization changed... … … 1072 1091 // <vssd:VirtualSystemType>vmx-4</vssd:VirtualSystemType> 1073 1092 const char *pcszHardware = "virtualbox-2.2"; 1074 if (enFormat == OVF_0_9)1093 if (enFormat == ovf::OVFVersion_0_9) 1075 1094 // pretend to be vmware compatible then 1076 1095 pcszHardware = "vmx-6"; … … 1499 1518 1500 1519 if (lBusNumber != -1) 1501 if (enFormat == OVF_0_9) // BusNumber is invalid OVF 1.0 so only write it in 0.9 mode for OVFTool compatibility1520 if (enFormat == ovf::OVFVersion_0_9) // BusNumber is invalid OVF 1.0 so only write it in 0.9 mode for OVFTool y 1502 1521 pItem->createChild("rasd:BusNumber")->addContent(Utf8StrFmt("%d", lBusNumber)); 1503 1522 … … 1512 1531 1513 1532 if (!strCaption.isEmpty()) 1514 if (enFormat == OVF_1_0)1533 if (enFormat == ovf::OVFVersion_1_0) 1515 1534 pItem->createChild("rasd:ElementName")->addContent(strCaption); 1516 1535 … … 1520 1539 // <rasd:InstanceID>1</rasd:InstanceID> 1521 1540 xml::ElementNode *pelmInstanceID; 1522 if (enFormat == OVF_0_9)1541 if (enFormat == ovf::OVFVersion_0_9) 1523 1542 pelmInstanceID = pItem->createChild("rasd:InstanceId"); 1524 1543 else -
trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
r45068 r45227 819 819 820 820 HRESULT rc = S_OK; 821 int vrc = VINF_SUCCESS; 821 822 822 823 PVDINTERFACEIO pShaIo = 0; … … 824 825 do 825 826 { 826 pShaIo = ShaCreateInterface(); 827 if (!pShaIo) 827 try 828 828 { 829 rc = E_OUTOFMEMORY; 830 break; 829 /* Create the necessary file access interfaces. */ 830 pFileIo = FileCreateInterface(); 831 if (!pFileIo) 832 { 833 rc = E_OUTOFMEMORY; 834 break; 835 } 836 837 Utf8Str strMfFile = Utf8Str(pTask->locInfo.strPath).stripExt().append(".mf"); 838 839 if (RTFileExists(strMfFile.c_str())) 840 { 841 SHASTORAGE storage; 842 RT_ZERO(storage); 843 844 pShaIo = ShaCreateInterface(); 845 if (!pShaIo) 846 { 847 rc = E_OUTOFMEMORY; 848 break; 849 } 850 851 //read the manifest file and find a type of used digest 852 RTFILE pFile = NULL; 853 RTFileOpen(&pFile, strMfFile.c_str(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE); 854 if(RT_SUCCESS(vrc) && pFile != NULL) 855 { 856 uint64_t size = 0; 857 uint64_t readed = 0; 858 void *pBuf; 859 860 vrc = RTFileGetSize(pFile, &size); 861 if(RT_SUCCESS(vrc) && size > 0) 862 pBuf = RTMemAllocZ(size); 863 else 864 throw vrc; 865 866 vrc = RTFileRead(pFile, pBuf, size, &readed); 867 868 if (RT_FAILURE(vrc)) 869 { 870 if (pBuf) 871 RTMemFree(pBuf); 872 throw setError(VBOX_E_FILE_ERROR, 873 tr("Could not read manifest file '%s' (%Rrc)"), 874 RTPathFilename(strMfFile.c_str()), vrc); 875 } 876 877 RTDIGESTTYPE digestType = RTDIGESTTYPE_UNKNOWN; 878 vrc = RTManifestVerifyDigestType(pBuf, readed, digestType); 879 880 if (RT_FAILURE(vrc)) 881 { 882 if (pBuf) 883 RTMemFree(pBuf); 884 throw setError(VBOX_E_FILE_ERROR, 885 tr("Could not verify supported digest types in the manifest file '%s' (%Rrc)"), 886 RTPathFilename(strMfFile.c_str()), vrc); 887 } 888 889 storage.fCreateDigest = true; 890 891 if (digestType == RTDIGESTTYPE_SHA256) 892 { 893 storage.fSha256 = true; 894 } 895 else 896 { 897 storage.fSha256 = false; 898 } 899 } 900 901 /////////////////////////////////////////// 902 903 vrc = VDInterfaceAdd(&pFileIo->Core, "Appliance::IOFile", 904 VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO), 905 &storage.pVDImageIfaces); 906 if (RT_FAILURE(vrc)) 907 rc = setError(VBOX_E_IPRT_ERROR, "Creation of the VD interface failed (%Rrc)", vrc); 908 909 storage.fCreateDigest = true; 910 911 rc = readFSImpl(pTask, pTask->locInfo.strPath, pShaIo, &storage); 912 } 913 else 914 rc = readFSImpl(pTask, pTask->locInfo.strPath, pFileIo, NULL); 831 915 } 832 pFileIo = FileCreateInterface(); 833 if (!pFileIo) 916 catch (HRESULT rc2) 834 917 { 835 rc = E_OUTOFMEMORY; 836 break; 918 rc = rc2; 837 919 } 838 SHASTORAGE storage; 839 RT_ZERO(storage); 840 int vrc = VDInterfaceAdd(&pFileIo->Core, "Appliance::IOFile", 841 VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO), 842 &storage.pVDImageIfaces); 843 if (RT_FAILURE(vrc)) 920 catch (int rc2) 844 921 { 845 rc = setError(VBOX_E_IPRT_ERROR, "Creation of the VD interface failed (%Rrc)", vrc); 846 break; 922 rc = rc2; 847 923 } 848 924 849 rc = readFSImpl(pTask, pTask->locInfo.strPath, pShaIo, &storage);850 925 }while(0); 851 926 … … 2837 2912 // if pReader != NULL 2838 2913 const ovf::OVFReader &reader = *m->pReader; 2914 const ovf::OVFVersion_T ovfVersion = reader.m_envelopeData.getOVFVersion(); 2915 2916 if ( ovfVersion == ovf::OVFVersion_2_0) 2917 pStorage->fSha256 = true; 2839 2918 2840 2919 // create a session for the machine + disks we manipulate below -
trunk/src/VBox/Main/xml/ovfreader.cpp
r44528 r45227 65 65 { 66 66 const xml::ElementNode *pRootElem = m_doc.getRootElement(); 67 const xml::AttributeNode *pTypeAttr; 68 const char *pcszTypeAttr = ""; 69 67 70 if ( !pRootElem 68 71 || strcmp(pRootElem->getName(), "Envelope") 69 72 ) 70 73 throw OVFLogicError(N_("Root element in OVF file must be \"Envelope\".")); 74 75 if ((pTypeAttr = pRootElem->findAttribute("version"))) 76 { 77 pcszTypeAttr = pTypeAttr->getValue(); 78 m_envelopeData.version = pcszTypeAttr; 79 } 80 else 81 { 82 // throw OVFLogicError(N_("Error reading \"%s\": missing or invalid attribute '%s' in 'Envelope' element, line %d"), 83 // m_strPath.c_str(), 84 // "version", 85 // pRootElem->getLineNumber()); 86 } 87 88 if ((pTypeAttr = pRootElem->findAttribute("xml:lang"))) 89 { 90 pcszTypeAttr = pTypeAttr->getValue(); 91 m_envelopeData.lang = pcszTypeAttr; 92 } 71 93 72 94 // OVF has the following rough layout:
Note:
See TracChangeset
for help on using the changeset viewer.