Changeset 79677 in vbox for trunk/src/VBox
- Timestamp:
- Jul 10, 2019 3:45:05 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 131994
- Location:
- trunk/src/VBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-all/ExtPackUtil.cpp
r76553 r79677 113 113 114 114 RTCString strFormatVersion; 115 if (!pVBoxExtPackElm->getAttributeValue ("version", strFormatVersion))115 if (!pVBoxExtPackElm->getAttributeValueN("version", strFormatVersion, RT_XML_ATTR_TINY)) 116 116 return new RTCString("Missing format version"); 117 117 if (!strFormatVersion.equals("1.0")) … … 124 124 if (!pNameElm) 125 125 return new RTCString("The 'Name' element is missing"); 126 const char *pszName = pNameElm->getValue ();126 const char *pszName = pNameElm->getValueN(RT_XML_CONTENT_SMALL); 127 127 if (!VBoxExtPackIsValidName(pszName)) 128 128 return &(new RTCString("Invalid name: "))->append(pszName); … … 131 131 if (!pDescElm) 132 132 return new RTCString("The 'Description' element is missing"); 133 const char *pszDesc = pDescElm->getValue ();133 const char *pszDesc = pDescElm->getValueN(RT_XML_CONTENT_LARGE); 134 134 if (!pszDesc || *pszDesc == '\0') 135 135 return new RTCString("The 'Description' element is empty"); … … 140 140 if (!pVersionElm) 141 141 return new RTCString("The 'Version' element is missing"); 142 const char *pszVersion = pVersionElm->getValue ();142 const char *pszVersion = pVersionElm->getValueN(RT_XML_CONTENT_SMALL); 143 143 if (!pszVersion || *pszVersion == '\0') 144 144 return new RTCString("The 'Version' element is empty"); … … 151 151 152 152 const char *pszEdition; 153 if (!pVersionElm->getAttributeValue ("edition", pszEdition))153 if (!pVersionElm->getAttributeValueN("edition", pszEdition, RT_XML_ATTR_TINY)) 154 154 pszEdition = ""; 155 155 if (!VBoxExtPackIsValidEditionString(pszEdition)) … … 159 159 if (!pMainModuleElm) 160 160 return new RTCString("The 'MainModule' element is missing"); 161 const char *pszMainModule = pMainModuleElm->getValue ();161 const char *pszMainModule = pMainModuleElm->getValueN(RT_XML_CONTENT_SMALL); 162 162 if (!pszMainModule || *pszMainModule == '\0') 163 163 return new RTCString("The 'MainModule' element is empty"); … … 173 173 if (pMainVMModuleElm) 174 174 { 175 pszMainVMModule = pMainVMModuleElm->getValue ();175 pszMainVMModule = pMainVMModuleElm->getValueN(RT_XML_CONTENT_SMALL); 176 176 if (!pszMainVMModule || *pszMainVMModule == '\0') 177 177 pszMainVMModule = NULL; … … 188 188 if (pVrdeModuleElm) 189 189 { 190 pszVrdeModule = pVrdeModuleElm->getValue ();190 pszVrdeModule = pVrdeModuleElm->getValueN(RT_XML_CONTENT_SMALL); 191 191 if (!pszVrdeModule || *pszVrdeModule == '\0') 192 192 pszVrdeModule = NULL; … … 282 282 * Hand the xml doc over to the common code. 283 283 */ 284 return vboxExtPackLoadDescFromDoc(&Doc, a_pExtPackDesc); 284 try 285 { 286 return vboxExtPackLoadDescFromDoc(&Doc, a_pExtPackDesc); 287 } 288 catch (RTCError &rXcpt) // includes all XML exceptions 289 { 290 return new RTCString(rXcpt.what()); 291 } 285 292 } 286 293 … … 358 365 */ 359 366 if (RT_SUCCESS(rc)) 360 pstrErr = vboxExtPackLoadDescFromDoc(&Doc, a_pExtPackDesc); 367 try 368 { 369 pstrErr = vboxExtPackLoadDescFromDoc(&Doc, a_pExtPackDesc); 370 } 371 catch (RTCError &rXcpt) // includes all XML exceptions 372 { 373 return new RTCString(rXcpt.what()); 374 } 361 375 362 376 return pstrErr; -
trunk/src/VBox/Main/xml/ovfreader.cpp
r78604 r79677 107 107 if ((pTypeAttr = pRootElem->findAttribute("lang", "xml"))) 108 108 { 109 pcszTypeAttr = pTypeAttr->getValue ();109 pcszTypeAttr = pTypeAttr->getValueN(RT_XML_ATTR_TINY); 110 110 m_envelopeData.lang = pcszTypeAttr; 111 111 } … … 148 148 const char *pcszElemName = pElem->getName(); 149 149 const xml::AttributeNode *pTypeAttr = pElem->findAttribute("type"); 150 const char *pcszTypeAttr = pTypeAttr ? pTypeAttr->getValue () : "";150 const char *pcszTypeAttr = pTypeAttr ? pTypeAttr->getValueN(RT_XML_ATTR_TINY) : ""; 151 151 152 152 if ( !strcmp(pcszElemName, "DiskSection") … … 226 226 const char *pcszDiskId; 227 227 const char *pcszFormat; 228 if (!pelmDisk->getAttributeValue ("diskId", pcszDiskId))228 if (!pelmDisk->getAttributeValueN("diskId", pcszDiskId, RT_XML_ATTR_TINY)) 229 229 pcszBad = "diskId"; 230 else if (!pelmDisk->getAttributeValue ("format", pcszFormat))230 else if (!pelmDisk->getAttributeValueN("format", pcszFormat, RT_XML_ATTR_SMALL)) 231 231 pcszBad = "format"; 232 232 else if (!pelmDisk->getAttributeValue("capacity", d.iCapacity)) … … 242 242 243 243 // optional vbox:uuid attribute (if OVF was exported by VirtualBox != 3.2) 244 pelmDisk->getAttributeValue ("uuid", d.uuidVBox, "vbox");244 pelmDisk->getAttributeValueN("uuid", d.uuidVBox, RT_XML_ATTR_TINY, "vbox"); 245 245 246 246 const char *pcszFileRef; 247 if (pelmDisk->getAttributeValue ("fileRef", pcszFileRef)) // optional247 if (pelmDisk->getAttributeValueN("fileRef", pcszFileRef, RT_XML_ATTR_SMALL)) // optional 248 248 { 249 249 // look up corresponding /References/File nodes (list built above) … … 257 257 const char *pcszBadInFile = NULL; 258 258 const char *pcszHref; 259 if (!pFileElem->getAttributeValue ("href", pcszHref))259 if (!pFileElem->getAttributeValueN("href", pcszHref, RT_XML_ATTR_SMALL)) 260 260 pcszBadInFile = "href"; 261 261 else if (!pFileElem->getAttributeValue("size", d.iSize)) … … 267 267 d.iChunkSize = -1; // optional 268 268 const char *pcszCompression; 269 if (pFileElem->getAttributeValue ("compression", pcszCompression))269 if (pFileElem->getAttributeValueN("compression", pcszCompression, RT_XML_ATTR_TINY)) 270 270 d.strCompression = pcszCompression; 271 271 … … 350 350 const xml::AttributeNode *pIdAttr = pelmVirtualSystem->findAttribute("id"); 351 351 if (pIdAttr) 352 vsys.strName = pIdAttr->getValue ();352 vsys.strName = pIdAttr->getValueN(RT_XML_ATTR_SMALL); 353 353 354 354 xml::NodesLoop loop(*pelmVirtualSystem); // all child elements … … 362 362 const xml::AttributeNode *pTypeAttr = pelmThis->findAttribute("type"); 363 363 if (pTypeAttr) 364 pcszTypeAttr = pTypeAttr->getValue ();364 pcszTypeAttr = pTypeAttr->getValueN(RT_XML_ATTR_TINY); 365 365 else 366 366 throw OVFLogicError(N_("Error reading \"%s\": element \"Section\" has no \"type\" attribute, line %d"), … … 380 380 const xml::ElementNode *pelmLicense; 381 381 if ((pelmLicense = pelmThis->findChildElement("License"))) 382 vsys.strLicenseText = pelmLicense->getValue ();382 vsys.strLicenseText = pelmLicense->getValueN(RT_XML_CONTENT_LARGE); 383 383 } 384 384 if ( !strcmp(pcszElemName, "ProductSection") … … 396 396 const xml::ElementNode *pelmProduct; 397 397 if ((pelmProduct = pelmThis->findChildElement("Product"))) 398 vsys.strProduct = pelmProduct->getValue ();398 vsys.strProduct = pelmProduct->getValueN(RT_XML_CONTENT_SMALL); 399 399 const xml::ElementNode *pelmVendor; 400 400 if ((pelmVendor = pelmThis->findChildElement("Vendor"))) 401 vsys.strVendor = pelmVendor->getValue ();401 vsys.strVendor = pelmVendor->getValueN(RT_XML_CONTENT_SMALL); 402 402 const xml::ElementNode *pelmVersion; 403 403 if ((pelmVersion = pelmThis->findChildElement("Version"))) 404 vsys.strVersion = pelmVersion->getValue ();404 vsys.strVersion = pelmVersion->getValueN(RT_XML_CONTENT_SMALL); 405 405 const xml::ElementNode *pelmProductUrl; 406 406 if ((pelmProductUrl = pelmThis->findChildElement("ProductUrl"))) 407 vsys.strProductUrl = pelmProductUrl->getValue ();407 vsys.strProductUrl = pelmProductUrl->getValueN(RT_XML_CONTENT_SMALL); 408 408 const xml::ElementNode *pelmVendorUrl; 409 409 if ((pelmVendorUrl = pelmThis->findChildElement("VendorUrl"))) 410 vsys.strVendorUrl = pelmVendorUrl->getValue ();410 vsys.strVendorUrl = pelmVendorUrl->getValueN(RT_XML_CONTENT_SMALL); 411 411 } 412 412 else if ( !strcmp(pcszElemName, "VirtualHardwareSection") … … 425 425 </System>*/ 426 426 if ((pelmVirtualSystemType = pelmSystem->findChildElement("VirtualSystemType"))) 427 vsys.strVirtualSystemType = pelmVirtualSystemType->getValue ();427 vsys.strVirtualSystemType = pelmVirtualSystemType->getValueN(RT_XML_CONTENT_SMALL); 428 428 } 429 429 … … 792 792 const xml::ElementNode *pelmCIMOSDescription; 793 793 if ((pelmCIMOSDescription = pelmThis->findChildElement("Description"))) 794 vsys.strCimosDesc = pelmCIMOSDescription->getValue ();794 vsys.strCimosDesc = pelmCIMOSDescription->getValueN(RT_XML_CONTENT_SMALL); 795 795 796 796 const xml::ElementNode *pelmVBoxOSType; 797 797 if ((pelmVBoxOSType = pelmThis->findChildElementNS("vbox", // namespace 798 798 "OSType"))) // element name 799 vsys.strTypeVBox = pelmVBoxOSType->getValue ();799 vsys.strTypeVBox = pelmVBoxOSType->getValueN(RT_XML_CONTENT_SMALL); 800 800 } 801 801 else if ( (!strcmp(pcszElemName, "AnnotationSection")) … … 805 805 const xml::ElementNode *pelmAnnotation; 806 806 if ((pelmAnnotation = pelmThis->findChildElement("Annotation"))) 807 vsys.strDescription = pelmAnnotation->getValue ();807 vsys.strDescription = pelmAnnotation->getValueN(RT_XML_CONTENT_SMALL); 808 808 } 809 809 } … … 818 818 const char *pcszItemChildName = pelmItemChild->getName(); 819 819 if (!strcmp(pcszItemChildName, "Description")) 820 strDescription = pelmItemChild->getValue ();820 strDescription = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 821 821 else if (!strcmp(pcszItemChildName, "Caption")) 822 strCaption = pelmItemChild->getValue ();822 strCaption = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 823 823 else if (!strcmp(pcszItemChildName, "ElementName")) 824 strElementName = pelmItemChild->getValue ();824 strElementName = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 825 825 else if ( !strcmp(pcszItemChildName, "InstanceID") 826 826 || !strcmp(pcszItemChildName, "InstanceId") ) 827 827 pelmItemChild->copyValue(ulInstanceID); 828 828 else if (!strcmp(pcszItemChildName, "HostResource")) 829 strHostResource = pelmItemChild->getValue ();829 strHostResource = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 830 830 else if (!strcmp(pcszItemChildName, "ResourceType")) 831 831 { … … 835 835 fResourceRequired = true; 836 836 const char *pcszAttValue; 837 if (item->getAttributeValue ("required", pcszAttValue))837 if (item->getAttributeValueN("required", pcszAttValue, RT_XML_ATTR_TINY)) 838 838 { 839 839 if (!strcmp(pcszAttValue, "false")) … … 842 842 } 843 843 else if (!strcmp(pcszItemChildName, "OtherResourceType")) 844 strOtherResourceType = pelmItemChild->getValue ();844 strOtherResourceType = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 845 845 else if (!strcmp(pcszItemChildName, "ResourceSubType")) 846 strResourceSubType = pelmItemChild->getValue ();846 strResourceSubType = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 847 847 else if (!strcmp(pcszItemChildName, "AutomaticAllocation")) 848 fAutomaticAllocation = (!strcmp(pelmItemChild->getValue (), "true")) ? true : false;848 fAutomaticAllocation = (!strcmp(pelmItemChild->getValueN(RT_XML_CONTENT_SMALL), "true")) ? true : false; 849 849 else if (!strcmp(pcszItemChildName, "AutomaticDeallocation")) 850 fAutomaticDeallocation = (!strcmp(pelmItemChild->getValue (), "true")) ? true : false;850 fAutomaticDeallocation = (!strcmp(pelmItemChild->getValueN(RT_XML_CONTENT_SMALL), "true")) ? true : false; 851 851 else if (!strcmp(pcszItemChildName, "Parent")) 852 852 pelmItemChild->copyValue(ulParent); 853 853 else if (!strcmp(pcszItemChildName, "Connection")) 854 strConnection = pelmItemChild->getValue ();854 strConnection = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 855 855 else if (!strcmp(pcszItemChildName, "Address")) 856 856 { 857 strAddress = pelmItemChild->getValue ();857 strAddress = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 858 858 pelmItemChild->copyValue(lAddress); 859 859 } 860 860 else if (!strcmp(pcszItemChildName, "AddressOnParent")) 861 strAddressOnParent = pelmItemChild->getValue ();861 strAddressOnParent = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 862 862 else if (!strcmp(pcszItemChildName, "AllocationUnits")) 863 strAllocationUnits = pelmItemChild->getValue ();863 strAllocationUnits = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 864 864 else if (!strcmp(pcszItemChildName, "VirtualQuantity")) 865 865 pelmItemChild->copyValue(ullVirtualQuantity); … … 871 871 pelmItemChild->copyValue(ullWeight); 872 872 else if (!strcmp(pcszItemChildName, "ConsumerVisibility")) 873 strConsumerVisibility = pelmItemChild->getValue ();873 strConsumerVisibility = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 874 874 else if (!strcmp(pcszItemChildName, "MappingBehavior")) 875 strMappingBehavior = pelmItemChild->getValue ();875 strMappingBehavior = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 876 876 else if (!strcmp(pcszItemChildName, "PoolID")) 877 strPoolID = pelmItemChild->getValue ();877 strPoolID = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 878 878 else if (!strcmp(pcszItemChildName, "BusNumber")) 879 879 pelmItemChild->copyValue(ulBusNumber); … … 921 921 const char *pcszItemChildName = pelmItemChild->getName(); 922 922 if (!strcmp(pcszItemChildName, "HostExtentName")) 923 strHostExtentName = pelmItemChild->getValue ();923 strHostExtentName = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 924 924 else if (!strcmp(pcszItemChildName, "OtherHostExtentNameFormat")) 925 strOtherHostExtentNameFormat = pelmItemChild->getValue ();925 strOtherHostExtentNameFormat = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 926 926 else if (!strcmp(pcszItemChildName, "OtherHostExtentNameNamespace")) 927 strOtherHostExtentNameNamespace = pelmItemChild->getValue ();927 strOtherHostExtentNameNamespace = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 928 928 else if (!strcmp(pcszItemChildName, "VirtualQuantityUnits")) 929 strVirtualQuantityUnits = pelmItemChild->getValue ();929 strVirtualQuantityUnits = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL); 930 930 else if (!strcmp(pcszItemChildName, "Access")) 931 931 { -
trunk/src/VBox/Runtime/r3/xml.cpp
r76553 r79677 565 565 566 566 /** 567 * Returns the value of a node. If this node is an attribute, returns 568 * the attribute value; if this node is an element, then this returns 569 * the element text content. 570 * @return 571 * @param cchValueLimit If the length of the returned value exceeds this 572 * limit a EIPRTFailure exception will be thrown. 573 */ 574 const char *Node::getValueN(size_t cchValueLimit) const 575 { 576 if ( m_pLibAttr 577 && m_pLibAttr->children 578 ) 579 { 580 // libxml hides attribute values in another node created as a 581 // single child of the attribute node, and it's in the content field 582 AssertStmt(strlen((const char *)m_pLibAttr->children->content) <= cchValueLimit, throw EIPRTFailure(VERR_BUFFER_OVERFLOW, "Attribute '%s' exceeds limit of %zu bytes", m_pcszName, cchValueLimit)); 583 return (const char *)m_pLibAttr->children->content; 584 } 585 586 if ( m_pLibNode 587 && m_pLibNode->children) 588 { 589 AssertStmt(strlen((const char *)m_pLibNode->children->content) <= cchValueLimit, throw EIPRTFailure(VERR_BUFFER_OVERFLOW, "Element '%s' exceeds limit of %zu bytes", m_pcszName, cchValueLimit)); 590 return (const char *)m_pLibNode->children->content; 591 } 592 593 return NULL; 594 } 595 596 /** 567 597 * Copies the value of a node into the given integer variable. 568 598 * Returns TRUE only if a value was found and was actually an … … 1152 1182 return true; 1153 1183 } 1184 } 1185 1186 return false; 1187 } 1188 1189 /** 1190 * Convenience method which attempts to find the attribute with the given 1191 * name and returns its value as a string. 1192 * 1193 * @param pcszMatch Name of attribute to find. 1194 * @param ppcsz Where to return the attribute. 1195 * @param cchValueLimit If the length of the returned value exceeds this 1196 * limit a EIPRTFailure exception will be thrown. 1197 * @param pcszNamespace The attribute name space prefix or NULL. 1198 * @returns Boolean success indicator. 1199 */ 1200 bool ElementNode::getAttributeValueN(const char *pcszMatch, const char **ppcsz, size_t cchValueLimit, const char *pcszNamespace /*= NULL*/) const 1201 { 1202 const AttributeNode *pAttr = findAttribute(pcszMatch, pcszNamespace); 1203 if (pAttr) 1204 { 1205 *ppcsz = pAttr->getValueN(cchValueLimit); 1206 return true; 1207 } 1208 return false; 1209 } 1210 1211 /** 1212 * Convenience method which attempts to find the attribute with the given 1213 * name and returns its value as a string. 1214 * 1215 * @param pcszMatch Name of attribute to find. 1216 * @param pStr Pointer to the string object that should receive the 1217 * attribute value. 1218 * @param cchValueLimit If the length of the returned value exceeds this 1219 * limit a EIPRTFailure exception will be thrown. 1220 * @param pcszNamespace The attribute name space prefix or NULL. 1221 * @returns Boolean success indicator. 1222 * 1223 * @throws Whatever the string class may throw on assignment. 1224 */ 1225 bool ElementNode::getAttributeValueN(const char *pcszMatch, RTCString *pStr, size_t cchValueLimit, const char *pcszNamespace /*= NULL*/) const 1226 { 1227 const AttributeNode *pAttr = findAttribute(pcszMatch, pcszNamespace); 1228 if (pAttr) 1229 { 1230 *pStr = pAttr->getValueN(cchValueLimit); 1231 return true; 1232 } 1233 1234 return false; 1235 } 1236 1237 /** 1238 * Like getAttributeValue (ministring variant), but makes sure that all backslashes 1239 * are converted to forward slashes. 1240 * 1241 * @param pcszMatch Name of attribute to find. 1242 * @param pStr Pointer to the string object that should 1243 * receive the attribute path value. 1244 * @param cchValueLimit If the length of the returned value exceeds this 1245 * limit a EIPRTFailure exception will be thrown. 1246 * @param pcszNamespace The attribute name space prefix or NULL. 1247 * @returns Boolean success indicator. 1248 */ 1249 bool ElementNode::getAttributeValuePathN(const char *pcszMatch, RTCString *pStr, size_t cchValueLimit, const char *pcszNamespace /*= NULL*/) const 1250 { 1251 if (getAttributeValueN(pcszMatch, pStr, cchValueLimit, pcszNamespace)) 1252 { 1253 pStr->findReplace('\\', '/'); 1254 return true; 1154 1255 } 1155 1256
Note:
See TracChangeset
for help on using the changeset viewer.