- Timestamp:
- Dec 2, 2008 2:37:52 PM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MachineImpl.cpp
r14858 r14904 2390 2390 { 2391 2391 using namespace settings; 2392 using namespace vboxxml;2392 using namespace xml; 2393 2393 2394 2394 /* load the settings file (we don't reuse the existing handle but … … 2494 2494 { 2495 2495 using namespace settings; 2496 using namespace vboxxml;2496 using namespace xml; 2497 2497 2498 2498 /* load the settings file (we don't reuse the existing handle but … … 2570 2570 { 2571 2571 using namespace settings; 2572 using namespace vboxxml;2572 using namespace xml; 2573 2573 2574 2574 /* load the settings file */ … … 4712 4712 { 4713 4713 using namespace settings; 4714 using namespace vboxxml;4714 using namespace xml; 4715 4715 4716 4716 /* no concurrent file access is possible in init() so open by handle */ … … 5870 5870 { 5871 5871 using namespace settings; 5872 using namespace vboxxml;5872 using namespace xml; 5873 5873 5874 5874 /* this object is locked for writing to prevent concurrent reads and writes */ … … 6066 6066 { 6067 6067 using namespace settings; 6068 using namespace vboxxml;6068 using namespace xml; 6069 6069 6070 6070 /* load the settings file */ … … 6629 6629 emptyStr); 6630 6630 } 6631 catch ( vboxxml::ENoMemory e)6631 catch (xml::ENoMemory e) 6632 6632 { 6633 6633 return E_OUTOFMEMORY; … … 6711 6711 { 6712 6712 using namespace settings; 6713 using namespace vboxxml;6713 using namespace xml; 6714 6714 6715 6715 /* load the settings file */ -
trunk/src/VBox/Main/Makefile.kmk
r14854 r14904 555 555 include 556 556 VBoxSettings_SOURCES = \ 557 xml/ vboxxml.cpp \557 xml/xml.cpp \ 558 558 xml/Settings.cpp 559 559 VBoxSettings_LDFLAGS.darwin = -install_name $(VBOX_DYLD_EXECUTABLE_PATH)/$(notdir $(LIB_SETTINGS)) -Wl,-x # no debug info please. -
trunk/src/VBox/Main/VirtualBoxBase.cpp
r14854 r14904 1255 1255 1256 1256 if (RT_FAILURE (vrc)) 1257 throw vboxxml::LogicError (RT_SRC_POS);1257 throw xml::LogicError (RT_SRC_POS); 1258 1258 1259 1259 return result; … … 1293 1293 int vrc = RTUuidToStr (aValue.raw(), result.get() + 1, RTUUID_STR_LENGTH); 1294 1294 if (RT_FAILURE (vrc)) 1295 throw vboxxml::LogicError (RT_SRC_POS);1295 throw xml::LogicError (RT_SRC_POS); 1296 1296 1297 1297 result.get() [0] = '{'; -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r14874 r14904 221 221 { 222 222 using namespace settings; 223 using namespace vboxxml;223 using namespace xml; 224 224 225 225 /* no concurrent file access is possible in init() so open by handle */ … … 1422 1422 { 1423 1423 using namespace settings; 1424 using namespace vboxxml;1424 using namespace xml; 1425 1425 1426 1426 /* load the settings file (we don't reuse the existing handle but … … 1521 1521 { 1522 1522 using namespace settings; 1523 using namespace vboxxml;1523 using namespace xml; 1524 1524 1525 1525 /* load the settings file (we don't reuse the existing handle but … … 1582 1582 { 1583 1583 using namespace settings; 1584 using namespace vboxxml;1584 using namespace xml; 1585 1585 1586 1586 /* load the settings file */ … … 3148 3148 { 3149 3149 using namespace settings; 3150 using namespace vboxxml;3150 using namespace xml; 3151 3151 3152 3152 /* load the settings file */ … … 3768 3768 /* static */ 3769 3769 HRESULT VirtualBox::loadSettingsTree (settings::XmlTreeBackend &aTree, 3770 vboxxml::File &aFile,3770 xml::File &aFile, 3771 3771 bool aValidate, 3772 3772 bool aCatchLoadErrors, … … 3803 3803 } 3804 3804 } 3805 catch (const vboxxml::EIPRTFailure &err)3805 catch (const xml::EIPRTFailure &err) 3806 3806 { 3807 3807 if (!aCatchLoadErrors) … … 3842 3842 /* static */ 3843 3843 HRESULT VirtualBox::saveSettingsTree (settings::TreeBackend &aTree, 3844 vboxxml::File &aFile,3844 xml::File &aFile, 3845 3845 Utf8Str &aFormatVersion) 3846 3846 { … … 3856 3856 aFormatVersion = VBOX_XML_VERSION_FULL; 3857 3857 } 3858 catch (const vboxxml::EIPRTFailure &err)3858 catch (const xml::EIPRTFailure &err) 3859 3859 { 3860 3860 /* this is the only expected exception for now */ -
trunk/src/VBox/Main/VirtualBoxImplExtra.cpp
r14854 r14904 68 68 * a wrong URI/ID pair. 69 69 */ 70 vboxxml::Input *70 xml::Input * 71 71 VirtualBox::SettingsTreeHelper::resolveEntity (const char *aURI, const char *aID) 72 72 { 73 73 if (strcmp (aURI, VBOX_XML_SCHEMA_COMMON) == 0) 74 74 { 75 return new vboxxml::75 return new xml:: 76 76 MemoryBuf ((const char *) g_ab_xml_VirtualBox_settings_common_xsd, 77 77 g_cb_xml_VirtualBox_settings_common_xsd, aURI); … … 80 80 if (strcmp (aURI, VBOX_XML_SCHEMA_ROOT) == 0) 81 81 { 82 return new vboxxml::82 return new xml:: 83 83 MemoryBuf ((const char *) g_ab_xml_VirtualBox_settings_root_xsd, 84 84 g_cb_xml_VirtualBox_settings_root_xsd, aURI); … … 87 87 if (strcmp (aURI, VBOX_XML_SCHEMA) == 0) 88 88 { 89 return new vboxxml::89 return new xml:: 90 90 MemoryBuf ((const char *) g_ab_xml_VirtualBox_settings_xsd, 91 91 g_cb_xml_VirtualBox_settings_xsd, aURI); … … 94 94 if (strcmp (aURI, VBOX_XML_SETTINGS_CONVERTER) == 0) 95 95 { 96 return new vboxxml::96 return new xml:: 97 97 MemoryBuf ((const char *) g_ab_xml_SettingsConverter_xsl, 98 98 g_cb_xml_SettingsConverter_xsl, aURI); -
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r14854 r14904 280 280 281 281 // InputResolver interface 282 vboxxml::Input *resolveEntity (const char *aURI, const char *aID);282 xml::Input *resolveEntity (const char *aURI, const char *aID); 283 283 284 284 // AutoConverter interface … … 288 288 289 289 static HRESULT loadSettingsTree (settings::XmlTreeBackend &aTree, 290 vboxxml::File &aFile,290 xml::File &aFile, 291 291 bool aValidate, 292 292 bool aCatchLoadErrors, … … 304 304 */ 305 305 static HRESULT loadSettingsTree_FirstTime (settings::XmlTreeBackend &aTree, 306 vboxxml::File &aFile,306 xml::File &aFile, 307 307 Utf8Str &aFormatVersion) 308 308 { … … 320 320 */ 321 321 static HRESULT loadSettingsTree_Again (settings::XmlTreeBackend &aTree, 322 vboxxml::File &aFile)322 xml::File &aFile) 323 323 { 324 324 return loadSettingsTree (aTree, aFile, true, false, true); … … 333 333 */ 334 334 static HRESULT loadSettingsTree_ForUpdate (settings::XmlTreeBackend &aTree, 335 vboxxml::File &aFile)335 xml::File &aFile) 336 336 { 337 337 return loadSettingsTree (aTree, aFile, true, false, false); … … 339 339 340 340 static HRESULT saveSettingsTree (settings::TreeBackend &aTree, 341 vboxxml::File &aFile,341 xml::File &aFile, 342 342 Utf8Str &aFormatVersion); 343 343 -
trunk/src/VBox/Main/xml/Settings.cpp
r14854 r14904 43 43 44 44 45 /**46 * Global module initialization structure.47 *48 * The constructor and destructor of this structure are used to perform global49 * module initiaizaton and cleanup. Thee must be only one global variable of50 * this structure.51 */52 static53 class Global54 {55 public:56 57 Global()58 {59 /* Check the parser version. The docs say it will kill the app if60 * there is a serious version mismatch, but I couldn't find it in the61 * source code (it only prints the error/warning message to the console) so62 * let's leave it as is for informational purposes. */63 LIBXML_TEST_VERSION64 65 /* Init libxml */66 xmlInitParser();67 68 /* Save the default entity resolver before someone has replaced it */69 xml.defaultEntityLoader = xmlGetExternalEntityLoader();70 }71 72 ~Global()73 {74 /* Shutdown libxml */75 xmlCleanupParser();76 }77 78 struct79 {80 xmlExternalEntityLoader defaultEntityLoader;81 82 /** Used to provide some thread safety missing in libxml2 (see e.g.83 * XmlTreeBackend::read()) */84 RTLockMtx lock;85 }86 xml;87 }88 gGlobal;89 90 91 45 namespace settings 92 46 { … … 143 97 break; 144 98 default: 145 throw vboxxml::ENotImplemented (RT_SRC_POS);99 throw xml::ENotImplemented (RT_SRC_POS); 146 100 } 147 101 … … 287 241 break; 288 242 default: 289 throw vboxxml::ENotImplemented (RT_SRC_POS);243 throw xml::ENotImplemented (RT_SRC_POS); 290 244 } 291 245 … … 295 249 return result; 296 250 297 throw vboxxml::EIPRTFailure (vrc);251 throw xml::EIPRTFailure (vrc); 298 252 } 299 253 … … 401 355 void XmlKeyBackend::setName (const char *aName) 402 356 { 403 throw vboxxml::ENotImplemented (RT_SRC_POS);357 throw xml::ENotImplemented (RT_SRC_POS); 404 358 } 405 359 … … 458 412 value = xmlEncodeSpecialChars (mNode->doc, value); 459 413 if (value == NULL) 460 throw vboxxml::ENoMemory();414 throw xml::ENoMemory(); 461 415 } 462 416 … … 484 438 int rc = xmlRemoveProp (attr); 485 439 if (rc != 0) 486 throw vboxxml::EInvalidArg (RT_SRC_POS);440 throw xml::EInvalidArg (RT_SRC_POS); 487 441 } 488 442 return; … … 492 446 (const xmlChar *) aValue); 493 447 if (attr == NULL) 494 throw vboxxml::ENoMemory();448 throw xml::ENoMemory(); 495 449 } 496 450 … … 545 499 xmlNodePtr node = xmlNewChild (mNode, NULL, (const xmlChar *) aName, NULL); 546 500 if (node == NULL) 547 throw vboxxml::ENoMemory();501 throw xml::ENoMemory(); 548 502 549 503 return Key (new XmlKeyBackend (node)); … … 571 525 { 572 526 if (!aErr) 573 throw vboxxml::EInvalidArg (RT_SRC_POS);527 throw xml::EInvalidArg (RT_SRC_POS); 574 528 575 529 char *msg = Format (aErr); … … 623 577 struct IOCtxt 624 578 { 625 IOCtxt ( vboxxml::Stream *aStream, std::auto_ptr <stdx::exception_trap_base> &aErr)579 IOCtxt (xml::Stream *aStream, std::auto_ptr <stdx::exception_trap_base> &aErr) 626 580 : stream (aStream), deleteStreamOnClose (false) 627 581 , err (aErr) {} … … 632 586 void resetErr() { err.reset(); } 633 587 634 vboxxml::Stream *stream;588 xml::Stream *stream; 635 589 bool deleteStreamOnClose; 636 590 … … 640 594 struct InputCtxt : public IOCtxt 641 595 { 642 InputCtxt ( vboxxml::Input *aInput, std::auto_ptr <stdx::exception_trap_base> &aErr)596 InputCtxt (xml::Input *aInput, std::auto_ptr <stdx::exception_trap_base> &aErr) 643 597 : IOCtxt (aInput, aErr), input (aInput) {} 644 598 645 vboxxml::Input *input;599 xml::Input *input; 646 600 }; 647 601 648 602 struct OutputCtxt : public IOCtxt 649 603 { 650 OutputCtxt ( vboxxml::Output *aOutput, std::auto_ptr <stdx::exception_trap_base> &aErr)604 OutputCtxt (xml::Output *aOutput, std::auto_ptr <stdx::exception_trap_base> &aErr) 651 605 : IOCtxt (aOutput, aErr), output (aOutput) {} 652 606 653 vboxxml::Output *output;607 xml::Output *output; 654 608 }; 655 609 }; … … 661 615 m->ctxt = xmlNewParserCtxt(); 662 616 if (m->ctxt == NULL) 663 throw vboxxml::ENoMemory();617 throw xml::ENoMemory(); 664 618 } 665 619 … … 700 654 extern "C" void *xsltGenericErrorContext; 701 655 702 void XmlTreeBackend::rawRead ( vboxxml::Input &aInput, const char *aSchema /* = NULL */,656 void XmlTreeBackend::rawRead (xml::Input &aInput, const char *aSchema /* = NULL */, 703 657 int aFlags /* = 0 */) 704 658 { … … 713 667 * unwanted now for several reasons. Search for "thread-safe" to find all 714 668 * unsafe cases. */ 715 RTLock alock (gGlobal.xml.lock);716 717 xmlExternalEntityLoader oldEntityLoader = xmlGetExternalEntityLoader(); 669 xml::GlobalLock global; 670 global.setExternalEntityLoader(ExternalEntityLoader); 671 718 672 sThat = this; 719 xmlSetExternalEntityLoader (ExternalEntityLoader);720 721 673 xmlDocPtr doc = NULL; 722 674 … … 727 679 * otherwise xmlSaveDoc() won't be able to do proper indentation on 728 680 * output. */ 729 730 681 /* parse the stream */ 731 682 /* NOTE: new InputCtxt instance will be deleted when the stream is closed by … … 764 715 /* parse the XSLT template */ 765 716 { 766 vboxxml::Input *xsltInput =717 xml::Input *xsltInput = 767 718 m->inputResolver->resolveEntity 768 719 (m->autoConverter->templateUri(), NULL); … … 800 751 { 801 752 if (errorStr != NULL) 802 throw vboxxml::LogicError (errorStr);753 throw xml::LogicError (errorStr); 803 754 /* errorStr is freed in catch(...) below */ 804 755 805 throw vboxxml::LogicError (RT_SRC_POS);756 throw xml::LogicError (RT_SRC_POS); 806 757 } 807 758 … … 811 762 xmlDocPtr newDoc = xsltApplyStylesheet (xslt, doc, NULL); 812 763 if (newDoc == NULL && errorStr == NULL) 813 throw vboxxml::LogicError (RT_SRC_POS);764 throw xml::LogicError (RT_SRC_POS); 814 765 815 766 if (errorStr != NULL) … … 873 824 schemaCtxt = xmlSchemaNewParserCtxt (aSchema); 874 825 if (schemaCtxt == NULL) 875 throw vboxxml::LogicError (RT_SRC_POS);826 throw xml::LogicError (RT_SRC_POS); 876 827 877 828 /* set our error handlers */ … … 887 838 validCtxt = xmlSchemaNewValidCtxt (schema); 888 839 if (validCtxt == NULL) 889 throw vboxxml::LogicError (RT_SRC_POS);840 throw xml::LogicError (RT_SRC_POS); 890 841 891 842 /* instruct to create default attribute's values in the document */ … … 908 859 909 860 if (errorStr == NULL) 910 throw vboxxml::LogicError (RT_SRC_POS);861 throw xml::LogicError (RT_SRC_POS); 911 862 912 863 throw Error (errorStr); … … 948 899 m->oldVersion = oldVersion; 949 900 950 /* restore the previous entity resolver */951 xmlSetExternalEntityLoader (oldEntityLoader);952 901 sThat = NULL; 953 902 } … … 957 906 xmlFreeDoc (doc); 958 907 959 /* restore the previous entity resolver */960 xmlSetExternalEntityLoader (oldEntityLoader);961 908 sThat = NULL; 962 909 … … 965 912 } 966 913 967 void XmlTreeBackend::rawWrite ( vboxxml::Output &aOutput)914 void XmlTreeBackend::rawWrite (xml::Output &aOutput) 968 915 { 969 916 /* reset error variables used to memorize exceptions while inside the … … 987 934 XML_SAVE_FORMAT); 988 935 if (saveCtxt == NULL) 989 throw vboxxml::LogicError (RT_SRC_POS);936 throw xml::LogicError (RT_SRC_POS); 990 937 991 938 long rc = xmlSaveDoc (saveCtxt, m->doc); … … 998 945 /* there must be an exception from the Output implementation, 999 946 * otherwise the save operation must always succeed. */ 1000 throw vboxxml::LogicError (RT_SRC_POS);947 throw xml::LogicError (RT_SRC_POS); 1001 948 } 1002 949 … … 1037 984 return ctxt->input->read (aBuf, aLen); 1038 985 } 1039 catch (const vboxxml::EIPRTFailure &err) { ctxt->setErr (err); }1040 catch (const vboxxml::Error &err) { ctxt->setErr (err); }986 catch (const xml::EIPRTFailure &err) { ctxt->setErr (err); } 987 catch (const xml::Error &err) { ctxt->setErr (err); } 1041 988 catch (const std::exception &err) { ctxt->setErr (err); } 1042 catch (...) { ctxt->setErr ( vboxxml::LogicError (RT_SRC_POS)); }989 catch (...) { ctxt->setErr (xml::LogicError (RT_SRC_POS)); } 1043 990 1044 991 return -1 /* failure */; … … 1058 1005 return ctxt->output->write (aBuf, aLen); 1059 1006 } 1060 catch (const vboxxml::EIPRTFailure &err) { ctxt->setErr (err); }1061 catch (const vboxxml::Error &err) { ctxt->setErr (err); }1007 catch (const xml::EIPRTFailure &err) { ctxt->setErr (err); } 1008 catch (const xml::Error &err) { ctxt->setErr (err); } 1062 1009 catch (const std::exception &err) { ctxt->setErr (err); } 1063 catch (...) { ctxt->setErr ( vboxxml::LogicError (RT_SRC_POS)); }1010 catch (...) { ctxt->setErr (xml::LogicError (RT_SRC_POS)); } 1064 1011 1065 1012 return -1 /* failure */; … … 1090 1037 return 0 /* success */; 1091 1038 } 1092 catch (const vboxxml::EIPRTFailure &err) { ctxt->setErr (err); }1093 catch (const vboxxml::Error &err) { ctxt->setErr (err); }1039 catch (const xml::EIPRTFailure &err) { ctxt->setErr (err); } 1040 catch (const xml::Error &err) { ctxt->setErr (err); } 1094 1041 catch (const std::exception &err) { ctxt->setErr (err); } 1095 catch (...) { ctxt->setErr ( vboxxml::LogicError (RT_SRC_POS)); }1042 catch (...) { ctxt->setErr (xml::LogicError (RT_SRC_POS)); } 1096 1043 1097 1044 return -1 /* failure */; … … 1191 1138 1192 1139 if (sThat->m->inputResolver == NULL) 1193 return gGlobal.xml.defaultEntityLoader(aURI, aID, aCtxt);1140 return xml::GlobalLock::callDefaultLoader(aURI, aID, aCtxt); 1194 1141 1195 1142 /* To prevent throwing exceptions while inside libxml2 code, we catch … … 1197 1144 try 1198 1145 { 1199 vboxxml::Input *input = sThat->m->inputResolver->resolveEntity (aURI, aID);1146 xml::Input *input = sThat->m->inputResolver->resolveEntity (aURI, aID); 1200 1147 if (input == NULL) 1201 1148 return NULL; … … 1232 1179 delete ctxt; 1233 1180 1234 throw vboxxml::ENoMemory();1235 } 1236 catch (const vboxxml::EIPRTFailure &err) { sThat->m->trappedErr.reset (stdx::new_exception_trap (err)); }1237 catch (const vboxxml::Error &err) { sThat->m->trappedErr.reset (stdx::new_exception_trap (err)); }1181 throw xml::ENoMemory(); 1182 } 1183 catch (const xml::EIPRTFailure &err) { sThat->m->trappedErr.reset (stdx::new_exception_trap (err)); } 1184 catch (const xml::Error &err) { sThat->m->trappedErr.reset (stdx::new_exception_trap (err)); } 1238 1185 catch (const std::exception &err) { sThat->m->trappedErr.reset (stdx::new_exception_trap (err)); } 1239 catch (...) { sThat->m->trappedErr.reset (stdx::new_exception_trap ( vboxxml::LogicError (RT_SRC_POS))); }1186 catch (...) { sThat->m->trappedErr.reset (stdx::new_exception_trap (xml::LogicError (RT_SRC_POS))); } 1240 1187 1241 1188 return NULL; -
trunk/src/VBox/Main/xml/xml.cpp
r14894 r14904 24 24 #include <iprt/file.h> 25 25 #include <iprt/lock.h> 26 #include <iprt/string.h> 26 27 27 28 #include <libxml/tree.h> … … 34 35 #include <libxml/xmlschemas.h> 35 36 36 #include <libxslt/xsltInternals.h> 37 #include <libxslt/transform.h> 38 #include <libxslt/xsltutils.h> 39 40 #include <string.h> 41 42 #include "VBox/vboxxml.h" 43 44 namespace vboxxml 45 { 37 #include <string> 38 39 #include "VBox/xml.h" 40 41 42 /** 43 * Global module initialization structure. 44 * 45 * The constructor and destructor of this structure are used to perform global 46 * module initiaizaton and cleanup. Thee must be only one global variable of 47 * this structure. 48 */ 49 static 50 class Global 51 { 52 public: 53 54 Global() 55 { 56 /* Check the parser version. The docs say it will kill the app if 57 * there is a serious version mismatch, but I couldn't find it in the 58 * source code (it only prints the error/warning message to the console) so 59 * let's leave it as is for informational purposes. */ 60 LIBXML_TEST_VERSION 61 62 /* Init libxml */ 63 xmlInitParser(); 64 65 /* Save the default entity resolver before someone has replaced it */ 66 xml.defaultEntityLoader = xmlGetExternalEntityLoader(); 67 } 68 69 ~Global() 70 { 71 /* Shutdown libxml */ 72 xmlCleanupParser(); 73 } 74 75 struct 76 { 77 xmlExternalEntityLoader defaultEntityLoader; 78 79 /** Used to provide some thread safety missing in libxml2 (see e.g. 80 * XmlTreeBackend::read()) */ 81 RTLockMtx lock; 82 } 83 xml; 84 } 85 gGlobal; 86 87 88 89 namespace xml 90 { 91 92 ////////////////////////////////////////////////////////////////////////////// 93 // Exceptions 94 ////////////////////////////////////////////////////////////////////////////// 95 96 LogicError::LogicError(RT_SRC_POS_DECL) 97 { 98 char *msg = NULL; 99 RTStrAPrintf(&msg, "In '%s', '%s' at #%d", 100 pszFunction, pszFile, iLine); 101 setWhat(msg); 102 RTStrFree(msg); 103 } 104 46 105 47 106 ////////////////////////////////////////////////////////////////////////////// … … 246 305 } 247 306 248 249 307 /* 250 * VBoxXml 251 * 252 * 253 */ 254 255 VBoxXmlBase::VBoxXmlBase() 308 * GlobalLock 309 * 310 * 311 */ 312 313 struct GlobalLock::Data 314 { 315 PFNEXTERNALENTITYLOADER pOldLoader; 316 RTLock lock; 317 318 Data() 319 : pOldLoader(NULL), 320 lock(gGlobal.xml.lock) 321 { 322 } 323 }; 324 325 GlobalLock::GlobalLock() 326 : m(new Data()) 327 { 328 } 329 330 GlobalLock::~GlobalLock() 331 { 332 if (m->pOldLoader) 333 xmlSetExternalEntityLoader(m->pOldLoader); 334 } 335 336 void GlobalLock::setExternalEntityLoader(PFNEXTERNALENTITYLOADER pLoader) 337 { 338 m->pOldLoader = xmlGetExternalEntityLoader(); 339 xmlSetExternalEntityLoader(pLoader); 340 } 341 342 // static 343 xmlParserInput* GlobalLock::callDefaultLoader(const char *aURI, 344 const char *aID, 345 xmlParserCtxt *aCtxt) 346 { 347 return gGlobal.xml.defaultEntityLoader(aURI, aID, aCtxt); 348 } 349 350 /* 351 * XmlParserBase 352 * 353 * 354 */ 355 356 XmlParserBase::XmlParserBase() 256 357 { 257 358 m_ctxt = xmlNewParserCtxt(); … … 260 361 } 261 362 262 VBoxXmlBase::~VBoxXmlBase()363 XmlParserBase::~XmlParserBase() 263 364 { 264 365 xmlFreeParserCtxt (m_ctxt); … … 266 367 } 267 368 268 269 int ReadCallback (void *aCtxt, char *aBuf, int aLen) 270 { 271 return -1 /* failure */; 272 } 273 274 275 VBoxXmlFile::VBoxXmlFile() 276 : VBoxXmlBase() 277 { 278 xmlDocPtr doc; 279 280 } 281 282 VBoxXmlFile::~VBoxXmlFile() 283 { 284 } 285 286 } // namespace vboxxml 287 288 369 /* 370 * XmlFileParser 371 * 372 * 373 */ 374 375 struct XmlFileParser::Data 376 { 377 xmlParserCtxtPtr ctxt; 378 std::string strXmlFilename; 379 380 Data() 381 { 382 if (!(ctxt = xmlNewParserCtxt())) 383 throw xml::ENoMemory(); 384 } 385 386 ~Data() 387 { 388 xmlFreeParserCtxt(ctxt); 389 ctxt = NULL; 390 } 391 }; 392 393 XmlFileParser::XmlFileParser() 394 : XmlParserBase(), 395 m(new Data()) 396 { 397 } 398 399 XmlFileParser::~XmlFileParser() 400 { 401 } 402 403 void XmlFileParser::read(const char *pcszFilename) 404 { 405 GlobalLock lock(); 406 407 xmlDocPtr doc = NULL; 408 409 m->strXmlFilename = pcszFilename; 410 411 /* Note: when parsing we use XML_PARSE_NOBLANKS to instruct libxml2 to 412 * remove text nodes that contain only blanks. This is important because 413 * otherwise xmlSaveDoc() won't be able to do proper indentation on 414 * output. */ 415 416 /* parse the stream */ 417 /* NOTE: new InputCtxt instance will be deleted when the stream is closed by 418 * the libxml2 API (e.g. when calling xmlFreeParserCtxt()) */ 419 // doc = xmlCtxtReadIO(m->ctxt, 420 // ReadCallback, 421 // CloseCallback, 422 // new Data::InputCtxt (&aInput, m->trappedErr), 423 // aInput.uri(), NULL, 424 // XML_PARSE_NOBLANKS); 425 if (doc == NULL) 426 { 427 /* look if there was a forwared exception from the lower level */ 428 // if (m->trappedErr.get() != NULL) 429 // m->trappedErr->rethrow(); 430 431 // throw XmlError (xmlCtxtGetLastError (m->ctxt)); 432 } 433 } 434 435 } // end namespace xml 436 437
Note:
See TracChangeset
for help on using the changeset viewer.