1 #include <libxml/xmlreader.h>
5 #include <zypp/base/LogControl.h>
6 #include <zypp/base/LogTools.h>
7 #include <zypp/base/Function.h>
8 #include <zypp/base/GzStream.h>
9 #include <zypp/parser/yum/YUMParser.h>
10 #include <zypp/Pathname.h>
14 using namespace zypp::parser::yum;
16 #include "zypp/parser/yum/YUMParser.h"
18 ///////////////////////////////////////////////////////////////////
21 void ti( const _Cl & c )
23 SEC << __PRETTY_FUNCTION__ << endl;
25 ///////////////////////////////////////////////////////////////////
27 template<class _Parser>
28 bool consume( const typename _Parser::value_type & node_r )
30 //DBG << node_r << endl;
34 template<class _Parser>
35 void parseXmlFile( const Pathname & file_r,
36 function<bool(const typename _Parser::value_type &)> consume_r
39 Measure x( " zparse "+file_r.asString() );
40 ifgzstream istr( file_r.asString().c_str() );
43 ZYPP_THROW( Exception( "Bad stream" ) );
46 for( _Parser parser( istr, "" ); ! parser.atEnd(); ++parser )
48 if ( consume_r && ! consume_r( *parser ) )
50 DBG << "abort parseXmlFile " << file_r << endl;
56 bool consumeRepomd( const YUMRepomdParser::value_type & node_r )
58 DBG << node_r << endl;
62 void zparse( const Pathname & repodata_r )
64 Measure x( "ZPARSE" );
65 parseXmlFile<YUMRepomdParser> ( repodata_r / "repomd.xml", consumeRepomd );
66 parseXmlFile<YUMPrimaryParser> ( repodata_r / "primary.xml" );
67 parseXmlFile<YUMOtherParser> ( repodata_r / "other.xml" );
68 parseXmlFile<YUMFileListParser>( repodata_r / "filelists.xml" );
69 //parseXmlFile<YUMPatchesParser> ( repodata_r / "patches.xml" );
72 ///////////////////////////////////////////////////////////////////
76 * @reader: the xmlReader
78 * Dump information about the current node
80 template<class _ParserValueType>
82 processNode(xmlTextReaderPtr reader, const _ParserValueType & stp ) {
83 const xmlChar *name, *value;
85 name = xmlTextReaderConstName(reader);
89 value = xmlTextReaderConstValue(reader);
93 t = (const char *)value;
96 printf("%d %d %s %d %d",
97 xmlTextReaderDepth(reader),
98 xmlTextReaderNodeType(reader),
100 xmlTextReaderIsEmptyElement(reader),
101 xmlTextReaderHasValue(reader));
105 if (xmlStrlen(value) > 40)
106 printf(" %.40s...\n", value);
108 printf(" %s\n", value);
115 * @filename: the file name to parse
117 * Parse and print information about an XML file.
119 template<class _Parser>
121 streamFile(const char *filename) {
122 Measure x( string(" lparse ")+filename );
123 xmlTextReaderPtr reader;
126 typename _Parser::value_type stp;
128 reader = xmlReaderForFile(filename, NULL, 0);
129 if (reader != NULL) {
130 ret = xmlTextReaderRead(reader);
132 stp = new typename _Parser::value_type::element_type;
133 processNode(reader, stp);
134 ret = xmlTextReaderRead(reader);
136 xmlFreeTextReader(reader);
138 ZYPP_THROW( Exception( string("Failed to parse ") + filename ) );
141 ZYPP_THROW( Exception( string("Unable to open ") + filename ) );
145 void lparse( const Pathname & repodata_r )
147 Measure x( "LPARSE" );
149 * this initialize the library and check potential ABI mismatches
150 * between the version it was compiled for and the actual shared
155 streamFile<YUMRepomdParser> ( (repodata_r / "repomd.xml").asString().c_str() );
156 streamFile<YUMPrimaryParser> ( (repodata_r / "primary.xml").asString().c_str() );
157 streamFile<YUMOtherParser> ( (repodata_r / "other.xml").asString().c_str() );
158 streamFile<YUMFileListParser>( (repodata_r / "filelists.xml").asString().c_str() );
159 //streamFile<YUMPatchesParser> ( (repodata_r / "patches.xml").asString().c_str() );
162 * Cleanup function for the XML library.
167 * this is to debug memory for regression tests
172 /******************************************************************
174 ** FUNCTION NAME : main
175 ** FUNCTION TYPE : int
177 int main( int argc, char * argv[] )
179 INT << "===[START]==========================================" << endl;
181 Pathname repodata( "/Local/PATCHES/repodata" );
182 repodata = "/Local/FACTORY/repodata";
186 INT << "===[END]============================================" << endl << endl;