1 /* 2 * Copyright (C) 2019 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <sstream> 20 21 #include "xml.pb.h" 22 23 namespace xmlProtoFuzzer { 24 class ProtoConverter 25 { 26 public: 27 ProtoConverter() = default; 28 29 ProtoConverter(ProtoConverter const&) = delete; 30 31 ProtoConverter(ProtoConverter&&) = delete; 32 33 std::string protoToString(XmlDocument const&); 34 35 private: 36 void visit(Prolog const&); 37 38 void visit(ProcessingInstruction const&); 39 40 void visit(ExternalId const&); 41 42 void visit(DocTypeDecl const&); 43 44 void visit(VersionNum const&); 45 46 void visit(Encodings const&); 47 48 void visit(Misc const&); 49 50 void visit(KeyValue const&); 51 52 void visit(Element const&); 53 54 void visit(ElementDecl const&); 55 56 void visit(AttValue const&); 57 58 void visit(DefaultDecl const&); 59 60 void visit(AttDef const&); 61 62 void visit(AttListDecl const&); 63 64 void visit(NotationDecl const&); 65 66 void visit(EntityDecl const&); 67 68 void visit(EntityValue const&); 69 70 void visit(EntityDef const&); 71 72 void visit(PEDef const&); 73 74 void visit(NDataDecl const&); 75 76 void visit(ConditionalSect const&); 77 78 void visit(OneExtSubsetDecl const&); 79 80 void visit(ExtSubsetDecl const&); 81 82 void visit(MarkupDecl const&); 83 84 void visit(CData const&); 85 86 void visit(Content const&); 87 88 void visit(XmlDeclaration const&); 89 90 void visit(XmlDocument const&); 91 92 template <typename T> isValid(T const & messageType)93 bool isValid(T const& messageType) { 94 return T::Type_IsValid(messageType.type()); 95 } 96 97 std::string removeNonAscii(std::string const&); 98 std::string getUri(Element_Id _x); 99 std::string getPredefined(Element_Id _x, std::string const&); 100 101 std::ostringstream m_output; 102 103 static constexpr auto s_XInclude = "xmlns:xi=\"http://www.w3.org/2001/XInclude\""; 104 }; 105 } 106 107