Changeset 14904 in vbox
- Timestamp:
- Dec 2, 2008 2:37:52 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/settings.h
r14854 r14904 36 36 37 37 #include <list> 38 #include <memory>39 #include <limits>40 38 41 39 /* these conflict with numeric_digits<>::min and max */ … … 43 41 #undef max 44 42 45 #include <iprt/assert.h>46 #include <iprt/string.h>47 #include <iprt/mem.h>48 43 #include <iprt/time.h> 49 44 50 #include <VBox/ vboxxml.h>45 #include <VBox/xml.h> 51 46 52 47 #include <stdarg.h> … … 233 228 * 234 229 * The alternative is to instantiate a template before the data member 235 * declaration with the VBOX SETTINGS_CLASS prefix, but the standard disables230 * declaration with the VBOXXML_CLASS prefix, but the standard disables 236 231 * explicit instantiations in a foreign namespace. In other words, a declaration 237 232 * like: 238 233 * 239 * template class VBOX SETTINGS_CLASS std::auto_ptr <Data>;234 * template class VBOXXML_CLASS std::auto_ptr <Data>; 240 235 * 241 236 * right before the member declaration makes MSVC happy too, but this is not a … … 270 265 ////////////////////////////////////////////////////////////////////////////// 271 266 272 class VBOX SETTINGS_CLASS ENoKey : public vboxxml::LogicError267 class VBOXXML_CLASS ENoKey : public xml::LogicError 273 268 { 274 269 public: 275 270 276 ENoKey (const char *aMsg = NULL) : vboxxml::LogicError (aMsg) {}271 ENoKey (const char *aMsg = NULL) : xml::LogicError (aMsg) {} 277 272 }; 278 273 279 class VBOX SETTINGS_CLASS ENoValue : public vboxxml::LogicError274 class VBOXXML_CLASS ENoValue : public xml::LogicError 280 275 { 281 276 public: 282 277 283 ENoValue (const char *aMsg = NULL) : vboxxml::LogicError (aMsg) {}278 ENoValue (const char *aMsg = NULL) : xml::LogicError (aMsg) {} 284 279 }; 285 280 286 class VBOX SETTINGS_CLASS ENoConversion : public vboxxml::RuntimeError281 class VBOXXML_CLASS ENoConversion : public xml::RuntimeError 287 282 { 288 283 public: … … 302 297 * <tr>const char *</tr> and makes a copy of the string it points to. 303 298 */ 304 class VBOX SETTINGS_CLASS FmtStr299 class VBOXXML_CLASS FmtStr 305 300 { 306 301 public: … … 372 367 } 373 368 374 throw vboxxml::ENotImplemented (RT_SRC_POS);369 throw xml::ENotImplemented (RT_SRC_POS); 375 370 } 376 371 … … 444 439 } 445 440 446 throw vboxxml::ENotImplemented (RT_SRC_POS);441 throw xml::ENotImplemented (RT_SRC_POS); 447 442 } 448 443 … … 496 491 * that becomes invalid when this TreeBackend instance is destroyed. 497 492 */ 498 class VBOX SETTINGS_CLASS Key493 class VBOXXML_CLASS Key 499 494 { 500 495 public: … … 508 503 * storing settings keys. 509 504 */ 510 class VBOX SETTINGS_CLASS Backend : public stdx::auto_ref505 class VBOXXML_CLASS Backend : public stdx::auto_ref 511 506 { 512 507 public: … … 892 887 * and an attempt to access Key data will cause the program crash. 893 888 */ 894 class VBOX SETTINGS_CLASS TreeBackend889 class VBOXXML_CLASS TreeBackend 895 890 { 896 891 public: … … 917 912 * @param aFlags Optional bit flags. 918 913 */ 919 void read ( vboxxml::Input &aInput, const char *aSchema = NULL, int aFlags = 0)914 void read (xml::Input &aInput, const char *aSchema = NULL, int aFlags = 0) 920 915 { 921 916 aInput.setPos (0); … … 933 928 * @see read() 934 929 */ 935 virtual void rawRead ( vboxxml::Input &aInput, const char *aSchema = NULL,930 virtual void rawRead (xml::Input &aInput, const char *aSchema = NULL, 936 931 int aFlags = 0) = 0; 937 932 … … 947 942 * @param aOutput Output stream. 948 943 */ 949 void write ( vboxxml::Output &aOutput)944 void write (xml::Output &aOutput) 950 945 { 951 946 aOutput.setPos (0); … … 966 961 * @see write() 967 962 */ 968 virtual void rawWrite ( vboxxml::Output &aOutput) = 0;963 virtual void rawWrite (xml::Output &aOutput) = 0; 969 964 970 965 /** … … 1002 997 * settings namespace) needs to be used by more than one thread. 1003 998 */ 1004 class VBOX SETTINGS_CLASS XmlTreeBackend : public TreeBackend999 class VBOXXML_CLASS XmlTreeBackend : public TreeBackend 1005 1000 { 1006 1001 public: … … 1021 1016 * validating the XML document representing the settings tree. 1022 1017 */ 1023 class VBOX SETTINGS_CLASS Error : public vboxxml::RuntimeError1018 class VBOXXML_CLASS Error : public xml::RuntimeError 1024 1019 { 1025 1020 public: … … 1032 1027 * AutoConverter::needsConversion() implementation. 1033 1028 */ 1034 class VBOX SETTINGS_CLASS EConversionCycle : public Error1029 class VBOXXML_CLASS EConversionCycle : public Error 1035 1030 { 1036 1031 public: … … 1043 1038 * for external entities given an URL and entity ID. 1044 1039 */ 1045 class VBOX SETTINGS_CLASS InputResolver1040 class VBOXXML_CLASS InputResolver 1046 1041 { 1047 1042 public: … … 1060 1055 * Input subclasses. 1061 1056 */ 1062 virtual vboxxml::Input *resolveEntity (const char *aURI, const char *aID) = 0;1057 virtual xml::Input *resolveEntity (const char *aURI, const char *aID) = 0; 1063 1058 }; 1064 1059 … … 1068 1063 * stream. 1069 1064 */ 1070 class VBOX SETTINGS_CLASS AutoConverter1065 class VBOXXML_CLASS AutoConverter 1071 1066 { 1072 1067 public: … … 1179 1174 const char *oldVersion() const; 1180 1175 1181 void rawRead ( vboxxml::Input &aInput, const char *aSchema = NULL, int aFlags = 0);1182 void rawWrite ( vboxxml::Output &aOutput);1176 void rawRead (xml::Input &aInput, const char *aSchema = NULL, int aFlags = 0); 1177 void rawWrite (xml::Output &aOutput); 1183 1178 void reset(); 1184 1179 Key &rootKey() const; -
trunk/include/VBox/xml.h
r14894 r14904 33 33 #include <iprt/cdefs.h> 34 34 #include <iprt/cpputils.h> 35 #include <iprt/string.h>36 37 #include <list>38 #include <memory>39 #include <limits>40 35 41 36 /* these conflict with numeric_digits<>::min and max */ … … 43 38 #undef max 44 39 45 #include <iprt/assert.h>46 #include <iprt/string.h>47 40 #include <iprt/mem.h> 48 #include <iprt/time.h>49 41 50 42 #ifndef IN_RING3 … … 52 44 #else /* IN_RING3 */ 53 45 54 /** @def IN_VBOX SETTINGS_R346 /** @def IN_VBOXXML_R3 55 47 * Used to indicate whether we're inside the same link module as the 56 48 * XML Settings File Manipulation API. … … 60 52 */ 61 53 #ifdef DOXYGEN_RUNNING 62 # define IN_VBOX SETTINGS_R354 # define IN_VBOXXML_R3 63 55 #endif 64 56 65 /** @def VBOX SETTINGS_CLASS57 /** @def VBOXXML_CLASS 66 58 * Class export/import wrapper. */ 67 #ifdef IN_VBOX SETTINGS_R368 # define VBOX SETTINGS_CLASS DECLEXPORT_CLASS59 #ifdef IN_VBOXXML_R3 60 # define VBOXXML_CLASS DECLEXPORT_CLASS 69 61 #else 70 # define VBOX SETTINGS_CLASS DECLIMPORT_CLASS62 # define VBOXXML_CLASS DECLIMPORT_CLASS 71 63 #endif 72 64 … … 78 70 * 79 71 * The alternative is to instantiate a template before the data member 80 * declaration with the VBOX SETTINGS_CLASS prefix, but the standard disables72 * declaration with the VBOXXML_CLASS prefix, but the standard disables 81 73 * explicit instantiations in a foreign namespace. In other words, a declaration 82 74 * like: 83 75 * 84 * template class VBOX SETTINGS_CLASS std::auto_ptr <Data>;76 * template class VBOXXML_CLASS std::auto_ptr <Data>; 85 77 * 86 78 * right before the member declaration makes MSVC happy too, but this is not a … … 105 97 typedef xmlError *xmlErrorPtr; 106 98 107 namespace vboxxml99 namespace xml 108 100 { 109 101 … … 114 106 * Base exception class. 115 107 */ 116 class VBOX SETTINGS_CLASS Error : public std::exception108 class VBOXXML_CLASS Error : public std::exception 117 109 { 118 110 public: … … 152 144 }; 153 145 154 class VBOX SETTINGS_CLASS LogicError : public Error146 class VBOXXML_CLASS LogicError : public Error 155 147 { 156 148 public: … … 158 150 LogicError (const char *aMsg = NULL) : Error (aMsg) {} 159 151 160 LogicError (RT_SRC_POS_DECL) 161 { 162 char *msg = NULL; 163 RTStrAPrintf (&msg, "In '%s', '%s' at #%d", 164 pszFunction, pszFile, iLine); 165 setWhat (msg); 166 RTStrFree (msg); 167 } 168 }; 169 170 class VBOXSETTINGS_CLASS RuntimeError : public Error 152 LogicError (RT_SRC_POS_DECL); 153 }; 154 155 class VBOXXML_CLASS RuntimeError : public Error 171 156 { 172 157 public: … … 178 163 ////////////////////////////////////////////////////////////////////////////// 179 164 180 class VBOX SETTINGS_CLASS ENotImplemented : public LogicError165 class VBOXXML_CLASS ENotImplemented : public LogicError 181 166 { 182 167 public: … … 186 171 }; 187 172 188 class VBOX SETTINGS_CLASS EInvalidArg : public LogicError173 class VBOXXML_CLASS EInvalidArg : public LogicError 189 174 { 190 175 public: … … 197 182 ////////////////////////////////////////////////////////////////////////////// 198 183 199 class VBOX SETTINGS_CLASS ENoMemory : public RuntimeError, public std::bad_alloc184 class VBOXXML_CLASS ENoMemory : public RuntimeError, public std::bad_alloc 200 185 { 201 186 public: … … 205 190 }; 206 191 207 class VBOX SETTINGS_CLASS EIPRTFailure : public RuntimeError192 class VBOXXML_CLASS EIPRTFailure : public RuntimeError 208 193 { 209 194 public: … … 223 208 * The Stream class is a base class for I/O streams. 224 209 */ 225 class VBOX SETTINGS_CLASS Stream210 class VBOXXML_CLASS Stream 226 211 { 227 212 public: … … 258 243 * useful functionality. 259 244 */ 260 class VBOX SETTINGS_CLASS Input : virtual public Stream245 class VBOXXML_CLASS Input : virtual public Stream 261 246 { 262 247 public: … … 276 261 * 277 262 */ 278 class VBOX SETTINGS_CLASS Output : virtual public Stream263 class VBOXXML_CLASS Output : virtual public Stream 279 264 { 280 265 public: … … 313 298 * when reading from or writing to such File instances. 314 299 */ 315 class VBOX SETTINGS_CLASS File : public Input, public Output300 class VBOXXML_CLASS File : public Input, public Output 316 301 { 317 302 public: … … 396 381 * memory buffer. 397 382 */ 398 class VBOX SETTINGS_CLASS MemoryBuf : public Input383 class VBOXXML_CLASS MemoryBuf : public Input 399 384 { 400 385 public: … … 411 396 412 397 private: 413 414 398 /* Obscure class data */ 415 399 struct Data; … … 422 406 423 407 /* 424 * VBoxXml 425 * 426 * 427 */ 428 429 430 class VBoxXmlBase 408 * GlobalLock 409 * 410 * 411 */ 412 413 typedef xmlParserInput* FNEXTERNALENTITYLOADER(const char *aURI, 414 const char *aID, 415 xmlParserCtxt *aCtxt); 416 typedef FNEXTERNALENTITYLOADER *PFNEXTERNALENTITYLOADER; 417 418 class VBOXXML_CLASS GlobalLock 419 { 420 public: 421 GlobalLock(); 422 ~GlobalLock(); 423 424 void setExternalEntityLoader(PFNEXTERNALENTITYLOADER pFunc); 425 426 static xmlParserInput* callDefaultLoader(const char *aURI, 427 const char *aID, 428 xmlParserCtxt *aCtxt); 429 430 private: 431 /* Obscure class data */ 432 struct Data; 433 std::auto_ptr<Data> m; 434 }; 435 436 /* 437 * XmlParserBase 438 * 439 */ 440 441 class VBOXXML_CLASS XmlParserBase 431 442 { 432 443 protected: 433 VBoxXmlBase(); 434 435 ~VBoxXmlBase(); 444 XmlParserBase(); 445 ~XmlParserBase(); 436 446 437 447 xmlParserCtxtPtr m_ctxt; 438 448 }; 439 449 440 class VBoxXmlFile : public VBoxXmlBase 441 { 442 public: 443 VBoxXmlFile(); 444 ~VBoxXmlFile(); 450 /* 451 * XmlFileParser 452 * 453 */ 454 455 class VBOXXML_CLASS XmlFileParser : public XmlParserBase 456 { 457 public: 458 XmlFileParser(); 459 ~XmlFileParser(); 460 461 void read(const char *pcszFilename); 462 463 private: 464 /* Obscure class data */ 465 struct Data; 466 std::auto_ptr<Data> m; 467 445 468 }; 446 469 … … 455 478 /** @} */ 456 479 457 } // end namespace vboxxml480 } // end namespace xml 458 481 459 482 #endif /* ___VBox_vboxxml_h */ -
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.