Line data Source code
1 : /* Copyright (C) 2025 Wildfire Games. 2 : * This file is part of 0 A.D. 3 : * 4 : * 0 A.D. is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * 0 A.D. is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #ifndef INCLUDED_RELAXNG 19 : #define INCLUDED_RELAXNG 20 : 21 : #include "lib/file/vfs/vfs.h" 22 : #include "lib/file/vfs/vfs_path.h" 23 : #include "maths/MD5.h" 24 : 25 : #include <libxml/parser.h> 26 : #include <string> 27 : 28 : typedef struct _xmlRelaxNG xmlRelaxNG; 29 : typedef xmlRelaxNG *xmlRelaxNGPtr; 30 : typedef struct _xmlDoc xmlDoc; 31 : typedef xmlDoc *xmlDocPtr; 32 : 33 : class RelaxNGValidator 34 : { 35 : public: 36 : RelaxNGValidator(); 37 : ~RelaxNGValidator(); 38 : 39 : bool LoadGrammar(const std::string& grammar); 40 : 41 : bool LoadGrammarFile(const PIVFS& vfs, const VfsPath& grammarPath); 42 : 43 8998 : MD5 GetGrammarHash() const { return m_Hash; } 44 : 45 : bool Validate(const std::string& filename, const std::string& document) const; 46 : 47 : bool ValidateEncoded(const std::string& filename, const std::string& document) const; 48 : 49 : bool ValidateEncoded(xmlDocPtr doc) const; 50 : 51 : bool CanValidate() const; 52 : 53 : private: 54 : MD5 m_Hash; 55 : xmlRelaxNGPtr m_Schema; 56 : }; 57 : 58 : /** 59 : * There should be no references to validators or schemas outside of the cache anymore when calling this. 60 : */ 61 : void ClearSchemaCache(); 62 : 63 : #endif // INCLUDED_RELAXNG