VirtualBox

Changeset 46518 in vbox for trunk/src/VBox/Main/xml


Ignore:
Timestamp:
Jun 13, 2013 10:07:09 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86374
Message:

Export/import OVA/OVF package supports ISO images. The problem with the wrong search files in the archive has been resolved. (see #5429). 2 new elements SASD and EPASD were added in the OVF XML file structure (see #6022).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/xml/ovfreader.cpp

    r46169 r46518  
    9191    }
    9292
    93 //    if ((pTypeAttr = pRootElem->findAttribute("version")))
    94 //    {
    95 //        pcszTypeAttr = pTypeAttr->getValue();
    96 //        m_envelopeData.version = pcszTypeAttr;
    97 //    }
    98 //    else
    99 //    {
    100 //        throw OVFLogicError(N_("Error reading \"%s\": missing or invalid attribute '%s' in 'Envelope' element, line %d"),
    101 //                           m_strPath.c_str(),
    102 //                            "version",
    103 //                            pRootElem->getLineNumber());
    104 //    }
    105 
    10693    if ((pTypeAttr = pRootElem->findAttribute("xml:lang")))
    10794    {
     
    255242                   )
    256243                {
     244
    257245                    // copy remaining values from file node then
    258246                    const char *pcszBadInFile = NULL;
     
    432420            }
    433421
    434             xml::NodesLoop loopVirtualHardwareItems(*pelmThis, "Item");      // all "Item" child elements
    435             const xml::ElementNode *pelmItem;
    436             while ((pelmItem = loopVirtualHardwareItems.forAllNodes()))
    437422            {
    438                 VirtualHardwareItem i;
    439 
    440                 i.ulLineNumber = pelmItem->getLineNumber();
    441 
    442                 xml::NodesLoop loopItemChildren(*pelmItem);      // all child elements
    443                 const xml::ElementNode *pelmItemChild;
    444                 while ((pelmItemChild = loopItemChildren.forAllNodes()))
     423                xml::NodesLoop loopVirtualHardwareItems(*pelmThis, "Item");      // all "Item" child elements
     424                const xml::ElementNode *pelmItem;
     425                while ((pelmItem = loopVirtualHardwareItems.forAllNodes()))
    445426                {
    446                     const char *pcszItemChildName = pelmItemChild->getName();
    447                     if (!strcmp(pcszItemChildName, "Description"))
    448                         i.strDescription = pelmItemChild->getValue();
    449                     else if (!strcmp(pcszItemChildName, "Caption"))
    450                         i.strCaption = pelmItemChild->getValue();
    451                     else if (!strcmp(pcszItemChildName, "ElementName"))
    452                         i.strElementName = pelmItemChild->getValue();
    453                     else if (    (!strcmp(pcszItemChildName, "InstanceID"))
    454                               || (!strcmp(pcszItemChildName, "InstanceId"))
    455                             )
    456                         pelmItemChild->copyValue(i.ulInstanceID);
    457                     else if (!strcmp(pcszItemChildName, "HostResource"))
    458                         i.strHostResource = pelmItemChild->getValue();
    459                     else if (!strcmp(pcszItemChildName, "ResourceType"))
     427                    VirtualHardwareItem i;
     428
     429                    i.ulLineNumber = pelmItem->getLineNumber();
     430                    i.fillItem(pelmItem);
     431                    try{
     432                        i.checkConsistencyAndCompliance();
     433                    }
     434                    catch (OVFLogicError &e)
    460435                    {
    461                         uint32_t ulType;
    462                         pelmItemChild->copyValue(ulType);
    463                         i.resourceType = (ResourceType_T)ulType;
    464                         i.fResourceRequired = true;
    465                         const char *pcszAttValue;
    466                         if (pelmItem->getAttributeValue("required", pcszAttValue))
    467                         {
    468                             if (!strcmp(pcszAttValue, "false"))
    469                                 i.fResourceRequired = false;
    470                         }
    471                     }
    472                     else if (!strcmp(pcszItemChildName, "OtherResourceType"))
    473                         i.strOtherResourceType = pelmItemChild->getValue();
    474                     else if (!strcmp(pcszItemChildName, "ResourceSubType"))
    475                         i.strResourceSubType = pelmItemChild->getValue();
    476                     else if (!strcmp(pcszItemChildName, "AutomaticAllocation"))
    477                         i.fAutomaticAllocation = (!strcmp(pelmItemChild->getValue(), "true")) ? true : false;
    478                     else if (!strcmp(pcszItemChildName, "AutomaticDeallocation"))
    479                         i.fAutomaticDeallocation = (!strcmp(pelmItemChild->getValue(), "true")) ? true : false;
    480                     else if (!strcmp(pcszItemChildName, "Parent"))
    481                         pelmItemChild->copyValue(i.ulParent);
    482                     else if (!strcmp(pcszItemChildName, "Connection"))
    483                         i.strConnection = pelmItemChild->getValue();
    484                     else if (!strcmp(pcszItemChildName, "Address"))
     436                        throw OVFLogicError(N_("Error reading \"%s\": \"%s\""),
     437                                            m_strPath.c_str(),
     438                                            e.what());
     439                    }
     440
     441                    // store!
     442                    vsys.mapHardwareItems[i.ulInstanceID] = i;
     443                }
     444            }
     445
     446            {
     447                xml::NodesLoop loopVirtualHardwareItems(*pelmThis, "StorageItem");// all "StorageItem" child elements
     448                const xml::ElementNode *pelmItem;
     449                while ((pelmItem = loopVirtualHardwareItems.forAllNodes()))
     450                {
     451                    StorageItem i;
     452
     453                    i.ulLineNumber = pelmItem->getLineNumber();
     454                    i.fillItem(pelmItem);
     455
     456                    try
    485457                    {
    486                         i.strAddress = pelmItemChild->getValue();
    487                         pelmItemChild->copyValue(i.lAddress);
    488                     }
    489                     else if (!strcmp(pcszItemChildName, "AddressOnParent"))
    490                         i.strAddressOnParent = pelmItemChild->getValue();
    491                     else if (!strcmp(pcszItemChildName, "AllocationUnits"))
    492                         i.strAllocationUnits = pelmItemChild->getValue();
    493                     else if (!strcmp(pcszItemChildName, "VirtualQuantity"))
    494                         pelmItemChild->copyValue(i.ullVirtualQuantity);
    495                     else if (!strcmp(pcszItemChildName, "Reservation"))
    496                         pelmItemChild->copyValue(i.ullReservation);
    497                     else if (!strcmp(pcszItemChildName, "Limit"))
    498                         pelmItemChild->copyValue(i.ullLimit);
    499                     else if (!strcmp(pcszItemChildName, "Weight"))
    500                         pelmItemChild->copyValue(i.ullWeight);
    501                     else if (!strcmp(pcszItemChildName, "ConsumerVisibility"))
    502                         i.strConsumerVisibility = pelmItemChild->getValue();
    503                     else if (!strcmp(pcszItemChildName, "MappingBehavior"))
    504                         i.strMappingBehavior = pelmItemChild->getValue();
    505                     else if (!strcmp(pcszItemChildName, "PoolID"))
    506                         i.strPoolID = pelmItemChild->getValue();
    507                     else if (!strcmp(pcszItemChildName, "BusNumber"))       // seen in some old OVF, but it's not listed in the OVF specs
    508                         pelmItemChild->copyValue(i.ulBusNumber);
    509                     else if (   pelmItemChild->getPrefix() == NULL
    510                              || strcmp(pelmItemChild->getPrefix(), "vmw"))
    511                         throw OVFLogicError(N_("Error reading \"%s\": unknown element \"%s\" under Item element, line %d"),
     458                        i.checkConsistencyAndCompliance();
     459                    }
     460                    catch (OVFLogicError &e)
     461                    {
     462                        throw OVFLogicError(N_("Error reading \"%s\": \"%s\""),
    512463                                            m_strPath.c_str(),
    513                                             pcszItemChildName,
    514                                             i.ulLineNumber);
     464                                            e.what());
     465                    }
     466
     467                    vsys.mapHardwareItems[i.ulInstanceID] = i;
    515468                }
    516 
    517                 // store!
    518                 vsys.mapHardwareItems[i.ulInstanceID] = i;
    519469            }
    520470
    521             HardDiskController *pPrimaryIDEController = NULL;       // will be set once found
     471            {
     472                xml::NodesLoop loopVirtualHardwareItems(*pelmThis, "EthernetPortItem");// all "EthernetPortItem" child elements
     473                const xml::ElementNode *pelmItem;
     474                while ((pelmItem = loopVirtualHardwareItems.forAllNodes()))
     475                {
     476                    EthernetPortItem i;
     477
     478                    i.ulLineNumber = pelmItem->getLineNumber();
     479                    i.fillItem(pelmItem);
     480
     481                    try{
     482                        i.checkConsistencyAndCompliance();
     483                    }
     484                    catch (OVFLogicError &e)
     485                    {
     486                        throw OVFLogicError(N_("Error reading \"%s\": \"%s\""),
     487                                            m_strPath.c_str(),
     488                                            e.what());
     489                    }
     490
     491                    vsys.mapHardwareItems[i.ulInstanceID] = i;
     492                }
     493            }
     494
     495            HardDiskController *pPrimaryIDEController = NULL;// will be set once found
    522496
    523497            // now go thru all hardware items and handle them according to their type;
     
    857831}
    858832
     833void VirtualHardwareItem::fillItem(const xml::ElementNode *item)
     834{
     835    xml::NodesLoop loopItemChildren(*item);// all child elements
     836    const xml::ElementNode *pelmItemChild;
     837    while ((pelmItemChild = loopItemChildren.forAllNodes()))
     838    {
     839        const char *pcszItemChildName = pelmItemChild->getName();
     840        if (!strcmp(pcszItemChildName, "Description"))
     841            strDescription = pelmItemChild->getValue();
     842        else if (!strcmp(pcszItemChildName, "Caption"))
     843            strCaption = pelmItemChild->getValue();
     844        else if (!strcmp(pcszItemChildName, "ElementName"))
     845            strElementName = pelmItemChild->getValue();
     846        else if ((!strcmp(pcszItemChildName, "InstanceID"))
     847                 ||(!strcmp(pcszItemChildName, "InstanceId"))
     848                )
     849            pelmItemChild->copyValue(ulInstanceID);
     850        else if (!strcmp(pcszItemChildName, "HostResource"))
     851            strHostResource = pelmItemChild->getValue();
     852        else if (!strcmp(pcszItemChildName, "ResourceType"))
     853        {
     854            uint32_t ulType;
     855            pelmItemChild->copyValue(ulType);
     856            resourceType = (ResourceType_T)ulType;
     857            fResourceRequired = true;
     858            const char *pcszAttValue;
     859            if (pelmItemChild->getAttributeValue("required", pcszAttValue))
     860            {
     861                if (!strcmp(pcszAttValue, "false"))
     862                    fResourceRequired = false;
     863            }
     864        }
     865        else if (!strcmp(pcszItemChildName, "OtherResourceType"))
     866            strOtherResourceType = pelmItemChild->getValue();
     867        else if (!strcmp(pcszItemChildName, "ResourceSubType"))
     868            strResourceSubType = pelmItemChild->getValue();
     869        else if (!strcmp(pcszItemChildName, "AutomaticAllocation"))
     870            fAutomaticAllocation = (!strcmp(pelmItemChild->getValue(), "true")) ? true : false;
     871        else if (!strcmp(pcszItemChildName, "AutomaticDeallocation"))
     872            fAutomaticDeallocation = (!strcmp(pelmItemChild->getValue(), "true")) ? true : false;
     873        else if (!strcmp(pcszItemChildName, "Parent"))
     874            pelmItemChild->copyValue(ulParent);
     875        else if (!strcmp(pcszItemChildName, "Connection"))
     876            strConnection = pelmItemChild->getValue();
     877        else if (!strcmp(pcszItemChildName, "Address"))
     878        {
     879            strAddress = pelmItemChild->getValue();
     880            pelmItemChild->copyValue(lAddress);
     881        }
     882        else if (!strcmp(pcszItemChildName, "AddressOnParent"))
     883            strAddressOnParent = pelmItemChild->getValue();
     884        else if (!strcmp(pcszItemChildName, "AllocationUnits"))
     885            strAllocationUnits = pelmItemChild->getValue();
     886        else if (!strcmp(pcszItemChildName, "VirtualQuantity"))
     887            pelmItemChild->copyValue(ullVirtualQuantity);
     888        else if (!strcmp(pcszItemChildName, "Reservation"))
     889            pelmItemChild->copyValue(ullReservation);
     890        else if (!strcmp(pcszItemChildName, "Limit"))
     891            pelmItemChild->copyValue(ullLimit);
     892        else if (!strcmp(pcszItemChildName, "Weight"))
     893            pelmItemChild->copyValue(ullWeight);
     894        else if (!strcmp(pcszItemChildName, "ConsumerVisibility"))
     895            strConsumerVisibility = pelmItemChild->getValue();
     896        else if (!strcmp(pcszItemChildName, "MappingBehavior"))
     897            strMappingBehavior = pelmItemChild->getValue();
     898        else if (!strcmp(pcszItemChildName, "PoolID"))
     899            strPoolID = pelmItemChild->getValue();
     900        else if (!strcmp(pcszItemChildName, "BusNumber"))
     901            pelmItemChild->copyValue(ulBusNumber);
     902//      else if (pelmItemChild->getPrefix() == NULL
     903//               || strcmp(pelmItemChild->getPrefix(), "vmw"))
     904//          throw OVFLogicError(N_("Unknown element \"%s\" under Item element, line %d"),
     905//                              pcszItemChildName,
     906//                              ulLineNumber);
     907    }
     908}
     909
     910void VirtualHardwareItem::_checkConsistencyAndCompliance() throw (OVFLogicError)
     911{
     912    RTCString name = getItemName();
     913    if (ulInstanceID == 0)
     914        throw OVFLogicError(N_("Element InstanceID is absent under %s element, line %d. "
     915                               "see DMTF Schema Documentation %s"),
     916                name.c_str(), ulLineNumber, DTMF_SPECS_URI);
     917    if (resourceType == 0)
     918        throw OVFLogicError(N_("Empty element ResourceType under %s element, line %d. "
     919                               "see DMTF Schema Documentation %s"),
     920                name.c_str(), ulLineNumber, DTMF_SPECS_URI);
     921}
     922
     923void StorageItem::fillItem(const xml::ElementNode *item)
     924{
     925    VirtualHardwareItem::fillItem(item);
     926
     927    xml::NodesLoop loopItemChildren(*item);// all child elements
     928    const xml::ElementNode *pelmItemChild;
     929    while ((pelmItemChild = loopItemChildren.forAllNodes()))
     930    {
     931        const char *pcszItemChildName = pelmItemChild->getName();
     932        if (!strcmp(pcszItemChildName, "HostExtentName"))
     933            strHostExtentName = pelmItemChild->getValue();
     934        else if (!strcmp(pcszItemChildName, "OtherHostExtentNameFormat"))
     935            strOtherHostExtentNameFormat = pelmItemChild->getValue();
     936        else if (!strcmp(pcszItemChildName, "OtherHostExtentNameNamespace"))
     937            strOtherHostExtentNameNamespace = pelmItemChild->getValue();
     938        else if (!strcmp(pcszItemChildName, "VirtualQuantityUnits"))
     939            strVirtualQuantityUnits = pelmItemChild->getValue();
     940        else if (!strcmp(pcszItemChildName, "Access"))
     941        {
     942            uint32_t temp;
     943            pelmItemChild->copyValue(temp);
     944            accessType = (StorageAccessType_T)temp;
     945        }
     946        else if (!strcmp(pcszItemChildName, "HostExtentNameFormat"))
     947        {
     948        }
     949        else if (!strcmp(pcszItemChildName, "HostExtentNameNamespace"))
     950        {
     951        }
     952        else if (!strcmp(pcszItemChildName, "HostExtentStartingAddress"))
     953        {
     954        }
     955        else if (!strcmp(pcszItemChildName, "HostResourceBlockSize"))
     956        {
     957            int64_t temp;
     958            pelmItemChild->copyValue(temp);
     959            hostResourceBlockSize = temp;
     960        }
     961        else if (!strcmp(pcszItemChildName, "Limit"))
     962        {
     963            int64_t temp;
     964            pelmItemChild->copyValue(temp);
     965            limit = temp;
     966        }
     967        else if (!strcmp(pcszItemChildName, "Reservation"))
     968        {
     969            int64_t temp;
     970            pelmItemChild->copyValue(temp);
     971            reservation = temp;
     972        }
     973        else if (!strcmp(pcszItemChildName, "VirtualQuantity"))
     974        {
     975            int64_t temp;
     976            pelmItemChild->copyValue(temp);
     977            virtualQuantity = temp;
     978        }
     979        else if (!strcmp(pcszItemChildName, "VirtualResourceBlockSize"))
     980        {
     981            int64_t temp;
     982            pelmItemChild->copyValue(temp);
     983            virtualResourceBlockSize = temp;
     984        }
     985    }
     986}
     987
     988
     989void StorageItem::_checkConsistencyAndCompliance() throw (OVFLogicError)
     990{
     991    VirtualHardwareItem::_checkConsistencyAndCompliance();
     992
     993    RTCString name = getItemName();
     994
     995    if (accessType == StorageAccessType_Unknown)
     996    {
     997        //throw OVFLogicError(N_("Access type is unknown under %s element, line %d"),
     998        //        name.c_str(), ulLineNumber);
     999    }
     1000
     1001    if (hostResourceBlockSize <= 0 && reservation > 0)
     1002    {
     1003        throw OVFLogicError(N_("Element HostResourceBlockSize is absent under %s element, line %d. "
     1004                               "see DMTF Schema Documentation %s"),
     1005                name.c_str(), ulLineNumber, DTMF_SPECS_URI);
     1006    }
     1007
     1008    if (virtualResourceBlockSize <= 0 && virtualQuantity > 0)
     1009    {
     1010        throw OVFLogicError(N_("Element VirtualResourceBlockSize is absent under %s element, line %d. "
     1011                               "see DMTF Schema Documentation %s"),
     1012                name.c_str(), ulLineNumber, DTMF_SPECS_URI);
     1013    }
     1014
     1015    if (virtualQuantity > 0 && strVirtualQuantityUnits.isEmpty())
     1016    {
     1017        throw OVFLogicError(N_("Element VirtualQuantityUnits is absent under %s element, line %d. "
     1018                               "see DMTF Schema Documentation %s"),
     1019                name.c_str(), ulLineNumber, DTMF_SPECS_URI);
     1020    }
     1021
     1022    if (virtualResourceBlockSize <= 1 &&
     1023        strVirtualQuantityUnits.compare(RTCString("count"), RTCString::CaseInsensitive) == 0
     1024       )
     1025    {
     1026        throw OVFLogicError(N_("Element VirtualQuantityUnits is set to \"count\" "
     1027                               "while VirtualResourceBlockSize is set to 1. "
     1028                               "under %s element, line %d. "
     1029                               "It's needed to change on \"byte\". "
     1030                               "see DMTF Schema Documentation %s"),
     1031                                name.c_str(), ulLineNumber, DTMF_SPECS_URI);
     1032    }
     1033}
     1034
     1035void EthernetPortItem::fillItem(const xml::ElementNode *item)
     1036{
     1037    VirtualHardwareItem::fillItem(item);
     1038
     1039    xml::NodesLoop loopItemChildren(*item);// all child elements
     1040    const xml::ElementNode *pelmItemChild;
     1041    while ((pelmItemChild = loopItemChildren.forAllNodes()))
     1042    {
     1043    }
     1044}
     1045
     1046void EthernetPortItem::_checkConsistencyAndCompliance() throw (OVFLogicError)
     1047{
     1048    VirtualHardwareItem::_checkConsistencyAndCompliance();
     1049}
     1050
    8591051////////////////////////////////////////////////////////////////////////////////
    8601052//
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette